aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-10-09 04:59:21 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-10-09 05:14:12 +0800
commit63dab7ab2d6a65e26c758697e0ab2f7614474c79 (patch)
tree2aced5d07d3349ecdeb5d8789b87103ef45f5cf8
parente143c562674626fe318828f6045b733b14c5714f (diff)
downloadgsoc2013-empathy-63dab7ab2d6a65e26c758697e0ab2f7614474c79.tar
gsoc2013-empathy-63dab7ab2d6a65e26c758697e0ab2f7614474c79.tar.gz
gsoc2013-empathy-63dab7ab2d6a65e26c758697e0ab2f7614474c79.tar.bz2
gsoc2013-empathy-63dab7ab2d6a65e26c758697e0ab2f7614474c79.tar.lz
gsoc2013-empathy-63dab7ab2d6a65e26c758697e0ab2f7614474c79.tar.xz
gsoc2013-empathy-63dab7ab2d6a65e26c758697e0ab2f7614474c79.tar.zst
gsoc2013-empathy-63dab7ab2d6a65e26c758697e0ab2f7614474c79.zip
nautilus-sendto: use EmpathyContactSelector instead of EmpathyContactChooser
This way we display meta-contacts rather than Telepathy contacts and use a nice treeview instead of a huge combo box. https://bugzilla.gnome.org/show_bug.cgi?id=629517
-rw-r--r--nautilus-sendto-plugin/empathy-nautilus-sendto.c100
1 files changed, 67 insertions, 33 deletions
diff --git a/nautilus-sendto-plugin/empathy-nautilus-sendto.c b/nautilus-sendto-plugin/empathy-nautilus-sendto.c
index cce55f8a0..2f38b8325 100644
--- a/nautilus-sendto-plugin/empathy-nautilus-sendto.c
+++ b/nautilus-sendto-plugin/empathy-nautilus-sendto.c
@@ -31,12 +31,11 @@
#include <libempathy/empathy-contact.h>
#include <libempathy/empathy-debug.h>
-#include <libempathy/empathy-contact-manager.h>
#include <libempathy/empathy-ft-factory.h>
#include <libempathy/empathy-ft-handler.h>
#include <libempathy/empathy-tp-file.h>
-#include <libempathy-gtk/empathy-contact-selector.h>
+#include <libempathy-gtk/empathy-contact-chooser.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include "nautilus-sendto-plugin.h"
@@ -56,37 +55,84 @@ init (NstPlugin *plugin)
return TRUE;
}
+static EmpathyContact *
+dup_contact_from_individual (FolksIndividual *individual)
+{
+ EmpathyContact *contact;
+ gboolean can_do_action;
+
+ if (individual == NULL)
+ return NULL;
+
+ contact = empathy_contact_dup_best_for_action (individual,
+ EMPATHY_ACTION_SEND_FILE);
+ if (contact == NULL)
+ return NULL;
+
+ can_do_action = empathy_contact_can_do_action (contact,
+ EMPATHY_ACTION_SEND_FILE);
+
+ if (!can_do_action)
+ {
+ /* If contact can't do FT we don't care about him */
+ g_object_unref (contact);
+ return NULL;
+ }
+
+ return contact;
+}
+
+static gboolean
+filter_individual (EmpathyContactChooser *chooser,
+ FolksIndividual *individual,
+ gboolean is_online,
+ gboolean searching,
+ gpointer user_data)
+{
+ EmpathyContact *contact;
+
+ if (!is_online)
+ return FALSE;
+
+ contact = dup_contact_from_individual (individual);
+ if (contact == NULL)
+ return FALSE;
+
+ g_object_unref (contact);
+ return TRUE;
+}
+
static GtkWidget *
get_contacts_widget (NstPlugin *plugin)
{
- EmpathyContactManager *manager;
- GtkWidget *selector;
+ GtkWidget *chooser;
- manager = empathy_contact_manager_dup_singleton ();
- selector = empathy_contact_selector_new (EMPATHY_CONTACT_LIST (manager));
+ chooser = empathy_contact_chooser_new ();
+ empathy_contact_chooser_set_filter_func (EMPATHY_CONTACT_CHOOSER (chooser),
+ filter_individual, plugin);
- empathy_contact_selector_set_visible (EMPATHY_CONTACT_SELECTOR (selector),
- (EmpathyContactSelectorFilterFunc) empathy_contact_can_send_files, NULL);
+ empathy_contact_chooser_show_search_entry (EMPATHY_CONTACT_CHOOSER (chooser),
+ FALSE);
- g_object_unref (manager);
-
- return selector;
+ /* Make sure to display some contacts */
+ gtk_widget_set_size_request (chooser, -1, 300);
+ return chooser;
}
static EmpathyContact *
-get_selected_contact (GtkWidget *contact_widget)
+get_selected_contact (GtkWidget *widget)
{
+ FolksIndividual *individual;
EmpathyContact *contact;
- GtkTreeModel *model;
- GtkTreeIter iter;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (contact_widget), &iter))
+ individual = empathy_contact_chooser_dup_selected (
+ EMPATHY_CONTACT_CHOOSER (widget));
+ if (individual == NULL)
return NULL;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (contact_widget));
- gtk_tree_model_get (model, &iter,
- EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, -1);
+ contact = dup_contact_from_individual (individual);
+ g_object_unref (individual);
return contact;
}
@@ -100,24 +146,12 @@ validate_destination (NstPlugin *plugin,
contact = get_selected_contact (contact_widget);
- if (!contact)
+ if (contact == NULL)
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;
+ return TRUE;
}
static void
@@ -192,7 +226,7 @@ send_files (NstPlugin *plugin,
contact = get_selected_contact (contact_widget);
- if (!contact)
+ if (contact == NULL)
return FALSE;
factory = empathy_ft_factory_dup_singleton ();