1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added autocomplete for enabled logins only

This commit is contained in:
James Booth 2012-12-10 00:53:57 +00:00
parent 210da7b137
commit 5013cce832
4 changed files with 53 additions and 20 deletions

View File

@ -33,7 +33,8 @@
static gchar *accounts_loc;
static GKeyFile *accounts;
static PAutocomplete login_ac;
static PAutocomplete all_ac;
static PAutocomplete enabled_ac;
static void _save_accounts(void);
@ -41,7 +42,8 @@ void
accounts_load(void)
{
log_info("Loading accounts");
login_ac = p_autocomplete_new();
all_ac = p_autocomplete_new();
enabled_ac = p_autocomplete_new();
accounts_loc = files_get_accounts_file();
accounts = g_key_file_new();
@ -55,7 +57,10 @@ accounts_load(void)
gsize i;
for (i = 0; i < njids; i++) {
p_autocomplete_add(login_ac, strdup(jids[i]));
if (g_key_file_get_boolean(accounts, jids[i], "enabled", NULL)) {
p_autocomplete_add(enabled_ac, strdup(jids[i]));
}
p_autocomplete_add(all_ac, strdup(jids[i]));
}
for (i = 0; i < njids; i++) {
@ -67,20 +72,33 @@ accounts_load(void)
void
accounts_close(void)
{
p_autocomplete_clear(login_ac);
p_autocomplete_clear(all_ac);
p_autocomplete_clear(enabled_ac);
g_key_file_free(accounts);
}
char *
accounts_find_login(char *prefix)
accounts_find_enabled(char *prefix)
{
return p_autocomplete_complete(login_ac, prefix);
return p_autocomplete_complete(enabled_ac, prefix);
}
char *
accounts_find_all(char *prefix)
{
return p_autocomplete_complete(all_ac, prefix);
}
void
accounts_reset_login_search(void)
accounts_reset_all_search(void)
{
p_autocomplete_reset(login_ac);
p_autocomplete_reset(all_ac);
}
void
accounts_reset_enabled_search(void)
{
p_autocomplete_reset(enabled_ac);
}
void
@ -95,7 +113,8 @@ accounts_add_login(const char *jid, const char *altdomain)
}
_save_accounts();
p_autocomplete_add(login_ac, strdup(jid));
p_autocomplete_add(all_ac, strdup(jid));
p_autocomplete_add(enabled_ac, strdup(jid));
// already exists, update old style accounts
} else {
@ -165,6 +184,7 @@ accounts_enable(const char * const name)
if (g_key_file_has_group(accounts, name)) {
g_key_file_set_boolean(accounts, name, "enabled", TRUE);
_save_accounts();
p_autocomplete_add(enabled_ac, strdup(name));
return TRUE;
} else {
return FALSE;
@ -177,6 +197,7 @@ accounts_disable(const char * const name)
if (g_key_file_has_group(accounts, name)) {
g_key_file_set_boolean(accounts, name, "enabled", FALSE);
_save_accounts();
p_autocomplete_remove(enabled_ac, strdup(name));
return TRUE;
} else {
return FALSE;
@ -212,8 +233,12 @@ accounts_rename(const char * const account_name, const char * const new_name)
g_key_file_remove_group(accounts, account_name, NULL);
_save_accounts();
p_autocomplete_remove(login_ac, strdup(account_name));
p_autocomplete_add(login_ac, strdup(new_name));
p_autocomplete_remove(all_ac, strdup(account_name));
p_autocomplete_add(all_ac, strdup(new_name));
if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
p_autocomplete_remove(enabled_ac, strdup(account_name));
p_autocomplete_add(enabled_ac, strdup(new_name));
}
return TRUE;
}

View File

@ -33,8 +33,10 @@ typedef struct prof_account_t {
void accounts_load(void);
void accounts_close(void);
char * accounts_find_login(char *prefix);
void accounts_reset_login_search(void);
char * accounts_find_all(char *prefix);
char * accounts_find_enabled(char *prefix);
void accounts_reset_all_search(void);
void accounts_reset_enabled_search(void);
void accounts_add_login(const char *jid, const char *altdomain);
gchar** accounts_get_list(void);
ProfAccount* accounts_get_account(const char * const name);

View File

@ -749,7 +749,8 @@ void
cmd_reset_autocomplete()
{
contact_list_reset_search_attempts();
accounts_reset_login_search();
accounts_reset_all_search();
accounts_reset_enabled_search();
prefs_reset_boolean_choice();
p_autocomplete_reset(help_ac);
p_autocomplete_reset(notify_ac);
@ -896,7 +897,7 @@ _cmd_complete_parameters(char *input, int *size)
_parameter_autocomplete(input, size, "/info",
contact_list_find_contact);
_parameter_autocomplete(input, size, "/connect",
accounts_find_login);
accounts_find_enabled);
_parameter_autocomplete_with_ac(input, size, "/sub", sub_ac);
_parameter_autocomplete_with_ac(input, size, "/help", help_ac);
_parameter_autocomplete_with_ac(input, size, "/who", who_ac);
@ -2220,15 +2221,15 @@ static void
_account_autocomplete(char *input, int *size)
{
if ((strncmp(input, "/account set ", 13) == 0) && (*size > 13)) {
_parameter_autocomplete(input, size, "/account set", accounts_find_login);
_parameter_autocomplete(input, size, "/account set", accounts_find_all);
} else if ((strncmp(input, "/account show ", 14) == 0) && (*size > 14)) {
_parameter_autocomplete(input, size, "/account show", accounts_find_login);
_parameter_autocomplete(input, size, "/account show", accounts_find_all);
} else if ((strncmp(input, "/account enable ", 16) == 0) && (*size > 16)) {
_parameter_autocomplete(input, size, "/account enable", accounts_find_login);
_parameter_autocomplete(input, size, "/account enable", accounts_find_all);
} else if ((strncmp(input, "/account disable ", 17) == 0) && (*size > 17)) {
_parameter_autocomplete(input, size, "/account disable", accounts_find_login);
_parameter_autocomplete(input, size, "/account disable", accounts_find_all);
} else if ((strncmp(input, "/account rename ", 16) == 0) && (*size > 16)) {
_parameter_autocomplete(input, size, "/account rename", accounts_find_login);
_parameter_autocomplete(input, size, "/account rename", accounts_find_all);
} else if ((strncmp(input, "/account ", 9) == 0) && (*size > 9)) {
_parameter_autocomplete_with_ac(input, size, "/account", account_ac);
}

View File

@ -147,6 +147,11 @@ jabber_conn_status_t
jabber_connect(const char * const user,
const char * const passwd, const char * const altdomain)
{
if (saved_account != NULL) {
free(saved_account);
saved_account = NULL)
}
if (saved_user == NULL) {
saved_user = strdup(user);
}