[network-manager-applet/NETWORKMANAGER_APPLET_0_7] applet: add "Disable Notifications" option to right-click menu



commit 5f970b328016e517ecd41c26b1e20062c01a7356
Author: Alex Buell <alex buell munted org uk>
Date:   Mon Dec 7 13:33:49 2009 -0800

    applet: add "Disable Notifications" option to right-click menu
    
    (with a few cleanups and fixes by dcbw to better match the how the
    applet constructs the right-click menu)

 src/applet-device-wifi.c |    6 +---
 src/applet.c             |   47 ++++++++++++++++++++++++++++++++++++++++++++++
 src/applet.h             |   11 +++++++--
 3 files changed, 57 insertions(+), 7 deletions(-)
---
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index ca2b087..95374c4 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -48,8 +48,6 @@
 #include "gnome-keyring-md5.h"
 #include "wireless-dialog.h"
 
-#define PREF_SUPPRESS_WIRELESS_NEWORKS_AVAILABLE    APPLET_PREFS_PATH "/suppress-wireless-networks-available"
-
 #define ACTIVE_AP_TAG "active-ap"
 
 static void wireless_dialog_response_cb (GtkDialog *dialog, gint response, gpointer user_data);
@@ -909,7 +907,7 @@ wifi_available_dont_show_cb (NotifyNotification *notify,
 		return;
 
 	gconf_client_set_bool (applet->gconf_client,
-	                       PREF_SUPPRESS_WIRELESS_NEWORKS_AVAILABLE,
+	                       PREF_SUPPRESS_WIRELESS_NETWORKS_AVAILABLE,
 	                       TRUE,
 	                       NULL);
 }
@@ -1012,7 +1010,7 @@ queue_avail_access_point_notification (NMDevice *device)
 		return;
 
 	if (gconf_client_get_bool (data->applet->gconf_client,
-	                           PREF_SUPPRESS_WIRELESS_NEWORKS_AVAILABLE,
+	                           PREF_SUPPRESS_WIRELESS_NETWORKS_AVAILABLE,
 	                           NULL))
 		return;
 
diff --git a/src/applet.c b/src/applet.c
index a149f1c..ac21619 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -1352,6 +1352,30 @@ nma_set_networking_enabled_cb (GtkWidget *widget, NMApplet *applet)
 	nm_client_sleep (applet->nm_client, !state);
 }
 
+
+static void
+nma_set_notifications_enabled_cb (GtkWidget *widget, NMApplet *applet)
+{
+	gboolean state;
+
+	g_return_if_fail (applet != NULL);
+
+	state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
+
+	gconf_client_set_bool (applet->gconf_client,
+	                       PREF_DISABLE_CONNECTED_NOTIFICATIONS,
+	                       !state,
+	                       NULL);
+	gconf_client_set_bool (applet->gconf_client,
+	                       PREF_DISABLE_DISCONNECTED_NOTIFICATIONS,
+	                       !state,
+	                       NULL);
+	gconf_client_set_bool (applet->gconf_client,
+	                       PREF_SUPPRESS_WIRELESS_NETWORKS_AVAILABLE,
+	                       !state,
+	                       NULL);
+}
+
 /*
  * nma_menu_show_cb
  *
@@ -1463,6 +1487,7 @@ nma_context_menu_update (NMApplet *applet)
 	NMState state;
 	gboolean have_wireless = FALSE;
 	gboolean wireless_hw_enabled;
+	gboolean notifications_enabled = TRUE;
 
 	state = nm_client_get_state (applet->nm_client);
 
@@ -1492,6 +1517,17 @@ nma_context_menu_update (NMApplet *applet)
 	gtk_widget_set_sensitive (GTK_WIDGET (applet->wifi_enabled_item),
 	                          wireless_hw_enabled);
 
+	/* Enabled notifications */
+	g_signal_handler_block (G_OBJECT (applet->notifications_enabled_item),
+	                        applet->notifications_enabled_toggled_id);
+	if (   gconf_client_get_bool (applet->gconf_client, PREF_DISABLE_CONNECTED_NOTIFICATIONS, NULL)
+	    && gconf_client_get_bool (applet->gconf_client, PREF_DISABLE_DISCONNECTED_NOTIFICATIONS, NULL)
+	    && gconf_client_get_bool (applet->gconf_client, PREF_SUPPRESS_WIRELESS_NETWORKS_AVAILABLE, NULL))
+		notifications_enabled = FALSE;
+	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (applet->notifications_enabled_item), notifications_enabled);
+	g_signal_handler_unblock (G_OBJECT (applet->notifications_enabled_item),
+	                          applet->notifications_enabled_toggled_id);
+
 	/* Don't show wifi-specific stuff if wireless is off */
 	if (state != NM_STATE_ASLEEP) {
 		const GPtrArray *devices;
@@ -1580,6 +1616,17 @@ static GtkWidget *nma_context_menu_create (NMApplet *applet)
 
 	nma_menu_add_separator_item (GTK_WIDGET (menu));
 
+	/* Toggle notifications item */
+	applet->notifications_enabled_item = gtk_check_menu_item_new_with_mnemonic (_("Enable N_otifications"));
+	id = g_signal_connect (applet->notifications_enabled_item,
+	                       "toggled",
+	                       G_CALLBACK (nma_set_notifications_enabled_cb),
+	                       applet);
+	applet->notifications_enabled_toggled_id = id;
+	gtk_menu_shell_append (menu, applet->notifications_enabled_item);
+
+	nma_menu_add_separator_item (GTK_WIDGET (menu));
+
 	/* 'Connection Information' item */
 	applet->info_menu_item = gtk_image_menu_item_new_with_mnemonic (_("Connection _Information"));
 	g_signal_connect_swapped (applet->info_menu_item,
diff --git a/src/applet.h b/src/applet.h
index a0f9bc9..f5c71ea 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -63,9 +63,10 @@ typedef struct
 } NMAppletClass; 
 
 #define APPLET_PREFS_PATH "/apps/nm-applet"
-#define PREF_DISABLE_CONNECTED_NOTIFICATIONS    APPLET_PREFS_PATH "/disable-connected-notifications"
-#define PREF_DISABLE_DISCONNECTED_NOTIFICATIONS APPLET_PREFS_PATH "/disable-disconnected-notifications"
-#define PREF_DISABLE_WIFI_CREATE                APPLET_PREFS_PATH "/disable-wifi-create"
+#define PREF_DISABLE_CONNECTED_NOTIFICATIONS      APPLET_PREFS_PATH "/disable-connected-notifications"
+#define PREF_DISABLE_DISCONNECTED_NOTIFICATIONS   APPLET_PREFS_PATH "/disable-disconnected-notifications"
+#define PREF_DISABLE_WIFI_CREATE                  APPLET_PREFS_PATH "/disable-wifi-create"
+#define PREF_SUPPRESS_WIRELESS_NETWORKS_AVAILABLE APPLET_PREFS_PATH "/suppress-wireless-networks-available"
 
 #define ICON_LAYER_LINK 0
 #define ICON_LAYER_VPN 1
@@ -139,6 +140,10 @@ typedef struct
 	guint           networking_enabled_toggled_id;
 	GtkWidget *		wifi_enabled_item;
 	guint           wifi_enabled_toggled_id;
+
+	GtkWidget *     notifications_enabled_item;
+	guint           notifications_enabled_toggled_id;
+
 	GtkWidget *		info_menu_item;
 	GtkWidget *		connections_menu_item;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]