]> git.0d.be Git - empathy.git/blobdiff - libempathy/gossip-contact.c
sv.po: Updated Swedish translation
[empathy.git] / libempathy / gossip-contact.c
index f198254372c0005ec64da4b05b153e3ff5e82d1e..ba97fa758e99b2c9ea3d8ca13a076c0fe62fd5f5 100644 (file)
@@ -46,6 +46,7 @@ struct _GossipContactPriv {
        GList              *groups;
        GossipSubscription  subscription;
        guint               handle;
+       gboolean            is_user;
 };
 
 static void contact_class_init    (GossipContactClass *class);
@@ -69,7 +70,8 @@ enum {
        PROP_PRESENCE,
        PROP_GROUPS,
        PROP_SUBSCRIPTION,
-       PROP_HANDLE
+       PROP_HANDLE,
+       PROP_IS_USER
 };
 
 static gpointer parent_class = NULL;
@@ -179,6 +181,13 @@ contact_class_init (GossipContactClass *class)
                                                            G_MAXUINT,
                                                            0,
                                                            G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_IS_USER,
+                                        g_param_spec_boolean ("is-user",
+                                                              "Contact is-user",
+                                                              "Is contact the user",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
 
        g_type_class_add_private (object_class, sizeof (GossipContactPriv));
 }
@@ -186,17 +195,6 @@ contact_class_init (GossipContactClass *class)
 static void
 contact_init (GossipContact *contact)
 {
-       GossipContactPriv *priv;
-
-       priv = GET_PRIV (contact);
-
-       priv->id       = NULL;
-       priv->name     = NULL;
-       priv->avatar   = NULL;
-       priv->account  = NULL;
-       priv->presence = NULL;
-       priv->groups   = NULL;
-       priv->handle   = 0;
 }
 
 static void
@@ -268,6 +266,9 @@ contact_get_property (GObject    *object,
        case PROP_HANDLE:
                g_value_set_uint (value, priv->handle);
                break;
+       case PROP_IS_USER:
+               g_value_set_boolean (value, priv->is_user);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -317,6 +318,10 @@ contact_set_property (GObject      *object,
                gossip_contact_set_handle (GOSSIP_CONTACT (object),
                                           g_value_get_uint (value));
                break;
+       case PROP_IS_USER:
+               gossip_contact_set_is_user (GOSSIP_CONTACT (object),
+                                           g_value_get_boolean (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -332,9 +337,9 @@ gossip_contact_new (McAccount *account)
 }
 
 GossipContact *
-gossip_contact_new_full (McAccount *account,
-                        const gchar   *id,
-                        const gchar   *name)
+gossip_contact_new_full (McAccount   *account,
+                        const gchar *id,
+                        const gchar *name)
 {
        return g_object_new (GOSSIP_TYPE_CONTACT,
                             "account", account,
@@ -368,7 +373,7 @@ gossip_contact_get_name (GossipContact *contact)
 
        priv = GET_PRIV (contact);
 
-       if (priv->name == NULL) {
+       if (G_STR_EMPTY (priv->name)) {
                return gossip_contact_get_id (contact);
        }
 
@@ -448,6 +453,18 @@ gossip_contact_get_handle (GossipContact *contact)
        return priv->handle;
 }
 
+gboolean
+gossip_contact_is_user (GossipContact *contact)
+{
+       GossipContactPriv *priv;
+
+       g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), FALSE);
+
+       priv = GET_PRIV (contact);
+
+       return priv->is_user;
+}
+
 void
 gossip_contact_set_id (GossipContact *contact,
                       const gchar   *id)
@@ -459,6 +476,10 @@ gossip_contact_set_id (GossipContact *contact,
 
        priv = GET_PRIV (contact);
 
+       if (priv->id && strcmp (id, priv->id) == 0) {
+               return;
+       }
+
        g_free (priv->id);
        priv->id = g_strdup (id);
 
@@ -476,6 +497,10 @@ gossip_contact_set_name (GossipContact *contact,
 
        priv = GET_PRIV (contact);
 
+       if (priv->name && strcmp (name, priv->name) == 0) {
+               return;
+       }
+
        g_free (priv->name);
        priv->name = g_strdup (name);
 
@@ -492,6 +517,10 @@ gossip_contact_set_avatar (GossipContact *contact,
 
        priv = GET_PRIV (contact);
 
+       if (priv->avatar == avatar) {
+               return;
+       }
+
        if (priv->avatar) {
                gossip_avatar_unref (priv->avatar);
                priv->avatar = NULL;
@@ -515,6 +544,10 @@ gossip_contact_set_account (GossipContact *contact,
 
        priv = GET_PRIV (contact);
 
+       if (account == priv->account) {
+               return;
+       }
+
        if (priv->account) {
                g_object_unref (priv->account);
        }
@@ -533,6 +566,10 @@ gossip_contact_set_presence (GossipContact  *contact,
 
        priv = GET_PRIV (contact);
 
+       if (presence == priv->presence) {
+               return;
+       }
+
        if (priv->presence) {
                g_object_unref (priv->presence);
                priv->presence = NULL;
@@ -580,6 +617,10 @@ gossip_contact_set_subscription (GossipContact      *contact,
 
        priv = GET_PRIV (contact);
 
+       if (priv->subscription == subscription) {
+               return;
+       }
+
        priv->subscription = subscription;
 
        g_object_notify (G_OBJECT (contact), "subscription");
@@ -591,13 +632,75 @@ gossip_contact_set_handle (GossipContact *contact,
 {
        GossipContactPriv *priv;
 
+       g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+
        priv = GET_PRIV (contact);
 
+       if (priv->handle == handle) {
+               return;
+       }
+
        priv->handle = handle;
 
        g_object_notify (G_OBJECT (contact), "handle");
 }
 
+void
+gossip_contact_set_is_user (GossipContact *contact,
+                           gboolean       is_user)
+{
+       GossipContactPriv *priv;
+
+       g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+
+       priv = GET_PRIV (contact);
+
+       if (priv->is_user == is_user) {
+               return;
+       }
+
+       priv->is_user = is_user;
+
+       g_object_notify (G_OBJECT (contact), "is-user");
+}
+
+void
+gossip_contact_add_group (GossipContact *contact,
+                         const gchar   *group)
+{
+       GossipContactPriv *priv;
+
+       g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+       g_return_if_fail (group != NULL);
+
+       priv = GET_PRIV (contact);
+
+       if (!g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp)) {
+               priv->groups = g_list_prepend (priv->groups, g_strdup (group));
+               g_object_notify (G_OBJECT (contact), "groups");
+       }
+}
+
+void
+gossip_contact_remove_group (GossipContact *contact,
+                            const gchar   *group)
+{
+       GossipContactPriv *priv;
+       GList             *l;
+
+       g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+       g_return_if_fail (group != NULL);
+
+       priv = GET_PRIV (contact);
+
+       l = g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp);
+       if (l) {
+               g_free (l->data);
+               priv->groups = g_list_delete_link (priv->groups, l);
+               g_object_notify (G_OBJECT (contact), "groups");
+       }
+}
+
 gboolean
 gossip_contact_is_online (GossipContact *contact)
 {
@@ -607,7 +710,29 @@ gossip_contact_is_online (GossipContact *contact)
 
        priv = GET_PRIV (contact);
 
-       return (priv->presence != NULL);
+       if (!priv->presence) {
+               return FALSE;
+       }
+
+       return (gossip_presence_get_state (priv->presence) > MC_PRESENCE_OFFLINE);
+}
+
+gboolean
+gossip_contact_is_in_group (GossipContact *contact,
+                           const gchar   *group)
+{
+       GossipContactPriv *priv;
+
+       g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), FALSE);
+       g_return_val_if_fail (!G_STR_EMPTY (group), FALSE);
+
+       priv = GET_PRIV (contact);
+
+       if (g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp)) {
+               return TRUE;
+       }
+
+       return FALSE;
 }
 
 const gchar *
@@ -624,7 +749,7 @@ gossip_contact_get_status (GossipContact *contact)
 
                status = gossip_presence_get_status (priv->presence);
                if (!status) {
-                       GossipPresenceState state;
+                       McPresence state;
 
                        state = gossip_presence_get_state (priv->presence);
                        status = gossip_presence_state_get_default_status (state);
@@ -633,7 +758,7 @@ gossip_contact_get_status (GossipContact *contact)
                return status;
        }
 
-       return _("Offline");
+       return gossip_presence_state_get_default_status (MC_PRESENCE_OFFLINE);
 }
 
 gboolean