1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Moved remimder notification code out of main loop

This commit is contained in:
James Booth 2015-01-15 00:42:40 +00:00
parent a1bbe07b4b
commit 0007e3569e
4 changed files with 56 additions and 47 deletions

View File

@ -77,8 +77,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
_init(disable_tls, log_level);
log_info("Starting main event loop");
ui_input_nonblocking(TRUE);
GTimer *remind_timer = g_timer_new();
gboolean cmd_result = TRUE;
jabber_conn_status_t conn_status = jabber_get_connection_status();
char inp[INP_WIN_MAX];
@ -97,6 +95,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
prefs_free_string(pref_connect_account);
ui_update();
gboolean cmd_result = TRUE;
while(cmd_result == TRUE) {
wint_t ch = ERR;
size = 0;
@ -107,18 +106,12 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
_handle_idle_time();
}
gdouble elapsed = g_timer_elapsed(remind_timer, NULL);
gint remind_period = prefs_get_notify_remind();
if (remind_period > 0 && elapsed >= remind_period) {
notify_remind();
g_timer_start(remind_timer);
}
ch = ui_get_char(inp, &size);
#ifdef HAVE_LIBOTR
otr_poll();
#endif
notify_remind();
jabber_process_events();
ui_update();
}
@ -126,8 +119,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
inp[size++] = '\0';
cmd_result = process_input(inp);
}
g_timer_destroy(remind_timer);
}
void

View File

@ -102,6 +102,7 @@ ui_init(void)
status_bar_active(1);
create_input_window();
wins_init();
notifier_initialise();
cons_about();
#ifdef HAVE_LIBXSS
display = XOpenDisplay(0);

View File

@ -48,10 +48,19 @@
#include "log.h"
#include "muc.h"
#include "ui/ui.h"
#include "config/preferences.h"
static void _notify(const char * const message, int timeout,
const char * const category);
static GTimer *remind_timer;
void
notifier_initialise(void)
{
remind_timer = g_timer_new();
}
void
notifier_uninit(void)
{
@ -60,6 +69,7 @@ notifier_uninit(void)
notify_uninit();
}
#endif
g_timer_destroy(remind_timer);
}
void
@ -128,46 +138,52 @@ notify_subscription(const char * const from)
void
notify_remind(void)
{
gint unread = ui_unread();
gint open = muc_invites_count();
gint subs = presence_sub_request_count();
gdouble elapsed = g_timer_elapsed(remind_timer, NULL);
gint remind_period = prefs_get_notify_remind();
if (remind_period > 0 && elapsed >= remind_period) {
gint unread = ui_unread();
gint open = muc_invites_count();
gint subs = presence_sub_request_count();
GString *text = g_string_new("");
GString *text = g_string_new("");
if (unread > 0) {
if (unread == 1) {
g_string_append(text, "1 unread message");
} else {
g_string_append_printf(text, "%d unread messages", unread);
}
}
if (open > 0) {
if (unread > 0) {
g_string_append(text, "\n");
}
if (open == 1) {
g_string_append(text, "1 room invite");
} else {
g_string_append_printf(text, "%d room invites", open);
}
}
if (subs > 0) {
if ((unread > 0) || (open > 0)) {
g_string_append(text, "\n");
}
if (subs == 1) {
g_string_append(text, "1 subscription request");
} else {
g_string_append_printf(text, "%d subscription requests", subs);
}
}
if (unread == 1) {
g_string_append(text, "1 unread message");
} else {
g_string_append_printf(text, "%d unread messages", unread);
}
if ((unread > 0) || (open > 0) || (subs > 0)) {
_notify(text->str, 5000, "Incoming message");
}
}
if (open > 0) {
if (unread > 0) {
g_string_append(text, "\n");
}
if (open == 1) {
g_string_append(text, "1 room invite");
} else {
g_string_append_printf(text, "%d room invites", open);
}
}
if (subs > 0) {
if ((unread > 0) || (open > 0)) {
g_string_append(text, "\n");
}
if (subs == 1) {
g_string_append(text, "1 subscription request");
} else {
g_string_append_printf(text, "%d subscription requests", subs);
}
}
g_string_free(text, TRUE);
if ((unread > 0) || (open > 0) || (subs > 0)) {
_notify(text->str, 5000, "Incoming message");
}
g_string_free(text, TRUE);
g_timer_start(remind_timer);
}
}
static void

View File

@ -329,6 +329,7 @@ void rosterwin_roster(void);
void occupantswin_occupants(const char * const room);
// desktop notifier actions
void notifier_initialise(void);
void notifier_uninit(void);
void notify_typing(const char * const handle);