diff options
author | Pavel Šimerda <psimerda@redhat.com> | 2014-11-23 13:30:46 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-12-17 10:58:16 +0100 |
commit | e0ae9aec366445e9ff6a0acdf4da42a4d74aa522 (patch) | |
tree | dfe2f5df40f361618ae4712ff8565a059d60fdae | |
parent | 7d98929ae23ead5d3d992bdee89edac788f0ea8a (diff) | |
download | network-manager-applet-e0ae9aec366445e9ff6a0acdf4da42a4d74aa522.tar.gz |
return icon name from get_icon() whenever possible
Get rid of all unnecessary pixbuf passing and prepare for appindicator
support that requires icon name passing instead.
-rw-r--r-- | src/applet-device-bond.c | 9 | ||||
-rw-r--r-- | src/applet-device-bridge.c | 9 | ||||
-rw-r--r-- | src/applet-device-broadband.c | 8 | ||||
-rw-r--r-- | src/applet-device-bt.c | 9 | ||||
-rw-r--r-- | src/applet-device-cdma.c | 24 | ||||
-rw-r--r-- | src/applet-device-ethernet.c | 9 | ||||
-rw-r--r-- | src/applet-device-gsm.c | 24 | ||||
-rw-r--r-- | src/applet-device-infiniband.c | 9 | ||||
-rw-r--r-- | src/applet-device-team.c | 9 | ||||
-rw-r--r-- | src/applet-device-vlan.c | 9 | ||||
-rw-r--r-- | src/applet-device-wifi.c | 46 | ||||
-rw-r--r-- | src/applet-device-wimax.c | 9 | ||||
-rw-r--r-- | src/applet.c | 120 | ||||
-rw-r--r-- | src/applet.h | 6 | ||||
-rw-r--r-- | src/mb-menu-item.c | 5 | ||||
-rw-r--r-- | src/mobile-helpers.c | 56 | ||||
-rw-r--r-- | src/mobile-helpers.h | 25 |
17 files changed, 197 insertions, 189 deletions
diff --git a/src/applet-device-bond.c b/src/applet-device-bond.c index d47715df..17c90d11 100644 --- a/src/applet-device-bond.c +++ b/src/applet-device-bond.c @@ -92,15 +92,16 @@ bond_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void bond_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -123,14 +124,12 @@ bond_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-device-wired", applet); + *out_icon_name = "nm-device-wired"; *tip = g_strdup_printf (_("Bond connection '%s' active"), id); break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } static gboolean diff --git a/src/applet-device-bridge.c b/src/applet-device-bridge.c index 78bed304..43215eaa 100644 --- a/src/applet-device-bridge.c +++ b/src/applet-device-bridge.c @@ -92,15 +92,16 @@ bridge_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void bridge_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -123,14 +124,12 @@ bridge_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-device-wired", applet); + *out_icon_name = "nm-device-wired"; *tip = g_strdup_printf (_("Bridge connection '%s' active"), id); break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } static gboolean diff --git a/src/applet-device-broadband.c b/src/applet-device-broadband.c index 856c5fe4..01d4c52c 100644 --- a/src/applet-device-broadband.c +++ b/src/applet-device-broadband.c @@ -616,10 +616,12 @@ broadband_act_to_mb_act (BroadbandDeviceInfo *info) return MB_TECH_UNKNOWN; } -static GdkPixbuf * +static void get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { @@ -627,7 +629,7 @@ get_icon (NMDevice *device, if (!applet->mm1) { g_warning ("ModemManager is not available for modem at %s", nm_device_get_udi (device)); - return NULL; + return; } info = g_object_get_data (G_OBJECT (device), "devinfo"); @@ -636,6 +638,8 @@ get_icon (NMDevice *device, return mobile_helper_get_icon (device, state, connection, + out_pixbuf, + out_icon_name, tip, applet, broadband_state_to_mb_state (info), diff --git a/src/applet-device-bt.c b/src/applet-device-bt.c index 6f34c790..6c9cb212 100644 --- a/src/applet-device-bt.c +++ b/src/applet-device-bt.c @@ -105,15 +105,16 @@ bt_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void bt_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -136,14 +137,12 @@ bt_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-device-wwan", applet); + *out_icon_name = "nm-device-wwan"; *tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id); break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } typedef struct { diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c index af54091d..5abd75d7 100644 --- a/src/applet-device-cdma.c +++ b/src/applet-device-cdma.c @@ -343,10 +343,12 @@ cdma_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void cdma_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { @@ -355,15 +357,17 @@ cdma_get_icon (NMDevice *device, info = g_object_get_data (G_OBJECT (device), "devinfo"); g_assert (info); - return mobile_helper_get_icon (device, - state, - connection, - tip, - applet, - cdma_state_to_mb_state (info), - cdma_act_to_mb_act (info), - info->quality, - info->quality_valid); + mobile_helper_get_icon (device, + state, + connection, + out_pixbuf, + out_icon_name, + tip, + applet, + cdma_state_to_mb_state (info), + cdma_act_to_mb_act (info), + info->quality, + info->quality_valid); } static gboolean diff --git a/src/applet-device-ethernet.c b/src/applet-device-ethernet.c index 7c37079f..60819480 100644 --- a/src/applet-device-ethernet.c +++ b/src/applet-device-ethernet.c @@ -149,15 +149,16 @@ ethernet_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void ethernet_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -180,14 +181,12 @@ ethernet_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting an ethernet network address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-device-wired", applet); + *out_icon_name = g_strdup_printf ("nm-device-wired"); *tip = g_strdup_printf (_("Ethernet network connection '%s' active"), id); break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } /* PPPoE */ diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c index 6a943ed5..b3982240 100644 --- a/src/applet-device-gsm.c +++ b/src/applet-device-gsm.c @@ -399,10 +399,12 @@ gsm_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void gsm_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { @@ -411,15 +413,17 @@ gsm_get_icon (NMDevice *device, info = g_object_get_data (G_OBJECT (device), "devinfo"); g_assert (info); - return mobile_helper_get_icon (device, - state, - connection, - tip, - applet, - gsm_state_to_mb_state (info), - gsm_act_to_mb_act (info), - info->quality, - info->quality_valid); + mobile_helper_get_icon (device, + state, + connection, + out_pixbuf, + out_icon_name, + tip, + applet, + gsm_state_to_mb_state (info), + gsm_act_to_mb_act (info), + info->quality, + info->quality_valid); } static gboolean diff --git a/src/applet-device-infiniband.c b/src/applet-device-infiniband.c index fdf0c8b2..a47ef3c0 100644 --- a/src/applet-device-infiniband.c +++ b/src/applet-device-infiniband.c @@ -145,15 +145,16 @@ infiniband_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void infiniband_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -176,14 +177,12 @@ infiniband_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-device-wired", applet); + *out_icon_name = "nm-device-wired"; *tip = g_strdup_printf (_("InfiniBand connection '%s' active"), id); break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } diff --git a/src/applet-device-team.c b/src/applet-device-team.c index 29868769..3d98ca6f 100644 --- a/src/applet-device-team.c +++ b/src/applet-device-team.c @@ -88,15 +88,16 @@ team_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void team_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -119,14 +120,12 @@ team_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-device-wired", applet); + *out_icon_name = "nm-device-wired"; *tip = g_strdup_printf (_("Team connection '%s' active"), id); break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } static gboolean diff --git a/src/applet-device-vlan.c b/src/applet-device-vlan.c index 81d097ff..b6039dff 100644 --- a/src/applet-device-vlan.c +++ b/src/applet-device-vlan.c @@ -206,15 +206,16 @@ vlan_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void vlan_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -237,14 +238,12 @@ vlan_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-device-wired", applet); + *out_icon_name = "nm-device-wired"; *tip = g_strdup_printf (_("VLAN connection '%s' active"), id); break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } static gboolean diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c index e85a71ed..c67f8b6b 100644 --- a/src/applet-device-wifi.c +++ b/src/applet-device-wifi.c @@ -1246,18 +1246,19 @@ wifi_notify_connected (NMDevice *device, g_free (esc_ssid); } -static GdkPixbuf * +static void wifi_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; NMAccessPoint *ap; - GdkPixbuf *pixbuf = NULL; const char *id; - char *ssid = NULL; + guint8 strength; ap = g_object_get_data (G_OBJECT (device), ACTIVE_AP_TAG); @@ -1281,37 +1282,32 @@ wifi_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting a Wi-Fi network address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: + strength = ap ? nm_access_point_get_strength (ap) : 0; + strength = MIN (strength, 100); + + if (strength > 80) + *out_icon_name = "nm-signal-100"; + else if (strength > 55) + *out_icon_name = "nm-signal-75"; + else if (strength > 30) + *out_icon_name = "nm-signal-50"; + else if (strength > 5) + *out_icon_name = "nm-signal-25"; + else + *out_icon_name = "nm-signal-00"; + if (ap) { - guint8 strength; - - strength = nm_access_point_get_strength (ap); - strength = MIN (strength, 100); - - if (strength > 80) - pixbuf = nma_icon_check_and_load ("nm-signal-100", applet); - else if (strength > 55) - pixbuf = nma_icon_check_and_load ("nm-signal-75", applet); - else if (strength > 30) - pixbuf = nma_icon_check_and_load ("nm-signal-50", applet); - else if (strength > 5) - pixbuf = nma_icon_check_and_load ("nm-signal-25", applet); - else - pixbuf = nma_icon_check_and_load ("nm-signal-00", applet); - - ssid = get_ssid_utf8 (ap); + char *ssid = get_ssid_utf8 (ap); + *tip = g_strdup_printf (_("Wi-Fi network connection '%s' active: %s (%d%%)"), id, ssid, strength); g_free (ssid); - } else { - pixbuf = nma_icon_check_and_load ("nm-signal-00", applet); + } else *tip = g_strdup_printf (_("Wi-Fi network connection '%s' active"), id); - } break; default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } diff --git a/src/applet-device-wimax.c b/src/applet-device-wimax.c index d724c14d..1741b2f4 100644 --- a/src/applet-device-wimax.c +++ b/src/applet-device-wimax.c @@ -404,15 +404,16 @@ wimax_notify_connected (NMDevice *device, PREF_DISABLE_CONNECTED_NOTIFICATIONS); } -static GdkPixbuf * +static void wimax_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; NMWimaxNsp *nsp; guint32 quality = 0; @@ -446,7 +447,7 @@ wimax_get_icon (NMDevice *device, break; case NM_DEVICE_STATE_ACTIVATED: roaming = (nsp_type == NM_WIMAX_NSP_NETWORK_TYPE_ROAMING_PARTNER); - pixbuf = mobile_helper_get_status_pixbuf (quality, + *out_pixbuf = mobile_helper_get_status_pixbuf (quality, TRUE, nsp_type_to_mb_state (nsp_type), MB_TECH_WIMAX, @@ -459,8 +460,6 @@ wimax_get_icon (NMDevice *device, default: break; } - - return pixbuf ? g_object_ref (pixbuf) : NULL; } static gboolean diff --git a/src/applet.c b/src/applet.c index 8848822d..9b7eb5e0 100644 --- a/src/applet.c +++ b/src/applet.c @@ -2378,14 +2378,11 @@ applet_add_default_connection_item (NMDevice *device, /*****************************************************************************/ static void -foo_set_icon (NMApplet *applet, GdkPixbuf *pixbuf, guint32 layer) +foo_set_icon (NMApplet *applet, guint32 layer, GdkPixbuf *pixbuf, char *icon_name) { int i; - if (layer > ICON_LAYER_MAX) { - g_warning ("Tried to icon to invalid layer %d", layer); - return; - } + g_return_if_fail (layer == ICON_LAYER_LINK || layer == ICON_LAYER_VPN); /* Ignore setting of the same icon as is already displayed */ if (applet->icon_layers[layer] == pixbuf) @@ -2421,7 +2418,6 @@ foo_set_icon (NMApplet *applet, GdkPixbuf *pixbuf, guint32 layer) g_object_unref (pixbuf); } - NMRemoteConnection * applet_get_exported_connection_for_device (NMDevice *device, NMApplet *applet) { @@ -2743,10 +2739,12 @@ mm1_client_setup (NMApplet *applet) #endif /* WITH_MODEM_MANAGER_1 */ -static GdkPixbuf * -applet_common_get_device_icon (NMDeviceState state, NMApplet *applet) +static void +applet_common_get_device_icon (NMDeviceState state, + GdkPixbuf **out_pixbuf, + char **out_icon_name, + NMApplet *applet) { - GdkPixbuf *pixbuf = NULL; int stage = -1; switch (state) { @@ -2767,15 +2765,17 @@ applet_common_get_device_icon (NMDeviceState state, NMApplet *applet) if (stage >= 0) { char *name = g_strdup_printf ("nm-stage%02d-connecting%02d", stage + 1, applet->animation_step + 1); - pixbuf = nma_icon_check_and_load (name, applet); - g_free (name); + if (out_pixbuf) + *out_pixbuf = g_object_ref (nma_icon_check_and_load (name, applet)); + if (out_icon_name) + *out_icon_name = name; + else + g_free (name); applet->animation_step++; if (applet->animation_step >= NUM_CONNECTING_FRAMES) applet->animation_step = 0; } - - return pixbuf; } static char * @@ -2814,15 +2814,20 @@ get_tip_for_device_state (NMDevice *device, return tip; } -static GdkPixbuf * -applet_get_device_icon_for_state (NMApplet *applet, char **tip) +static void +applet_get_device_icon_for_state (NMApplet *applet, + GdkPixbuf **out_pixbuf, + char **out_icon_name, + char **out_tip) { NMActiveConnection *active; NMDevice *device = NULL; - GdkPixbuf *pixbuf = NULL; NMDeviceState state = NM_DEVICE_STATE_UNKNOWN; NMADeviceClass *dclass; + g_assert (out_pixbuf && out_icon_name && out_tip); + g_assert (!*out_pixbuf && !*out_icon_name && !*out_tip); + // FIXME: handle multiple device states here /* First show the best activating device's state */ @@ -2841,22 +2846,24 @@ applet_get_device_icon_for_state (NMApplet *applet, char **tip) dclass = get_device_class (device, applet); if (dclass) { NMConnection *connection; + const char *icon_name = NULL; connection = applet_find_active_connection_for_device (device, applet, NULL); - /* device class returns a referenced pixbuf */ - pixbuf = dclass->get_icon (device, state, connection, tip, applet); - if (!*tip) - *tip = get_tip_for_device_state (device, state, connection); + + dclass->get_icon (device, state, connection, out_pixbuf, &icon_name, out_tip, applet); + + if (!*out_pixbuf && icon_name) + *out_pixbuf = g_object_ref (nma_icon_check_and_load (icon_name, applet)); + *out_icon_name = icon_name ? g_strdup (icon_name) : NULL; + if (!*out_tip) + *out_tip = get_tip_for_device_state (device, state, connection); + if (icon_name || *out_pixbuf) + return; + /* Fall through for common icons */ } out: - if (!pixbuf) { - pixbuf = applet_common_get_device_icon (state, applet); - /* reference the pixbuf to match the device class' get_icon() function behavior */ - if (pixbuf) - g_object_ref (pixbuf); - } - return pixbuf; + applet_common_get_device_icon (state, out_pixbuf, out_icon_name, applet); } static char * @@ -2912,7 +2919,7 @@ applet_update_icon (gpointer user_data) NMApplet *applet = NM_APPLET (user_data); GdkPixbuf *pixbuf = NULL; NMState state; - char *dev_tip = NULL, *vpn_tip = NULL; + char *dev_tip = NULL, *vpn_tip = NULL, *icon_name = NULL; NMVPNConnectionState vpn_state = NM_VPN_CONNECTION_STATE_UNKNOWN; gboolean nm_running; NMActiveConnection *active_vpn = NULL; @@ -2932,33 +2939,37 @@ applet_update_icon (gpointer user_data) switch (state) { case NM_STATE_UNKNOWN: case NM_STATE_ASLEEP: - pixbuf = nma_icon_check_and_load ("nm-no-connection", applet); - g_object_ref (pixbuf); + icon_name = g_strdup ("nm-no-connection"); + pixbuf = g_object_ref (nma_icon_check_and_load (icon_name, applet)); dev_tip = g_strdup (_("Networking disabled")); break; case NM_STATE_DISCONNECTED: - pixbuf = nma_icon_check_and_load ("nm-no-connection", applet); - g_object_ref (pixbuf); + icon_name = g_strdup ("nm-no-connection"); + pixbuf = g_object_ref (nma_icon_check_and_load (icon_name, applet)); dev_tip = g_strdup (_("No network connection")); break; default: - pixbuf = applet_get_device_icon_for_state (applet, &dev_tip); + applet_get_device_icon_for_state (applet, &pixbuf, &icon_name, &dev_tip); break; } - foo_set_icon (applet, pixbuf, ICON_LAYER_LINK); + foo_set_icon (applet, ICON_LAYER_LINK, pixbuf, icon_name); if (pixbuf) g_object_unref (pixbuf); + if (icon_name) + g_free (icon_name); /* VPN state next */ pixbuf = NULL; + icon_name = NULL; active_vpn = applet_get_first_active_vpn_connection (applet, &vpn_state); if (active_vpn) { char *name; switch (vpn_state) { case NM_VPN_CONNECTION_STATE_ACTIVATED: - pixbuf = nma_icon_check_and_load ("nm-vpn-active-lock", applet); + icon_name = g_strdup_printf ("nm-vpn-active-lock"); + pixbuf = nma_icon_check_and_load (icon_name, applet); break; case NM_VPN_CONNECTION_STATE_PREPARE: case NM_VPN_CONNECTION_STATE_NEED_AUTH: @@ -2977,29 +2988,24 @@ applet_update_icon (gpointer user_data) } vpn_tip = get_tip_for_vpn (active_vpn, vpn_state, applet); - } - foo_set_icon (applet, pixbuf, ICON_LAYER_VPN); - - g_free (applet->tip); - applet->tip = NULL; - - if (dev_tip || vpn_tip) { - GString *tip; + if (vpn_tip && dev_tip) { + char *tmp; - tip = g_string_new (dev_tip); - - if (vpn_tip) - g_string_append_printf (tip, "%s%s", tip->len ? "\n" : "", vpn_tip); - - if (tip->len) - applet->tip = tip->str; - - g_free (vpn_tip); - g_free (dev_tip); - g_string_free (tip, FALSE); + tmp = g_strdup_printf ("%s\n%s", dev_tip, vpn_tip); + g_free (vpn_tip); + vpn_tip = tmp; + } } + foo_set_icon (applet, ICON_LAYER_VPN, pixbuf, icon_name); + if (icon_name) + g_free (icon_name); + /* update tooltip */ + g_free (applet->tip); + applet->tip = g_strdup (vpn_tip ? vpn_tip : dev_tip); gtk_status_icon_set_tooltip_text (applet->status_icon, applet->tip); + g_free (vpn_tip); + g_free (dev_tip); return FALSE; } @@ -3273,8 +3279,8 @@ nma_icon_check_and_load (const char *name, NMApplet *applet) GError *error = NULL; GdkPixbuf *icon = g_hash_table_lookup (applet->icon_cache, name); - g_return_val_if_fail (name != NULL, NULL); - g_return_val_if_fail (applet != NULL, NULL); + g_assert (name != NULL); + g_assert (applet != NULL); /* icon already loaded successfully */ if (icon) @@ -3290,7 +3296,7 @@ nma_icon_check_and_load (const char *name, NMApplet *applet) (error && error->message) ? error->message : "(unknown)"); g_clear_error (&error); - return applet->fallback_icon; + icon = applet->fallback_icon; } g_hash_table_insert (applet->icon_cache, g_strdup (name), icon); diff --git a/src/applet.h b/src/applet.h index 323ad8a8..66ca9455 100644 --- a/src/applet.h +++ b/src/applet.h @@ -222,13 +222,15 @@ struct NMADeviceClass { const char *msg, NMApplet *applet); - /* Device class is expected to return a *referenced* pixbuf, which will + /* Device class is expected to pass a *referenced* pixbuf, which will * be unrefed by the icon code. This allows the device class to create * a composited pixbuf if necessary and pass the reference to the caller. */ - GdkPixbuf * (*get_icon) (NMDevice *device, + void (*get_icon) (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet); diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c index 4512a023..ee471e27 100644 --- a/src/mb-menu-item.c +++ b/src/mb-menu-item.c @@ -185,8 +185,9 @@ nm_mb_menu_item_new (const char *connection_name, /* And the strength icon, if we have strength information at all */ if (enabled && strength) { - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), - mobile_helper_get_quality_icon (strength, applet)); + GdkPixbuf *pixbuf = nma_icon_check_and_load (mobile_helper_get_quality_icon_name (strength), applet); + + gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), pixbuf); } return GTK_WIDGET (item); diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c index eaa64cf9..9cfb5fe0 100644 --- a/src/mobile-helpers.c +++ b/src/mobile-helpers.c @@ -44,7 +44,7 @@ mobile_helper_get_status_pixbuf (guint32 quality, if (!quality_valid) quality = 0; - qual_pixbuf = mobile_helper_get_quality_icon (quality, applet); + qual_pixbuf = nma_icon_check_and_load (mobile_helper_get_quality_icon_name (quality), applet); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, @@ -78,7 +78,7 @@ mobile_helper_get_status_pixbuf (guint32 quality, 0, 0, 1.0, 1.0, GDK_INTERP_BILINEAR, 255); } else { - tmp = mobile_helper_get_tech_icon (access_tech, applet); + tmp = nma_icon_check_and_load (mobile_helper_get_tech_icon_name (access_tech), applet); if (tmp) { gdk_pixbuf_composite (tmp, pixbuf, 0, 0, gdk_pixbuf_get_width (tmp), @@ -92,43 +92,43 @@ mobile_helper_get_status_pixbuf (guint32 quality, return pixbuf; } -GdkPixbuf * -mobile_helper_get_quality_icon (guint32 quality, NMApplet *applet) +const char * +mobile_helper_get_quality_icon_name (guint32 quality) { if (quality > 80) - return nma_icon_check_and_load ("nm-signal-100", applet); + return "nm-signal-100"; else if (quality > 55) - return nma_icon_check_and_load ("nm-signal-75", applet); + return "nm-signal-75"; else if (quality > 30) - return nma_icon_check_and_load ("nm-signal-50", applet); + return "nm-signal-50"; else if (quality > 5) - return nma_icon_check_and_load ("nm-signal-25", applet); - - return nma_icon_check_and_load ("nm-signal-00", applet); + return "nm-signal-25"; + else + return "nm-signal-00"; } -GdkPixbuf * -mobile_helper_get_tech_icon (guint32 tech, NMApplet *applet) +const char * +mobile_helper_get_tech_icon_name (guint32 tech) { switch (tech) { case MB_TECH_1XRTT: - return nma_icon_check_and_load ("nm-tech-cdma-1x", applet); + return "nm-tech-cdma-1x"; case MB_TECH_EVDO: - return nma_icon_check_and_load ("nm-tech-evdo", applet); + return "nm-tech-evdo"; case MB_TECH_GSM: case MB_TECH_GPRS: - return nma_icon_check_and_load ("nm-tech-gprs", applet); + return "nm-tech-gprs"; case MB_TECH_EDGE: - return nma_icon_check_and_load ("nm-tech-edge", applet); + return "nm-tech-edge"; case MB_TECH_UMTS: - return nma_icon_check_and_load ("nm-tech-umts", applet); + return "nm-tech-umts"; case MB_TECH_HSDPA: case MB_TECH_HSUPA: case MB_TECH_HSPA: case MB_TECH_HSPA_PLUS: - return nma_icon_check_and_load ("nm-tech-hspa", applet); + return "nm-tech-hspa"; case MB_TECH_LTE: - return nma_icon_check_and_load ("nm-tech-lte", applet); + return "nm-tech-lte"; case MB_TECH_WIMAX: default: return NULL; @@ -556,10 +556,12 @@ mobile_helper_get_secrets (NMDeviceModemCapabilities capabilities, /********************************************************************/ -GdkPixbuf * +void mobile_helper_get_icon (NMDevice *device, NMDeviceState state, NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, char **tip, NMApplet *applet, guint32 mb_state, @@ -568,7 +570,6 @@ mobile_helper_get_icon (NMDevice *device, gboolean quality_valid) { NMSettingConnection *s_con; - GdkPixbuf *pixbuf = NULL; const char *id; id = nm_device_get_iface (NM_DEVICE (device)); @@ -591,12 +592,11 @@ mobile_helper_get_icon (NMDevice *device, *tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id); break; case NM_DEVICE_STATE_ACTIVATED: - pixbuf = mobile_helper_get_status_pixbuf (quality, - quality_valid, - mb_state, - mb_tech, - applet); - + *out_pixbuf = mobile_helper_get_status_pixbuf (quality, + quality_valid, + mb_state, + mb_tech, + applet); if ((mb_state != MB_STATE_UNKNOWN) && quality_valid) { gboolean roaming = (mb_state == MB_STATE_ROAMING); @@ -610,8 +610,6 @@ mobile_helper_get_icon (NMDevice *device, default: break; } - - return pixbuf; } /********************************************************************/ diff --git a/src/mobile-helpers.h b/src/mobile-helpers.h index ce20135b..cbb01434 100644 --- a/src/mobile-helpers.h +++ b/src/mobile-helpers.h @@ -62,9 +62,8 @@ GdkPixbuf *mobile_helper_get_status_pixbuf (guint32 quality, guint32 access_tech, NMApplet *applet); -GdkPixbuf *mobile_helper_get_quality_icon (guint32 quality, NMApplet *applet); - -GdkPixbuf *mobile_helper_get_tech_icon (guint32 tech, NMApplet *applet); +const char *mobile_helper_get_quality_icon_name (guint32 quality); +const char *mobile_helper_get_tech_icon_name (guint32 tech); /********************************************************************/ @@ -97,15 +96,17 @@ gboolean mobile_helper_get_secrets (NMDeviceModemCapabilities capabilities, /********************************************************************/ -GdkPixbuf *mobile_helper_get_icon (NMDevice *device, - NMDeviceState state, - NMConnection *connection, - char **tip, - NMApplet *applet, - guint32 mb_state, - guint32 mb_tech, - guint32 quality, - gboolean quality_valid); +void mobile_helper_get_icon (NMDevice *device, + NMDeviceState state, + NMConnection *connection, + GdkPixbuf **out_pixbuf, + const char **out_icon_name, + char **tip, + NMApplet *applet, + guint32 mb_state, + guint32 mb_tech, + guint32 quality, + gboolean quality_valid); /********************************************************************/ |