File: | capplet/cafe-notification-properties.c |
Warning: | line 85, column 2 Value stored to 'valid' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
2 | * |
3 | * Copyright (C) 2007 Jonh Wendell <wendell@bani.com.br> |
4 | * Copyright (C) 2011 Perberos <perberos@gmail.com> |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2, or (at your option) |
9 | * any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
19 | * 02110-1301, USA. |
20 | */ |
21 | |
22 | #include "config.h" |
23 | |
24 | #include <glib/gi18n.h> |
25 | #include <glib.h> |
26 | #include <gmodule.h> |
27 | #include <ctk/ctk.h> |
28 | #include <cdk/cdk.h> |
29 | #include <gio/gio.h> |
30 | #include <string.h> |
31 | #include <libnotify/notify.h> |
32 | |
33 | #include "stack.h" |
34 | |
35 | #define GSETTINGS_SCHEMA"org.cafe.NotificationDaemon" "org.cafe.NotificationDaemon" |
36 | #define GSETTINGS_KEY_THEME"theme" "theme" |
37 | #define GSETTINGS_KEY_POPUP_LOCATION"popup-location" "popup-location" |
38 | #define GSETTINGS_KEY_MONITOR_NUMBER"monitor-number" "monitor-number" |
39 | #define GSETTINGS_KEY_USE_ACTIVE_MONITOR"use-active-monitor" "use-active-monitor" |
40 | #define GSETTINGS_KEY_DO_NOT_DISTURB"do-not-disturb" "do-not-disturb" |
41 | |
42 | typedef struct { |
43 | GSettings* gsettings; |
44 | |
45 | CtkWidget* dialog; |
46 | CtkWidget* position_combo; |
47 | CtkWidget* monitor_combo; |
48 | CtkWidget* theme_combo; |
49 | CtkWidget* preview_button; |
50 | CtkWidget* active_checkbox; |
51 | CtkWidget* dnd_checkbox; |
52 | CtkWidget* monitor_label; |
53 | |
54 | NotifyNotification* preview; |
55 | } NotificationAppletDialog; |
56 | |
57 | enum { |
58 | NOTIFY_POSITION_LABEL, |
59 | NOTIFY_POSITION_NAME, |
60 | N_COLUMNS_POSITION |
61 | }; |
62 | |
63 | enum { |
64 | NOTIFY_MONITOR_NUMBER, |
65 | N_COLUMNS_MONITOR |
66 | }; |
67 | |
68 | enum { |
69 | NOTIFY_THEME_LABEL, |
70 | NOTIFY_THEME_NAME, |
71 | NOTIFY_THEME_FILENAME, |
72 | N_COLUMNS_THEME |
73 | }; |
74 | |
75 | static void notification_properties_position_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) |
76 | { |
77 | CtkTreeModel* model; |
78 | CtkTreeIter iter; |
79 | const char* location; |
80 | gboolean valid; |
81 | |
82 | location = g_settings_get_string(dialog->gsettings, key); |
83 | |
84 | model = ctk_combo_box_get_model(CTK_COMBO_BOX(dialog->position_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->position_combo)), ((ctk_combo_box_get_type () ))))))); |
85 | valid = ctk_tree_model_get_iter_first(model, &iter); |
Value stored to 'valid' is never read | |
86 | |
87 | for (valid = ctk_tree_model_get_iter_first(model, &iter); valid; valid = ctk_tree_model_iter_next(model, &iter)) |
88 | { |
89 | gchar* key; |
90 | |
91 | ctk_tree_model_get(model, &iter, NOTIFY_POSITION_NAME, &key, -1); |
92 | |
93 | if (g_str_equal(key, location)(strcmp ((const char *) (key), (const char *) (location)) == 0 )) |
94 | { |
95 | ctk_combo_box_set_active_iter(CTK_COMBO_BOX(dialog->position_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->position_combo)), ((ctk_combo_box_get_type () )))))), &iter); |
96 | g_free(key); |
97 | break; |
98 | } |
99 | |
100 | g_free(key); |
101 | } |
102 | } |
103 | |
104 | static void notification_properties_monitor_changed(CtkComboBox* widget, NotificationAppletDialog* dialog) |
105 | { |
106 | gint monitor; |
107 | CtkTreeIter iter; |
108 | |
109 | CtkTreeModel *model = ctk_combo_box_get_model(CTK_COMBO_BOX(dialog->monitor_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->monitor_combo)), ((ctk_combo_box_get_type ()) )))))); |
110 | |
111 | if (!ctk_combo_box_get_active_iter(CTK_COMBO_BOX(dialog->monitor_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->monitor_combo)), ((ctk_combo_box_get_type ()) ))))), &iter)) |
112 | { |
113 | return; |
114 | } |
115 | |
116 | ctk_tree_model_get(model, &iter, NOTIFY_MONITOR_NUMBER, &monitor, -1); |
117 | |
118 | g_settings_set_int(dialog->gsettings, GSETTINGS_KEY_MONITOR_NUMBER"monitor-number", monitor); |
119 | } |
120 | |
121 | static void notification_properties_monitor_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) |
122 | { |
123 | CtkTreeModel* model; |
124 | CtkTreeIter iter; |
125 | gint monitor_number; |
126 | gint monitor_number_at_iter; |
127 | gboolean valid; |
128 | |
129 | model = ctk_combo_box_get_model(CTK_COMBO_BOX(dialog->monitor_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->monitor_combo)), ((ctk_combo_box_get_type ()) )))))); |
130 | |
131 | monitor_number = g_settings_get_int(dialog->gsettings, GSETTINGS_KEY_MONITOR_NUMBER"monitor-number"); |
132 | |
133 | for (valid = ctk_tree_model_get_iter_first(model, &iter); valid; valid = ctk_tree_model_iter_next(model, &iter)) |
134 | { |
135 | ctk_tree_model_get(model, &iter, NOTIFY_MONITOR_NUMBER, &monitor_number_at_iter, -1); |
136 | |
137 | if (monitor_number_at_iter == monitor_number) |
138 | { |
139 | ctk_combo_box_set_active_iter(CTK_COMBO_BOX(dialog->monitor_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->monitor_combo)), ((ctk_combo_box_get_type ()) ))))), &iter); |
140 | break; |
141 | } |
142 | } |
143 | } |
144 | |
145 | static void notification_properties_location_changed(CtkComboBox* widget, NotificationAppletDialog* dialog) |
146 | { |
147 | char* location; |
148 | CtkTreeIter iter; |
149 | |
150 | CtkTreeModel* model = ctk_combo_box_get_model(CTK_COMBO_BOX(dialog->position_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->position_combo)), ((ctk_combo_box_get_type () ))))))); |
151 | |
152 | if (!ctk_combo_box_get_active_iter(CTK_COMBO_BOX(dialog->position_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->position_combo)), ((ctk_combo_box_get_type () )))))), &iter)) |
153 | { |
154 | return; |
155 | } |
156 | |
157 | ctk_tree_model_get(model, &iter, NOTIFY_POSITION_NAME, &location, -1); |
158 | |
159 | g_settings_set_string (dialog->gsettings, GSETTINGS_KEY_POPUP_LOCATION"popup-location", location); |
160 | g_free(location); |
161 | } |
162 | |
163 | static void notification_properties_dialog_setup_positions(NotificationAppletDialog* dialog) |
164 | { |
165 | char* location; |
166 | gboolean valid; |
167 | CtkTreeModel* model; |
168 | CtkTreeIter iter; |
169 | |
170 | g_signal_connect(dialog->gsettings, "changed::" GSETTINGS_KEY_POPUP_LOCATION, G_CALLBACK (notification_properties_position_notify), dialog)g_signal_connect_data ((dialog->gsettings), ("changed::" "popup-location" ), (((GCallback) (notification_properties_position_notify))), (dialog), ((void*)0), (GConnectFlags) 0); |
171 | g_signal_connect(dialog->position_combo, "changed", G_CALLBACK(notification_properties_location_changed), dialog)g_signal_connect_data ((dialog->position_combo), ("changed" ), (((GCallback) (notification_properties_location_changed))) , (dialog), ((void*)0), (GConnectFlags) 0); |
172 | |
173 | model = ctk_combo_box_get_model(CTK_COMBO_BOX(dialog->position_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->position_combo)), ((ctk_combo_box_get_type () ))))))); |
174 | location = g_settings_get_string(dialog->gsettings, GSETTINGS_KEY_POPUP_LOCATION"popup-location"); |
175 | |
176 | for (valid = ctk_tree_model_get_iter_first(model, &iter); valid; valid = ctk_tree_model_iter_next(model, &iter)) |
177 | { |
178 | gchar* key; |
179 | |
180 | ctk_tree_model_get(model, &iter, NOTIFY_POSITION_NAME, &key, -1); |
181 | |
182 | if (g_str_equal(key, location)(strcmp ((const char *) (key), (const char *) (location)) == 0 )) |
183 | { |
184 | ctk_combo_box_set_active_iter(CTK_COMBO_BOX(dialog->position_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->position_combo)), ((ctk_combo_box_get_type () )))))), &iter); |
185 | g_free(key); |
186 | break; |
187 | } |
188 | |
189 | g_free(key); |
190 | } |
191 | |
192 | g_free(location); |
193 | } |
194 | |
195 | static void notification_properties_dialog_setup_monitors(NotificationAppletDialog* dialog) |
196 | { |
197 | CtkListStore *store; |
198 | CdkDisplay *display; |
199 | CdkScreen *screen; |
200 | CtkTreeIter iter; |
201 | gint num_monitors; |
202 | gint cur_monitor_number; |
203 | gint cur_monitor_number_at_iter; |
204 | gboolean valid; |
205 | |
206 | // Assumes the user has only one display. |
207 | // TODO: add support for multiple displays. |
208 | display = cdk_display_get_default(); |
209 | g_assert(display != NULL)do { if (display != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 209, ((const char*) (__func__)), "display != NULL"); } while (0); |
210 | |
211 | // Assumes the user has only one screen. |
212 | // TODO: add support for mulitple screens. |
213 | screen = cdk_display_get_default_screen(display); |
214 | g_assert(screen != NULL)do { if (screen != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 214, ((const char*) (__func__)), "screen != NULL"); } while (0); |
215 | |
216 | num_monitors = cdk_display_get_n_monitors(display); |
217 | g_assert(num_monitors >= 1)do { if (num_monitors >= 1) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 217, ((const char*) (__func__)), "num_monitors >= 1"); } while (0); |
218 | |
219 | store = ctk_list_store_new(N_COLUMNS_MONITOR, G_TYPE_INT((GType) ((6) << (2)))); |
220 | |
221 | gint i; |
222 | for (i = 0; i < num_monitors; i++) |
223 | { |
224 | ctk_list_store_append(store, &iter); |
225 | ctk_list_store_set(store, &iter, NOTIFY_MONITOR_NUMBER, i, -1); |
226 | } |
227 | |
228 | ctk_combo_box_set_model(CTK_COMBO_BOX (dialog->monitor_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->monitor_combo)), ((ctk_combo_box_get_type ()) ))))), CTK_TREE_MODEL (store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ()))))))); |
229 | |
230 | g_signal_connect(dialog->gsettings, "changed::" GSETTINGS_KEY_MONITOR_NUMBER, G_CALLBACK (notification_properties_monitor_notify), dialog)g_signal_connect_data ((dialog->gsettings), ("changed::" "monitor-number" ), (((GCallback) (notification_properties_monitor_notify))), ( dialog), ((void*)0), (GConnectFlags) 0); |
231 | cur_monitor_number = g_settings_get_int(dialog->gsettings, GSETTINGS_KEY_MONITOR_NUMBER"monitor-number"); |
232 | |
233 | for (valid = ctk_tree_model_get_iter_first(CTK_TREE_MODEL (store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ())))))), &iter); valid; valid = ctk_tree_model_iter_next(CTK_TREE_MODEL (store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ())))))), &iter)) |
234 | { |
235 | ctk_tree_model_get(CTK_TREE_MODEL (store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ())))))), &iter, NOTIFY_MONITOR_NUMBER, &cur_monitor_number_at_iter, -1); |
236 | |
237 | if (cur_monitor_number_at_iter == cur_monitor_number) |
238 | { |
239 | ctk_combo_box_set_active_iter(CTK_COMBO_BOX(dialog->monitor_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->monitor_combo)), ((ctk_combo_box_get_type ()) ))))), &iter); |
240 | break; |
241 | } |
242 | } |
243 | |
244 | g_object_unref(store); |
245 | |
246 | g_signal_connect(dialog->monitor_combo, "changed", G_CALLBACK(notification_properties_monitor_changed), dialog)g_signal_connect_data ((dialog->monitor_combo), ("changed" ), (((GCallback) (notification_properties_monitor_changed))), (dialog), ((void*)0), (GConnectFlags) 0); |
247 | } |
248 | |
249 | static void notification_properties_theme_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) |
250 | { |
251 | const char* theme = g_settings_get_string(dialog->gsettings, key); |
252 | |
253 | CtkTreeModel* model = ctk_combo_box_get_model(CTK_COMBO_BOX(dialog->theme_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->theme_combo)), ((ctk_combo_box_get_type ()))) )))); |
254 | |
255 | CtkTreeIter iter; |
256 | gboolean valid; |
257 | |
258 | for (valid = ctk_tree_model_get_iter_first(model, &iter); valid; valid = ctk_tree_model_iter_next(model, &iter)) |
259 | { |
260 | gchar* theme_name; |
261 | |
262 | ctk_tree_model_get(model, &iter, NOTIFY_THEME_NAME, &theme_name, -1); |
263 | |
264 | if (g_str_equal(theme_name, theme)(strcmp ((const char *) (theme_name), (const char *) (theme)) == 0)) |
265 | { |
266 | ctk_combo_box_set_active_iter(CTK_COMBO_BOX(dialog->theme_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->theme_combo)), ((ctk_combo_box_get_type ()))) ))), &iter); |
267 | g_free(theme_name); |
268 | break; |
269 | } |
270 | |
271 | g_free(theme_name); |
272 | } |
273 | } |
274 | |
275 | static void notification_properties_theme_changed(CtkComboBox* widget, NotificationAppletDialog* dialog) |
276 | { |
277 | char* theme; |
278 | CtkTreeIter iter; |
279 | |
280 | CtkTreeModel* model = ctk_combo_box_get_model(CTK_COMBO_BOX(dialog->theme_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->theme_combo)), ((ctk_combo_box_get_type ()))) )))); |
281 | |
282 | if (!ctk_combo_box_get_active_iter(CTK_COMBO_BOX(dialog->theme_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->theme_combo)), ((ctk_combo_box_get_type ()))) ))), &iter)) |
283 | { |
284 | return; |
285 | } |
286 | |
287 | ctk_tree_model_get(model, &iter, NOTIFY_THEME_NAME, &theme, -1); |
288 | g_settings_set_string(dialog->gsettings, GSETTINGS_KEY_THEME"theme", theme); |
289 | g_free(theme); |
290 | } |
291 | |
292 | static gchar* get_theme_name(const gchar* filename) |
293 | { |
294 | /* TODO: Remove magic numbers. Strip "lib" and ".so" */ |
295 | gchar* result = g_strdup(filename + 3)g_strdup_inline (filename + 3); |
296 | result[strlen(result) - strlen("." G_MODULE_SUFFIX"so")] = '\0'; |
297 | return result; |
298 | } |
299 | |
300 | static void notification_properties_dialog_setup_themes(NotificationAppletDialog* dialog) |
301 | { |
302 | GDir* dir; |
303 | const gchar* filename; |
304 | char* theme; |
305 | char* theme_name; |
306 | char* theme_label; |
307 | gboolean valid; |
308 | CtkListStore* store; |
309 | CtkTreeIter iter; |
310 | |
311 | store = ctk_list_store_new(N_COLUMNS_THEME, G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_STRING((GType) ((16) << (2)))); |
312 | |
313 | ctk_combo_box_set_model(CTK_COMBO_BOX(dialog->theme_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->theme_combo)), ((ctk_combo_box_get_type ()))) ))), CTK_TREE_MODEL(store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ()))))))); |
314 | |
315 | g_signal_connect(dialog->gsettings, "changed::" GSETTINGS_KEY_THEME, G_CALLBACK (notification_properties_theme_notify), dialog)g_signal_connect_data ((dialog->gsettings), ("changed::" "theme" ), (((GCallback) (notification_properties_theme_notify))), (dialog ), ((void*)0), (GConnectFlags) 0); |
316 | g_signal_connect(dialog->theme_combo, "changed", G_CALLBACK(notification_properties_theme_changed), dialog)g_signal_connect_data ((dialog->theme_combo), ("changed"), (((GCallback) (notification_properties_theme_changed))), (dialog ), ((void*)0), (GConnectFlags) 0); |
317 | |
318 | if ((dir = g_dir_open(ENGINES_DIR"/usr/lib/cafe-notification-daemon/engines", 0, NULL((void*)0)))) |
319 | { |
320 | while ((filename = g_dir_read_name(dir))) |
321 | { |
322 | if (g_str_has_suffix(filename, "." G_MODULE_SUFFIX)(__builtin_constant_p ("." "so")? __extension__ ({ const char * const __str = (filename); const char * const __suffix = ("." "so"); gboolean __result = (0); if (__str == ((void*)0) || __suffix == ((void*)0)) __result = (g_str_has_suffix) (__str, __suffix ); else { const size_t __str_len = strlen (((__str) + !(__str ))); const size_t __suffix_len = strlen (((__suffix) + !(__suffix ))); if (__str_len >= __suffix_len) __result = memcmp (__str + __str_len - __suffix_len, ((__suffix) + !(__suffix)), __suffix_len ) == 0; } __result; }) : (g_str_has_suffix) (filename, "." "so" ) )) |
323 | { |
324 | theme_name = get_theme_name(filename); |
325 | |
326 | /* FIXME: other solution than hardcode? */ |
327 | if (g_str_equal(theme_name, "coco")(strcmp ((const char *) (theme_name), (const char *) ("coco") ) == 0)) |
328 | { |
329 | theme_label = g_strdup(_("Coco"))g_strdup_inline (gettext ("Coco")); |
330 | } |
331 | else if (g_str_equal(theme_name, "nodoka")(strcmp ((const char *) (theme_name), (const char *) ("nodoka" )) == 0)) |
332 | { |
333 | theme_label = g_strdup(_("Nodoka"))g_strdup_inline (gettext ("Nodoka")); |
334 | } |
335 | else if (g_str_equal(theme_name, "slider")(strcmp ((const char *) (theme_name), (const char *) ("slider" )) == 0)) |
336 | { |
337 | theme_label = g_strdup(_("Slider"))g_strdup_inline (gettext ("Slider")); |
338 | } |
339 | else if (g_str_equal(theme_name, "standard")(strcmp ((const char *) (theme_name), (const char *) ("standard" )) == 0)) |
340 | { |
341 | theme_label = g_strdup(_("Standard theme"))g_strdup_inline (gettext ("Standard theme")); |
342 | } |
343 | else |
344 | { |
345 | theme_label = g_strdup(theme_name)g_strdup_inline (theme_name); |
346 | } |
347 | |
348 | ctk_list_store_append(store, &iter); |
349 | ctk_list_store_set(store, &iter, NOTIFY_THEME_LABEL, theme_label, NOTIFY_THEME_NAME, theme_name, NOTIFY_THEME_FILENAME, filename, -1); |
350 | g_free(theme_name); |
351 | g_free(theme_label); |
352 | } |
353 | } |
354 | |
355 | g_dir_close(dir); |
356 | } |
357 | else |
358 | { |
359 | g_warning("Error opening themes dir"); |
360 | } |
361 | |
362 | theme = g_settings_get_string(dialog->gsettings, GSETTINGS_KEY_THEME"theme"); |
363 | |
364 | for (valid = ctk_tree_model_get_iter_first(CTK_TREE_MODEL(store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ())))))), &iter); valid; valid = ctk_tree_model_iter_next(CTK_TREE_MODEL(store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ())))))), &iter)) |
365 | { |
366 | gchar* key; |
367 | |
368 | ctk_tree_model_get(CTK_TREE_MODEL(store)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((store)), ((ctk_tree_model_get_type ())))))), &iter, NOTIFY_THEME_NAME, &key, -1); |
369 | |
370 | if (g_str_equal(key, theme)(strcmp ((const char *) (key), (const char *) (theme)) == 0)) |
371 | { |
372 | ctk_combo_box_set_active_iter(CTK_COMBO_BOX(dialog->theme_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->theme_combo)), ((ctk_combo_box_get_type ()))) ))), &iter); |
373 | g_free(key); |
374 | break; |
375 | } |
376 | |
377 | g_free(key); |
378 | } |
379 | |
380 | g_free(theme); |
381 | } |
382 | |
383 | static void notification_properties_checkbox_toggled(CtkWidget* widget, NotificationAppletDialog* dialog) |
384 | { |
385 | gboolean is_active; |
386 | |
387 | is_active = ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON (widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ()))))))); |
388 | |
389 | // This was called as a result of notification_properties_checkbox_notify being called. |
390 | // Stop here instead of doing redundant work. |
391 | if (is_active == g_settings_get_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR"use-active-monitor")) |
392 | { |
393 | return; |
394 | } |
395 | |
396 | if (is_active) |
397 | { |
398 | g_settings_set_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR"use-active-monitor", TRUE(!(0))); |
399 | ctk_widget_set_sensitive(dialog->monitor_combo, FALSE(0)); |
400 | ctk_widget_set_sensitive(dialog->monitor_label, FALSE(0)); |
401 | } |
402 | else |
403 | { |
404 | g_settings_set_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR"use-active-monitor", FALSE(0)); |
405 | ctk_widget_set_sensitive(dialog->monitor_combo, TRUE(!(0))); |
406 | ctk_widget_set_sensitive(dialog->monitor_label, TRUE(!(0))); |
407 | } |
408 | } |
409 | |
410 | static void notification_properties_checkbox_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) |
411 | { |
412 | gboolean is_set; |
413 | |
414 | is_set = g_settings_get_boolean(settings, key); |
415 | |
416 | // This was called as a result of notification_properties_checkbox_toggled being called. |
417 | // Stop here instead of doing redundant work. |
418 | if(is_set == ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON (dialog->active_checkbox)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->active_checkbox)), ((ctk_toggle_button_get_type ())))))))) |
419 | { |
420 | return; |
421 | } |
422 | |
423 | if (is_set) |
424 | { |
425 | ctk_widget_set_sensitive(dialog->monitor_combo, FALSE(0)); |
426 | ctk_widget_set_sensitive(dialog->monitor_label, FALSE(0)); |
427 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON (dialog->active_checkbox)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->active_checkbox)), ((ctk_toggle_button_get_type ())))))), TRUE(!(0))); |
428 | } |
429 | else |
430 | { |
431 | ctk_widget_set_sensitive(dialog->monitor_combo, TRUE(!(0))); |
432 | ctk_widget_set_sensitive(dialog->monitor_label, TRUE(!(0))); |
433 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON (dialog->active_checkbox)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->active_checkbox)), ((ctk_toggle_button_get_type ())))))), FALSE(0)); |
434 | } |
435 | } |
436 | |
437 | static void notification_properties_dnd_toggled(CtkWidget* widget, NotificationAppletDialog* dialog) |
438 | { |
439 | gboolean is_active; |
440 | |
441 | is_active = ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON (widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ()))))))); |
442 | |
443 | // This was called as a result of notification_properties_dnd_notify being called. |
444 | // Stop here instead of doing redundant work. |
445 | if (is_active == g_settings_get_boolean(dialog->gsettings, GSETTINGS_KEY_DO_NOT_DISTURB"do-not-disturb")) |
446 | { |
447 | return; |
448 | } |
449 | |
450 | g_settings_set_boolean(dialog->gsettings, GSETTINGS_KEY_DO_NOT_DISTURB"do-not-disturb", is_active); |
451 | } |
452 | |
453 | static void notification_properties_dnd_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog) |
454 | { |
455 | gboolean is_set; |
456 | |
457 | is_set = g_settings_get_boolean(settings, key); |
458 | |
459 | // This was called as a result of notification_properties_dnd_toggled being called. |
460 | // Stop here instead of doing redundant work. |
461 | if(is_set == ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON (dialog->dnd_checkbox)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->dnd_checkbox)), ((ctk_toggle_button_get_type ( ))))))))) |
462 | { |
463 | return; |
464 | } |
465 | |
466 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON (dialog->dnd_checkbox)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->dnd_checkbox)), ((ctk_toggle_button_get_type ( ))))))), is_set); |
467 | } |
468 | |
469 | static void show_message(NotificationAppletDialog* dialog, const gchar* message) |
470 | { |
471 | CtkWidget* d = ctk_message_dialog_new(CTK_WINDOW(dialog->dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->dialog)), ((ctk_window_get_type ())))))), CTK_DIALOG_DESTROY_WITH_PARENT, CTK_MESSAGE_ERROR, CTK_BUTTONS_CLOSE, "%s", message); |
472 | ctk_dialog_run(CTK_DIALOG(d)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((d)), ((ctk_dialog_get_type ()))))))); |
473 | ctk_widget_destroy(d); |
474 | } |
475 | |
476 | static void notification_properties_dialog_preview_closed(NotifyNotification* preview, NotificationAppletDialog* dialog) |
477 | { |
478 | if (preview == dialog->preview) |
479 | { |
480 | dialog->preview = NULL((void*)0); |
481 | } |
482 | |
483 | g_object_unref(preview); |
484 | } |
485 | |
486 | static void notification_properties_dialog_preview(NotificationAppletDialog* dialog) |
487 | { |
488 | if (!notify_is_initted() && !notify_init("n-d")) |
489 | { |
490 | show_message(dialog, _("Error initializing libcafenotify")gettext ("Error initializing libcafenotify")); |
491 | return; |
492 | } |
493 | |
494 | GError* error = NULL((void*)0); |
495 | |
496 | if (dialog->preview) |
497 | { |
498 | notify_notification_close(dialog->preview, NULL((void*)0)); |
499 | g_object_unref(dialog->preview); |
500 | dialog->preview = NULL((void*)0); |
501 | } |
502 | |
503 | dialog->preview = notify_notification_new(_("Notification Test")gettext ("Notification Test"), _("Just a test")gettext ("Just a test"), "dialog-information"); |
504 | |
505 | if (!notify_notification_show(dialog->preview, &error)) |
506 | { |
507 | char* message = g_strdup_printf(_("Error while displaying notification: %s")gettext ("Error while displaying notification: %s"), error->message); |
508 | show_message(dialog, message); |
509 | g_error_free(error); |
510 | g_free(message); |
511 | } |
512 | |
513 | g_signal_connect(dialog->preview, "closed", G_CALLBACK(notification_properties_dialog_preview_closed), dialog)g_signal_connect_data ((dialog->preview), ("closed"), (((GCallback ) (notification_properties_dialog_preview_closed))), (dialog) , ((void*)0), (GConnectFlags) 0); |
514 | } |
515 | |
516 | static void notification_properties_dialog_response(CtkWidget* widget, int response, NotificationAppletDialog* dialog) |
517 | { |
518 | switch (response) |
519 | { |
520 | case CTK_RESPONSE_ACCEPT: |
521 | notification_properties_dialog_preview(dialog); |
522 | break; |
523 | |
524 | case CTK_RESPONSE_CLOSE: |
525 | default: |
526 | ctk_widget_destroy(widget); |
527 | break; |
528 | } |
529 | } |
530 | |
531 | static void notification_properties_dialog_destroyed(CtkWidget* widget, NotificationAppletDialog* dialog) |
532 | { |
533 | dialog->dialog = NULL((void*)0); |
534 | |
535 | ctk_main_quit(); |
536 | } |
537 | |
538 | static gboolean notification_properties_dialog_init(NotificationAppletDialog* dialog) |
539 | { |
540 | CtkBuilder* builder = ctk_builder_new(); |
541 | GError* error = NULL((void*)0); |
542 | |
543 | ctk_builder_add_from_resource (builder, "/org/cafe/notifications/properties/cafe-notification-properties.ui", &error); |
544 | |
545 | if (error != NULL((void*)0)) |
546 | { |
547 | g_warning(_("Could not load user interface: %s")gettext ("Could not load user interface: %s"), error->message); |
548 | g_error_free(error); |
549 | return FALSE(0); |
550 | } |
551 | |
552 | dialog->dialog = CTK_WIDGET(ctk_builder_get_object(builder, "dialog"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object(builder, "dialog"))), ((ctk_widget_get_type ())))))); |
553 | g_assert(dialog->dialog != NULL)do { if (dialog->dialog != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 553, ((const char*) (__func__)), "dialog->dialog != NULL"); } while (0 ); |
554 | |
555 | dialog->position_combo = CTK_WIDGET(ctk_builder_get_object(builder, "position_combo"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object(builder, "position_combo"))), ((ctk_widget_get_type ())))))); |
556 | g_assert(dialog->position_combo != NULL)do { if (dialog->position_combo != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 556, ((const char*) (__func__)), "dialog->position_combo != NULL"); } while (0); |
557 | |
558 | dialog->monitor_combo = CTK_WIDGET(ctk_builder_get_object(builder, "monitor_combo"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object(builder, "monitor_combo"))), ((ctk_widget_get_type ())))))); |
559 | g_assert(dialog->monitor_combo != NULL)do { if (dialog->monitor_combo != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 559, ((const char*) (__func__)), "dialog->monitor_combo != NULL"); } while (0); |
560 | |
561 | dialog->theme_combo = CTK_WIDGET(ctk_builder_get_object(builder, "theme_combo"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object(builder, "theme_combo"))), ((ctk_widget_get_type ())))))); |
562 | g_assert(dialog->theme_combo != NULL)do { if (dialog->theme_combo != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 562, ((const char*) (__func__)), "dialog->theme_combo != NULL"); } while (0); |
563 | |
564 | dialog->active_checkbox = CTK_WIDGET(ctk_builder_get_object(builder, "use_active_check"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object(builder, "use_active_check"))), ( (ctk_widget_get_type ())))))); |
565 | g_assert(dialog->active_checkbox != NULL)do { if (dialog->active_checkbox != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 565, ((const char*) (__func__)), "dialog->active_checkbox != NULL"); } while (0); |
566 | |
567 | dialog->dnd_checkbox = CTK_WIDGET(ctk_builder_get_object(builder, "do_not_disturb_check"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object(builder, "do_not_disturb_check")) ), ((ctk_widget_get_type ())))))); |
568 | g_assert(dialog->dnd_checkbox != NULL)do { if (dialog->dnd_checkbox != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 568, ((const char*) (__func__)), "dialog->dnd_checkbox != NULL"); } while (0); |
569 | |
570 | dialog->monitor_label = CTK_WIDGET(ctk_builder_get_object(builder, "monitor_label"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object(builder, "monitor_label"))), ((ctk_widget_get_type ())))))); |
571 | g_assert(dialog->monitor_label != NULL)do { if (dialog->monitor_label != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "cafe-notification-properties.c", 571, ((const char*) (__func__)), "dialog->monitor_label != NULL"); } while (0); |
572 | |
573 | g_object_unref(builder); |
574 | |
575 | dialog->gsettings = g_settings_new (GSETTINGS_SCHEMA"org.cafe.NotificationDaemon"); |
576 | |
577 | g_signal_connect(dialog->dialog, "response", G_CALLBACK(notification_properties_dialog_response), dialog)g_signal_connect_data ((dialog->dialog), ("response"), ((( GCallback) (notification_properties_dialog_response))), (dialog ), ((void*)0), (GConnectFlags) 0); |
578 | g_signal_connect(dialog->dialog, "destroy", G_CALLBACK(notification_properties_dialog_destroyed), dialog)g_signal_connect_data ((dialog->dialog), ("destroy"), (((GCallback ) (notification_properties_dialog_destroyed))), (dialog), ((void *)0), (GConnectFlags) 0); |
579 | |
580 | g_signal_connect(dialog->gsettings, "changed::" GSETTINGS_KEY_USE_ACTIVE_MONITOR, G_CALLBACK (notification_properties_checkbox_notify), dialog)g_signal_connect_data ((dialog->gsettings), ("changed::" "use-active-monitor" ), (((GCallback) (notification_properties_checkbox_notify))), (dialog), ((void*)0), (GConnectFlags) 0); |
581 | g_signal_connect(dialog->active_checkbox, "toggled", G_CALLBACK(notification_properties_checkbox_toggled), dialog)g_signal_connect_data ((dialog->active_checkbox), ("toggled" ), (((GCallback) (notification_properties_checkbox_toggled))) , (dialog), ((void*)0), (GConnectFlags) 0); |
582 | |
583 | g_signal_connect(dialog->gsettings, "changed::" GSETTINGS_KEY_DO_NOT_DISTURB, G_CALLBACK (notification_properties_dnd_notify), dialog)g_signal_connect_data ((dialog->gsettings), ("changed::" "do-not-disturb" ), (((GCallback) (notification_properties_dnd_notify))), (dialog ), ((void*)0), (GConnectFlags) 0); |
584 | g_signal_connect(dialog->dnd_checkbox, "toggled", G_CALLBACK(notification_properties_dnd_toggled), dialog)g_signal_connect_data ((dialog->dnd_checkbox), ("toggled") , (((GCallback) (notification_properties_dnd_toggled))), (dialog ), ((void*)0), (GConnectFlags) 0); |
585 | |
586 | notification_properties_dialog_setup_themes(dialog); |
587 | notification_properties_dialog_setup_positions(dialog); |
588 | notification_properties_dialog_setup_monitors(dialog); |
589 | |
590 | if (g_settings_get_boolean(dialog->gsettings, GSETTINGS_KEY_USE_ACTIVE_MONITOR"use-active-monitor")) |
591 | { |
592 | ctk_widget_set_sensitive(dialog->monitor_combo, FALSE(0)); |
593 | ctk_widget_set_sensitive(dialog->monitor_label, FALSE(0)); |
594 | } |
595 | else |
596 | { |
597 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON (dialog->active_checkbox)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->active_checkbox)), ((ctk_toggle_button_get_type ())))))), FALSE(0)); |
598 | ctk_widget_set_sensitive(dialog->monitor_combo, TRUE(!(0))); |
599 | ctk_widget_set_sensitive(dialog->monitor_label, TRUE(!(0))); |
600 | } |
601 | |
602 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON (dialog->dnd_checkbox)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog->dnd_checkbox)), ((ctk_toggle_button_get_type ( ))))))), g_settings_get_boolean(dialog->gsettings, GSETTINGS_KEY_DO_NOT_DISTURB"do-not-disturb")); |
603 | |
604 | ctk_widget_show_all(dialog->dialog); |
605 | |
606 | dialog->preview = NULL((void*)0); |
607 | |
608 | return TRUE(!(0)); |
609 | } |
610 | |
611 | static void notification_properties_dialog_finalize(NotificationAppletDialog* dialog) |
612 | { |
613 | if (dialog->dialog != NULL((void*)0)) |
614 | { |
615 | ctk_widget_destroy(dialog->dialog); |
616 | dialog->dialog = NULL((void*)0); |
617 | } |
618 | |
619 | if (dialog->preview) |
620 | { |
621 | notify_notification_close(dialog->preview, NULL((void*)0)); |
622 | dialog->preview = NULL((void*)0); |
623 | } |
624 | } |
625 | |
626 | int main(int argc, char** argv) |
627 | { |
628 | NotificationAppletDialog dialog = {NULL((void*)0), }; /* <- ? */ |
629 | |
630 | bindtextdomain(GETTEXT_PACKAGE"cafe-notification-daemon", NOTIFICATION_LOCALEDIR"/usr/share/locale"); |
631 | bind_textdomain_codeset(GETTEXT_PACKAGE"cafe-notification-daemon", "UTF-8"); |
632 | textdomain(GETTEXT_PACKAGE"cafe-notification-daemon"); |
633 | |
634 | ctk_init(&argc, &argv); |
635 | |
636 | notify_init("cafe-notification-properties"); |
637 | |
638 | if (!notification_properties_dialog_init(&dialog)) |
639 | { |
640 | notification_properties_dialog_finalize(&dialog); |
641 | return 1; |
642 | } |
643 | |
644 | ctk_main(); |
645 | |
646 | notification_properties_dialog_finalize(&dialog); |
647 | |
648 | return 0; |
649 | } |