comparison pui-application.c @ 35:c4b8785d0b75

Back out fallback icon support which does not work as intended The fallback icon support does not work as intended since it depends on gtk_icon_theme_has_icon() in order to determine whether an icon exists in the current icon theme. Contrary to the documentation GtkIconTheme not only falls back to the "hicolor" theme but also to the "Adwaita" and "gnome" themes when looking for icons. The Adwaita theme provides the "system-software-update", "software-update-available", and "software-update-urgent" icons so the fallback will never be used even if the current theme does not provide these icons. SNI host implementations such as the one in KDE Plasma Shell will only look for icon names in the current theme and do not fall back to the "Adwaita" and "gnome" themes.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Fri, 06 Sep 2019 13:49:54 +0200
parents 811df672633d
children 24cba399757f
comparison
equal deleted inserted replaced
34:cf7c73dfdac0 35:c4b8785d0b75
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 gchar *icon_names[PUI_STATE_LAST][2] = { 65 static const gchar *icon_names[PUI_STATE_LAST] = {
66 [PUI_STATE_INITIAL] = { "system-software-update", "update-none" }, 66 [PUI_STATE_INITIAL] = "system-software-update",
67 [PUI_STATE_UP_TO_DATE] = { "system-software-update", "update-none" }, 67 [PUI_STATE_UP_TO_DATE] = "system-software-update",
68 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = { "software-update-available", 68 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available",
69 "update-medium" }, 69 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent",
70 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = { "software-update-urgent", 70 [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out",
71 "update-high" }, 71 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot",
72 [PUI_STATE_SESSION_RESTART_REQUIRED] = { "system-log-out", 72 [PUI_STATE_ERROR] = "dialog-warning"
73 "system-log-out" },
74 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = { "system-reboot",
75 "system-reboot" },
76 [PUI_STATE_ERROR] = { "dialog-warning",
77 "dialog-warning" }
78 }; 73 };
79 74
80 static const GOptionEntry cmd_options[] = { 75 static const GOptionEntry cmd_options[] = {
81 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, 76 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
82 N_("Enable debugging messages"), NULL }, 77 N_("Enable debugging messages"), NULL },
199 GSimpleAction *install_updates_action; 194 GSimpleAction *install_updates_action;
200 guint important_updates = 0; 195 guint important_updates = 0;
201 guint normal_updates = 0; 196 guint normal_updates = 0;
202 gchar *title = NULL; 197 gchar *title = NULL;
203 gchar *body = NULL; 198 gchar *body = NULL;
204 GtkIconTheme *icon_theme;
205 const gchar * const *icon_namep;
206 const gchar *icon_name;
207 GApplication *application = G_APPLICATION(self); 199 GApplication *application = G_APPLICATION(self);
208 GNotification *notification = NULL; 200 GNotification *notification = NULL;
209 201
210 install_updates_action = 202 install_updates_action =
211 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self), 203 G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(self),
307 case PUI_STATE_ERROR: 299 case PUI_STATE_ERROR:
308 app_indicator_set_status(self->indicator, 300 app_indicator_set_status(self->indicator,
309 APP_INDICATOR_STATUS_ACTIVE); 301 APP_INDICATOR_STATUS_ACTIVE);
310 break; 302 break;
311 } 303 }
312 304 app_indicator_set_icon_full(self->indicator, icon_names[self->state],
313 /* determine icon name using fallbacks if necessary */ 305 title);
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);
324 306
325 /* notification */ 307 /* notification */
326 switch (self->state) { 308 switch (self->state) {
327 case PUI_STATE_INITIAL: /* FALLTHGROUGH */ 309 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
328 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ 310 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
354 if (notification != NULL) { 336 if (notification != NULL) {
355 g_object_unref(notification); 337 g_object_unref(notification);
356 } 338 }
357 339
358 g_debug("indicator icon: %s, notification title: \"%s\", " 340 g_debug("indicator icon: %s, notification title: \"%s\", "
359 "notification body: \"%s\"", icon_name, title, body); 341 "notification body: \"%s\"", icon_names[self->state], title, body);
360 342
361 g_free(body); 343 g_free(body);
362 g_free(title); 344 g_free(title);
363 } 345 }
364 346
491 pui_application_actions, G_N_ELEMENTS(pui_application_actions), 473 pui_application_actions, G_N_ELEMENTS(pui_application_actions),
492 self); 474 self);
493 475
494 /* load icons */ 476 /* load icons */
495 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) { 477 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
496 self->icons[i] = g_themed_icon_new_from_names(icon_names[i], 2); 478 self->icons[i] = g_themed_icon_new(icon_names[i]);
497 } 479 }
498 480
499 /* create settings */ 481 /* create settings */
500 self->settings = pui_settings_new(); 482 self->settings = pui_settings_new();
501 g_settings_bind(self->settings, "update-command", self, 483 g_settings_bind(self->settings, "update-command", self,