[folks] Add the PersonaStore:can-group-personas property.



commit 88b60ddc8acac40e3c39d3ad3250a1be75199967
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Tue Oct 12 16:59:08 2010 -0700

    Add the PersonaStore:can-group-personas property.
    
    Helps bgo#626179.

 backends/key-file/kf-persona-store.vala         |   12 ++++
 backends/telepathy/lib/tp-lowlevel.c            |   78 +++++++++++++++++++++++
 backends/telepathy/lib/tp-lowlevel.h            |   13 ++++
 backends/telepathy/lib/tpf-persona-store.vala   |   71 +++++++++++++++++++++
 folks/persona-store.vala                        |   11 +++
 tests/telepathy/persona-store-capabilities.vala |   22 +++++++
 6 files changed, 207 insertions(+), 0 deletions(-)
---
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index ee4fc68..a626165 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -78,6 +78,18 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
     }
 
   /**
+   * Whether this PersonaStore can set the groups of { link Folks.Persona}s.
+   *
+   * See { link Folks.PersonaStore.can_group_personas}.
+   *
+   * @since 0.3.1
+   */
+  public override MaybeBool can_group_personas
+    {
+      get { return MaybeBool.FALSE; }
+    }
+
+  /**
    * Whether this PersonaStore can remove { link Folks.Persona}s.
    *
    * See { link Folks.PersonaStore.can_remove_personas}.
diff --git a/backends/telepathy/lib/tp-lowlevel.c b/backends/telepathy/lib/tp-lowlevel.c
index 327fafa..51f99d9 100644
--- a/backends/telepathy/lib/tp-lowlevel.c
+++ b/backends/telepathy/lib/tp-lowlevel.c
@@ -423,6 +423,84 @@ folks_tp_lowlevel_connection_get_contacts_by_id_finish (
 }
 
 static void
+connection_get_requestable_channel_classes_cb (TpProxy *conn,
+    const GValue *value,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
+  gpointer props;
+
+  if (error != NULL)
+    {
+      g_simple_async_result_set_from_error (simple, error);
+    }
+  else
+    {
+      props = g_value_dup_boxed (value);
+      g_simple_async_result_set_op_res_gpointer (simple, props, NULL);
+    }
+
+  g_simple_async_result_complete (simple);
+  g_object_unref (simple);
+}
+
+void
+folks_tp_lowlevel_connection_get_requestable_channel_classes_async (
+    FolksTpLowlevel *tp_lowlevel,
+    TpConnection *conn,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  GSimpleAsyncResult *result;
+
+  result = g_simple_async_result_new (G_OBJECT (conn), callback, user_data,
+      folks_tp_lowlevel_connection_get_requestable_channel_classes_finish);
+
+  tp_cli_dbus_properties_call_get (conn, -1,
+      TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "RequestableChannelClasses",
+      connection_get_requestable_channel_classes_cb, result, NULL,
+      G_OBJECT (conn));
+}
+
+/**
+ * folks_tp_lowlevel_connection_get_requestable_channel_classes_finish:
+ * @tp_lowlevel: a #FolksTpLowlevel
+ * @result: a #GAsyncResult
+ * @error: return location for a #GError, or %NULL
+ *
+ * Retrieve the #TpConnection's RequestableChannelClasses D-Bus property.
+ *
+ * Returns: (transfer full): the boxed property details. Free with
+ * g_boxed_free().
+ */
+GPtrArray *
+folks_tp_lowlevel_connection_get_requestable_channel_classes_finish (
+    FolksTpLowlevel *tp_lowlevel,
+    GAsyncResult *result,
+    GError **error)
+{
+  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+  TpConnection *conn;
+
+  g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), FALSE);
+
+  conn = TP_CONNECTION (g_async_result_get_source_object (result));
+  g_return_val_if_fail (TP_IS_CONNECTION (conn), FALSE);
+
+  if (g_simple_async_result_propagate_error (simple, error))
+    return 0;
+
+  g_return_val_if_fail (g_simple_async_result_is_valid (result,
+      G_OBJECT (conn),
+      folks_tp_lowlevel_connection_get_requestable_channel_classes_finish), 0);
+
+  return g_simple_async_result_get_op_res_gpointer (
+      G_SIMPLE_ASYNC_RESULT (result));
+}
+
+static void
 group_request_channel_cb (
     TpConnection *conn,
     const gchar *object_path,
diff --git a/backends/telepathy/lib/tp-lowlevel.h b/backends/telepathy/lib/tp-lowlevel.h
index d0c7222..d8d09ee 100644
--- a/backends/telepathy/lib/tp-lowlevel.h
+++ b/backends/telepathy/lib/tp-lowlevel.h
@@ -162,6 +162,19 @@ folks_tp_lowlevel_connection_get_contacts_by_id_finish (
     GAsyncResult *result,
     GError **error);
 
+void
+folks_tp_lowlevel_connection_get_requestable_channel_classes_async (
+    FolksTpLowlevel *tp_lowlevel,
+    TpConnection *conn,
+    GAsyncReadyCallback callback,
+    gpointer user_data);
+
+GPtrArray *
+folks_tp_lowlevel_connection_get_requestable_channel_classes_finish (
+    FolksTpLowlevel *tp_lowlevel,
+    GAsyncResult *result,
+    GError **error);
+
 G_END_DECLS
 
 #endif /* FOLKS_TP_LOWLEVEL_H */
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index 5b1ae44..9a68624 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -34,6 +34,15 @@ using Folks;
  */
 public class Tpf.PersonaStore : Folks.PersonaStore
 {
+  /* FIXME: expose the interface strings in the introspected tp-glib bindings
+   */
+  private static string tp_channel_iface = "org.freedesktop.Telepathy.Channel";
+  private static string tp_channel_contact_list_type = tp_channel_iface +
+      ".Type.ContactList";
+  private static string tp_channel_channel_type = tp_channel_iface +
+      ".ChannelType";
+  private static string tp_channel_handle_type = tp_channel_iface +
+      ".TargetHandleType";
   private string[] undisplayed_groups = { "publish", "stored", "subscribe" };
   private static ContactFeature[] contact_features =
       {
@@ -67,6 +76,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
   private Contact self_contact;
   private MaybeBool _can_add_personas = MaybeBool.UNSET;
   private MaybeBool _can_alias_personas = MaybeBool.UNSET;
+  private MaybeBool _can_group_personas = MaybeBool.UNSET;
   private MaybeBool _can_remove_personas = MaybeBool.UNSET;
   private bool _is_prepared = false;
 
@@ -129,6 +139,18 @@ public class Tpf.PersonaStore : Folks.PersonaStore
     }
 
   /**
+   * Whether this PersonaStore can set the groups of { link Folks.Persona}s.
+   *
+   * See { link Folks.PersonaStore.can_group_personas}.
+   *
+   * @since 0.3.1
+   */
+  public override MaybeBool can_group_personas
+    {
+      get { return this._can_group_personas; }
+    }
+
+  /**
    * Whether this PersonaStore can remove { link Folks.Persona}s.
    *
    * See { link Folks.PersonaStore.can_remove_personas}.
@@ -485,6 +507,55 @@ public class Tpf.PersonaStore : Folks.PersonaStore
             this.notify_property ("can-alias-personas");
           });
 
+      this.ll.connection_get_requestable_channel_classes_async.begin (c,
+          (s3, res3) =>
+          {
+            var new_can_group = MaybeBool.FALSE;
+            try
+              {
+                var ll = this.ll;
+                GenericArray<weak void*> v;
+                int i;
+
+                v = ll.connection_get_requestable_channel_classes_async.end (
+                  res3);
+
+                for (i = 0; i < v.length; i++)
+                  {
+                    unowned ValueArray @class = (ValueArray) v.get (i);
+                    var val = @class.get_nth (0);
+                    if (val != null)
+                      {
+                        var props = (HashTable<weak string, weak Value?>)
+                            val.get_boxed ();
+
+                        var channel_type = TelepathyGLib.asv_get_string (props,
+                            tp_channel_channel_type);
+                        bool handle_type_valid;
+                        var handle_type = TelepathyGLib.asv_get_uint32 (props,
+                            tp_channel_handle_type, out handle_type_valid);
+
+                        if ((channel_type == tp_channel_contact_list_type) &&
+                            handle_type_valid &&
+                            (handle_type == HandleType.GROUP))
+                          {
+                            new_can_group = MaybeBool.TRUE;
+                            break;
+                          }
+                      }
+                  }
+              }
+            catch (GLib.Error e3)
+              {
+                GLib.warning ("failed to determine whether we can set " +
+                  "groups on Telepathy account %s: %s",
+                  this.display_name, e3.message);
+              }
+
+            this._can_group_personas = new_can_group;
+            this.notify_property ("can-group-personas");
+          });
+
       this.add_standard_channel (c, "publish");
       this.add_standard_channel (c, "stored");
       this.add_standard_channel (c, "subscribe");
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index 15e7db5..db57909 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -194,6 +194,17 @@ public abstract class Folks.PersonaStore : Object
     }
 
   /**
+   * Whether this { link PersonaStore} can set the groups of { link Persona}s.
+   *
+   * @since 0.3.1
+   */
+  public abstract MaybeBool can_group_personas
+    {
+      get;
+      default = MaybeBool.UNSET;
+    }
+
+  /**
    * Whether this { link PersonaStore} can remove { link Persona}s.
    *
    * @since 0.3.1
diff --git a/tests/telepathy/persona-store-capabilities.vala b/tests/telepathy/persona-store-capabilities.vala
index 8a39e26..da1fa14 100644
--- a/tests/telepathy/persona-store-capabilities.vala
+++ b/tests/telepathy/persona-store-capabilities.vala
@@ -199,6 +199,12 @@ public class PersonaStoreCapabilitiesTests : Folks.TestCase
               else
                 store.notify["can-alias-personas"].connect (
                     this.can_alias_personas_cb);
+
+              if (store.can_group_personas != MaybeBool.UNSET)
+                can_group_personas_cb (store, null);
+              else
+                store.notify["can-group-personas"].connect (
+                    this.can_group_personas_cb);
             }
           catch (GLib.Error e)
             {
@@ -255,6 +261,22 @@ public class PersonaStoreCapabilitiesTests : Folks.TestCase
               this.can_alias_personas_cb);
         }
     }
+
+  private void can_group_personas_cb (GLib.Object s, ParamSpec? p)
+    {
+      assert (s is Tpf.PersonaStore);
+      var store = (Tpf.PersonaStore) s;
+
+      if (store.can_group_personas != MaybeBool.UNSET)
+        {
+          assert (store.can_group_personas == MaybeBool.TRUE);
+
+          this.group_flags_received.add ("can-group-personas");
+
+          store.notify["can-group-personas"].disconnect (
+              this.can_group_personas_cb);
+        }
+    }
 }
 
 public int main (string[] args)



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