From e2f43f8e42064400f777e52937b845f804331b26 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 24 Aug 2010 17:54:14 +0100 Subject: Add an EmpathyIndividualView::drag-persona-received signal This allows notification of drops of personas on the individual view. Helps: bgo#627715 --- libempathy-gtk/empathy-individual-view.c | 86 +++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'libempathy-gtk/empathy-individual-view.c') diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c index 7899acce8..96f6c38f4 100644 --- a/libempathy-gtk/empathy-individual-view.c +++ b/libempathy-gtk/empathy-individual-view.c @@ -110,6 +110,7 @@ enum enum DndDragType { DND_DRAG_TYPE_INDIVIDUAL_ID, + DND_DRAG_TYPE_PERSONA_ID, DND_DRAG_TYPE_URI_LIST, DND_DRAG_TYPE_STRING, }; @@ -121,6 +122,7 @@ static const GtkTargetEntry drag_types_dest[] = { DRAG_TYPE ("text/path-list", DND_DRAG_TYPE_URI_LIST), DRAG_TYPE ("text/uri-list", DND_DRAG_TYPE_URI_LIST), DRAG_TYPE ("text/individual-id", DND_DRAG_TYPE_INDIVIDUAL_ID), + DRAG_TYPE ("text/persona-id", DND_DRAG_TYPE_PERSONA_ID), DRAG_TYPE ("text/plain", DND_DRAG_TYPE_STRING), DRAG_TYPE ("STRING", DND_DRAG_TYPE_STRING), }; @@ -142,6 +144,7 @@ static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)]; enum { DRAG_INDIVIDUAL_RECEIVED, + DRAG_PERSONA_RECEIVED, LAST_SIGNAL }; @@ -269,7 +272,7 @@ group_can_be_modified (const gchar *name, } static gboolean -individual_view_contact_drag_received (GtkWidget *self, +individual_view_individual_drag_received (GtkWidget *self, GdkDragContext *context, GtkTreeModel *model, GtkTreePath *path, @@ -396,6 +399,71 @@ real_drag_individual_received_cb (EmpathyIndividualView *self, } } +static gboolean +individual_view_persona_drag_received (GtkWidget *self, + GdkDragContext *context, + GtkTreeModel *model, + GtkTreePath *path, + GtkSelectionData *selection) +{ + EmpathyIndividualViewPriv *priv; + EmpathyIndividualManager *manager = NULL; + FolksIndividual *individual = NULL; + FolksPersona *persona = NULL; + const gchar *persona_uid; + GList *individuals, *l; + gboolean retval = FALSE; + + priv = GET_PRIV (self); + + persona_uid = (const gchar *) gtk_selection_data_get_data (selection); + + /* FIXME: This is slow, but the only way to find the Persona we're having + * dropped on us. */ + manager = empathy_individual_manager_dup_singleton (); + individuals = empathy_individual_manager_get_members (manager); + + for (l = individuals; l != NULL; l = l->next) + { + GList *personas, *p; + + personas = folks_individual_get_personas (FOLKS_INDIVIDUAL (l->data)); + + for (p = personas; p != NULL; p = p->next) + { + if (!tp_strdiff (folks_persona_get_uid (FOLKS_PERSONA (p->data)), + persona_uid)) + { + persona = g_object_ref (p->data); + individual = g_object_ref (l->data); + goto got_persona; + } + } + } + +got_persona: + g_list_free (individuals); + + if (persona == NULL || individual == NULL) + { + DEBUG ("Failed to find drag event persona with UID '%s'", persona_uid); + } + else + { + /* Emit a signal notifying of the drag. We change the Individual's groups in + * the default signal handler. */ + g_signal_emit (self, signals[DRAG_PERSONA_RECEIVED], 0, + gdk_drag_context_get_selected_action (context), persona, individual, + &retval); + } + + tp_clear_object (&manager); + tp_clear_object (&persona); + tp_clear_object (&individual); + + return retval; +} + static gboolean individual_view_file_drag_received (GtkWidget *view, GdkDragContext *context, @@ -452,9 +520,14 @@ individual_view_drag_data_received (GtkWidget *view, else if (info == DND_DRAG_TYPE_INDIVIDUAL_ID || info == DND_DRAG_TYPE_STRING) { - success = individual_view_contact_drag_received (view, + success = individual_view_individual_drag_received (view, context, model, path, selection); } + else if (info == DND_DRAG_TYPE_PERSONA_ID) + { + success = individual_view_persona_drag_received (view, context, model, + path, selection); + } else if (info == DND_DRAG_TYPE_URI_LIST) { success = individual_view_file_drag_received (view, @@ -1916,6 +1989,15 @@ empathy_individual_view_class_init (EmpathyIndividualViewClass *klass) G_TYPE_NONE, 4, G_TYPE_UINT, FOLKS_TYPE_INDIVIDUAL, G_TYPE_STRING, G_TYPE_STRING); + signals[DRAG_PERSONA_RECEIVED] = + g_signal_new ("drag-persona-received", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EmpathyIndividualViewClass, drag_persona_received), + NULL, NULL, + _empathy_gtk_marshal_BOOLEAN__UINT_OBJECT_OBJECT, + G_TYPE_BOOLEAN, 3, G_TYPE_UINT, FOLKS_TYPE_PERSONA, FOLKS_TYPE_INDIVIDUAL); + g_object_class_install_property (object_class, PROP_STORE, g_param_spec_object ("store", -- cgit v1.2.3