[empathy] Move protocol_is_supported() to empathy-import-utils



commit 3ee3162a25751ce528cf84661b2d515820b15cfb
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 14 12:08:59 2009 +0200

    Move protocol_is_supported() to empathy-import-utils

 src/empathy-import-utils.c  |   44 +++++++++++++++++++++++++++++++++++++++++++
 src/empathy-import-utils.h  |    4 +++
 src/empathy-import-widget.c |   31 ++++-------------------------
 3 files changed, 53 insertions(+), 26 deletions(-)
---
diff --git a/src/empathy-import-utils.c b/src/empathy-import-utils.c
index f84b206..520f056 100644
--- a/src/empathy-import-utils.c
+++ b/src/empathy-import-utils.c
@@ -21,6 +21,7 @@
 
 #include <telepathy-glib/util.h>
 
+#include <libempathy/empathy-connection-managers.h>
 #include <libempathy/empathy-utils.h>
 
 #include "empathy-import-utils.h"
@@ -74,3 +75,46 @@ empathy_import_accounts_load (EmpathyImportApplication id)
 
   return empathy_import_pidgin_load ();
 }
+
+gboolean
+empathy_import_protocol_is_supported (const gchar *protocol,
+    TpConnectionManager **cm)
+{
+  EmpathyConnectionManagers *manager;
+  GList *cms;
+  GList *l;
+  gboolean proto_is_supported = FALSE;
+
+  manager = empathy_connection_managers_dup_singleton ();
+  cms = empathy_connection_managers_get_cms (manager);
+
+  for (l = cms; l; l = l->next)
+    {
+
+      TpConnectionManager *tp_cm = l->data;
+      if (tp_connection_manager_has_protocol (tp_cm,
+          (const gchar*) protocol))
+        {
+          if (!proto_is_supported)
+            {
+              *cm = tp_cm;
+              proto_is_supported = TRUE;
+
+              continue;
+            }
+
+          /* we have more than one CM for this protocol,
+           * select the one which is not haze.
+           */
+          if (!tp_strdiff ((*cm)->name, "haze"))
+            {
+              *cm = tp_cm;
+              break;
+            }
+        }
+    }
+
+  g_object_unref (manager);
+
+  return proto_is_supported;
+}
diff --git a/src/empathy-import-utils.h b/src/empathy-import-utils.h
index 8c971a0..20af25a 100644
--- a/src/empathy-import-utils.h
+++ b/src/empathy-import-utils.h
@@ -22,6 +22,7 @@
 #ifndef __EMPATHY_IMPORT_UTILS_H__
 #define __EMPATHY_IMPORT_UTILS_H__
 
+#include <telepathy-glib/connection-manager.h>
 #include <glib.h>
 
 G_BEGIN_DECLS
@@ -51,6 +52,9 @@ void empathy_import_account_data_free (EmpathyImportAccountData *data);
 gboolean empathy_import_accounts_to_import (void);
 GList *empathy_import_accounts_load (EmpathyImportApplication id);
 
+gboolean empathy_import_protocol_is_supported (const gchar *protocol,
+    TpConnectionManager **cm);
+
 G_END_DECLS
 
 #endif /* __EMPATHY_IMPORT_UTILS_H__ */
diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c
index 17f1962..34f94e5 100644
--- a/src/empathy-import-widget.c
+++ b/src/empathy-import-widget.c
@@ -101,31 +101,6 @@ import_widget_account_id_in_list (GList *accounts,
   return FALSE;
 }
 
-static gboolean
-protocol_is_supported (EmpathyImportWidget *self,
-    EmpathyImportAccountData *data)
-{
-  EmpathyImportWidgetPriv *priv = GET_PRIV (self);
-  GList *cms = empathy_connection_managers_get_cms (priv->cms);
-  GList *l;
-  gboolean proto_is_supported = FALSE;
-
-  for (l = cms; l; l = l->next)
-    {
-      TpConnectionManager *tp_cm = l->data;
-      const gchar *cm_name = tp_connection_manager_get_name (tp_cm);
-      if (tp_connection_manager_has_protocol (tp_cm,
-          (const gchar*) data->protocol))
-        {
-          data->connection_manager = g_strdup (cm_name);
-          proto_is_supported = TRUE;
-          break;
-        }
-    }
-
-  return proto_is_supported;
-}
-
 static void
 import_widget_add_accounts_to_model (EmpathyImportWidget *self)
 {
@@ -143,10 +118,14 @@ import_widget_add_accounts_to_model (EmpathyImportWidget *self)
       EmpathyImportAccountData *data = l->data;
       gboolean import;
       GList *accounts;
+      TpConnectionManager *cm = NULL;
 
-      if (!protocol_is_supported (self, data))
+      if (!empathy_import_protocol_is_supported (data->protocol, &cm))
         continue;
 
+      data->connection_manager = g_strdup (
+          tp_connection_manager_get_name (cm));
+
       value = g_hash_table_lookup (data->settings, "account");
 
       accounts = empathy_account_manager_dup_accounts (manager);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]