about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-06-28 23:45:37 +0100
committerJames Booth <boothj5@gmail.com>2012-06-28 23:45:37 +0100
commit54ef09bfbd619cf5d936d27b7ec207744c7f5c04 (patch)
tree41ed9ec5ff2c0be1621ced6ac33e672d9db2200e
parent18494c3701334bb64756f218095b6003039c8169 (diff)
downloadprofani-tty-54ef09bfbd619cf5d936d27b7ec207744c7f5c04.tar.gz
Added notify preference
-rw-r--r--command.c17
-rw-r--r--preferences.c11
-rw-r--r--preferences.h2
-rw-r--r--windows.c4
4 files changed, 33 insertions, 1 deletions
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 <on/off>");
+    }        
+
+    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 <on/off>       : Enable/disable sound notification");
+    cons_show("/notify <on/off>     : Enable/disable desktop notifications");
     cons_show("/flash <on/off>      : Enable/disable screen flash notification");
     cons_show("/showsplash <on/off> : Enable/disable splash logo on startup");
     cons_show("");