mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-25 07:56:21 +00:00
Now sends desktop notification periodically to remind of unread messages
This commit is contained in:
@@ -41,7 +41,7 @@ static log_level_t _get_log_level(char *log_level);
|
|||||||
gboolean _process_input(char *inp);
|
gboolean _process_input(char *inp);
|
||||||
static void _create_config_directory();
|
static void _create_config_directory();
|
||||||
|
|
||||||
static gdouble remind_period = 0;
|
static gdouble remind_period = 10;
|
||||||
|
|
||||||
void
|
void
|
||||||
profanity_run(void)
|
profanity_run(void)
|
||||||
@@ -65,10 +65,8 @@ profanity_run(void)
|
|||||||
|
|
||||||
// 0 means to not remind
|
// 0 means to not remind
|
||||||
if (remind_period > 0 && elapsed >= remind_period) {
|
if (remind_period > 0 && elapsed >= remind_period) {
|
||||||
if (win_get_unread() > 0) {
|
win_remind();
|
||||||
log_info("Unread : %d", win_get_unread());
|
g_timer_start(timer);
|
||||||
g_timer_start(timer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
win_handle_special_keys(&ch);
|
win_handle_special_keys(&ch);
|
||||||
|
|||||||
2
src/ui.h
2
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_disconnected(void);
|
||||||
void win_show(const char * const msg);
|
void win_show(const char * const msg);
|
||||||
void win_bad_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
|
// console window actions
|
||||||
void cons_help(void);
|
void cons_help(void);
|
||||||
|
|||||||
@@ -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_switch(const int * const ch);
|
||||||
static void _win_handle_page(const int * const ch);
|
static void _win_handle_page(const int * const ch);
|
||||||
static void _win_resize_all(void);
|
static void _win_resize_all(void);
|
||||||
|
static gint _win_get_unread(void);
|
||||||
|
|
||||||
#ifdef HAVE_LIBNOTIFY
|
#ifdef HAVE_LIBNOTIFY
|
||||||
|
static void _win_notify_remind(gint unread);
|
||||||
static void _win_notify_message(char * short_from);
|
static void _win_notify_message(char * short_from);
|
||||||
static void _win_notify_typing(char * short_from);
|
static void _win_notify_typing(char * short_from);
|
||||||
#endif
|
#endif
|
||||||
@@ -229,15 +231,15 @@ win_show_typing(const char * const from)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gint
|
void
|
||||||
win_get_unread(void)
|
win_remind(void)
|
||||||
{
|
{
|
||||||
int i;
|
#ifdef HAVE_LIBNOTIFY
|
||||||
gint result = 0;
|
gint unread = _win_get_unread();
|
||||||
for (i = 0; i < NUM_WINS; i++) {
|
if (unread > 0) {
|
||||||
result += _wins[i].unread;
|
_win_notify_remind(unread);
|
||||||
}
|
}
|
||||||
return result;
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -282,6 +284,36 @@ win_show_incomming_msg(const char * const from, const char * const message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBNOTIFY
|
#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
|
static void
|
||||||
_win_notify_message(char * short_from)
|
_win_notify_message(char * short_from)
|
||||||
{
|
{
|
||||||
@@ -997,3 +1029,15 @@ _win_handle_page(const int * const ch)
|
|||||||
dirty = TRUE;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user