about summary refs log tree commit diff stats
path: root/command.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-05-28 21:51:05 +0100
committerJames Booth <boothj5@gmail.com>2012-05-28 21:51:05 +0100
commit240f7badb0050862320f413aeb53b39f34a35a81 (patch)
tree445bb39940d86c151c0855dacdad696e8f2f7ccd /command.c
parentf237a17c2a4b9143fac97053543c9caf6c24fdb9 (diff)
downloadprofani-tty-240f7badb0050862320f413aeb53b39f34a35a81.tar.gz
Refactored presence commands
Diffstat (limited to 'command.c')
-rw-r--r--command.c73
1 files changed, 23 insertions, 50 deletions
diff --git a/command.c b/command.c
index ab868016..c5139c92 100644
--- a/command.c
+++ b/command.c
@@ -50,6 +50,8 @@ static gboolean _cmd_dnd(const char * const inp);
 static gboolean _cmd_chat(const char * const inp);
 static gboolean _cmd_xa(const char * const inp);
 static gboolean _cmd_default(const char * const inp);
+static void _update_presence(const jabber_presence_t presence, 
+    const char * const show);
 
 gboolean process_input(char *inp)
 {
@@ -267,76 +269,31 @@ static gboolean _cmd_set_flash(const char * const inp)
 
 static gboolean _cmd_away(const char * const inp)
 {
-    jabber_conn_status_t conn_status = jabber_connection_status();
-
-    if (conn_status != JABBER_CONNECTED) {
-        cons_show("You are not currently connected.");
-    } else {
-        jabber_update_presence(PRESENCE_AWAY);
-        title_bar_set_status(PRESENCE_AWAY);
-        cons_show("Status set to \"away\"");
-    }
-
+    _update_presence(PRESENCE_AWAY, "away");
     return TRUE;
 }
 
 static gboolean _cmd_online(const char * const inp)
 {
-    jabber_conn_status_t conn_status = jabber_connection_status();
-
-    if (conn_status != JABBER_CONNECTED) {
-        cons_show("You are not currently connected.");
-    } else {
-        jabber_update_presence(PRESENCE_ONLINE);
-        title_bar_set_status(PRESENCE_ONLINE);
-        cons_show("Status set to \"online\"");
-    }
-
+    _update_presence(PRESENCE_ONLINE, "online");
     return TRUE;
 }
 
 static gboolean _cmd_dnd(const char * const inp)
 {
-    jabber_conn_status_t conn_status = jabber_connection_status();
-
-    if (conn_status != JABBER_CONNECTED) {
-        cons_show("You are not currently connected.");
-    } else {
-        jabber_update_presence(PRESENCE_DND);
-        title_bar_set_status(PRESENCE_DND);
-        cons_show("Status set to \"dnd\"");
-    }
-
+    _update_presence(PRESENCE_DND, "dnd");
     return TRUE;
 }
 
 static gboolean _cmd_chat(const char * const inp)
 {
-    jabber_conn_status_t conn_status = jabber_connection_status();
-
-    if (conn_status != JABBER_CONNECTED) {
-        cons_show("You are not currently connected.");
-    } else {
-        jabber_update_presence(PRESENCE_CHAT);
-        title_bar_set_status(PRESENCE_CHAT);
-        cons_show("Status set to \"chat\"");
-    }
-
+    _update_presence(PRESENCE_CHAT, "chat");
     return TRUE;
 }
 
 static gboolean _cmd_xa(const char * const inp)
 {
-    jabber_conn_status_t conn_status = jabber_connection_status();
-
-    if (conn_status != JABBER_CONNECTED) {
-        cons_show("You are not currently connected.");
-    } else {
-        jabber_update_presence(PRESENCE_XA);
-        title_bar_set_status(PRESENCE_XA);
-        cons_show("Status set to \"xa\"");
-    }
-
+    _update_presence(PRESENCE_XA, "xa");
     return TRUE;
 }
 
@@ -353,3 +310,19 @@ static gboolean _cmd_default(const char * const inp)
 
     return TRUE;
 }
+
+static void _update_presence(const jabber_presence_t presence, 
+    const char * const show)
+{
+    jabber_conn_status_t conn_status = jabber_connection_status();
+    
+    if (conn_status != JABBER_CONNECTED) {
+        cons_show("You are not currently connected.");
+    } else {
+        jabber_update_presence(presence);
+        title_bar_set_status(presence);
+        char str[16 + strlen(show) + 1];
+        sprintf(str, "Status set to \"%s\"", show);
+        cons_show(str);
+    }
+}