mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Option to use last presence at login, or use a specific presence
This commit is contained in:
parent
9aa6a39cd6
commit
e6749d669d
@ -152,6 +152,7 @@ accounts_get_account(const char * const name)
|
||||
} else {
|
||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||
account->name = strdup(name);
|
||||
|
||||
gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);
|
||||
if (jid != NULL) {
|
||||
account->jid = strdup(jid);
|
||||
@ -160,13 +161,16 @@ accounts_get_account(const char * const name)
|
||||
g_key_file_set_string(accounts, name, "jid", name);
|
||||
_save_accounts();
|
||||
}
|
||||
|
||||
account->enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
|
||||
|
||||
gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
|
||||
if (server != NULL) {
|
||||
account->server = strdup(server);
|
||||
} else {
|
||||
account->server = NULL;
|
||||
}
|
||||
|
||||
gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
|
||||
if (resource != NULL) {
|
||||
account->resource = strdup(resource);
|
||||
@ -174,6 +178,24 @@ accounts_get_account(const char * const name)
|
||||
account->resource = NULL;
|
||||
}
|
||||
|
||||
gchar *presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
|
||||
if (presence == NULL || (!presence_valid_string(presence))) {
|
||||
account->last_presence = strdup("online");
|
||||
} else {
|
||||
account->last_presence = strdup(presence);
|
||||
}
|
||||
|
||||
presence = g_key_file_get_string(accounts, name, "presence.login", NULL);
|
||||
if (presence == NULL) {
|
||||
account->login_presence = strdup("online");
|
||||
} else if (strcmp(presence, "last") == 0) {
|
||||
account->login_presence = strdup("last");
|
||||
} else if (!presence_valid_string(presence)) {
|
||||
account->login_presence = strdup("online");
|
||||
} else {
|
||||
account->login_presence = strdup(presence);
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
}
|
||||
@ -186,6 +208,8 @@ accounts_free_account(ProfAccount *account)
|
||||
FREE_SET_NULL(account->jid);
|
||||
FREE_SET_NULL(account->resource);
|
||||
FREE_SET_NULL(account->server);
|
||||
FREE_SET_NULL(account->last_presence);
|
||||
FREE_SET_NULL(account->login_presence);
|
||||
FREE_SET_NULL(account);
|
||||
}
|
||||
}
|
||||
@ -319,19 +343,47 @@ accounts_set_login_presence(const char * const account_name, const char * const
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
account_get_login_presence(const char * const account_name, char *str)
|
||||
jabber_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;
|
||||
} else if (strcmp(setting, "chat") == 0) {
|
||||
return PRESENCE_CHAT;
|
||||
} else if (strcmp(setting, "away") == 0) {
|
||||
return PRESENCE_AWAY;
|
||||
} else if (strcmp(setting, "xa") == 0) {
|
||||
return PRESENCE_XA;
|
||||
} else if (strcmp(setting, "dnd") == 0) {
|
||||
return PRESENCE_DND;
|
||||
} else {
|
||||
log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'",
|
||||
account_name, setting);
|
||||
return PRESENCE_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
jabber_presence_t
|
||||
account_get_login_presence(const char * const account_name)
|
||||
{
|
||||
static char *online = "online";
|
||||
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
|
||||
if (setting == NULL) {
|
||||
str = online;
|
||||
} else if (!presence_valid_string(setting)) {
|
||||
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
||||
return PRESENCE_ONLINE;
|
||||
} else if (strcmp(setting, "chat") == 0) {
|
||||
return PRESENCE_CHAT;
|
||||
} else if (strcmp(setting, "away") == 0) {
|
||||
return PRESENCE_AWAY;
|
||||
} else if (strcmp(setting, "xa") == 0) {
|
||||
return PRESENCE_XA;
|
||||
} else if (strcmp(setting, "dnd") == 0) {
|
||||
return PRESENCE_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);
|
||||
str = online;
|
||||
} else {
|
||||
str = setting;
|
||||
return PRESENCE_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,15 @@
|
||||
#ifndef ACCOUNTS_H
|
||||
#define ACCOUNTS_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef struct prof_account_t {
|
||||
gchar *name;
|
||||
gchar *jid;
|
||||
gchar *resource;
|
||||
gchar *server;
|
||||
gchar *last_presence;
|
||||
gchar *login_presence;
|
||||
gboolean enabled;
|
||||
} ProfAccount;
|
||||
|
||||
@ -52,6 +56,7 @@ 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);
|
||||
void account_get_login_presence(const char * const account_name, char *str);
|
||||
jabber_presence_t account_get_login_presence(const char * const account_name);
|
||||
jabber_presence_t accounts_get_last_presence(const char * const account_name);
|
||||
|
||||
#endif
|
||||
|
16
src/common.c
16
src/common.c
@ -246,6 +246,22 @@ release_get_latest()
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
presence_valid_string(const char * const str)
|
||||
{
|
||||
if (str == NULL) {
|
||||
return FALSE;
|
||||
} else if ((strcmp(str, "online") == 0) ||
|
||||
(strcmp(str, "chat") == 0) ||
|
||||
(strcmp(str, "away") == 0) ||
|
||||
(strcmp(str, "xa") == 0) ||
|
||||
(strcmp(str, "dnd") == 0)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
{
|
||||
|
10
src/common.h
10
src/common.h
@ -54,6 +54,15 @@
|
||||
resource = NULL; \
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
PRESENCE_OFFLINE,
|
||||
PRESENCE_ONLINE,
|
||||
PRESENCE_AWAY,
|
||||
PRESENCE_DND,
|
||||
PRESENCE_CHAT,
|
||||
PRESENCE_XA
|
||||
} jabber_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);
|
||||
void create_dir(char *name);
|
||||
@ -64,5 +73,6 @@ 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);
|
||||
|
||||
#endif
|
||||
|
@ -1225,16 +1225,22 @@ cons_show_account(ProfAccount *account)
|
||||
{
|
||||
cons_show("%s account details:", account->name);
|
||||
if (account->enabled) {
|
||||
cons_show("enabled : TRUE");
|
||||
cons_show("enabled : TRUE");
|
||||
} else {
|
||||
cons_show("enabled : FALSE");
|
||||
cons_show("enabled : FALSE");
|
||||
}
|
||||
cons_show("jid : %s", account->jid);
|
||||
cons_show("jid : %s", account->jid);
|
||||
if (account->resource != NULL) {
|
||||
cons_show("resource : %s", account->resource);
|
||||
cons_show("resource : %s", account->resource);
|
||||
}
|
||||
if (account->server != NULL) {
|
||||
cons_show("server : %s", account->server);
|
||||
cons_show("server : %s", account->server);
|
||||
}
|
||||
if (account->last_presence != NULL) {
|
||||
cons_show("Last presence : %s", account->last_presence);
|
||||
}
|
||||
if (account->login_presence != NULL) {
|
||||
cons_show("Login presence : %s", account->login_presence);
|
||||
}
|
||||
cons_show("");
|
||||
}
|
||||
|
10
src/xmpp.h
10
src/xmpp.h
@ -109,15 +109,6 @@ typedef enum {
|
||||
JABBER_DISCONNECTED
|
||||
} jabber_conn_status_t;
|
||||
|
||||
typedef enum {
|
||||
PRESENCE_OFFLINE,
|
||||
PRESENCE_ONLINE,
|
||||
PRESENCE_AWAY,
|
||||
PRESENCE_DND,
|
||||
PRESENCE_CHAT,
|
||||
PRESENCE_XA
|
||||
} jabber_presence_t;
|
||||
|
||||
typedef enum {
|
||||
PRESENCE_SUBSCRIBE,
|
||||
PRESENCE_SUBSCRIBED,
|
||||
@ -178,7 +169,6 @@ void iq_roster_request(void);
|
||||
// presence functions
|
||||
void presence_add_handlers(void);
|
||||
void presence_init(void);
|
||||
gboolean presence_valid_string(const char * const str);
|
||||
void presence_subscription(const char * const jid, const jabber_subscr_t action);
|
||||
GList* presence_get_subscription_requests(void);
|
||||
void presence_free_sub_requests(void);
|
||||
|
@ -149,11 +149,8 @@ _iq_handle_roster_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
item = xmpp_stanza_get_next(item);
|
||||
}
|
||||
|
||||
/* TODO: Save somehow last presence show and use it for initial
|
||||
* presence rather than PRESENCE_ONLINE. It will be helpful
|
||||
* when I set dnd status and reconnect for some reason */
|
||||
// send initial presence
|
||||
presence_update(PRESENCE_ONLINE, NULL, 0);
|
||||
jabber_presence_t connect_presence = account_get_login_presence(jabber_get_account_name());
|
||||
presence_update(connect_presence, NULL, 0);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -56,23 +56,6 @@ presence_add_handlers(void)
|
||||
HANDLE(NULL, NULL, _presence_handler);
|
||||
}
|
||||
|
||||
gboolean
|
||||
presence_valid_string(const char * const str)
|
||||
{
|
||||
if (str == NULL) {
|
||||
return FALSE;
|
||||
} else if ((strcmp(str, "online") == 0) ||
|
||||
(strcmp(str, "chat") == 0) ||
|
||||
(strcmp(str, "away") == 0) ||
|
||||
(strcmp(str, "xa") == 0) ||
|
||||
(strcmp(str, "dnd") == 0)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
presence_subscription(const char * const jid, const jabber_subscr_t action)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user