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

Added functions for autocompletion of JID on login

This commit is contained in:
James Booth 2012-05-10 23:11:48 +01:00
parent 5e3962a129
commit d6f7862097

View File

@ -30,11 +30,13 @@ static GKeyFile *prefs;
// search logins list
static GSList *logins = NULL;
//static GSList *last_found = NULL;
//static gchar *search_str = NULL;
static GSList *last_found = NULL;
static gchar *search_str = NULL;
static void _save_prefs(void);
static gint _compare_jids(gconstpointer a, gconstpointer b);
static void _reset_login_search(void);
static gchar * _search_logins_from(GSList *curr);
void prefs_load(void)
{
@ -55,6 +57,57 @@ void prefs_load(void)
}
}
char * find_login(char *search_str)
{
gchar *found = NULL;
if (!logins)
return NULL;
if (last_found == NULL) {
search_str = g_strdup(search_str);
found = _search_logins_from(logins);
return found;
} else {
found = _search_logins_from(g_slist_next(last_found));
if (found != NULL)
return found;
found = _search_logins_from(logins);
if (found != NULL)
return found;
_reset_login_search();
return NULL;
}
}
static void _reset_login_search(void)
{
last_found = NULL;
if (search_str != NULL)
free(search_str);
}
static gchar * _search_logins_from(GSList *curr)
{
while(curr) {
gchar *curr_jid = curr->data;
if (strncmp(curr_jid, search_str, strlen(search_str)) == 0) {
gchar *result = g_strdup(curr_jid);
last_found = curr;
return result;
}
curr = g_slist_next(curr);
}
return NULL;
}
static gint _compare_jids(gconstpointer a, gconstpointer b)
{
const gchar *str_a = (const gchar *) a;