about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-05-27 20:36:31 +0100
committerJames Booth <boothj5@gmail.com>2012-05-27 20:36:31 +0100
commitdd9f6f825ea7b602f3064ca4a6099dfb5cd9910d (patch)
treee55549537342d40031b4b41d903a8622dac6c175
parentf5eab875884feda2b1e40e0dcd76150ca1b0763f (diff)
downloadprofani-tty-dd9f6f825ea7b602f3064ca4a6099dfb5cd9910d.tar.gz
Commands for presence updates
-rw-r--r--command.c19
-rw-r--r--common.h13
-rw-r--r--jabber.c3
-rw-r--r--jabber.h13
-rw-r--r--title_bar.c53
-rw-r--r--ui.h5
6 files changed, 64 insertions, 42 deletions
diff --git a/command.c b/command.c
index f8f7eb7d..19f982cd 100644
--- a/command.c
+++ b/command.c
@@ -45,6 +45,7 @@ static gboolean _cmd_close(const char * const inp);
 static gboolean _cmd_set_beep(const char * const inp);
 static gboolean _cmd_set_flash(const char * const inp);
 static gboolean _cmd_away(const char * const inp);
+static gboolean _cmd_online(const char * const inp);
 static gboolean _cmd_default(const char * const inp);
 
 gboolean process_input(char *inp)
@@ -103,6 +104,8 @@ static gboolean _handle_command(const char * const command, const char * const i
         result = _cmd_set_flash(inp);
     } else if (strcmp(command, "/away") == 0) {
         result = _cmd_away(inp);
+    } else if (strcmp(command, "/online") == 0) {
+        result = _cmd_online(inp);
     } else {
         result = _cmd_default(inp);
     }
@@ -261,12 +264,28 @@ static gboolean _cmd_away(const char * const inp)
         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\"");
     }
 
     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\"");
+    }
+
+    return TRUE;
+}
+
 static gboolean _cmd_default(const char * const inp)
 {
     if (win_in_chat()) {
diff --git a/common.h b/common.h
index 9966408a..ee87da27 100644
--- a/common.h
+++ b/common.h
@@ -25,6 +25,19 @@
 
 #include <glib.h>
 
+typedef enum {
+    JABBER_STARTED,
+    JABBER_CONNECTING,
+    JABBER_CONNECTED,
+    JABBER_DISCONNECTED
+} jabber_conn_status_t;
+
+typedef enum {
+    PRESENCE_OFFLINE,
+    PRESENCE_ONLINE,
+    PRESENCE_AWAY
+} jabber_presence_t;
+
 #if !GLIB_CHECK_VERSION(2,28,0)
 #define g_slist_free_full(items, free_func)      p_slist_free_full(items, free_func)
 #endif
diff --git a/jabber.c b/jabber.c
index 4867e3e1..37a049f7 100644
--- a/jabber.c
+++ b/jabber.c
@@ -24,6 +24,7 @@
 #include <strophe.h>
 
 #include "jabber.h"
+#include "common.h"
 #include "log.h"
 #include "contact_list.h"
 #include "ui.h"
@@ -214,7 +215,7 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
         const char *msg = " logged in successfully.";
         char line[strlen(jid) + 1 + strlen(msg) + 1];
         sprintf(line, "%s %s", jid, msg);
-        title_bar_connected();
+        title_bar_set_status(PRESENCE_ONLINE);
 
         cons_show(line);
         win_page_off();
diff --git a/jabber.h b/jabber.h
index fc7766d2..574ea0a1 100644
--- a/jabber.h
+++ b/jabber.h
@@ -23,18 +23,7 @@
 #ifndef JABBER_H
 #define JABBER_H
 
-typedef enum {
-    JABBER_STARTED,
-    JABBER_CONNECTING,
-    JABBER_CONNECTED,
-    JABBER_DISCONNECTED
-} jabber_conn_status_t;
-
-typedef enum {
-    PRESENCE_OFFLINE,
-    PRESENCE_ONLINE,
-    PRESENCE_AWAY
-} jabber_presence_t;
+#include "common.h"
 
 void jabber_init(const int disable_tls);
 jabber_conn_status_t jabber_connection_status(void);
diff --git a/title_bar.c b/title_bar.c
index 2b0e08b5..c487801a 100644
--- a/title_bar.c
+++ b/title_bar.c
@@ -24,15 +24,16 @@
 #include <string.h>
 #include <ncurses.h>
 
+#include "common.h"
 #include "ui.h"
 
 static WINDOW *title_bar;
 static char *current_title = NULL;
-static int connected = FALSE;
 static int dirty;
+static jabber_presence_t current_status;
 
-void _title_bar_draw_title(void);
-void _title_bar_draw_status(void);
+static void _title_bar_draw_title(void);
+static void _title_bar_draw_status(void);
 
 void create_title_bar(void)
 {
@@ -42,7 +43,7 @@ void create_title_bar(void)
     title_bar = newwin(1, cols, 0, 0);
     wbkgd(title_bar, COLOR_PAIR(3));
     title_bar_title();
-    title_bar_disconnected();
+    title_bar_set_status(PRESENCE_OFFLINE);
     dirty = TRUE;
 }
 
@@ -52,18 +53,6 @@ void title_bar_title(void)
     dirty = TRUE;
 }
 
-void title_bar_connected(void)
-{
-    connected = TRUE;
-    _title_bar_draw_status();
-}
-
-void title_bar_disconnected(void)
-{
-    connected = FALSE;
-    _title_bar_draw_status();
-}
-
 void title_bar_resize(void)
 {
     int rows, cols;
@@ -96,18 +85,13 @@ void title_bar_show(const char * const title)
     _title_bar_draw_title();
 }
 
-void _title_bar_draw_title(void)
+void title_bar_set_status(jabber_presence_t status)
 {
-    wmove(title_bar, 0, 0);
-    int i;
-    for (i = 0; i < 45; i++)
-        waddch(title_bar, ' ');
-    mvwprintw(title_bar, 0, 0, " %s", current_title);
-    
-    dirty = TRUE;
+    current_status = status;
+    _title_bar_draw_status();
 }
 
-void _title_bar_draw_status(void)
+static void _title_bar_draw_status()
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
@@ -116,10 +100,13 @@ void _title_bar_draw_status(void)
     mvwaddch(title_bar, 0, cols - 14, '[');
     wattroff(title_bar, COLOR_PAIR(4));
 
-    if (connected == TRUE)
+    if (current_status == PRESENCE_ONLINE) {
         mvwprintw(title_bar, 0, cols - 13, " ...online ");
-    else
+    } else if (current_status == PRESENCE_AWAY) {
+        mvwprintw(title_bar, 0, cols - 13, " .....away ");
+    } else {
         mvwprintw(title_bar, 0, cols - 13, " ..offline ");
+    }
     
     wattron(title_bar, COLOR_PAIR(4));
     mvwaddch(title_bar, 0, cols - 2, ']');
@@ -127,3 +114,15 @@ void _title_bar_draw_status(void)
     
     dirty = TRUE;
 }
+
+static void _title_bar_draw_title(void)
+{
+    wmove(title_bar, 0, 0);
+    int i;
+    for (i = 0; i < 45; i++)
+        waddch(title_bar, ' ');
+    mvwprintw(title_bar, 0, 0, " %s", current_title);
+    
+    dirty = TRUE;
+}
+
diff --git a/ui.h b/ui.h
index 42d2b764..5bdda9a8 100644
--- a/ui.h
+++ b/ui.h
@@ -24,6 +24,8 @@
 #define WINDOWS_h
 
 #include <ncurses.h>
+
+#include "common.h"
 #include "contact_list.h"
 
 struct prof_win {
@@ -50,8 +52,7 @@ void title_bar_refresh(void);
 void title_bar_resize(void);
 void title_bar_show(const char * const title);
 void title_bar_title(void);
-void title_bar_connected(void);
-void title_bar_disconnected(void);
+void title_bar_set_status(jabber_presence_t status);
 
 // main window actions
 int win_close_win(void);