[network-manager-applet] applet: remove duplicated "you are now connected..." code
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] applet: remove duplicated "you are now connected..." code
- Date: Tue, 21 May 2013 19:59:33 +0000 (UTC)
commit 3ee1bbdfec0c7841de45eeae58d85010beed277c
Author: Dan Winship <danw gnome org>
Date: Fri May 17 07:48:22 2013 -0400
applet: remove duplicated "you are now connected..." code
Most devices types were doing exactly the same thing in their
device_state_changed() method. Move the shared code into applet.c and
add a new notify_connected() method for the non-shared bit. (And make
device_state_changed() optional to implement.)
src/applet-device-broadband.c | 30 +++++-------------------------
src/applet-device-bt.c | 36 +++++++++---------------------------
src/applet-device-cdma.c | 36 +++++++++++++-----------------------
src/applet-device-ethernet.c | 36 +++++++++---------------------------
src/applet-device-gsm.c | 36 +++++++++++++-----------------------
src/applet-device-wifi.c | 28 +++++++++++++++++-----------
src/applet-device-wimax.c | 37 +++++++++----------------------------
src/applet.c | 22 +++++++++++++++++++++-
src/applet.h | 3 +++
9 files changed, 99 insertions(+), 165 deletions(-)
---
diff --git a/src/applet-device-broadband.c b/src/applet-device-broadband.c
index e021278..be5c8e0 100644
--- a/src/applet-device-broadband.c
+++ b/src/applet-device-broadband.c
@@ -793,35 +793,15 @@ add_menu_item (NMDevice *device,
/********************************************************************/
static void
-device_state_changed (NMDevice *device,
- NMDeviceState new_state,
- NMDeviceState old_state,
- NMDeviceStateReason reason,
- NMApplet *applet)
+notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
{
- NMConnection *connection;
- NMSettingConnection *s_con = NULL;
- char *str = NULL;
-
- if (new_state != NM_DEVICE_STATE_ACTIVATED)
- return;
-
- connection = applet_find_active_connection_for_device (device, applet, NULL);
- if (connection) {
- const char *id;
-
- s_con = nm_connection_get_setting_connection (connection);
- id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
- if (id)
- str = g_strdup_printf (_("You are now connected to '%s'."), id);
- }
-
applet_do_notify_with_pref (applet,
_("Connection Established"),
- str ? str : _("You are now connected to the Mobile Broadband network."),
+ msg ? msg : _("You are now connected to the Mobile Broadband network."),
"nm-device-wwan",
PREF_DISABLE_CONNECTED_NOTIFICATIONS);
- g_free (str);
}
/********************************************************************/
@@ -1075,7 +1055,7 @@ applet_device_broadband_get_class (NMApplet *applet)
dclass->new_auto_connection = new_auto_connection;
dclass->add_menu_item = add_menu_item;
dclass->device_added = device_added;
- dclass->device_state_changed = device_state_changed;
+ dclass->notify_connected = notify_connected;
dclass->get_icon = get_icon;
dclass->get_secrets = get_secrets;
dclass->secrets_request_size = sizeof (MobileHelperSecretsInfo);
diff --git a/src/applet-device-bt.c b/src/applet-device-bt.c
index 5a17846..811a637 100644
--- a/src/applet-device-bt.c
+++ b/src/applet-device-bt.c
@@ -175,33 +175,15 @@ bt_add_menu_item (NMDevice *device,
}
static void
-bt_device_state_changed (NMDevice *device,
- NMDeviceState new_state,
- NMDeviceState old_state,
- NMDeviceStateReason reason,
- NMApplet *applet)
+bt_notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
{
- if (new_state == NM_DEVICE_STATE_ACTIVATED) {
- NMConnection *connection;
- NMSettingConnection *s_con = NULL;
- char *str = NULL;
-
- connection = applet_find_active_connection_for_device (device, applet, NULL);
- if (connection) {
- const char *id;
- s_con = nm_connection_get_setting_connection (connection);
- id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
- if (id)
- str = g_strdup_printf (_("You are now connected to '%s'."), id);
- }
-
- applet_do_notify_with_pref (applet,
- _("Connection Established"),
- str ? str : _("You are now connected to the mobile broadband
network."),
- "nm-device-wwan",
- PREF_DISABLE_CONNECTED_NOTIFICATIONS);
- g_free (str);
- }
+ applet_do_notify_with_pref (applet,
+ _("Connection Established"),
+ msg ? msg : _("You are now connected to the mobile broadband network."),
+ "nm-device-wwan",
+ PREF_DISABLE_CONNECTED_NOTIFICATIONS);
}
static GdkPixbuf *
@@ -370,7 +352,7 @@ applet_device_bt_get_class (NMApplet *applet)
dclass->new_auto_connection = bt_new_auto_connection;
dclass->add_menu_item = bt_add_menu_item;
- dclass->device_state_changed = bt_device_state_changed;
+ dclass->notify_connected = bt_notify_connected;
dclass->get_icon = bt_get_icon;
dclass->get_secrets = bt_get_secrets;
dclass->secrets_request_size = sizeof (NMBtSecretsInfo);
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index f45ad33..bee9a5e 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -331,34 +331,23 @@ cdma_device_state_changed (NMDevice *device,
{
CdmaDeviceInfo *info;
- if (new_state == NM_DEVICE_STATE_ACTIVATED) {
- NMConnection *connection;
- NMSettingConnection *s_con = NULL;
- char *str = NULL;
-
- connection = applet_find_active_connection_for_device (device, applet, NULL);
- if (connection) {
- const char *id;
-
- s_con = nm_connection_get_setting_connection (connection);
- id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
- if (id)
- str = g_strdup_printf (_("You are now connected to '%s'."), id);
- }
-
- applet_do_notify_with_pref (applet,
- _("Connection Established"),
- str ? str : _("You are now connected to the CDMA network."),
- "nm-device-wwan",
- PREF_DISABLE_CONNECTED_NOTIFICATIONS);
- g_free (str);
- }
-
/* Start/stop polling of quality and registration when device state changes */
info = g_object_get_data (G_OBJECT (device), "devinfo");
check_start_polling (info);
}
+static void
+cdma_notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
+{
+ applet_do_notify_with_pref (applet,
+ _("Connection Established"),
+ msg ? msg : _("You are now connected to the CDMA network."),
+ "nm-device-wwan",
+ PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+}
+
static GdkPixbuf *
cdma_get_icon (NMDevice *device,
NMDeviceState state,
@@ -748,6 +737,7 @@ applet_device_cdma_get_class (NMApplet *applet)
dclass->new_auto_connection = cdma_new_auto_connection;
dclass->add_menu_item = cdma_add_menu_item;
dclass->device_state_changed = cdma_device_state_changed;
+ dclass->notify_connected = cdma_notify_connected;
dclass->get_icon = cdma_get_icon;
dclass->get_secrets = cdma_get_secrets;
dclass->secrets_request_size = sizeof (MobileHelperSecretsInfo);
diff --git a/src/applet-device-ethernet.c b/src/applet-device-ethernet.c
index 6e63dcb..fecad17 100644
--- a/src/applet-device-ethernet.c
+++ b/src/applet-device-ethernet.c
@@ -246,33 +246,15 @@ ethernet_add_menu_item (NMDevice *device,
}
static void
-ethernet_device_state_changed (NMDevice *device,
- NMDeviceState new_state,
- NMDeviceState old_state,
- NMDeviceStateReason reason,
- NMApplet *applet)
+ethernet_notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
{
- if (new_state == NM_DEVICE_STATE_ACTIVATED) {
- NMConnection *connection;
- NMSettingConnection *s_con = NULL;
- char *str = NULL;
-
- connection = applet_find_active_connection_for_device (device, applet, NULL);
- if (connection) {
- const char *id;
- s_con = nm_connection_get_setting_connection (connection);
- id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
- if (id)
- str = g_strdup_printf (_("You are now connected to '%s'."), id);
- }
-
- applet_do_notify_with_pref (applet,
- _("Connection Established"),
- str ? str : _("You are now connected to the ethernet network."),
- "nm-device-wired",
- PREF_DISABLE_CONNECTED_NOTIFICATIONS);
- g_free (str);
- }
+ applet_do_notify_with_pref (applet,
+ _("Connection Established"),
+ msg ? msg : _("You are now connected to the ethernet network."),
+ "nm-device-wired",
+ PREF_DISABLE_CONNECTED_NOTIFICATIONS);
}
static GdkPixbuf *
@@ -646,7 +628,7 @@ applet_device_ethernet_get_class (NMApplet *applet)
dclass->new_auto_connection = ethernet_new_auto_connection;
dclass->add_menu_item = ethernet_add_menu_item;
- dclass->device_state_changed = ethernet_device_state_changed;
+ dclass->notify_connected = ethernet_notify_connected;
dclass->get_icon = ethernet_get_icon;
dclass->get_secrets = ethernet_get_secrets;
dclass->secrets_request_size = MAX (sizeof (NM8021xInfo), sizeof (NMPppoeInfo));
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index a647fca..ebc7e5f 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -387,34 +387,23 @@ gsm_device_state_changed (NMDevice *device,
{
GsmDeviceInfo *info;
- if (new_state == NM_DEVICE_STATE_ACTIVATED) {
- NMConnection *connection;
- NMSettingConnection *s_con = NULL;
- char *str = NULL;
-
- connection = applet_find_active_connection_for_device (device, applet, NULL);
- if (connection) {
- const char *id;
-
- s_con = nm_connection_get_setting_connection (connection);
- id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
- if (id)
- str = g_strdup_printf (_("You are now connected to '%s'."), id);
- }
-
- applet_do_notify_with_pref (applet,
- _("Connection Established"),
- str ? str : _("You are now connected to the GSM network."),
- "nm-device-wwan",
- PREF_DISABLE_CONNECTED_NOTIFICATIONS);
- g_free (str);
- }
-
/* Start/stop polling of quality and registration when device state changes */
info = g_object_get_data (G_OBJECT (device), "devinfo");
check_start_polling (info);
}
+static void
+gsm_notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
+{
+ applet_do_notify_with_pref (applet,
+ _("Connection Established"),
+ msg ? msg : _("You are now connected to the GSM network."),
+ "nm-device-wwan",
+ PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+}
+
static GdkPixbuf *
gsm_get_icon (NMDevice *device,
NMDeviceState state,
@@ -1224,6 +1213,7 @@ applet_device_gsm_get_class (NMApplet *applet)
dclass->new_auto_connection = gsm_new_auto_connection;
dclass->add_menu_item = gsm_add_menu_item;
dclass->device_state_changed = gsm_device_state_changed;
+ dclass->notify_connected = gsm_notify_connected;
dclass->get_icon = gsm_get_icon;
dclass->get_secrets = gsm_get_secrets;
dclass->secrets_request_size = sizeof (MobileHelperSecretsInfo);
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index fa3d618..9710c6c 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -1244,24 +1244,29 @@ wifi_device_state_changed (NMDevice *device,
NMDeviceStateReason reason,
NMApplet *applet)
{
- NMAccessPoint *new = NULL;
- char *msg;
- char *esc_ssid = NULL;
-
- new = update_active_ap (device, new_state, applet);
+ update_active_ap (device, new_state, applet);
if (new_state == NM_DEVICE_STATE_DISCONNECTED)
queue_avail_access_point_notification (device);
+}
- if (new_state != NM_DEVICE_STATE_ACTIVATED)
- return;
+static void
+wifi_notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
+{
+ NMAccessPoint *ap;
+ char *esc_ssid;
+ char *ssid_msg;
+
+ ap = g_object_get_data (G_OBJECT (device), ACTIVE_AP_TAG);
- esc_ssid = get_ssid_utf8 (new);
- msg = g_strdup_printf (_("You are now connected to the Wi-Fi network '%s'."), esc_ssid);
+ esc_ssid = get_ssid_utf8 (ap);
+ ssid_msg = g_strdup_printf (_("You are now connected to the Wi-Fi network '%s'."), esc_ssid);
applet_do_notify_with_pref (applet, _("Connection Established"),
- msg, "nm-device-wireless",
+ ssid_msg, "nm-device-wireless",
PREF_DISABLE_CONNECTED_NOTIFICATIONS);
- g_free (msg);
+ g_free (ssid_msg);
g_free (esc_ssid);
}
@@ -1697,6 +1702,7 @@ applet_device_wifi_get_class (NMApplet *applet)
dclass->add_menu_item = wifi_add_menu_item;
dclass->device_added = wifi_device_added;
dclass->device_state_changed = wifi_device_state_changed;
+ dclass->notify_connected = wifi_notify_connected;
dclass->get_icon = wifi_get_icon;
dclass->get_secrets = wifi_get_secrets;
dclass->secrets_request_size = sizeof (NMWifiInfo);
diff --git a/src/applet-device-wimax.c b/src/applet-device-wimax.c
index a870c48..df6cca9 100644
--- a/src/applet-device-wimax.c
+++ b/src/applet-device-wimax.c
@@ -398,34 +398,15 @@ wimax_device_added (NMDevice *device, NMApplet *applet)
}
static void
-wimax_device_state_changed (NMDevice *device,
- NMDeviceState new_state,
- NMDeviceState old_state,
- NMDeviceStateReason reason,
- NMApplet *applet)
+wimax_notify_connected (NMDevice *device,
+ const char *msg,
+ NMApplet *applet)
{
- if (new_state == NM_DEVICE_STATE_ACTIVATED) {
- NMConnection *connection;
- NMSettingConnection *s_con = NULL;
- char *str = NULL;
-
- connection = applet_find_active_connection_for_device (device, applet, NULL);
- if (connection) {
- const char *id;
-
- s_con = nm_connection_get_setting_connection (connection);
- id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
- if (id)
- str = g_strdup_printf (_("You are now connected to '%s'."), id);
- }
-
- applet_do_notify_with_pref (applet,
- _("Connection Established"),
- str ? str : _("You are now connected to the WiMAX network."),
- "nm-device-wwan",
- PREF_DISABLE_CONNECTED_NOTIFICATIONS);
- g_free (str);
- }
+ applet_do_notify_with_pref (applet,
+ _("Connection Established"),
+ msg ? msg : _("You are now connected to the WiMAX network."),
+ "nm-device-wwan",
+ PREF_DISABLE_CONNECTED_NOTIFICATIONS);
}
static GdkPixbuf *
@@ -510,7 +491,7 @@ applet_device_wimax_get_class (NMApplet *applet)
dclass->new_auto_connection = wimax_new_auto_connection;
dclass->add_menu_item = wimax_add_menu_item;
dclass->device_added = wimax_device_added;
- dclass->device_state_changed = wimax_device_state_changed;
+ dclass->notify_connected = wimax_notify_connected;
dclass->get_icon = wimax_get_icon;
dclass->get_secrets = wimax_get_secrets;
diff --git a/src/applet.c b/src/applet.c
index 3ab1942..8a57043 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -2268,9 +2268,29 @@ foo_device_state_changed_cb (NMDevice *device,
dclass = get_device_class (device, applet);
g_assert (dclass);
- dclass->device_state_changed (device, new_state, old_state, reason, applet);
+ if (dclass->device_state_changed)
+ dclass->device_state_changed (device, new_state, old_state, reason, applet);
applet_common_device_state_changed (device, new_state, old_state, reason, applet);
+ if ( new_state == NM_DEVICE_STATE_ACTIVATED
+ && !g_settings_get_boolean (applet->gsettings, PREF_DISABLE_CONNECTED_NOTIFICATIONS)) {
+ NMConnection *connection;
+ NMSettingConnection *s_con = NULL;
+ char *str = NULL;
+
+ connection = applet_find_active_connection_for_device (device, applet, NULL);
+ if (connection) {
+ const char *id;
+ s_con = nm_connection_get_setting_connection (connection);
+ id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
+ if (id)
+ str = g_strdup_printf (_("You are now connected to '%s'."), id);
+ }
+
+ dclass->notify_connected (device, str, applet);
+ g_free (str);
+ }
+
applet_schedule_update_icon (applet);
}
diff --git a/src/applet.h b/src/applet.h
index 647500b..b7a50f1 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -241,6 +241,9 @@ struct NMADeviceClass {
NMDeviceState old_state,
NMDeviceStateReason reason,
NMApplet *applet);
+ void (*notify_connected) (NMDevice *device,
+ const char *msg,
+ NMApplet *applet);
/* Device class is expected to return a *referenced* pixbuf, which will
* be unrefed by the icon code. This allows the device class to create
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]