1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

The /priority command now sets per account/status settings

This commit is contained in:
James Booth 2013-01-31 22:48:21 +00:00
parent e6596735c4
commit b397a8c53e
5 changed files with 70 additions and 39 deletions

View File

@ -205,6 +205,12 @@ accounts_get_account(const char * const name)
account->login_presence = strdup(presence); account->login_presence = strdup(presence);
} }
account->priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL);
account->priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL);
account->priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL);
account->priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
account->priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);
return account; return account;
} }
} }
@ -381,34 +387,48 @@ accounts_set_priority_dnd(const char * const account_name, const gint value)
} }
} }
gint void
prefs_get_priority_online(const char * const account_name) accounts_set_priority_all(const char * const account_name, const gint value)
{ {
return g_key_file_get_integer(accounts, account_name, "priority.online", NULL); if (accounts_account_exists(account_name)) {
accounts_set_priority_online(account_name, value);
accounts_set_priority_chat(account_name, value);
accounts_set_priority_away(account_name, value);
accounts_set_priority_xa(account_name, value);
accounts_set_priority_dnd(account_name, value);
_save_accounts();
}
} }
gint gint
prefs_get_priority_chat(const char * const account_name) accounts_get_priority_for_presence_type(const char * const account_name,
jabber_presence_t presence_type)
{ {
return g_key_file_get_integer(accounts, account_name, "priority.chat", NULL); gint result;
}
gint switch (presence_type)
prefs_get_priority_away(const char * const account_name) {
{ case (PRESENCE_ONLINE):
return g_key_file_get_integer(accounts, account_name, "priority.away", NULL); result = g_key_file_get_integer(accounts, account_name, "priority.online", NULL);
} break;
case (PRESENCE_CHAT):
result = g_key_file_get_integer(accounts, account_name, "priority.chat", NULL);
break;
case (PRESENCE_AWAY):
result = g_key_file_get_integer(accounts, account_name, "priority.away", NULL);
break;
case (PRESENCE_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;
break;
}
gint return result;
prefs_get_priority_xa(const char * const account_name)
{
return g_key_file_get_integer(accounts, account_name, "priority.xa", NULL);
}
gint
prefs_get_priority_dnd(const char * const account_name)
{
return g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL);
} }
void void

View File

@ -68,10 +68,8 @@ void accounts_set_priority_chat(const char * const account_name, const gint valu
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);
void accounts_set_priority_xa(const char * const account_name, const gint value); 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);
gint prefs_get_priority_online(const char * const account_name); void accounts_set_priority_all(const char * const account_name, const gint value);
gint prefs_get_priority_chat(const char * const account_name); gint accounts_get_priority_for_presence_type(const char * const account_name,
gint prefs_get_priority_away(const char * const account_name); jabber_presence_t presence_type);
gint prefs_get_priority_xa(const char * const account_name);
gint prefs_get_priority_dnd(const char * const account_name);
#endif #endif

View File

@ -558,10 +558,11 @@ static struct cmd_t setting_commands[] =
{ "/priority", { "/priority",
_cmd_set_priority, parse_args, 1, 1, _cmd_set_priority, parse_args, 1, 1,
{ "/priority value", "Set priority for connection.", { "/priority value", "Set priority for the current account.",
{ "/priority value", { "/priority value",
"---------------", "---------------",
"Set priority for the current session.", "Set priority for the current account, presence will be sent when calling this command.",
"See the /account command for more specific priority settings per presence status.",
"value : Number between -128 and 127. Default value is 0.", "value : Number between -128 and 127. Default value is 0.",
NULL } } }, NULL } } },
@ -2189,11 +2190,19 @@ _cmd_set_autoaway(gchar **args, struct cmd_help_t help)
static gboolean static gboolean
_cmd_set_priority(gchar **args, struct cmd_help_t help) _cmd_set_priority(gchar **args, struct cmd_help_t help)
{ {
jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
return TRUE;
}
char *value = args[0]; char *value = args[0];
int intval; int intval;
if (_strtoi(value, &intval, -128, 127) == 0) { if (_strtoi(value, &intval, -128, 127) == 0) {
prefs_set_priority((int)intval); accounts_set_priority_all(jabber_get_account_name(), intval);
//prefs_set_priority((int)intval);
// update presence with new priority // update presence with new priority
presence_update(jabber_get_presence_type(), jabber_get_presence_message(), 0); presence_update(jabber_get_presence_type(), jabber_get_presence_message(), 0);
cons_show("Priority set to %d.", intval); cons_show("Priority set to %d.", intval);

View File

@ -1259,23 +1259,28 @@ cons_show_account(ProfAccount *account)
{ {
cons_show("%s account details:", account->name); cons_show("%s account details:", account->name);
if (account->enabled) { if (account->enabled) {
cons_show("enabled : TRUE"); cons_show ("enabled : TRUE");
} else { } 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) { if (account->resource != NULL) {
cons_show("resource : %s", account->resource); cons_show ("resource : %s", account->resource);
} }
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) { if (account->last_presence != NULL) {
cons_show("Last presence : %s", account->last_presence); cons_show ("Last presence : %s", account->last_presence);
} }
if (account->login_presence != NULL) { if (account->login_presence != NULL) {
cons_show("Login presence : %s", account->login_presence); cons_show ("Login presence : %s", account->login_presence);
} }
cons_show ("Priority (online) : %d", account->priority_online);
cons_show ("Priority (chat) : %d", account->priority_chat);
cons_show ("Priority (away) : %d", account->priority_away);
cons_show ("Priority (xa) : %d", account->priority_xa);
cons_show ("Priority (dnd) : %d", account->priority_dnd);
cons_show(""); cons_show("");
} }
@ -1405,8 +1410,6 @@ cons_show_presence_prefs(void)
cons_show("Presence preferences:"); cons_show("Presence preferences:");
cons_show(""); cons_show("");
cons_show("Priority (/priority) : %d", prefs_get_priority());
if (strcmp(prefs_get_autoaway_mode(), "off") == 0) { if (strcmp(prefs_get_autoaway_mode(), "off") == 0) {
cons_show("Autoaway (/autoaway mode) : OFF"); cons_show("Autoaway (/autoaway mode) : OFF");
} else { } else {

View File

@ -153,7 +153,8 @@ presence_update(jabber_presence_t presence_type, const char * const msg,
if (jabber_get_connection_status() != JABBER_CONNECTED) if (jabber_get_connection_status() != JABBER_CONNECTED)
return; return;
pri = prefs_get_priority(); pri = accounts_get_priority_for_presence_type(jabber_get_account_name(),
presence_type);
if (pri < JABBER_PRIORITY_MIN || pri > JABBER_PRIORITY_MAX) if (pri < JABBER_PRIORITY_MIN || pri > JABBER_PRIORITY_MAX)
pri = 0; pri = 0;