117
|
1 /*
|
|
2 * Audacious: A cross-platform multimedia player.
|
|
3 * Copyright (c) 2005 Audacious Team
|
|
4 */
|
|
5 #include "config.h"
|
|
6
|
|
7 #include <glib.h>
|
|
8 #include <glib/gi18n.h>
|
|
9 #include <gtk/gtk.h>
|
|
10 #include <sys/types.h>
|
|
11 #include <sys/wait.h>
|
|
12
|
|
13 #include <signal.h>
|
|
14 #include <unistd.h>
|
|
15 #include <stdio.h>
|
|
16
|
|
17 #include <string.h>
|
|
18
|
|
19 #include "audacious/plugin.h"
|
|
20 #include "libaudacious/configfile.h"
|
|
21 #include "libaudacious/beepctrl.h"
|
|
22 #include "libaudacious/formatter.h"
|
|
23
|
|
24 static void init(void);
|
|
25 static void cleanup(void);
|
|
26 static void configure(void);
|
|
27 static int timeout_func(gpointer);
|
|
28
|
|
29 static int timeout_tag = 0;
|
|
30 static int previous_song = -1;
|
|
31 static char *cmd_line = NULL;
|
|
32 static char *cmd_line_after = NULL;
|
|
33 static char *cmd_line_end = NULL;
|
|
34 static gboolean possible_pl_end;
|
|
35
|
|
36 static GtkWidget *configure_win = NULL, *configure_vbox;
|
|
37 static GtkWidget *cmd_entry, *cmd_after_entry, *cmd_end_entry;
|
|
38
|
|
39 GeneralPlugin sc_gp =
|
|
40 {
|
|
41 NULL, /* handle */
|
|
42 NULL, /* filename */
|
|
43 -1, /* xmms_session */
|
|
44 NULL, /* Description */
|
|
45 init,
|
|
46 NULL,
|
|
47 configure,
|
|
48 cleanup,
|
|
49 };
|
|
50
|
|
51 GeneralPlugin *get_gplugin_info(void)
|
|
52 {
|
|
53 sc_gp.description = g_strdup_printf(_("Song Change %s"), VERSION);
|
|
54 return &sc_gp;
|
|
55 }
|
|
56
|
|
57 static void read_config(void)
|
|
58 {
|
|
59 ConfigFile *cfgfile;
|
|
60
|
|
61 g_free(cmd_line);
|
|
62 g_free(cmd_line_after);
|
|
63 g_free(cmd_line_end);
|
|
64 cmd_line = NULL;
|
|
65 cmd_line_after = NULL;
|
|
66 cmd_line_end = NULL;
|
|
67
|
|
68 if ((cfgfile = xmms_cfg_open_default_file()) != NULL)
|
|
69 {
|
|
70 xmms_cfg_read_string(cfgfile, "song_change", "cmd_line", &cmd_line);
|
|
71 xmms_cfg_read_string(cfgfile, "song_change", "cmd_line_after", &cmd_line_after);
|
|
72 xmms_cfg_read_string(cfgfile, "song_change", "cmd_line_end", &cmd_line_end);
|
|
73 xmms_cfg_free(cfgfile);
|
|
74 }
|
|
75 if (!cmd_line)
|
|
76 cmd_line = g_strdup("");
|
|
77 if (!cmd_line_after)
|
|
78 cmd_line_after = g_strdup("");
|
|
79 if (!cmd_line_end)
|
|
80 cmd_line_end = g_strdup("");
|
|
81 }
|
|
82
|
|
83 static void init(void)
|
|
84 {
|
|
85 read_config();
|
|
86
|
|
87 previous_song = -1;
|
|
88 timeout_tag = gtk_timeout_add(100, timeout_func, NULL);
|
|
89 }
|
|
90
|
|
91 static void cleanup(void)
|
|
92 {
|
|
93 if (timeout_tag)
|
|
94 gtk_timeout_remove(timeout_tag);
|
|
95 timeout_tag = 0;
|
|
96
|
|
97 g_free(cmd_line);
|
|
98 g_free(cmd_line_after);
|
|
99 g_free(cmd_line_end);
|
|
100 cmd_line = NULL;
|
|
101 cmd_line_after = NULL;
|
|
102 cmd_line_end = NULL;
|
|
103 signal(SIGCHLD, SIG_DFL);
|
|
104 }
|
|
105
|
|
106 static void save_and_close(GtkWidget *w, gpointer data)
|
|
107 {
|
|
108 char *cmd, *cmd_after, *cmd_end;
|
|
109 ConfigFile *cfgfile = xmms_cfg_open_default_file();
|
|
110
|
|
111 cmd = gtk_entry_get_text(GTK_ENTRY(cmd_entry));
|
|
112 cmd_after = gtk_entry_get_text(GTK_ENTRY(cmd_after_entry));
|
|
113 cmd_end = gtk_entry_get_text(GTK_ENTRY(cmd_end_entry));
|
|
114
|
|
115 xmms_cfg_write_string(cfgfile, "song_change", "cmd_line", cmd);
|
|
116 xmms_cfg_write_string(cfgfile, "song_change", "cmd_line_after", cmd_after);
|
|
117 xmms_cfg_write_string(cfgfile, "song_change", "cmd_line_end", cmd_end);
|
|
118 xmms_cfg_write_default_file(cfgfile);
|
|
119 xmms_cfg_free(cfgfile);
|
|
120
|
|
121 if (timeout_tag)
|
|
122 {
|
|
123 g_free(cmd_line);
|
|
124 cmd_line = g_strdup(cmd);
|
|
125 g_free(cmd_line_after);
|
|
126 cmd_line_after = g_strdup(cmd_after);
|
|
127 g_free(cmd_line_end);
|
|
128 cmd_line_end = g_strdup(cmd_end);
|
|
129 }
|
|
130 gtk_widget_destroy(configure_win);
|
|
131 }
|
|
132
|
|
133 static void warn_user(void)
|
|
134 {
|
|
135 GtkWidget *warn_win, *warn_vbox, *warn_desc;
|
|
136 GtkWidget *warn_bbox, *warn_yes, *warn_no;
|
|
137
|
118
|
138 warn_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
117
|
139 gtk_window_set_title(GTK_WINDOW(warn_win), _("Warning"));
|
|
140 gtk_window_set_transient_for(GTK_WINDOW(warn_win),
|
|
141 GTK_WINDOW(configure_win));
|
|
142 gtk_window_set_modal(GTK_WINDOW(warn_win), TRUE);
|
|
143
|
|
144 gtk_container_set_border_width(GTK_CONTAINER(warn_win), 10);
|
|
145
|
|
146 warn_vbox = gtk_vbox_new(FALSE, 10);
|
|
147 gtk_container_add(GTK_CONTAINER(warn_win), warn_vbox);
|
|
148
|
|
149 warn_desc = gtk_label_new(_(
|
|
150 "Filename and song title tags should be inside "
|
|
151 "double quotes (\"). Not doing so might be a "
|
|
152 "security risk. Continue anyway?"));
|
|
153 gtk_label_set_justify(GTK_LABEL(warn_desc), GTK_JUSTIFY_LEFT);
|
|
154 gtk_misc_set_alignment(GTK_MISC(warn_desc), 0, 0.5);
|
|
155 gtk_box_pack_start(GTK_BOX(warn_vbox), warn_desc, FALSE, FALSE, 0);
|
|
156 gtk_label_set_line_wrap(GTK_LABEL(warn_desc), TRUE);
|
|
157
|
|
158 warn_bbox = gtk_hbutton_box_new();
|
|
159 gtk_button_box_set_layout(GTK_BUTTON_BOX(warn_bbox), GTK_BUTTONBOX_END);
|
|
160 gtk_button_box_set_spacing(GTK_BUTTON_BOX(warn_bbox), 5);
|
|
161 gtk_box_pack_start(GTK_BOX(warn_vbox), warn_bbox, FALSE, FALSE, 0);
|
|
162
|
|
163 warn_yes = gtk_button_new_with_label(_("Yes"));
|
|
164 gtk_signal_connect(GTK_OBJECT(warn_yes), "clicked",
|
|
165 GTK_SIGNAL_FUNC(save_and_close), NULL);
|
|
166 gtk_signal_connect_object(GTK_OBJECT(warn_yes), "clicked",
|
|
167 GTK_SIGNAL_FUNC(gtk_widget_destroy),
|
|
168 GTK_OBJECT(warn_win));
|
|
169 GTK_WIDGET_SET_FLAGS(warn_yes, GTK_CAN_DEFAULT);
|
|
170 gtk_box_pack_start(GTK_BOX(warn_bbox), warn_yes, TRUE, TRUE, 0);
|
|
171 gtk_widget_grab_default(warn_yes);
|
|
172
|
|
173 warn_no = gtk_button_new_with_label(_("No"));
|
|
174 gtk_signal_connect_object(GTK_OBJECT(warn_no), "clicked",
|
|
175 GTK_SIGNAL_FUNC(gtk_widget_destroy),
|
|
176 GTK_OBJECT(warn_win));
|
|
177 GTK_WIDGET_SET_FLAGS(warn_no, GTK_CAN_DEFAULT);
|
|
178 gtk_box_pack_start(GTK_BOX(warn_bbox), warn_no, TRUE, TRUE, 0);
|
|
179
|
|
180 gtk_widget_show_all(warn_win);
|
|
181 }
|
|
182
|
|
183 static int check_command(char *command)
|
|
184 {
|
|
185 const char *dangerous = "fns";
|
|
186 char *c;
|
|
187 int qu = 0;
|
|
188
|
|
189 for (c = command; *c != '\0'; c++)
|
|
190 {
|
|
191 if (*c == '"' && (c == command || *(c - 1) != '\\'))
|
|
192 qu = !qu;
|
|
193 else if (*c == '%' && !qu && strchr(dangerous, *(c + 1)))
|
|
194 return -1;
|
|
195 }
|
|
196 return 0;
|
|
197 }
|
|
198
|
|
199 static void configure_ok_cb(GtkWidget *w, gpointer data)
|
|
200 {
|
|
201 char *cmd, *cmd_after, *cmd_end;
|
|
202
|
|
203 cmd = gtk_entry_get_text(GTK_ENTRY(cmd_entry));
|
|
204 cmd_after = gtk_entry_get_text(GTK_ENTRY(cmd_after_entry));
|
|
205 cmd_end = gtk_entry_get_text(GTK_ENTRY(cmd_end_entry));
|
|
206
|
|
207 if (check_command(cmd) < 0 || check_command(cmd_after) < 0
|
|
208 || check_command(cmd_end) < 0)
|
|
209 warn_user();
|
|
210 else
|
|
211 save_and_close(NULL, NULL);
|
|
212 }
|
|
213
|
|
214
|
|
215 static void configure(void)
|
|
216 {
|
|
217 GtkWidget *sep1, *sep2, *sep3;
|
|
218 GtkWidget *cmd_hbox, *cmd_label;
|
|
219 GtkWidget *cmd_after_hbox, *cmd_after_label;
|
|
220 GtkWidget *cmd_end_hbox, *cmd_end_label;
|
|
221 GtkWidget *cmd_desc, *cmd_after_desc, *cmd_end_desc, *f_desc;
|
|
222 GtkWidget *configure_bbox, *configure_ok, *configure_cancel;
|
|
223 GtkWidget *song_frame, *song_vbox;
|
|
224 char *temp;
|
|
225
|
|
226 if (configure_win)
|
|
227 return;
|
|
228
|
|
229 read_config();
|
|
230
|
118
|
231 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
117
|
232 gtk_signal_connect(GTK_OBJECT(configure_win), "destroy",
|
|
233 GTK_SIGNAL_FUNC(gtk_widget_destroyed),
|
|
234 &configure_win);
|
|
235 gtk_window_set_title(GTK_WINDOW(configure_win),
|
|
236 _("Song Change Configuration"));
|
|
237
|
|
238 gtk_container_set_border_width(GTK_CONTAINER(configure_win), 10);
|
|
239
|
|
240 configure_vbox = gtk_vbox_new(FALSE, 10);
|
|
241 gtk_container_add(GTK_CONTAINER(configure_win), configure_vbox);
|
|
242
|
|
243 song_frame = gtk_frame_new(_("Commands"));
|
|
244 gtk_box_pack_start(GTK_BOX(configure_vbox), song_frame, FALSE, FALSE, 0);
|
|
245 song_vbox = gtk_vbox_new(FALSE, 10);
|
|
246 gtk_container_set_border_width(GTK_CONTAINER(song_vbox), 5);
|
|
247 gtk_container_add(GTK_CONTAINER(song_frame), song_vbox);
|
|
248
|
|
249 cmd_desc = gtk_label_new(_(
|
119
|
250 "Shell-command to run when Audacious starts a new song."));
|
117
|
251 gtk_label_set_justify(GTK_LABEL(cmd_desc), GTK_JUSTIFY_LEFT);
|
|
252 gtk_misc_set_alignment(GTK_MISC(cmd_desc), 0, 0.5);
|
|
253 gtk_box_pack_start(GTK_BOX(song_vbox), cmd_desc, FALSE, FALSE, 0);
|
|
254 gtk_label_set_line_wrap(GTK_LABEL(cmd_desc), TRUE);
|
|
255
|
|
256 cmd_hbox = gtk_hbox_new(FALSE, 5);
|
|
257 gtk_box_pack_start(GTK_BOX(song_vbox), cmd_hbox, FALSE, FALSE, 0);
|
|
258
|
|
259 cmd_label = gtk_label_new(_("Command:"));
|
|
260 gtk_box_pack_start(GTK_BOX(cmd_hbox), cmd_label, FALSE, FALSE, 0);
|
|
261
|
|
262 cmd_entry = gtk_entry_new();
|
|
263 if (cmd_line)
|
|
264 gtk_entry_set_text(GTK_ENTRY(cmd_entry), cmd_line);
|
|
265 gtk_widget_set_usize(cmd_entry, 200, -1);
|
|
266 gtk_box_pack_start(GTK_BOX(cmd_hbox), cmd_entry, TRUE, TRUE, 0);
|
|
267
|
|
268 sep1 = gtk_hseparator_new();
|
|
269 gtk_box_pack_start(GTK_BOX(song_vbox), sep1, TRUE, TRUE, 0);
|
|
270
|
|
271
|
|
272 cmd_after_desc = gtk_label_new(_(
|
|
273 "Shell-command to run toward the end of a song."));
|
|
274 gtk_label_set_justify(GTK_LABEL(cmd_after_desc), GTK_JUSTIFY_LEFT);
|
|
275 gtk_misc_set_alignment(GTK_MISC(cmd_after_desc), 0, 0.5);
|
|
276 gtk_box_pack_start(GTK_BOX(song_vbox), cmd_after_desc, FALSE, FALSE, 0);
|
|
277 gtk_label_set_line_wrap(GTK_LABEL(cmd_after_desc), TRUE);
|
|
278
|
|
279 cmd_after_hbox = gtk_hbox_new(FALSE, 5);
|
|
280 gtk_box_pack_start(GTK_BOX(song_vbox), cmd_after_hbox, FALSE, FALSE, 0);
|
|
281
|
|
282 cmd_after_label = gtk_label_new(_("Command:"));
|
|
283 gtk_box_pack_start(GTK_BOX(cmd_after_hbox), cmd_after_label, FALSE, FALSE, 0);
|
|
284
|
|
285 cmd_after_entry = gtk_entry_new();
|
|
286 if (cmd_line_after)
|
|
287 gtk_entry_set_text(GTK_ENTRY(cmd_after_entry), cmd_line_after);
|
|
288 gtk_widget_set_usize(cmd_after_entry, 200, -1);
|
|
289 gtk_box_pack_start(GTK_BOX(cmd_after_hbox), cmd_after_entry, TRUE, TRUE, 0);
|
|
290 sep2 = gtk_hseparator_new();
|
|
291 gtk_box_pack_start(GTK_BOX(song_vbox), sep2, TRUE, TRUE, 0);
|
|
292
|
|
293
|
|
294 cmd_end_desc = gtk_label_new(_(
|
119
|
295 "Shell-command to run when Audacious reaches the end "
|
117
|
296 "of the playlist."));
|
|
297 gtk_label_set_justify(GTK_LABEL(cmd_end_desc), GTK_JUSTIFY_LEFT);
|
|
298 gtk_misc_set_alignment(GTK_MISC(cmd_end_desc), 0, 0.5);
|
|
299 gtk_box_pack_start(GTK_BOX(song_vbox), cmd_end_desc, FALSE, FALSE, 0);
|
|
300 gtk_label_set_line_wrap(GTK_LABEL(cmd_end_desc), TRUE);
|
|
301
|
|
302 cmd_end_hbox = gtk_hbox_new(FALSE, 5);
|
|
303 gtk_box_pack_start(GTK_BOX(song_vbox), cmd_end_hbox, FALSE, FALSE, 0);
|
|
304
|
|
305 cmd_end_label = gtk_label_new(_("Command:"));
|
|
306 gtk_box_pack_start(GTK_BOX(cmd_end_hbox), cmd_end_label, FALSE, FALSE, 0);
|
|
307
|
|
308 cmd_end_entry = gtk_entry_new();
|
|
309 if (cmd_line_end)
|
|
310 gtk_entry_set_text(GTK_ENTRY(cmd_end_entry), cmd_line_end);
|
|
311 gtk_widget_set_usize(cmd_end_entry, 200, -1);
|
|
312 gtk_box_pack_start(GTK_BOX(cmd_end_hbox), cmd_end_entry, TRUE, TRUE, 0);
|
|
313 sep3 = gtk_hseparator_new();
|
|
314 gtk_box_pack_start(GTK_BOX(song_vbox), sep3, TRUE, TRUE, 0);
|
|
315
|
|
316
|
|
317 temp = g_strdup_printf(
|
|
318 _("You can use the following format strings which "
|
|
319 "will be substituted before calling the command "
|
|
320 "(not all are useful for the end-of-playlist command).\n\n"
|
|
321 "%%F: Frequency (in hertz)\n"
|
|
322 "%%c: Number of channels\n"
|
|
323 "%%f: filename (full path)\n"
|
|
324 "%%l: length (in milliseconds)\n"
|
|
325 "%%n or %%s: Song name\n"
|
|
326 "%%r: Rate (in bits per second)\n"
|
|
327 "%%t: Playlist position (%%02d)\n"
|
|
328 "%%p: Currently playing (1 or 0)"));
|
|
329 f_desc = gtk_label_new(temp);
|
|
330 g_free(temp);
|
|
331
|
|
332 gtk_label_set_justify(GTK_LABEL(f_desc), GTK_JUSTIFY_LEFT);
|
|
333 gtk_misc_set_alignment(GTK_MISC(f_desc), 0, 0.5);
|
|
334 gtk_box_pack_start(GTK_BOX(song_vbox), f_desc, FALSE, FALSE, 0);
|
|
335 gtk_label_set_line_wrap(GTK_LABEL(f_desc), TRUE);
|
|
336
|
|
337
|
|
338
|
|
339
|
|
340 configure_bbox = gtk_hbutton_box_new();
|
|
341 gtk_button_box_set_layout(GTK_BUTTON_BOX(configure_bbox), GTK_BUTTONBOX_END);
|
|
342 gtk_button_box_set_spacing(GTK_BUTTON_BOX(configure_bbox), 5);
|
|
343 gtk_box_pack_start(GTK_BOX(configure_vbox), configure_bbox, FALSE, FALSE, 0);
|
|
344
|
|
345 configure_ok = gtk_button_new_with_label(_("OK"));
|
|
346 gtk_signal_connect(GTK_OBJECT(configure_ok), "clicked", GTK_SIGNAL_FUNC(configure_ok_cb), NULL);
|
|
347 GTK_WIDGET_SET_FLAGS(configure_ok, GTK_CAN_DEFAULT);
|
|
348 gtk_box_pack_start(GTK_BOX(configure_bbox), configure_ok, TRUE, TRUE, 0);
|
|
349 gtk_widget_grab_default(configure_ok);
|
|
350
|
|
351 configure_cancel = gtk_button_new_with_label(_("Cancel"));
|
|
352 gtk_signal_connect_object(GTK_OBJECT(configure_cancel), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(configure_win));
|
|
353 GTK_WIDGET_SET_FLAGS(configure_cancel, GTK_CAN_DEFAULT);
|
|
354 gtk_box_pack_start(GTK_BOX(configure_bbox), configure_cancel, TRUE, TRUE, 0);
|
|
355
|
|
356 gtk_widget_show_all(configure_win);
|
|
357 }
|
|
358
|
|
359 static void bury_child(int signal)
|
|
360 {
|
|
361 waitpid(-1, NULL, WNOHANG);
|
|
362 }
|
|
363
|
|
364 static void execute_command(char *cmd)
|
|
365 {
|
|
366 char *argv[4] = {"/bin/sh", "-c", NULL, NULL};
|
|
367 int i;
|
|
368 argv[2] = cmd;
|
|
369 signal(SIGCHLD, bury_child);
|
|
370 if (fork() == 0)
|
|
371 {
|
|
372 /* We don't want this process to hog the audio device etc */
|
|
373 for (i = 3; i < 255; i++)
|
|
374 close(i);
|
|
375 execv("/bin/sh", argv);
|
|
376 }
|
|
377 }
|
|
378
|
|
379 /*
|
|
380 * escape_shell_chars()
|
|
381 *
|
|
382 * Escapes characters that are special to the shell inside double quotes.
|
|
383 */
|
|
384
|
|
385 static char* escape_shell_chars(const char *string)
|
|
386 {
|
|
387 const char *special = "$`\"\\"; /* Characters to escape */
|
|
388 const char *in = string;
|
|
389 char *out;
|
|
390 char *escaped;
|
|
391 int num = 0;
|
|
392
|
|
393 while (*in != '\0')
|
|
394 if (strchr(special, *in++))
|
|
395 num++;
|
|
396
|
|
397 escaped = g_malloc(strlen(string) + num + 1);
|
|
398
|
|
399 in = string;
|
|
400 out = escaped;
|
|
401
|
|
402 while (*in != '\0')
|
|
403 {
|
|
404 if (strchr(special, *in))
|
|
405 *out++ = '\\';
|
|
406 *out++ = *in++;
|
|
407 }
|
|
408 *out = '\0';
|
|
409
|
|
410 return escaped;
|
|
411 }
|
|
412
|
|
413
|
|
414
|
|
415 /* Format codes:
|
|
416 *
|
|
417 * F - frequency (in hertz)
|
|
418 * c - number of channels
|
|
419 * f - filename (full path)
|
|
420 * l - length (in milliseconds)
|
|
421 * n - name
|
|
422 * r - rate (in bits per second)
|
|
423 * s - name (since everyone's used to it)
|
|
424 * t - playlist position (%02d)
|
|
425 * p - currently playing (1 or 0)
|
|
426 */
|
|
427 /* do_command(): do @cmd after replacing the format codes
|
|
428 @cmd: command to run
|
|
429 @current_file: file name of current song
|
|
430 @pos: playlist_pos */
|
|
431 void do_command(char *cmd, const char *current_file, int pos)
|
|
432 {
|
|
433 int length, rate, freq, nch;
|
|
434 char *str, *shstring = NULL, *temp, numbuf[16];
|
|
435 gboolean playing;
|
|
436 Formatter *formatter;
|
|
437
|
|
438 if (cmd && strlen(cmd) > 0)
|
|
439 {
|
|
440 formatter = xmms_formatter_new();
|
|
441 str = xmms_remote_get_playlist_title(sc_gp.xmms_session, pos);
|
|
442 if (str)
|
|
443 {
|
|
444 temp = escape_shell_chars(str);
|
|
445 xmms_formatter_associate(formatter, 's', temp);
|
|
446 xmms_formatter_associate(formatter, 'n', temp);
|
|
447 g_free(str);
|
|
448 g_free(temp);
|
|
449 }
|
|
450 else
|
|
451 {
|
|
452 xmms_formatter_associate(formatter, 's', "");
|
|
453 xmms_formatter_associate(formatter, 'n', "");
|
|
454 }
|
|
455
|
|
456 if (current_file)
|
|
457 {
|
|
458 temp = escape_shell_chars(current_file);
|
|
459 xmms_formatter_associate(formatter, 'f', temp);
|
|
460 g_free(temp);
|
|
461 }
|
|
462 else
|
|
463 xmms_formatter_associate(formatter, 'f', "");
|
|
464 sprintf(numbuf, "%02d", pos + 1);
|
|
465 xmms_formatter_associate(formatter, 't', numbuf);
|
|
466 length = xmms_remote_get_playlist_time(sc_gp.xmms_session, pos);
|
|
467 if (length != -1)
|
|
468 {
|
|
469 sprintf(numbuf, "%d", length);
|
|
470 xmms_formatter_associate(formatter, 'l', numbuf);
|
|
471 }
|
|
472 else
|
|
473 xmms_formatter_associate(formatter, 'l', "0");
|
|
474 xmms_remote_get_info(sc_gp.xmms_session, &rate, &freq, &nch);
|
|
475 sprintf(numbuf, "%d", rate);
|
|
476 xmms_formatter_associate(formatter, 'r', numbuf);
|
|
477 sprintf(numbuf, "%d", freq);
|
|
478 xmms_formatter_associate(formatter, 'F', numbuf);
|
|
479 sprintf(numbuf, "%d", nch);
|
|
480 xmms_formatter_associate(formatter, 'c', numbuf);
|
|
481 playing = xmms_remote_is_playing(sc_gp.xmms_session);
|
|
482 sprintf(numbuf, "%d", playing);
|
|
483 xmms_formatter_associate(formatter, 'p', numbuf);
|
|
484 shstring = xmms_formatter_format(formatter, cmd);
|
|
485 xmms_formatter_destroy(formatter);
|
|
486
|
|
487 if (shstring)
|
|
488 {
|
|
489 execute_command(shstring);
|
|
490 /* FIXME: This can possibly be freed too early */
|
|
491 g_free(shstring);
|
|
492 }
|
|
493 }
|
|
494 }
|
|
495
|
|
496
|
|
497 static int timeout_func(gpointer data)
|
|
498 {
|
|
499 int pos;
|
|
500 gboolean playing;
|
|
501 static char *previous_file = NULL;
|
|
502 static gboolean cmd_after_already_run = FALSE;
|
|
503 char *current_file;
|
|
504
|
|
505 GDK_THREADS_ENTER();
|
|
506
|
|
507 playing = xmms_remote_is_playing(sc_gp.xmms_session);
|
|
508 pos = xmms_remote_get_playlist_pos(sc_gp.xmms_session);
|
|
509 current_file = xmms_remote_get_playlist_file(sc_gp.xmms_session, pos);
|
|
510
|
|
511 if ((pos != previous_song ||
|
|
512 (!previous_file && current_file) ||
|
|
513 (previous_file && !current_file) ||
|
|
514 (previous_file && current_file &&
|
|
515 strcmp(previous_file, current_file))) &&
|
|
516 xmms_remote_get_output_time(sc_gp.xmms_session) > 0)
|
|
517 {
|
|
518 do_command(cmd_line, current_file, pos);
|
|
519 g_free(previous_file);
|
|
520 previous_file = g_strdup(current_file);
|
|
521 previous_song = pos;
|
|
522 cmd_after_already_run = FALSE;
|
|
523 }
|
|
524 if (!cmd_after_already_run &&
|
|
525 ((xmms_remote_get_playlist_time(sc_gp.xmms_session,pos) -
|
|
526 xmms_remote_get_output_time(sc_gp.xmms_session)) < 100))
|
|
527 {
|
|
528 do_command(cmd_line_after, current_file, pos);
|
|
529 cmd_after_already_run = TRUE;
|
|
530 }
|
|
531
|
|
532 if (playing)
|
|
533 {
|
|
534 int playlist_length = xmms_remote_get_playlist_length(sc_gp.xmms_session);
|
|
535 if (pos + 1 == playlist_length)
|
|
536 possible_pl_end = TRUE;
|
|
537 else
|
|
538 possible_pl_end = FALSE;
|
|
539 }
|
|
540 else if (possible_pl_end)
|
|
541 {
|
|
542 if (pos == 0)
|
|
543 do_command(cmd_line_end, current_file, pos);
|
|
544 possible_pl_end = FALSE;
|
|
545 g_free(previous_file);
|
|
546 previous_file = NULL;
|
|
547 }
|
|
548
|
|
549 g_free(current_file);
|
|
550 current_file = NULL;
|
|
551
|
|
552 GDK_THREADS_LEAVE();
|
|
553
|
|
554 return TRUE;
|
|
555 }
|