~network-manager/network-manager-applet/ubuntu.0.7.1

« back to all changes in this revision

Viewing changes to patches/lpXXX_device_sensitive_disconnect_notify.patch

  • Committer: Alexander Sack
  • Date: 2009-03-19 13:53:35 UTC
  • Revision ID: asac@jwsdot.com-20090319135335-q7oegx3xji05zgfp
* add patch to support device sensitive disconnect/offline notifications;
  this patch queues event from NMClient and NMDevice and then decides what
  kind of disconnect happened and which device was reponsible.
  - add patches/lpXXX_device_sensitive_disconnect_notify.patch
  - update patches/series

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=== modified file 'src/applet-device-wifi.c'
 
2
---
 
3
 src/applet-device-wifi.c |    4 +
 
4
 src/applet.c             |  126 +++++++++++++++++++++++++++++++++++++++++++++--
 
5
 src/applet.h             |    2 
 
6
 3 files changed, 127 insertions(+), 5 deletions(-)
 
7
 
 
8
Index: network-manager-applet-0.7.1~rc3/src/applet-device-wifi.c
 
9
===================================================================
 
10
--- network-manager-applet-0.7.1~rc3.orig/src/applet-device-wifi.c
 
11
+++ network-manager-applet-0.7.1~rc3/src/applet-device-wifi.c
 
12
@@ -1164,18 +1164,20 @@
 
13
                queue_avail_access_point_notification (device);
 
14
 
 
15
        if (new_state != NM_DEVICE_STATE_ACTIVATED)
 
16
                return;
 
17
 
 
18
        if (new) {
 
19
                const GByteArray *ssid = nm_access_point_get_ssid (new);
 
20
 
 
21
-               if (ssid)
 
22
+               if (ssid) {
 
23
                        esc_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
 
24
+                       g_object_set_data_full (G_OBJECT(device), "canonical-last-essid", g_strdup (esc_ssid), (GDestroyNotify) g_free);
 
25
+               }
 
26
 
 
27
                /* Save this BSSID to seen-bssids list */
 
28
                gconf_connection = applet_get_exported_connection_for_device (device, applet);
 
29
                if (gconf_connection && add_seen_bssid (gconf_connection, new))
 
30
                        nma_gconf_connection_save (gconf_connection);
 
31
        }
 
32
 
 
33
        applet_do_notify_with_pref (applet,
 
34
Index: network-manager-applet-0.7.1~rc3/src/applet.c
 
35
===================================================================
 
36
--- network-manager-applet-0.7.1~rc3.orig/src/applet.c
 
37
+++ network-manager-applet-0.7.1~rc3/src/applet.c
 
38
@@ -36,16 +36,17 @@
 
39
 #include <strings.h>
 
40
 #include <gtk/gtk.h>
 
41
 #include <glib/gi18n.h>
 
42
 #include "wireless-helper.h"
 
43
 #include <unistd.h>
 
44
 #include <sys/socket.h>
 
45
 
 
46
 #include <NetworkManagerVPN.h>
 
47
+#include <nm-device.h>
 
48
 #include <nm-device-ethernet.h>
 
49
 #include <nm-device-wifi.h>
 
50
 #include <nm-gsm-device.h>
 
51
 #include <nm-cdma-device.h>
 
52
 #include <nm-utils.h>
 
53
 #include <nm-connection.h>
 
54
 #include <nm-vpn-connection.h>
 
55
 #include <nm-setting-connection.h>
 
56
@@ -69,16 +70,28 @@
 
57
 #include "applet-dbus-manager.h"
 
58
 #include "utils.h"
 
59
 #include "gconf-helpers.h"
 
60
 
 
61
 #define NOTIFY_CAPS_ACTIONS_KEY "actions"
 
62
 
 
63
 G_DEFINE_TYPE(NMApplet, nma, G_TYPE_OBJECT)
 
64
 
 
65
+struct _OfflineNotificationContextInfo {
 
66
+  NMState state;
 
67
+  NMDeviceState device_state;
 
68
+  NMDeviceStateReason device_state_reason;
 
69
+  NMDeviceType device_type;
 
70
+  gchar* title;
 
71
+  const gchar* text;
 
72
+  const gchar* icon;
 
73
+};
 
74
+
 
75
+typedef struct _OfflineNotificationContextInfo OfflineNotificationContextInfo;
 
76
+
 
77
 static NMActiveConnection *
 
78
 applet_get_best_activating_connection (NMApplet *applet, NMDevice **device)
 
79
 {
 
80
        NMActiveConnection *best = NULL;
 
81
        NMDevice *best_dev = NULL;
 
82
        const GPtrArray *connections;
 
83
        int i;
 
84
 
 
85
@@ -1634,27 +1647,119 @@
 
86
                if (!gconf_connection || !nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (gconf_connection)))
 
87
                        continue;
 
88
 
 
89
                return gconf_connection;
 
90
        }
 
91
        return NULL;
 
92
 }
 
93
 
 
94
+static gboolean
 
95
+select_merged_notification_text (OfflineNotificationContextInfo *info)
 
96
+{
 
97
+       /* only do something if this is about full offline state */
 
98
+       if(info->state != NM_STATE_UNKNOWN) {
 
99
+               if (!info->title)
 
100
+                       info->title = g_strdup (_("Network"));
 
101
+               if (info->state == NM_STATE_DISCONNECTED || info->state == NM_STATE_ASLEEP)
 
102
+                       info->text = _("Disconnected - you are now offline");
 
103
+               else
 
104
+                       info->text = _("Disconnected");
 
105
+
 
106
+               switch (info->device_type) {
 
107
+                       case NM_DEVICE_TYPE_ETHERNET:
 
108
+                               info->icon = "notification-network-wired-disconnected";
 
109
+                               break;
 
110
+                       case NM_DEVICE_TYPE_WIFI:
 
111
+                               info->icon = "notification-network-wireless-disconnected";
 
112
+                               break;
 
113
+                       case NM_DEVICE_TYPE_GSM:
 
114
+                               info->icon = "notification-network-gsm-disconnected";
 
115
+                               break;
 
116
+                       default:
 
117
+                               info->icon = "nm-no-connection";
 
118
+                               break;
 
119
+               }
 
120
+               g_debug("going for offline with icon: %s", info->icon);
 
121
+               return TRUE;
 
122
+       }
 
123
+       return FALSE;
 
124
+}
 
125
+
 
126
+static gboolean
 
127
+foo_online_offline_deferred_notify (gpointer user_data)
 
128
+{
 
129
+       NMApplet *applet = NM_APPLET (user_data);
 
130
+       OfflineNotificationContextInfo *info = applet->notification_queue_data;
 
131
+        if(select_merged_notification_text (info))
 
132
+               applet_do_notify (applet, NOTIFY_URGENCY_LOW, info->title, info->text, info->icon, NULL, NULL, NULL, applet);
 
133
+       else
 
134
+               g_debug("no notification because merged found that we have nothing to say (e.g. not offline)");
 
135
+       if (info->title)
 
136
+               g_free (info->title);
 
137
+       info->title = NULL;
 
138
+       g_free (applet->notification_queue_data);
 
139
+       applet->notification_queue_data = NULL;
 
140
+       applet->deferred_id = 0;
 
141
+       return FALSE;
 
142
+}
 
143
+
 
144
+
 
145
 static void
 
146
 applet_common_device_state_changed (NMDevice *device,
 
147
                                     NMDeviceState new_state,
 
148
                                     NMDeviceState old_state,
 
149
                                     NMDeviceStateReason reason,
 
150
                                     NMApplet *applet)
 
151
 {
 
152
        NMConnection *connection;
 
153
        NMActiveConnection *active = NULL;
 
154
+       g_debug("applet_common_device_state_changed");
 
155
 
 
156
        switch (new_state) {
 
157
+       case NM_DEVICE_STATE_FAILED:
 
158
+       case NM_DEVICE_STATE_DISCONNECTED:
 
159
+       case NM_DEVICE_STATE_UNMANAGED:
 
160
+       case NM_DEVICE_STATE_UNAVAILABLE:
 
161
+       {
 
162
+                OfflineNotificationContextInfo *info = applet->notification_queue_data;
 
163
+               if (!info) {
 
164
+                       info = g_new0(OfflineNotificationContextInfo, 1);
 
165
+                       applet->notification_queue_data = info;
 
166
+               }
 
167
+
 
168
+                info->device_state = new_state;
 
169
+                info->device_state_reason = reason;
 
170
+               if (info->title) {
 
171
+                       g_free(info->title);
 
172
+                       info->title = NULL;
 
173
+               }
 
174
+               if (NM_IS_DEVICE_WIFI (device)) {
 
175
+                       info->device_type = NM_DEVICE_TYPE_WIFI;
 
176
+                       info->title = g_strdup(g_object_get_data (G_OBJECT(device), "canonical-last-essid"));
 
177
+                       if (!info->title)
 
178
+                               info->title = g_strdup (_("Wireless network"));
 
179
+               } else if (NM_IS_DEVICE_ETHERNET (device)) {
 
180
+                       info->device_type = NM_DEVICE_TYPE_ETHERNET;
 
181
+                       info->title = g_strdup(_("Wired network"));
 
182
+               } else if (NM_IS_GSM_DEVICE (device)) {
 
183
+                       info->device_type = NM_DEVICE_TYPE_GSM;
 
184
+                       info->title = g_strdup (_("GSM network"));
 
185
+               } else {
 
186
+                       info->device_type = NM_DEVICE_TYPE_UNKNOWN;
 
187
+                       info->title = g_strdup (_("Network"));
 
188
+               }
 
189
+
 
190
+                if (applet->deferred_id)
 
191
+                        g_source_remove (applet->deferred_id);
 
192
+                applet->deferred_id = g_timeout_add (1000, foo_online_offline_deferred_notify, applet);
 
193
+       
 
194
+               clear_animation_timeout (applet);
 
195
+               break;
 
196
+       }
 
197
        case NM_DEVICE_STATE_PREPARE:
 
198
        case NM_DEVICE_STATE_CONFIG:
 
199
        case NM_DEVICE_STATE_NEED_AUTH:
 
200
        case NM_DEVICE_STATE_IP_CONFIG:
 
201
                start_animation_timeout (applet);
 
202
                break;
 
203
        case NM_DEVICE_STATE_ACTIVATED:
 
204
                /* If the device activation was successful, update the corresponding
 
205
@@ -1712,23 +1817,36 @@
 
206
                                     applet);
 
207
 }
 
208
 
 
209
 static void
 
210
 foo_client_state_changed_cb (NMClient *client, GParamSpec *pspec, gpointer user_data)
 
211
 {
 
212
        NMApplet *applet = NM_APPLET (user_data);
 
213
 
 
214
+       g_debug("foo_client_state_changed_cb");
 
215
        switch (nm_client_get_state (client)) {
 
216
        case NM_STATE_DISCONNECTED:
 
217
-               applet_do_notify_with_pref (applet, _("Disconnected"),
 
218
-                                           _("The network connection has been disconnected."),
 
219
-                                           "nm-no-connection",
 
220
-                                           PREF_DISABLE_DISCONNECTED_NOTIFICATIONS);
 
221
+       case NM_STATE_ASLEEP:
 
222
+       {
 
223
+               OfflineNotificationContextInfo *info = applet->notification_queue_data;
 
224
+               if (!info) {
 
225
+                       info = g_new0(OfflineNotificationContextInfo, 1);
 
226
+                       applet->notification_queue_data = info;
 
227
+               }
 
228
+
 
229
+               info->state = nm_client_get_state (client);
 
230
+               select_merged_notification_text (info);
 
231
+
 
232
+               if (applet->deferred_id)
 
233
+                       g_source_remove (applet->deferred_id);
 
234
+               applet->deferred_id = g_timeout_add (1000, foo_online_offline_deferred_notify, applet);
 
235
+
 
236
                /* Fall through */
 
237
+       }
 
238
        default:
 
239
                break;
 
240
        }
 
241
 
 
242
        applet_schedule_update_icon (applet);
 
243
 }
 
244
 
 
245
 static void
 
246
Index: network-manager-applet-0.7.1~rc3/src/applet.h
 
247
===================================================================
 
248
--- network-manager-applet-0.7.1~rc3.orig/src/applet.h
 
249
+++ network-manager-applet-0.7.1~rc3/src/applet.h
 
250
@@ -153,16 +153,18 @@
 
251
        GtkWidget *             info_menu_item;
 
252
        GtkWidget *             connections_menu_item;
 
253
 
 
254
        GladeXML *              info_dialog_xml;
 
255
        NotifyNotification*     notification;
 
256
 
 
257
        /* Notification stuff */
 
258
        gboolean                notify_with_actions;
 
259
+       gpointer notification_queue_data;
 
260
+       guint deferred_id;
 
261
 
 
262
 #ifdef WITH_MBCA
 
263
        GSList *mbca_assistants; /* list of UdiAssistant */
 
264
        GModule *mbca_module;
 
265
        void (*mbca_assistant_abort_func) (MBCAAssistant*);
 
266
        void (*mbca_assistant_present_func) (MBCAAssistant*);
 
267
        MBCAAssistant* (*mbca_assistant_new_func) ();
 
268
        gint (*mbca_assistant_run_for_device_func) (MBCAAssistant*,