[telepathy-gabble/master] search-manager: use the server's JUD if no Server has been specified

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Wed Aug 26 09:22:06 PDT 2009


---
 src/search-manager.c |   66 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/src/search-manager.c b/src/search-manager.c
index 09117f7..18d3dd9 100644
--- a/src/search-manager.c
+++ b/src/search-manager.c
@@ -32,7 +32,9 @@
 #include "caps-channel-manager.h"
 #include "connection.h"
 #include "debug.h"
+#include "disco.h"
 #include "search-channel.h"
+#include "util.h"
 
 static void channel_manager_iface_init (gpointer, gpointer);
 static void caps_channel_manager_iface_init (gpointer, gpointer);
@@ -61,6 +63,8 @@ struct _GabbleSearchManagerPrivate
    */
   GHashTable *channels;
 
+  gchar *default_jud;
+
   gboolean dispose_has_run;
 };
 
@@ -94,15 +98,43 @@ gabble_search_manager_close_all (GabbleSearchManager *self)
 }
 
 static void
+disco_item_found_cb (GabbleDisco *disco,
+    GabbleDiscoItem *item,
+    GabbleSearchManager *self)
+{
+  if (tp_strdiff (item->category, "directory") ||
+      tp_strdiff (item->type, "user"))
+    return;
+
+  DEBUG ("Found contact directory: %s\n", item->jid);
+  g_free (self->priv->default_jud);
+  self->priv->default_jud = g_strdup (item->jid);
+}
+
+static void
 connection_status_changed_cb (GabbleConnection *conn,
                               guint status,
                               guint reason,
                               GabbleSearchManager *self)
 {
-  if (status != TP_CONNECTION_STATUS_DISCONNECTED)
-    return;
-
-  gabble_search_manager_close_all (self);
+  switch (status)
+    {
+      case TP_CONNECTION_STATUS_CONNECTING:
+        /* Track Search server available on the connection.
+         *
+         * The GabbleDisco object is created after the channel manager so we
+         * can connect this signal in our constructor. */
+        gabble_signal_connect_weak (self->priv->conn->disco, "item-found",
+            G_CALLBACK (disco_item_found_cb), G_OBJECT (self));
+        break;
+
+      case TP_CONNECTION_STATUS_DISCONNECTED:
+        gabble_search_manager_close_all (self);
+        break;
+
+      default:
+        return;
+    }
 }
 
 static GObject *
@@ -139,6 +171,18 @@ gabble_search_manager_dispose (GObject *object)
 }
 
 static void
+gabble_search_manager_finalize (GObject *object)
+{
+  GabbleSearchManager *fac = GABBLE_SEARCH_MANAGER (object);
+  GabbleSearchManagerPrivate *priv = fac->priv;
+
+  g_free (priv->default_jud);
+
+  if (G_OBJECT_CLASS (gabble_search_manager_parent_class)->finalize)
+    G_OBJECT_CLASS (gabble_search_manager_parent_class)->finalize (object);
+}
+
+static void
 gabble_search_manager_get_property (GObject *object,
                                     guint property_id,
                                     GValue *value,
@@ -185,6 +229,7 @@ gabble_search_manager_class_init (GabbleSearchManagerClass *klass)
 
   object_class->constructor = gabble_search_manager_constructor;
   object_class->dispose = gabble_search_manager_dispose;
+  object_class->finalize = gabble_search_manager_finalize;
 
   object_class->get_property = gabble_search_manager_get_property;
   object_class->set_property = gabble_search_manager_set_property;
@@ -368,9 +413,16 @@ gabble_search_manager_create_channel (TpChannelManager *manager,
 
   if (server == NULL)
     {
-      error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
-          "Server must be specified; default not yet implemented");
-      goto error;
+      if (self->priv->default_jud == NULL)
+        {
+          error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+              "No Server has been specified and no server has been discovered "
+              "on the connection");
+          goto error;
+        }
+
+      DEBUG ("No Server specified; use %s as default", self->priv->default_jud);
+      server = self->priv->default_jud;
     }
 
   new_search_channel (self, server, request_token);
-- 
1.5.6.5




More information about the telepathy-commits mailing list