~ubuntu-branches/ubuntu/saucy/network-manager-applet/saucy-updates

« back to all changes in this revision

Viewing changes to debian/patches/hide_policy_items_env_var.patch

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-08-30 14:27:42 UTC
  • Revision ID: package-import@ubuntu.com-20120830142742-wy114kfhl2cy643j
Tags: 0.9.6.2-0ubuntu2
* debian/patches/position_dialogs_to_center_of_the_screen.patch: make sure
  created dialogs (like password requests) are properly centered on the
  screen. (LP: #1043934)
* debian/patches/make_menu_items_invisible_based_on_permissions.patch,
  debian/patches/hide_policy_items_env_var.patch: items that are disallowed
  by the effective PolicyKit policy for a user should be consistently showing
  as such: they should either be insensitive (greyed), or hidden altogether.
  (LP: #1043929)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From: Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
 
2
Subject: Implement support for hiding rather than desensitizing disallowed items
 
3
 
 
4
This is done using a new environment variable that can be set when nm-applet is
 
5
started: NM_APPLET_HIDE_POLICY_ITEMS.
 
6
 
 
7
---
 
8
 src/applet-device-wifi.c |   20 ++++++++++--
 
9
 src/applet.c             |   74 +++++++++++++++++++++++++++++++++++++++++------
 
10
 src/applet.h             |    1 
 
11
 3 files changed, 83 insertions(+), 12 deletions(-)
 
12
 
 
13
Index: b/src/applet.c
 
14
===================================================================
 
15
--- a/src/applet.c
 
16
+++ b/src/applet.c
 
17
@@ -1582,8 +1582,16 @@ nma_menu_device_get_menu_item (NMDevice
 
18
                                       (GClosureNotify) applet_device_info_destroy, 0);
 
19
                if (is_permission_yes (applet, NM_CLIENT_PERMISSION_NETWORK_CONTROL))
 
20
                        gtk_widget_set_sensitive (item, TRUE);
 
21
-               else
 
22
+               else {
 
23
                        gtk_widget_set_sensitive (item, FALSE);
 
24
+                       if (applet->hide_policy_items) {
 
25
+                               /* TODO: is this the final solution? */
 
26
+                               g_object_ref_sink (item);
 
27
+                               g_object_unref (item);
 
28
+                               item = NULL; /* it's safe for this function to return NULL as all the
 
29
+                                                               callers are handling it properly */
 
30
+                       }
 
31
+               }
 
32
                break;
 
33
        }
 
34
        default:
 
35
@@ -1721,6 +1729,8 @@ nma_menu_add_vpn_submenu (GtkWidget *men
 
36
        GtkMenuItem *item;
 
37
        GSList *list, *iter;
 
38
        int num_vpn_active = 0;
 
39
+       gboolean configure_allowed;
 
40
+       gboolean disconnect_allowed;
 
41
 
 
42
        vpn_menu = GTK_MENU (gtk_menu_new ());
 
43
 
 
44
@@ -1788,30 +1798,58 @@ nma_menu_add_vpn_submenu (GtkWidget *men
 
45
                gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
 
46
        }
 
47
 
 
48
+       if (   is_permission_yes (applet, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM)
 
49
+               || is_permission_yes (applet, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN))
 
50
+               configure_allowed = TRUE;
 
51
+       else
 
52
+               configure_allowed = FALSE;
 
53
+
 
54
+       if (is_permission_yes (applet, NM_CLIENT_PERMISSION_NETWORK_CONTROL))
 
55
+               disconnect_allowed = TRUE;
 
56
+       else
 
57
+               disconnect_allowed = FALSE;
 
58
+
 
59
+
 
60
        /* Draw a seperator, but only if we have VPN connections above it */
 
61
        if (list)
 
62
-               nma_menu_add_separator_item (GTK_WIDGET (vpn_menu));
 
63
+               if (   !applet->hide_policy_items
 
64
+                       || configure_allowed
 
65
+                       || disconnect_allowed)
 
66
+                       nma_menu_add_separator_item (GTK_WIDGET (vpn_menu)); /* separator is added if there
 
67
+                                                                                                                                       will be items under it */
 
68
 
 
69
        item = GTK_MENU_ITEM (gtk_menu_item_new_with_mnemonic (_("_Configure VPN...")));
 
70
        g_signal_connect (item, "activate", G_CALLBACK (nma_menu_configure_vpn_item_activate), applet);
 
71
-       gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
 
72
-       if (   is_permission_yes (applet, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM)
 
73
-               || is_permission_yes (applet, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN)) {
 
74
+       if (configure_allowed) {
 
75
                gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
 
76
+               gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
 
77
        } else {
 
78
                gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
 
79
+               if (!applet->hide_policy_items) {
 
80
+                       gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
 
81
+               } else {
 
82
+                       /* TODO: is this the final solution? */
 
83
+                       g_object_ref_sink (item);
 
84
+                       g_object_unref (item);
 
85
+               }
 
86
        }
 
87
 
 
88
        item = GTK_MENU_ITEM (gtk_menu_item_new_with_mnemonic (_("_Disconnect VPN")));
 
89
        g_signal_connect (item, "activate", G_CALLBACK (nma_menu_disconnect_vpn_item_activate), applet);
 
90
-       gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
 
91
-       if (is_permission_yes (applet, NM_CLIENT_PERMISSION_NETWORK_CONTROL)) {
 
92
+       if (disconnect_allowed) {
 
93
                gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
 
94
                if (num_vpn_active == 0)
 
95
                        gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
 
96
-
 
97
+               gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
 
98
        } else {
 
99
                gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
 
100
+               if (!applet->hide_policy_items)
 
101
+                       gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
 
102
+               else {
 
103
+                       /* TODO: is this the final solution? */
 
104
+                       g_object_ref_sink (item);
 
105
+                       g_object_unref (item);
 
106
+               }
 
107
        }
 
108
 
 
109
        g_slist_free (list);
 
110
@@ -1897,6 +1935,8 @@ nma_set_notifications_enabled_cb (GtkWid
 
111
 static void nma_menu_show_cb (GtkWidget *menu, NMApplet *applet)
 
112
 {
 
113
        guint32 n_wireless;
 
114
+       guint n_children;
 
115
+       GList *children = NULL;
 
116
 
 
117
        g_return_if_fail (menu != NULL);
 
118
        g_return_if_fail (applet != NULL);
 
119
@@ -1916,10 +1956,21 @@ static void nma_menu_show_cb (GtkWidget
 
120
        n_wireless = nma_menu_add_devices (menu, applet);
 
121
 
 
122
        if (n_wireless > 0 && nm_client_wireless_get_enabled (applet->nm_client)) {
 
123
+               children = gtk_container_get_children (GTK_CONTAINER (menu));
 
124
+               n_children = g_list_length (children);
 
125
+               g_list_free (children);
 
126
+
 
127
                /* Add the "Hidden wireless network..." entry */
 
128
                nma_menu_add_hidden_network_item (menu, applet);
 
129
                nma_menu_add_create_network_item (menu, applet);
 
130
-               nma_menu_add_separator_item (menu);
 
131
+
 
132
+               children = gtk_container_get_children (GTK_CONTAINER (menu));
 
133
+               if (g_list_length (children) > n_children) {
 
134
+                       /* items were added. Add a separator */
 
135
+                       /* TODO: see TODO comments in the above add_*_network_item functions */
 
136
+                       nma_menu_add_separator_item (menu);
 
137
+               }
 
138
+               g_list_free (children);
 
139
        }
 
140
 
 
141
        nma_menu_add_vpn_submenu (menu, applet);
 
142
@@ -2096,6 +2147,7 @@ nma_context_menu_update (NMApplet *apple
 
143
                 * so set the "Edit Connections..." menu item insensitive.
 
144
                 */
 
145
                gtk_widget_set_sensitive (applet->connections_menu_item, FALSE);
 
146
+               gtk_widget_set_visible (applet->connections_menu_item, !applet->hide_policy_items);
 
147
        }
 
148
 }
 
149
 
 
150
@@ -3992,6 +4044,10 @@ static void nma_init (NMApplet *applet)
 
151
        applet->icon_theme = NULL;
 
152
        applet->notification = NULL;
 
153
        applet->icon_size = 16;
 
154
+
 
155
+       applet->hide_policy_items = FALSE;
 
156
+       if (getenv ("NM_APPLET_HIDE_POLICY_ITEMS"))
 
157
+               applet->hide_policy_items = TRUE;
 
158
 }
 
159
 
 
160
 enum {
 
161
Index: b/src/applet-device-wifi.c
 
162
===================================================================
 
163
--- a/src/applet-device-wifi.c
 
164
+++ b/src/applet-device-wifi.c
 
165
@@ -101,7 +101,6 @@ nma_menu_add_hidden_network_item (GtkWid
 
166
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
167
        gtk_container_add (GTK_CONTAINER (menu_item), label);
 
168
        gtk_widget_show_all (menu_item);
 
169
-       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
170
        g_signal_connect_swapped (menu_item, "activate",
 
171
                                  G_CALLBACK (applet_wifi_connect_to_hidden_network),
 
172
                                  applet);
 
173
@@ -132,6 +131,13 @@ nma_menu_add_hidden_network_item (GtkWid
 
174
        }
 
175
 
 
176
        gtk_widget_set_sensitive (GTK_WIDGET (menu_item), allowed);
 
177
+       if (!allowed && applet->hide_policy_items) {
 
178
+               /* don't add the item if it should be hidden */
 
179
+               /* TODO: is this the final solution? */
 
180
+               g_object_ref_sink (menu_item);
 
181
+               g_object_unref (menu_item);
 
182
+       } else
 
183
+               gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
184
 }
 
185
 
 
186
 gboolean
 
187
@@ -179,13 +185,21 @@ nma_menu_add_create_network_item (GtkWid
 
188
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
189
        gtk_container_add (GTK_CONTAINER (menu_item), label);
 
190
        gtk_widget_show_all (menu_item);
 
191
-       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
192
        g_signal_connect_swapped (menu_item, "activate",
 
193
                                  G_CALLBACK (applet_wifi_create_wifi_network),
 
194
                                  applet);
 
195
 
 
196
-       if (!applet_wifi_can_create_wifi_network (applet))
 
197
+       if (!applet_wifi_can_create_wifi_network (applet)) {
 
198
                gtk_widget_set_sensitive (GTK_WIDGET (menu_item), FALSE);
 
199
+               if (applet->hide_policy_items) {
 
200
+                       /* don't add the item if it should be hidden */
 
201
+                       /* TODO: is this the final solution? */
 
202
+                       g_object_ref_sink (menu_item);
 
203
+                       g_object_unref (menu_item);
 
204
+                       return;
 
205
+               }
 
206
+       }
 
207
+       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
208
 }
 
209
 
 
210
 static void
 
211
Index: b/src/applet.h
 
212
===================================================================
 
213
--- a/src/applet.h
 
214
+++ b/src/applet.h
 
215
@@ -101,6 +101,7 @@ typedef struct
 
216
        GSettings *gsettings;
 
217
 
 
218
        gboolean visible;
 
219
+       gboolean hide_policy_items;
 
220
 
 
221
        /* Permissions */
 
222
        NMClientPermissionResult permissions[NM_CLIENT_PERMISSION_LAST + 1];