updated on Tue Jan 10 04:01:21 UTC 2012
[aur-mirror.git] / network-manager-applet-notify-osd / lp341684_device_sensitive_disconnect_notify.patch
blob5b6f829fad45d1e9ccaba59cfcd5047ecfaf9f1c
1 === modified file 'src/applet-device-wifi.c'
2 ---
3 src/applet-device-wifi.c | 4 +
4 src/applet.c | 136 +++++++++++++++++++++++++++++++++++++++++++++--
5 src/applet.h | 3 +
6 3 files changed, 138 insertions(+), 5 deletions(-)
8 Index: network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe/src/applet-device-wifi.c
9 ===================================================================
10 --- network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe.orig/src/applet-device-wifi.c 2010-06-02 22:00:39.000000000 -0400
11 +++ network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe/src/applet-device-wifi.c 2010-06-02 22:00:58.398889073 -0400
12 @@ -1242,8 +1242,10 @@
13 if (new) {
14 const GByteArray *ssid = nm_access_point_get_ssid (new);
16 - if (ssid)
17 + if (ssid) {
18 esc_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
19 + g_object_set_data_full (G_OBJECT(device), "canonical-last-essid", g_strdup (esc_ssid), (GDestroyNotify) g_free);
20 + }
22 /* Save this BSSID to seen-bssids list */
23 connection = applet_get_exported_connection_for_device (device, applet);
24 Index: network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe/src/applet.c
25 ===================================================================
26 --- network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe.orig/src/applet.c 2010-06-02 22:00:31.000000000 -0400
27 +++ network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe/src/applet.c 2010-06-02 22:00:58.398889073 -0400
28 @@ -40,6 +40,7 @@
29 #include <sys/socket.h>
31 #include <NetworkManagerVPN.h>
32 +#include <nm-device.h>
33 #include <nm-device-ethernet.h>
34 #include <nm-device-wifi.h>
35 #include <nm-gsm-device.h>
36 @@ -74,6 +75,19 @@
38 G_DEFINE_TYPE(NMApplet, nma, G_TYPE_OBJECT)
40 +struct _OfflineNotificationContextInfo {
41 + NMState state;
42 + NMDeviceState device_state;
43 + NMDeviceStateReason device_state_reason;
44 + NMDeviceType device_type;
45 + gchar* title;
46 + const gchar* text;
47 + const gchar* icon;
48 + NotifyUrgency urgency;
49 +};
51 +typedef struct _OfflineNotificationContextInfo OfflineNotificationContextInfo;
53 static NMActiveConnection *
54 applet_get_best_activating_connection (NMApplet *applet, NMDevice **device)
56 @@ -2004,6 +2018,59 @@
57 return NULL;
60 +static gboolean
61 +select_merged_notification_text (OfflineNotificationContextInfo *info)
63 + info->urgency = NOTIFY_URGENCY_LOW;
64 + /* only do something if this is about full offline state */
65 + if(info->state != NM_STATE_UNKNOWN || info->device_state != NM_STATE_UNKNOWN) {
66 + info->urgency = NOTIFY_URGENCY_NORMAL;
67 + if (!info->title)
68 + info->title = g_strdup (_("Network"));
69 + if (info->state == NM_STATE_DISCONNECTED || info->state == NM_STATE_ASLEEP) {
70 + info->urgency = NOTIFY_URGENCY_CRITICAL;
71 + info->text = _("Disconnected - you are now offline");
72 + } else
73 + info->text = _("Disconnected");
75 + switch (info->device_type) {
76 + case NM_DEVICE_TYPE_ETHERNET:
77 + info->icon = "notification-network-ethernet-disconnected";
78 + break;
79 + case NM_DEVICE_TYPE_WIFI:
80 + info->icon = "notification-network-wireless-disconnected";
81 + break;
82 + case NM_DEVICE_TYPE_GSM:
83 + info->icon = "notification-gsm-disconnected";
84 + break;
85 + default:
86 + info->icon = "nm-no-connection";
87 + break;
88 + }
89 + g_debug("going for offline with icon: %s", info->icon);
90 + return TRUE;
91 + }
92 + return FALSE;
95 +static gboolean
96 +foo_online_offline_deferred_notify (gpointer user_data)
98 + NMApplet *applet = NM_APPLET (user_data);
99 + OfflineNotificationContextInfo *info = applet->notification_queue_data;
100 + if(select_merged_notification_text (info))
101 + applet_do_notify (applet, info->urgency, info->title, info->text, info->icon, NULL, NULL, NULL, applet);
102 + else
103 + g_debug("no notification because merged found that we have nothing to say (e.g. not offline)");
104 + if (info->title)
105 + g_free (info->title);
106 + info->title = NULL;
107 + g_free (applet->notification_queue_data);
108 + applet->notification_queue_data = NULL;
109 + applet->deferred_id = 0;
110 + return FALSE;
113 static void
114 applet_common_device_state_changed (NMDevice *device,
115 NMDeviceState new_state,
116 @@ -2019,6 +2086,54 @@
117 vpn_activating = applet_is_any_vpn_activating (applet);
119 switch (new_state) {
120 + case NM_DEVICE_STATE_FAILED:
121 + case NM_DEVICE_STATE_DISCONNECTED:
122 + case NM_DEVICE_STATE_UNMANAGED:
123 + case NM_DEVICE_STATE_UNAVAILABLE:
125 + if (old_state != NM_DEVICE_STATE_FAILED &&
126 + old_state != NM_DEVICE_STATE_UNKNOWN &&
127 + old_state != NM_DEVICE_STATE_DISCONNECTED &&
128 + old_state != NM_DEVICE_STATE_UNMANAGED &&
129 + old_state != NM_DEVICE_STATE_UNAVAILABLE) {
130 + OfflineNotificationContextInfo *info = applet->notification_queue_data;
131 + if (!info) {
132 + info = g_new0(OfflineNotificationContextInfo, 1);
133 + applet->notification_queue_data = info;
136 + info->device_state = new_state;
137 + info->device_state_reason = reason;
138 + if (info->title) {
139 + g_free(info->title);
140 + info->title = NULL;
142 + if (NM_IS_DEVICE_WIFI (device)) {
143 + info->device_type = NM_DEVICE_TYPE_WIFI;
144 + info->title = g_strdup(g_object_get_data (G_OBJECT(device), "canonical-last-essid"));
145 + if (!info->title)
146 + info->title = g_strdup (_("Wireless network"));
147 + } else if (NM_IS_DEVICE_ETHERNET (device)) {
148 + info->device_type = NM_DEVICE_TYPE_ETHERNET;
149 + info->title = g_strdup(_("Wired network"));
150 + } else if (NM_IS_GSM_DEVICE (device)) {
151 + info->device_type = NM_DEVICE_TYPE_GSM;
152 + info->title = g_strdup (_("GSM network"));
153 + } else {
154 + info->device_type = NM_DEVICE_TYPE_UNKNOWN;
155 + info->title = g_strdup (_("Network"));
158 + if (applet->deferred_id)
159 + g_source_remove (applet->deferred_id);
160 + applet->deferred_id = g_timeout_add (1000, foo_online_offline_deferred_notify, applet);
162 + clear_animation_timeout (applet);
163 + } else {
164 + g_debug ("old state indicates that this was not a disconnect %d", old_state);
166 + break;
168 case NM_DEVICE_STATE_PREPARE:
169 case NM_DEVICE_STATE_CONFIG:
170 case NM_DEVICE_STATE_NEED_AUTH:
171 @@ -2096,13 +2211,26 @@
173 NMApplet *applet = NM_APPLET (user_data);
175 + g_debug("foo_client_state_changed_cb");
176 switch (nm_client_get_state (client)) {
177 case NM_STATE_DISCONNECTED:
178 - applet_do_notify_with_pref (applet, _("Disconnected"),
179 - _("The network connection has been disconnected."),
180 - "nm-no-connection",
181 - PREF_DISABLE_DISCONNECTED_NOTIFICATIONS);
182 + case NM_STATE_ASLEEP:
184 + OfflineNotificationContextInfo *info = applet->notification_queue_data;
185 + if (!info) {
186 + info = g_new0(OfflineNotificationContextInfo, 1);
187 + applet->notification_queue_data = info;
190 + info->state = nm_client_get_state (client);
191 + select_merged_notification_text (info);
193 + if (applet->deferred_id)
194 + g_source_remove (applet->deferred_id);
195 + applet->deferred_id = g_timeout_add (1000, foo_online_offline_deferred_notify, applet);
197 /* Fall through */
199 default:
200 break;
202 Index: network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe/src/applet.h
203 ===================================================================
204 --- network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe.orig/src/applet.h 2010-06-02 21:27:49.000000000 -0400
205 +++ network-manager-applet-0.8.1~beta3~git.20100601t071733.8665dfe/src/applet.h 2010-06-02 22:02:28.888889469 -0400
206 @@ -167,6 +167,9 @@
207 GladeXML * info_dialog_xml;
208 NotifyNotification* notification;
209 gboolean notify_actions;
211 + gpointer notification_queue_data;
212 + guint deferred_id;
213 } NMApplet;
215 typedef void (*AppletNewAutoConnectionCallback) (NMConnection *connection,