#include "config.h"
-#include <glib.h>
#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-#include <gio/gio.h>
-#include <telepathy-glib/enums.h>
-#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 "empathy-debug.h"
+#include "empathy-ft-factory.h"
+
+#include "empathy-roster-model-manager.h"
+#include "empathy-ui-utils.h"
+#include "empathy-roster-view.h"
+#include "empathy-roster-contact.h"
-#include <libempathy-gtk/empathy-contact-selector.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
#include "nautilus-sendto-plugin.h"
static EmpathyFTFactory *factory = NULL;
static guint transfers = 0;
+#define BOX_DATA_KEY "roster_view"
+
static gboolean destroy (NstPlugin *plugin);
static gboolean
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 (GtkWidget *child,
+ gpointer user_data)
+{
+ FolksIndividual *individual;
+ EmpathyContact *contact;
+
+ if (!EMPATHY_IS_ROSTER_CONTACT (child))
+ return FALSE;
+
+ individual = empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
+
+ 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 *roster_view, *box, *scrolled;
+ EmpathyIndividualManager *mgr;
+ EmpathyRosterModel *model;
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
+
+ mgr = empathy_individual_manager_dup_singleton ();
+ model = EMPATHY_ROSTER_MODEL (empathy_roster_model_manager_new (mgr));
+ roster_view = empathy_roster_view_new (model);
+
+ g_object_unref (model);
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
- manager = empathy_contact_manager_dup_singleton ();
- selector = empathy_contact_selector_new (EMPATHY_CONTACT_LIST (manager));
+ g_object_unref (mgr);
- empathy_contact_selector_set_visible (EMPATHY_CONTACT_SELECTOR (selector),
- (EmpathyContactSelectorFilterFunc) empathy_contact_can_send_files, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ egg_list_box_set_filter_func (EGG_LIST_BOX (roster_view), filter_individual,
+ roster_view, NULL);
+ egg_list_box_add_to_scrolled (EGG_LIST_BOX (roster_view),
+ GTK_SCROLLED_WINDOW (scrolled));
- g_object_unref (manager);
+ gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0);
- return selector;
+ gtk_widget_set_size_request (box, -1, 300);
+ gtk_widget_show (roster_view);
+ gtk_widget_show (scrolled);
+ gtk_widget_show (box);
+
+ g_object_set_data (G_OBJECT (box), BOX_DATA_KEY, roster_view);
+
+ return box;
}
static EmpathyContact *
-get_selected_contact (GtkWidget *contact_widget)
+get_selected_contact (GtkWidget *widget)
{
+ EmpathyRosterView *roster_view;
+ FolksIndividual *individual;
EmpathyContact *contact;
- GtkTreeModel *model;
- GtkTreeIter iter;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (contact_widget), &iter))
+ roster_view = g_object_get_data (G_OBJECT (widget), BOX_DATA_KEY);
+ individual = empathy_roster_view_get_selected_individual (roster_view);
+
+ 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;
}
gchar **error)
{
EmpathyContact *contact = NULL;
- gboolean ret = TRUE;
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
static void
transfer_done_cb (EmpathyFTHandler *handler,
- EmpathyTpFile *tp_file,
+ TpFileTransferChannel *channel,
NstPlugin *plugin)
{
quit ();
contact = get_selected_contact (contact_widget);
- if (!contact)
+ if (contact == NULL)
return FALSE;
factory = empathy_ft_factory_dup_singleton ();
++transfers;
empathy_ft_factory_new_transfer_outgoing (factory,
- contact, file);
+ contact, file, empathy_get_current_action_time ());
g_object_unref (file);
}
static
NstPluginInfo plugin_info = {
- "im",
+ "empathy",
"empathy",
N_("Instant Message (Empathy)"),
GETTEXT_PACKAGE,