1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Commands for presence updates

This commit is contained in:
James Booth 2012-05-27 20:36:31 +01:00
parent f5eab87588
commit dd9f6f825e
6 changed files with 74 additions and 52 deletions

View File

@ -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()) {

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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,7 +85,37 @@ 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)
{
current_status = status;
_title_bar_draw_status();
}
static void _title_bar_draw_status()
{
int rows, cols;
getmaxyx(stdscr, rows, cols);
wattron(title_bar, COLOR_PAIR(4));
mvwaddch(title_bar, 0, cols - 14, '[');
wattroff(title_bar, COLOR_PAIR(4));
if (current_status == PRESENCE_ONLINE) {
mvwprintw(title_bar, 0, cols - 13, " ...online ");
} 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, ']');
wattroff(title_bar, COLOR_PAIR(4));
dirty = TRUE;
}
static void _title_bar_draw_title(void)
{
wmove(title_bar, 0, 0);
int i;
@ -107,23 +126,3 @@ void _title_bar_draw_title(void)
dirty = TRUE;
}
void _title_bar_draw_status(void)
{
int rows, cols;
getmaxyx(stdscr, rows, cols);
wattron(title_bar, COLOR_PAIR(4));
mvwaddch(title_bar, 0, cols - 14, '[');
wattroff(title_bar, COLOR_PAIR(4));
if (connected == TRUE)
mvwprintw(title_bar, 0, cols - 13, " ...online ");
else
mvwprintw(title_bar, 0, cols - 13, " ..offline ");
wattron(title_bar, COLOR_PAIR(4));
mvwaddch(title_bar, 0, cols - 2, ']');
wattroff(title_bar, COLOR_PAIR(4));
dirty = TRUE;
}

5
ui.h
View File

@ -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);