[drwright] Add persistent notification support
- From: Christopher Aillon <caillon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [drwright] Add persistent notification support
- Date: Thu, 3 Mar 2011 22:35:55 +0000 (UTC)
commit 81b0c5e1dd05caedc9489a3248af0c2402af12fa
Author: Christopher Aillon <caillon redhat com>
Date: Thu Mar 3 13:20:01 2011 -0800
Add persistent notification support
GNOME bug 643535 part 2
configure.in | 2 +
src/drwright.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/configure.in b/configure.in
index 52b369b..b79886c 100644
--- a/configure.in
+++ b/configure.in
@@ -44,6 +44,7 @@ GLIB_REQUIRED=2.26.0
GIO_REQUIRED=2.26.0
GTK_REQUIRED=3.0.0
LIBCANBERRA_REQUIRED=0
+LIBNOTIFY_REQUIRED=0.7
GSD_REQUIRED=2.91.8
GNOMECC_REQUIRED=2.91.6
@@ -56,6 +57,7 @@ PKG_CHECK_MODULES([TYPING],[
gio-2.0 >= $GIO_REQUIRED
gtk+-3.0 >= $GTK_REQUIRED
libcanberra-gtk3 >= $LIBCANBERRA_REQUIRED
+ libnotify >= $LIBNOTIFY_REQUIRED
x11])
AC_PATH_XTRA
diff --git a/src/drwright.c b/src/drwright.c
index 1b01f1b..7a7ebb9 100644
--- a/src/drwright.c
+++ b/src/drwright.c
@@ -28,6 +28,7 @@
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
+#include <libnotify/notify.h>
#include "drwright.h"
#include "drw-break-window.h"
@@ -56,6 +57,9 @@ struct _DrWright {
GtkWidget *break_window;
GList *secondary_break_windows;
+ NotifyNotification *notification;
+ gint num_minutes_last_displayed;
+
DrwMonitor *monitor;
DrwState state;
@@ -87,6 +91,69 @@ static GList * create_secondary_break_windows (void);
extern gboolean debug;
static void
+show_warning_notification (DrWright *dr, gboolean show)
+{
+ NotifyNotification *notification;
+ gint minutes, seconds;
+ gchar *summary, *body;
+ GError *error = NULL;
+
+ if (show == FALSE) {
+ if (dr->notification) {
+ gboolean success = notify_notification_close (dr->notification, &error);
+ if (success) {
+ g_object_unref (dr->notification);
+ dr->notification = NULL;
+ }
+ else {
+ g_warning ("%s", error->message);
+ }
+ g_clear_error (&error);
+ }
+ dr->num_minutes_last_displayed = -1;
+ return;
+ }
+
+ seconds = dr->type_time - drw_timer_elapsed (dr->timer) - dr->save_last_time;
+ minutes = (seconds / 60) + 1;
+
+ if (minutes == dr->num_minutes_last_displayed) {
+ return;
+ }
+ dr->num_minutes_last_displayed = minutes;
+
+ summary = _("Typing Break Reminder");
+
+ if (minutes > 1) {
+ body = g_strdup_printf (ngettext ("Approximately %d minute to the next break.",
+ "Approximately %d minutes to the next break.",
+ minutes),
+ minutes);
+ }
+ else {
+ body = g_strdup (_("Less than one minute to the next break."));
+ }
+
+ if (dr->notification) {
+ notification = dr->notification;
+ notify_notification_update (notification, summary, body, "typing-monitor");
+ }
+ else {
+ notification = notify_notification_new (summary, body, "typing-monitor");
+ notify_notification_set_hint (notification, "resident",
+ g_variant_new_boolean (TRUE));
+ dr->notification = notification;
+ }
+
+ if (!notify_notification_show (notification, &error)) {
+ g_warning ("%s", error->message);
+ }
+
+ g_clear_error (&error);
+ g_free (body);
+}
+
+static void
setup_debug_values (DrWright *dr)
{
dr->type_time = 300;
@@ -150,6 +217,7 @@ maybe_change_state (DrWright *dr)
drw_timer_start (dr->timer);
drw_timer_start (dr->idle_timer);
+ show_warning_notification (dr, FALSE);
if (dr->enabled) {
dr->state = STATE_RUNNING;
@@ -167,6 +235,9 @@ maybe_change_state (DrWright *dr)
&& elapsed_time >= dr->type_time - dr->warn_time) {
dr->state = STATE_WARN;
}
+ if (dr->state == STATE_WARN) {
+ show_warning_notification (dr, TRUE);
+ }
break;
case STATE_BREAK_SETUP:
@@ -178,6 +249,8 @@ maybe_change_state (DrWright *dr)
break;
}
+ show_warning_notification (dr, FALSE);
+
drw_timer_start (dr->timer);
dr->break_window = drw_break_window_new ();
@@ -363,6 +436,10 @@ drwright_new (void)
setup_debug_values (dr);
}
+ if (!notify_is_initted ()) {
+ notify_init (PACKAGE_NAME);
+ }
+
dr->timer = drw_timer_new ();
dr->idle_timer = drw_timer_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]