diff options
-rw-r--r-- | jabber.c | 4 | ||||
-rw-r--r-- | preferences.c | 43 | ||||
-rw-r--r-- | preferences.h | 1 |
3 files changed, 48 insertions, 0 deletions
diff --git a/jabber.c b/jabber.c index 8244c257..6d55d620 100644 --- a/jabber.c +++ b/jabber.c @@ -28,6 +28,7 @@ #include "contact_list.h" #include "windows.h" #include "util.h" +#include "preferences.h" #define PING_INTERVAL 120000 // 2 minutes @@ -221,6 +222,9 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn, xmpp_stanza_set_name(pres, "presence"); xmpp_send(conn, pres); xmpp_stanza_release(pres); + + prefs_add_login(jid); + jabber_conn.conn_status = JABBER_CONNECTED; } else { diff --git a/preferences.c b/preferences.c index 7814f918..2b16e000 100644 --- a/preferences.c +++ b/preferences.c @@ -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; diff --git a/preferences.h b/preferences.h index 31754b0e..cb6586d2 100644 --- a/preferences.h +++ b/preferences.h @@ -31,5 +31,6 @@ gboolean prefs_get_beep(void); void prefs_set_beep(gboolean value); gboolean prefs_get_flash(void); void prefs_set_flash(gboolean value); +void prefs_add_login(const char *jid); #endif |