[krb5-auth-dialog] allow notifications to be turned off



commit 03e53f40fa38e61988b240aa1d99a570d0cbd2e1
Author: Guido Günther <agx sigxcpu org>
Date:   Tue May 19 19:47:57 2009 +0200

    allow notifications to be turned off
---
 ChangeLog                       |   13 ++++++
 src/krb5-auth-applet.c          |   82 +++++++++++++++++++++++++++++++++------
 src/krb5-auth-dialog.c          |    3 -
 src/krb5-auth-dialog.schemas.in |   39 ++++++++++++++++++
 src/krb5-auth-gconf-tools.c     |   24 +++++++++++
 src/krb5-auth-gconf-tools.h     |    4 ++
 src/krb5-auth-gconf.c           |   26 ++++++------
 src/krb5-auth-gconf.h           |    3 +-
 8 files changed, 165 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 714aade..2139dbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Wed May 20 16:33:54 CEST 2009 Guido Günther <agx sigxcpu org>
+
+	allow to turn off notifcations
+	* src/krb5-auth-applet.c: add action to notifications
+	  (ka_send_event_notification): only show notification when
+	  corresponding gconf key is set
+	* src/krb5-auth-dialog.schemas.in: add schema entries
+	* src/krb5-auth-gconf-tools.c (ka_gconf_set_bool): new function
+	* src/src/krb5-auth-gconf-tools.c (ka_gconf_set_*): fix defaults
+	  (ka_gconf_init); return GconfClient
+	* src/krb5-auth-gconf-tools.h: define gconf keys
+	BZ: #579850
+
 Fri May 15 19:10:57 CEST 2009 Guido Günther <agx sigxcpu org>
 
 	* po/krb5-auth-dialog.pot: update translatable strings
diff --git a/src/krb5-auth-applet.c b/src/krb5-auth-applet.c
index a9a840e..5a8975c 100644
--- a/src/krb5-auth-applet.c
+++ b/src/krb5-auth-applet.c
@@ -24,6 +24,8 @@
 
 #include "krb5-auth-applet.h"
 #include "krb5-auth-dialog.h"
+#include "krb5-auth-gconf-tools.h"
+#include "krb5-auth-gconf.h"
 #ifdef HAVE_LIBNOTIFY
 #include <libnotify/notify.h>
 #endif
@@ -73,6 +75,7 @@ struct _KaAppletPrivate
 
 #ifdef HAVE_LIBNOTIFY
 	NotifyNotification* notification;/* notification messages */
+	const char* notify_gconf_key;	/* disable notification gconf key */
 #endif /* HAVE_LIBNOTIFY */
 	char* principal;		/* the principal to request */
 	gboolean renewable;		/* credentials renewable? */
@@ -81,6 +84,8 @@ struct _KaAppletPrivate
 	gboolean tgt_forwardable;	/* request a forwardable ticket */
 	gboolean tgt_renewable;		/* request a renewable ticket */
 	gboolean tgt_proxiable;		/* request a proxiable ticket */
+
+	GConfClient *gconf;		/* gconf client */
 };
 
 static void
@@ -373,23 +378,42 @@ ka_applet_select_icon(KaApplet* applet, int remaining)
 
 #ifdef HAVE_LIBNOTIFY
 static gboolean
-show_notification (KaApplet *applet)
+ka_show_notification (KaApplet *applet)
 {
 	/* wait for the panel to be settled before showing a bubble */
 	if (gtk_status_icon_is_embedded (applet->priv->tray_icon)) {
 		notify_notification_show (applet->priv->notification, NULL);
 	} else {
-		g_timeout_add_seconds (5, (GSourceFunc)show_notification, applet);
+		g_timeout_add_seconds (5, (GSourceFunc)ka_show_notification, applet);
 	}
 	return FALSE;
 }
 
 
 static void
+ka_notify_action_cb (NotifyNotification *notification G_GNUC_UNUSED,
+	             gchar *action, gpointer user_data)
+{
+	KaApplet *self = KA_APPLET (user_data);
+
+	if (strcmp (action, "dont-show-again") == 0) {
+		KA_DEBUG ("turning of notification %s", self->priv->notify_gconf_key);
+		ka_gconf_set_bool (self->priv->gconf,
+				   self->priv->notify_gconf_key,
+				   FALSE);
+		self->priv->notify_gconf_key = NULL;
+	} else {
+		g_warning("unkonwn action for callback");
+	}
+}
+
+
+static void
 ka_send_event_notification (KaApplet *applet,
 			    const char *summary,
 			    const char *message,
-			    const char *icon)
+			    const char *icon,
+			    const char *action)
 {
         const char *notify_icon;
 
@@ -408,17 +432,26 @@ ka_send_event_notification (KaApplet *applet,
 	notify_icon = icon ? icon : "gtk-dialog-authentication";
 
 	applet->priv->notification = \
-		notify_notification_new_with_status_icon(summary, message, notify_icon, applet->priv->tray_icon);
+		notify_notification_new_with_status_icon(summary,
+							 message,
+							 notify_icon,
+							 applet->priv->tray_icon);
 
 	notify_notification_set_urgency (applet->priv->notification, NOTIFY_URGENCY_NORMAL);
-	show_notification (applet);
+	notify_notification_add_action (applet->priv->notification,
+					action,
+					_("Don't show me this again"),
+					(NotifyActionCallback) ka_notify_action_cb,
+					applet, NULL);
+	ka_show_notification (applet);
 }
 #else
 static void
 ka_send_event_notification (KaApplet *applet G_GNUC_UNUSED,
 			    const char *summary G_GNUC_UNUSED,
 			    const char *message G_GNUC_UNUSED,
-			    const char *icon G_GNUC_UNUSED)
+			    const char *icon G_GNUC_UNUSED,
+			    const char *action G_GNUC_UNUSED)
 {
 }
 #endif /* ! HAVE_LIBNOTIFY */
@@ -432,27 +465,49 @@ ka_applet_update_status(KaApplet* applet, krb5_timestamp expiry)
 	int remaining = expiry - now;
 	static int last_warn = 0;
 	static gboolean expiry_notified = FALSE;
+	gboolean notify = TRUE;
 	const char* tray_icon = ka_applet_select_icon (applet, remaining);
 	char* tooltip_text = ka_applet_tooltip_text (remaining);
 
 	if (remaining > 0) {
 		if (expiry_notified) {
-			ka_send_event_notification (applet,
+			ka_gconf_get_bool(applet->priv->gconf,
+					  KA_GCONF_KEY_NOTIFY_VALID,
+					  &notify);
+			if (notify) {
+				applet->priv->notify_gconf_key = KA_GCONF_KEY_NOTIFY_VALID;
+				ka_send_event_notification (applet,
 						_("Network credentials valid"),
-						_("Your Kerberos credentials have been refreshed."), NULL);
+						_("You've refreshed your Kerberos credentials."),
+						NULL, "dont-show-again");
+			}
 			expiry_notified = FALSE;
 		} else if (remaining < applet->priv->pw_prompt_secs && (now - last_warn) > NOTIFY_SECONDS &&
 			   !applet->priv->renewable) {
-			ka_send_event_notification (applet,
+			ka_gconf_get_bool(applet->priv->gconf,
+					  KA_GCONF_KEY_NOTIFY_EXPIRING,
+					  &notify);
+			if (notify) {
+				applet->priv->notify_gconf_key = KA_GCONF_KEY_NOTIFY_EXPIRING;
+				ka_send_event_notification (applet,
 						_("Network credentials expiring"),
-						tooltip_text, NULL);
+						tooltip_text,
+						NULL, "dont-show-again");
+			}
 			last_warn = now;
 		}
 	} else {
 		if (!expiry_notified) {
-			ka_send_event_notification (applet,
+			ka_gconf_get_bool(applet->priv->gconf,
+					  KA_GCONF_KEY_NOTIFY_EXPIRED,
+					  &notify);
+			if (notify) {
+				applet->priv->notify_gconf_key = KA_GCONF_KEY_NOTIFY_EXPIRED;
+				ka_send_event_notification (applet,
 						_("Network credentials expired"),
-						_("Your Kerberos credentails have expired."), NULL);
+						_("Your Kerberos credentails have expired."),
+						NULL, "dont-show-again");
+			}
 			expiry_notified = TRUE;
 			last_warn = 0;
 		}
@@ -681,6 +736,9 @@ ka_applet_create(GtkBuilder *xml)
 	applet->priv->pwdialog = ka_pwdialog_create(xml);
 	g_return_val_if_fail (applet->priv->pwdialog != NULL, NULL);
 
+	applet->priv->gconf = ka_gconf_init (applet);
+	g_return_val_if_fail (applet->priv->gconf != NULL, NULL);
+
 	return applet;
 }
 
diff --git a/src/krb5-auth-dialog.c b/src/krb5-auth-dialog.c
index 778491d..56a3a8c 100644
--- a/src/krb5-auth-dialog.c
+++ b/src/krb5-auth-dialog.c
@@ -39,7 +39,6 @@
 #include "krb5-auth-dialog.h"
 #include "krb5-auth-applet.h"
 #include "krb5-auth-pwdialog.h"
-#include "krb5-auth-gconf.h"
 #include "krb5-auth-dbus.h"
 
 #ifdef ENABLE_NETWORK_MANAGER
@@ -985,8 +984,6 @@ main (int argc, char *argv[])
 		applet = ka_applet_create (xml);
 		if (!applet)
 			return 1;
-		if (!ka_gconf_init (applet, argc, argv))
-			return 1;
 		ka_nm_init();
 
 		if (credentials_expiring ((gpointer)applet)) {
diff --git a/src/krb5-auth-dialog.schemas.in b/src/krb5-auth-dialog.schemas.in
index bc3143e..f8c7348 100644
--- a/src/krb5-auth-dialog.schemas.in
+++ b/src/krb5-auth-dialog.schemas.in
@@ -103,5 +103,44 @@
         <long>Requested tickets should be proxiable</long>
       </locale>
     </schema>
+
+    <schema>
+      <key>/schemas/apps/krb5-auth-dialog/notify/valid</key>
+      <applyto>/apps/krb5-auth-dialog/notify/valid</applyto>
+      <owner>krb5-auth-dialog</owner>
+      <type>bool</type>
+      <default>1</default>
+
+      <locale name="C">
+        <short>valid ticket notification</short>
+        <long>Notify user when ticket becomes valid</long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/krb5-auth-dialog/notify/expiring</key>
+      <applyto>/apps/krb5-auth-dialog/notify/expiring</applyto>
+      <owner>krb5-auth-dialog</owner>
+      <type>bool</type>
+      <default>1</default>
+
+      <locale name="C">
+        <short>ticket expiring notification</short>
+        <long>Notify user when ticket is about to expire</long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/krb5-auth-dialog/notify/expired</key>
+      <applyto>/apps/krb5-auth-dialog/notify/expired</applyto>
+      <owner>krb5-auth-dialog</owner>
+      <type>bool</type>
+      <default>1</default>
+
+      <locale name="C">
+        <short>ticket expired notification</short>
+        <long>Notify user when ticket has expired</long>
+      </locale>
+    </schema>
   </schemalist>
 </gconfschemafile>
diff --git a/src/krb5-auth-gconf-tools.c b/src/krb5-auth-gconf-tools.c
index 8b4add2..01f4d39 100644
--- a/src/krb5-auth-gconf-tools.c
+++ b/src/krb5-auth-gconf-tools.c
@@ -31,6 +31,7 @@ ka_gconf_get_string (GConfClient* client,
 	gboolean	success = FALSE;
 	GConfValue*	gc_value;
 
+	g_return_val_if_fail (client != NULL, FALSE);
 	g_return_val_if_fail (key != NULL, FALSE);
 	g_return_val_if_fail (*value == NULL, FALSE);
 
@@ -57,6 +58,7 @@ ka_gconf_get_int (GConfClient* client,
 	gboolean	success = FALSE;
 	GConfValue*	gc_value;
 
+	g_return_val_if_fail (client != NULL, FALSE);
 	g_return_val_if_fail (key != NULL, FALSE);
 	g_return_val_if_fail (value != NULL, FALSE);
 
@@ -84,6 +86,7 @@ ka_gconf_get_bool (GConfClient* client,
 	gboolean	success = FALSE;
 	GConfValue*	gc_value;
 
+	g_return_val_if_fail (client != NULL, FALSE);
 	g_return_val_if_fail (key != NULL, FALSE);
 	g_return_val_if_fail (value != NULL, FALSE);
 
@@ -100,3 +103,24 @@ ka_gconf_get_bool (GConfClient* client,
 	return success;
 }
 
+
+gboolean
+ka_gconf_set_bool (GConfClient* client,
+		    const char* key,
+		    gboolean value)
+{
+	GError*		error = NULL;
+
+	g_return_val_if_fail (client != NULL, FALSE);
+	g_return_val_if_fail (key != NULL, FALSE);
+
+	if(!gconf_client_set_bool (client, key, value, &error)) {
+		if (error) {
+			g_print ("%s", error->message);
+			g_error_free (error);
+		}
+		return FALSE;
+	}
+	return TRUE;
+}
+
diff --git a/src/krb5-auth-gconf-tools.h b/src/krb5-auth-gconf-tools.h
index 9f9020f..6d9f124 100644
--- a/src/krb5-auth-gconf-tools.h
+++ b/src/krb5-auth-gconf-tools.h
@@ -34,9 +34,13 @@
 #define KA_GCONF_KEY_FORWARDABLE	KA_GCONF_PATH "/forwardable"
 #define KA_GCONF_KEY_RENEWABLE		KA_GCONF_PATH "/renewable"
 #define KA_GCONF_KEY_PROXIABLE		KA_GCONF_PATH "/proxiable"
+#define KA_GCONF_KEY_NOTIFY_VALID	KA_GCONF_PATH "/notify/valid"
+#define KA_GCONF_KEY_NOTIFY_EXPIRED	KA_GCONF_PATH "/notify/expired"
+#define KA_GCONF_KEY_NOTIFY_EXPIRING	KA_GCONF_PATH "/notify/expiring"
 
 gboolean ka_gconf_get_string (GConfClient* client, const char* key, char** value);
 gboolean ka_gconf_get_int (GConfClient* client, const char* key, int* value);
 gboolean ka_gconf_get_bool (GConfClient* client, const char* key, gboolean* value);
+gboolean ka_gconf_set_bool (GConfClient* client, const char* key, gboolean value);
 
 #endif
diff --git a/src/krb5-auth-gconf.c b/src/krb5-auth-gconf.c
index fec5457..5b9df35 100644
--- a/src/krb5-auth-gconf.c
+++ b/src/krb5-auth-gconf.c
@@ -86,7 +86,7 @@ ka_gconf_set_prompt_mins (GConfClient* client, KaApplet* applet)
 static gboolean
 ka_gconf_set_show_trayicon (GConfClient* client, KaApplet* applet)
 {
-	gboolean show_trayicon = FALSE;
+	gboolean show_trayicon = TRUE;
 
 	if(!ka_gconf_get_bool(client, KA_GCONF_KEY_SHOW_TRAYICON, &show_trayicon)) {
 		show_trayicon = TRUE;
@@ -102,7 +102,7 @@ ka_gconf_set_tgt_forwardable (GConfClient* client, KaApplet* applet)
 	gboolean forwardable = FALSE;
 
 	if(!ka_gconf_get_bool(client, KA_GCONF_KEY_FORWARDABLE, &forwardable)) {
-		forwardable = TRUE;
+		forwardable = FALSE;
 	}
 	g_object_set(applet, "tgt-forwardable", forwardable, NULL);
 	return TRUE;
@@ -115,7 +115,7 @@ ka_gconf_set_tgt_renewable (GConfClient* client, KaApplet* applet)
 	gboolean renewable = FALSE;
 
 	if(!ka_gconf_get_bool(client, KA_GCONF_KEY_RENEWABLE, &renewable)) {
-		renewable = TRUE;
+		renewable = FALSE;
 	}
 	g_object_set(applet, "tgt-renewable", renewable, NULL);
 	return TRUE;
@@ -128,7 +128,7 @@ ka_gconf_set_tgt_proxiable (GConfClient* client, KaApplet* applet)
 	gboolean proxiable = FALSE;
 
 	if(!ka_gconf_get_bool(client, KA_GCONF_KEY_PROXIABLE, &proxiable)) {
-		proxiable = TRUE;
+		proxiable = FALSE;
 	}
 	g_object_set(applet, "tgt-proxiable", proxiable, NULL);
 	return TRUE;
@@ -165,20 +165,21 @@ ka_gconf_key_changed_callback (GConfClient* client,
 		ka_gconf_set_tgt_renewable (client, applet);
 	} else if (g_strcmp0 (key, KA_GCONF_KEY_PROXIABLE) == 0) {
 		ka_gconf_set_tgt_proxiable (client, applet);
+	} else if (g_strcmp0 (key, KA_GCONF_KEY_NOTIFY_VALID)
+		    || g_strcmp0 (key,KA_GCONF_KEY_NOTIFY_EXPIRING)
+		    || g_strcmp0 (key,KA_GCONF_KEY_NOTIFY_EXPIRED)) {
+		/* nothing to do */
 	} else
 		g_warning("Received notification for unknown gconf key %s", key);
 	return;
 }
 
 
-gboolean
-ka_gconf_init (KaApplet* applet,
-               int argc G_GNUC_UNUSED,
-               char* argv[] G_GNUC_UNUSED)
+GConfClient*
+ka_gconf_init (KaApplet* applet)
 {
 	GError *error = NULL;
-	GConfClient* client;
-	gboolean success = FALSE;
+	GConfClient *client;
 
 	client = gconf_client_get_default ();
 	gconf_client_add_dir (client, KA_GCONF_PATH, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
@@ -199,12 +200,11 @@ ka_gconf_init (KaApplet* applet,
 	ka_gconf_set_tgt_forwardable(client, applet);
 	ka_gconf_set_tgt_renewable(client, applet);
 	ka_gconf_set_tgt_proxiable(client, applet);
-
-	success = TRUE;
 out:
 	if(error) {
+		client = NULL;
 		g_print ("%s", error->message);
 		g_error_free (error);
 	}
-	return success;
+	return client;
 }
diff --git a/src/krb5-auth-gconf.h b/src/krb5-auth-gconf.h
index 3d2baae..e4c3b5a 100644
--- a/src/krb5-auth-gconf.h
+++ b/src/krb5-auth-gconf.h
@@ -21,8 +21,9 @@
 #ifndef KRB5_AUTH_GCONF_H
 #define KRB5_AUTH_GCONF_H
 
+#include <gconf/gconf-client.h>
 #include "krb5-auth-applet.h"
 
-gboolean ka_gconf_init (KaApplet* applet, int argc, char* argv[]);
+GConfClient* ka_gconf_init (KaApplet* applet);
 
 #endif



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