[gnome-color-manager] trivial: add some notifications to the bubbles to be able to ignore them



commit 266c09a62cec84f47eec3f71ec470b9b242035ad
Author: Richard Hughes <richard hughsie com>
Date:   Thu Mar 25 20:54:54 2010 +0000

    trivial: add some notifications to the bubbles to be able to ignore them

 src/gcm-session.c |  124 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 90 insertions(+), 34 deletions(-)
---
diff --git a/src/gcm-session.c b/src/gcm-session.c
index 3cd0ee9..219402d 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -36,6 +36,7 @@
 #include "org.gnome.ColorManager.h"
 
 static GMainLoop *loop = NULL;
+static GConfClient *gconf_client = NULL;
 
 #define GCM_DBUS_SERVICE		"org.gnome.ColorManager"
 #define GCM_DBUS_INTERFACE		"org.gnome.ColorManager"
@@ -112,10 +113,32 @@ gcm_session_check_idle_cb (GcmDbus *dbus)
 }
 
 /**
+ * gcm_session_notify_cb:
+ **/
+static void
+gcm_session_notify_cb (NotifyNotification *notification, gchar *action, gpointer user_data)
+{
+	gboolean ret;
+	GError *error = NULL;
+
+	if (g_strcmp0 (action, "display") == 0) {
+		gconf_client_set_int (gconf_client, GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD, 0, NULL);
+	} else if (g_strcmp0 (action, "printer") == 0) {
+		gconf_client_set_int (gconf_client, GCM_SETTINGS_RECALIBRATE_PRINTER_THRESHOLD, 0, NULL);
+	} else if (g_strcmp0 (action, "recalibrate") == 0) {
+		ret = g_spawn_command_line_async ("gcm-prefs", &error);
+		if (!ret) {
+			egg_warning ("failed to spawn: %s", error->message);
+			g_error_free (error);
+		}
+	}
+}
+
+/**
  * gcm_session_notify_recalibrate:
  **/
 static gboolean
-gcm_session_notify_recalibrate (const gchar *title, const gchar *message)
+gcm_session_notify_recalibrate (const gchar *title, const gchar *message, GcmDeviceKind kind)
 {
 	gboolean ret;
 	GError *error = NULL;
@@ -125,28 +148,73 @@ gcm_session_notify_recalibrate (const gchar *title, const gchar *message)
 	notification = notify_notification_new (title, message, GCM_STOCK_ICON, NULL);
 	notify_notification_set_timeout (notification, GCM_SESSION_NOTIFY_TIMEOUT);
 	notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
+
+	/* TRANSLATORS: button: this is to open GCM */
+	notify_notification_add_action (notification, "recalibrate", _("Recalibrate now"), gcm_session_notify_cb, NULL, NULL);
+
+	/* TRANSLATORS: button: this is to ignore the recalibrate notifications */
+	notify_notification_add_action (notification, gcm_device_kind_to_string (kind), _("Ignore"), gcm_session_notify_cb, NULL, NULL);
+
 	ret = notify_notification_show (notification, &error);
 	if (!ret) {
 		egg_warning ("failed to show notification: %s", error->message);
 		g_error_free (error);
 	}
-	g_object_unref (notification);
 	return ret;
 }
 
 /**
- * gcm_session_added_cb:
+ * gcm_session_notify_device:
  **/
 static void
-gcm_session_added_cb (GcmClient *client, GcmDevice *device, gpointer user_data)
+gcm_session_notify_device (GcmDevice *device)
 {
+	const gchar *message;
+	const gchar *title;
+	GcmDeviceKind kind;
 	glong since;
 	GTimeVal timeval;
-	GConfClient *gconf_client;
 	gint threshold;
+
+	/* get current time */
+	g_get_current_time (&timeval);
+
+	/* TRANSLATORS: this is when the device has not been recalibrated in a while */
+	title = _("Recalibration required");
+
+	/* check we care */
+	kind = gcm_device_get_kind (device);
+	if (kind == GCM_DEVICE_KIND_DISPLAY) {
+
+		/* get from GConf */
+		threshold = gconf_client_get_int (gconf_client, GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD, NULL);
+
+		/* TRANSLATORS: this is when the display has not been recalibrated in a while */
+		message = _("The display attached to this computer should be recalibrated soon.");
+	} else {
+
+		/* get from GConf */
+		threshold = gconf_client_get_int (gconf_client, GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD, NULL);
+
+		/* TRANSLATORS: this is when the printer has not been recalibrated in a while */
+		message = _("The printer attached to this computer should be recalibrated soon.");
+	}
+
+	/* check if we need to notify */
+	since = timeval.tv_sec - gcm_device_get_modified_time (device);
+	if (threshold > since || TRUE)
+		gcm_session_notify_recalibrate (title, message, kind);
+}
+
+/**
+ * gcm_session_added_cb:
+ **/
+static void
+gcm_session_added_cb (GcmClient *client, GcmDevice *device, gpointer user_data)
+{
 	GcmDeviceKind kind;
-	const gchar *title;
 	const gchar *profile;
+	gchar *basename = NULL;
 
 	/* check we care */
 	kind = gcm_device_get_kind (device);
@@ -156,38 +224,22 @@ gcm_session_added_cb (GcmClient *client, GcmDevice *device, gpointer user_data)
 
 	/* ensure we have a profile */
 	profile = gcm_device_get_profile_filename (device);
-	if (profile == NULL)
-		return;
+	if (profile == NULL) {
+		egg_debug ("no profile set for %s", gcm_device_get_id (device));
+		goto out;
+	}
 
 	/* ensure it's a profile generated by us */
-	if (!g_str_has_prefix (profile, "GCM"))
-		return;
-
-	/* get current time */
-	g_get_current_time (&timeval);
-
-	/* TRANSLATORS: this is when the device has not been recalibrated in a while */
-	title = _("Recalibration required");
-
-	/* check if we need to notify */
-	gconf_client = gconf_client_get_default ();
-	since = timeval.tv_sec - gcm_device_get_modified_time (device);
-	if (kind == GCM_DEVICE_KIND_DISPLAY) {
-		threshold = gconf_client_get_int (gconf_client, GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD, NULL);
-		if (threshold > since) {
-			/* TRANSLATORS: this is when the display has not been recalibrated in a while */
-			gcm_session_notify_recalibrate (title, _("The display attached to this computer should be recalibrated soon."));
-		}
-	}
-	if (kind == GCM_DEVICE_KIND_PRINTER) {
-		threshold = gconf_client_get_int (gconf_client, GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD, NULL);
-		if (threshold > since) {
-			/* TRANSLATORS: this is when the printer has not been recalibrated in a while */
-			gcm_session_notify_recalibrate (title, _("The printer attached to this computer should be recalibrated soon."));
-		}
+	basename = g_path_get_basename (profile);
+	if (!g_str_has_prefix (basename, "GCM")) {
+		egg_debug ("not a GCM profile for %s: %s", gcm_device_get_id (device), profile);
+		goto out;
 	}
 
-	g_object_unref (gconf_client);
+	/* handle device */
+	gcm_session_notify_device (device);
+out:
+	g_free (basename);
 }
 
 /**
@@ -235,6 +287,9 @@ main (int argc, char *argv[])
 
 	gtk_init (&argc, &argv);
 
+	/* get the settings */
+	gconf_client = gconf_client_get_default ();
+
 	/* monitor devices as they are added */
 	client = gcm_client_new ();
 	g_signal_connect (client, "added", G_CALLBACK (gcm_session_added_cb), NULL);
@@ -267,6 +322,7 @@ main (int argc, char *argv[])
 	/* wait */
 	g_main_loop_run (loop);
 out:
+	g_object_unref (gconf_client);
 	g_object_unref (client);
 	g_main_loop_unref (loop);
 	g_object_unref (dbus);



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