]> git.0d.be Git - empathy.git/blobdiff - src/empathy-import-dialog.c
Be more compatible with Facebook emoticon codes
[empathy.git] / src / empathy-import-dialog.c
index bffd3f8637de9a12e492c5b866a473de028b9508..9d86dd1dec4a69044220c6b23f21abaa10f706e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Collabora Ltd.
+ * Copyright (C) 2008-2009 Collabora Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
  *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
  *
  * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
- * */
-
-#include <config.h>
-
-#include <string.h>
-
-#include <glib.h>
-#include <gtk/gtk.h>
-#include <glade/glade.h>
-#include <glib/gi18n.h>
-#include <glib/gstdio.h>
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-#include <libmissioncontrol/mc-account.h>
-#include <telepathy-glib/util.h>
+ *          Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
+ */
 
+#include "config.h"
 #include "empathy-import-dialog.h"
 
-#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
-#include <libempathy/empathy-utils.h>
+#include <glib/gi18n-lib.h>
 
-#include <libempathy-gtk/empathy-ui-utils.h>
+#include "empathy-import-widget.h"
+#include "empathy-utils.h"
 
-/* Pidgin to MC map */
-typedef struct
-{
-  gchar *protocol;
-  gchar *pidgin_name;
-  gchar *mc_name;
-} PidginMcMapItem;
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
 
-static PidginMcMapItem pidgin_mc_map[] =
-{
-  { "msn", "server", "server" },
-  { "msn", "port", "port" },
-
-  { "jabber", "connect_server", "server" },
-  { "jabber", "port", "port" },
-  { "jabber", "require_tls", "require-encryption" },
-  { "jabber", "old_ssl", "old-ssl" },
-
-  { "aim", "server", "server" },
-  { "aim", "port", "port" },
-
-  { "salut", "first", "first-name" },
-  { "salut", "last", "last-name" },
-  { "salut", "jid", "jid" },
-  { "salut", "email", "email" },
-
-  { "groupwise", "server", "server" },
-  { "groupwise", "port", "port" },
-
-  { "icq", "server", "server" },
-  { "icq", "port", "port" },
-
-  { "irc", "realname", "fullname" },
-  { "irc", "ssl", "use-ssl" },
-  { "irc", "port", "port" },
-
-  { "yahoo", "server", "server" },
-  { "yahoo", "port", "port" },
-  { "yahoo", "xfer_port", "xfer-port" },
-  { "yahoo", "ignore_invites", "ignore-invites" },
-  { "yahoo", "yahoojp", "yahoojp" },
-  { "yahoo", "xferjp_host", "xferjp-host" },
-  { "yahoo", "serverjp", "serverjp" },
-  { "yahoo", "xfer_host", "xfer-host" },
+enum {
+  PROP_PARENT = 1,
+  PROP_SHOW_WARNING,
+  PROP_CMS,
 };
 
-typedef struct
-{
-  GHashTable *settings;
-  McProfile *profile;
-} AccountData;
+typedef struct {
+  GtkWindow *parent_window;
 
-typedef struct
-{
-  GtkWidget *window;
-  GtkWidget *treeview;
-  GtkWidget *button_ok;
-  GtkWidget *button_cancel;
-  GList *accounts;
-} EmpathyImportDialog;
-
-#define PIDGIN_ACCOUNT_TAG_NAME "name"
-#define PIDGIN_ACCOUNT_TAG_ACCOUNT "account"
-#define PIDGIN_ACCOUNT_TAG_PROTOCOL "protocol"
-#define PIDGIN_ACCOUNT_TAG_PASSWORD "password"
-#define PIDGIN_ACCOUNT_TAG_SETTINGS "settings"
-#define PIDGIN_SETTING_PROP_TYPE "type"
-#define PIDGIN_PROTOCOL_BONJOUR "bonjour"
-#define PIDGIN_PROTOCOL_NOVELL "novell"
-
-enum
-{
-  COL_IMPORT = 0,
-  COL_PROTOCOL,
-  COL_NAME,
-  COL_SOURCE,
-  COL_ACCOUNT_DATA,
-  COL_COUNT
-};
+  EmpathyImportWidget *iw;
 
-static void
-import_dialog_account_data_free (AccountData *data)
-{
-  if (data == NULL)
-    return;
-  if (data->profile != NULL)
-    g_object_unref (data->profile);
-  if (data->settings != NULL)
-    g_hash_table_destroy (data->settings);
-}
-
-static void
-import_dialog_add_account (AccountData *data)
-{
-  McAccount *account;
-  GHashTableIter iter;
-  gpointer key, value;
-  gchar *display_name;
-  GValue *username;
-
-  account = mc_account_create (data->profile);
-
-  g_hash_table_iter_init (&iter, data->settings);
-  while (g_hash_table_iter_next (&iter, &key, &value))
-    {
-      const gchar *param = key;
-      GValue *gvalue = value;
+  gboolean show_warning;
+  TpawConnectionManagers *cms;
+} EmpathyImportDialogPriv;
 
-      switch (G_VALUE_TYPE (gvalue))
-        {
-          case G_TYPE_STRING:
-            DEBUG ("Set param '%s' to '%s' (string)",
-                param, g_value_get_string (gvalue));
-            mc_account_set_param_string (account,
-                param, g_value_get_string (gvalue));
-            break;
-
-          case G_TYPE_BOOLEAN:
-            DEBUG ("Set param '%s' to %s (boolean)",
-                param, g_value_get_boolean (gvalue) ? "TRUE" : "FALSE");
-            mc_account_set_param_boolean (account,
-                param, g_value_get_boolean (gvalue));
-            break;
-
-          case G_TYPE_INT:
-            DEBUG ("Set param '%s' to '%i' (integer)",
-                param, g_value_get_int (gvalue));
-            mc_account_set_param_int (account,
-                param, g_value_get_int (gvalue));
-            break;
-        }
-    }
-
-  /* Set the display name of the account */
-  username = g_hash_table_lookup (data->settings, "account");
-  display_name = g_strdup_printf ("%s (%s)",
-      mc_profile_get_display_name (data->profile),
-      g_value_get_string (username));
-  mc_account_set_display_name (account, display_name);
-
-  g_free (display_name);
-  g_object_unref (account);
-}
+G_DEFINE_TYPE (EmpathyImportDialog, empathy_import_dialog, GTK_TYPE_DIALOG)
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyImportDialog)
 
 static void
-import_dialog_pidgin_parse_setting (AccountData *data,
-                                    xmlNodePtr setting)
+import_dialog_add_import_widget (EmpathyImportDialog *self)
 {
-  PidginMcMapItem *item = NULL;
-  gchar *tag_name;
-  gchar *type = NULL;
-  gchar *content;
-  gint 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);
-  if (!tag_name)
-    return;
-
-  /* Search for the map corresponding to setting we are parsing */
-  for (i = 0; i < G_N_ELEMENTS (pidgin_mc_map); i++)
-    {
-      if (!tp_strdiff (mc_profile_get_protocol_name (data->profile),
-            pidgin_mc_map[i].protocol) &&
-          !tp_strdiff (tag_name, pidgin_mc_map[i].pidgin_name))
-        {
-          item = pidgin_mc_map + i;
-          break;
-        }
-    }
-  g_free (tag_name);
+  EmpathyImportWidget *iw;
+  EmpathyImportDialogPriv *priv = GET_PRIV (self);
+  GtkWidget *widget, *area;
 
-  /* If we didn't find the item, there is nothing we can do */
-  if (!item)
-    return;
+  area = gtk_dialog_get_content_area (GTK_DIALOG (self));
 
-  type = (gchar *) xmlGetProp (setting, PIDGIN_SETTING_PROP_TYPE);
-  content = (gchar *) xmlNodeGetContent (setting);
+  iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL, priv->cms);
+  widget = empathy_import_widget_get_widget (iw);
+  gtk_box_pack_start (GTK_BOX (area), widget, TRUE, TRUE, 0);
+  gtk_widget_show (widget);
 
-  if (!tp_strdiff (type, "bool"))
-    {
-      i = (gint) g_ascii_strtod (content, NULL);
-      value = tp_g_value_slice_new (G_TYPE_BOOLEAN);
-      g_value_set_boolean (value, i != 0);
-    }
-  else if (!tp_strdiff (type, "int"))
-    {
-      i = (gint) g_ascii_strtod (content, NULL);
-      value = tp_g_value_slice_new (G_TYPE_INT);
-      g_value_set_int (value, i);
-    }
-  else if (!tp_strdiff (type, "string"))
-    {
-      value = tp_g_value_slice_new (G_TYPE_STRING);
-      g_value_set_string (value, content);
-    }
-
-  if (value)
-    g_hash_table_insert (data->settings, item->mc_name, value);
+  priv->iw = iw;
 
-  g_free (type);
-  g_free (content);
+  gtk_dialog_add_buttons (GTK_DIALOG (self),
+      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+      _("_Import"), GTK_RESPONSE_OK,
+      NULL);
 }
 
-static GList *
-import_dialog_pidgin_load (void)
+static void
+import_dialog_show_warning_message (EmpathyImportDialog *self)
 {
-  xmlNodePtr rootnode, node, child, setting;
-  xmlParserCtxtPtr ctxt;
-  xmlDocPtr doc;
-  gchar *filename;
-  GList *accounts = NULL;
-
-  /* Load pidgin accounts xml */
-  ctxt = xmlNewParserCtxt ();
-  filename = g_build_filename (g_get_home_dir (), ".purple", "accounts.xml",
-      NULL);
+  GtkWidget *hbox, *vbox, *w;
 
-  if (g_access (filename, R_OK) != 0)
-    goto FILENAME;
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
 
-  doc = xmlCtxtReadFile (ctxt, filename, NULL, 0);
+  w = gtk_label_new (_("No accounts to import could be found. Empathy "
+          "currently only supports importing accounts from Pidgin."));
+  gtk_label_set_line_wrap  (GTK_LABEL (w), TRUE);
+  gtk_label_set_selectable (GTK_LABEL (w), TRUE);
+  gtk_misc_set_alignment   (GTK_MISC  (w), 0.0, 0.0);
+  gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
 
-  rootnode = xmlDocGetRootElement (doc);
-  if (rootnode == NULL)
-    goto OUT;
+  w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
+      GTK_ICON_SIZE_DIALOG);
+  gtk_misc_set_alignment (GTK_MISC (w), 0.5, 0.0);
+  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
 
-  for (node = rootnode->children; node; node = node->next)
-    {
-      AccountData *data;
+  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
 
-      /* If it is not an account node, skip. */
-      if (tp_strdiff ((gchar *) node->name, PIDGIN_ACCOUNT_TAG_ACCOUNT))
-        continue;
+  w = gtk_dialog_get_content_area (GTK_DIALOG (self));
+  gtk_box_pack_start (GTK_BOX (w), hbox, FALSE, FALSE, 0);
 
-      /* Create account data struct */
-      data = g_slice_new0 (AccountData);
-      data->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
-        (GDestroyNotify) tp_g_value_slice_free);
+  gtk_box_set_spacing (GTK_BOX (w), 14); /* 14 + 2 * 5 = 24 */
 
-      /* Parse account's child nodes to fill the account data struct */
-      for (child = node->children; child; child = child->next)
-        {
-          GValue *value;
-
-          /* Protocol */
-          if (!tp_strdiff ((gchar *) child->name,
-              PIDGIN_ACCOUNT_TAG_PROTOCOL))
-            {
-              const gchar *protocol;
-
-              protocol = (gchar *) xmlNodeGetContent (child);
-
-              if (g_str_has_prefix (protocol, "prpl-"))
-                protocol += 5;
-
-              if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_BONJOUR))
-                protocol = "salut";
-              else if (!tp_strdiff (protocol, PIDGIN_PROTOCOL_NOVELL))
-                protocol = "groupwise";
-
-              data->profile = mc_profile_lookup (protocol);
-            }
-
-          /* Username and IRC server. */
-          else if (!tp_strdiff ((gchar *) child->name,
-              PIDGIN_ACCOUNT_TAG_NAME))
-            {
-              gchar *name;
-              GStrv name_resource = NULL;
-              GStrv nick_server = NULL;
-              const gchar *username;
-
-              name = (gchar *) xmlNodeGetContent (child);
-
-              /* Split "username/resource" */
-              if (g_strrstr (name, "/") != NULL)
-                {
-                  name_resource = g_strsplit (name, "/", 2);
-                  username = name_resource[0];
-                }
-              else
-                username = name;
-
-             /* Split "username@server" if it is an IRC account */
-             if (strstr (name, "@") && !tp_strdiff (
-                   mc_profile_get_protocol_name (data->profile), "irc"))
-              {
-                nick_server = g_strsplit (name, "@", 2);
-                username = nick_server[0];
-
-                /* 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);
-              }
-
-              /* 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_strfreev (name_resource);
-              g_strfreev (nick_server);
-              g_free (name);
-            }
-
-          /* Password */
-          else if (!tp_strdiff ((gchar *) child->name,
-              PIDGIN_ACCOUNT_TAG_PASSWORD))
-            {
-              gchar *password;
-
-              password = (gchar *) xmlNodeGetContent (child);
-
-              /* 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_free (password);
-            }
-
-          /* 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);
-        }
-
-      /* If we have the needed settings, add the account data to the list,
-       * otherwise free the data */
-      if (g_hash_table_size (data->settings) > 0)
-        accounts = g_list_prepend (accounts, data);
-      else
-        import_dialog_account_data_free (data);
-    }
+  gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CLOSE,
+      GTK_RESPONSE_CLOSE);
 
-OUT:
-  xmlFreeDoc(doc);
-  xmlFreeParserCtxt (ctxt);
-
-FILENAME:
-  g_free (filename);
-
-  return accounts;
+  gtk_widget_show_all (w);
 }
 
-static gboolean
-import_dialog_tree_model_foreach (GtkTreeModel *model,
-                                  GtkTreePath *path,
-                                  GtkTreeIter *iter,
-                                  gpointer user_data)
+static void
+impl_signal_response (GtkDialog *dialog,
+    gint response_id)
 {
-  EmpathyImportDialog *dialog = (EmpathyImportDialog *) user_data;
-  gboolean to_import;
-  AccountData *data;
+  EmpathyImportDialogPriv *priv = GET_PRIV (dialog);
 
-  gtk_tree_model_get (model, iter,
-      COL_IMPORT, &to_import,
-      COL_ACCOUNT_DATA, &data,
-      -1);
+  if (response_id == GTK_RESPONSE_OK)
+    empathy_import_widget_add_selected_accounts (priv->iw);
 
-  if (to_import)
-    import_dialog_add_account (data);
-
-  import_dialog_account_data_free (data);
-  return FALSE;
+  gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 static void
-import_dialog_free (EmpathyImportDialog *dialog)
+do_get_property (GObject *object,
+    guint property_id,
+    GValue *value,
+    GParamSpec *pspec)
 {
-  if (dialog->window)
-    gtk_widget_destroy (dialog->window);
-  g_list_free (dialog->accounts);
-  g_slice_free (EmpathyImportDialog, dialog);
+  EmpathyImportDialogPriv *priv = GET_PRIV (object);
+
+  switch (property_id)
+    {
+    case PROP_PARENT:
+      g_value_set_object (value, priv->parent_window);
+      break;
+    case PROP_SHOW_WARNING:
+      g_value_set_boolean (value, priv->show_warning);
+      break;
+    case PROP_CMS:
+      g_value_set_object (value, priv->cms);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
 }
 
 static void
-import_dialog_button_ok_clicked_cb (GtkButton *button,
-                                    EmpathyImportDialog *dialog)
+do_set_property (GObject *object,
+    guint property_id,
+    const GValue *value,
+    GParamSpec *pspec)
 {
-  GtkTreeModel *model;
+  EmpathyImportDialogPriv *priv = GET_PRIV (object);
 
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
-  gtk_tree_model_foreach (model, import_dialog_tree_model_foreach, dialog);
-  import_dialog_free (dialog);
+  switch (property_id)
+    {
+    case PROP_PARENT:
+      priv->parent_window = g_value_get_object (value);
+      break;
+    case PROP_SHOW_WARNING:
+      priv->show_warning = g_value_get_boolean (value);
+      break;
+    case PROP_CMS:
+      priv->cms = g_value_dup_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
 }
 
 static void
-import_dialog_button_cancel_clicked_cb (GtkButton *button,
-                                        EmpathyImportDialog *dialog)
+do_constructed (GObject *obj)
 {
-  import_dialog_free (dialog);
-}
+  EmpathyImportDialog *self = EMPATHY_IMPORT_DIALOG (obj);
+  EmpathyImportDialogPriv *priv = GET_PRIV (self);
+  gboolean have_accounts;
 
-static gboolean
-import_dialog_account_id_in_list (GList *accounts,
-                                  const gchar *account_id)
-{
-  GList *l;
+  have_accounts = empathy_import_accounts_to_import ();
 
-  for (l = accounts; l; l = l->next)
+  if (!have_accounts)
     {
-      McAccount *account = l->data;
-      gchar *value;
-      gboolean result;
-
-      if (mc_account_get_param_string (account, "account", &value)
-          == MC_ACCOUNT_SETTING_ABSENT)
-        continue;
-
-      result = tp_strdiff (value, account_id);
-
-      g_free (value);
-
-      if (!result)
-        return TRUE;
+      if (priv->show_warning)
+        {
+          import_dialog_show_warning_message (self);
+        }
+      else
+        DEBUG ("No accounts to import; closing dialog silently.");
+    }
+  else
+    {
+      import_dialog_add_import_widget (self);
     }
 
-  return FALSE;
+  if (priv->parent_window)
+    gtk_window_set_transient_for (GTK_WINDOW (self), priv->parent_window);
 }
 
 static void
-import_dialog_add_accounts_to_model (EmpathyImportDialog *dialog)
+empathy_import_dialog_init (EmpathyImportDialog *self)
 {
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GList *account;
-
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
-
-  for (account = dialog->accounts; account; account = account->next)
-    {
-      GValue *value;
-      AccountData *data = (AccountData *) account->data;
-      gboolean import;
-      GList *accounts;
-
-      value = g_hash_table_lookup (data->settings, "account");
+  EmpathyImportDialogPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+      EMPATHY_TYPE_IMPORT_DIALOG, EmpathyImportDialogPriv);
 
-      accounts = mc_accounts_list_by_profile (data->profile);
+  self->priv = priv;
 
-      /* Only set the "Import" cell to be active if there isn't already an
-       * account set up with the same account id. */
-      import = !import_dialog_account_id_in_list (accounts,
-          g_value_get_string (value));
-
-      mc_accounts_list_free (accounts);
-
-      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-
-      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-          COL_IMPORT, import,
-          COL_PROTOCOL, mc_profile_get_display_name (data->profile),
-          COL_NAME, g_value_get_string (value),
-          COL_SOURCE, "Pidgin",
-          COL_ACCOUNT_DATA, data,
-          -1);
-    }
+  gtk_container_set_border_width (GTK_CONTAINER (self), 5);
+  gtk_window_set_title (GTK_WINDOW (self), _("Import Accounts"));
+  gtk_window_set_modal (GTK_WINDOW (self), TRUE);
 }
-
 static void
-import_dialog_cell_toggled_cb (GtkCellRendererToggle *cell_renderer,
-                               const gchar *path_str,
-                               EmpathyImportDialog *dialog)
+do_dispose (GObject *obj)
 {
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GtkTreePath *path;
-
-  path = gtk_tree_path_new_from_string (path_str);
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
-
-  gtk_tree_model_get_iter (model, &iter, path);
+  EmpathyImportDialogPriv *priv = GET_PRIV (obj);
 
-  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-      COL_IMPORT, !gtk_cell_renderer_toggle_get_active (cell_renderer),
-      -1);
+  g_clear_object (&priv->cms);
 
-  gtk_tree_path_free (path);
+  G_OBJECT_CLASS (empathy_import_dialog_parent_class)->dispose (obj);
 }
 
 static void
-import_dialog_set_up_account_list (EmpathyImportDialog *dialog)
+empathy_import_dialog_class_init (EmpathyImportDialogClass *klass)
 {
-  GtkListStore *store;
-  GtkTreeView *view;
-  GtkTreeViewColumn *column;
-  GtkCellRenderer *cell;
-
-  store = gtk_list_store_new (COL_COUNT, G_TYPE_BOOLEAN, G_TYPE_STRING,
-      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
-
-  gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
-      GTK_TREE_MODEL (store));
-
-  g_object_unref (store);
-
-  view = GTK_TREE_VIEW (dialog->treeview);
-  gtk_tree_view_set_headers_visible (view, TRUE);
-
-  /* Import column */
-  cell = gtk_cell_renderer_toggle_new ();
-  gtk_tree_view_insert_column_with_attributes (view, -1,
-      _("Import"), cell,
-      "active", COL_IMPORT,
-      NULL);
-
-  g_signal_connect (cell, "toggled",
-      G_CALLBACK (import_dialog_cell_toggled_cb), dialog);
-
-  /* Protocol column */
-  column = gtk_tree_view_column_new ();
-  gtk_tree_view_column_set_title (column, _("Protocol"));
-  gtk_tree_view_column_set_expand (column, TRUE);
-  gtk_tree_view_append_column (view, column);
-
-  cell = gtk_cell_renderer_text_new ();
-  g_object_set (cell,
-      "editable", FALSE,
-      NULL);
-  gtk_tree_view_column_pack_start (column, cell, TRUE);
-  gtk_tree_view_column_add_attribute (column, cell, "text", COL_PROTOCOL);
-
-  /* Account column */
-  column = gtk_tree_view_column_new ();
-  gtk_tree_view_column_set_title (column, _("Account"));
-  gtk_tree_view_column_set_expand (column, TRUE);
-  gtk_tree_view_append_column (view, column);
-
-  cell = gtk_cell_renderer_text_new ();
-  g_object_set (cell,
-      "editable", FALSE,
-      NULL);
-  gtk_tree_view_column_pack_start (column, cell, TRUE);
-  gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
-
-  /* Source column */
-  column = gtk_tree_view_column_new ();
-  gtk_tree_view_column_set_title (column, _("Source"));
-  gtk_tree_view_column_set_expand (column, TRUE);
-  gtk_tree_view_append_column (view, column);
-
-  cell = gtk_cell_renderer_text_new ();
-  g_object_set (cell,
-      "editable", FALSE,
-      NULL);
-  gtk_tree_view_column_pack_start (column, cell, TRUE);
-  gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE);
-
-  import_dialog_add_accounts_to_model (dialog);
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+  GtkDialogClass *gtkclass = GTK_DIALOG_CLASS (klass);
+  GParamSpec *param_spec;
+
+  oclass->constructed = do_constructed;
+  oclass->get_property = do_get_property;
+  oclass->set_property = do_set_property;
+  oclass->dispose = do_dispose;
+
+  gtkclass->response = impl_signal_response;
+
+  param_spec = g_param_spec_object ("parent-window",
+      "parent-window", "The parent window",
+      GTK_TYPE_WINDOW,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (oclass, PROP_PARENT, param_spec);
+
+  param_spec = g_param_spec_boolean ("show-warning",
+      "show-warning", "Whether a warning should be shown when there are no "
+       "sources for importing accounts.",
+      FALSE,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (oclass, PROP_SHOW_WARNING, param_spec);
+
+  param_spec = g_param_spec_object ("cms",
+      "TpawConnectionManagers", "EmpathyConnectionManager",
+      TPAW_TYPE_CONNECTION_MANAGERS,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (oclass, PROP_CMS, param_spec);
+
+  g_type_class_add_private (klass, sizeof (EmpathyImportDialogPriv));
 }
 
-void
-empathy_import_dialog_show (GtkWindow *parent,
-                            gboolean warning)
+GtkWidget *
+empathy_import_dialog_new (GtkWindow *parent,
+    gboolean warning,
+    TpawConnectionManagers *cms)
 {
-  static EmpathyImportDialog *dialog = NULL;
-  GladeXML *glade;
-  gchar *filename;
-
-  if (dialog)
-    {
-      gtk_window_present (GTK_WINDOW (dialog->window));
-      return;
-    }
-
-  dialog = g_slice_new0 (EmpathyImportDialog);
-
-  dialog->accounts = import_dialog_pidgin_load ();
-
-  if (!dialog->accounts)
-    {
-      GtkWidget *message;
-
-      if (warning)
-        {
-          message = gtk_message_dialog_new (parent,
-              GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
-              _("No accounts to import could be found. Empathy currently only "
-                "supports importing accounts from Pidgin."));
-
-          gtk_dialog_run (GTK_DIALOG (message));
-          gtk_widget_destroy (message);
-        }
-      else
-        DEBUG ("No accounts to import; closing dialog silently.");
-
-      import_dialog_free (dialog);
-      dialog = NULL;
-      return;
-    }
+  g_return_val_if_fail (TPAW_IS_CONNECTION_MANAGERS (cms), NULL);
 
-  filename = empathy_file_lookup ("empathy-import-dialog.glade", "src");
-  glade = empathy_glade_get_file (filename,
-      "import_dialog",
-      NULL,
-      "import_dialog", &dialog->window,
-      "treeview", &dialog->treeview,
+  return g_object_new (EMPATHY_TYPE_IMPORT_DIALOG,
+      "parent-window", parent,
+      "show-warning", warning,
+      "cms", cms,
       NULL);
-
-  empathy_glade_connect (glade,
-      dialog,
-      "button_ok", "clicked", import_dialog_button_ok_clicked_cb,
-      "button_cancel", "clicked", import_dialog_button_cancel_clicked_cb,
-      NULL);
-
-  g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
-
-  g_free (filename);
-  g_object_unref (glade);
-
-  if (parent)
-    gtk_window_set_transient_for (GTK_WINDOW (dialog->window), parent);
-
-  import_dialog_set_up_account_list (dialog);
-
-  gtk_widget_show (dialog->window);
 }