From 54ef09bfbd619cf5d936d27b7ec207744c7f5c04 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 28 Jun 2012 23:45:37 +0100 Subject: [PATCH] Added notify preference --- command.c | 17 +++++++++++++++++ preferences.c | 11 +++++++++++ preferences.h | 2 ++ windows.c | 4 +++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/command.c b/command.c index 19fd1ab7..7d03a476 100644 --- a/command.c +++ b/command.c @@ -44,6 +44,7 @@ static gboolean _cmd_connect(const char * const inp); static gboolean _cmd_msg(const char * const inp); static gboolean _cmd_close(const char * const inp); static gboolean _cmd_set_beep(const char * const inp); +static gboolean _cmd_set_notify(const char * const inp); static gboolean _cmd_set_flash(const char * const inp); static gboolean _cmd_set_showsplash(const char * const inp); static gboolean _cmd_away(const char * const inp); @@ -65,6 +66,7 @@ static PAutocomplete commands_ac; static struct cmd_t commands[] = { { "/away", _cmd_away }, { "/beep", _cmd_set_beep }, + { "/notify", _cmd_set_notify }, { "/chat", _cmd_chat }, { "/close", _cmd_close }, { "/connect", _cmd_connect }, @@ -273,6 +275,21 @@ static gboolean _cmd_set_beep(const char * const inp) return TRUE; } +static gboolean _cmd_set_notify(const char * const inp) +{ + if (strcmp(inp, "/notify on") == 0) { + cons_show("Desktop notifications enabled."); + prefs_set_notify(TRUE); + } else if (strcmp(inp, "/notify off") == 0) { + cons_show("Desktop notifications disabled."); + prefs_set_notify(FALSE); + } else { + cons_show("Usage: /notify "); + } + + return TRUE; +} + static gboolean _cmd_set_flash(const char * const inp) { if (strcmp(inp, "/flash on") == 0) { diff --git a/preferences.c b/preferences.c index b1284a4c..90002161 100644 --- a/preferences.c +++ b/preferences.c @@ -173,6 +173,17 @@ void prefs_set_beep(gboolean value) _save_prefs(); } +gboolean prefs_get_notify(void) +{ + return g_key_file_get_boolean(prefs, "ui", "notify", NULL); +} + +void prefs_set_notify(gboolean value) +{ + g_key_file_set_boolean(prefs, "ui", "notify", value); + _save_prefs(); +} + gboolean prefs_get_flash(void) { return g_key_file_get_boolean(prefs, "ui", "flash", NULL); diff --git a/preferences.h b/preferences.h index 056b8253..93fea268 100644 --- a/preferences.h +++ b/preferences.h @@ -32,6 +32,8 @@ void reset_login_search(void); gboolean prefs_get_beep(void); void prefs_set_beep(gboolean value); +gboolean prefs_get_notify(void); +void prefs_set_notify(gboolean value); gboolean prefs_get_flash(void); void prefs_set_flash(gboolean value); void prefs_add_login(const char *jid); diff --git a/windows.c b/windows.c index 76cb2781..6ccf0ff0 100644 --- a/windows.c +++ b/windows.c @@ -189,11 +189,12 @@ void win_show_incomming_msg(const char * const from, const char * const message) if (prefs_get_flash()) flash(); - _win_notify(short_from); } if (prefs_get_beep()) beep(); + if (prefs_get_notify()) + _win_notify(short_from); } static void _win_notify(char * short_from) @@ -305,6 +306,7 @@ void cons_help(void) cons_show("Settings:"); cons_show(""); cons_show("/beep : Enable/disable sound notification"); + cons_show("/notify : Enable/disable desktop notifications"); cons_show("/flash : Enable/disable screen flash notification"); cons_show("/showsplash : Enable/disable splash logo on startup"); cons_show("");