Mercurial > projects > package-update-indicator
comparison pui-application.c @ 30:811df672633d
Add fallback icons for KDE-based themes
author | Guido Berhoerster <guido+pui@berhoerster.name> |
---|---|
date | Wed, 28 Aug 2019 13:29:23 +0200 |
parents | 73081cc299f5 |
children | c4b8785d0b75 |
comparison
equal
deleted
inserted
replaced
29:9fc3e0c1a54b | 30:811df672633d |
---|---|
60 | 60 |
61 extern gboolean restart; | 61 extern gboolean restart; |
62 | 62 |
63 static GParamSpec *properties[PROP_LAST] = { NULL }; | 63 static GParamSpec *properties[PROP_LAST] = { NULL }; |
64 | 64 |
65 static const gchar *icon_names[PUI_STATE_LAST] = { | 65 static gchar *icon_names[PUI_STATE_LAST][2] = { |
66 [PUI_STATE_INITIAL] = "system-software-update", | 66 [PUI_STATE_INITIAL] = { "system-software-update", "update-none" }, |
67 [PUI_STATE_UP_TO_DATE] = "system-software-update", | 67 [PUI_STATE_UP_TO_DATE] = { "system-software-update", "update-none" }, |
68 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available", | 68 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = { "software-update-available", |
69 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent", | 69 "update-medium" }, |
70 [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out", | 70 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = { "software-update-urgent", |
71 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot", | 71 "update-high" }, |
72 [PUI_STATE_ERROR] = "dialog-warning" | 72 [PUI_STATE_SESSION_RESTART_REQUIRED] = { "system-log-out", |
73 "system-log-out" }, | |
74 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = { "system-reboot", | |
75 "system-reboot" }, | |
76 [PUI_STATE_ERROR] = { "dialog-warning", | |
77 "dialog-warning" } | |
73 }; | 78 }; |
74 | 79 |
75 static const GOptionEntry cmd_options[] = { | 80 static const GOptionEntry cmd_options[] = { |
76 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, | 81 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, |
77 N_("Enable debugging messages"), NULL }, | 82 N_("Enable debugging messages"), NULL }, |
194 GSimpleAction *install_updates_action; | 199 GSimpleAction *install_updates_action; |
195 guint important_updates = 0; | 200 guint important_updates = 0; |
196 guint normal_updates = 0; | 201 guint normal_updates = 0; |
197 gchar *title = NULL; | 202 gchar *title = NULL; |
198 gchar *body = NULL; | 203 gchar *body = NULL; |
204 GtkIconTheme *icon_theme; | |
205 const gchar * const *icon_namep; | |
206 const gchar *icon_name; | |
199 GApplication *application = G_APPLICATION(self); | 207 GApplication *application = G_APPLICATION(self); |
200 GNotification *notification = NULL; | 208 GNotification *notification = NULL; |
201 | 209 |
202 install_updates_action = | 210 install_updates_action = |
203 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self), | 211 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self), |
299 case PUI_STATE_ERROR: | 307 case PUI_STATE_ERROR: |
300 app_indicator_set_status(self->indicator, | 308 app_indicator_set_status(self->indicator, |
301 APP_INDICATOR_STATUS_ACTIVE); | 309 APP_INDICATOR_STATUS_ACTIVE); |
302 break; | 310 break; |
303 } | 311 } |
304 app_indicator_set_icon_full(self->indicator, icon_names[self->state], | 312 |
305 title); | 313 /* determine icon name using fallbacks if necessary */ |
314 icon_theme = gtk_icon_theme_get_default(); | |
315 for (icon_namep = | |
316 g_themed_icon_get_names(G_THEMED_ICON(self->icons[self->state])), | |
317 icon_name = *icon_namep; *icon_namep != NULL; icon_namep++) { | |
318 if (gtk_icon_theme_has_icon(icon_theme, *icon_namep)) { | |
319 icon_name = *icon_namep; | |
320 break; | |
321 } | |
322 } | |
323 app_indicator_set_icon_full(self->indicator, icon_name, title); | |
306 | 324 |
307 /* notification */ | 325 /* notification */ |
308 switch (self->state) { | 326 switch (self->state) { |
309 case PUI_STATE_INITIAL: /* FALLTHGROUGH */ | 327 case PUI_STATE_INITIAL: /* FALLTHGROUGH */ |
310 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ | 328 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ |
336 if (notification != NULL) { | 354 if (notification != NULL) { |
337 g_object_unref(notification); | 355 g_object_unref(notification); |
338 } | 356 } |
339 | 357 |
340 g_debug("indicator icon: %s, notification title: \"%s\", " | 358 g_debug("indicator icon: %s, notification title: \"%s\", " |
341 "notification body: \"%s\"", icon_names[self->state], title, body); | 359 "notification body: \"%s\"", icon_name, title, body); |
342 | 360 |
343 g_free(body); | 361 g_free(body); |
344 g_free(title); | 362 g_free(title); |
345 } | 363 } |
346 | 364 |
473 pui_application_actions, G_N_ELEMENTS(pui_application_actions), | 491 pui_application_actions, G_N_ELEMENTS(pui_application_actions), |
474 self); | 492 self); |
475 | 493 |
476 /* load icons */ | 494 /* load icons */ |
477 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) { | 495 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) { |
478 self->icons[i] = g_themed_icon_new(icon_names[i]); | 496 self->icons[i] = g_themed_icon_new_from_names(icon_names[i], 2); |
479 } | 497 } |
480 | 498 |
481 /* create settings */ | 499 /* create settings */ |
482 self->settings = pui_settings_new(); | 500 self->settings = pui_settings_new(); |
483 g_settings_bind(self->settings, "update-command", self, | 501 g_settings_bind(self->settings, "update-command", self, |