File: | sensors-applet/sensors-applet.c |
Warning: | line 894, column 9 Value stored to 'not_empty_tree' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (C) 2005-2009 Alex Murray <murray.alex@gmail.com> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | /** Contain the functions for operating on the SensorsApplet structure |
20 | * (represents the applet itself, and its associated variables. |
21 | */ |
22 | |
23 | #ifdef HAVE_CONFIG_H1 |
24 | #include "config.h" |
25 | #endif /* HAVE_CONFIG_H */ |
26 | |
27 | #ifdef HAVE_UNISTD_H1 |
28 | #include <unistd.h> |
29 | #endif /* HAVE_UNISTD_H */ |
30 | |
31 | #include <glib/gi18n.h> |
32 | #include <glib/gprintf.h> |
33 | #include <gio/gio.h> |
34 | #include "sensors-applet.h" |
35 | #include "active-sensor.h" |
36 | #include "sensors-applet-settings.h" |
37 | #include "sensors-applet-plugins.h" |
38 | |
39 | #ifdef HAVE_LIBNOTIFY1 |
40 | #include "active-sensor-libnotify.h" |
41 | #define DEFAULT_NOTIFY_TIMEOUT3000 3000 |
42 | #endif |
43 | |
44 | #include "prefs-dialog.h" |
45 | #include "about-dialog.h" |
46 | |
47 | #define SENSORS_APPLET_MENU_FILE"SensorsApplet.xml" "SensorsApplet.xml" |
48 | /* initially set as sensors_applet->size to ensure a real value is stored */ |
49 | #define DEFAULT_APPLET_SIZE24 24 |
50 | #define COLUMN_SPACING2 2 |
51 | #define ROW_SPACING1 1 |
52 | |
53 | |
54 | /* builder for sensor sorting verification */ |
55 | static GVariantBuilder gvb_sensors_hash_list; |
56 | |
57 | |
58 | /* callbacks for panel menu */ |
59 | static void prefs_cb(CtkAction *action, gpointer *data) { |
60 | |
61 | SensorsApplet *sensors_applet; |
62 | sensors_applet = (SensorsApplet *)data; |
63 | |
64 | if (sensors_applet->prefs_dialog) { |
65 | ctk_window_present(CTK_WINDOW(sensors_applet->prefs_dialog->dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->prefs_dialog->dialog)), ((ctk_window_get_type ()))))))); |
66 | return; |
67 | } |
68 | prefs_dialog_open(sensors_applet); |
69 | } |
70 | |
71 | static void about_cb(CtkAction *action, gpointer data) { |
72 | SensorsApplet *sensors_applet; |
73 | sensors_applet = (SensorsApplet *)data; |
74 | |
75 | about_dialog_open(sensors_applet); |
76 | } |
77 | |
78 | static void help_cb(CtkAction *action, gpointer data) { |
79 | |
80 | GError *error = NULL((void*)0); |
81 | |
82 | ctk_show_uri_on_window(NULL((void*)0), "help:cafe-sensors-applet", |
83 | |
84 | ctk_get_current_event_time(), |
85 | &error); |
86 | |
87 | if (error) { |
88 | g_debug("Could not open help document: %s ",error->message); |
89 | g_error_free(error); |
90 | } |
91 | } |
92 | |
93 | static void destroy_cb(CtkWidget *widget, gpointer data) { |
94 | SensorsApplet *sensors_applet; |
95 | sensors_applet = (SensorsApplet *)data; |
96 | |
97 | /* destroy dialogs, remove timeout and clear sensors tree and finally the applet */ |
98 | if (sensors_applet->prefs_dialog != NULL((void*)0)) { |
99 | /* destroy's dialog too */ |
100 | prefs_dialog_close(sensors_applet); |
101 | } |
102 | |
103 | if (sensors_applet->timeout_id) { |
104 | g_source_remove(sensors_applet->timeout_id); |
105 | } |
106 | |
107 | if (sensors_applet->settings) { |
108 | g_object_unref (sensors_applet->settings); |
109 | sensors_applet->settings = NULL((void*)0); |
110 | } |
111 | |
112 | /* destroy all active sensors */ |
113 | g_list_foreach(sensors_applet->active_sensors, |
114 | (GFunc)active_sensor_destroy, |
115 | NULL((void*)0)); |
116 | |
117 | if (sensors_applet->sensors != NULL((void*)0)) { |
118 | ctk_tree_store_clear(sensors_applet->sensors); |
119 | } |
120 | |
121 | ctk_widget_destroy(CTK_WIDGET(sensors_applet->applet)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_widget_get_type ()))) )))); |
122 | |
123 | g_free(sensors_applet); |
124 | return; |
125 | } |
126 | |
127 | static void change_orient_cb (CafePanelApplet *applet, |
128 | CafePanelAppletOrient orient, |
129 | gpointer data) { |
130 | |
131 | SensorsApplet *sensors_applet; |
132 | sensors_applet = (SensorsApplet *)data; |
133 | |
134 | sensors_applet_display_layout_changed(sensors_applet); |
135 | } |
136 | |
137 | static void size_allocate_cb(CafePanelApplet *applet, |
138 | CtkAllocation *allocation, |
139 | gpointer data) { |
140 | |
141 | SensorsApplet *sensors_applet; |
142 | CafePanelAppletOrient orient; |
143 | |
144 | sensors_applet = (SensorsApplet *)data; |
145 | orient = cafe_panel_applet_get_orient(sensors_applet->applet); |
146 | |
147 | if ((orient == CAFE_PANEL_APPLET_ORIENT_LEFT) || |
148 | (orient == CAFE_PANEL_APPLET_ORIENT_RIGHT)) { |
149 | |
150 | if (sensors_applet->size == allocation->width) |
151 | return; |
152 | sensors_applet->size = allocation->width; |
153 | } else { |
154 | if (sensors_applet->size == allocation->height) |
155 | return; |
156 | sensors_applet->size = allocation->height; |
157 | } |
158 | |
159 | /* update if new value */ |
160 | sensors_applet_graph_size_changed(sensors_applet); |
161 | sensors_applet_display_layout_changed(sensors_applet); |
162 | } |
163 | |
164 | static void style_set_cb(CtkWidget *widget, CtkStyle *old_style, gpointer data) { |
165 | |
166 | /* update all icons in the sensors tree and update all active sensors */ |
167 | CtkTreeIter interfaces_iter, sensors_iter; |
168 | CtkTreePath *path; |
169 | gboolean not_end_of_interfaces = TRUE(!(0)), not_end_of_sensors = TRUE(!(0)); |
170 | IconType icon_type; |
171 | GdkPixbuf *new_icon; |
172 | gboolean enabled; |
173 | SensorsApplet *sensors_applet; |
174 | DisplayMode display_mode; |
175 | |
176 | sensors_applet = (SensorsApplet *)data; |
177 | |
178 | display_mode = g_settings_get_int (sensors_applet->settings, DISPLAY_MODE"display-mode"); |
179 | if (sensors_applet->sensors) { |
180 | for (ctk_tree_model_get_iter_first(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &interfaces_iter); |
181 | not_end_of_interfaces; |
182 | not_end_of_interfaces = ctk_tree_model_iter_next(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &interfaces_iter)) { |
183 | |
184 | /* reset sensors sentinel */ |
185 | not_end_of_sensors = TRUE(!(0)); |
186 | |
187 | for (ctk_tree_model_iter_children(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &sensors_iter, &interfaces_iter); |
188 | not_end_of_sensors; |
189 | not_end_of_sensors = ctk_tree_model_iter_next(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &sensors_iter)) { |
190 | |
191 | ctk_tree_model_get(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), |
192 | &sensors_iter, |
193 | ENABLE_COLUMN, &enabled, |
194 | ICON_TYPE_COLUMN, &icon_type, |
195 | -1); |
196 | /* update icons */ |
197 | new_icon = sensors_applet_load_icon(icon_type); |
198 | |
199 | ctk_tree_store_set(sensors_applet->sensors, |
200 | &sensors_iter, |
201 | ICON_PIXBUF_COLUMN, new_icon, |
202 | -1); |
203 | g_object_unref(new_icon); |
204 | |
205 | /* update icons only if currently being displayed */ |
206 | if (enabled && |
207 | (display_mode == DISPLAY_ICON || |
208 | display_mode == DISPLAY_ICON_WITH_VALUE)) { |
209 | |
210 | path = ctk_tree_model_get_path(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &sensors_iter); |
211 | sensors_applet_icon_changed(sensors_applet, path); |
212 | ctk_tree_path_free(path); |
213 | } |
214 | } |
215 | } |
216 | /* now update layout as size may have changed */ |
217 | sensors_applet_display_layout_changed(sensors_applet); |
218 | } |
219 | |
220 | } |
221 | |
222 | static gboolean mouse_enter_cb(CtkWidget *widget, CdkEventCrossing *event, gpointer data) |
223 | { |
224 | SensorsApplet *sensor_applet = data; |
225 | sensor_applet->show_tooltip = TRUE(!(0)); |
226 | sensors_applet_update_active_sensors(sensor_applet); |
227 | return TRUE(!(0)); |
228 | } |
229 | |
230 | static gboolean mouse_leave_cb(CtkWidget *widget, CdkEventCrossing *event, gpointer data) |
231 | { |
232 | SensorsApplet *sensor_applet = data; |
233 | sensor_applet->show_tooltip = FALSE(0); |
234 | return TRUE(!(0)); |
235 | } |
236 | |
237 | static const CtkActionEntry sensors_applet_menu_actions[] = { |
238 | { "Preferences", "document-properties", N_("_Preferences")("_Preferences"), |
239 | NULL((void*)0), NULL((void*)0), |
240 | G_CALLBACK(prefs_cb)((GCallback) (prefs_cb)) }, |
241 | { "Help", "help-browser", N_("_Help")("_Help"), |
242 | NULL((void*)0), NULL((void*)0), |
243 | G_CALLBACK(help_cb)((GCallback) (help_cb)) }, |
244 | { "About", "help-about", N_("_About")("_About"), |
245 | NULL((void*)0), NULL((void*)0), |
246 | G_CALLBACK(about_cb)((GCallback) (about_cb)) } |
247 | }; |
248 | |
249 | #ifdef HAVE_LIBNOTIFY1 |
250 | static void notif_closed_cb(NotifyNotification *notification, SensorsApplet *sensors_applet) { |
251 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 251, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
252 | |
253 | sensors_applet->notification = NULL((void*)0); |
254 | } |
255 | #endif // HAVE_LIBNOTIFY |
256 | |
257 | void sensors_applet_notify_active_sensor(ActiveSensor *active_sensor, NotifType notif_type) { |
258 | #ifdef HAVE_LIBNOTIFY1 |
259 | |
260 | SensorsApplet *sensors_applet; |
261 | gchar *summary, *message; |
262 | gint timeout_msecs; |
263 | gchar *sensor_label; |
264 | gchar *sensor_path; |
265 | SensorType sensor_type; |
266 | TemperatureScale temp_scale; |
267 | CtkTreeIter iter; |
268 | CtkTreePath *path; |
269 | const gchar *unit_type = NULL((void*)0); |
270 | const gchar *unit_type_title = NULL((void*)0); |
271 | const gchar *relation = NULL((void*)0); |
272 | const gchar *limit_type = NULL((void*)0); |
273 | const gchar *units = NULL((void*)0); |
274 | gdouble limit_value; |
275 | gdouble seconds; |
276 | gboolean show_notification = TRUE(!(0)); |
277 | |
278 | sensors_applet = active_sensor->sensors_applet; |
279 | |
280 | if (!g_settings_get_boolean (sensors_applet->settings, DISPLAY_NOTIFICATIONS"display-notifications")) { |
281 | g_debug("Wanted to display notification, but user has disabled them"); |
282 | return; |
283 | } |
284 | |
285 | path = ctk_tree_row_reference_get_path(active_sensor->sensor_row); |
286 | if (ctk_tree_model_get_iter(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &iter, path)) { |
287 | |
288 | ctk_tree_model_get(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &iter, |
289 | LABEL_COLUMN, &sensor_label, |
290 | PATH_COLUMN, &sensor_path, |
291 | SENSOR_TYPE_COLUMN, &sensor_type, |
292 | -1); |
293 | } else { |
294 | g_warning("Error getting data from tree for notification..."); |
295 | ctk_tree_path_free(path); |
296 | return; |
297 | } |
298 | |
299 | ctk_tree_path_free(path); |
300 | |
301 | /* do different stuff for different notif types */ |
302 | switch (notif_type) { |
303 | case LOW_ALARM: /* fall thru */ |
304 | case HIGH_ALARM: |
305 | if (active_sensor->sensor_values[0] <= active_sensor->sensor_low_value && notif_type == LOW_ALARM) { |
306 | |
307 | relation = _("is very low")gettext ("is very low"); |
308 | limit_type = _("lower limit")gettext ("lower limit"); |
309 | limit_value = active_sensor->sensor_low_value; |
310 | } else if (active_sensor->sensor_values[0] >= active_sensor->sensor_high_value && notif_type == HIGH_ALARM) { |
311 | |
312 | /* assume high alarm condition */ |
313 | relation = _("is very high")gettext ("is very high"); |
314 | limit_type = _("upper limit")gettext ("upper limit"); |
315 | limit_value = active_sensor->sensor_high_value; |
316 | } else { |
317 | g_warning("Alarm notify called when no alarm condition!"); |
318 | g_free(sensor_path); |
319 | g_free(sensor_label); |
320 | return; |
321 | } |
322 | |
323 | switch ((SensorType)sensor_type) { |
324 | case TEMP_SENSOR: |
325 | unit_type_title = _("Temperature")gettext ("Temperature"); |
326 | unit_type = _("temperature")gettext ("temperature"); |
327 | temp_scale = (TemperatureScale) g_settings_get_int (active_sensor->sensors_applet->settings, TEMPERATURE_SCALE"temperature-scale"); |
328 | |
329 | switch (temp_scale) { |
330 | case CELSIUS: |
331 | units = UNITS_CELSIUS"\302\260C"; |
332 | break; |
333 | case FAHRENHEIT: |
334 | units = UNITS_FAHRENHEIT"\302\260F"; |
335 | break; |
336 | case KELVIN: |
337 | units = UNITS_KELVIN""; |
338 | break; |
339 | default: |
340 | units = NULL((void*)0); |
341 | } |
342 | break; |
343 | |
344 | case VOLTAGE_SENSOR: |
345 | unit_type_title = _("Voltage")gettext ("Voltage"); |
346 | unit_type = _("voltage")gettext ("voltage"); |
347 | units = UNITS_VOLTAGEgettext ("V"); |
348 | break; |
349 | |
350 | case FAN_SENSOR: |
351 | unit_type_title = _("Fan Speed")gettext ("Fan Speed"); |
352 | unit_type = _("fan speed")gettext ("fan speed"); |
353 | units = UNITS_RPMgettext ("RPM"); |
354 | break; |
355 | |
356 | case CURRENT_SENSOR: |
357 | unit_type_title = _("Current")gettext ("Current"); |
358 | unit_type = _("current")gettext ("current"); |
359 | units = UNITS_CURRENTgettext ("A"); |
360 | break; |
361 | } |
362 | |
363 | timeout_msecs = (active_sensor->alarm_timeout ? MIN(DEFAULT_NOTIFY_TIMEOUT, (active_sensor->alarm_timeout * 1000))(((3000) < ((active_sensor->alarm_timeout * 1000))) ? ( 3000) : ((active_sensor->alarm_timeout * 1000))) : DEFAULT_NOTIFY_TIMEOUT3000); |
364 | |
365 | summary = g_strdup_printf("%s %s %s", sensor_label, unit_type_title, _("Alarm")gettext ("Alarm")); |
366 | message = g_strdup_printf("%s %s %s (%s %2.0f%s)", sensor_label, unit_type, relation, limit_type, limit_value, units); |
367 | break; |
368 | |
369 | case SENSOR_INTERFACE_ERROR: |
370 | /* get time since the last error */ |
371 | seconds = difftime(time(NULL((void*)0)), active_sensor->ierror_ts); |
372 | |
373 | /* if the last error happened less than 10 seconds ago, don't display this one |
374 | * this should prevent recurring popups for removed sensors, like USB-HDDs */ |
375 | if (seconds < 11.0) { |
376 | show_notification = FALSE(0); |
377 | } |
378 | |
379 | summary = g_strdup_printf(_("Error updating sensor %s")gettext ("Error updating sensor %s"), sensor_label); |
380 | message = g_strdup_printf(_("An error occurred while trying to update the value of the sensor %s located at %s.")gettext ("An error occurred while trying to update the value of the sensor %s located at %s." ), sensor_label, sensor_path); |
381 | timeout_msecs = g_settings_get_int (active_sensor->sensors_applet->settings, TIMEOUT"timeout-delay"); |
382 | |
383 | /* update timestamp */ |
384 | time(&(active_sensor->ierror_ts)); |
385 | break; |
386 | |
387 | default: |
388 | g_assert_not_reached()do { g_assertion_message_expr ("sensors-applet", "sensors-applet.c" , 388, ((const char*) (__func__)), ((void*)0)); } while (0); |
389 | } |
390 | |
391 | if (show_notification) { |
392 | active_sensor_libnotify_notify(active_sensor, |
393 | notif_type, |
394 | summary, |
395 | message, |
396 | "dialog-warning", |
397 | timeout_msecs); |
398 | } |
399 | |
400 | g_free(sensor_path); |
401 | g_free(sensor_label); |
402 | g_free(summary); |
403 | g_free(message); |
404 | #endif |
405 | } |
406 | |
407 | void sensors_applet_notify_end(ActiveSensor *active_sensor, NotifType notif_type) { |
408 | #ifdef HAVE_LIBNOTIFY1 |
409 | active_sensor_libnotify_notify_end(active_sensor, notif_type); |
410 | #endif |
411 | } |
412 | |
413 | #ifdef HAVE_LIBNOTIFY1 |
414 | static void sensors_applet_notify_end_all_gfunc(ActiveSensor *active_sensor, gpointer data) { |
415 | active_sensor_libnotify_notify_end(active_sensor, LOW_ALARM); |
416 | active_sensor_libnotify_notify_end(active_sensor, HIGH_ALARM); |
417 | } |
418 | #endif |
419 | |
420 | void sensors_applet_notify_end_all(SensorsApplet *sensors_applet) { |
421 | #ifdef HAVE_LIBNOTIFY1 |
422 | g_list_foreach(sensors_applet->active_sensors, (GFunc)sensors_applet_notify_end_all_gfunc, NULL((void*)0)); |
423 | #endif |
424 | } |
425 | |
426 | /* internal helper functions for updating display etc */ |
427 | |
428 | /* should be called as a g_container_foreach at the start of |
429 | * pack_display if the grid already exists to remove but keep alive |
430 | * all children of the grid before repacking it */ |
431 | static void sensors_applet_pack_display_empty_grid_cb(CtkWidget *widget, gpointer data) |
432 | { |
433 | CtkContainer *container; |
434 | |
435 | container = CTK_CONTAINER(data)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_container_get_type ())))))); |
436 | |
437 | /* ref then remove widget */ |
438 | g_object_ref(widget)((__typeof__ (widget)) (g_object_ref) (widget)); |
439 | ctk_container_remove(container, widget); |
440 | } |
441 | |
442 | /* should be called as a g_container_foreach at the end of |
443 | * pack_display to unref any of the old children that we have readdded |
444 | * to the table to stop reference creep from the g_object_ref called |
445 | * on each child at the start of pack labels */ |
446 | static void sensors_applet_pack_display_cleanup_refs_cb(CtkWidget *widget, gpointer data) { |
447 | |
448 | GList *old_children; |
449 | |
450 | old_children = (GList *)data; |
451 | if (g_list_find(old_children, widget)) { |
452 | g_object_unref(widget); |
453 | } |
454 | } |
455 | |
456 | static void sensors_applet_pack_display(SensorsApplet *sensors_applet) { |
457 | /* note the if () around each widget is to ensure we only |
458 | * operate on those that actually exist */ |
459 | CtkLabel *no_sensors_enabled_label = NULL((void*)0); |
460 | gint num_active_sensors = 0, num_sensors_per_group, rows, cols, i, j; |
461 | GList *old_grid_children = NULL((void*)0); |
462 | |
463 | GList *current_sensor; |
464 | |
465 | DisplayMode display_mode; |
466 | LayoutMode layout_mode; |
467 | |
468 | gboolean horizontal; |
469 | gint label_width, icon_width, value_width; |
470 | gint label_height, icon_height, value_height; |
471 | |
472 | CtkRequisition req; |
473 | |
474 | ActiveSensor *first_sensor; |
475 | |
476 | /* it is possible that there could be no active sensors so |
477 | * handle that case first - make sure we dont do a NULL |
478 | * pointer access first though */ |
479 | if (sensors_applet->active_sensors == NULL((void*)0) || g_list_length(sensors_applet->active_sensors) == 0) { |
480 | g_debug("no active sensors to pack in grid"); |
481 | no_sensors_enabled_label = g_object_new(CTK_TYPE_LABEL(ctk_label_get_type ()), "label", _("No sensors enabled!")gettext ("No sensors enabled!"), NULL((void*)0)); |
482 | |
483 | if (sensors_applet->grid == NULL((void*)0)) { |
484 | /* only need 1 row and 1 col */ |
485 | sensors_applet->grid = ctk_grid_new(); |
486 | ctk_grid_set_column_spacing(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), COLUMN_SPACING2); |
487 | ctk_grid_set_row_spacing(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), ROW_SPACING1); |
488 | ctk_widget_set_halign(sensors_applet->grid, CTK_ALIGN_CENTER); |
489 | ctk_widget_set_valign(sensors_applet->grid, CTK_ALIGN_CENTER); |
490 | /* add grid to applet */ |
491 | ctk_container_add(CTK_CONTAINER(sensors_applet->applet)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_container_get_type () )))))), sensors_applet->grid); |
492 | } else { |
493 | /* destroy existing widgets - could be an |
494 | * existing version of no sensors label - okay |
495 | * to just add again though if destroy first */ |
496 | g_debug("destroying any existing widgets in container"); |
497 | ctk_container_foreach(CTK_CONTAINER(sensors_applet->grid)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_container_get_type ())) )))), (CtkCallback)ctk_widget_destroy, NULL((void*)0)); |
498 | } |
499 | g_debug("packing no sensors enabled label"); |
500 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
501 | CTK_WIDGET(no_sensors_enabled_label)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((no_sensors_enabled_label)), ((ctk_widget_get_type ())))) )), |
502 | 0, 0, 1, 1); |
503 | ctk_widget_show_all(CTK_WIDGET(sensors_applet->applet)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_widget_get_type ()))) )))); |
504 | return; |
505 | } |
506 | /* otherwise can acess active_sensors without any worries */ |
507 | num_active_sensors = g_list_length(sensors_applet->active_sensors); |
508 | |
509 | display_mode = (DisplayMode) g_settings_get_int (sensors_applet->settings, DISPLAY_MODE"display-mode"); |
510 | layout_mode = (LayoutMode) g_settings_get_int (sensors_applet->settings, LAYOUT_MODE"layout-mode"); |
511 | |
512 | horizontal = (((cafe_panel_applet_get_orient(sensors_applet->applet) == CAFE_PANEL_APPLET_ORIENT_UP) || |
513 | (cafe_panel_applet_get_orient(sensors_applet->applet) == CAFE_PANEL_APPLET_ORIENT_DOWN))); |
514 | |
515 | /* figure out num rows / cols by how high / wide sensors |
516 | * labels / icons are and how much size we have to put them in */ |
517 | |
518 | /* get the first active sensor */ |
519 | first_sensor = (ActiveSensor *)sensors_applet->active_sensors->data; |
520 | |
521 | switch (display_mode) { |
522 | case DISPLAY_VALUE: |
523 | ctk_widget_get_preferred_size(CTK_WIDGET(first_sensor->value)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((first_sensor->value)), ((ctk_widget_get_type ())))))), &req, NULL((void*)0)); |
524 | value_width = req.width + COLUMN_SPACING2; |
525 | value_height = req.height + ROW_SPACING1; |
526 | |
527 | /* make sure all widths and heights are non zero, |
528 | * otherwise will get a divide by zero exception below |
529 | * - is a non critical error since can happen when |
530 | * elements first added to list, so simply return - is |
531 | * not a programming error */ |
532 | if (value_width == 0 && value_height == 0) { |
533 | return; |
534 | } |
535 | |
536 | num_sensors_per_group = (sensors_applet->size / (horizontal ? value_height : value_width)); |
537 | break; |
538 | |
539 | case DISPLAY_LABEL_WITH_VALUE: |
540 | /* even though we end up packing the event boxes into the |
541 | * panel, these dont give back request sizes, so need to ask |
542 | * widgets directly */ |
543 | ctk_widget_get_preferred_size(CTK_WIDGET(first_sensor->value)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((first_sensor->value)), ((ctk_widget_get_type ())))))), &req, NULL((void*)0)); |
544 | |
545 | value_width = req.width + COLUMN_SPACING2; |
546 | value_height = req.height + ROW_SPACING1; |
547 | |
548 | ctk_widget_get_preferred_size(CTK_WIDGET(first_sensor->label)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((first_sensor->label)), ((ctk_widget_get_type ())))))), &req, NULL((void*)0)); |
549 | label_width = req.width + COLUMN_SPACING2; |
550 | label_height = req.height + ROW_SPACING1; |
551 | |
552 | /* make sure all widths and heights are non zero, otherwise |
553 | * will get a divide by zero exception below |
554 | * - is a non critical error since can happen when |
555 | * elements first added to list, so simply return - is |
556 | * not a programming error */ |
557 | if (!(label_width && label_height && value_width && value_height)) { |
558 | return; |
559 | } |
560 | |
561 | switch (layout_mode) { |
562 | case VALUE_BESIDE_LABEL: |
563 | num_sensors_per_group = (sensors_applet->size / (horizontal ? MAX(label_height, value_height)(((label_height) > (value_height)) ? (label_height) : (value_height )) : (label_width + value_width))); |
564 | break; |
565 | case VALUE_BELOW_LABEL: |
566 | num_sensors_per_group = (sensors_applet->size / (horizontal ? (label_height + value_height) : MAX(label_width, value_width)(((label_width) > (value_width)) ? (label_width) : (value_width )))); |
567 | break; |
568 | } |
569 | break; |
570 | |
571 | case DISPLAY_ICON_WITH_VALUE: |
572 | ctk_widget_get_preferred_size(CTK_WIDGET(first_sensor->value)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((first_sensor->value)), ((ctk_widget_get_type ())))))), &req, NULL((void*)0)); |
573 | value_width = req.width + COLUMN_SPACING2; |
574 | value_height = req.height + ROW_SPACING1; |
575 | |
576 | ctk_widget_get_preferred_size(CTK_WIDGET(first_sensor->icon)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((first_sensor->icon)), ((ctk_widget_get_type ())))))), &req, NULL((void*)0)); |
577 | icon_width = req.width + COLUMN_SPACING2; |
578 | icon_height = req.height + ROW_SPACING1; |
579 | |
580 | if (!(icon_width && icon_height && value_width && value_height)) { |
581 | return; |
582 | } |
583 | |
584 | switch (layout_mode) { |
585 | case VALUE_BESIDE_LABEL: |
586 | num_sensors_per_group = (sensors_applet->size / (horizontal ? MAX(icon_height, value_height)(((icon_height) > (value_height)) ? (icon_height) : (value_height )) : (icon_width + value_width))); |
587 | break; |
588 | |
589 | case VALUE_BELOW_LABEL: |
590 | num_sensors_per_group = (sensors_applet->size / (horizontal ? (icon_height + value_height) : MAX(icon_width, value_width)(((icon_width) > (value_width)) ? (icon_width) : (value_width )))); |
591 | break; |
592 | } |
593 | break; |
594 | |
595 | case DISPLAY_ICON: |
596 | ctk_widget_get_preferred_size(CTK_WIDGET(first_sensor->icon)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((first_sensor->icon)), ((ctk_widget_get_type ())))))), &req, NULL((void*)0)); |
597 | icon_width = req.width + COLUMN_SPACING2; |
598 | icon_height = req.height + ROW_SPACING1; |
599 | |
600 | if (!(icon_width && icon_height)) { |
601 | return; |
602 | } |
603 | |
604 | num_sensors_per_group = (sensors_applet->size / (horizontal ? icon_height : icon_width)); |
605 | break; |
606 | |
607 | case DISPLAY_GRAPH: |
608 | /* only show graphs in a line like System Monitor applet */ |
609 | num_sensors_per_group = 1; |
610 | break; |
611 | } |
612 | |
613 | /* ensure always atleast 1 sensor per group */ |
614 | if (num_sensors_per_group < 1) { |
615 | /* force a better layout */ |
616 | if (horizontal && layout_mode == VALUE_BELOW_LABEL) { |
617 | layout_mode = VALUE_BESIDE_LABEL; |
618 | } else if (!horizontal && layout_mode == VALUE_BESIDE_LABEL) { |
619 | layout_mode = VALUE_BELOW_LABEL; |
620 | } |
621 | num_sensors_per_group = 1; |
622 | } |
623 | |
624 | if (horizontal) { |
625 | /* if oriented horizontally, want as many |
626 | sensors per column as user has defined, then |
627 | enough columns to hold all the widgets */ |
628 | rows = num_sensors_per_group; |
629 | cols = num_active_sensors / num_sensors_per_group; |
630 | while (rows * cols < num_active_sensors || cols == 0) { |
631 | cols++; |
632 | } |
633 | |
634 | } else { |
635 | /* if oriented vertically, want as many |
636 | sensors per row as user has defined, then |
637 | enough rows to hold all the widgets*/ |
638 | cols = num_sensors_per_group; |
639 | rows = num_active_sensors / num_sensors_per_group; |
640 | while (rows * cols < num_active_sensors || rows == 0) { |
641 | rows++; |
642 | } |
643 | |
644 | } |
645 | |
646 | /* if displaying labels / icons and values need to modify |
647 | number of rows / colums to accomodate this */ |
648 | if (display_mode == DISPLAY_LABEL_WITH_VALUE || display_mode == DISPLAY_ICON_WITH_VALUE) { |
649 | if (layout_mode == VALUE_BESIDE_LABEL) { |
650 | /* to display labels next to values need twice as many columns */ |
651 | cols *= 2; |
652 | } else { |
653 | /* to display labels above values, we need twice as many rows as without */ |
654 | rows *= 2; |
655 | } |
656 | } |
657 | |
658 | if (sensors_applet->grid == NULL((void*)0)) { |
659 | /* create grid and add to applet */ |
660 | sensors_applet->grid = ctk_grid_new(); |
661 | ctk_grid_set_column_spacing(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), COLUMN_SPACING2); |
662 | ctk_grid_set_row_spacing(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), ROW_SPACING1); |
663 | ctk_widget_set_halign(sensors_applet->grid, CTK_ALIGN_CENTER); |
664 | ctk_widget_set_valign(sensors_applet->grid, CTK_ALIGN_CENTER); |
665 | ctk_container_add(CTK_CONTAINER(sensors_applet->applet)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_container_get_type () )))))), sensors_applet->grid); |
666 | } else { |
667 | /* remove all children if grid already exists so we can start again */ |
668 | /* save a list of the old children for later */ |
669 | old_grid_children = ctk_container_get_children(CTK_CONTAINER(sensors_applet->grid)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_container_get_type ())) ))))); |
670 | |
671 | ctk_container_foreach(CTK_CONTAINER(sensors_applet->grid)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_container_get_type ())) )))), |
672 | sensors_applet_pack_display_empty_grid_cb, |
673 | sensors_applet->grid); |
674 | } |
675 | /* pack icons / labels and values into grid */ |
676 | current_sensor = sensors_applet->active_sensors; |
677 | |
678 | /* if showing labels / icons and values, need to pack labels / icons these first */ |
679 | if (display_mode == DISPLAY_ICON_WITH_VALUE || display_mode == DISPLAY_LABEL_WITH_VALUE) { |
680 | /* loop through columns */ |
681 | for (i = 0; current_sensor != NULL((void*)0) && i < cols; /* increments depends on how we lay them out - see below */) { |
682 | |
683 | /* loop through rows in a column */ |
684 | for (j = 0; current_sensor && j < rows; /* see bottom of for loop*/) { |
685 | /* attach label / icon at this point */ |
686 | if (display_mode == DISPLAY_ICON_WITH_VALUE) { |
687 | if (((ActiveSensor *)(current_sensor->data))->icon) { |
688 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
689 | ((ActiveSensor *)(current_sensor->data))->icon, |
690 | i, j, 1, 1); |
691 | } |
692 | } else { |
693 | if (((ActiveSensor *)(current_sensor->data))->label) { |
694 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
695 | ((ActiveSensor *)(current_sensor->data))->label, |
696 | i, j, 1, 1); |
697 | } |
698 | } |
699 | /* now attach sensor value to either row below or column next to */ |
700 | if (layout_mode == VALUE_BESIDE_LABEL) { |
701 | /* left align labels */ |
702 | if (((ActiveSensor *)(current_sensor->data))->icon) { |
703 | ctk_widget_set_halign (((ActiveSensor *)(current_sensor->data))->icon, CTK_ALIGN_START); |
704 | ctk_widget_set_valign (((ActiveSensor *)(current_sensor->data))->icon, CTK_ALIGN_CENTER); |
705 | } |
706 | if (((ActiveSensor *)(current_sensor->data))->label) { |
707 | ctk_label_set_xalign (CTK_LABEL(((ActiveSensor *)(current_sensor->data))->label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((((ActiveSensor *)(current_sensor->data))->label)), ((ctk_label_get_type ())))))), 0); |
708 | ctk_label_set_yalign (CTK_LABEL(((ActiveSensor *)(current_sensor->data))->label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((((ActiveSensor *)(current_sensor->data))->label)), ((ctk_label_get_type ())))))), 0.5); |
709 | } |
710 | if (((ActiveSensor *)(current_sensor->data))->value) { |
711 | ctk_widget_set_halign (((ActiveSensor *)(current_sensor->data))->value, CTK_ALIGN_START); |
712 | ctk_widget_set_valign (((ActiveSensor *)(current_sensor->data))->value, CTK_ALIGN_CENTER); |
713 | } |
714 | |
715 | /* place value next to label */ |
716 | if (((ActiveSensor *)(current_sensor->data))->value) { |
717 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
718 | ((ActiveSensor *)(current_sensor->data))->value, |
719 | i + 1, j, 1, 1); |
720 | } |
721 | j++; |
722 | } else { /* place value below label */ |
723 | |
724 | /* center align labels */ |
725 | if (((ActiveSensor *)(current_sensor->data))->icon) { |
726 | ctk_widget_set_halign (((ActiveSensor *)(current_sensor->data))->icon, CTK_ALIGN_CENTER); |
727 | ctk_widget_set_valign (((ActiveSensor *)(current_sensor->data))->icon, CTK_ALIGN_CENTER); |
728 | } |
729 | if (((ActiveSensor *)(current_sensor->data))->label) { |
730 | ctk_label_set_xalign (CTK_LABEL(((ActiveSensor *)(current_sensor->data))->label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((((ActiveSensor *)(current_sensor->data))->label)), ((ctk_label_get_type ())))))), 0.5); |
731 | ctk_label_set_yalign (CTK_LABEL(((ActiveSensor *)(current_sensor->data))->label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((((ActiveSensor *)(current_sensor->data))->label)), ((ctk_label_get_type ())))))), 0.5); |
732 | } |
733 | if (((ActiveSensor *)(current_sensor->data))->value) { |
734 | ctk_widget_set_halign (((ActiveSensor *)(current_sensor->data))->value, CTK_ALIGN_CENTER); |
735 | ctk_widget_set_valign (((ActiveSensor *)(current_sensor->data))->value, CTK_ALIGN_CENTER); |
736 | } |
737 | |
738 | if (((ActiveSensor *)(current_sensor->data))->value) { |
739 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
740 | ((ActiveSensor *)(current_sensor->data))->value, |
741 | i, j + 1, 1, 1); |
742 | } |
743 | j += 2; |
744 | } |
745 | current_sensor = g_list_next(current_sensor)((current_sensor) ? (((GList *)(current_sensor))->next) : ( (void*)0)); |
746 | } /* end row loop */ |
747 | |
748 | /* now increment column index as needed */ |
749 | if (layout_mode == VALUE_BESIDE_LABEL) { /* place value next to label */ |
750 | i += 2; |
751 | } else { |
752 | i++; |
753 | } |
754 | } /* end column loop */ |
755 | |
756 | } else { /* not showing labels and icons with values, so just pack either only icons or values */ |
757 | for (i = 0; current_sensor != NULL((void*)0) && i < cols; ++i) { |
758 | for (j = 0; current_sensor!= NULL((void*)0) && j < rows; ++j) { |
759 | if (display_mode == DISPLAY_VALUE) { |
760 | if (((ActiveSensor *)(current_sensor->data))->value) { |
761 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
762 | ((ActiveSensor *)(current_sensor->data))->value, |
763 | i, j, 1, 1); |
764 | } |
765 | } else if (display_mode == DISPLAY_ICON) { |
766 | if (((ActiveSensor *)(current_sensor->data))->value) { |
767 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
768 | ((ActiveSensor *)(current_sensor->data))->icon, |
769 | i, j, 1, 1); |
770 | } |
771 | } else if (display_mode == DISPLAY_GRAPH) { |
772 | if (((ActiveSensor *)(current_sensor->data))->graph) { |
773 | ctk_grid_attach(CTK_GRID(sensors_applet->grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_grid_get_type ())))))), |
774 | ((ActiveSensor *)(current_sensor->data))->graph_frame, |
775 | i, j, 1, 1); |
776 | } |
777 | } |
778 | |
779 | current_sensor = g_list_next(current_sensor)((current_sensor) ? (((GList *)(current_sensor))->next) : ( (void*)0)); |
780 | } |
781 | } |
782 | } |
783 | |
784 | if (old_grid_children != NULL((void*)0)) { |
785 | ctk_container_foreach(CTK_CONTAINER(sensors_applet->grid)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->grid)), ((ctk_container_get_type ())) )))), |
786 | sensors_applet_pack_display_cleanup_refs_cb, |
787 | old_grid_children); |
788 | g_list_free(old_grid_children); |
789 | } |
790 | ctk_widget_show_all(CTK_WIDGET(sensors_applet->applet)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_widget_get_type ()))) )))); |
791 | |
792 | } |
793 | |
794 | /* must unref when done with returned pixbuf */ |
795 | GdkPixbuf *sensors_applet_load_icon(IconType icon_type) { |
796 | CtkIconTheme *icon_theme; |
797 | GdkPixbuf *icon = NULL((void*)0); |
798 | GError *error = NULL((void*)0); |
799 | |
800 | /* try to load the icon */ |
801 | |
802 | /* not allowed to unref or ref icon_theme once we have it */ |
803 | icon_theme = ctk_icon_theme_get_default(); |
804 | icon = ctk_icon_theme_load_icon(icon_theme, |
805 | stock_icons[icon_type], |
806 | DEFAULT_ICON_SIZE22, |
807 | CTK_ICON_LOOKUP_USE_BUILTIN, |
808 | &error); |
809 | |
810 | if (error) { |
811 | g_warning ("Could not load icon: %s", error->message); |
812 | g_error_free(error); |
813 | error = NULL((void*)0); |
814 | |
815 | /* try again with default icon */ |
816 | icon = ctk_icon_theme_load_icon(icon_theme, |
817 | "image-missing", |
818 | DEFAULT_ICON_SIZE22, |
819 | CTK_ICON_LOOKUP_USE_BUILTIN, |
820 | &error); |
821 | |
822 | if (error) { |
823 | /* this will quit sensors-applet but it is a pretty major error so may as well */ |
824 | g_error("Could not load CTK_STOCK_MISSING_IMAGE - major error!!!: %s", error->message); |
825 | g_error_free(error); |
826 | error = NULL((void*)0); |
827 | } |
828 | |
829 | } |
830 | return icon; |
831 | } |
832 | |
833 | // MUST FREE STRINGS AFTER CALLING THIS FUNCTION!! |
834 | gboolean sensors_applet_add_sensor(SensorsApplet *sensors_applet, |
835 | const gchar *path, |
836 | const gchar *id, |
837 | const gchar *label, |
838 | const gchar *interface, |
839 | SensorType type, |
840 | gboolean enable, |
841 | gdouble low_value, |
842 | gdouble high_value, |
843 | gboolean alarm_enable, |
844 | const gchar *low_alarm_command, |
845 | const gchar *high_alarm_command, |
846 | gint alarm_timeout, |
847 | gdouble multiplier, |
848 | gdouble offset, |
849 | IconType icon_type, |
850 | const gchar *graph_color) { |
851 | |
852 | CtkTreeIter interfaces_iter, sensors_iter; |
853 | gboolean not_empty_tree; |
854 | |
855 | gchar *node_interface; |
856 | gboolean not_end_of_interfaces = TRUE(!(0)), interface_exists = FALSE(0); |
857 | gboolean not_end_of_sensors = TRUE(!(0)); |
858 | gchar *sensor_id; |
859 | gchar *sensor_path; |
860 | SensorType sensor_type; |
861 | GdkPixbuf *icon; |
862 | CtkTreePath *tree_path; |
863 | |
864 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 864, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
865 | |
866 | /* assume tree is not empty */ |
867 | not_empty_tree = TRUE(!(0)); |
868 | |
869 | if (NULL((void*)0) == sensors_applet->sensors) { |
870 | |
871 | sensors_applet->sensors = ctk_tree_store_new(N_COLUMNS, |
872 | G_TYPE_STRING((GType) ((16) << (2))), /* path */ |
873 | G_TYPE_STRING((GType) ((16) << (2))), /* id */ |
874 | G_TYPE_STRING((GType) ((16) << (2))), /* label */ |
875 | G_TYPE_STRING((GType) ((16) << (2))), /* interface */ |
876 | G_TYPE_UINT((GType) ((7) << (2))), /* sensor type */ |
877 | G_TYPE_BOOLEAN((GType) ((5) << (2))), /* enable */ |
878 | G_TYPE_BOOLEAN((GType) ((5) << (2))), /* visible */ |
879 | G_TYPE_DOUBLE((GType) ((15) << (2))), /* low value */ |
880 | G_TYPE_DOUBLE((GType) ((15) << (2))), /* high type */ |
881 | G_TYPE_BOOLEAN((GType) ((5) << (2))), /* alarm enable */ |
882 | G_TYPE_STRING((GType) ((16) << (2))), /* low alarm command */ |
883 | G_TYPE_STRING((GType) ((16) << (2))), /* high alarm command */ |
884 | G_TYPE_UINT((GType) ((7) << (2))), /* alarm timeout */ |
885 | G_TYPE_DOUBLE((GType) ((15) << (2))), /* multiplier */ |
886 | G_TYPE_DOUBLE((GType) ((15) << (2))), /* offset */ |
887 | G_TYPE_UINT((GType) ((7) << (2))), /* icon type */ |
888 | GDK_TYPE_PIXBUF(gdk_pixbuf_get_type ()), /* icon pixbuf */ |
889 | G_TYPE_STRING((GType) ((16) << (2)))); /* graph color */ |
890 | |
891 | g_debug("Sensor tree created."); |
892 | |
893 | /* we know tree is actually empty since we just created it */ |
894 | not_empty_tree = FALSE(0); |
Value stored to 'not_empty_tree' is never read | |
895 | } |
896 | |
897 | /* search sensor tree for the parent interface to place this sensor under */ |
898 | for (not_empty_tree = ctk_tree_model_get_iter_first(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &interfaces_iter); |
899 | not_empty_tree && not_end_of_interfaces && !interface_exists; |
900 | not_end_of_interfaces = ctk_tree_model_iter_next(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &interfaces_iter)) { |
901 | |
902 | ctk_tree_model_get(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &interfaces_iter, INTERFACE_COLUMN, &node_interface, -1); |
903 | if (g_ascii_strcasecmp(interface, node_interface) == 0) { |
904 | /* found interface in tree */ |
905 | interface_exists = TRUE(!(0)); |
906 | |
907 | /* now see if this actual sensor already exists within this interface - don't want to add duplicates */ |
908 | /* see if have children */ |
909 | for (not_end_of_sensors = ctk_tree_model_iter_children(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &sensors_iter, &interfaces_iter); |
910 | not_end_of_sensors; |
911 | not_end_of_sensors = ctk_tree_model_iter_next(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &sensors_iter)) { |
912 | |
913 | ctk_tree_model_get(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &sensors_iter, |
914 | PATH_COLUMN, &sensor_path, |
915 | ID_COLUMN, &sensor_id, |
916 | SENSOR_TYPE_COLUMN, &sensor_type, |
917 | -1); |
918 | if (g_ascii_strcasecmp(sensor_id, id) == 0 && g_ascii_strcasecmp(sensor_path, path) == 0 && sensor_type == type) { |
919 | /* sensor already exists so dont add a second time */ |
920 | g_debug("sensor with path: %s, id: %s already exists in tree, not adding a second time", sensor_path, sensor_id); |
921 | g_free(sensor_id); |
922 | g_free(sensor_path); |
923 | g_free(node_interface); |
924 | return FALSE(0); |
925 | } |
926 | g_free(sensor_id); |
927 | g_free(sensor_path); |
928 | } |
929 | g_free(node_interface); |
930 | break; |
931 | } |
932 | g_free(node_interface); |
933 | } |
934 | |
935 | if (!interface_exists) { |
936 | /* add to required plugins hash table so we ensure this |
937 | plugin stays loaded to make sure we have a get sensor |
938 | value function if possible */ |
939 | g_hash_table_insert(sensors_applet->required_plugins, |
940 | g_strdup(interface)g_strdup_inline (interface), |
941 | GINT_TO_POINTER(TRUE)((gpointer) (glong) ((!(0))))); |
942 | g_debug("added interface %s to required plugins", interface); |
943 | |
944 | /* wasn't able to find interface root node so create it */ |
945 | ctk_tree_store_append(sensors_applet->sensors, |
946 | &interfaces_iter, |
947 | NULL((void*)0)); |
948 | |
949 | ctk_tree_store_set(sensors_applet->sensors, |
950 | &interfaces_iter, |
951 | ID_COLUMN, interface, |
952 | INTERFACE_COLUMN, interface, |
953 | VISIBLE_COLUMN, FALSE(0), |
954 | -1); |
955 | g_debug("Added sensor interface %s to tree", interface); |
956 | } |
957 | |
958 | /* then add sensor as a child under interface node - ie assume |
959 | * we either found it or created it - the inteface node that is */ |
960 | |
961 | /* for now just add sensors all in a single list */ |
962 | ctk_tree_store_append(sensors_applet->sensors, &sensors_iter, &interfaces_iter); |
963 | |
964 | /* if sensor is already in settings, load values from there */ |
965 | gchar *applet_path = cafe_panel_applet_get_preferences_path (sensors_applet->applet); |
966 | gchar *gsuid = sensors_applet_settings_get_unique_id (interface, id, path); |
967 | gchar *settings_path = g_strdup_printf ("%s%s/", applet_path, gsuid); |
968 | GSettings *settings = g_settings_new_with_path ("org.cafe.sensors-applet.sensor", settings_path); |
969 | |
970 | /* add hash to temp sorting list */ |
971 | g_variant_builder_add (&gvb_sensors_hash_list, "s", gsuid); |
972 | |
973 | g_free (applet_path); |
974 | g_free (gsuid); |
975 | g_free (settings_path); |
976 | |
977 | gchar *settings_id = g_settings_get_string (settings, ID"id"); |
978 | |
979 | if (settings_id != NULL((void*)0) && settings_id[0] != '\0') { |
980 | enable = g_settings_get_boolean (settings, ENABLED"enabled"); |
981 | icon = sensors_applet_load_icon(g_settings_get_int (settings, ICON_TYPE"icon-type")); |
982 | ctk_tree_store_set(sensors_applet->sensors, |
983 | &sensors_iter, |
984 | PATH_COLUMN, g_settings_get_string (settings, PATH"path"), |
985 | ID_COLUMN, settings_id, |
986 | LABEL_COLUMN, g_settings_get_string (settings, LABEL"label"), |
987 | INTERFACE_COLUMN, g_settings_get_string (settings, INTERFACE"interface"), |
988 | SENSOR_TYPE_COLUMN, g_settings_get_int (settings, SENSOR_TYPE"sensor-type"), |
989 | ENABLE_COLUMN, enable, |
990 | VISIBLE_COLUMN, TRUE(!(0)), |
991 | LOW_VALUE_COLUMN, g_settings_get_double (settings, LOW_VALUE"low-value"), |
992 | HIGH_VALUE_COLUMN, g_settings_get_double (settings, HIGH_VALUE"high-value"), |
993 | ALARM_ENABLE_COLUMN, g_settings_get_boolean (settings, ALARM_ENABLED"alarm-enabled"), |
994 | ALARM_TIMEOUT_COLUMN, g_settings_get_int (settings, ALARM_TIMEOUT"alarm-timeout"), |
995 | LOW_ALARM_COMMAND_COLUMN, g_settings_get_string (settings, LOW_ALARM_COMMAND"low-alarm-command"), |
996 | HIGH_ALARM_COMMAND_COLUMN, g_settings_get_string (settings, HIGH_ALARM_COMMAND"high-alarm-command"), |
997 | MULTIPLIER_COLUMN, g_settings_get_double (settings, MULTIPLIER"multiplier"), |
998 | OFFSET_COLUMN, g_settings_get_double (settings, OFFSET"offset"), |
999 | ICON_TYPE_COLUMN, g_settings_get_int (settings, ICON_TYPE"icon-type"), |
1000 | ICON_PIXBUF_COLUMN, icon, |
1001 | GRAPH_COLOR_COLUMN, g_settings_get_string (settings, GRAPH_COLOR"graph-color"), |
1002 | -1); |
1003 | g_free (settings_id); |
1004 | } else { |
1005 | icon = sensors_applet_load_icon(icon_type); |
1006 | ctk_tree_store_set(sensors_applet->sensors, |
1007 | &sensors_iter, |
1008 | PATH_COLUMN, path, |
1009 | ID_COLUMN, id, |
1010 | LABEL_COLUMN, label, |
1011 | INTERFACE_COLUMN, interface, |
1012 | SENSOR_TYPE_COLUMN, type, |
1013 | ENABLE_COLUMN, enable, |
1014 | VISIBLE_COLUMN, TRUE(!(0)), |
1015 | LOW_VALUE_COLUMN, low_value, |
1016 | HIGH_VALUE_COLUMN, high_value, |
1017 | ALARM_ENABLE_COLUMN, alarm_enable, |
1018 | ALARM_TIMEOUT_COLUMN, alarm_timeout, |
1019 | LOW_ALARM_COMMAND_COLUMN, low_alarm_command, |
1020 | HIGH_ALARM_COMMAND_COLUMN, high_alarm_command, |
1021 | MULTIPLIER_COLUMN, multiplier, |
1022 | OFFSET_COLUMN, offset, |
1023 | ICON_TYPE_COLUMN, icon_type, |
1024 | ICON_PIXBUF_COLUMN, icon, |
1025 | GRAPH_COLOR_COLUMN, graph_color, |
1026 | -1); |
1027 | } |
1028 | g_object_unref (settings); |
1029 | g_debug("added sensor %s to tree", path); |
1030 | |
1031 | /* remove reference to icon as tree now has ref */ |
1032 | g_object_unref(icon); |
1033 | |
1034 | /* create the active sensor */ |
1035 | if (enable) { |
1036 | tree_path = ctk_tree_model_get_path(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), &sensors_iter); |
1037 | sensors_applet_sensor_enabled(sensors_applet, tree_path); |
1038 | ctk_tree_path_free(tree_path); |
1039 | } |
1040 | return TRUE(!(0)); |
1041 | } |
1042 | |
1043 | static ActiveSensor *sensors_applet_find_active_sensor(SensorsApplet *sensors_applet, CtkTreePath *path) { |
1044 | CtkTreePath *sensor_tree_path; |
1045 | GList *current_sensor; |
1046 | |
1047 | for (current_sensor = sensors_applet->active_sensors; current_sensor != NULL((void*)0); current_sensor = g_list_next(current_sensor)((current_sensor) ? (((GList *)(current_sensor))->next) : ( (void*)0))) { |
1048 | sensor_tree_path = ctk_tree_row_reference_get_path(((ActiveSensor *)(current_sensor->data))->sensor_row); |
1049 | |
1050 | if (ctk_tree_path_compare(path, sensor_tree_path) == 0) { |
1051 | ctk_tree_path_free(sensor_tree_path); |
1052 | return ((ActiveSensor *)(current_sensor->data)); |
1053 | } |
1054 | ctk_tree_path_free(sensor_tree_path); |
1055 | } |
1056 | return NULL((void*)0); |
1057 | } |
1058 | |
1059 | /* path should be the full path to a file representing the sensor (eg |
1060 | * /dev/hda or /sys/devices/platform/i2c-0/0-0290/temp1_input) */ |
1061 | void sensors_applet_display_layout_changed(SensorsApplet *sensors_applet) { |
1062 | /* update sensors since will need to update icons / graphs etc |
1063 | * if weren't displayed before */ |
1064 | GList *list = NULL((void*)0); |
1065 | for (list = sensors_applet->active_sensors; list != NULL((void*)0); list = list->next) { |
1066 | ActiveSensor *as = (ActiveSensor *)list->data; |
1067 | as->updated = FALSE(0); |
1068 | } |
1069 | sensors_applet_update_active_sensors(sensors_applet); |
1070 | sensors_applet_pack_display(sensors_applet); |
1071 | } |
1072 | |
1073 | void sensors_applet_alarm_off(SensorsApplet *sensors_applet, |
1074 | CtkTreePath *path, |
1075 | NotifType notif_type) { |
1076 | ActiveSensor *active_sensor; |
1077 | |
1078 | if ((active_sensor = sensors_applet_find_active_sensor(sensors_applet, path)) != NULL((void*)0)) { |
1079 | active_sensor_alarm_off(active_sensor, notif_type); |
1080 | } |
1081 | } |
1082 | |
1083 | void sensors_applet_all_alarms_off(SensorsApplet *sensors_applet, CtkTreePath *path) { |
1084 | sensors_applet_alarm_off(sensors_applet, path, LOW_ALARM); |
1085 | sensors_applet_alarm_off(sensors_applet, path, HIGH_ALARM); |
1086 | } |
1087 | |
1088 | void sensors_applet_sensor_enabled(SensorsApplet *sensors_applet, CtkTreePath *path) { |
1089 | ActiveSensor *active_sensor; |
1090 | |
1091 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1091, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
1092 | g_assert(path)do { if (path) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1092, ((const char*) (__func__)), "path" ); } while (0); |
1093 | |
1094 | active_sensor = active_sensor_new(sensors_applet, ctk_tree_row_reference_new(CTK_TREE_MODEL(sensors_applet->sensors)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->sensors)), ((ctk_tree_model_get_type ( ))))))), path)); |
1095 | active_sensor_update(active_sensor, sensors_applet); |
1096 | |
1097 | /* keep list sorted */ |
1098 | sensors_applet->active_sensors = g_list_insert_sorted(sensors_applet->active_sensors, |
1099 | active_sensor, |
1100 | (GCompareFunc)active_sensor_compare); |
1101 | |
1102 | sensors_applet_pack_display(sensors_applet); |
1103 | } |
1104 | |
1105 | void sensors_applet_reorder_sensors(SensorsApplet *sensors_applet) { |
1106 | sensors_applet->active_sensors = g_list_sort(sensors_applet->active_sensors, (GCompareFunc)active_sensor_compare); |
1107 | |
1108 | sensors_applet_pack_display(sensors_applet); |
1109 | } |
1110 | |
1111 | void sensors_applet_sensor_disabled(SensorsApplet *sensors_applet, CtkTreePath *path) { |
1112 | |
1113 | ActiveSensor *active_sensor; |
1114 | |
1115 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1115, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
1116 | g_assert(path)do { if (path) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1116, ((const char*) (__func__)), "path" ); } while (0); |
1117 | |
1118 | if ((active_sensor = sensors_applet_find_active_sensor(sensors_applet, path)) != NULL((void*)0)) { |
1119 | g_debug("Destroying active sensor..."); |
1120 | |
1121 | g_debug("-- removing from list..."); |
1122 | sensors_applet->active_sensors = g_list_remove(sensors_applet->active_sensors, active_sensor); |
1123 | g_debug("-- repacking display...."); |
1124 | sensors_applet_pack_display(sensors_applet); |
1125 | |
1126 | active_sensor_destroy(active_sensor); |
1127 | } |
1128 | } |
1129 | |
1130 | void sensors_applet_update_sensor(SensorsApplet *sensors_applet, CtkTreePath *path) { |
1131 | ActiveSensor *active_sensor; |
1132 | |
1133 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1133, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
1134 | g_assert(path)do { if (path) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1134, ((const char*) (__func__)), "path" ); } while (0); |
1135 | |
1136 | if ((active_sensor = sensors_applet_find_active_sensor(sensors_applet, path)) != NULL((void*)0)) { |
1137 | active_sensor_update(active_sensor, sensors_applet); |
1138 | } |
1139 | } |
1140 | |
1141 | void sensors_applet_icon_changed(SensorsApplet *sensors_applet, CtkTreePath *path) { |
1142 | ActiveSensor *active_sensor; |
1143 | |
1144 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1144, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
1145 | g_assert(path)do { if (path) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1145, ((const char*) (__func__)), "path" ); } while (0); |
1146 | |
1147 | if ((active_sensor = sensors_applet_find_active_sensor(sensors_applet, path)) != NULL((void*)0)) { |
1148 | active_sensor_icon_changed(active_sensor, sensors_applet); |
1149 | } |
1150 | } |
1151 | |
1152 | /* Cycle thru ActiveSensors and update them all */ |
1153 | gboolean sensors_applet_update_active_sensors(SensorsApplet *sensors_applet) { |
1154 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1154, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
1155 | |
1156 | if (sensors_applet->active_sensors) { |
1157 | g_list_foreach(sensors_applet->active_sensors, |
1158 | (GFunc)active_sensor_update, |
1159 | sensors_applet); |
1160 | return TRUE(!(0)); |
1161 | } |
1162 | return FALSE(0); |
1163 | } |
1164 | |
1165 | /* Cycle thru ActiveSensors and set new graph dimensions */ |
1166 | void sensors_applet_graph_size_changed(SensorsApplet *sensors_applet) { |
1167 | gint dimensions[2]; |
1168 | gint graph_size; |
1169 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1169, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
1170 | |
1171 | if (sensors_applet->active_sensors) { |
1172 | |
1173 | graph_size = g_settings_get_int (sensors_applet->settings, GRAPH_SIZE"graph-size"); |
1174 | if (cafe_panel_applet_get_orient(sensors_applet->applet) == CAFE_PANEL_APPLET_ORIENT_UP || |
1175 | cafe_panel_applet_get_orient(sensors_applet->applet) == CAFE_PANEL_APPLET_ORIENT_DOWN) { |
1176 | |
1177 | /* is horizontal so set graph_size as width */ |
1178 | dimensions[0] = graph_size; |
1179 | dimensions[1] = sensors_applet->size; |
1180 | } else { |
1181 | dimensions[0] = sensors_applet->size; |
1182 | dimensions[1] = graph_size; |
1183 | } |
1184 | |
1185 | g_list_foreach(sensors_applet->active_sensors, |
1186 | (GFunc)active_sensor_update_graph_dimensions, |
1187 | &dimensions); |
1188 | } |
1189 | |
1190 | } |
1191 | |
1192 | gdouble sensors_applet_convert_temperature(gdouble value, TemperatureScale old, TemperatureScale new) { |
1193 | |
1194 | switch (old) { |
1195 | case KELVIN: |
1196 | switch (new) { |
1197 | case CELSIUS: |
1198 | value = value - 273.0; |
1199 | break; |
1200 | case FAHRENHEIT: |
1201 | value = (9.0 * (value - 273) / 5.0) + 32.0; |
1202 | break; |
1203 | case KELVIN: |
1204 | break; |
1205 | } |
1206 | break; |
1207 | |
1208 | case CELSIUS: |
1209 | switch (new) { |
1210 | case FAHRENHEIT: |
1211 | value = (9.0 * value / 5.0) + 32.0; |
1212 | break; |
1213 | case KELVIN: |
1214 | value = value + 273.0; |
1215 | break; |
1216 | case CELSIUS: |
1217 | break; |
1218 | } |
1219 | break; |
1220 | |
1221 | case FAHRENHEIT: |
1222 | switch (new) { |
1223 | case CELSIUS: |
1224 | value = (5.0 * (value - 32.0) / 9.0); |
1225 | break; |
1226 | case KELVIN: |
1227 | value = (5.0 * (value - 32.0) / 9.0) + 273.0; |
1228 | break; |
1229 | case FAHRENHEIT: |
1230 | break; |
1231 | } |
1232 | break; |
1233 | } |
1234 | return value; |
1235 | } |
1236 | |
1237 | void sensors_applet_init(SensorsApplet *sensors_applet) { |
1238 | |
1239 | g_assert(sensors_applet)do { if (sensors_applet) ; else g_assertion_message_expr ("sensors-applet" , "sensors-applet.c", 1239, ((const char*) (__func__)), "sensors_applet" ); } while (0); |
1240 | g_assert(sensors_applet->applet)do { if (sensors_applet->applet) ; else g_assertion_message_expr ("sensors-applet", "sensors-applet.c", 1240, ((const char*) ( __func__)), "sensors_applet->applet"); } while (0); |
1241 | |
1242 | CtkActionGroup *action_group; |
1243 | gchar *ui_path; |
1244 | |
1245 | /* Have our background automatically painted. */ |
1246 | cafe_panel_applet_set_background_widget(CAFE_PANEL_APPLET(sensors_applet->applet)((((CafePanelApplet*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((cafe_panel_applet_get_type ())))))), CTK_WIDGET(sensors_applet->applet)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_widget_get_type ()))) )))); |
1247 | |
1248 | /* plugin functions are stored as name -> get_value_function pairs so |
1249 | * use standard string functions on hash table */ |
1250 | sensors_applet->plugins = g_hash_table_new(g_str_hash, g_str_equal); |
1251 | |
1252 | sensors_applet->required_plugins = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL((void*)0)); |
1253 | |
1254 | /* initialise size */ |
1255 | sensors_applet->size = DEFAULT_APPLET_SIZE24; |
1256 | |
1257 | cafe_panel_applet_set_flags(sensors_applet->applet, CAFE_PANEL_APPLET_EXPAND_MINOR); |
1258 | |
1259 | g_signal_connect(sensors_applet->applet, "destroy",g_signal_connect_data ((sensors_applet->applet), ("destroy" ), (((GCallback) (destroy_cb))), (sensors_applet), ((void*)0) , (GConnectFlags) 0) |
1260 | G_CALLBACK(destroy_cb),g_signal_connect_data ((sensors_applet->applet), ("destroy" ), (((GCallback) (destroy_cb))), (sensors_applet), ((void*)0) , (GConnectFlags) 0) |
1261 | sensors_applet)g_signal_connect_data ((sensors_applet->applet), ("destroy" ), (((GCallback) (destroy_cb))), (sensors_applet), ((void*)0) , (GConnectFlags) 0); |
1262 | |
1263 | /* init gsettings */ |
1264 | sensors_applet->settings = cafe_panel_applet_settings_new (sensors_applet->applet, "org.cafe.sensors-applet"); |
1265 | |
1266 | |
1267 | /* set up builder for sorting verification */ |
1268 | g_variant_builder_init (&gvb_sensors_hash_list, G_VARIANT_TYPE ("as")(g_variant_type_checked_ (("as")))); |
1269 | |
1270 | /* set up / load sensors from the plugins */ |
1271 | sensors_applet_plugins_load_all(sensors_applet); |
1272 | |
1273 | /* set sorting hash array */ |
1274 | GVariant *gv_temp = g_variant_builder_end (&gvb_sensors_hash_list); |
1275 | sensors_applet->sensors_hash_array = g_variant_dup_strv (gv_temp, NULL((void*)0)); |
1276 | g_variant_unref (gv_temp); |
1277 | |
1278 | /* sort sensors based on saved sorting */ |
1279 | sensors_applet_settings_sort_sensors(sensors_applet); |
1280 | |
1281 | /* free hash array */ |
1282 | g_strfreev (sensors_applet->sensors_hash_array); |
1283 | |
1284 | |
1285 | /* should have created sensors tree above, but if have not was because we couldn't find any sensors */ |
1286 | if (NULL((void*)0) == sensors_applet->sensors) { |
1287 | CtkWidget *label; |
1288 | label = ctk_label_new(_("No sensors found!")gettext ("No sensors found!")); |
1289 | ctk_container_add(CTK_CONTAINER(sensors_applet->applet)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_container_get_type () )))))), label); |
1290 | ctk_widget_show_all(CTK_WIDGET(sensors_applet->applet)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_widget_get_type ()))) )))); |
1291 | return; |
1292 | } |
1293 | |
1294 | /* only do menu and signal connections if sensors are found */ |
1295 | action_group = ctk_action_group_new ("Sensors Applet Actions"); |
1296 | ctk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE"cafe-sensors-applet"); |
1297 | ctk_action_group_add_actions (action_group, |
1298 | sensors_applet_menu_actions, |
1299 | G_N_ELEMENTS (sensors_applet_menu_actions)(sizeof (sensors_applet_menu_actions) / sizeof ((sensors_applet_menu_actions )[0])), |
1300 | sensors_applet); |
1301 | ui_path = g_build_filename (UIDIR"/usr/share/cafe-sensors-applet/ui", SENSORS_APPLET_MENU_FILE"SensorsApplet.xml", NULL((void*)0)); |
1302 | cafe_panel_applet_setup_menu_from_file (sensors_applet->applet, ui_path, action_group); |
1303 | g_free (ui_path); |
1304 | g_object_unref (action_group); |
1305 | |
1306 | g_signal_connect(sensors_applet->applet, "style-set",g_signal_connect_data ((sensors_applet->applet), ("style-set" ), (((GCallback) (style_set_cb))), (sensors_applet), ((void*) 0), (GConnectFlags) 0) |
1307 | G_CALLBACK(style_set_cb),g_signal_connect_data ((sensors_applet->applet), ("style-set" ), (((GCallback) (style_set_cb))), (sensors_applet), ((void*) 0), (GConnectFlags) 0) |
1308 | sensors_applet)g_signal_connect_data ((sensors_applet->applet), ("style-set" ), (((GCallback) (style_set_cb))), (sensors_applet), ((void*) 0), (GConnectFlags) 0); |
1309 | |
1310 | g_signal_connect(G_OBJECT(sensors_applet->applet), "change_orient",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("change_orient"), (((GCallback) ( change_orient_cb))), (sensors_applet), ((void*)0), (GConnectFlags ) 0) |
1311 | G_CALLBACK(change_orient_cb),g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("change_orient"), (((GCallback) ( change_orient_cb))), (sensors_applet), ((void*)0), (GConnectFlags ) 0) |
1312 | sensors_applet)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("change_orient"), (((GCallback) ( change_orient_cb))), (sensors_applet), ((void*)0), (GConnectFlags ) 0); |
1313 | |
1314 | g_signal_connect(G_OBJECT(sensors_applet->applet), "size_allocate",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("size_allocate"), (((GCallback) ( size_allocate_cb))), (sensors_applet), ((void*)0), (GConnectFlags ) 0) |
1315 | G_CALLBACK(size_allocate_cb),g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("size_allocate"), (((GCallback) ( size_allocate_cb))), (sensors_applet), ((void*)0), (GConnectFlags ) 0) |
1316 | sensors_applet)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("size_allocate"), (((GCallback) ( size_allocate_cb))), (sensors_applet), ((void*)0), (GConnectFlags ) 0); |
1317 | |
1318 | g_signal_connect(G_OBJECT(sensors_applet->applet), "leave_notify_event",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("leave_notify_event"), (((GCallback ) (mouse_leave_cb))), ((gpointer)sensors_applet), ((void*)0), (GConnectFlags) 0) |
1319 | G_CALLBACK(mouse_leave_cb),g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("leave_notify_event"), (((GCallback ) (mouse_leave_cb))), ((gpointer)sensors_applet), ((void*)0), (GConnectFlags) 0) |
1320 | (gpointer)sensors_applet)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("leave_notify_event"), (((GCallback ) (mouse_leave_cb))), ((gpointer)sensors_applet), ((void*)0), (GConnectFlags) 0); |
1321 | |
1322 | g_signal_connect(G_OBJECT(sensors_applet->applet), "enter_notify_event",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("enter_notify_event"), (((GCallback ) (mouse_enter_cb))), ((gpointer)sensors_applet), ((void*)0), (GConnectFlags) 0) |
1323 | G_CALLBACK(mouse_enter_cb),g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("enter_notify_event"), (((GCallback ) (mouse_enter_cb))), ((gpointer)sensors_applet), ((void*)0), (GConnectFlags) 0) |
1324 | (gpointer)sensors_applet)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((sensors_applet->applet)), (((GType) ( (20) << (2))))))))), ("enter_notify_event"), (((GCallback ) (mouse_enter_cb))), ((gpointer)sensors_applet), ((void*)0), (GConnectFlags) 0); |
1325 | |
1326 | sensors_applet_update_active_sensors(sensors_applet); |
1327 | sensors_applet_pack_display(sensors_applet); |
1328 | |
1329 | sensors_applet->timeout_id = g_timeout_add_seconds(g_settings_get_int(sensors_applet->settings, TIMEOUT"timeout-delay") / 1000, |
1330 | (GSourceFunc)sensors_applet_update_active_sensors, |
1331 | sensors_applet); |
1332 | |
1333 | g_object_set (ctk_settings_get_default (), "ctk-menu-images", TRUE(!(0)), NULL((void*)0)); |
1334 | g_object_set (ctk_settings_get_default (), "ctk-button-images", TRUE(!(0)), NULL((void*)0)); |
1335 | |
1336 | ctk_widget_show_all(CTK_WIDGET(sensors_applet->applet)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sensors_applet->applet)), ((ctk_widget_get_type ()))) )))); |
1337 | } |
1338 |