]> git.0d.be Git - empathy.git/blobdiff - src/empathy-import-widget.c
add an header bar to the main window
[empathy.git] / src / empathy-import-widget.c
index 041c51003349dc8486134a70cea26f08d58ffaf4..708370bae6ea4e08d1f019ee14635f6b5bee0f48 100644 (file)
 
 /* empathy-import-widget.c */
 
-#include <config.h>
-
-#include "empathy-import-dialog.h"
+#include "config.h"
 #include "empathy-import-widget.h"
-#include "empathy-import-pidgin.h"
-
-#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
-#include <libempathy/empathy-connection-managers.h>
-#include <libempathy/empathy-utils.h>
 
-#include <libempathy-gtk/empathy-ui-utils.h>
+#include <glib/gi18n-lib.h>
+#include <tp-account-widgets/tpaw-builder.h>
+#include <tp-account-widgets/tpaw-utils.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
 
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/util.h>
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
-#include <glib/gi18n-lib.h>
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
 
 G_DEFINE_TYPE (EmpathyImportWidget, empathy_import_widget, G_TYPE_OBJECT)
 
@@ -62,11 +58,12 @@ enum {
 typedef struct {
   GtkWidget *vbox;
   GtkWidget *treeview;
+  GtkWidget *scrolledwindow;
 
   GList *accounts;
   EmpathyImportApplication app_id;
 
-  EmpathyConnectionManagers *cms;
+  TpawConnectionManagers *cms;
 
   gboolean dispose_run;
 } EmpathyImportWidgetPriv;
@@ -91,25 +88,18 @@ import_widget_account_id_in_list (GList *accounts,
   return FALSE;
 }
 
+#define MAX_TREEVIEW_HEIGHT 300
+
 static void
-account_manager_prepared_cb (GObject *source_object,
-    GAsyncResult *result,
-    gpointer user_data)
+import_widget_add_accounts_to_model (EmpathyImportWidget *self)
 {
-  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
-  EmpathyImportWidget *self = user_data;
+  TpAccountManager *manager;
   GtkTreeModel *model;
-  GtkTreeIter iter;
   GList *l;
   EmpathyImportWidgetPriv *priv = GET_PRIV (self);
-  GError *error = NULL;
+  gint min, natural;
 
-  if (!tp_proxy_prepare_finish (manager, result, &error))
-    {
-      DEBUG ("Failed to prepare account manager: %s", error->message);
-      g_error_free (error);
-      return;
-    }
+  manager = tp_account_manager_dup ();
 
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
 
@@ -129,36 +119,29 @@ account_manager_prepared_cb (GObject *source_object,
 
       value = g_hash_table_lookup (data->settings, "account");
 
-      accounts = tp_account_manager_get_valid_accounts (manager);
+      accounts = tp_account_manager_dup_valid_accounts (manager);
 
       /* Only set the "Import" cell to be active if there isn't already an
        * account set up with the same account id. */
       import = !import_widget_account_id_in_list (accounts,
           g_value_get_string (value));
 
-      g_list_free (accounts);
-
-      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+      g_list_free_full (accounts, g_object_unref);
 
-      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+      gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, -1,
           COL_IMPORT, import,
           COL_PROTOCOL, data->protocol,
           COL_NAME, g_value_get_string (value),
           COL_SOURCE, data->source,
           COL_ACCOUNT_DATA, data,
           -1);
-    }
-}
 
-static void
-import_widget_add_accounts_to_model (EmpathyImportWidget *self)
-{
-  TpAccountManager *manager;
-
-  manager = tp_account_manager_dup ();
+    }
 
-  tp_proxy_prepare_async (manager, NULL,
-      account_manager_prepared_cb, self);
+  /* Display as much rows as possible */
+  gtk_widget_get_preferred_height (priv->treeview, &min, &natural);
+  gtk_widget_set_size_request (priv->scrolledwindow, -1,
+      MIN (natural, MAX_TREEVIEW_HEIGHT));
 
   g_object_unref (manager);
 }
@@ -189,7 +172,7 @@ import_widget_create_account_cb (GObject *source,
   if (tp_account_is_enabled (account))
     {
       account_manager = tp_account_manager_dup ();
-      empathy_connect_new_account (account, account_manager);
+      tpaw_connect_new_account (account, account_manager);
       g_object_unref (account_manager);
     }
 
@@ -450,13 +433,14 @@ do_constructed (GObject *obj)
   gchar *filename;
 
   filename = empathy_file_lookup ("empathy-import-dialog.ui", "src");
-  gui = empathy_builder_get_file (filename,
+  gui = tpaw_builder_get_file (filename,
       "widget_vbox", &priv->vbox,
       "treeview", &priv->treeview,
+      "scrolledwindow", &priv->scrolledwindow,
       NULL);
 
   g_free (filename);
-  empathy_builder_unref_and_keep_widget (gui, priv->vbox);
+  tpaw_builder_unref_and_keep_widget (gui, priv->vbox);
 
   g_signal_connect (priv->vbox, "destroy",
       G_CALLBACK (import_widget_destroy_cb), self);
@@ -483,8 +467,8 @@ empathy_import_widget_class_init (EmpathyImportWidgetClass *klass)
   g_object_class_install_property (oclass, PROP_APPLICATION_ID, param_spec);
 
   param_spec = g_param_spec_object ("cms",
-      "EmpathyConnectionManagers", "EmpathyConnectionManager",
-      EMPATHY_TYPE_CONNECTION_MANAGERS,
+      "TpawConnectionManagers", "TpawConnectionManagers",
+      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);
 
@@ -503,9 +487,9 @@ empathy_import_widget_init (EmpathyImportWidget *self)
 
 EmpathyImportWidget *
 empathy_import_widget_new (EmpathyImportApplication id,
-    EmpathyConnectionManagers *cms)
+    TpawConnectionManagers *cms)
 {
-  g_return_val_if_fail (EMPATHY_IS_CONNECTION_MANAGERS (cms), NULL);
+  g_return_val_if_fail (TPAW_IS_CONNECTION_MANAGERS (cms), NULL);
 
   return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET,
       "application-id", id,