]> 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 f5cbb70815dfde87fe3e472cab44ff6b5516d63d..c3471c1578c432c721667ba7929a7fd4cbfd336b 100644 (file)
 
 #include <libmissioncontrol/mc-account.h>
 
-#include <telepathy-glib/channel.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 {
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpGroup)
+typedef struct {
        TpChannel             *channel;
        gboolean               ready;
 
@@ -50,10 +47,7 @@ struct _EmpathyTpGroupPriv {
        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,
@@ -210,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);
@@ -293,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
@@ -335,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;
        }
 
@@ -349,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");
 }
@@ -365,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;
        }
 
@@ -407,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;
        }
 
@@ -432,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;
        }
 
@@ -447,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);
 }
 
@@ -465,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;
        }
 
@@ -546,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);
@@ -583,7 +570,7 @@ 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",
@@ -721,6 +708,10 @@ 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 *
@@ -739,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);
        }
 }
 
@@ -959,11 +948,16 @@ 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 && contact) {
@@ -973,3 +967,15 @@ empathy_tp_group_get_invitation (EmpathyTpGroup  *group,
        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);
+}