[gnome-color-manager] Add a notification when devices with profiles need recalibrating



commit d123d0fdd43e39c753df99d8dd595efc77e2364b
Author: Richard Hughes <richard hughsie com>
Date:   Thu Mar 25 20:32:32 2010 +0000

    Add a notification when devices with profiles need recalibrating

 src/Makefile.am   |    1 +
 src/gcm-session.c |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 97 insertions(+), 4 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3cff542..45ccc62 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -278,6 +278,7 @@ gcm_session_LDADD =					\
 	$(XORG_LIBS)					\
 	$(GTK_LIBS)					\
 	$(SANE_LIBS)					\
+	$(NOTIFY_LIBS)					\
 	$(CUPS_LIBS)					\
 	-lm
 
diff --git a/src/gcm-session.c b/src/gcm-session.c
index ea54d65..3cd0ee9 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -25,17 +25,23 @@
 #include <dbus/dbus-glib.h>
 #include <gtk/gtk.h>
 #include <locale.h>
+#include <gconf/gconf-client.h>
+#include <libnotify/notify.h>
 
 #include "egg-debug.h"
 #include "gcm-dbus.h"
+#include "gcm-client.h"
+#include "gcm-device.h"
+#include "gcm-utils.h"
 #include "org.gnome.ColorManager.h"
 
 static GMainLoop *loop = NULL;
 
-#define GCM_DBUS_SERVICE	"org.gnome.ColorManager"
-#define GCM_DBUS_INTERFACE	"org.gnome.ColorManager"
-#define GCM_DBUS_PATH		"/org/gnome/ColorManager"
-#define GCM_SESSION_IDLE_EXIT	60 /* seconds */
+#define GCM_DBUS_SERVICE		"org.gnome.ColorManager"
+#define GCM_DBUS_INTERFACE		"org.gnome.ColorManager"
+#define GCM_DBUS_PATH			"/org/gnome/ColorManager"
+#define GCM_SESSION_IDLE_EXIT		60 /* seconds */
+#define GCM_SESSION_NOTIFY_TIMEOUT	30000 /* ms */
 
 /**
  * gcm_session_object_register:
@@ -106,6 +112,85 @@ gcm_session_check_idle_cb (GcmDbus *dbus)
 }
 
 /**
+ * gcm_session_notify_recalibrate:
+ **/
+static gboolean
+gcm_session_notify_recalibrate (const gchar *title, const gchar *message)
+{
+	gboolean ret;
+	GError *error = NULL;
+	NotifyNotification *notification;
+
+	/* show a bubble */
+	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);
+	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:
+ **/
+static void
+gcm_session_added_cb (GcmClient *client, GcmDevice *device, gpointer user_data)
+{
+	glong since;
+	GTimeVal timeval;
+	GConfClient *gconf_client;
+	gint threshold;
+	GcmDeviceKind kind;
+	const gchar *title;
+	const gchar *profile;
+
+	/* check we care */
+	kind = gcm_device_get_kind (device);
+	if (kind != GCM_DEVICE_KIND_DISPLAY &&
+	    kind != GCM_DEVICE_KIND_PRINTER)
+		return;
+
+	/* ensure we have a profile */
+	profile = gcm_device_get_profile_filename (device);
+	if (profile == NULL)
+		return;
+
+	/* 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."));
+		}
+	}
+
+	g_object_unref (gconf_client);
+}
+
+/**
  * main:
  **/
 int
@@ -118,6 +203,7 @@ main (int argc, char *argv[])
 	gboolean ret;
 	guint retval = 0;
 	DBusGConnection *connection;
+	GcmClient *client = NULL;
 
 	const GOptionEntry options[] = {
 		{ "no-timed-exit", '\0', 0, G_OPTION_ARG_NONE, &no_timed_exit,
@@ -135,6 +221,7 @@ main (int argc, char *argv[])
 		g_thread_init (NULL);
 	dbus_g_thread_init ();
 	g_type_init ();
+	notify_init ("gnome-color-manager");
 
 	/* TRANSLATORS: program name, a session wide daemon to watch for updates and changing system state */
 	g_set_application_name (_("Color Management"));
@@ -148,6 +235,10 @@ main (int argc, char *argv[])
 
 	gtk_init (&argc, &argv);
 
+	/* monitor devices as they are added */
+	client = gcm_client_new ();
+	g_signal_connect (client, "added", G_CALLBACK (gcm_session_added_cb), NULL);
+
 	/* create new objects */
 	dbus = gcm_dbus_new ();
 	loop = g_main_loop_new (NULL, FALSE);
@@ -176,6 +267,7 @@ main (int argc, char *argv[])
 	/* wait */
 	g_main_loop_run (loop);
 out:
+	g_object_unref (client);
 	g_main_loop_unref (loop);
 	g_object_unref (dbus);
 	return retval;



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