2
* alarm-gconf.c -- GConf routines
4
* Copyright (C) 2007-2008 Johannes H. Jensen <joh@pseudoberries.com>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* Johannes H. Jensen <joh@pseudoberries.com>
25
#include <panel-applet-gconf.h>
27
#include "alarm-applet.h"
28
#include "alarm-gconf.h"
29
#include "edit-alarm.h"
33
* LabelType enum to GConf string value map
35
GConfEnumStringPair label_type_enum_map [] = {
36
{ LABEL_TYPE_TIME, "alarm-time" },
37
{ LABEL_TYPE_REMAIN, "remaining-time" },
46
alarm_applet_gconf_show_label_changed (GConfClient *client,
51
g_debug ("show_label_changed");
53
if (!entry->value || entry->value->type != GCONF_VALUE_BOOL)
56
applet->show_label = gconf_value_get_bool (entry->value);
58
g_object_set (applet->label, "visible", applet->show_label, NULL);
60
if (applet->preferences_dialog != NULL) {
61
pref_update_label_show (applet);
66
alarm_applet_gconf_label_type_changed (GConfClient *client,
71
g_debug ("label_type_changed");
75
if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
78
tmp = gconf_value_get_string (entry->value);
80
if (!gconf_string_to_enum (label_type_enum_map, tmp, (gint *)&(applet->label_type))) {
81
// No match, set to default
82
applet->label_type = DEF_LABEL_TYPE;
85
alarm_applet_label_update (applet);
88
if (applet->preferences_dialog != NULL) {
89
pref_update_label_type (applet);
95
* Triggered on global changes to our gconf preference dir.
96
* We do this because we're interested in the events where
97
* an alarm directory is either added or deleted externally.
99
* When this happens we update our list of alarms.
102
alarm_applet_gconf_global_change (GConfClient *client,
112
gboolean found = FALSE;
114
//g_debug ("GLOBAL_change: %s", entry->key);
117
* We're only interested in the first part of the key matching
118
* {applet_gconf_pref_dir}/{something}
120
* Here we extract {something}
122
dir = ALARM_GCONF_DIR;
123
len = strlen (entry->key);
124
str = g_string_new ("");
126
for (i = strlen(dir) + 1; i < len; i++) {
127
if (entry->key[i] == '/')
130
str = g_string_append_c (str, entry->key[i]);
133
//g_debug ("\tEXTRACTED: %s", str->str);
135
// Check if the key is valid
136
id = alarm_gconf_dir_get_id (str->str);
139
// Valid, probably an alarm which has been removed
140
g_debug ("GLOBAL change ON alarm #%d", id);
142
// Check if the alarm exists in our alarms list
143
for (l = applet->alarms; l != NULL; l = l->next) {
152
if (found && entry->value == NULL) {
154
g_debug ("\tDELETE alarm #%d %p", id, a);
156
/* If there's a settings dialog open for this
159
AlarmSettingsDialog *sdialog = g_hash_table_lookup (applet->edit_alarm_dialogs, (gconstpointer)a->id);
161
alarm_settings_dialog_close (sdialog);
167
alarm_applet_alarms_remove (applet, a);
170
if (applet->list_alarms_dialog)
171
list_alarms_update (applet);
173
} else if (!found && entry->value != NULL) {
178
a = alarm_new (ALARM_GCONF_DIR, id);
180
g_debug ("\tADD alarm #%d %p", id, a);
182
alarm_applet_alarms_add (applet, a);
185
if (applet->list_alarms_dialog)
186
list_alarms_update (applet);
190
g_string_free (str, TRUE);
202
alarm_applet_gconf_init (AlarmApplet *applet)
207
client = gconf_client_get_default ();
209
key = panel_applet_gconf_get_full_key (PANEL_APPLET (applet->parent), KEY_SHOW_LABEL);
210
applet->listeners [0] =
211
gconf_client_notify_add (
213
(GConfClientNotifyFunc) alarm_applet_gconf_show_label_changed,
217
key = panel_applet_gconf_get_full_key (PANEL_APPLET (applet->parent), KEY_LABEL_TYPE);
218
applet->listeners [1] =
219
gconf_client_notify_add (
221
(GConfClientNotifyFunc) alarm_applet_gconf_label_type_changed,
226
* Listen for changes to the alarms.
227
* We want to know when an alarm is added and removed.
229
applet->listeners [2] =
230
gconf_client_notify_add (
231
client, ALARM_GCONF_DIR,
232
(GConfClientNotifyFunc) alarm_applet_gconf_global_change,
237
/* Load gconf values into applet.
238
* We are very paranoid about gconf here.
239
* We can't rely on the schemas to exist, and so if we don't get any
240
* defaults from gconf, we set them manually.
241
* Not only that, but if some error occurs while setting the
242
* defaults in gconf, we already have them copied locally. */
244
alarm_applet_gconf_load (AlarmApplet *applet)
251
client = gconf_client_get_default ();
254
key = panel_applet_gconf_get_full_key (PANEL_APPLET (applet->parent), KEY_SHOW_LABEL);
255
value = gconf_client_get (client, key, NULL);
257
// Schema defaults not found
258
applet->show_label = DEF_SHOW_LABEL;
259
panel_applet_gconf_set_bool (applet->parent, KEY_SHOW_LABEL, DEF_SHOW_LABEL, NULL);
261
applet->show_label = gconf_value_get_bool (value);
262
gconf_value_free (value);
268
tmp = panel_applet_gconf_get_string (applet->parent, KEY_LABEL_TYPE, NULL);
269
if (tmp == NULL || !gconf_string_to_enum (label_type_enum_map, tmp, (gint *)&(applet->label_type))) {
270
// Schema defaults not found or unable to map
271
applet->label_type = DEF_LABEL_TYPE;
272
panel_applet_gconf_set_string (applet->parent, KEY_LABEL_TYPE, gconf_enum_to_string (label_type_enum_map, DEF_LABEL_TYPE), NULL);