*/
#include "config.h"
-
-#include <string.h>
+#include "empathy-individual-menu.h"
#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-#include <gio/gdesktopappinfo.h>
-
-#include <telepathy-glib/util.h>
-
-#include <folks/folks.h>
-#include <folks/folks-telepathy.h>
-
-#include <libempathy/empathy-camera-monitor.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-individual-manager.h>
-#include <libempathy/empathy-chatroom-manager.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-pkg-kit.h>
#include "empathy-account-selector-dialog.h"
-#include "empathy-individual-menu.h"
-#include "empathy-images.h"
-#include "empathy-log-window.h"
-#include "empathy-contact-dialogs.h"
+#include "empathy-call-utils.h"
+#include "empathy-camera-monitor.h"
+#include "empathy-chatroom-manager.h"
#include "empathy-gtk-enum-types.h"
+#include "empathy-images.h"
+#include "empathy-individual-dialogs.h"
#include "empathy-individual-dialogs.h"
#include "empathy-individual-edit-dialog.h"
-#include "empathy-ui-utils.h"
-#include "empathy-share-my-desktop.h"
-#include "empathy-call-utils.h"
-#include "empathy-individual-store-channel.h"
#include "empathy-individual-information-dialog.h"
+#include "empathy-individual-manager.h"
+#include "empathy-individual-store-channel.h"
+#include "empathy-log-window.h"
+#include "empathy-request-util.h"
+#include "empathy-share-my-desktop.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualMenu)
FolksIndividual *individual);
static GtkWidget * empathy_individiual_block_menu_item_new (
FolksIndividual *individual);
+static GtkWidget * empathy_individiual_remove_menu_item_new (
+ FolksIndividual *individual);
static void
individual_menu_add_personas (GtkMenuShell *menu,
GeeSet *personas;
GeeIterator *iter;
guint persona_count = 0;
- gboolean c;
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
/* return early if these entries would add nothing beyond the "quick" items */
if (persona_count <= 1)
- return;
+ goto out;
/* add a separator before the list of personas */
item = gtk_separator_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
- for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
GtkWidget *image;
GtkWidget *contact_item;
single_individual = empathy_create_individual_from_tp_contact (
tp_contact);
+ /* Pretty hacky. Creating single_individual had a side effect to change
+ * persona.individual from individual to single_individual which is not
+ * what we want so we set it back. See bgo#684971 for details. */
+ g_object_set (persona, "individual", individual, NULL);
+
store = folks_persona_get_store (FOLKS_PERSONA (persona));
account = folks_persona_store_get_display_name (store);
gtk_widget_show (action);
/* File transfer */
- action = empathy_individual_file_transfer_menu_item_new (
- single_individual);
- gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
- gtk_widget_show (action);
+ if (features & EMPATHY_INDIVIDUAL_FEATURE_FILE_TRANSFER)
+ {
+ action = empathy_individual_file_transfer_menu_item_new (
+ single_individual);
+ gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
+ gtk_widget_show (action);
+ }
/* Share my desktop */
action = empathy_individual_share_my_desktop_menu_item_new (
g_clear_object (&persona);
}
+out:
g_clear_object (&iter);
}
am = tp_account_manager_dup ();
g_return_val_if_fail (am != NULL, NULL);
- accounts = tp_account_manager_get_valid_accounts (am);
+ accounts = tp_account_manager_dup_valid_accounts (am);
for (l = accounts; l != NULL; l = g_list_next (l))
{
TpAccount *account = l->data;
found = g_list_prepend (found, g_object_ref (account));
}
- g_list_free (accounts);
+ g_list_free_full (accounts, g_object_unref);
g_object_unref (am);
return found;
gtk_menu_shell_append (GTK_MENU_SHELL (self), item);
gtk_widget_show (item);
}
+
+ g_object_unref (iter);
}
/* return a list of TpContact supporting the blocking iface */
return item;
}
+enum
+{
+ REMOVE_DIALOG_RESPONSE_CANCEL = 0,
+ REMOVE_DIALOG_RESPONSE_DELETE,
+ REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK,
+};
+
+static int
+remove_dialog_show (const gchar *message,
+ const gchar *secondary_text,
+ gboolean block_button,
+ GdkPixbuf *avatar)
+{
+ GtkWidget *dialog;
+ gboolean res;
+
+ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", message);
+
+ if (avatar != NULL)
+ {
+ GtkWidget *image = gtk_image_new_from_pixbuf (avatar);
+ gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
+ gtk_widget_show (image);
+ }
+
+ if (block_button)
+ {
+ GtkWidget *button;
+
+ /* gtk_dialog_add_button() doesn't allow us to pass a string with a
+ * mnemonic so we have to create the button manually. */
+ button = gtk_button_new_with_mnemonic (
+ _("Delete and _Block"));
+
+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
+ REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK);
+
+ gtk_widget_show (button);
+ }
+
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, REMOVE_DIALOG_RESPONSE_CANCEL,
+ GTK_STOCK_DELETE, REMOVE_DIALOG_RESPONSE_DELETE, NULL);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", secondary_text);
+
+ gtk_widget_show (dialog);
+
+ res = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ return res;
+}
+
+static void
+remove_got_avatar (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ FolksIndividual *individual = FOLKS_INDIVIDUAL (source_object);
+ GdkPixbuf *avatar;
+ EmpathyIndividualManager *manager;
+ gchar *text;
+ GeeSet *personas;
+ guint persona_count = 0;
+ gboolean can_block;
+ GError *error = NULL;
+ gint res;
+
+ avatar = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
+ result, &error);
+
+ if (error != NULL)
+ {
+ DEBUG ("Could not get avatar: %s", error->message);
+ g_error_free (error);
+ }
+
+ /* We couldn't retrieve the avatar, but that isn't a fatal error,
+ * so we still display the remove dialog. */
+
+ personas = folks_individual_get_personas (individual);
+
+ persona_count = gee_collection_get_size (GEE_COLLECTION (personas));
+
+ /* If we have more than one TpfPersona, display a different message
+ * ensuring the user knows that *all* of the meta-contacts' personas will
+ * be removed. */
+
+ if (persona_count < 2)
+ {
+ /* Not a meta-contact */
+ text =
+ g_strdup_printf (
+ _("Do you really want to remove the contact '%s'?"),
+ folks_alias_details_get_alias (
+ FOLKS_ALIAS_DETAILS (individual)));
+ }
+ else
+ {
+ /* Meta-contact */
+ text =
+ g_strdup_printf (
+ _("Do you really want to remove the linked contact '%s'? "
+ "Note that this will remove all the contacts which make up "
+ "this linked contact."),
+ folks_alias_details_get_alias (
+ FOLKS_ALIAS_DETAILS (individual)));
+ }
+
+
+ manager = empathy_individual_manager_dup_singleton ();
+ can_block = empathy_individual_manager_supports_blocking (manager,
+ individual);
+ res = remove_dialog_show (_("Removing contact"), text, can_block, avatar);
+
+ if (res == REMOVE_DIALOG_RESPONSE_DELETE ||
+ res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
+ {
+ gboolean abusive;
+
+ if (res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
+ {
+ if (!empathy_block_individual_dialog_show (NULL, individual,
+ avatar, &abusive))
+ goto finally;
+
+ empathy_individual_manager_set_blocked (manager, individual,
+ TRUE, abusive);
+ }
+
+ empathy_individual_manager_remove (manager, individual, "");
+ }
+
+ finally:
+ g_free (text);
+ g_object_unref (manager);
+}
+
+static void
+remove_activate_cb (GtkMenuItem *menuitem,
+ FolksIndividual *individual)
+{
+ empathy_pixbuf_avatar_from_individual_scaled_async (individual,
+ 48, 48, NULL, remove_got_avatar, NULL);
+}
+
+static GtkWidget *
+empathy_individiual_remove_menu_item_new (FolksIndividual *individual)
+{
+ GeeSet *personas;
+ GeeIterator *iter;
+ gboolean can_remove = FALSE;
+ GtkWidget *item, *image;
+
+ /* If any of the Individual's personas can be removed, add an option to
+ * remove. This will act as a best-effort option. If any Personas cannot be
+ * removed from the server, then this option will just be inactive upon
+ * subsequent menu openings */
+ personas = folks_individual_get_personas (individual);
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (!can_remove && gee_iterator_next (iter))
+ {
+ FolksPersona *persona = gee_iterator_get (iter);
+ FolksPersonaStore *store = folks_persona_get_store (persona);
+ FolksMaybeBool maybe_can_remove =
+ folks_persona_store_get_can_remove_personas (store);
+
+ if (maybe_can_remove == FOLKS_MAYBE_BOOL_TRUE)
+ can_remove = TRUE;
+
+ g_clear_object (&persona);
+ }
+ g_clear_object (&iter);
+
+ if (!can_remove)
+ return NULL;
+
+ item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
+ image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE,
+ GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+
+ g_signal_connect (item, "activate",
+ G_CALLBACK (remove_activate_cb), individual);
+
+ return item;
+}
+
static void
constructed (GObject *object)
{
gtk_widget_show (item);
/* File transfer */
- item = empathy_individual_file_transfer_menu_item_new (individual);
- gtk_menu_shell_append (shell, item);
- gtk_widget_show (item);
+ if (features & EMPATHY_INDIVIDUAL_FEATURE_FILE_TRANSFER)
+ {
+ item = empathy_individual_file_transfer_menu_item_new (individual);
+ gtk_menu_shell_append (shell, item);
+ gtk_widget_show (item);
+ }
/* Share my desktop */
/* FIXME we should add the "Share my desktop" menu item if Vino is
gtk_menu_shell_append (shell, item);
gtk_widget_show (item);
}
+
+ /* Separator & Remove */
+ if (features & EMPATHY_INDIVIDUAL_FEATURE_REMOVE &&
+ (item = empathy_individiual_remove_menu_item_new (individual)) != NULL) {
+ GtkWidget *sep;
+
+ sep = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (shell, sep);
+ gtk_widget_show (sep);
+
+ gtk_menu_shell_append (shell, item);
+ gtk_widget_show (item);
+ }
}
static void
return item;
}
-static void
-show_gnome_contacts_error_dialog (void)
-{
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- _("gnome-contacts not installed"));
-
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("Please install gnome-contacts to access contacts details."));
-
- g_signal_connect_swapped (dialog, "response",
- G_CALLBACK (gtk_widget_destroy), dialog);
-
- gtk_widget_show (dialog);
-}
-
-static void
-start_gnome_contacts (FolksIndividual *individual,
- gboolean try_installing);
-
-static void
-install_gnome_contacts_cb (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- FolksIndividual *individual = user_data;
- GError *error = NULL;
-
- if (!empathy_pkg_kit_install_packages_finish (result, &error))
- {
- DEBUG ("Failed to install gnome-contacts: %s", error->message);
- g_error_free (error);
-
- show_gnome_contacts_error_dialog ();
- goto out;
- }
-
- DEBUG ("gnome-contacts installed");
-
- start_gnome_contacts (individual, FALSE);
-
-out:
- g_object_unref (individual);
-}
-
-static void
-start_gnome_contacts (FolksIndividual *individual,
- gboolean try_installing)
-{
- GDesktopAppInfo *desktop_info;
- gchar *cmd;
- GAppInfo *app_info;
- GError *error = NULL;
- GdkAppLaunchContext *context = NULL;
- GdkDisplay *display;
-
- g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
-
- /* Start gnome-contacts */
- display = gdk_display_get_default ();
- context = gdk_display_get_app_launch_context (display);
-
- desktop_info = g_desktop_app_info_new ("gnome-contacts.desktop");
- if (desktop_info == NULL)
- {
- if (try_installing)
- {
- const gchar *packages[] = { "gnome-contacts", NULL };
-
- DEBUG ("gnome-contacts not installed; try to install it");
-
- empathy_pkg_kit_install_packages_async (0, packages, NULL,
- NULL, install_gnome_contacts_cb, g_object_ref (individual));
- }
- else
- {
- show_gnome_contacts_error_dialog ();
- }
-
- return;
- }
-
- /* glib doesn't have API to start a desktop file with args... (#637875) */
- cmd = g_strdup_printf ("%s -i %s", g_app_info_get_commandline (
- (GAppInfo *) desktop_info), folks_individual_get_id (individual));
-
- app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
- if (app_info == NULL)
- {
- DEBUG ("Failed to create app_info: %s", error->message);
- g_error_free (error);
- return;
- }
-
- if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
- &error))
- {
- g_critical ("Failed to start gnome-contacts: %s", error->message);
- g_error_free (error);
- }
-
- g_object_unref (desktop_info);
- g_object_unref (app_info);
-}
-
static void
individual_info_menu_item_activate_cb (GtkMenuItem *item,
FolksIndividual *individual)
{
- EmpathyIndividualManager *mgr;
-
- mgr = empathy_individual_manager_dup_singleton ();
-
- /* Only use gnome-contacts if that's a 'real' individual we got from
- * Folks (and so the individual manager knows about it). If not that's a
- * MUC contact and we use the simple dialog. */
- if (empathy_individual_manager_lookup_member (mgr,
- folks_individual_get_id (individual)) != NULL)
- {
- start_gnome_contacts (individual, TRUE);
- }
- else
- {
- empathy_individual_information_dialog_show (individual, NULL);
- }
-
- g_object_unref (mgr);
+ empathy_display_individual_info (individual);
}
static GtkWidget *
TpContact *tp_contact)
{
GtkWidget *toplevel;
- EmpathyContact *contact;
+ FolksIndividual *individual;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item));
if (!gtk_widget_is_toplevel (toplevel) || !GTK_IS_WINDOW (toplevel))
toplevel = NULL;
- contact = empathy_contact_dup_from_tp_contact (tp_contact);
+ individual = empathy_ensure_individual_from_tp_contact (tp_contact);
- empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel),
- contact);
+ empathy_new_individual_dialog_show_with_individual (GTK_WINDOW (toplevel),
+ individual);
- g_object_unref (contact);
+ g_object_unref (individual);
}
static GtkWidget *