GList *groups;
GossipSubscription subscription;
guint handle;
+ gboolean is_user;
};
static void contact_class_init (GossipContactClass *class);
PROP_PRESENCE,
PROP_GROUPS,
PROP_SUBSCRIPTION,
- PROP_HANDLE
+ PROP_HANDLE,
+ PROP_IS_USER
};
static gpointer parent_class = NULL;
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));
}
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
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;
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;
}
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,
priv = GET_PRIV (contact);
- if (priv->name == NULL) {
+ if (G_STR_EMPTY (priv->name)) {
return gossip_contact_get_id (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)
priv = GET_PRIV (contact);
+ if (priv->id && strcmp (id, priv->id) == 0) {
+ return;
+ }
+
g_free (priv->id);
priv->id = g_strdup (id);
priv = GET_PRIV (contact);
+ if (priv->name && strcmp (name, priv->name) == 0) {
+ return;
+ }
+
g_free (priv->name);
priv->name = g_strdup (name);
priv = GET_PRIV (contact);
+ if (priv->avatar == avatar) {
+ return;
+ }
+
if (priv->avatar) {
gossip_avatar_unref (priv->avatar);
priv->avatar = NULL;
priv = GET_PRIV (contact);
+ if (account == priv->account) {
+ return;
+ }
+
if (priv->account) {
g_object_unref (priv->account);
}
priv = GET_PRIV (contact);
+ if (presence == priv->presence) {
+ return;
+ }
+
if (priv->presence) {
g_object_unref (priv->presence);
priv->presence = NULL;
priv = GET_PRIV (contact);
+ if (priv->subscription == subscription) {
+ return;
+ }
+
priv->subscription = subscription;
g_object_notify (G_OBJECT (contact), "subscription");
{
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)
{
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 *
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);
return status;
}
- return _("Offline");
+ return gossip_presence_state_get_default_status (MC_PRESENCE_OFFLINE);
}
gboolean