static void
logger_favourite_contacts_changed_cb (TpProxy      *proxy,
				      const gchar  *account_name,
				      const gchar **added,
				      const gchar **removed,
				      gpointer      user_data,
				      GObject      *weak_object)
{
	EmpathyContactManagerPriv *priv;
	EmpathyContactManager *manager = EMPATHY_CONTACT_MANAGER (weak_object);
	GHashTable *contact_hash;
	EmpathyContact *contact;
	gint i;

	priv = GET_PRIV (manager);

	contact_hash = g_hash_table_lookup (priv->favourites, account_name);

	/* XXX: note that, at the time of this comment, there will always be
	 * exactly one contact amongst added and removed, so the linear lookup
	 * of each contact isn't as painful as it appears */

	add_contacts_to_favourites (manager, account_name, added);

	for (i = 0; added && added[i]; i++) {
		contact = contact_manager_lookup_contact (manager, account_name,
							  added[i]);
		if (contact != NULL)
			g_signal_emit_by_name (manager, "favourites-changed",
					       contact, TRUE);
		else
			DEBUG ("failed to find contact for account %s, contact "
			       "id %s", account_name, added[i]);
	}

	for (i = 0; removed && removed[i]; i++) {
		contact_hash = g_hash_table_lookup (priv->favourites,
						    account_name);

		if (contact_hash != NULL) {
			g_hash_table_remove (contact_hash, removed[i]);

			if (g_hash_table_size (contact_hash) < 1) {
				g_hash_table_remove (priv->favourites,
						     account_name);
			}
		}

		contact = contact_manager_lookup_contact (manager, account_name,
							  removed[i]);
		if (contact != NULL)
			g_signal_emit_by_name (manager, "favourites-changed",
					       contact, FALSE);
		else
			DEBUG ("failed to find contact for account %s, contact "
			       "id %s", account_name, removed[i]);
	}
}
static GObject *
contact_manager_constructor (GType type,
			     guint n_props,
			     GObjectConstructParam *props)
{
	GObject *retval;

	if (manager_singleton) {
		retval = g_object_ref (manager_singleton);
	} else {
		retval = G_OBJECT_CLASS (empathy_contact_manager_parent_class)->constructor
			(type, n_props, props);

		manager_singleton = EMPATHY_CONTACT_MANAGER (retval);
		g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
	}

	return retval;
}
static void
logger_favourite_contacts_get_cb (TpProxy         *proxy,
				  const GPtrArray *result,
				  const GError    *error,
				  gpointer         user_data,
				  GObject         *weak_object)
{
	EmpathyContactManager *manager = EMPATHY_CONTACT_MANAGER (weak_object);

	if (error == NULL) {
		g_ptr_array_foreach ((GPtrArray *) result,
				(GFunc)
				logger_favourite_contacts_add_from_value_array,
				manager);
	} else {
		DEBUG ("Failed to get the FavouriteContacts property: %s",
				error->message);
	}
}
Esempio n. 4
0
static void
contact_list_store_add_contact (EmpathyContactListStore *store,
				EmpathyContact          *contact)
{
	EmpathyContactListStorePriv *priv;
	GtkTreeIter                 iter;
	GList                      *groups = NULL, *l;
	TpConnection               *connection;
	EmpathyContactListFlags     flags = 0;

	priv = GET_PRIV (store);

	if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
	    (!priv->show_offline && !empathy_contact_is_online (contact))) {
		return;
	}

	if (priv->show_groups) {
		groups = empathy_contact_list_get_groups (priv->list, contact);
	}

	connection = empathy_contact_get_connection (contact);
	if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
		flags = empathy_contact_manager_get_flags_for_connection (
			EMPATHY_CONTACT_MANAGER (priv->list), connection);
	}
	/* If no groups just add it at the top level. */
	if (!groups) {
		GtkTreeModel *model = GTK_TREE_MODEL (store);

		if (gtk_tree_model_get_iter_first (model, &iter)) do {
			EmpathyContact *c;

			gtk_tree_model_get (model, &iter,
				EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c,
				-1);

			if (c == contact) {
				g_object_unref (c);
				return;
			}
			if (c != NULL)
				g_object_unref (c);
		} while (gtk_tree_model_iter_next (model, &iter));

		gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
				    -1);
	}

	/* Else add to each group. */
	for (l = groups; l; l = l->next) {
		GtkTreeIter iter_group;

		contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);

		gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
					     &iter_group, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
				    -1);
		g_free (l->data);
	}
	g_list_free (groups);

	contact_list_store_contact_update (store, contact);

}