]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-group.c
Add empathy_tp_chat_get_connection() to direct access the channel's connection.
[empathy.git] / libempathy / empathy-tp-group.c
index ef6697de4cb573e9741fcb1fe4babe8d57ccfb77..c3471c1578c432c721667ba7929a7fd4cbfd336b 100644 (file)
 
 #include <config.h>
 
-#include <telepathy-glib/channel.h>
+#include <libmissioncontrol/mc-account.h>
+
 #include <telepathy-glib/util.h>
 #include <telepathy-glib/interfaces.h>
 
 #include "empathy-tp-group.h"
 #include "empathy-contact-factory.h"
-#include "empathy-debug.h"
 #include "empathy-utils.h"
 #include "empathy-marshal.h"
 
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
-                      EMPATHY_TYPE_TP_GROUP, EmpathyTpGroupPriv))
-
-#define DEBUG_DOMAIN "TpGroup"
+#define DEBUG_FLAG EMPATHY_DEBUG_TP
+#include "empathy-debug.h"
 
-struct _EmpathyTpGroupPriv {
-       McAccount             *account;
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpGroup)
+typedef struct {
        TpChannel             *channel;
        gboolean               ready;
 
        EmpathyContactFactory *factory;
+       McAccount             *account;
        gchar                 *group_name;
        guint                  self_handle;
        GList                 *members;
        GList                 *local_pendings;
        GList                 *remote_pendings;
-};
-
-static void empathy_tp_group_class_init (EmpathyTpGroupClass *klass);
-static void empathy_tp_group_init       (EmpathyTpGroup      *group);
+} EmpathyTpGroupPriv;
 
 enum {
        MEMBER_ADDED,
@@ -64,7 +60,6 @@ enum {
 
 enum {
        PROP_0,
-       PROP_ACCOUNT,
        PROP_CHANNEL,
        PROP_READY
 };
@@ -209,18 +204,17 @@ tp_group_update_members (EmpathyTpGroup *group,
 
        actor_contact = tp_group_get_contact (group, actor);
 
-       empathy_debug (DEBUG_DOMAIN, "Members changed for list %s:\n"
-                                    "  added-len=%d, current-len=%d\n"
-                                    "  removed-len=%d\n"
-                                    "  local-pending-len=%d, current-len=%d\n"
-                                    "  remote-pending-len=%d, current-len=%d",
-                      priv->group_name,
-                      added ? added->len : 0, g_list_length (priv->members),
-                      removed ? removed->len : 0,
-                      local_pending ? local_pending->len : 0,
-                      g_list_length (priv->local_pendings),
-                      remote_pending ? remote_pending->len : 0,
-                      g_list_length (priv->remote_pendings));
+       DEBUG ("Members changed for list %s:\n"
+               "  added-len=%d, current-len=%d\n"
+               "  removed-len=%d\n"
+               "  local-pending-len=%d, current-len=%d\n"
+               "  remote-pending-len=%d, current-len=%d",
+               priv->group_name, added ? added->len : 0,
+               g_list_length (priv->members), removed ? removed->len : 0,
+               local_pending ? local_pending->len : 0,
+               g_list_length (priv->local_pendings),
+               remote_pending ? remote_pending->len : 0,
+               g_list_length (priv->remote_pendings));
 
        /* Contacts added */
        contacts = tp_group_get_contacts (group, added);
@@ -292,14 +286,13 @@ tp_group_update_members (EmpathyTpGroup *group,
                g_object_unref (actor_contact);
        }
 
-       empathy_debug (DEBUG_DOMAIN, "Members changed done for list %s:\n"
-                                    "  members-len=%d\n"
-                                    "  local-pendings-len=%d\n"
-                                    "  remote-pendings-len=%d",
-                      priv->group_name,
-                      g_list_length (priv->members),
-                      g_list_length (priv->local_pendings),
-                      g_list_length (priv->remote_pendings));
+       DEBUG ("Members changed done for list %s:\n"
+               "  members-len=%d\n"
+               "  local-pendings-len=%d\n"
+               "  remote-pendings-len=%d",
+               priv->group_name, g_list_length (priv->members),
+               g_list_length (priv->local_pendings),
+               g_list_length (priv->remote_pendings));
 }
 
 static void
@@ -334,8 +327,7 @@ tp_group_get_members_cb (TpChannel    *channel,
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
 
        if (error) {
-               empathy_debug (DEBUG_DOMAIN, "Failed to get members: %s",
-                              error->message);
+               DEBUG ("Failed to get members: %s", error->message);
                return;
        }
 
@@ -348,7 +340,7 @@ tp_group_get_members_cb (TpChannel    *channel,
                                 0,       /* actor */
                                 0);      /* reason */
 
-       empathy_debug (DEBUG_DOMAIN, "Ready");
+       DEBUG ("Ready");
        priv->ready = TRUE;
        g_object_notify (group, "ready");
 }
@@ -364,8 +356,7 @@ tp_group_get_local_pending_cb (TpChannel        *channel,
        guint   i = 0;
        
        if (error) {
-               empathy_debug (DEBUG_DOMAIN, "Failed to get local pendings: %s",
-                              error->message);
+               DEBUG ("Failed to get local pendings: %s", error->message);
                return;
        }
 
@@ -406,8 +397,7 @@ tp_group_get_remote_pending_cb (TpChannel    *channel,
                                GObject      *group)
 {
        if (error) {
-               empathy_debug (DEBUG_DOMAIN, "Failed to get remote pendings: %s",
-                              error->message);
+               DEBUG ("Failed to get remote pendings: %s", error->message);
                return;
        }
 
@@ -431,8 +421,7 @@ tp_group_inspect_handles_cb (TpConnection  *connection,
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
 
        if (error) {
-               empathy_debug (DEBUG_DOMAIN, "Failed to inspect channel handle: %s",
-                              error->message);
+               DEBUG ("Failed to inspect channel handle: %s", error->message);
                return;
        }
 
@@ -446,7 +435,7 @@ tp_group_invalidated_cb (TpProxy        *proxy,
                         gchar          *message,
                         EmpathyTpGroup *group)
 {
-       empathy_debug (DEBUG_DOMAIN, "Channel invalidated: %s", message);
+       DEBUG ("Channel invalidated: %s", message);
        g_signal_emit (group, signals[DESTROY], 0);
 }
 
@@ -464,8 +453,7 @@ tp_group_get_self_handle_cb (TpChannel    *proxy,
        GArray             *handles;
 
        if (error) {
-               empathy_debug (DEBUG_DOMAIN, "Failed to get self handle: %s",
-                              error->message);
+               DEBUG ("Failed to get self handle: %s", error->message);
                return;
        }
 
@@ -545,7 +533,7 @@ tp_group_finalize (GObject *object)
        EmpathyTpGroupPriv      *priv = GET_PRIV (object);
        EmpathyTpContactFactory *tp_factory;
 
-       empathy_debug (DEBUG_DOMAIN, "finalize: %p", object);
+       DEBUG ("finalize: %p", object);
 
        tp_factory = empathy_contact_factory_get_tp_factory (priv->factory, priv->account);
        g_signal_handlers_disconnect_by_func (tp_factory, tp_group_factory_ready_cb, object);
@@ -582,7 +570,8 @@ tp_group_constructed (GObject *group)
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
        gboolean            channel_ready;
 
-       priv->factory = empathy_contact_factory_new ();
+       priv->factory = empathy_contact_factory_dup_singleton ();
+       priv->account = empathy_channel_get_account (priv->channel);
 
        g_signal_connect (priv->channel, "invalidated",
                          G_CALLBACK (tp_group_invalidated_cb),
@@ -607,9 +596,6 @@ tp_group_get_property (GObject    *object,
        EmpathyTpGroupPriv *priv = GET_PRIV (object);
 
        switch (param_id) {
-       case PROP_ACCOUNT:
-               g_value_set_object (value, priv->account);
-               break;
        case PROP_CHANNEL:
                g_value_set_object (value, priv->channel);
                break;
@@ -631,9 +617,6 @@ tp_group_set_property (GObject      *object,
        EmpathyTpGroupPriv *priv = GET_PRIV (object);
 
        switch (param_id) {
-       case PROP_ACCOUNT:
-               priv->account = g_object_ref (g_value_get_object (value));
-               break;
        case PROP_CHANNEL:
                priv->channel = g_object_ref (g_value_get_object (value));
                break;
@@ -653,14 +636,6 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
        object_class->get_property = tp_group_get_property;
        object_class->set_property = tp_group_set_property;
 
-       g_object_class_install_property (object_class,
-                                        PROP_ACCOUNT,
-                                        g_param_spec_object ("account",
-                                                             "channel Account",
-                                                             "The account associated with the channel",
-                                                             MC_TYPE_ACCOUNT,
-                                                             G_PARAM_READWRITE |
-                                                             G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
                                         PROP_CHANNEL,
                                         g_param_spec_object ("channel",
@@ -733,18 +708,18 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
 static void
 empathy_tp_group_init (EmpathyTpGroup *group)
 {
+       EmpathyTpGroupPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (group,
+               EMPATHY_TYPE_TP_GROUP, EmpathyTpGroupPriv);
+
+       group->priv = priv;
 }
 
 EmpathyTpGroup *
-empathy_tp_group_new (McAccount *account,
-                     TpChannel *channel)
+empathy_tp_group_new (TpChannel *channel)
 {
-       g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
        g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
 
-
        return g_object_new (EMPATHY_TYPE_TP_GROUP, 
-                            "account", account,
                             "channel", channel,
                             NULL);
 }
@@ -755,10 +730,8 @@ tp_group_async_cb (TpChannel    *channel,
                   gpointer      user_data,
                   GObject      *weak_object)
 {
-       const gchar *msg = user_data;
-
        if (error) {
-               empathy_debug (DEBUG_DOMAIN, "%s: %s", msg, error->message);
+               DEBUG ("%s: %s", (gchar*) user_data, error->message);
        }
 }
 
@@ -975,17 +948,34 @@ empathy_tp_group_get_invitation (EmpathyTpGroup  *group,
                }
        }
 
-       if (invitation && priv->members && !priv->members->next) {
-               contact = priv->members->data;
+       if (invitation) {
+               contact = invitation->actor;
        }
-       if (!invitation && priv->remote_pendings && !priv->remote_pendings->next) {
-               contact = priv->remote_pendings->data;
+       if (!invitation) {
+               if (priv->remote_pendings) {
+                       contact = priv->remote_pendings->data;
+               }
+               else if (priv->members) {
+                       contact = priv->members->data;
+               }
        }
 
-       if (remote_contact) {
-               *remote_contact = contact;
+       if (remote_contact && contact) {
+               *remote_contact = g_object_ref (contact);
        }
 
        return invitation;
 }
 
+TpChannelGroupFlags
+empathy_tp_group_get_flags (EmpathyTpGroup *self)
+{
+       EmpathyTpGroupPriv *priv = GET_PRIV (self);
+
+       g_return_val_if_fail (EMPATHY_IS_TP_GROUP (self), 0);
+
+       if (priv->channel == NULL)
+               return 0;
+
+       return tp_channel_group_get_flags (priv->channel);
+}