changeset 180:1265988dc2bf multiaccounts

changed saving file that preferences per conversation from accounts.xml to prefs.xml
author mikanbako <maoutwo@gmail.com>
date Tue, 05 Aug 2008 01:26:08 +0900
parents 0339b4abe290
children 0b0b4cab7c0e
files pidgin-twitter.c pidgin-twitter.h
diffstat 2 files changed, 99 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Sun Aug 03 12:15:09 2008 +0900
+++ b/pidgin-twitter.c	Tue Aug 05 01:26:08 2008 +0900
@@ -3289,12 +3289,66 @@
     gtk_widget_destroy(GTK_WIDGET(dialog));
 }
 
+static void
+add_pref(const char *key)
+{
+    gchar **names;
+    guint names_length;
+    gchar *generated_key, *temp;
+    int i, j;
+
+    if(purple_prefs_exists(key))
+        return;
+
+    twitter_debug("eeeee : %s\n", key);
+
+    names = g_strsplit(key, "/", 0);
+    names_length = g_strv_length(names);
+
+    for(i = 2; i < names_length - 1; i++) {
+        /* names[0] is an empty string */
+        generated_key = g_strdup(names[1]);
+        temp = generated_key;
+
+        for(j = 2; j <= i; j++) {
+            generated_key = g_strjoin("/", generated_key, names[j], NULL);
+            g_free(temp);
+            temp = generated_key;
+        }
+
+        generated_key = g_strconcat("/", generated_key, NULL);
+        g_free(temp);
+        if(!purple_prefs_exists(generated_key))
+            purple_prefs_add_none(generated_key);
+        g_free(generated_key);
+    }
+
+    g_strfreev(names);
+}
+
 static gchar*
 create_key_with_service_account(PurpleAccount *account,
                                 const char *conv_name,
-                                const char *key)
+                                const char *key,
+                                gboolean create_node)
 {
-    return g_strdup_printf("%s:%s", key, get_service_name(account, conv_name));
+    gchar *account_username, *key_with_account;
+
+    account_username = purple_strcasereplace(
+                               purple_account_get_username(account),
+                               "/",
+                               "_");
+
+    key_with_account = g_strdup_printf("%s/%s/%s",
+                                        key,
+                                        account_username,
+                                        get_service_name(account, conv_name));
+
+    if (create_node)
+        add_pref(key_with_account);
+
+    g_free(account_username);
+    return key_with_account;
 }
 
 static void
@@ -3305,9 +3359,10 @@
 {
     gchar *key_with_account = create_key_with_service_account(account,
                                                               conv_name,
-                                                              key);
-
-    purple_account_set_string(account, key_with_account, value);
+                                                              key,
+                                                              TRUE);
+
+    purple_prefs_set_string(key_with_account, value);
     g_free(key_with_account);
 }
 
@@ -3319,11 +3374,16 @@
 {
     gchar *key_with_account = create_key_with_service_account(account,
                                                               conv_name,
-                                                              key);
-    const char *value = purple_account_get_string(account,
-                                                  key_with_account,
-                                                  default_value);
-
+                                                              key,
+                                                              FALSE);
+    const char *value;
+
+    if(!purple_prefs_exists(key_with_account)) {
+        g_free(key_with_account);
+        return default_value;
+    }
+
+    value = purple_prefs_get_string(key_with_account);
     g_free(key_with_account);
 
     return value;
@@ -3337,9 +3397,10 @@
 {
     gchar *key_with_account = create_key_with_service_account(account,
                                                               conv_name,
-                                                              key);
-
-    purple_account_set_int(account, key_with_account, value);
+                                                              key,
+                                                              TRUE);
+
+    purple_prefs_set_int(key_with_account, value);
     g_free(key_with_account);
 }
 
@@ -3351,11 +3412,16 @@
 {
     gchar *key_with_account = create_key_with_service_account(account,
                                                               conv_name,
-                                                              key);
-    int value = purple_account_get_int(account,
-                                       key_with_account,
-                                       default_value);
-
+                                                              key,
+                                                              FALSE);
+    int value;
+    
+    if(!purple_prefs_exists(key_with_account)) {
+        g_free(key_with_account);
+        return default_value;
+    }
+    
+    value = purple_prefs_get_int(key_with_account);
     g_free(key_with_account);
 
     return value;
@@ -3369,9 +3435,10 @@
 {
     gchar *key_with_account = create_key_with_service_account(account,
                                                               conv_name,
-                                                              key);
-
-    purple_account_set_bool(account, key_with_account, value);
+                                                              key,
+                                                              TRUE);
+
+    purple_prefs_set_bool(key_with_account, value);
     g_free(key_with_account);
 }
 
@@ -3383,11 +3450,16 @@
 {
     gchar *key_with_account = create_key_with_service_account(account,
                                                               conv_name,
-                                                              key);
-    gboolean value = purple_account_get_bool(account,
-                                             key_with_account,
-                                             default_value);
-
+                                                              key,
+                                                              FALSE);
+    gboolean value;
+
+    if(!purple_prefs_exists(key_with_account)) {
+        g_free(key_with_account);
+        return default_value;
+    }
+
+    value = purple_prefs_get_bool(key_with_account);
     g_free(key_with_account);
 
     return value;
--- a/pidgin-twitter.h	Sun Aug 03 12:15:09 2008 +0900
+++ b/pidgin-twitter.h	Tue Aug 05 01:26:08 2008 +0900
@@ -229,7 +229,7 @@
 static void account_preference_bool_toggled_cb(GtkToggleButton *togglebutton, gpointer conv_ptr);
 static void account_preference_interval_changed(PurpleAccount *account, const char *conv_name);
 static void account_preference_spin_changed_cb(GtkSpinButton *spinbutton, gpointer conv_ptr);
-static gchar* create_key_with_service_account(PurpleAccount *account, const char *conv_name, const char *key);
+static gchar* create_key_with_service_account(PurpleAccount *account, const char *conv_name, const char *key, gboolean create_node);
 static void service_account_set_string(PurpleAccount *account, const char *conv_name, const char *key, const char *value);
 static const char* service_account_get_string(PurpleAccount *account, const char *conv_name, const char *key, const char *default_value);
 static void service_account_set_int(PurpleAccount *account, const char *conv_name, const char *key, gboolean value);