projects/package-update-indicator

changeset 30:811df672633d

Add fallback icons for KDE-based themes
author Guido Berhoerster <guido+pui@berhoerster.name>
date Wed Aug 28 13:29:23 2019 +0200 (9 months ago)
parents 9fc3e0c1a54b
children 9905d4ae351c
files pui-application.c
line diff
     1.1 --- a/pui-application.c	Wed Jul 24 16:28:17 2019 +0200
     1.2 +++ b/pui-application.c	Wed Aug 28 13:29:23 2019 +0200
     1.3 @@ -62,14 +62,19 @@
     1.4  
     1.5  static GParamSpec *properties[PROP_LAST] = { NULL };
     1.6  
     1.7 -static const gchar *icon_names[PUI_STATE_LAST] = {
     1.8 -    [PUI_STATE_INITIAL] = "system-software-update",
     1.9 -    [PUI_STATE_UP_TO_DATE] = "system-software-update",
    1.10 -    [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available",
    1.11 -    [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent",
    1.12 -    [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out",
    1.13 -    [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot",
    1.14 -    [PUI_STATE_ERROR] = "dialog-warning"
    1.15 +static gchar *icon_names[PUI_STATE_LAST][2] = {
    1.16 +    [PUI_STATE_INITIAL] = { "system-software-update", "update-none" },
    1.17 +    [PUI_STATE_UP_TO_DATE] = { "system-software-update", "update-none" },
    1.18 +    [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = { "software-update-available",
    1.19 +        "update-medium" },
    1.20 +    [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = { "software-update-urgent",
    1.21 +        "update-high" },
    1.22 +    [PUI_STATE_SESSION_RESTART_REQUIRED] = { "system-log-out",
    1.23 +        "system-log-out" },
    1.24 +    [PUI_STATE_SYSTEM_RESTART_REQUIRED] = { "system-reboot",
    1.25 +        "system-reboot" },
    1.26 +    [PUI_STATE_ERROR] = { "dialog-warning",
    1.27 +        "dialog-warning" }
    1.28  };
    1.29  
    1.30  static const GOptionEntry cmd_options[] = {
    1.31 @@ -196,6 +201,9 @@
    1.32  	guint		normal_updates = 0;
    1.33  	gchar		*title = NULL;
    1.34  	gchar		*body = NULL;
    1.35 +	GtkIconTheme	*icon_theme;
    1.36 +	const gchar	* const *icon_namep;
    1.37 +	const gchar	*icon_name;
    1.38  	GApplication	*application = G_APPLICATION(self);
    1.39  	GNotification	*notification = NULL;
    1.40  
    1.41 @@ -301,8 +309,18 @@
    1.42  		    APP_INDICATOR_STATUS_ACTIVE);
    1.43  		break;
    1.44  	}
    1.45 -	app_indicator_set_icon_full(self->indicator, icon_names[self->state],
    1.46 -	    title);
    1.47 +
    1.48 +	/* determine icon name using fallbacks if necessary */
    1.49 +	icon_theme = gtk_icon_theme_get_default();
    1.50 +	for (icon_namep =
    1.51 +	    g_themed_icon_get_names(G_THEMED_ICON(self->icons[self->state])),
    1.52 +	    icon_name = *icon_namep; *icon_namep != NULL; icon_namep++) {
    1.53 +		if (gtk_icon_theme_has_icon(icon_theme, *icon_namep)) {
    1.54 +			icon_name = *icon_namep;
    1.55 +			break;
    1.56 +		}
    1.57 +	}
    1.58 +	app_indicator_set_icon_full(self->indicator, icon_name, title);
    1.59  
    1.60  	/* notification */
    1.61  	switch (self->state) {
    1.62 @@ -338,7 +356,7 @@
    1.63  	}
    1.64  
    1.65  	g_debug("indicator icon: %s, notification title: \"%s\", "
    1.66 -	    "notification body: \"%s\"", icon_names[self->state], title, body);
    1.67 +	    "notification body: \"%s\"", icon_name, title, body);
    1.68  
    1.69  	g_free(body);
    1.70  	g_free(title);
    1.71 @@ -475,7 +493,7 @@
    1.72  
    1.73  	/* load icons */
    1.74  	for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
    1.75 -		self->icons[i] = g_themed_icon_new(icon_names[i]);
    1.76 +		self->icons[i] = g_themed_icon_new_from_names(icon_names[i], 2);
    1.77  	}
    1.78  
    1.79  	/* create settings */