annotate src/alarm/alarm.c @ 2181:bbb631ab78e9

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