Mercurial > audlegacy-plugins
annotate src/alarm/alarm.c @ 1034:b0cb6f8d4339 trunk
[svn] - lirc: works again with auddrct
author | giacomo |
---|---|
date | Sat, 12 May 2007 05:21:09 -0700 |
parents | 2346d918470d |
children | 711ec8d39ca6 |
rev | line source |
---|---|
121 | 1 /* |
2 * Copyright (C) Adam Feakin <adamf@snika.uklinux.net> | |
3 * | |
4 * modified by Daniel Stodden <stodden@in.tum.de> | |
5 * | |
6 * This program is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License | |
8 * as published by the Free Software Foundation; either version 2 | |
9 * of the License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 */ | |
20 | |
21 /* | |
22 * xmms-alarm.c - a XMMS plugin which allows you to set a time for it to | |
23 * start playing a playlist with the volume fading up and more things | |
24 * the next time I get bored | |
25 */ | |
26 | |
27 /* this file really should get split/cleaned up sometime ;) */ | |
28 #include "config.h" | |
29 | |
30 #if STDC_HEADERS | |
31 # include <stdlib.h> | |
32 #endif | |
33 | |
34 #include <time.h> | |
35 #if TM_IN_SYS_TIME | |
36 # include <sys/time.h> | |
37 #endif | |
38 | |
39 #include <string.h> | |
40 #include <stdio.h> | |
41 #include <audacious/plugin.h> | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
42 // #include <audacious/beepctrl.h> |
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
43 #include <audacious/audctrl.h> |
121 | 44 #include <audacious/configdb.h> |
45 #include <gdk/gdk.h> | |
46 #include <gtk/gtk.h> | |
47 #include <pthread.h> | |
48 #include <assert.h> | |
49 #include <math.h> | |
50 | |
51 #include "alarm.h" | |
52 #include "interface.h" | |
53 #include "callbacks.h" | |
54 | |
55 static pthread_t start_tid; /* thread id of alarm loop */ | |
56 static pthread_t stop_tid; /* thread id of stop loop */ | |
57 static pthread_mutex_t fader_lock = PTHREAD_MUTEX_INITIALIZER; | |
58 | |
59 static GeneralPlugin alarm_plugin; | |
60 | |
61 /* string tokens to allow loops and shorten code */ | |
62 static char day_cb[7][7] = {"sun_cb", "mon_cb", "tue_cb", | |
63 "wed_cb", "thu_cb", "fri_cb", "sat_cb"}; | |
64 | |
65 static char day_flags[7][10] = {"sun_flags", "mon_flags", "tue_flags", | |
66 "wed_flags", "thu_flags", "fri_flags", "sat_flags"}; | |
67 | |
68 static char day_h[7][6] = {"sun_h", "mon_h", "tue_h", | |
69 "wed_h", "thu_h", "fri_h", "sat_h"}; | |
70 | |
71 static char day_m[7][6] = {"sun_m", "mon_m", "tue_m", | |
72 "wed_m", "thu_m", "fri_m", "sat_m"}; | |
73 | |
74 static char day_def[7][8] = {"sun_def", "mon_def", "tue_def", | |
75 "wed_def", "thu_def", "fri_def", "sat_def"}; | |
76 | |
77 static struct | |
78 { | |
79 GtkSpinButton *alarm_h; | |
80 GtkSpinButton *alarm_m; | |
81 | |
82 GtkToggleButton *stop_on; | |
83 GtkSpinButton *stop_h; | |
84 GtkSpinButton *stop_m; | |
85 | |
86 GtkRange *volume; | |
87 GtkRange *quietvol; | |
88 | |
89 GtkSpinButton *fading; | |
90 | |
91 GtkEntry *cmdstr; | |
92 GtkToggleButton *cmd_on; | |
93 | |
94 GtkEntry *playlist; | |
95 | |
96 int default_hour; | |
97 int default_min; | |
98 | |
99 // array allows looping of days | |
100 alarmday day[7]; | |
101 | |
102 | |
103 GtkEntry *reminder; | |
104 GtkToggleButton *reminder_cb; | |
105 gchar *reminder_msg; | |
106 gboolean reminder_on; | |
107 } | |
108 alarm_conf; | |
109 | |
110 static gint alarm_h, alarm_m; | |
111 | |
112 static gboolean stop_on; | |
113 static gint stop_h, stop_m; | |
114 | |
115 static gint volume, quietvol; | |
116 | |
117 static gint fading; | |
118 | |
119 static gchar *cmdstr = NULL; | |
120 static gboolean cmd_on; | |
121 | |
122 static gchar *playlist = NULL; | |
123 | |
124 static GtkWidget *config_dialog = NULL; | |
125 static GtkWidget *alarm_dialog = NULL; | |
126 | |
127 static GtkWidget *lookup_widget(GtkWidget *w, const gchar *name) | |
128 { | |
129 GtkWidget *widget; | |
130 | |
131 widget = (GtkWidget*) gtk_object_get_data(GTK_OBJECT(w), | |
132 name); | |
133 g_return_val_if_fail(widget != NULL, NULL); | |
134 | |
135 return widget; | |
136 } | |
137 | |
138 static void dialog_destroyed(GtkWidget *dialog, gpointer data) | |
139 { | |
140 DEBUG("dialog destroyed\n"); | |
141 *(GtkObject**)data = NULL; | |
142 } | |
143 | |
144 static inline gboolean dialog_visible(GtkWidget *dialog) | |
145 { | |
146 return(((dialog != NULL) && GTK_WIDGET_VISIBLE(dialog))); | |
147 } | |
148 | |
149 /* | |
150 * tell the user about that bug | |
151 */ | |
152 static void alarm_warning(void) | |
153 { | |
154 | |
155 static GtkWidget *warning_dialog = NULL; | |
156 | |
157 if(dialog_visible(warning_dialog)) | |
158 return; | |
159 | |
160 warning_dialog = create_warning_dialog(); | |
161 | |
162 gtk_signal_connect(GTK_OBJECT(warning_dialog), "destroy", | |
163 GTK_SIGNAL_FUNC(dialog_destroyed), &warning_dialog); | |
164 | |
165 gtk_widget_show_all(warning_dialog); | |
166 | |
167 return; | |
168 } | |
169 | |
170 /* | |
171 * the callback function that is called when the save button is | |
172 * pressed saves configuration to ~/.bmp/alarmconfig | |
173 */ | |
174 void alarm_save(GtkButton *w, gpointer data) | |
175 { | |
176 int daynum = 0; // used to identify day number | |
177 ConfigDb *conf; | |
178 | |
179 DEBUG("alarm_save\n"); | |
180 | |
181 conf = bmp_cfg_db_open(); | |
182 | |
183 /* | |
184 * update the live values and write them out | |
185 */ | |
186 alarm_h = alarm_conf.default_hour = | |
187 gtk_spin_button_get_value_as_int(alarm_conf.alarm_h); | |
188 bmp_cfg_db_set_int(conf, "alarm", "alarm_h", alarm_h); | |
189 | |
190 alarm_m = alarm_conf.default_min = | |
191 gtk_spin_button_get_value_as_int(alarm_conf.alarm_m); | |
192 bmp_cfg_db_set_int(conf, "alarm", "alarm_m", alarm_m); | |
193 | |
194 | |
195 stop_h = | |
196 gtk_spin_button_get_value_as_int( alarm_conf.stop_h); | |
197 | |
198 stop_m = | |
199 gtk_spin_button_get_value_as_int(alarm_conf.stop_m); | |
200 | |
201 stop_on = | |
202 gtk_toggle_button_get_active(alarm_conf.stop_on); | |
203 | |
204 /* days of the week */ | |
205 for(; daynum < 7; daynum++) | |
206 { | |
207 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(alarm_conf.day[daynum].cb))) | |
208 alarm_conf.day[daynum].flags = 0; | |
209 else | |
210 alarm_conf.day[daynum].flags = ALARM_OFF; | |
211 | |
212 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(alarm_conf.day[daynum].cb_def))) | |
213 alarm_conf.day[daynum].flags |= ALARM_DEFAULT; | |
214 | |
215 alarm_conf.day[daynum].hour = | |
216 gtk_spin_button_get_value_as_int(alarm_conf.day[daynum].spin_hr); | |
217 alarm_conf.day[daynum].min = | |
218 gtk_spin_button_get_value_as_int(alarm_conf.day[daynum].spin_min); | |
219 | |
220 bmp_cfg_db_set_int(conf, "alarm", day_flags[daynum], alarm_conf.day[daynum].flags); | |
221 bmp_cfg_db_set_int(conf, "alarm", day_h[daynum], alarm_conf.day[daynum].hour); | |
222 bmp_cfg_db_set_int(conf, "alarm", day_m[daynum], alarm_conf.day[daynum].min); | |
223 } | |
224 | |
225 /* END: days of week */ | |
226 | |
227 volume = | |
228 gtk_range_get_adjustment(alarm_conf.volume)->value; | |
229 bmp_cfg_db_set_int(conf, "alarm", "volume", volume); | |
230 | |
231 quietvol = | |
232 gtk_range_get_adjustment(alarm_conf.quietvol)->value; | |
233 bmp_cfg_db_set_int(conf, "alarm", "quietvol", quietvol); | |
234 | |
235 fading = | |
236 gtk_spin_button_get_value_as_int(alarm_conf.fading); | |
237 //xmms_cfg_write_int(conf, "alarm", "fading", fading); | |
238 | |
239 /* lets check to see if we need to show the bug warning */ | |
240 if((stop_on == TRUE) && | |
241 ((((stop_h * 60) + stop_m) * 60) < (fading + 65))) | |
242 { | |
243 DEBUG("Displaying bug warning, stop %dh %dm, fade %d\n", | |
244 stop_h, stop_m, fading); | |
245 alarm_warning(); | |
246 } | |
247 else if((stop_on == TRUE) && (fading < 10)) | |
248 { | |
249 DEBUG("Displaying bug warning, stop %dh %dm, fade %d\n", | |
250 stop_h, stop_m, fading); | |
251 alarm_warning(); | |
252 } | |
253 else | |
254 { | |
255 /* write the new values */ | |
256 bmp_cfg_db_set_int(conf, "alarm", "stop_h", stop_h); | |
257 bmp_cfg_db_set_int(conf, "alarm", "stop_m", stop_m); | |
258 bmp_cfg_db_set_int(conf, "alarm", "fading", fading); | |
259 bmp_cfg_db_set_bool(conf, "alarm", "stop_on", stop_on); | |
260 } | |
261 | |
262 | |
263 g_free(cmdstr); | |
264 cmdstr = gtk_editable_get_chars(GTK_EDITABLE(alarm_conf.cmdstr), | |
265 0, -1); | |
266 bmp_cfg_db_set_string(conf, "alarm", "cmdstr", cmdstr); | |
267 | |
268 cmd_on = | |
269 gtk_toggle_button_get_active(alarm_conf.cmd_on); | |
270 bmp_cfg_db_set_bool(conf, "alarm", "cmd_on", cmd_on); | |
271 | |
272 g_free(playlist); | |
273 playlist = gtk_editable_get_chars(GTK_EDITABLE(alarm_conf.playlist), | |
274 0, -1); | |
275 bmp_cfg_db_set_string(conf, "alarm", "playlist", playlist); | |
276 | |
277 /* reminder */ | |
278 g_free(alarm_conf.reminder_msg); | |
279 alarm_conf.reminder_msg = gtk_editable_get_chars(GTK_EDITABLE(alarm_conf.reminder), | |
280 0, -1); | |
281 bmp_cfg_db_set_string(conf, "alarm", "reminder_msg", alarm_conf.reminder_msg); | |
282 | |
283 alarm_conf.reminder_on = | |
284 gtk_toggle_button_get_active(alarm_conf.reminder_cb); | |
285 bmp_cfg_db_set_bool(conf, "alarm", "reminder_on", alarm_conf.reminder_on); | |
286 | |
287 bmp_cfg_db_close(conf); | |
288 } | |
289 | |
290 /* | |
291 * read the current configuration from the file | |
292 */ | |
293 static void alarm_read_config() | |
294 { | |
295 int daynum = 0; // used for day number | |
296 ConfigDb *conf; | |
297 | |
298 DEBUG("alarm_read_config\n"); | |
299 | |
300 conf = bmp_cfg_db_open(); | |
301 | |
302 if(!bmp_cfg_db_get_int(conf, "alarm", "alarm_h", &alarm_h)) | |
303 alarm_h = DEFAULT_ALARM_HOUR; | |
304 if(!bmp_cfg_db_get_int(conf, "alarm", "alarm_m", &alarm_m)) | |
305 alarm_m = DEFAULT_ALARM_MIN; | |
306 | |
307 /* save them here too */ | |
308 alarm_conf.default_hour = alarm_h; | |
309 alarm_conf.default_min = alarm_m; | |
310 | |
311 if(!bmp_cfg_db_get_int( conf, "alarm", "stop_h", &stop_h)) | |
312 stop_h = DEFAULT_STOP_HOURS; | |
313 if(!bmp_cfg_db_get_int( conf, "alarm", "stop_m", &stop_m)) | |
314 stop_m = DEFAULT_STOP_MINS; | |
315 if(!bmp_cfg_db_get_bool(conf, "alarm", "stop_on", &stop_on)) | |
316 stop_on = TRUE; | |
317 | |
318 if(!bmp_cfg_db_get_int(conf, "alarm", "volume", &volume)) | |
319 volume = DEFAULT_VOLUME; | |
320 if(!bmp_cfg_db_get_int(conf, "alarm", "quietvol", &quietvol)) | |
321 quietvol = DEFAULT_QUIET_VOL; | |
322 | |
323 if(!bmp_cfg_db_get_int(conf, "alarm", "fading", &fading)) | |
324 fading = DEFAULT_FADING; | |
325 | |
326 if(!bmp_cfg_db_get_string(conf, "alarm", "cmdstr", &cmdstr)) | |
327 cmdstr = g_strdup(""); | |
328 if(!bmp_cfg_db_get_bool(conf, "alarm", "cmd_on", &cmd_on)) | |
329 cmd_on = FALSE; | |
330 | |
331 if(!bmp_cfg_db_get_string(conf, "alarm", "playlist", &playlist)) | |
332 playlist = g_strdup(""); | |
333 | |
334 if(!bmp_cfg_db_get_string(conf, "alarm", "reminder_msg", &alarm_conf.reminder_msg)) | |
335 alarm_conf.reminder_msg = g_strdup(""); | |
336 if(!bmp_cfg_db_get_bool(conf, "alarm", "reminder_on", &alarm_conf.reminder_on)) | |
337 alarm_conf.reminder_on = FALSE; | |
338 | |
339 /* day flags and times */ | |
340 for(; daynum < 7; daynum++) | |
341 { | |
342 /* read the flags */ | |
343 if(!bmp_cfg_db_get_int(conf, "alarm", day_flags[daynum], &alarm_conf.day[daynum].flags)) { | |
344 // only turn alarm off by default on a sunday | |
345 if(daynum != 0) | |
346 alarm_conf.day[daynum].flags = DEFAULT_FLAGS; | |
347 else | |
348 alarm_conf.day[daynum].flags = DEFAULT_FLAGS | ALARM_OFF; | |
349 } | |
350 | |
351 /* read the times */ | |
352 if(!bmp_cfg_db_get_int(conf, "alarm", day_h[daynum], &alarm_conf.day[daynum].hour)) | |
353 alarm_conf.day[daynum].hour = DEFAULT_ALARM_HOUR; | |
354 | |
355 if(!bmp_cfg_db_get_int(conf, "alarm", day_m[daynum], &alarm_conf.day[daynum].min)) | |
356 alarm_conf.day[daynum].min = DEFAULT_ALARM_MIN; | |
357 } | |
358 | |
359 DEBUG("END alarm_read_config\n"); | |
360 } | |
361 | |
362 /* | |
363 * display an about box | |
364 */ | |
365 static void alarm_about() | |
366 { | |
367 static GtkWidget *about_dialog = NULL; | |
368 | |
369 DEBUG("alarm_about\n"); | |
370 | |
371 if(dialog_visible(about_dialog)) | |
372 return; | |
373 | |
374 about_dialog = create_about_dialog(); | |
375 | |
376 gtk_signal_connect(GTK_OBJECT(about_dialog), "destroy", | |
377 GTK_SIGNAL_FUNC(dialog_destroyed), &about_dialog); | |
378 | |
379 gtk_widget_show_all(about_dialog); | |
380 | |
381 return; | |
382 } | |
383 | |
384 /* | |
385 * create a playlist file selection dialog | |
386 */ | |
387 static void alarm_playlist_browse(GtkButton *button, gpointer data) | |
388 { | |
389 GtkWidget *fs; | |
390 gchar *dirname, *path; | |
391 | |
392 dirname = g_dirname(playlist); | |
393 DEBUG("dirname = %s\n", dirname); | |
394 path = g_strdup_printf("%s/", dirname); | |
395 DEBUG("path = %s\n", path); | |
396 g_free(dirname); | |
397 | |
398 fs = create_playlist_fileselection(); | |
399 | |
400 gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), path); | |
401 g_free(path); | |
402 | |
403 gtk_widget_show_all(fs); | |
404 } | |
405 | |
406 /* | |
407 * save selected playlist to the corresponding text entry | |
408 */ | |
409 void alarm_store_playlistname(GtkButton *button, gpointer data) | |
410 { | |
411 GtkFileSelection *fs = GTK_FILE_SELECTION(data); | |
412 gchar *plist; | |
413 | |
414 DEBUG("alarm_store_playlistname\n"); | |
415 | |
132
26a5aef73955
[svn] Fixes compiler warnings that "Joker" was talking about in #audacious.
asheldon
parents:
129
diff
changeset
|
416 plist = g_strdup(gtk_file_selection_get_filename(fs)); |
121 | 417 |
418 gtk_entry_set_text(alarm_conf.playlist, plist); | |
132
26a5aef73955
[svn] Fixes compiler warnings that "Joker" was talking about in #audacious.
asheldon
parents:
129
diff
changeset
|
419 g_free(plist); |
121 | 420 } |
421 | |
422 /* | |
423 * displays the configuration window and opens the config file. | |
424 */ | |
425 static void alarm_configure(void) | |
426 { | |
427 int daynum = 0; // used to loop days | |
428 GtkWidget *w; | |
429 | |
430 DEBUG("alarm_configure\n"); | |
431 | |
432 /* | |
433 * dont want to show more than one config window | |
434 */ | |
435 if(dialog_visible(config_dialog)) | |
436 return; | |
437 | |
438 alarm_read_config(); | |
439 | |
440 /* | |
441 * Create the widgets | |
442 */ | |
443 config_dialog = create_config_dialog(); | |
444 | |
445 w = lookup_widget(config_dialog, "alarm_h_spin"); | |
446 alarm_conf.alarm_h = GTK_SPIN_BUTTON(w); | |
447 gtk_spin_button_set_value(alarm_conf.alarm_h, alarm_h); | |
448 | |
449 w = lookup_widget(config_dialog, "alarm_m_spin"); | |
450 alarm_conf.alarm_m = GTK_SPIN_BUTTON(w); | |
451 gtk_spin_button_set_value(alarm_conf.alarm_m, alarm_m); | |
452 | |
453 w = lookup_widget(config_dialog, "stop_h_spin"); | |
454 alarm_conf.stop_h = GTK_SPIN_BUTTON(w); | |
455 gtk_spin_button_set_value(alarm_conf.stop_h, stop_h); | |
456 | |
457 w = lookup_widget(config_dialog, "stop_m_spin"); | |
458 alarm_conf.stop_m = GTK_SPIN_BUTTON(w); | |
459 gtk_spin_button_set_value(alarm_conf.stop_m, stop_m); | |
460 | |
461 w = lookup_widget(config_dialog, "stop_checkb"); | |
462 alarm_conf.stop_on = GTK_TOGGLE_BUTTON(w); | |
463 gtk_toggle_button_set_active(alarm_conf.stop_on, stop_on); | |
464 | |
465 w = lookup_widget(config_dialog, "vol_scale"); | |
466 alarm_conf.volume = GTK_RANGE(w); | |
467 gtk_range_set_adjustment(alarm_conf.volume, | |
468 GTK_ADJUSTMENT(gtk_adjustment_new(volume, | |
469 0, | |
470 100, 1, | |
471 5, 0))); | |
472 | |
473 w = lookup_widget(config_dialog, "quiet_vol_scale"); | |
474 alarm_conf.quietvol = GTK_RANGE(w); | |
475 gtk_range_set_adjustment(alarm_conf.quietvol, | |
476 GTK_ADJUSTMENT(gtk_adjustment_new(quietvol, | |
477 0, | |
478 100, 1, | |
479 5, 0))); | |
480 | |
481 /* days of week */ | |
482 for(; daynum < 7; daynum++) | |
483 { | |
484 w = lookup_widget(config_dialog, day_cb[daynum]); | |
485 alarm_conf.day[daynum].cb = GTK_CHECK_BUTTON(w); | |
486 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(alarm_conf.day[daynum].cb), | |
487 !(alarm_conf.day[daynum].flags & ALARM_OFF)); | |
488 | |
489 w = lookup_widget(config_dialog, day_def[daynum]); | |
490 alarm_conf.day[daynum].cb_def = GTK_CHECK_BUTTON(w); | |
491 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(alarm_conf.day[daynum].cb_def), | |
492 alarm_conf.day[daynum].flags & ALARM_DEFAULT); | |
493 | |
494 | |
495 /* Changed to show default time instead of set time when ALARM_DEFAULT set, | |
496 * as suggested by Mark Brown | |
497 */ | |
498 /* w = lookup_widget(config_dialog, day_h[daynum]); | |
499 alarm_conf.day[daynum].spin_hr = GTK_SPIN_BUTTON(w); | |
500 gtk_spin_button_set_value(alarm_conf.day[daynum].spin_hr, alarm_conf.day[daynum].hour); | |
501 | |
502 w = lookup_widget(config_dialog, day_m[daynum]); | |
503 alarm_conf.day[daynum].spin_min = GTK_SPIN_BUTTON(w); | |
504 gtk_spin_button_set_value(alarm_conf.day[daynum].spin_min, alarm_conf.day[daynum].min); | |
505 */ | |
506 if(alarm_conf.day[daynum].flags & ALARM_DEFAULT) | |
507 { | |
508 w = lookup_widget(config_dialog, day_h[daynum]); | |
509 alarm_conf.day[daynum].spin_hr = GTK_SPIN_BUTTON(w); | |
510 gtk_spin_button_set_value(alarm_conf.day[daynum].spin_hr, alarm_conf.default_hour); | |
511 | |
512 w = lookup_widget(config_dialog, day_m[daynum]); | |
513 alarm_conf.day[daynum].spin_min = GTK_SPIN_BUTTON(w); | |
514 gtk_spin_button_set_value(alarm_conf.day[daynum].spin_min, alarm_conf.default_min); | |
515 | |
516 gtk_widget_set_sensitive((GtkWidget *)alarm_conf.day[daynum].spin_hr, FALSE); | |
517 gtk_widget_set_sensitive((GtkWidget *)alarm_conf.day[daynum].spin_min, FALSE); | |
518 } | |
519 else | |
520 { | |
521 w = lookup_widget(config_dialog, day_h[daynum]); | |
522 alarm_conf.day[daynum].spin_hr = GTK_SPIN_BUTTON(w); | |
523 gtk_spin_button_set_value(alarm_conf.day[daynum].spin_hr, alarm_conf.day[daynum].hour); | |
524 | |
525 w = lookup_widget(config_dialog, day_m[daynum]); | |
526 alarm_conf.day[daynum].spin_min = GTK_SPIN_BUTTON(w); | |
527 gtk_spin_button_set_value(alarm_conf.day[daynum].spin_min, alarm_conf.day[daynum].min); | |
528 | |
529 gtk_widget_set_sensitive((GtkWidget *)alarm_conf.day[daynum].spin_hr, TRUE); | |
530 gtk_widget_set_sensitive((GtkWidget *)alarm_conf.day[daynum].spin_min, TRUE); | |
531 } | |
532 } | |
533 | |
534 /* END: days of week */ | |
535 | |
536 w = lookup_widget(config_dialog,"fading_spin"); | |
537 alarm_conf.fading = GTK_SPIN_BUTTON(w); | |
538 gtk_spin_button_set_value(alarm_conf.fading, fading); | |
539 | |
540 w = lookup_widget(config_dialog, "cmd_entry"); | |
541 alarm_conf.cmdstr = GTK_ENTRY(w); | |
542 gtk_entry_set_text(alarm_conf.cmdstr, cmdstr); | |
543 | |
544 w = lookup_widget(config_dialog, "cmd_checkb"); | |
545 alarm_conf.cmd_on = GTK_TOGGLE_BUTTON(w); | |
546 gtk_toggle_button_set_active(alarm_conf.cmd_on, cmd_on); | |
547 | |
548 w = lookup_widget(config_dialog, "playlist"); | |
549 alarm_conf.playlist = GTK_ENTRY(w); | |
550 gtk_entry_set_text(alarm_conf.playlist, playlist); | |
551 | |
552 w = lookup_widget(config_dialog, "reminder_text"); | |
553 alarm_conf.reminder = GTK_ENTRY(w); | |
554 gtk_entry_set_text(alarm_conf.reminder, alarm_conf.reminder_msg); | |
555 | |
556 w = lookup_widget(config_dialog, "reminder_cb"); | |
557 alarm_conf.reminder_cb = GTK_TOGGLE_BUTTON(w); | |
558 gtk_toggle_button_set_active(alarm_conf.reminder_cb, alarm_conf.reminder_on); | |
559 | |
560 w = lookup_widget(config_dialog, "playlist_browse_button"); | |
561 gtk_signal_connect(GTK_OBJECT(w), "clicked", | |
562 GTK_SIGNAL_FUNC(alarm_playlist_browse), NULL); | |
563 | |
564 gtk_signal_connect(GTK_OBJECT(config_dialog), "destroy", | |
565 GTK_SIGNAL_FUNC(dialog_destroyed), &config_dialog); | |
566 | |
567 gtk_widget_show_all(config_dialog); | |
568 | |
569 DEBUG("END alarm_configure\n"); | |
570 } | |
571 | |
572 /* functions for greying out the time for days */ | |
573 void on_day_def_toggled(GtkToggleButton *togglebutton, gpointer user_data, int daynum) | |
574 { | |
575 GtkWidget *w; | |
576 | |
577 /* change the time shown too */ | |
578 w = lookup_widget(config_dialog, day_h[daynum]); | |
579 if(w == NULL) | |
580 return; | |
581 | |
582 if(gtk_toggle_button_get_active(togglebutton) == TRUE) | |
583 { | |
584 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), alarm_conf.default_hour); | |
585 gtk_widget_set_sensitive(w, FALSE); | |
586 } | |
587 else | |
588 { | |
589 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), alarm_conf.day[daynum].hour); | |
590 gtk_widget_set_sensitive(w, TRUE); | |
591 } | |
592 | |
593 w = lookup_widget(config_dialog, day_m[daynum]); | |
594 if(gtk_toggle_button_get_active(togglebutton) == TRUE) | |
595 { | |
596 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), alarm_conf.default_min); | |
597 gtk_widget_set_sensitive(w, FALSE); | |
598 } | |
599 else | |
600 { | |
601 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), alarm_conf.day[daynum].min); | |
602 gtk_widget_set_sensitive(w, TRUE); | |
603 } | |
604 } | |
605 | |
606 void on_sun_def_toggled(GtkToggleButton *togglebutton, gpointer user_data) | |
607 { | |
608 on_day_def_toggled(togglebutton, user_data, 0); | |
609 } | |
610 | |
611 void on_mon_def_toggled(GtkToggleButton *togglebutton, gpointer user_data) | |
612 { | |
613 on_day_def_toggled(togglebutton, user_data, 1); | |
614 } | |
615 | |
616 void on_tue_def_toggled(GtkToggleButton *togglebutton, gpointer user_data) | |
617 { | |
618 on_day_def_toggled(togglebutton, user_data, 2); | |
619 } | |
620 | |
621 void on_wed_def_toggled(GtkToggleButton *togglebutton, gpointer user_data) | |
622 { | |
623 on_day_def_toggled(togglebutton, user_data, 3); | |
624 } | |
625 | |
626 void on_thu_def_toggled(GtkToggleButton *togglebutton, gpointer user_data) | |
627 { | |
628 on_day_def_toggled(togglebutton, user_data, 4); | |
629 } | |
630 | |
631 void on_fri_def_toggled(GtkToggleButton *togglebutton, gpointer user_data) | |
632 { | |
633 on_day_def_toggled(togglebutton, user_data, 5); | |
634 } | |
635 | |
636 void on_sat_def_toggled(GtkToggleButton *togglebutton, gpointer user_data) | |
637 { | |
638 on_day_def_toggled(togglebutton, user_data, 6); | |
639 } | |
640 | |
641 /* END: greying things */ | |
642 | |
643 void alarm_current_volume(GtkButton *button, gpointer data) | |
644 { | |
645 gint vol; | |
646 GtkAdjustment *adj; | |
647 | |
648 DEBUG("on_current_button_clicked\n"); | |
649 | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
650 vol = audacious_remote_get_main_volume(alarm_plugin.dbus_proxy); |
121 | 651 |
652 adj = gtk_range_get_adjustment(alarm_conf.volume); | |
653 gtk_adjustment_set_value(adj, (gfloat)vol); | |
654 } | |
655 | |
656 GeneralPlugin *get_gplugin_info() | |
657 { | |
658 return &alarm_plugin; | |
659 } | |
660 | |
661 /* | |
662 * a thread safe sleeping function - | |
663 * and it even works in solaris (I think) | |
664 */ | |
665 static void threadsleep(float x) | |
666 { | |
667 DEBUG("threadsleep: waiting %f seconds\n", x); | |
668 | |
122
96fc1ef32c99
[svn] - push fixes from p4://depot/svn-audacious-plugins-devel/virt-branches/audalarm/src
nenolod
parents:
121
diff
changeset
|
669 g_usleep((int) ((float) x * (float) 1000000.0)); |
121 | 670 |
671 return; | |
672 } | |
673 | |
674 static inline pthread_t alarm_thread_create(void *(*start_routine)(void *), void *args, unsigned int detach) | |
675 { | |
676 pthread_t tid; | |
677 pthread_attr_t attr; | |
678 | |
679 pthread_attr_init(&attr); | |
680 | |
681 if(detach != 0) | |
682 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
683 | |
684 pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); | |
685 pthread_attr_setschedpolicy(&attr, SCHED_OTHER); | |
686 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); | |
687 | |
688 pthread_create(&tid, &attr, start_routine, args); | |
689 | |
690 return(tid); | |
691 } | |
692 | |
693 static void *alarm_fade(void *arg) | |
694 { | |
695 fader *vols = (fader *)arg; | |
696 guint i; | |
697 gint inc, diff, adiff; | |
698 | |
699 /* lock */ | |
700 pthread_mutex_lock(&fader_lock); | |
701 | |
702 /* slide volume */ | |
703 /* the Kaspar Giger way of fading, check the current mixer volume and | |
704 * increment from there so that if you have some other app lowering the | |
705 * volume at the same time xmms-alarm will not ignore it. If you have some | |
706 * other app increasing the volume, then it could get louder that you expect | |
707 * though - because the loop does not recalculate the difference each time. | |
708 */ | |
709 | |
710 /* difference between the 2 volumes */ | |
711 diff = vols->end - vols->start; | |
712 adiff = abs(diff); | |
713 | |
714 /* Are we going up or down? */ | |
715 if(diff < 0) | |
716 inc = -1; | |
717 else | |
718 inc = 1; | |
719 | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
720 audacious_remote_set_main_volume(alarm_plugin.dbus_proxy, (gint)vols->start); |
121 | 721 //for(i=0;i<(vols->end - vols->start);i++) |
722 for(i=0;i<adiff;i++) | |
723 { | |
724 //threadsleep((gfloat)fading / (vols->end - vols->start)); | |
725 threadsleep((gfloat)fading / (gfloat)adiff); | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
726 audacious_remote_set_main_volume(alarm_plugin.dbus_proxy, |
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
727 (gint)(audacious_remote_get_main_volume(alarm_plugin.dbus_proxy) + inc)); |
121 | 728 } |
729 /* Setting the volume to the end volume sort of defeats the point if having | |
730 * the code in there to allow other apps to control volume too :) | |
731 */ | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
732 //audacious_remote_set_main_volume(alarm_plugin.dbus_proxy, (gint)vols->end); |
121 | 733 |
734 /* and */ | |
735 pthread_mutex_unlock(&fader_lock); | |
736 | |
737 DEBUG("volume = %f%%\n", (gdouble)vols->end); | |
738 return(0); | |
739 } | |
740 | |
741 static void *alarm_stop_thread( void *args ) | |
742 { | |
743 gint currvol; | |
744 fader fade_vols; | |
745 pthread_t f_tid; | |
746 | |
747 DEBUG("alarm_stop_thread\n"); | |
748 | |
749 | |
750 /* sleep for however long we are meant to be sleeping for until | |
751 * its time to shut up | |
752 */ | |
753 threadsleep(((stop_h * 60) + stop_m) * 60); | |
754 | |
755 DEBUG("alarm_stop triggered\n"); | |
756 | |
757 if (dialog_visible(alarm_dialog)) | |
758 gtk_widget_destroy(alarm_dialog); | |
759 | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
760 currvol = audacious_remote_get_main_volume(alarm_plugin.dbus_proxy), |
121 | 761 |
762 /* fade back to zero */ | |
763 fade_vols.start = currvol; | |
764 fade_vols.end = 0; | |
765 | |
766 /* The fader thread locks the fader_mutex now */ | |
767 f_tid = alarm_thread_create(alarm_fade, &fade_vols, 0); | |
768 | |
769 pthread_join(f_tid, NULL); | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
770 audacious_remote_stop(alarm_plugin.dbus_proxy); |
121 | 771 |
772 /* might as well set the volume to something higher than zero so we | |
773 * dont confuse the poor people who just woke up and cant work out why | |
774 * theres no music playing when they press the little play button :) | |
775 */ | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
776 audacious_remote_set_main_volume(alarm_plugin.dbus_proxy, currvol); |
121 | 777 |
778 DEBUG("alarm_stop done\n"); | |
779 return(NULL); | |
780 } | |
781 | |
782 void alarm_stop_cancel(GtkButton *w, gpointer data) | |
783 { | |
784 DEBUG("alarm_stop_cancel\n"); | |
785 pthread_cancel(stop_tid); | |
786 } | |
787 | |
788 /* the main alarm thread */ | |
789 static void *alarm_start_thread(void *args) | |
790 { | |
791 struct tm *currtime; | |
792 time_t timenow; | |
793 unsigned int play_start = 0; | |
794 guint today; | |
795 | |
796 /* give it time to set start_tid to something */ | |
797 threadsleep(1); | |
798 | |
799 while(start_tid != 0) | |
800 { | |
801 /* sit around and wait for the faders to not be doing anything */ | |
802 DEBUG("Waiting for fader to be unlocked.."); | |
803 pthread_mutex_lock(&fader_lock); | |
804 DEBUG("Ok\n"); | |
805 pthread_mutex_unlock(&fader_lock); | |
806 | |
807 DEBUG("Getting time\n"); | |
808 timenow = time(NULL); | |
809 currtime = localtime(&timenow); | |
810 today = currtime->tm_wday; | |
811 DEBUG("Today is %d\n", today); | |
812 | |
813 /* see if its time to do something */ | |
814 DEBUG("Checking Day\n"); | |
815 | |
816 /* Had to put something here so I put the hour string. | |
817 ** Its only debug stuff anyway */ | |
818 DEBUG(day_h[today]); | |
819 | |
820 if(alarm_conf.day[today].flags & ALARM_OFF) | |
821 { | |
822 threadsleep(8.5); | |
823 continue; | |
824 } | |
825 else | |
826 { | |
827 /* set the alarm_h and alarm_m for today, if not default */ | |
828 if(!(alarm_conf.day[today].flags & ALARM_DEFAULT)) | |
829 { | |
830 alarm_h = alarm_conf.day[today].hour; | |
831 alarm_m = alarm_conf.day[today].min; | |
832 } | |
833 else | |
834 { | |
835 alarm_h = alarm_conf.default_hour; | |
836 alarm_m = alarm_conf.default_min; | |
837 } | |
838 } | |
839 | |
840 DEBUG("Alarm time is %d:%d (def: %d:%d)\n", alarm_h, alarm_m, | |
841 alarm_conf.default_hour, alarm_conf.default_min); | |
842 | |
843 DEBUG("Checking time (%d:%d)\n", currtime->tm_hour, currtime->tm_min); | |
844 if((currtime->tm_hour != alarm_h) || (currtime->tm_min != alarm_m)) | |
845 { | |
846 threadsleep(8.5); | |
847 continue; | |
848 } | |
849 | |
850 if(cmd_on == TRUE) | |
851 { | |
852 DEBUG("Executing %s, cmd_on is true\n", cmdstr); | |
963 | 853 if(system(cmdstr) == -1) |
854 { | |
855 DEBUG("Executing %s failed\n",cmdstr); | |
856 } | |
121 | 857 } |
858 | |
859 DEBUG("strcmp playlist, playlist is [%s]\n", playlist); | |
860 if(strcmp(playlist, "")) | |
861 { | |
862 DEBUG("playlist is not blank, aparently\n"); | |
863 /* Is this a url? */ | |
864 /* Thanks Thomer */ | |
628
8e1c653cd605
[svn] - patch from Mark Glines to polish up https:// support.
nenolod
parents:
132
diff
changeset
|
865 if(!strncmp(playlist, "http://", 7) || !strncmp(playlist, "https://", 8)) |
121 | 866 { |
867 /* Yes */ | |
868 DEBUG("This looks like a URL to me...\n"); | |
869 /* If I just add the url and it turns out to be a playlist then xmms | |
870 * will sort that out.. It should also work for radio streams, I guess | |
871 */ | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
872 audacious_remote_playlist_clear(alarm_plugin.dbus_proxy); |
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
873 audacious_remote_playlist_add_url_string(alarm_plugin.dbus_proxy, playlist); |
121 | 874 } |
875 else | |
876 { | |
877 /* No, its probably a local file */ | |
878 /* Does that mean we want to go through it and add files to the list | |
879 * properly, or just use this semi-hack to let xmms do the playlist | |
880 * parsing? | |
881 */ | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
882 audacious_remote_playlist_clear(alarm_plugin.dbus_proxy); |
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
883 audacious_remote_playlist(alarm_plugin.dbus_proxy, |
121 | 884 &playlist, 1, TRUE); |
885 } | |
886 } | |
887 | |
888 if(fading) | |
889 { | |
890 fader fade_vols; | |
891 | |
892 DEBUG("Fading is true\n"); | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
893 audacious_remote_set_main_volume(alarm_plugin.dbus_proxy, quietvol); |
121 | 894 |
895 /* start playing */ | |
896 play_start = time(NULL); | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
897 audacious_remote_play(alarm_plugin.dbus_proxy); |
121 | 898 |
899 /* fade volume */ | |
900 fade_vols.start = quietvol; | |
901 fade_vols.end = volume; | |
902 | |
903 //alarm_fade(quietvol, volume); | |
904 alarm_thread_create(alarm_fade, &fade_vols, 0); | |
905 } | |
906 else | |
907 { | |
908 /* no fading */ | |
909 | |
910 /* set volume */ | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
911 audacious_remote_set_main_volume(alarm_plugin.dbus_proxy, volume); |
121 | 912 |
913 /* start playing */ | |
914 play_start = time(NULL); | |
1005
2346d918470d
[svn] Fixed rootvis' config to only declare stuff once; modified alarm.c to use dbus and made appropriate changes to the build system.
magma
parents:
963
diff
changeset
|
915 audacious_remote_play(alarm_plugin.dbus_proxy); |
121 | 916 } |
917 | |
918 if(alarm_conf.reminder_on == TRUE) | |
919 { | |
920 GtkWidget *reminder_dialog; | |
921 DEBUG("Showing reminder '%s'\n", alarm_conf.reminder_msg); | |
922 | |
923 GDK_THREADS_ENTER(); | |
132
26a5aef73955
[svn] Fixes compiler warnings that "Joker" was talking about in #audacious.
asheldon
parents:
129
diff
changeset
|
924 reminder_dialog = (GtkWidget*) create_reminder_dialog(alarm_conf.reminder_msg); |
121 | 925 gtk_signal_connect(GTK_OBJECT(reminder_dialog), "destroy", |
926 GTK_SIGNAL_FUNC(dialog_destroyed), &reminder_dialog); | |
927 gtk_widget_show_all(reminder_dialog); | |
928 GDK_THREADS_LEAVE(); | |
929 } | |
930 | |
931 /* bring up the wakeup call dialog if stop_on is set TRUE, this | |
932 * has been moved to after making xmms play so that it doesnt | |
933 * get in the way for people with manual window placement turned on | |
934 * | |
935 * this means that the dialog doesnt get shown until the volume has | |
936 * finished fading though !, so thats something else to fix | |
937 */ | |
938 if(stop_on == TRUE) | |
939 { | |
940 /* ok, so when we want to open dialogs in threaded programs | |
941 * we use this do we? | |
942 * anyone? | |
943 */ | |
944 GDK_THREADS_ENTER(); | |
945 { | |
946 DEBUG("stop_on is true\n"); | |
947 alarm_dialog = create_alarm_dialog(); | |
948 DEBUG("created alarm dialog, %p\n", alarm_dialog); | |
949 | |
950 gtk_signal_connect(GTK_OBJECT(alarm_dialog), "destroy", | |
951 GTK_SIGNAL_FUNC(dialog_destroyed), &alarm_dialog); | |
952 DEBUG("attached destroy signal to alarm dialog, %p\n", alarm_dialog); | |
953 gtk_widget_show_all(alarm_dialog); | |
954 DEBUG("dialog now showing\n"); | |
955 | |
956 DEBUG("now starting stop thread\n"); | |
957 stop_tid = alarm_thread_create(alarm_stop_thread, NULL, 0); | |
958 DEBUG("Created wakeup dialog and started stop thread(%d)\n", (int)stop_tid); | |
959 | |
960 } | |
961 GDK_THREADS_LEAVE(); | |
962 | |
963 /* now wait for the stop thread */ | |
964 DEBUG("Waiting for stop to stop.... (%d)", (int)stop_tid); | |
965 pthread_join(stop_tid, NULL); | |
966 /* loop until we are out of the starting minute */ | |
967 while(time(NULL) < (play_start + 61)) | |
968 { | |
969 DEBUG("Waiting until out of starting minute\n"); | |
970 threadsleep(5.0); | |
971 } | |
972 DEBUG("OK\n"); | |
973 } | |
974 /* loop until we are out of the starting minute */ | |
975 while(time(NULL) < (play_start + 61)) | |
976 { | |
977 threadsleep(5.0); | |
978 } | |
979 threadsleep(fading); | |
980 } | |
981 | |
982 DEBUG("Main thread has gone...\n"); | |
983 return NULL; | |
984 } | |
985 | |
986 /* | |
987 * initialization | |
988 * opens the config file and reads the value, creates a new | |
989 * config in memory if the file doesnt exist and sets default vals | |
990 */ | |
991 static void alarm_init() | |
992 { | |
993 DEBUG("alarm_init\n"); | |
994 | |
995 alarm_read_config(); | |
996 | |
997 /* start the main thread running */ | |
998 start_tid = alarm_thread_create(alarm_start_thread, NULL, 1); | |
999 } | |
1000 | |
1001 /* | |
1002 * kill the main thread | |
1003 */ | |
1004 static void alarm_cleanup() | |
1005 { | |
1006 DEBUG("alarm_cleanup\n"); | |
1007 | |
129
dae03298753f
[svn] - don't cancel threads that don't exist (TODO: GThreadify)
nenolod
parents:
122
diff
changeset
|
1008 if (start_tid) |
dae03298753f
[svn] - don't cancel threads that don't exist (TODO: GThreadify)
nenolod
parents:
122
diff
changeset
|
1009 pthread_cancel(start_tid); |
121 | 1010 start_tid = 0; |
1011 if(stop_tid) | |
1012 pthread_cancel(stop_tid); | |
129
dae03298753f
[svn] - don't cancel threads that don't exist (TODO: GThreadify)
nenolod
parents:
122
diff
changeset
|
1013 stop_tid = 0; |
121 | 1014 } |
1015 | |
1016 /* | |
1017 * for xmms to get the function names | |
1018 */ | |
1019 static GeneralPlugin alarm_plugin = | |
1020 { | |
1021 NULL, | |
1022 NULL, | |
1023 -1, | |
1024 "Alarm "VERSION, | |
1025 alarm_init, | |
1026 alarm_about, | |
1027 alarm_configure, | |
1028 alarm_cleanup, | |
1029 }; | |
1030 | |
1031 /* | |
1032 * vi:ai:expandtab:ts=2 sts=2 shiftwidth=2:nowrap: | |
1033 */ |