Mercurial > projects > package-update-indicator
diff 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 |
line wrap: on
line diff
--- a/pui-application.c Wed Jul 24 16:28:17 2019 +0200 +++ b/pui-application.c Wed Aug 28 13:29:23 2019 +0200 @@ -62,14 +62,19 @@ static GParamSpec *properties[PROP_LAST] = { NULL }; -static const gchar *icon_names[PUI_STATE_LAST] = { - [PUI_STATE_INITIAL] = "system-software-update", - [PUI_STATE_UP_TO_DATE] = "system-software-update", - [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available", - [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent", - [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out", - [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot", - [PUI_STATE_ERROR] = "dialog-warning" +static gchar *icon_names[PUI_STATE_LAST][2] = { + [PUI_STATE_INITIAL] = { "system-software-update", "update-none" }, + [PUI_STATE_UP_TO_DATE] = { "system-software-update", "update-none" }, + [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = { "software-update-available", + "update-medium" }, + [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = { "software-update-urgent", + "update-high" }, + [PUI_STATE_SESSION_RESTART_REQUIRED] = { "system-log-out", + "system-log-out" }, + [PUI_STATE_SYSTEM_RESTART_REQUIRED] = { "system-reboot", + "system-reboot" }, + [PUI_STATE_ERROR] = { "dialog-warning", + "dialog-warning" } }; static const GOptionEntry cmd_options[] = { @@ -196,6 +201,9 @@ guint normal_updates = 0; gchar *title = NULL; gchar *body = NULL; + GtkIconTheme *icon_theme; + const gchar * const *icon_namep; + const gchar *icon_name; GApplication *application = G_APPLICATION(self); GNotification *notification = NULL; @@ -301,8 +309,18 @@ APP_INDICATOR_STATUS_ACTIVE); break; } - app_indicator_set_icon_full(self->indicator, icon_names[self->state], - title); + + /* determine icon name using fallbacks if necessary */ + icon_theme = gtk_icon_theme_get_default(); + for (icon_namep = + g_themed_icon_get_names(G_THEMED_ICON(self->icons[self->state])), + icon_name = *icon_namep; *icon_namep != NULL; icon_namep++) { + if (gtk_icon_theme_has_icon(icon_theme, *icon_namep)) { + icon_name = *icon_namep; + break; + } + } + app_indicator_set_icon_full(self->indicator, icon_name, title); /* notification */ switch (self->state) { @@ -338,7 +356,7 @@ } g_debug("indicator icon: %s, notification title: \"%s\", " - "notification body: \"%s\"", icon_names[self->state], title, body); + "notification body: \"%s\"", icon_name, title, body); g_free(body); g_free(title); @@ -475,7 +493,7 @@ /* load icons */ for (i = 0; i < G_N_ELEMENTS(self->icons); i++) { - self->icons[i] = g_themed_icon_new(icon_names[i]); + self->icons[i] = g_themed_icon_new_from_names(icon_names[i], 2); } /* create settings */