about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-15 01:41:34 +0100
committerJames Booth <boothj5@gmail.com>2016-05-15 01:41:34 +0100
commitc6a6e3a51cb2fa1b036fa17cf89b8d9dab95c293 (patch)
tree60183c7b199b73521269d3f58fac8d6cd434c423
parentd00615beba0e9f6d463b821c3a9406e412ebbfe2 (diff)
downloadprofani-tty-c6a6e3a51cb2fa1b036fa17cf89b8d9dab95c293.tar.gz
Add /tray timer <seconds>
closes #787
-rw-r--r--src/command/command.c9
-rw-r--r--src/command/commands.c35
-rw-r--r--src/config/preferences.c19
-rw-r--r--src/config/preferences.h3
-rw-r--r--src/tray.c11
-rw-r--r--src/tray.h2
-rw-r--r--src/ui/console.c3
7 files changed, 75 insertions, 7 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 129c2d6b..7495506f 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -1420,12 +1420,14 @@ static struct cmd_t command_defs[] =
             CMD_TAG_UI)
         CMD_SYN(
             "/tray on|off",
-            "/tray read on|off")
+            "/tray read on|off",
+            "/tray timer <seconds>")
         CMD_DESC(
             "Display an icon in the tray that will indicate new messages.")
         CMD_ARGS(
-            { "on|off", "Show tray icon." },
-            { "read on|off", "Show tray icon when no unread messages." })
+            { "on|off",             "Show tray icon." },
+            { "read on|off",        "Show tray icon when no unread messages." },
+            { "timer <seconds>",    "Set tray icon timer, seconds must be between 1-10" })
         CMD_NOEXAMPLES
     },
 
@@ -2868,6 +2870,7 @@ cmd_init(void)
     autocomplete_add(tray_ac, "on");
     autocomplete_add(tray_ac, "off");
     autocomplete_add(tray_ac, "read");
+    autocomplete_add(tray_ac, "timer");
 }
 
 void
diff --git a/src/command/commands.c b/src/command/commands.c
index d0947a60..3060cf49 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -5865,9 +5865,35 @@ gboolean
 cmd_tray(ProfWin *window, const char *const command, gchar **args)
 {
 #ifdef HAVE_GTK
-    if (g_strcmp0(args[0], "read") == 0) {
+    if (g_strcmp0(args[0], "timer") == 0) {
+        if (args[1] == NULL) {
+            cons_bad_cmd_usage(command);
+            return TRUE;
+        }
+
         if (prefs_get_boolean(PREF_TRAY) == FALSE) {
-            cons_show("Tray icon no currently enable, see /help tray");
+            cons_show("Tray icon not currently enabled, see /help tray");
+            return TRUE;
+        }
+
+        int intval = 0;
+        char *err_msg = NULL;
+        gboolean res = strtoi_range(args[1], &intval, 1, 10, &err_msg);
+        if (res) {
+            cons_show("Tray timer set to %d seconds.", intval);
+            prefs_set_tray_timer(intval);
+            if (prefs_get_boolean(PREF_TRAY)) {
+                tray_set_timer(intval);
+            }
+        } else {
+            cons_show(err_msg);
+            free(err_msg);
+        }
+
+        return TRUE;
+    } else if (g_strcmp0(args[0], "read") == 0) {
+        if (prefs_get_boolean(PREF_TRAY) == FALSE) {
+            cons_show("Tray icon not currently enabled, see /help tray");
         } else if (g_strcmp0(args[1], "on") == 0) {
             prefs_set_boolean(PREF_TRAY_READ, TRUE);
             cons_show("Tray icon enabled when no unread messages.");
@@ -5877,6 +5903,8 @@ cmd_tray(ProfWin *window, const char *const command, gchar **args)
         } else {
             cons_bad_cmd_usage(command);
         }
+
+        return TRUE;
     } else {
         gboolean old = prefs_get_boolean(PREF_TRAY);
         _cmd_set_boolean_preference(args[0], command, "Tray icon", PREF_TRAY);
@@ -5888,8 +5916,9 @@ cmd_tray(ProfWin *window, const char *const command, gchar **args)
                 tray_disable();
             }
         }
+
+        return TRUE;
     }
-    return TRUE;
 #else
     cons_show("This version of Profanity has not been built with GTK Tray Icon support enabled");
     return TRUE;
diff --git a/src/config/preferences.c b/src/config/preferences.c
index afbde809..5d3d0512 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -591,6 +591,25 @@ prefs_set_autoxa_time(gint value)
     _save_prefs();
 }
 
+void
+prefs_set_tray_timer(gint value)
+{
+    g_key_file_set_integer(prefs, PREF_GROUP_NOTIFICATIONS, "tray.timer", value);
+    _save_prefs();
+}
+
+gint
+prefs_get_tray_timer(void)
+{
+    gint result = g_key_file_get_integer(prefs, PREF_GROUP_NOTIFICATIONS, "tray.timer", NULL);
+
+    if (result == 0) {
+        return 5;
+    } else {
+        return result;
+    }
+}
+
 gchar**
 prefs_get_plugins(void)
 {
diff --git a/src/config/preferences.h b/src/config/preferences.h
index b4a31a77..5e4b28ef 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -224,6 +224,9 @@ void prefs_set_roster_presence_indent(gint value);
 
 void prefs_add_login(const char *jid);
 
+void prefs_set_tray_timer(gint value);
+gint prefs_get_tray_timer(void);
+
 gboolean prefs_add_alias(const char *const name, const char *const value);
 gboolean prefs_remove_alias(const char *const name);
 char* prefs_get_alias(const char *const name);
diff --git a/src/tray.c b/src/tray.c
index dfe2831e..c16557a3 100644
--- a/src/tray.c
+++ b/src/tray.c
@@ -193,12 +193,21 @@ tray_shutdown(void)
 }
 
 void
+tray_set_timer(int interval)
+{
+    g_source_remove(timer);
+    _tray_change_icon(NULL);
+    timer = g_timeout_add(interval * 1000, _tray_change_icon, NULL);
+}
+
+void
 tray_enable(void)
 {
     prof_tray = gtk_status_icon_new_from_file(icon_filename->str);
     shutting_down = FALSE;
     _tray_change_icon(NULL);
-    timer = g_timeout_add(5000, _tray_change_icon, NULL);
+    int interval = prefs_get_tray_timer() * 1000;
+    timer = g_timeout_add(interval, _tray_change_icon, NULL);
 }
 
 void
diff --git a/src/tray.h b/src/tray.h
index 81ddd20f..751af07c 100644
--- a/src/tray.h
+++ b/src/tray.h
@@ -51,4 +51,6 @@ void tray_enable(void);
  */
 void tray_disable(void);
 
+void tray_set_timer(int interval);
+
 #endif
diff --git a/src/ui/console.c b/src/ui/console.c
index fc0da30f..3f44f133 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1193,6 +1193,9 @@ cons_tray_setting(void)
         cons_show("Tray icon read (/tray)              : ON");
     else
         cons_show("Tray icon read (/tray)              : OFF");
+
+    int seconds = prefs_get_tray_timer();
+    cons_show("Tray timer (/tray)                  : %d seconds", seconds);
 }
 
 void