]> git.0d.be Git - empathy.git/blobdiff - src/empathy-import-pidgin.c
GNOME Goal: Update icon names
[empathy.git] / src / empathy-import-pidgin.c
index a58111d5920e771ee23048bd9abfa310e70c367a..92adb861ea3204a96437f074b0675b1be019b204 100644 (file)
  * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
  * */
 
-#include <config.h>
-
-#include <string.h>
+#include "config.h"
+#include "empathy-import-pidgin.h"
 
-#include <glib.h>
 #include <glib/gstdio.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-#include <libmissioncontrol/mc-account.h>
-#include <telepathy-glib/util.h>
+#include <dbus/dbus-protocol.h>
 
-#include "empathy-import-dialog.h"
-#include "empathy-import-pidgin.h"
+#include "empathy-import-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
-#include <libempathy/empathy-utils.h>
-
-#include <libempathy-gtk/empathy-ui-utils.h>
+#include "empathy-debug.h"
 
 /* Pidgin to CM map */
 typedef struct
 {
-  gchar *protocol;
-  gchar *pidgin_name;
-  gchar *cm_name;
+  const gchar *protocol;
+  const gchar *pidgin_name;
+  const gchar *cm_name;
 } PidginCmMapItem;
 
 static PidginCmMapItem pidgin_cm_map[] =
@@ -91,6 +82,8 @@ static PidginCmMapItem pidgin_cm_map[] =
 #define PIDGIN_ACCOUNT_TAG_PROTOCOL "protocol"
 #define PIDGIN_ACCOUNT_TAG_PASSWORD "password"
 #define PIDGIN_ACCOUNT_TAG_SETTINGS "settings"
+#define PIDGIN_SETTING_PROP_UI "ui"
+#define PIDGIN_SETTING_PROP_NAME "name"
 #define PIDGIN_SETTING_PROP_TYPE "type"
 #define PIDGIN_PROTOCOL_BONJOUR "bonjour"
 #define PIDGIN_PROTOCOL_NOVELL "novell"
@@ -103,19 +96,19 @@ import_dialog_pidgin_parse_setting (EmpathyImportAccountData *data,
   gchar *tag_name;
   gchar *type = NULL;
   gchar *content;
-  gint i;
+  guint i;
   GValue *value = NULL;
 
   /* We can't do anything if the setting don't have a name */
-  tag_name = (gchar *) xmlGetProp (setting, PIDGIN_ACCOUNT_TAG_NAME);
+  tag_name = (gchar *) xmlGetProp (setting,
+      (xmlChar *) PIDGIN_SETTING_PROP_NAME);
   if (!tag_name)
     return;
 
   /* Search for the map corresponding to setting we are parsing */
   for (i = 0; i < G_N_ELEMENTS (pidgin_cm_map); i++)
     {
-      if (!tp_strdiff (mc_profile_get_protocol_name (data->profile),
-            pidgin_cm_map[i].protocol) &&
+      if (!tp_strdiff (data->protocol, pidgin_cm_map[i].protocol) &&
           !tp_strdiff (tag_name, pidgin_cm_map[i].pidgin_name))
         {
           item = pidgin_cm_map + i;
@@ -128,7 +121,7 @@ import_dialog_pidgin_parse_setting (EmpathyImportAccountData *data,
   if (!item)
     return;
 
-  type = (gchar *) xmlGetProp (setting, PIDGIN_SETTING_PROP_TYPE);
+  type = (gchar *) xmlGetProp (setting, (xmlChar *) PIDGIN_SETTING_PROP_TYPE);
   content = (gchar *) xmlNodeGetContent (setting);
 
   if (!tp_strdiff (type, "bool"))
@@ -139,9 +132,34 @@ import_dialog_pidgin_parse_setting (EmpathyImportAccountData *data,
     }
   else if (!tp_strdiff (type, "int"))
     {
+      TpConnectionManager *cm = NULL;
+      TpProtocol *proto;
+      const TpConnectionManagerParam *param;
+      const gchar *signature;
+      int signature_i;
+
+      if (!empathy_import_protocol_is_supported (data->protocol, &cm))
+        return;
+
+      proto = tp_connection_manager_get_protocol_object (cm, data->protocol);
+      param = tp_protocol_get_param (proto, item->cm_name);
+      signature = tp_connection_manager_param_get_dbus_signature (param);
+      signature_i = (int) (*signature);
+
       i = (gint) g_ascii_strtod (content, NULL);
-      value = tp_g_value_slice_new (G_TYPE_INT);
-      g_value_set_int (value, i);
+
+      if (signature_i == DBUS_TYPE_INT16 ||
+          signature_i == DBUS_TYPE_INT32)
+        {
+          value = tp_g_value_slice_new (G_TYPE_INT);
+          g_value_set_int (value, i);
+        }
+      else if (signature_i == DBUS_TYPE_UINT16 ||
+          signature_i == DBUS_TYPE_UINT32)
+        {
+          value = tp_g_value_slice_new (G_TYPE_UINT);
+          g_value_set_uint (value, (guint) i);
+        }
     }
   else if (!tp_strdiff (type, "string"))
     {
@@ -150,16 +168,60 @@ import_dialog_pidgin_parse_setting (EmpathyImportAccountData *data,
     }
 
   if (value)
-    g_hash_table_insert (data->settings, item->cm_name, value);
+    g_hash_table_insert (data->settings, (gpointer) item->cm_name, value);
 
   g_free (type);
   g_free (content);
 }
 
+static void
+import_dialog_pidgin_handle_settings (EmpathyImportAccountData *data,
+                                      xmlNodePtr settings)
+{
+  xmlNodePtr setting;
+  gchar *tag_ui, *name, *type, *content;
+
+  tag_ui = (gchar *) xmlGetProp (settings, (xmlChar *) PIDGIN_SETTING_PROP_UI);
+
+  /* UI settings - fetch the Enabled parameter.
+   * The expected value of the ui property is 'gtk-gaim', which looks obsolete,
+   * but still valid for 2.7.3.
+   */
+  if (tag_ui && !tp_strdiff (tag_ui, "gtk-gaim"))
+    {
+      for (setting = settings->children; setting; setting = setting->next)
+        {
+          name = (gchar *) xmlGetProp (setting,
+              (xmlChar *) PIDGIN_SETTING_PROP_NAME);
+          type = (gchar *) xmlGetProp (setting,
+              (xmlChar *) PIDGIN_SETTING_PROP_TYPE);
+          /* The Enabled parameter is supposed to be boolean.
+           * Pidgin name of the setting is 'auto-login'.
+           */
+          if (!tp_strdiff (name, "auto-login") && !tp_strdiff (type, "bool"))
+            {
+              content = (gchar *) xmlNodeGetContent (setting);
+              data->enabled = (0 != (gint) g_ascii_strtod (content, NULL));
+              g_free (content);
+            }
+          g_free (type);
+          g_free (name);
+        }
+    }
+  /* General settings. */
+  else
+    {
+      for (setting = settings->children; setting; setting = setting->next)
+        import_dialog_pidgin_parse_setting (data, setting);
+    }
+
+  g_free (tag_ui);
+}
+
 GList *
 empathy_import_pidgin_load (void)
 {
-  xmlNodePtr rootnode, node, child, setting;
+  xmlNodePtr rootnode, node, child;
   xmlParserCtxtPtr ctxt;
   xmlDocPtr doc;
   gchar *filename;
@@ -199,23 +261,26 @@ empathy_import_pidgin_load (void)
           if (!tp_strdiff ((gchar *) child->name,
               PIDGIN_ACCOUNT_TAG_PROTOCOL))
             {
-              gchar *content;
+              xmlChar *content;
               const gchar *protocol;
 
-              protocol = content = (gchar *) xmlNodeGetContent (child);
+              content = xmlNodeGetContent (child);
+
+              protocol = (const gchar *) content;
 
               if (g_str_has_prefix (protocol, "prpl-"))
                 protocol += 5;
 
               if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_BONJOUR))
-                protocol = "salut";
+                data->protocol = g_strdup ("salut");
               else if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_NOVELL))
-                protocol = "groupwise";
+                data->protocol = g_strdup ("groupwise");
+              else
+                data->protocol = g_strdup (protocol);
 
-              data->profile = mc_profile_lookup (protocol);
-              g_free (content);
+              xmlFree (content);
 
-              if (data->profile == NULL)
+              if (data->protocol == NULL)
                 break;
             }
 
@@ -240,8 +305,7 @@ empathy_import_pidgin_load (void)
                 username = name;
 
              /* Split "username@server" if it is an IRC account */
-             if (strstr (name, "@") && !tp_strdiff (
-                   mc_profile_get_protocol_name (data->profile), "irc"))
+             if (strstr (name, "@") && !tp_strdiff (data->protocol, "irc"))
               {
                 nick_server = g_strsplit (name, "@", 2);
                 username = nick_server[0];
@@ -249,13 +313,13 @@ empathy_import_pidgin_load (void)
                 /* Add the server setting */
                 value = tp_g_value_slice_new (G_TYPE_STRING);
                 g_value_set_string (value, nick_server[1]);
-                g_hash_table_insert (data->settings, "server", value);
+                g_hash_table_insert (data->settings, (gpointer) "server", value);
               }
 
               /* Add the account setting */
               value = tp_g_value_slice_new (G_TYPE_STRING);
               g_value_set_string (value, username);
-              g_hash_table_insert (data->settings, "account", value);
+              g_hash_table_insert (data->settings, (gpointer) "account", value);
 
               g_strfreev (name_resource);
               g_strfreev (nick_server);
@@ -273,7 +337,7 @@ empathy_import_pidgin_load (void)
               /* Add the password setting */
               value = tp_g_value_slice_new (G_TYPE_STRING);
               g_value_set_string (value, password);
-              g_hash_table_insert (data->settings, "password", value);
+              g_hash_table_insert (data->settings, (gpointer) "password", value);
 
               g_free (password);
             }
@@ -281,14 +345,36 @@ empathy_import_pidgin_load (void)
           /* Other settings */
           else if (!tp_strdiff ((gchar *) child->name,
               PIDGIN_ACCOUNT_TAG_SETTINGS))
-              for (setting = child->children; setting; setting = setting->next)
-                import_dialog_pidgin_parse_setting (data, setting);
+            import_dialog_pidgin_handle_settings (data, child);
         }
 
       /* If we have the needed settings, add the account data to the list,
        * otherwise free the data */
-      if (data->profile != NULL && g_hash_table_size (data->settings) > 0)
-        accounts = g_list_prepend (accounts, data);
+      if (data->protocol != NULL && g_hash_table_size (data->settings) > 0)
+        {
+          /* Special-case XMPP:
+           * http://bugzilla.gnome.org/show_bug.cgi?id=579992 */
+          if (!tp_strdiff (data->protocol, "jabber"))
+            {
+              if (EMP_STR_EMPTY (tp_asv_get_string (data->settings, "server")))
+                {
+                  g_hash_table_remove (data->settings, "port");
+                  g_hash_table_remove (data->settings, "server");
+                }
+            }
+
+          /* If there is no password then MC treats the account as not
+           * ready and doesn't display it. */
+          if (!g_hash_table_lookup (data->settings, "password"))
+            {
+              GValue *value;
+              value = tp_g_value_slice_new (G_TYPE_STRING);
+              g_value_set_string (value, "");
+              g_hash_table_insert (data->settings, (gpointer) "password", value);
+            }
+
+          accounts = g_list_prepend (accounts, data);
+        }
       else
         empathy_import_account_data_free (data);
     }
@@ -310,7 +396,8 @@ empathy_import_pidgin_accounts_to_import (void)
   gboolean out;
   GFile *file;
 
-  filename = g_build_filename (g_get_home_dir (), ".purple", "accounts.xml", NULL);
+  filename = g_build_filename (g_get_home_dir (), ".purple", "accounts.xml",
+      NULL);
   file = g_file_new_for_path (filename);
   out = g_file_query_exists (file, NULL);