annotate src/alarm/alarm.c @ 1034:b0cb6f8d4339 trunk

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