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