mirror of
https://github.com/profanity-im/profanity.git
synced 2024-09-15 19:38:07 -04:00
Added resource_presence_t and contact_presence_t
This commit is contained in:
parent
59e9b10d19
commit
e922568770
@ -87,7 +87,7 @@ if test "x$enable_notifications" != xno; then
|
||||
fi
|
||||
|
||||
# Default parameters
|
||||
AM_CFLAGS="-Wall"
|
||||
AM_CFLAGS="-Wall -Werror"
|
||||
LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS"
|
||||
|
||||
AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS"
|
||||
|
@ -68,7 +68,7 @@ struct cmd_t {
|
||||
};
|
||||
|
||||
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);
|
||||
static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
|
||||
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);
|
||||
|
||||
static int _strtoi(char *str, int *saveptr, int min, int max);
|
||||
static presence_t _presence_type_from_string(const char * const str);
|
||||
|
||||
// command prototypes
|
||||
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("");
|
||||
} 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);
|
||||
} else {
|
||||
accounts_set_login_presence(account_name, value);
|
||||
cons_show("Updated login status for account %s: %s", account_name, value);
|
||||
}
|
||||
cons_show("");
|
||||
} else if (presence_valid_string(property)) {
|
||||
} else if (valid_resource_presence_string(property)) {
|
||||
int intval;
|
||||
|
||||
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)
|
||||
{
|
||||
case (PRESENCE_ONLINE):
|
||||
case (RESOURCE_ONLINE):
|
||||
accounts_set_priority_online(account_name, intval);
|
||||
break;
|
||||
case (PRESENCE_CHAT):
|
||||
case (RESOURCE_CHAT):
|
||||
accounts_set_priority_chat(account_name, intval);
|
||||
break;
|
||||
case (PRESENCE_AWAY):
|
||||
case (RESOURCE_AWAY):
|
||||
accounts_set_priority_away(account_name, intval);
|
||||
break;
|
||||
case (PRESENCE_XA):
|
||||
case (RESOURCE_XA):
|
||||
accounts_set_priority_xa(account_name, intval);
|
||||
break;
|
||||
case (PRESENCE_DND):
|
||||
case (RESOURCE_DND):
|
||||
accounts_set_priority_dnd(account_name, intval);
|
||||
break;
|
||||
default:
|
||||
accounts_set_priority_online(account_name, intval);
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
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);
|
||||
cons_show("Priority set to %d.", intval);
|
||||
}
|
||||
@ -2313,42 +2309,42 @@ _cmd_set_history(gchar **args, struct cmd_help_t help)
|
||||
static gboolean
|
||||
_cmd_away(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
_update_presence(PRESENCE_AWAY, "away", args);
|
||||
_update_presence(RESOURCE_AWAY, "away", args);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmd_online(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
_update_presence(PRESENCE_ONLINE, "online", args);
|
||||
_update_presence(RESOURCE_ONLINE, "online", args);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmd_dnd(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
_update_presence(PRESENCE_DND, "dnd", args);
|
||||
_update_presence(RESOURCE_DND, "dnd", args);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmd_chat(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
_update_presence(PRESENCE_CHAT, "chat", args);
|
||||
_update_presence(RESOURCE_CHAT, "chat", args);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmd_xa(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
_update_presence(PRESENCE_XA, "xa", args);
|
||||
_update_presence(RESOURCE_XA, "xa", args);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// helper function for status change commands
|
||||
|
||||
static void
|
||||
_update_presence(const presence_t presence,
|
||||
_update_presence(const resource_presence_t resource_presence,
|
||||
const char * const show, gchar **args)
|
||||
{
|
||||
char *msg = NULL;
|
||||
@ -2362,9 +2358,12 @@ _update_presence(const presence_t presence,
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
} else {
|
||||
presence_update(presence, msg, 0);
|
||||
title_bar_set_status(presence);
|
||||
gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), presence);
|
||||
presence_update(resource_presence, msg, 0);
|
||||
|
||||
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) {
|
||||
cons_show("Status set to %s (priority %d), \"%s\".", show, priority, msg);
|
||||
} else {
|
||||
@ -2647,23 +2646,3 @@ _strtoi(char *str, int *saveptr, int min, int max)
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
66
src/common.c
66
src/common.c
@ -261,7 +261,7 @@ release_get_latest()
|
||||
}
|
||||
|
||||
gboolean
|
||||
presence_valid_string(const char * const str)
|
||||
valid_resource_presence_string(const char * const str)
|
||||
{
|
||||
assert(str != NULL);
|
||||
if ((strcmp(str, "online") == 0) || (strcmp(str, "chat") == 0) ||
|
||||
@ -274,46 +274,58 @@ presence_valid_string(const char * const str)
|
||||
}
|
||||
|
||||
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:
|
||||
return "online";
|
||||
case PRESENCE_CHAT:
|
||||
case RESOURCE_CHAT:
|
||||
return "chat";
|
||||
case PRESENCE_AWAY:
|
||||
case RESOURCE_AWAY:
|
||||
return "away";
|
||||
case PRESENCE_XA:
|
||||
case RESOURCE_XA:
|
||||
return "xa";
|
||||
case PRESENCE_DND:
|
||||
case RESOURCE_DND:
|
||||
return "dnd";
|
||||
case PRESENCE_OFFLINE:
|
||||
return "offline";
|
||||
default:
|
||||
return NULL;
|
||||
return "online";
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
presence_stanza_show_from_type(presence_t presence)
|
||||
resource_presence_t
|
||||
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:
|
||||
return NULL;
|
||||
case PRESENCE_CHAT:
|
||||
return "chat";
|
||||
case PRESENCE_AWAY:
|
||||
return "away";
|
||||
case PRESENCE_XA:
|
||||
return "xa";
|
||||
case PRESENCE_DND:
|
||||
return "dnd";
|
||||
case RESOURCE_CHAT:
|
||||
return CONTACT_CHAT;
|
||||
case RESOURCE_AWAY:
|
||||
return CONTACT_AWAY;
|
||||
case RESOURCE_XA:
|
||||
return CONTACT_XA;
|
||||
case RESOURCE_DND:
|
||||
return CONTACT_DND;
|
||||
default:
|
||||
return NULL;
|
||||
return CONTACT_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
|
30
src/common.h
30
src/common.h
@ -56,13 +56,21 @@
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
PRESENCE_OFFLINE,
|
||||
PRESENCE_ONLINE,
|
||||
PRESENCE_AWAY,
|
||||
PRESENCE_DND,
|
||||
PRESENCE_CHAT,
|
||||
PRESENCE_XA
|
||||
} presence_t;
|
||||
CONTACT_OFFLINE,
|
||||
CONTACT_ONLINE,
|
||||
CONTACT_AWAY,
|
||||
CONTACT_DND,
|
||||
CONTACT_CHAT,
|
||||
CONTACT_XA
|
||||
} 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);
|
||||
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);
|
||||
int octet_compare(unsigned char *str1, unsigned char *str2);
|
||||
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_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
|
||||
|
@ -189,7 +189,7 @@ accounts_get_account(const char * const name)
|
||||
}
|
||||
|
||||
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");
|
||||
} else {
|
||||
account->last_presence = strdup(presence);
|
||||
@ -200,7 +200,7 @@ accounts_get_account(const char * const name)
|
||||
account->login_presence = strdup("online");
|
||||
} else if (strcmp(presence, "last") == 0) {
|
||||
account->login_presence = strdup("last");
|
||||
} else if (!presence_valid_string(presence)) {
|
||||
} else if (!valid_resource_presence_string(presence)) {
|
||||
account->login_presence = strdup("online");
|
||||
} else {
|
||||
account->login_presence = strdup(presence);
|
||||
@ -403,29 +403,26 @@ accounts_set_priority_all(const char * const account_name, const gint value)
|
||||
|
||||
gint
|
||||
accounts_get_priority_for_presence_type(const char * const account_name,
|
||||
presence_t presence_type)
|
||||
resource_presence_t presence_type)
|
||||
{
|
||||
gint result;
|
||||
|
||||
switch (presence_type)
|
||||
{
|
||||
case (PRESENCE_ONLINE):
|
||||
case (RESOURCE_ONLINE):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL);
|
||||
break;
|
||||
case (PRESENCE_CHAT):
|
||||
case (RESOURCE_CHAT):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL);
|
||||
break;
|
||||
case (PRESENCE_AWAY):
|
||||
case (RESOURCE_AWAY):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL);
|
||||
break;
|
||||
case (PRESENCE_XA):
|
||||
case (RESOURCE_XA):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.xa", NULL);
|
||||
break;
|
||||
case (PRESENCE_DND):
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
|
||||
break;
|
||||
default:
|
||||
result = 0;
|
||||
result = g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
|
||||
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)
|
||||
{
|
||||
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
|
||||
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
||||
return PRESENCE_ONLINE;
|
||||
return RESOURCE_ONLINE;
|
||||
} else if (strcmp(setting, "chat") == 0) {
|
||||
return PRESENCE_CHAT;
|
||||
return RESOURCE_CHAT;
|
||||
} else if (strcmp(setting, "away") == 0) {
|
||||
return PRESENCE_AWAY;
|
||||
return RESOURCE_AWAY;
|
||||
} else if (strcmp(setting, "xa") == 0) {
|
||||
return PRESENCE_XA;
|
||||
return RESOURCE_XA;
|
||||
} else if (strcmp(setting, "dnd") == 0) {
|
||||
return PRESENCE_DND;
|
||||
return RESOURCE_DND;
|
||||
} else {
|
||||
log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'",
|
||||
account_name, setting);
|
||||
return PRESENCE_ONLINE;
|
||||
return RESOURCE_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
presence_t
|
||||
resource_presence_t
|
||||
accounts_get_login_presence(const char * const account_name)
|
||||
{
|
||||
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
|
||||
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
||||
return PRESENCE_ONLINE;
|
||||
return RESOURCE_ONLINE;
|
||||
} else if (strcmp(setting, "chat") == 0) {
|
||||
return PRESENCE_CHAT;
|
||||
return RESOURCE_CHAT;
|
||||
} else if (strcmp(setting, "away") == 0) {
|
||||
return PRESENCE_AWAY;
|
||||
return RESOURCE_AWAY;
|
||||
} else if (strcmp(setting, "xa") == 0) {
|
||||
return PRESENCE_XA;
|
||||
return RESOURCE_XA;
|
||||
} else if (strcmp(setting, "dnd") == 0) {
|
||||
return PRESENCE_DND;
|
||||
return RESOURCE_DND;
|
||||
} else if (strcmp(setting, "last") == 0) {
|
||||
return accounts_get_last_presence(account_name);
|
||||
} else {
|
||||
log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'",
|
||||
account_name, setting);
|
||||
return PRESENCE_ONLINE;
|
||||
return RESOURCE_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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_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);
|
||||
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_login_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_chat(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_all(const char * const account_name, const gint value);
|
||||
gint accounts_get_priority_for_presence_type(const char * const account_name,
|
||||
presence_t presence_type);
|
||||
resource_presence_t presence_type);
|
||||
|
||||
#endif
|
||||
|
@ -189,9 +189,10 @@ void
|
||||
prof_handle_login_account_success(char *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);
|
||||
title_bar_set_status(presence);
|
||||
title_bar_set_status(contact_presence);
|
||||
log_info("%s logged in successfully", account->jid);
|
||||
win_current_page_off();
|
||||
status_bar_print_message(account->jid);
|
||||
@ -439,28 +440,28 @@ _handle_idle_time()
|
||||
|
||||
// handle away mode
|
||||
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) {
|
||||
int pri =
|
||||
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\".",
|
||||
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();
|
||||
} else {
|
||||
int pri =
|
||||
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).",
|
||||
prefs_get_autoaway_time(), pri);
|
||||
title_bar_set_status(PRESENCE_AWAY);
|
||||
title_bar_set_status(RESOURCE_AWAY);
|
||||
win_current_page_off();
|
||||
}
|
||||
|
||||
// handle idle mode
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@ -472,16 +473,16 @@ _handle_idle_time()
|
||||
// handle check
|
||||
if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) {
|
||||
if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) {
|
||||
presence_update(PRESENCE_ONLINE, NULL, 0);
|
||||
presence_update(CONTACT_ONLINE, NULL, 0);
|
||||
int pri =
|
||||
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);
|
||||
title_bar_set_status(PRESENCE_ONLINE);
|
||||
title_bar_set_status(RESOURCE_ONLINE);
|
||||
win_current_page_off();
|
||||
} else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) {
|
||||
presence_update(PRESENCE_ONLINE, NULL, 0);
|
||||
title_bar_set_status(PRESENCE_ONLINE);
|
||||
presence_update(CONTACT_ONLINE, NULL, 0);
|
||||
title_bar_set_status(RESOURCE_ONLINE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,14 +23,6 @@
|
||||
#ifndef RESOURCE_H
|
||||
#define RESOURCE_H
|
||||
|
||||
typedef enum {
|
||||
RESOURCE_ONLINE,
|
||||
RESOURCE_CHAT,
|
||||
RESOURCE_AWAY,
|
||||
RESOURCE_XA,
|
||||
RESOURCE_DND
|
||||
} resource_presence_t;
|
||||
|
||||
typedef struct resource_t {
|
||||
char *name;
|
||||
char *show;
|
||||
|
@ -32,7 +32,7 @@ static char *current_title = NULL;
|
||||
static char *recipient = NULL;
|
||||
static GTimer *typing_elapsed;
|
||||
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_status(void);
|
||||
@ -45,7 +45,7 @@ create_title_bar(void)
|
||||
title_bar = newwin(1, cols, 0, 0);
|
||||
wbkgd(title_bar, COLOUR_TITLE_TEXT);
|
||||
title_bar_title();
|
||||
title_bar_set_status(PRESENCE_OFFLINE);
|
||||
title_bar_set_status(CONTACT_OFFLINE);
|
||||
dirty = TRUE;
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ title_bar_show(const char * const title)
|
||||
}
|
||||
|
||||
void
|
||||
title_bar_set_status(presence_t status)
|
||||
title_bar_set_status(contact_presence_t status)
|
||||
{
|
||||
current_status = status;
|
||||
_title_bar_draw_status();
|
||||
@ -187,18 +187,26 @@ _title_bar_draw_status(void)
|
||||
mvwaddch(title_bar, 0, cols - 14, '[');
|
||||
wattroff(title_bar, COLOUR_TITLE_BRACKET);
|
||||
|
||||
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 if (current_status == PRESENCE_DND) {
|
||||
mvwprintw(title_bar, 0, cols - 13, " ......dnd ");
|
||||
} else if (current_status == PRESENCE_CHAT) {
|
||||
mvwprintw(title_bar, 0, cols - 13, " .....chat ");
|
||||
} else if (current_status == PRESENCE_XA) {
|
||||
mvwprintw(title_bar, 0, cols - 13, " .......xa ");
|
||||
} else {
|
||||
mvwprintw(title_bar, 0, cols - 13, " ..offline ");
|
||||
switch (current_status)
|
||||
{
|
||||
case CONTACT_ONLINE:
|
||||
mvwprintw(title_bar, 0, cols - 13, " ...online ");
|
||||
break;
|
||||
case CONTACT_AWAY:
|
||||
mvwprintw(title_bar, 0, cols - 13, " .....away ");
|
||||
break;
|
||||
case CONTACT_DND:
|
||||
mvwprintw(title_bar, 0, cols - 13, " ......dnd ");
|
||||
break;
|
||||
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);
|
||||
|
@ -92,7 +92,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_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_typing(gboolean is_typing);
|
||||
void title_bar_draw(void);
|
||||
|
@ -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_refresh();
|
||||
}
|
||||
@ -1094,26 +1094,8 @@ cons_show_login_success(ProfAccount *account)
|
||||
_win_show_time(console->win, '-');
|
||||
wprintw(console->win, "%s logged in successfully, ", account->jid);
|
||||
|
||||
presence_t presence = accounts_get_login_presence(account->name);
|
||||
char *presence_str;
|
||||
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;
|
||||
}
|
||||
resource_presence_t presence = accounts_get_login_presence(account->name);
|
||||
const char *presence_str = string_from_resource_presence(presence);
|
||||
|
||||
_presence_colour_on(console->win, presence_str);
|
||||
wprintw(console->win, "%s", presence_str);
|
||||
|
@ -29,7 +29,6 @@ void connection_free_resources(void);
|
||||
xmpp_conn_t *connection_get_conn(void);
|
||||
xmpp_ctx_t *connection_get_ctx(void);
|
||||
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_presence_message(const char * const message);
|
||||
|
||||
|
@ -153,8 +153,8 @@ _iq_handle_roster_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
item = xmpp_stanza_get_next(item);
|
||||
}
|
||||
|
||||
presence_t connect_presence = accounts_get_login_presence(jabber_get_account_name());
|
||||
presence_update(connect_presence, NULL, 0);
|
||||
contact_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name());
|
||||
presence_update(conn_presence, NULL, 0);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -106,7 +106,7 @@ presence_free_sub_requests(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)
|
||||
{
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
@ -160,7 +160,7 @@ presence_join_room(Jid *jid)
|
||||
{
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
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);
|
||||
char *status = jabber_get_presence_message();
|
||||
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_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);
|
||||
char *status = jabber_get_presence_message();
|
||||
int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(),
|
||||
|
@ -664,19 +664,19 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence)
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
case PRESENCE_AWAY:
|
||||
case RESOURCE_AWAY:
|
||||
return STANZA_TEXT_AWAY;
|
||||
case PRESENCE_DND:
|
||||
case RESOURCE_DND:
|
||||
return STANZA_TEXT_DND;
|
||||
case PRESENCE_CHAT:
|
||||
case RESOURCE_CHAT:
|
||||
return STANZA_TEXT_CHAT;
|
||||
case PRESENCE_XA:
|
||||
case RESOURCE_XA:
|
||||
return STANZA_TEXT_XA;
|
||||
default: // PRESENCE_ONLINE
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
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
|
||||
|
@ -84,7 +84,7 @@ GList* presence_get_subscription_requests(void);
|
||||
void presence_join_room(Jid *jid);
|
||||
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_update(presence_t status, const char * const msg,
|
||||
void presence_update(resource_presence_t status, const char * const msg,
|
||||
int idle);
|
||||
|
||||
// caps functions
|
||||
|
Loading…
Reference in New Issue
Block a user