static gboolean contact_list_store_contact_active_cb (ShowActiveData *data) { EmpathyContactListStorePriv *priv; priv = GET_PRIV (data->store); if (data->remove && !priv->show_offline && !empathy_contact_is_online (data->contact)) { DEBUG ("Contact:'%s' active timeout, removing item", empathy_contact_get_name (data->contact)); contact_list_store_remove_contact (data->store, data->contact); } DEBUG ("Contact:'%s' no longer active", empathy_contact_get_name (data->contact)); contact_list_store_contact_set_active (data->store, data->contact, FALSE, TRUE); contact_list_store_contact_active_free (data); return FALSE; }
static gboolean validate_destination (NstPlugin *plugin, GtkWidget *contact_widget, gchar **error) { EmpathyContact *contact = NULL; gboolean ret = TRUE; contact = get_selected_contact (contact_widget); if (!contact) return FALSE; if (!empathy_contact_can_send_files (contact)) { *error = g_strdup (_("The selected contact cannot receive files.")); ret = FALSE; } if (ret && !empathy_contact_is_online (contact)) { *error = g_strdup (_("The selected contact is offline.")); ret = FALSE; } g_object_unref (contact); return ret; }
static void contact_list_store_contact_update (EmpathyContactListStore *store, EmpathyContact *contact) { EmpathyContactListStorePriv *priv; ShowActiveData *data; GtkTreeModel *model; GList *iters, *l; gboolean in_list; gboolean should_be_in_list; gboolean was_online = TRUE; gboolean now_online = FALSE; gboolean set_model = FALSE; gboolean do_remove = FALSE; gboolean do_set_active = FALSE; gboolean do_set_refresh = FALSE; gboolean show_avatar = FALSE; GdkPixbuf *pixbuf_avatar; priv = GET_PRIV (store); model = GTK_TREE_MODEL (store); iters = contact_list_store_find_contact (store, contact); if (!iters) { in_list = FALSE; } else { in_list = TRUE; } /* Get online state now. */ now_online = empathy_contact_is_online (contact); if (priv->show_offline || now_online) { should_be_in_list = TRUE; } else { should_be_in_list = FALSE; } if (!in_list && !should_be_in_list) { /* Nothing to do. */ DEBUG ("Contact:'%s' in list:NO, should be:NO", empathy_contact_get_name (contact)); g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL); g_list_free (iters); return; } else if (in_list && !should_be_in_list) { DEBUG ("Contact:'%s' in list:YES, should be:NO", empathy_contact_get_name (contact)); if (priv->show_active) { do_remove = TRUE; do_set_active = TRUE; do_set_refresh = TRUE; set_model = TRUE; DEBUG ("Remove item (after timeout)"); } else { DEBUG ("Remove item (now)!"); contact_list_store_remove_contact (store, contact); } } else if (!in_list && should_be_in_list) { DEBUG ("Contact:'%s' in list:NO, should be:YES", empathy_contact_get_name (contact)); contact_list_store_add_contact (store, contact); if (priv->show_active) { do_set_active = TRUE; DEBUG ("Set active (contact added)"); } } else { DEBUG ("Contact:'%s' in list:YES, should be:YES", empathy_contact_get_name (contact)); /* Get online state before. */ if (iters && g_list_length (iters) > 0) { gtk_tree_model_get (model, iters->data, EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online, -1); } /* Is this really an update or an online/offline. */ if (priv->show_active) { if (was_online != now_online) { do_set_active = TRUE; do_set_refresh = TRUE; DEBUG ("Set active (contact updated %s)", was_online ? "online -> offline" : "offline -> online"); } else { /* Was TRUE for presence updates. */ /* do_set_active = FALSE; */ do_set_refresh = TRUE; DEBUG ("Set active (contact updated)"); } } set_model = TRUE; } if (priv->show_avatars && !priv->is_compact) { show_avatar = TRUE; } pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32); for (l = iters; l && set_model; l = l->next) { gtk_tree_store_set (GTK_TREE_STORE (store), l->data, EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, empathy_icon_name_for_contact (contact), EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar, EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar, EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact), EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact), EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact, EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online, 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, -1); } if (pixbuf_avatar) { g_object_unref (pixbuf_avatar); } if (priv->show_active && do_set_active) { contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh); if (do_set_active) { data = contact_list_store_contact_active_new (store, contact, do_remove); g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME, (GSourceFunc) contact_list_store_contact_active_cb, data); } } /* FIXME: when someone goes online then offline quickly, the * first timeout sets the user to be inactive and the second * timeout removes the user from the contact list, really we * should remove the first timeout. */ g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL); g_list_free (iters); }
static void contact_list_store_add_contact (EmpathyContactListStore *store, EmpathyContact *contact) { EmpathyContactListStorePriv *priv; GtkTreeIter iter; GList *groups = NULL, *l; 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); } /* If no groups just add it at the top level. */ if (!groups) { 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, -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, -1); g_free (l->data); } g_list_free (groups); contact_list_store_contact_update (store, contact); }
static void megaphone_applet_update_icon (MegaphoneApplet *applet) { MegaphoneAppletPriv *priv = GET_PRIV (applet); EmpathyAvatar *avatar = NULL; GdkPixbuf *avatar_pixbuf; if (priv->contact) { avatar = empathy_contact_get_avatar (priv->contact); } else { gtk_image_set_from_icon_name (GTK_IMAGE (priv->image), GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); return; } if (!avatar) { gchar *avatar_token; /* Try to take avatar from cache */ avatar_token = panel_applet_gconf_get_string (PANEL_APPLET (applet), "avatar_token", NULL); if (!EMP_STR_EMPTY (avatar_token)) { empathy_contact_load_avatar_cache (priv->contact, avatar_token); avatar = empathy_contact_get_avatar (priv->contact); } g_free (avatar_token); } if (avatar) { avatar_pixbuf = empathy_pixbuf_from_avatar_scaled (avatar, priv->image_size - 2, priv->image_size - 2); } else { GtkIconTheme *icon_theme; /* Load the default icon when no avatar is found */ icon_theme = gtk_icon_theme_get_default (); avatar_pixbuf = gtk_icon_theme_load_icon (icon_theme, "stock_contact", priv->image_size - 2, 0, NULL); } /* Now some desaturation if the contact is offline */ if (!empathy_contact_is_online (priv->contact)) { GdkPixbuf *offline_avatar; offline_avatar = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, gdk_pixbuf_get_height (avatar_pixbuf), gdk_pixbuf_get_width (avatar_pixbuf)); gdk_pixbuf_saturate_and_pixelate (avatar_pixbuf, offline_avatar, 0.0, TRUE); g_object_unref (avatar_pixbuf); avatar_pixbuf = offline_avatar; } gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), avatar_pixbuf); g_object_unref (avatar_pixbuf); }
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); }