From 5356118147f715109f8482b4af4d642bc5f6c4a1 Mon Sep 17 00:00:00 2001 From: Backalor Date: Mon, 14 Jan 2013 18:51:37 +0900 Subject: [PATCH] Add new command "/notify status" to enable/disable status messages, such as users going on/offline or room joining/parting. --- src/command.c | 24 ++++++++++++++++++++++-- src/preferences.c | 13 +++++++++++++ src/preferences.h | 2 ++ src/windows.c | 8 ++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index 82374b3a..0c495947 100644 --- a/src/command.c +++ b/src/command.c @@ -385,11 +385,14 @@ static struct cmd_t setting_commands[] = " : use 0 to disable.", "typing : Notifications when contacts are typing.", " : on|off", + "status : Notifcations for status messages.", + " : on|off", "", "Example : /notify message on (enable message notifications)", "Example : /notify remind 10 (remind every 10 seconds)", "Example : /notify remind 0 (switch off reminders)", "Example : /notify typing on (enable typing notifications)", + "Example : /notify status off (disable status notifications)", NULL } } }, { "/flash", @@ -642,6 +645,7 @@ cmd_init(void) p_autocomplete_add(notify_ac, strdup("message")); p_autocomplete_add(notify_ac, strdup("typing")); p_autocomplete_add(notify_ac, strdup("remind")); + p_autocomplete_add(notify_ac, strdup("status")); sub_ac = p_autocomplete_new(); p_autocomplete_add(sub_ac, strdup("request")); @@ -1778,7 +1782,7 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help) // bad kind if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) && - (strcmp(kind, "remind") != 0)) { + (strcmp(kind, "remind") != 0) && (strcmp(kind, "status") != 0)) { cons_show("Usage: %s", help.usage); // set message setting @@ -1805,7 +1809,8 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help) cons_show("Usage: /notify typing on|off"); } - } else { // remind + // set remind setting + } else if (strcmp(kind, "remind") == 0) { gint period = atoi(value); prefs_set_notify_remind(period); if (period == 0) { @@ -1815,6 +1820,21 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help) } else { cons_show("Message reminder period set to %d seconds.", period); } + + // set status setting + } else if (strcmp(kind, "status") == 0) { + if (strcmp(value, "on") == 0) { + cons_show("Status notifications enabled."); + prefs_set_notify_status(TRUE); + } else if (strcmp(value, "off") == 0) { + cons_show("Status notifications disabled."); + prefs_set_notify_status(FALSE); + } else { + cons_show("Usage: /notify status on|off"); + } + + } else { + cons_show("Unknown command: %s.", kind); } return TRUE; diff --git a/src/preferences.c b/src/preferences.c index e8c727b5..64a420ee 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -410,6 +410,19 @@ prefs_set_splash(gboolean value) _save_prefs(); } +gboolean +prefs_get_notify_status(void) +{ + return g_key_file_get_boolean(prefs, "notification", "status", NULL); +} + +void +prefs_set_notify_status(gboolean value) +{ + g_key_file_set_boolean(prefs, "notification", "status", value); + _save_prefs(); +} + static void _save_prefs(void) { diff --git a/src/preferences.h b/src/preferences.h index f9bb8f45..a0b6224c 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -75,6 +75,8 @@ void prefs_set_notify_typing(gboolean value); gboolean prefs_get_notify_typing(void); void prefs_set_notify_remind(gint period); gint prefs_get_notify_remind(void); +void prefs_set_notify_status(gboolean value); +gboolean prefs_get_notify_status(void); void prefs_set_max_log_size(gint value); gint prefs_get_max_log_size(void); void prefs_set_priority(gint value); diff --git a/src/windows.c b/src/windows.c index ccba1631..ea3a6815 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1253,6 +1253,11 @@ cons_show_desktop_prefs(void) } else { cons_show("Reminder period (/notify remind) : %d seconds", remind_period); } + + if (prefs_get_notify_status()) + cons_show("Status (/notify status) : ON"); + else + cons_show("Status (/notify status) : OFF"); } void @@ -1966,6 +1971,9 @@ _show_status_string(WINDOW *win, const char * const from, GDateTime *last_activity, const char * const pre, const char * const default_show) { + if (!prefs_get_notify_status()) + return; + _win_show_time(win); if (show != NULL) {