1
From: Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
2
Subject: Implement support for hiding rather than desensitizing disallowed items
4
This is done using a new environment variable that can be set when nm-applet is
5
started: NM_APPLET_HIDE_POLICY_ITEMS.
8
src/applet-device-wifi.c | 20 ++++++++++--
9
src/applet.c | 74 +++++++++++++++++++++++++++++++++++++++++------
11
3 files changed, 83 insertions(+), 12 deletions(-)
14
===================================================================
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);
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 */
35
@@ -1721,6 +1729,8 @@ nma_menu_add_vpn_submenu (GtkWidget *men
38
int num_vpn_active = 0;
39
+ gboolean configure_allowed;
40
+ gboolean disconnect_allowed;
42
vpn_menu = GTK_MENU (gtk_menu_new ());
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));
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;
52
+ configure_allowed = FALSE;
54
+ if (is_permission_yes (applet, NM_CLIENT_PERMISSION_NETWORK_CONTROL))
55
+ disconnect_allowed = TRUE;
57
+ disconnect_allowed = FALSE;
60
/* Draw a seperator, but only if we have VPN connections above it */
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 */
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));
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));
82
+ /* TODO: is this the final solution? */
83
+ g_object_ref_sink (item);
84
+ g_object_unref (item);
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);
97
+ gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item));
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));
103
+ /* TODO: is this the final solution? */
104
+ g_object_ref_sink (item);
105
+ g_object_unref (item);
110
@@ -1897,6 +1935,8 @@ nma_set_notifications_enabled_cb (GtkWid
111
static void nma_menu_show_cb (GtkWidget *menu, NMApplet *applet)
115
+ GList *children = NULL;
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);
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);
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);
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);
138
+ g_list_free (children);
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.
145
gtk_widget_set_sensitive (applet->connections_menu_item, FALSE);
146
+ gtk_widget_set_visible (applet->connections_menu_item, !applet->hide_policy_items);
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;
155
+ applet->hide_policy_items = FALSE;
156
+ if (getenv ("NM_APPLET_HIDE_POLICY_ITEMS"))
157
+ applet->hide_policy_items = TRUE;
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),
173
@@ -132,6 +131,13 @@ nma_menu_add_hidden_network_item (GtkWid
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);
183
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
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),
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);
207
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
211
Index: b/src/applet.h
212
===================================================================
215
@@ -101,6 +101,7 @@ typedef struct
216
GSettings *gsettings;
219
+ gboolean hide_policy_items;
222
NMClientPermissionResult permissions[NM_CLIENT_PERMISSION_LAST + 1];