Added resource_presence_t and contact_presence_t

This commit is contained in:
James Booth
2013-02-10 17:13:19 +00:00
parent 59e9b10d19
commit e922568770
17 changed files with 162 additions and 182 deletions

View File

@@ -87,7 +87,7 @@ if test "x$enable_notifications" != xno; then
fi fi
# Default parameters # Default parameters
AM_CFLAGS="-Wall" AM_CFLAGS="-Wall -Werror"
LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS" LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS"
AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS" AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS"

View File

@@ -68,7 +68,7 @@ struct cmd_t {
}; };
static struct cmd_t * _cmd_get_command(const char * const command); static struct cmd_t * _cmd_get_command(const char * const command);
static void _update_presence(const presence_t presence, static void _update_presence(const resource_presence_t presence,
const char * const show, gchar **args); const char * const show, gchar **args);
static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
const char * const display, preference_t pref); const char * const display, preference_t pref);
@@ -85,7 +85,6 @@ static void _parameter_autocomplete_with_ac(char *input, int *size, char *comman
Autocomplete ac); Autocomplete ac);
static int _strtoi(char *str, int *saveptr, int min, int max); static int _strtoi(char *str, int *saveptr, int min, int max);
static presence_t _presence_type_from_string(const char * const str);
// command prototypes // command prototypes
static gboolean _cmd_quit(gchar **args, struct cmd_help_t help); static gboolean _cmd_quit(gchar **args, struct cmd_help_t help);
@@ -1164,41 +1163,38 @@ _cmd_account(gchar **args, struct cmd_help_t help)
cons_show("Updated resource for account %s: %s", account_name, value); cons_show("Updated resource for account %s: %s", account_name, value);
cons_show(""); cons_show("");
} else if (strcmp(property, "status") == 0) { } else if (strcmp(property, "status") == 0) {
if (!presence_valid_string(value) && (strcmp(value, "last") != 0)) { if (!valid_resource_presence_string(value) && (strcmp(value, "last") != 0)) {
cons_show("Invalud status: %s", value); cons_show("Invalud status: %s", value);
} else { } else {
accounts_set_login_presence(account_name, value); accounts_set_login_presence(account_name, value);
cons_show("Updated login status for account %s: %s", account_name, value); cons_show("Updated login status for account %s: %s", account_name, value);
} }
cons_show(""); cons_show("");
} else if (presence_valid_string(property)) { } else if (valid_resource_presence_string(property)) {
int intval; int intval;
if (_strtoi(value, &intval, -128, 127) == 0) { if (_strtoi(value, &intval, -128, 127) == 0) {
presence_t presence_type = _presence_type_from_string(property); resource_presence_t presence_type = resource_presence_from_string(property);
switch (presence_type) switch (presence_type)
{ {
case (PRESENCE_ONLINE): case (RESOURCE_ONLINE):
accounts_set_priority_online(account_name, intval); accounts_set_priority_online(account_name, intval);
break; break;
case (PRESENCE_CHAT): case (RESOURCE_CHAT):
accounts_set_priority_chat(account_name, intval); accounts_set_priority_chat(account_name, intval);
break; break;
case (PRESENCE_AWAY): case (RESOURCE_AWAY):
accounts_set_priority_away(account_name, intval); accounts_set_priority_away(account_name, intval);
break; break;
case (PRESENCE_XA): case (RESOURCE_XA):
accounts_set_priority_xa(account_name, intval); accounts_set_priority_xa(account_name, intval);
break; break;
case (PRESENCE_DND): case (RESOURCE_DND):
accounts_set_priority_dnd(account_name, intval); accounts_set_priority_dnd(account_name, intval);
break; break;
default:
accounts_set_priority_online(account_name, intval);
break;
} }
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name());
if (conn_status == JABBER_CONNECTED && presence_type == last_presence) { if (conn_status == JABBER_CONNECTED && presence_type == last_presence) {
presence_update(last_presence, jabber_get_presence_message(), 0); presence_update(last_presence, jabber_get_presence_message(), 0);
} }
@@ -2239,7 +2235,7 @@ _cmd_set_priority(gchar **args, struct cmd_help_t help)
if (_strtoi(value, &intval, -128, 127) == 0) { if (_strtoi(value, &intval, -128, 127) == 0) {
accounts_set_priority_all(jabber_get_account_name(), intval); accounts_set_priority_all(jabber_get_account_name(), intval);
presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name());
presence_update(last_presence, jabber_get_presence_message(), 0); presence_update(last_presence, jabber_get_presence_message(), 0);
cons_show("Priority set to %d.", intval); cons_show("Priority set to %d.", intval);
} }
@@ -2313,42 +2309,42 @@ _cmd_set_history(gchar **args, struct cmd_help_t help)
static gboolean static gboolean
_cmd_away(gchar **args, struct cmd_help_t help) _cmd_away(gchar **args, struct cmd_help_t help)
{ {
_update_presence(PRESENCE_AWAY, "away", args); _update_presence(RESOURCE_AWAY, "away", args);
return TRUE; return TRUE;
} }
static gboolean static gboolean
_cmd_online(gchar **args, struct cmd_help_t help) _cmd_online(gchar **args, struct cmd_help_t help)
{ {
_update_presence(PRESENCE_ONLINE, "online", args); _update_presence(RESOURCE_ONLINE, "online", args);
return TRUE; return TRUE;
} }
static gboolean static gboolean
_cmd_dnd(gchar **args, struct cmd_help_t help) _cmd_dnd(gchar **args, struct cmd_help_t help)
{ {
_update_presence(PRESENCE_DND, "dnd", args); _update_presence(RESOURCE_DND, "dnd", args);
return TRUE; return TRUE;
} }
static gboolean static gboolean
_cmd_chat(gchar **args, struct cmd_help_t help) _cmd_chat(gchar **args, struct cmd_help_t help)
{ {
_update_presence(PRESENCE_CHAT, "chat", args); _update_presence(RESOURCE_CHAT, "chat", args);
return TRUE; return TRUE;
} }
static gboolean static gboolean
_cmd_xa(gchar **args, struct cmd_help_t help) _cmd_xa(gchar **args, struct cmd_help_t help)
{ {
_update_presence(PRESENCE_XA, "xa", args); _update_presence(RESOURCE_XA, "xa", args);
return TRUE; return TRUE;
} }
// helper function for status change commands // helper function for status change commands
static void static void
_update_presence(const presence_t presence, _update_presence(const resource_presence_t resource_presence,
const char * const show, gchar **args) const char * const show, gchar **args)
{ {
char *msg = NULL; char *msg = NULL;
@@ -2362,9 +2358,12 @@ _update_presence(const presence_t presence,
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
} else { } else {
presence_update(presence, msg, 0); presence_update(resource_presence, msg, 0);
title_bar_set_status(presence);
gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), presence); contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence);
title_bar_set_status(contact_presence);
gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), resource_presence);
if (msg != NULL) { if (msg != NULL) {
cons_show("Status set to %s (priority %d), \"%s\".", show, priority, msg); cons_show("Status set to %s (priority %d), \"%s\".", show, priority, msg);
} else { } else {
@@ -2647,23 +2646,3 @@ _strtoi(char *str, int *saveptr, int min, int max)
return 0; return 0;
} }
static presence_t
_presence_type_from_string(const char * const str)
{
if (str == NULL) {
return PRESENCE_ONLINE;
} else if (!presence_valid_string(str)) {
return PRESENCE_ONLINE;
} else if (strcmp(str, "online") == 0) {
return PRESENCE_ONLINE;
} else if (strcmp(str, "chat") == 0) {
return PRESENCE_CHAT;
} else if (strcmp(str, "away") == 0) {
return PRESENCE_AWAY;
} else if (strcmp(str, "xa") == 0) {
return PRESENCE_XA;
} else {
return PRESENCE_DND;
}
}

View File

@@ -261,7 +261,7 @@ release_get_latest()
} }
gboolean gboolean
presence_valid_string(const char * const str) valid_resource_presence_string(const char * const str)
{ {
assert(str != NULL); assert(str != NULL);
if ((strcmp(str, "online") == 0) || (strcmp(str, "chat") == 0) || if ((strcmp(str, "online") == 0) || (strcmp(str, "chat") == 0) ||
@@ -274,46 +274,58 @@ presence_valid_string(const char * const str)
} }
const char * const char *
presence_display_string_from_type(presence_t presence) string_from_resource_presence(resource_presence_t presence)
{ {
switch (presence) switch(presence)
{ {
case PRESENCE_ONLINE: case RESOURCE_CHAT:
return "online";
case PRESENCE_CHAT:
return "chat"; return "chat";
case PRESENCE_AWAY: case RESOURCE_AWAY:
return "away"; return "away";
case PRESENCE_XA: case RESOURCE_XA:
return "xa"; return "xa";
case PRESENCE_DND: case RESOURCE_DND:
return "dnd"; return "dnd";
case PRESENCE_OFFLINE:
return "offline";
default: default:
return NULL; return "online";
} }
} }
const char * resource_presence_t
presence_stanza_show_from_type(presence_t presence) resource_presence_from_string(const char * const str)
{ {
assert(presence != PRESENCE_OFFLINE); if (str == NULL) {
return RESOURCE_ONLINE;
} else if (strcmp(str, "online") == 0) {
return RESOURCE_ONLINE;
} else if (strcmp(str, "chat") == 0) {
return RESOURCE_CHAT;
} else if (strcmp(str, "away") == 0) {
return RESOURCE_AWAY;
} else if (strcmp(str, "xa") == 0) {
return RESOURCE_XA;
} else if (strcmp(str, "dnd") == 0) {
return RESOURCE_DND;
} else {
return RESOURCE_ONLINE;
}
}
switch (presence) contact_presence_t
contact_presence_from_resource_presence(resource_presence_t resource_presence)
{
switch(resource_presence)
{ {
case PRESENCE_ONLINE: case RESOURCE_CHAT:
return NULL; return CONTACT_CHAT;
case PRESENCE_CHAT: case RESOURCE_AWAY:
return "chat"; return CONTACT_AWAY;
case PRESENCE_AWAY: case RESOURCE_XA:
return "away"; return CONTACT_XA;
case PRESENCE_XA: case RESOURCE_DND:
return "xa"; return CONTACT_DND;
case PRESENCE_DND:
return "dnd";
default: default:
return NULL; return CONTACT_ONLINE;
} }
} }

View File

@@ -56,13 +56,21 @@
} }
typedef enum { typedef enum {
PRESENCE_OFFLINE, CONTACT_OFFLINE,
PRESENCE_ONLINE, CONTACT_ONLINE,
PRESENCE_AWAY, CONTACT_AWAY,
PRESENCE_DND, CONTACT_DND,
PRESENCE_CHAT, CONTACT_CHAT,
PRESENCE_XA CONTACT_XA
} presence_t; } contact_presence_t;
typedef enum {
RESOURCE_ONLINE,
RESOURCE_AWAY,
RESOURCE_DND,
RESOURCE_CHAT,
RESOURCE_XA
} resource_presence_t;
gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos); gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos);
void p_slist_free_full(GSList *items, GDestroyNotify free_func); void p_slist_free_full(GSList *items, GDestroyNotify free_func);
@@ -75,10 +83,12 @@ char* encode_xml(const char * const xml);
char * prof_getline(FILE *stream); char * prof_getline(FILE *stream);
int octet_compare(unsigned char *str1, unsigned char *str2); int octet_compare(unsigned char *str1, unsigned char *str2);
char* release_get_latest(void); char* release_get_latest(void);
gboolean presence_valid_string(const char * const str);
const char * presence_display_string_from_type(presence_t presence);
const char * presence_stanza_show_from_type(presence_t presence);
gchar * xdg_get_config_home(void); gchar * xdg_get_config_home(void);
gchar * xdg_get_data_home(void); gchar * xdg_get_data_home(void);
gboolean valid_resource_presence_string(const char * const str);
const char * string_from_resource_presence(resource_presence_t presence);
resource_presence_t resource_presence_from_string(const char * const str);
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
#endif #endif

View File

@@ -189,7 +189,7 @@ accounts_get_account(const char * const name)
} }
gchar *presence = g_key_file_get_string(accounts, name, "presence.last", NULL); gchar *presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
if (presence == NULL || (!presence_valid_string(presence))) { if (presence == NULL || (!valid_resource_presence_string(presence))) {
account->last_presence = strdup("online"); account->last_presence = strdup("online");
} else { } else {
account->last_presence = strdup(presence); account->last_presence = strdup(presence);
@@ -200,7 +200,7 @@ accounts_get_account(const char * const name)
account->login_presence = strdup("online"); account->login_presence = strdup("online");
} else if (strcmp(presence, "last") == 0) { } else if (strcmp(presence, "last") == 0) {
account->login_presence = strdup("last"); account->login_presence = strdup("last");
} else if (!presence_valid_string(presence)) { } else if (!valid_resource_presence_string(presence)) {
account->login_presence = strdup("online"); account->login_presence = strdup("online");
} else { } else {
account->login_presence = strdup(presence); account->login_presence = strdup(presence);
@@ -403,29 +403,26 @@ accounts_set_priority_all(const char * const account_name, const gint value)
gint gint
accounts_get_priority_for_presence_type(const char * const account_name, accounts_get_priority_for_presence_type(const char * const account_name,
presence_t presence_type) resource_presence_t presence_type)
{ {
gint result; gint result;
switch (presence_type) switch (presence_type)
{ {
case (PRESENCE_ONLINE): case (RESOURCE_ONLINE):
result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL); result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL);
break; break;
case (PRESENCE_CHAT): case (RESOURCE_CHAT):
result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL); result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL);
break; break;
case (PRESENCE_AWAY): case (RESOURCE_AWAY):
result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL); result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL);
break; break;
case (PRESENCE_XA): case (RESOURCE_XA):
result = g_key_file_get_integer(accounts, account_name, "priority.xa", NULL); result = g_key_file_get_integer(accounts, account_name, "priority.xa", NULL);
break; break;
case (PRESENCE_DND):
result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
break;
default: default:
result = 0; result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
break; break;
} }
@@ -453,47 +450,47 @@ accounts_set_login_presence(const char * const account_name, const char * const
} }
} }
presence_t resource_presence_t
accounts_get_last_presence(const char * const account_name) accounts_get_last_presence(const char * const account_name)
{ {
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL); gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
if (setting == NULL || (strcmp(setting, "online") == 0)) { if (setting == NULL || (strcmp(setting, "online") == 0)) {
return PRESENCE_ONLINE; return RESOURCE_ONLINE;
} else if (strcmp(setting, "chat") == 0) { } else if (strcmp(setting, "chat") == 0) {
return PRESENCE_CHAT; return RESOURCE_CHAT;
} else if (strcmp(setting, "away") == 0) { } else if (strcmp(setting, "away") == 0) {
return PRESENCE_AWAY; return RESOURCE_AWAY;
} else if (strcmp(setting, "xa") == 0) { } else if (strcmp(setting, "xa") == 0) {
return PRESENCE_XA; return RESOURCE_XA;
} else if (strcmp(setting, "dnd") == 0) { } else if (strcmp(setting, "dnd") == 0) {
return PRESENCE_DND; return RESOURCE_DND;
} else { } else {
log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'", log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'",
account_name, setting); account_name, setting);
return PRESENCE_ONLINE; return RESOURCE_ONLINE;
} }
} }
presence_t resource_presence_t
accounts_get_login_presence(const char * const account_name) accounts_get_login_presence(const char * const account_name)
{ {
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
if (setting == NULL || (strcmp(setting, "online") == 0)) { if (setting == NULL || (strcmp(setting, "online") == 0)) {
return PRESENCE_ONLINE; return RESOURCE_ONLINE;
} else if (strcmp(setting, "chat") == 0) { } else if (strcmp(setting, "chat") == 0) {
return PRESENCE_CHAT; return RESOURCE_CHAT;
} else if (strcmp(setting, "away") == 0) { } else if (strcmp(setting, "away") == 0) {
return PRESENCE_AWAY; return RESOURCE_AWAY;
} else if (strcmp(setting, "xa") == 0) { } else if (strcmp(setting, "xa") == 0) {
return PRESENCE_XA; return RESOURCE_XA;
} else if (strcmp(setting, "dnd") == 0) { } else if (strcmp(setting, "dnd") == 0) {
return PRESENCE_DND; return RESOURCE_DND;
} else if (strcmp(setting, "last") == 0) { } else if (strcmp(setting, "last") == 0) {
return accounts_get_last_presence(account_name); return accounts_get_last_presence(account_name);
} else { } else {
log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'", log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'",
account_name, setting); account_name, setting);
return PRESENCE_ONLINE; return RESOURCE_ONLINE;
} }
} }

View File

@@ -61,8 +61,8 @@ void accounts_set_server(const char * const account_name, const char * const val
void accounts_set_resource(const char * const account_name, const char * const value); void accounts_set_resource(const char * const account_name, const char * const value);
void accounts_set_last_presence(const char * const account_name, const char * const value); void accounts_set_last_presence(const char * const account_name, const char * const value);
void accounts_set_login_presence(const char * const account_name, const char * const value); void accounts_set_login_presence(const char * const account_name, const char * const value);
presence_t accounts_get_login_presence(const char * const account_name); resource_presence_t accounts_get_login_presence(const char * const account_name);
presence_t accounts_get_last_presence(const char * const account_name); resource_presence_t accounts_get_last_presence(const char * const account_name);
void accounts_set_priority_online(const char * const account_name, const gint value); void accounts_set_priority_online(const char * const account_name, const gint value);
void accounts_set_priority_chat(const char * const account_name, const gint value); void accounts_set_priority_chat(const char * const account_name, const gint value);
void accounts_set_priority_away(const char * const account_name, const gint value); void accounts_set_priority_away(const char * const account_name, const gint value);
@@ -70,6 +70,6 @@ void accounts_set_priority_xa(const char * const account_name, const gint value)
void accounts_set_priority_dnd(const char * const account_name, const gint value); void accounts_set_priority_dnd(const char * const account_name, const gint value);
void accounts_set_priority_all(const char * const account_name, const gint value); void accounts_set_priority_all(const char * const account_name, const gint value);
gint accounts_get_priority_for_presence_type(const char * const account_name, gint accounts_get_priority_for_presence_type(const char * const account_name,
presence_t presence_type); resource_presence_t presence_type);
#endif #endif

View File

@@ -189,9 +189,10 @@ void
prof_handle_login_account_success(char *account_name) prof_handle_login_account_success(char *account_name)
{ {
ProfAccount *account = accounts_get_account(account_name); ProfAccount *account = accounts_get_account(account_name);
presence_t presence = accounts_get_login_presence(account->name); resource_presence_t resource_presence = accounts_get_login_presence(account->name);
contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence);
cons_show_login_success(account); cons_show_login_success(account);
title_bar_set_status(presence); title_bar_set_status(contact_presence);
log_info("%s logged in successfully", account->jid); log_info("%s logged in successfully", account->jid);
win_current_page_off(); win_current_page_off();
status_bar_print_message(account->jid); status_bar_print_message(account->jid);
@@ -439,28 +440,28 @@ _handle_idle_time()
// handle away mode // handle away mode
if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) { if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) {
presence_update(PRESENCE_AWAY, prefs_get_string(PREF_AUTOAWAY_MESSAGE), 0); presence_update(CONTACT_AWAY, prefs_get_string(PREF_AUTOAWAY_MESSAGE), 0);
if (prefs_get_string(PREF_AUTOAWAY_MESSAGE) != NULL) { if (prefs_get_string(PREF_AUTOAWAY_MESSAGE) != NULL) {
int pri = int pri =
accounts_get_priority_for_presence_type(jabber_get_account_name(), accounts_get_priority_for_presence_type(jabber_get_account_name(),
PRESENCE_AWAY); CONTACT_AWAY);
cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".", cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".",
prefs_get_autoaway_time(), pri, prefs_get_string(PREF_AUTOAWAY_MESSAGE)); prefs_get_autoaway_time(), pri, prefs_get_string(PREF_AUTOAWAY_MESSAGE));
title_bar_set_status(PRESENCE_AWAY); title_bar_set_status(RESOURCE_AWAY);
win_current_page_off(); win_current_page_off();
} else { } else {
int pri = int pri =
accounts_get_priority_for_presence_type(jabber_get_account_name(), accounts_get_priority_for_presence_type(jabber_get_account_name(),
PRESENCE_AWAY); CONTACT_AWAY);
cons_show("Idle for %d minutes, status set to away (priority %d).", cons_show("Idle for %d minutes, status set to away (priority %d).",
prefs_get_autoaway_time(), pri); prefs_get_autoaway_time(), pri);
title_bar_set_status(PRESENCE_AWAY); title_bar_set_status(RESOURCE_AWAY);
win_current_page_off(); win_current_page_off();
} }
// handle idle mode // handle idle mode
} else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) { } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) {
presence_update(PRESENCE_ONLINE, presence_update(CONTACT_ONLINE,
prefs_get_string(PREF_AUTOAWAY_MESSAGE), idle_ms / 1000); prefs_get_string(PREF_AUTOAWAY_MESSAGE), idle_ms / 1000);
} }
} }
@@ -472,16 +473,16 @@ _handle_idle_time()
// handle check // handle check
if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) {
if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) { if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) {
presence_update(PRESENCE_ONLINE, NULL, 0); presence_update(CONTACT_ONLINE, NULL, 0);
int pri = int pri =
accounts_get_priority_for_presence_type(jabber_get_account_name(), accounts_get_priority_for_presence_type(jabber_get_account_name(),
PRESENCE_ONLINE); CONTACT_ONLINE);
cons_show("No longer idle, status set to online (priority %d).", pri); cons_show("No longer idle, status set to online (priority %d).", pri);
title_bar_set_status(PRESENCE_ONLINE); title_bar_set_status(RESOURCE_ONLINE);
win_current_page_off(); win_current_page_off();
} else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) { } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) {
presence_update(PRESENCE_ONLINE, NULL, 0); presence_update(CONTACT_ONLINE, NULL, 0);
title_bar_set_status(PRESENCE_ONLINE); title_bar_set_status(RESOURCE_ONLINE);
} }
} }
} }

View File

@@ -23,14 +23,6 @@
#ifndef RESOURCE_H #ifndef RESOURCE_H
#define RESOURCE_H #define RESOURCE_H
typedef enum {
RESOURCE_ONLINE,
RESOURCE_CHAT,
RESOURCE_AWAY,
RESOURCE_XA,
RESOURCE_DND
} resource_presence_t;
typedef struct resource_t { typedef struct resource_t {
char *name; char *name;
char *show; char *show;

View File

@@ -32,7 +32,7 @@ static char *current_title = NULL;
static char *recipient = NULL; static char *recipient = NULL;
static GTimer *typing_elapsed; static GTimer *typing_elapsed;
static int dirty; static int dirty;
static presence_t current_status; static contact_presence_t current_status;
static void _title_bar_draw_title(void); static void _title_bar_draw_title(void);
static void _title_bar_draw_status(void); static void _title_bar_draw_status(void);
@@ -45,7 +45,7 @@ create_title_bar(void)
title_bar = newwin(1, cols, 0, 0); title_bar = newwin(1, cols, 0, 0);
wbkgd(title_bar, COLOUR_TITLE_TEXT); wbkgd(title_bar, COLOUR_TITLE_TEXT);
title_bar_title(); title_bar_title();
title_bar_set_status(PRESENCE_OFFLINE); title_bar_set_status(CONTACT_OFFLINE);
dirty = TRUE; dirty = TRUE;
} }
@@ -119,7 +119,7 @@ title_bar_show(const char * const title)
} }
void void
title_bar_set_status(presence_t status) title_bar_set_status(contact_presence_t status)
{ {
current_status = status; current_status = status;
_title_bar_draw_status(); _title_bar_draw_status();
@@ -187,18 +187,26 @@ _title_bar_draw_status(void)
mvwaddch(title_bar, 0, cols - 14, '['); mvwaddch(title_bar, 0, cols - 14, '[');
wattroff(title_bar, COLOUR_TITLE_BRACKET); wattroff(title_bar, COLOUR_TITLE_BRACKET);
if (current_status == PRESENCE_ONLINE) { switch (current_status)
mvwprintw(title_bar, 0, cols - 13, " ...online "); {
} else if (current_status == PRESENCE_AWAY) { case CONTACT_ONLINE:
mvwprintw(title_bar, 0, cols - 13, " .....away "); mvwprintw(title_bar, 0, cols - 13, " ...online ");
} else if (current_status == PRESENCE_DND) { break;
mvwprintw(title_bar, 0, cols - 13, " ......dnd "); case CONTACT_AWAY:
} else if (current_status == PRESENCE_CHAT) { mvwprintw(title_bar, 0, cols - 13, " .....away ");
mvwprintw(title_bar, 0, cols - 13, " .....chat "); break;
} else if (current_status == PRESENCE_XA) { case CONTACT_DND:
mvwprintw(title_bar, 0, cols - 13, " .......xa "); mvwprintw(title_bar, 0, cols - 13, " ......dnd ");
} else { break;
mvwprintw(title_bar, 0, cols - 13, " ..offline "); case CONTACT_CHAT:
mvwprintw(title_bar, 0, cols - 13, " .....chat ");
break;
case CONTACT_XA:
mvwprintw(title_bar, 0, cols - 13, " .......xa ");
break;
case CONTACT_OFFLINE:
mvwprintw(title_bar, 0, cols - 13, " ..offline ");
break;
} }
wattron(title_bar, COLOUR_TITLE_BRACKET); wattron(title_bar, COLOUR_TITLE_BRACKET);

View File

@@ -92,7 +92,7 @@ void title_bar_refresh(void);
void title_bar_resize(void); void title_bar_resize(void);
void title_bar_show(const char * const title); void title_bar_show(const char * const title);
void title_bar_title(void); void title_bar_title(void);
void title_bar_set_status(presence_t status); void title_bar_set_status(contact_presence_t status);
void title_bar_set_recipient(char *from); void title_bar_set_recipient(char *from);
void title_bar_set_typing(gboolean is_typing); void title_bar_set_typing(gboolean is_typing);
void title_bar_draw(void); void title_bar_draw(void);

View File

@@ -506,7 +506,7 @@ ui_disconnected(void)
} }
} }
title_bar_set_status(PRESENCE_OFFLINE); title_bar_set_status(CONTACT_OFFLINE);
status_bar_clear_message(); status_bar_clear_message();
status_bar_refresh(); status_bar_refresh();
} }
@@ -1094,26 +1094,8 @@ cons_show_login_success(ProfAccount *account)
_win_show_time(console->win, '-'); _win_show_time(console->win, '-');
wprintw(console->win, "%s logged in successfully, ", account->jid); wprintw(console->win, "%s logged in successfully, ", account->jid);
presence_t presence = accounts_get_login_presence(account->name); resource_presence_t presence = accounts_get_login_presence(account->name);
char *presence_str; const char *presence_str = string_from_resource_presence(presence);
switch(presence)
{
case PRESENCE_CHAT:
presence_str = "chat";
break;
case PRESENCE_AWAY:
presence_str = "away";
break;
case PRESENCE_XA:
presence_str = "xa";
break;
case PRESENCE_DND:
presence_str = "dnd";
break;
default:
presence_str = "online";
break;
}
_presence_colour_on(console->win, presence_str); _presence_colour_on(console->win, presence_str);
wprintw(console->win, "%s", presence_str); wprintw(console->win, "%s", presence_str);

View File

@@ -29,7 +29,6 @@ void connection_free_resources(void);
xmpp_conn_t *connection_get_conn(void); xmpp_conn_t *connection_get_conn(void);
xmpp_ctx_t *connection_get_ctx(void); xmpp_ctx_t *connection_get_ctx(void);
int connection_error_handler(xmpp_stanza_t * const stanza); int connection_error_handler(xmpp_stanza_t * const stanza);
void connection_set_presence_type(presence_t presence_type);
void connection_set_priority(int priority); void connection_set_priority(int priority);
void connection_set_presence_message(const char * const message); void connection_set_presence_message(const char * const message);

View File

@@ -153,8 +153,8 @@ _iq_handle_roster_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
item = xmpp_stanza_get_next(item); item = xmpp_stanza_get_next(item);
} }
presence_t connect_presence = accounts_get_login_presence(jabber_get_account_name()); contact_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name());
presence_update(connect_presence, NULL, 0); presence_update(conn_presence, NULL, 0);
} }
return 1; return 1;

View File

@@ -106,7 +106,7 @@ presence_free_sub_requests(void)
} }
void void
presence_update(presence_t presence_type, const char * const msg, presence_update(resource_presence_t presence_type, const char * const msg,
int idle) int idle)
{ {
xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_ctx_t *ctx = connection_get_ctx();
@@ -160,7 +160,7 @@ presence_join_room(Jid *jid)
{ {
xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn(); xmpp_conn_t *conn = connection_get_conn();
presence_t presence_type = accounts_get_last_presence(jabber_get_account_name()); contact_presence_t presence_type = accounts_get_last_presence(jabber_get_account_name());
const char *show = stanza_get_presence_string_from_type(presence_type); const char *show = stanza_get_presence_string_from_type(presence_type);
char *status = jabber_get_presence_message(); char *status = jabber_get_presence_message();
int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(),
@@ -183,7 +183,7 @@ presence_change_room_nick(const char * const room, const char * const nick)
{ {
xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_conn_t *conn = connection_get_conn(); xmpp_conn_t *conn = connection_get_conn();
presence_t presence_type = accounts_get_last_presence(jabber_get_account_name()); contact_presence_t presence_type = accounts_get_last_presence(jabber_get_account_name());
const char *show = stanza_get_presence_string_from_type(presence_type); const char *show = stanza_get_presence_string_from_type(presence_type);
char *status = jabber_get_presence_message(); char *status = jabber_get_presence_message();
int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(),

View File

@@ -664,19 +664,19 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence)
} }
const char * const char *
stanza_get_presence_string_from_type(presence_t presence_type) stanza_get_presence_string_from_type(resource_presence_t presence_type)
{ {
switch(presence_type) switch(presence_type)
{ {
case PRESENCE_AWAY: case RESOURCE_AWAY:
return STANZA_TEXT_AWAY; return STANZA_TEXT_AWAY;
case PRESENCE_DND: case RESOURCE_DND:
return STANZA_TEXT_DND; return STANZA_TEXT_DND;
case PRESENCE_CHAT: case RESOURCE_CHAT:
return STANZA_TEXT_CHAT; return STANZA_TEXT_CHAT;
case PRESENCE_XA: case RESOURCE_XA:
return STANZA_TEXT_XA; return STANZA_TEXT_XA;
default: // PRESENCE_ONLINE default:
return NULL; return NULL;
} }
} }

View File

@@ -160,6 +160,6 @@ void stanza_attach_show(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence,
void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence,
const char * const status); const char * const status);
const char * stanza_get_presence_string_from_type(presence_t presence_type); const char * stanza_get_presence_string_from_type(resource_presence_t presence_type);
#endif #endif

View File

@@ -84,7 +84,7 @@ GList* presence_get_subscription_requests(void);
void presence_join_room(Jid *jid); void presence_join_room(Jid *jid);
void presence_change_room_nick(const char * const room, const char * const nick); void presence_change_room_nick(const char * const room, const char * const nick);
void presence_leave_chat_room(const char * const room_jid); void presence_leave_chat_room(const char * const room_jid);
void presence_update(presence_t status, const char * const msg, void presence_update(resource_presence_t status, const char * const msg,
int idle); int idle);
// caps functions // caps functions