Logins remembered in ~/.profanity

This commit is contained in:
James Booth
2012-05-10 22:18:08 +01:00
parent 73ba46da0d
commit 4e23031c74
3 changed files with 48 additions and 0 deletions

View File

@@ -21,6 +21,8 @@
*/
#include <stdlib.h>
#include <string.h>
#include <glib.h>
static GString *prefs_loc;
@@ -59,6 +61,47 @@ void prefs_set_flash(gboolean value)
_save_prefs();
}
void prefs_add_login(const char *jid)
{
gsize njids;
gchar **jids =
g_key_file_get_string_list(prefs, "connections", "logins", &njids, NULL);
// no logins remembered yet
if (jids == NULL) {
njids = 1;
jids = (gchar**) g_malloc(sizeof(gchar *) * 2);
jids[0] = g_strdup(jid);
jids[1] = NULL;
g_key_file_set_string_list(prefs, "connections", "logins",
(const gchar * const *)jids, njids);
_save_prefs();
g_strfreev(jids);
return;
} else {
gsize i;
for (i = 0; i < njids; i++) {
if (strcmp(jid, jids[i]) == 0) {
g_strfreev(jids);
return;
}
}
// jid not found, add to the list
jids = (gchar **) g_realloc(jids, (sizeof(gchar *) * (njids+2)));
jids[njids] = g_strdup(jid);
njids++;
jids[njids] = NULL;
g_key_file_set_string_list(prefs, "connections", "logins",
(const gchar * const *)jids, njids);
_save_prefs();
g_strfreev(jids);
return;
}
}
static void _save_prefs(void)
{
gsize g_data_size;