diff options
author | James Booth <boothj5@gmail.com> | 2012-09-23 20:52:47 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-09-23 20:52:47 +0100 |
commit | 294ea2d1bedd741d4f2ea2c17036f517227a9282 (patch) | |
tree | ddb0ec3b5333abc42a1aac138fc21c2ac98af099 /src | |
parent | d888a378d3083eaac159c6372729a3435e4c2cf0 (diff) | |
download | profani-tty-294ea2d1bedd741d4f2ea2c17036f517227a9282.tar.gz |
Now sends desktop notification periodically to remind of unread messages
Diffstat (limited to 'src')
-rw-r--r-- | src/profanity.c | 8 | ||||
-rw-r--r-- | src/ui.h | 2 | ||||
-rw-r--r-- | src/windows.c | 58 |
3 files changed, 55 insertions, 13 deletions
diff --git a/src/profanity.c b/src/profanity.c index 2c7bf08e..e8047030 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -41,7 +41,7 @@ static log_level_t _get_log_level(char *log_level); gboolean _process_input(char *inp); static void _create_config_directory(); -static gdouble remind_period = 0; +static gdouble remind_period = 10; void profanity_run(void) @@ -65,10 +65,8 @@ profanity_run(void) // 0 means to not remind if (remind_period > 0 && elapsed >= remind_period) { - if (win_get_unread() > 0) { - log_info("Unread : %d", win_get_unread()); - g_timer_start(timer); - } + win_remind(); + g_timer_start(timer); } win_handle_special_keys(&ch); diff --git a/src/ui.h b/src/ui.h index beffcdb6..e866482b 100644 --- a/src/ui.h +++ b/src/ui.h @@ -98,7 +98,7 @@ void win_contact_offline(const char * const from, const char * const show, void win_disconnected(void); void win_show(const char * const msg); void win_bad_show(const char * const msg); -gint win_get_unread(void); +void win_remind(void); // console window actions void cons_help(void); diff --git a/src/windows.c b/src/windows.c index 0198a342..df0d8c7f 100644 --- a/src/windows.c +++ b/src/windows.c @@ -80,8 +80,10 @@ static void _cons_show_incoming_message(const char * const short_from, static void _win_handle_switch(const int * const ch); static void _win_handle_page(const int * const ch); static void _win_resize_all(void); +static gint _win_get_unread(void); #ifdef HAVE_LIBNOTIFY +static void _win_notify_remind(gint unread); static void _win_notify_message(char * short_from); static void _win_notify_typing(char * short_from); #endif @@ -229,15 +231,15 @@ win_show_typing(const char * const from) #endif } -gint -win_get_unread(void) +void +win_remind(void) { - int i; - gint result = 0; - for (i = 0; i < NUM_WINS; i++) { - result += _wins[i].unread; +#ifdef HAVE_LIBNOTIFY + gint unread = _win_get_unread(); + if (unread > 0) { + _win_notify_remind(unread); } - return result; +#endif } void @@ -283,6 +285,36 @@ win_show_incomming_msg(const char * const from, const char * const message) #ifdef HAVE_LIBNOTIFY static void +_win_notify_remind(gint unread) +{ + notify_init("Profanity"); + + char message[20]; + if (unread == 1) { + sprintf(message, "1 unread message"); + } else { + sprintf(message, "%d unread messages", unread); + } + + // create a new notification + NotifyNotification *incoming; + incoming = notify_notification_new("Profanity", message, NULL); + + // set the timeout of the notification to 10 secs + notify_notification_set_timeout(incoming, 5000); + + // set the category so as to tell what kind it is + char category[30] = "Incoming message"; + notify_notification_set_category(incoming, category); + + // set the urgency level of the notification + notify_notification_set_urgency(incoming, NOTIFY_URGENCY_NORMAL); + + GError *error = NULL; + notify_notification_show(incoming, &error); +} + +static void _win_notify_message(char * short_from) { notify_init("Profanity"); @@ -997,3 +1029,15 @@ _win_handle_page(const int * const ch) dirty = TRUE; } } + +static gint +_win_get_unread(void) +{ + int i; + gint result = 0; + for (i = 0; i < NUM_WINS; i++) { + result += _wins[i].unread; + } + return result; +} + |