]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-group.c
Do not load avatar from cache if token is empty. Fixes bug #517098.
[empathy.git] / libempathy / empathy-tp-group.c
index dbc2d228e07a6f19362ca8b12746fc75476c7c48..c20bf205347ecfec004156adcd34a3bfcf3dc72d 100644 (file)
@@ -3,20 +3,19 @@
  * Copyright (C) 2006 Xavier Claessens <xclaesse@gmail.com>
  * Copyright (C) 2007 Collabora Ltd.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
@@ -358,6 +357,7 @@ tp_group_get_members_cb (DBusGProxy *proxy,
        if (error) {
                empathy_debug (DEBUG_DOMAIN, "Failed to get members: %s",
                               error->message);
+               g_object_unref (group);
                return;
        }
 
@@ -372,6 +372,7 @@ tp_group_get_members_cb (DBusGProxy *proxy,
                                     group);
 
        g_array_free (handles, TRUE);
+       g_object_unref (group);
 }
 
 static void
@@ -383,15 +384,17 @@ tp_group_get_local_pending_cb (DBusGProxy *proxy,
        EmpathyTpGroup     *group = user_data;
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
        GArray             *handles;
-       guint               i;
+       guint               i = 0;
        
        if (error) {
                empathy_debug (DEBUG_DOMAIN, "Failed to get local pendings: %s",
                               error->message);
+               g_object_unref (group);
                return;
        }
 
        handles = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
+       g_array_append_val (handles, i);
        for (i = 0; array->len > i; i++) {
                GValueArray        *pending_struct;
                const gchar        *message;
@@ -405,7 +408,7 @@ tp_group_get_local_pending_cb (DBusGProxy *proxy,
                reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
                message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
 
-               g_array_insert_val (handles, 0, member_handle);
+               g_array_index (handles, guint, 0) = member_handle;
                tp_group_members_changed_cb (priv->group_iface,
                                             message,      /* message */
                                             NULL,         /* added */
@@ -420,6 +423,7 @@ tp_group_get_local_pending_cb (DBusGProxy *proxy,
        }
        g_ptr_array_free (array, TRUE);
        g_array_free (handles, TRUE);
+       g_object_unref (group);
 }
 
 static void
@@ -434,6 +438,7 @@ tp_group_get_remote_pending_cb (DBusGProxy *proxy,
        if (error) {
                empathy_debug (DEBUG_DOMAIN, "Failed to get remote pendings: %s",
                               error->message);
+               g_object_unref (group);
                return;
        }
 
@@ -448,6 +453,7 @@ tp_group_get_remote_pending_cb (DBusGProxy *proxy,
                                     group);
 
        g_array_free (handles, TRUE);
+       g_object_unref (group);
 }
 
 static void
@@ -455,6 +461,8 @@ tp_group_finalize (GObject *object)
 {
        EmpathyTpGroupPriv *priv = GET_PRIV (object);
 
+       empathy_debug (DEBUG_DOMAIN, "finalize: %p");
+
        tp_group_disconnect (EMPATHY_TP_GROUP (object));
 
        if (priv->tp_chan) {
@@ -493,7 +501,7 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
+                             _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
                              G_TYPE_NONE,
                              4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
 
@@ -503,7 +511,7 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
+                             _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
                              G_TYPE_NONE,
                              4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
 
@@ -513,7 +521,7 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
+                             _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
                              G_TYPE_NONE,
                              4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
 
@@ -523,7 +531,7 @@ empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
+                             _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
                              G_TYPE_NONE,
                              4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
 
@@ -552,13 +560,13 @@ empathy_tp_group_new (McAccount *account,
        EmpathyTpGroup     *group;
        EmpathyTpGroupPriv *priv;
        DBusGProxy         *group_iface;
-       GError             *error;
+       GError             *error = NULL;
 
-       g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
        g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
+       g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
 
        group_iface = tp_chan_get_interface (tp_chan,
-                                            TELEPATHY_CHAN_IFACE_GROUP_QUARK);
+                                            TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);
        g_return_val_if_fail (group_iface != NULL, NULL);
 
        group = g_object_new (EMPATHY_TYPE_TP_GROUP, NULL);
@@ -590,13 +598,13 @@ empathy_tp_group_new (McAccount *account,
 
        tp_chan_iface_group_get_members_async (priv->group_iface,
                                               tp_group_get_members_cb,
-                                              group);
+                                              g_object_ref (group));
        tp_chan_iface_group_get_local_pending_members_with_info_async (priv->group_iface,
                                                                       tp_group_get_local_pending_cb,
-                                                                      group);
+                                                                      g_object_ref (group));
        tp_chan_iface_group_get_remote_pending_members_async (priv->group_iface,
                                                              tp_group_get_remote_pending_cb,
-                                                             group);
+                                                             g_object_ref (group));
 
        return group;
 }
@@ -612,10 +620,12 @@ tp_group_async_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
 }
 
 void
-empathy_tp_group_close  (EmpathyTpGroup *group)
+empathy_tp_group_close (EmpathyTpGroup *group)
 {
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
 
+       g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
+
        tp_chan_close_async (DBUS_G_PROXY (priv->tp_chan),
                             tp_group_async_cb,
                             "Failed to close");
@@ -671,6 +681,9 @@ empathy_tp_group_add_member (EmpathyTpGroup *group,
        GArray             *handles;
        guint               handle;
 
+       g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
+       g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
        handle = empathy_contact_get_handle (contact);
        handles = g_array_new (FALSE, FALSE, sizeof (guint));
        g_array_append_val (handles, handle);
@@ -714,6 +727,9 @@ empathy_tp_group_remove_member (EmpathyTpGroup *group,
        GArray             *handles;
        guint               handle;
 
+       g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
+       g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
        handle = empathy_contact_get_handle (contact);
        handles = g_array_new (FALSE, FALSE, sizeof (guint));
        g_array_append_val (handles, handle);
@@ -732,6 +748,8 @@ empathy_tp_group_get_members (EmpathyTpGroup *group)
 {
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
 
+       g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
+
        g_list_foreach (priv->members, (GFunc) g_object_ref, NULL);
 
        return g_list_copy (priv->members);
@@ -743,6 +761,8 @@ empathy_tp_group_get_local_pendings (EmpathyTpGroup *group)
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
        GList              *pendings = NULL, *l;
 
+       g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
+
        for (l = priv->local_pendings; l; l = l->next) {
                EmpathyPendingInfo *info;
                EmpathyPendingInfo *new_info;
@@ -762,6 +782,8 @@ empathy_tp_group_get_remote_pendings (EmpathyTpGroup *group)
 {
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
 
+       g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
+
        g_list_foreach (priv->remote_pendings, (GFunc) g_object_ref, NULL);
 
        return g_list_copy (priv->remote_pendings);
@@ -812,6 +834,9 @@ empathy_tp_group_is_member (EmpathyTpGroup *group,
 {
        EmpathyTpGroupPriv *priv = GET_PRIV (group);
 
+       g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), FALSE);
+       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
+
        return g_list_find (priv->members, contact) != NULL;
 }