Commit 65a594c0 authored by Thomas Haller's avatar Thomas Haller
Browse files

applet: merge branch 'th/applet-icon-crash-bgo762421'

https://bugzilla.gnome.org/show_bug.cgi?id=762421
parents 882bf557 e1075eee
......@@ -2041,6 +2041,10 @@ applet_schedule_update_menu (NMApplet *applet)
static void
foo_set_icon (NMApplet *applet, guint32 layer, GdkPixbuf *pixbuf, char *icon_name)
{
#ifndef ENABLE_INDICATOR
gs_unref_object GdkPixbuf *pixbuf_free = NULL;
#endif
g_return_if_fail (layer == ICON_LAYER_LINK || layer == ICON_LAYER_VPN);
#ifdef ENABLE_INDICATOR
......@@ -2061,10 +2065,7 @@ foo_set_icon (NMApplet *applet, guint32 layer, GdkPixbuf *pixbuf, char *icon_nam
if (applet->icon_layers[layer] == pixbuf)
return;
if (applet->icon_layers[layer]) {
g_object_unref (applet->icon_layers[layer]);
applet->icon_layers[layer] = NULL;
}
g_clear_object (&applet->icon_layers[layer]);
if (pixbuf)
applet->icon_layers[layer] = g_object_ref (pixbuf);
......@@ -2072,7 +2073,7 @@ foo_set_icon (NMApplet *applet, guint32 layer, GdkPixbuf *pixbuf, char *icon_nam
if (applet->icon_layers[0]) {
int i;
pixbuf = gdk_pixbuf_copy (applet->icon_layers[0]);
pixbuf = applet->icon_layers[0];
for (i = ICON_LAYER_LINK + 1; i <= ICON_LAYER_MAX; i++) {
GdkPixbuf *top = applet->icon_layers[i];
......@@ -2080,16 +2081,18 @@ foo_set_icon (NMApplet *applet, guint32 layer, GdkPixbuf *pixbuf, char *icon_nam
if (!top)
continue;
if (!pixbuf_free)
pixbuf = pixbuf_free = gdk_pixbuf_copy (pixbuf);
gdk_pixbuf_composite (top, pixbuf, 0, 0, gdk_pixbuf_get_width (top),
gdk_pixbuf_get_height (top),
0, 0, 1.0, 1.0,
GDK_INTERP_NEAREST, 255);
gdk_pixbuf_get_height (top),
0, 0, 1.0, 1.0,
GDK_INTERP_NEAREST, 255);
}
} else
pixbuf = g_object_ref (nma_icon_check_and_load ("nm-no-connection", applet));
pixbuf = nma_icon_check_and_load ("nm-no-connection", applet);
gtk_status_icon_set_from_pixbuf (applet->status_icon, pixbuf);
g_object_unref (pixbuf);
#endif
}
......@@ -2917,24 +2920,14 @@ applet_agent_cancel_secrets_cb (AppletAgent *agent,
/*****************************************************************************/
static void
nma_clear_icon (GdkPixbuf **icon, NMApplet *applet)
{
g_return_if_fail (icon != NULL);
g_return_if_fail (applet != NULL);
if (*icon && (*icon != applet->fallback_icon)) {
g_object_unref (*icon);
*icon = NULL;
}
}
static void nma_icons_free (NMApplet *applet)
{
int i;
guint i;
g_return_if_fail (NM_IS_APPLET (applet));
for (i = 0; i <= ICON_LAYER_MAX; i++)
nma_clear_icon (&applet->icon_layers[i], applet);
g_clear_object (&applet->icon_layers[i]);
}
GdkPixbuf *
......@@ -2954,13 +2947,13 @@ nma_icon_check_and_load (const char *name, NMApplet *applet)
* the icon to the fallback icon if requested.
*/
if (!(icon = gtk_icon_theme_load_icon (applet->icon_theme, name, applet->icon_size, GTK_ICON_LOOKUP_FORCE_SIZE, &error))) {
g_warning ("Icon %s missing: (%d) %s",
g_warning ("Icon %s missing: %s",
name,
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
error->message);
g_clear_error (&error);
icon = applet->fallback_icon;
if (applet->fallback_icon)
icon = g_object_ref (applet->fallback_icon);
}
g_hash_table_insert (applet->icon_cache, g_strdup (name), icon);
......@@ -2970,13 +2963,13 @@ nma_icon_check_and_load (const char *name, NMApplet *applet)
#include "fallback-icon.h"
static gboolean
nma_icons_reload (NMApplet *applet)
static void
nma_icons_reload (NMApplet *applet, gpointer user_data)
{
GError *error = NULL;
GdkPixbufLoader *loader;
gs_unref_object GdkPixbufLoader *loader = NULL;
g_return_val_if_fail (applet->icon_size > 0, FALSE);
g_return_if_fail (applet->icon_size > 0);
g_hash_table_remove_all (applet->icon_cache);
nma_icons_free (applet);
......@@ -2994,21 +2987,15 @@ nma_icons_reload (NMApplet *applet)
if (!gdk_pixbuf_loader_close (loader, &error))
goto error;
g_clear_object (&applet->fallback_icon);
applet->fallback_icon = gdk_pixbuf_loader_get_pixbuf (loader);
g_return_if_fail (applet->fallback_icon);
g_object_ref (applet->fallback_icon);
g_assert (applet->fallback_icon);
g_object_unref (loader);
return TRUE;
return;
error:
g_warning ("Could not load fallback icon: (%d) %s",
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
g_critical ("Failed loading default-icon: %s", error->message);
g_clear_error (&error);
/* Die if we can't get a fallback icon */
g_assert (FALSE);
return FALSE;
}
static void nma_icons_init (NMApplet *applet)
......@@ -3017,8 +3004,8 @@ static void nma_icons_init (NMApplet *applet)
if (applet->icon_theme) {
g_signal_handlers_disconnect_by_func (applet->icon_theme,
G_CALLBACK (nma_icons_reload),
applet);
G_CALLBACK (nma_icons_reload),
applet);
g_object_unref (G_OBJECT (applet->icon_theme));
}
......@@ -3030,12 +3017,12 @@ static void nma_icons_init (NMApplet *applet)
/* If not done yet, append our search path */
path_appended = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (applet->icon_theme),
"NMAIconPathAppended"));
"NMAIconPathAppended"));
if (path_appended == FALSE) {
gtk_icon_theme_append_search_path (applet->icon_theme, ICONDIR);
g_object_set_data (G_OBJECT (applet->icon_theme),
"NMAIconPathAppended",
GINT_TO_POINTER (TRUE));
"NMAIconPathAppended",
GINT_TO_POINTER (TRUE));
}
g_signal_connect (applet->icon_theme, "changed", G_CALLBACK (nma_icons_reload), applet);
......@@ -3048,7 +3035,7 @@ status_icon_screen_changed_cb (GtkStatusIcon *icon,
NMApplet *applet)
{
nma_icons_init (applet);
nma_icons_reload (applet);
nma_icons_reload (applet, NULL);
}
static gboolean
......@@ -3061,9 +3048,14 @@ status_icon_size_changed_cb (GtkStatusIcon *icon,
/* icon_size may be 0 if for example the panel hasn't given us any space
* yet. We'll get resized later, but for now just load the 16x16 icons.
*/
applet->icon_size = size ? size : 16;
if (size > 0)
applet->icon_size = size;
else {
applet->icon_size = 16;
g_warn_if_fail (size == 0);
}
nma_icons_reload (applet);
nma_icons_reload (applet, NULL);
applet_schedule_update_icon (applet);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment