aboutsummaryrefslogtreecommitdiff
path: root/audio/herrie/patches/herrie-autoquit.diff
blob: d2f01b60dbe2268590d5c31abc36fbde1e14b6ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
diff -ru herrie-autoplay/herrie-2.0.2/src/config.c herrie-autoquit/herrie-2.0.2/src/config.c
--- herrie-autoplay/herrie-2.0.2/src/config.c	2008-05-16 20:49:55.000000000 -0500
+++ herrie-autoquit/herrie-2.0.2/src/config.c	2008-05-16 02:31:56.000000000 -0500
@@ -163,6 +163,7 @@
 	{ "gui.input.may_quit",		"yes",		valid_bool,	NULL },
 	{ "gui.vfslist.scrollpages",	"no",		valid_bool,	NULL },
 	{ "playq.autoplay",		"no",		valid_bool,	NULL },
+	{ "playq.autoquit",		"no",		valid_bool,	NULL },
 	{ "playq.dumpfile",		CONFHOMEDIR PLAYQ_DUMPFILE, NULL, NULL },
 	{ "playq.xmms",			"no",		valid_bool,	NULL },
 #ifdef BUILD_SCROBBLER
diff -ru herrie-autoplay/herrie-2.0.2/src/main.c herrie-autoquit/herrie-2.0.2/src/main.c
--- herrie-autoplay/herrie-2.0.2/src/main.c	2008-05-16 20:49:55.000000000 -0500
+++ herrie-autoquit/herrie-2.0.2/src/main.c	2008-05-16 02:33:37.000000000 -0500
@@ -99,7 +99,7 @@
 static void
 usage(void)
 {
-	g_printerr("%s: " APP_NAME " [-pvx] [-c configfile] "
+	g_printerr("%s: " APP_NAME " [-pqvx] [-c configfile] "
 	    "[file ...]\n", _("usage"));
 	exit(1);
 }
@@ -110,7 +110,7 @@
 int
 main(int argc, char *argv[])
 {
-	int ch, i, show_version = 0, autoplay = 0, xmms = 0;
+	int ch, i, show_version = 0, autoplay = 0, autoquit = 0, xmms = 0;
 	char *cwd;
 	const char *errmsg;
 	struct vfsref *vr;
@@ -128,7 +128,7 @@
 	config_load(CONFFILE, 1);
 	config_load(CONFHOMEDIR "config", 1);
 
-	while ((ch = getopt(argc, argv, "c:pvx")) != -1) {
+	while ((ch = getopt(argc, argv, "c:pqvx")) != -1) {
 		switch (ch) {
 		case 'c':
 			config_load(optarg, 0);
@@ -136,6 +136,9 @@
 		case 'p':
 			autoplay = 1;
 			break;
+		case 'q':
+			autoquit = 1;
+			break;
 		case 'v':
 			show_version = 1;
 			break;
@@ -173,7 +176,7 @@
 #ifdef BUILD_SCROBBLER
 	scrobbler_init();
 #endif /* BUILD_SCROBBLER */
-	playq_init(autoplay, xmms, (argc == 0));
+	playq_init(autoplay, autoquit, xmms, (argc == 0));
 
 	/* Draw all the windows */
 	gui_draw_init_post();
diff -ru herrie-autoplay/herrie-2.0.2/src/playq.c herrie-autoquit/herrie-2.0.2/src/playq.c
--- herrie-autoplay/herrie-2.0.2/src/playq.c	2008-05-16 20:49:55.000000000 -0500
+++ herrie-autoquit/herrie-2.0.2/src/playq.c	2008-05-25 00:25:02.000000000 -0500
@@ -151,6 +151,11 @@
 static volatile int	playq_seek_time;
 
 /**
+ * @brief If true, quit when end of list reached
+ */
+int			playq_autoquit = 0;
+
+/**
  * @brief Infinitely play music in the playlist, honouring the
  *        playq_flags.
  */
@@ -163,6 +168,8 @@
 
 	gui_input_sigmask();
 
+	/* Used to prevent autoquit occuring at startup when autoplay is enabled on an empty list */
+	int playq_autoquit_ready = 0;
 	do {
 		/* Wait until there's a song available */
 		playq_lock();
@@ -174,10 +181,20 @@
 			}
 
 			/* Try to start a new song when we're not stopped */
-			if (!(playq_flags & PF_STOP) &&
-			    (nvr = funcs->give()) != NULL) {
+			if (!(playq_flags & PF_STOP)) {
+			    if ((nvr = funcs->give()) != NULL) {
 				/* We've got work to do */
 				break;
+			    }
+			    else {
+				if (playq_autoquit_ready && playq_autoquit) {
+					/* Time to quit - Send ourself the SIGTERM */
+					int res = getpid();
+  					if (res !=0){
+    						kill(res,SIGTERM);
+  					}
+			        }
+			    }
 			}
 
 			/* Wait for new events to occur */
@@ -188,6 +205,9 @@
 		}
 		playq_unlock();
 
+		/* Safe to autoquit now */
+		playq_autoquit_ready = 1;
+
 		cur = audio_file_open(nvr);
 		if (cur == NULL) {
 			/* Skip broken songs */
@@ -242,7 +262,7 @@
 }
 
 void
-playq_init(int autoplay, int xmms, int load_dumpfile)
+playq_init(int autoplay, int autoquit, int xmms, int load_dumpfile)
 {
 	const char *filename;
 	struct vfsref *vr;
@@ -259,6 +279,9 @@
 		playq_repeat = 1;
 	}
 
+	if (autoquit || config_getopt_bool("playq.autoquit"))
+		playq_autoquit = 1;
+
 	filename = config_getopt("playq.dumpfile");
 	if (load_dumpfile && filename[0] != '\0') {
 		/* Autoload playlist */
diff -ru herrie-autoplay/herrie-2.0.2/src/playq.h herrie-autoquit/herrie-2.0.2/src/playq.h
--- herrie-autoplay/herrie-2.0.2/src/playq.h	2008-05-16 20:49:55.000000000 -0500
+++ herrie-autoquit/herrie-2.0.2/src/playq.h	2008-05-16 02:38:12.000000000 -0500
@@ -33,7 +33,7 @@
 /**
  * @brief Initialize the playlist locking.
  */
-void playq_init(int autoplay, int xmms, int load_dumpfile);
+void playq_init(int autoplay, int autoquit, int xmms, int load_dumpfile);
 /**
  * @brief Spawn the playback thread.
  */
diff -ru herrie-autoplay/herrie-2.0.2/src/playq_modules.h herrie-autoquit/herrie-2.0.2/src/playq_modules.h
--- herrie-autoplay/herrie-2.0.2/src/playq_modules.h	2008-04-23 14:29:24.000000000 -0500
+++ herrie-autoquit/herrie-2.0.2/src/playq_modules.h	2008-05-16 03:01:29.000000000 -0500
@@ -36,6 +36,11 @@
 extern int playq_repeat;
 
 /**
+ * @brief Flag whether autoquit is turned on by the user.
+ */
+extern int playq_autoquit;
+
+/**
  * @brief Herrie's routine to fetch the next song from the playlist
  *        (always the first song).
  */
diff -ru herrie-autoplay/herrie-2.0.2/src/playq_party.c herrie-autoquit/herrie-2.0.2/src/playq_party.c
--- herrie-autoplay/herrie-2.0.2/src/playq_party.c	2008-04-23 14:29:24.000000000 -0500
+++ herrie-autoquit/herrie-2.0.2/src/playq_party.c	2008-05-16 03:57:41.000000000 -0500
@@ -49,7 +49,7 @@
 	nvr = vfs_dup(vr);
 	gui_playq_notify_pre_removal(1);
 	vfs_list_remove(&playq_list, vr);
-	if (playq_repeat) {
+	if (playq_repeat && !playq_autoquit) {
 		/* Add it back to the tail */
 		vfs_list_insert_tail(&playq_list, vr);
 		gui_playq_notify_post_insertion(vfs_list_items(&playq_list));
diff -ru herrie-autoplay/herrie-2.0.2/src/playq_xmms.c herrie-autoquit/herrie-2.0.2/src/playq_xmms.c
--- herrie-autoplay/herrie-2.0.2/src/playq_xmms.c	2008-05-16 20:49:55.000000000 -0500
+++ herrie-autoquit/herrie-2.0.2/src/playq_xmms.c	2008-05-16 02:50:17.000000000 -0500
@@ -61,7 +61,7 @@
 		/* Song after current song */
 		cursong = vfs_list_next(cursong);
 		/* We've reached the end */
-		if (cursong == NULL && playq_repeat)
+		if (cursong == NULL && playq_repeat && !playq_autoquit)
 			cursong = vfs_list_first(&playq_list);
 	} else {
 		cursong = vfs_list_first(&playq_list);