mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -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 {
|
} else {
|
||||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
ProfAccount *account = malloc(sizeof(ProfAccount));
|
||||||
account->name = strdup(name);
|
account->name = strdup(name);
|
||||||
|
|
||||||
gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);
|
gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);
|
||||||
if (jid != NULL) {
|
if (jid != NULL) {
|
||||||
account->jid = strdup(jid);
|
account->jid = strdup(jid);
|
||||||
@ -160,13 +161,16 @@ accounts_get_account(const char * const name)
|
|||||||
g_key_file_set_string(accounts, name, "jid", name);
|
g_key_file_set_string(accounts, name, "jid", name);
|
||||||
_save_accounts();
|
_save_accounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
account->enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
|
account->enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
|
||||||
|
|
||||||
gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
|
gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
|
||||||
if (server != NULL) {
|
if (server != NULL) {
|
||||||
account->server = strdup(server);
|
account->server = strdup(server);
|
||||||
} else {
|
} else {
|
||||||
account->server = NULL;
|
account->server = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
|
gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
|
||||||
if (resource != NULL) {
|
if (resource != NULL) {
|
||||||
account->resource = strdup(resource);
|
account->resource = strdup(resource);
|
||||||
@ -174,6 +178,24 @@ accounts_get_account(const char * const name)
|
|||||||
account->resource = NULL;
|
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;
|
return account;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,6 +208,8 @@ accounts_free_account(ProfAccount *account)
|
|||||||
FREE_SET_NULL(account->jid);
|
FREE_SET_NULL(account->jid);
|
||||||
FREE_SET_NULL(account->resource);
|
FREE_SET_NULL(account->resource);
|
||||||
FREE_SET_NULL(account->server);
|
FREE_SET_NULL(account->server);
|
||||||
|
FREE_SET_NULL(account->last_presence);
|
||||||
|
FREE_SET_NULL(account->login_presence);
|
||||||
FREE_SET_NULL(account);
|
FREE_SET_NULL(account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,19 +343,47 @@ accounts_set_login_presence(const char * const account_name, const char * const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
jabber_presence_t
|
||||||
account_get_login_presence(const char * const account_name, char *str)
|
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);
|
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
|
||||||
if (setting == NULL) {
|
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
||||||
str = online;
|
return PRESENCE_ONLINE;
|
||||||
} else if (!presence_valid_string(setting)) {
|
} 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'",
|
log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'",
|
||||||
account_name, setting);
|
account_name, setting);
|
||||||
str = online;
|
return PRESENCE_ONLINE;
|
||||||
} else {
|
|
||||||
str = setting;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,11 +23,15 @@
|
|||||||
#ifndef ACCOUNTS_H
|
#ifndef ACCOUNTS_H
|
||||||
#define ACCOUNTS_H
|
#define ACCOUNTS_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
typedef struct prof_account_t {
|
typedef struct prof_account_t {
|
||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *jid;
|
gchar *jid;
|
||||||
gchar *resource;
|
gchar *resource;
|
||||||
gchar *server;
|
gchar *server;
|
||||||
|
gchar *last_presence;
|
||||||
|
gchar *login_presence;
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
} ProfAccount;
|
} 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_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);
|
||||||
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
|
#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
|
static size_t
|
||||||
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
_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; \
|
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);
|
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);
|
||||||
void create_dir(char *name);
|
void create_dir(char *name);
|
||||||
@ -64,5 +73,6 @@ 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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1236,6 +1236,12 @@ cons_show_account(ProfAccount *account)
|
|||||||
if (account->server != NULL) {
|
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("");
|
cons_show("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/xmpp.h
10
src/xmpp.h
@ -109,15 +109,6 @@ typedef enum {
|
|||||||
JABBER_DISCONNECTED
|
JABBER_DISCONNECTED
|
||||||
} jabber_conn_status_t;
|
} jabber_conn_status_t;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
PRESENCE_OFFLINE,
|
|
||||||
PRESENCE_ONLINE,
|
|
||||||
PRESENCE_AWAY,
|
|
||||||
PRESENCE_DND,
|
|
||||||
PRESENCE_CHAT,
|
|
||||||
PRESENCE_XA
|
|
||||||
} jabber_presence_t;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PRESENCE_SUBSCRIBE,
|
PRESENCE_SUBSCRIBE,
|
||||||
PRESENCE_SUBSCRIBED,
|
PRESENCE_SUBSCRIBED,
|
||||||
@ -178,7 +169,6 @@ void iq_roster_request(void);
|
|||||||
// presence functions
|
// presence functions
|
||||||
void presence_add_handlers(void);
|
void presence_add_handlers(void);
|
||||||
void presence_init(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);
|
void presence_subscription(const char * const jid, const jabber_subscr_t action);
|
||||||
GList* presence_get_subscription_requests(void);
|
GList* presence_get_subscription_requests(void);
|
||||||
void presence_free_sub_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);
|
item = xmpp_stanza_get_next(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Save somehow last presence show and use it for initial
|
jabber_presence_t connect_presence = account_get_login_presence(jabber_get_account_name());
|
||||||
* presence rather than PRESENCE_ONLINE. It will be helpful
|
presence_update(connect_presence, NULL, 0);
|
||||||
* when I set dnd status and reconnect for some reason */
|
|
||||||
// send initial presence
|
|
||||||
presence_update(PRESENCE_ONLINE, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -56,23 +56,6 @@ presence_add_handlers(void)
|
|||||||
HANDLE(NULL, NULL, _presence_handler);
|
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
|
void
|
||||||
presence_subscription(const char * const jid, const jabber_subscr_t action)
|
presence_subscription(const char * const jid, const jabber_subscr_t action)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user