about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-09-23 22:24:31 +0100
committerJames Booth <boothj5@gmail.com>2012-09-23 22:24:31 +0100
commitf48820040837626ea156d9dbc9b071417a0c365b (patch)
tree9ff587cc84fc8becdc851852f94c1dcdbbcabb0b
parent294ea2d1bedd741d4f2ea2c17036f517227a9282 (diff)
downloadprofani-tty-f48820040837626ea156d9dbc9b071417a0c365b.tar.gz
Made periodic message reminders a user option
-rw-r--r--src/command.c41
-rw-r--r--src/preferences.c13
-rw-r--r--src/preferences.h2
-rw-r--r--src/profanity.c4
-rw-r--r--src/windows.c30
5 files changed, 74 insertions, 16 deletions
diff --git a/src/command.c b/src/command.c
index ec165ca1..740294a3 100644
--- a/src/command.c
+++ b/src/command.c
@@ -73,6 +73,7 @@ static gboolean _cmd_set_typing(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_set_flash(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_set_showsplash(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_set_chlog(const char * const inp, struct cmd_help_t help);
+static gboolean _cmd_set_remind(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_away(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_online(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help);
@@ -204,10 +205,10 @@ static struct cmd_t setting_commands[] =
 
     { "/notify",
         _cmd_set_notify,
-        { "/notify on|off", "Enable/disable desktop notifications.",
+        { "/notify on|off", "Enable/disable message notifications.",
         { "/notify on|off",
           "--------------",
-          "Switch the desktop notifications on or off.",
+          "Switch the message notifications on or off.",
           "The notification will appear for all incoming messages.",
           "The desktop environment must support desktop notifications.",
           "",
@@ -228,6 +229,19 @@ static struct cmd_t setting_commands[] =
           "Config file value :   typing=true|false",
           NULL } } },
 
+    { "/remind",
+        _cmd_set_remind,
+        { "/remind seconds", "Set message reminder period in seconds.",
+        { "/remind seconds",
+          "--------------",
+          "Set the period for new message reminders as desktop notifications.",
+          "The value is in seconds, a setting of 0 will disable the feature.",
+          "The desktop environment must support desktop notifications.",
+          "",
+          "Config file section : [ui]",
+          "Config file value :   remind=seconds",
+          NULL } } },
+
     { "/flash", 
         _cmd_set_flash,
         { "/flash on|off", "Enable/disable screen flash notifications.",
@@ -702,6 +716,29 @@ _cmd_set_chlog(const char * const inp, struct cmd_help_t help)
 }
 
 static gboolean
+_cmd_set_remind(const char * const inp, struct cmd_help_t help)
+{
+    if ((strncmp(inp, "/remind ", 8) != 0) || (strlen(inp) < 9)) {
+        char usage[strlen(help.usage + 8)];
+        sprintf(usage, "Usage: %s", help.usage);
+        cons_show(usage);
+    } else {
+        // copy input    
+        char inp_cpy[strlen(inp) + 1];
+        strcpy(inp_cpy, inp);
+
+        // get period
+        strtok(inp_cpy, " ");
+        char *period_str = strtok(NULL, " ");
+        gint period = atoi(period_str);
+
+        prefs_set_remind(period);
+    }
+
+    return TRUE;    
+}
+
+static gboolean
 _cmd_away(const char * const inp, struct cmd_help_t help)
 {
     _update_presence(PRESENCE_AWAY, "away", inp);
diff --git a/src/preferences.c b/src/preferences.c
index cb575313..13aa1793 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -269,6 +269,19 @@ prefs_set_chlog(gboolean value)
     _save_prefs();
 }
 
+gint
+prefs_get_remind(void)
+{
+    return g_key_file_get_integer(prefs, "ui", "remind", NULL);
+}
+
+void
+prefs_set_remind(gint value)
+{
+    g_key_file_set_integer(prefs, "ui", "remind", value);
+    _save_prefs();
+}
+
 void
 prefs_add_login(const char *jid)
 {
diff --git a/src/preferences.h b/src/preferences.h
index 452720d9..e94701e4 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -52,6 +52,8 @@ gboolean prefs_get_chlog(void);
 void prefs_set_chlog(gboolean value);
 gboolean prefs_get_showsplash(void);
 void prefs_set_showsplash(gboolean value);
+gint prefs_get_remind(void);
+void prefs_set_remind(gint value);
 
 void prefs_add_login(const char *jid);
 
diff --git a/src/profanity.c b/src/profanity.c
index e8047030..0a76dbff 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -41,8 +41,6 @@ static log_level_t _get_log_level(char *log_level);
 gboolean _process_input(char *inp);
 static void _create_config_directory();
 
-static gdouble remind_period = 10;
-
 void
 profanity_run(void)
 {
@@ -62,6 +60,8 @@ profanity_run(void)
         while(ch != '\n') {
 
             gdouble elapsed = g_timer_elapsed(timer, NULL);
+            
+            gint remind_period = prefs_get_remind();
 
             // 0 means to not remind
             if (remind_period > 0 && elapsed >= remind_period) {
diff --git a/src/windows.c b/src/windows.c
index df0d8c7f..e7e93bb9 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -472,34 +472,40 @@ cons_prefs(void)
     cons_show("");
     
     if (prefs_get_beep())
-        cons_show("Terminal beep         : ON");
+        cons_show("Terminal beep           : ON");
     else
-        cons_show("Terminal beep         : OFF");    
+        cons_show("Terminal beep           : OFF");    
     
     if (prefs_get_flash())
-        cons_show("Terminal flash        : ON");
+        cons_show("Terminal flash          : ON");
     else
-        cons_show("Terminal flash        : OFF");    
+        cons_show("Terminal flash          : OFF");    
     
     if (prefs_get_notify())
-        cons_show("Desktop notifications : ON");
+        cons_show("Message notifications   : ON");
     else
-        cons_show("Desktop notifications : OFF");    
+        cons_show("Message notifications   : OFF");    
 
     if (prefs_get_typing())
-        cons_show("Typing notifications  : ON");
+        cons_show("Typing notifications    : ON");
     else
-        cons_show("Typing notifications  : OFF");    
+        cons_show("Typing notifications    : OFF");    
 
     if (prefs_get_showsplash())
-        cons_show("Splash screen         : ON");
+        cons_show("Splash screen           : ON");
     else
-        cons_show("Splash screen         : OFF");    
+        cons_show("Splash screen           : OFF");    
     
     if (prefs_get_chlog())
-        cons_show("Chat logging          : ON");
+        cons_show("Chat logging            : ON");
     else
-        cons_show("Chat logging          : OFF");    
+        cons_show("Chat logging            : OFF");    
+
+    char remind_period[50];
+    sprintf(remind_period, 
+                  "Message reminder period : %d seconds", prefs_get_remind());
+
+    cons_show(remind_period);
 
     cons_show("");