]> git.0d.be Git - empathy.git/commitdiff
Add an EmpathyIndividualView::drag-individual-received signal
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Tue, 24 Aug 2010 13:34:00 +0000 (14:34 +0100)
committerPhilip Withnall <philip.withnall@collabora.co.uk>
Fri, 27 Aug 2010 09:23:48 +0000 (10:23 +0100)
Subclasses or users of the widget can then override this and stop the signal
emission to do new and interesting things with dropped Individuals, rather
than just changing their groups.

libempathy-gtk/empathy-individual-view.c
libempathy-gtk/empathy-individual-view.h

index 63b689687c714f55d39caac9fc6a2b72c458145b..7899acce867c7af1e44449d8c894cd177a22592c 100644 (file)
@@ -141,7 +141,7 @@ static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
 
 enum
 {
-  DRAG_CONTACT_RECEIVED,
+  DRAG_INDIVIDUAL_RECEIVED,
   LAST_SIGNAL
 };
 
@@ -341,6 +341,29 @@ individual_view_contact_drag_received (GtkWidget *self,
   /* FIXME: We should probably wait for the cb before calling
    * gtk_drag_finish */
 
+  /* Emit a signal notifying of the drag. We change the Individual's groups in
+   * the default signal handler. */
+  g_signal_emit (self, signals[DRAG_INDIVIDUAL_RECEIVED], 0,
+      gdk_drag_context_get_selected_action (context), individual, new_group,
+      old_group);
+
+  retval = TRUE;
+
+finished:
+  tp_clear_object (&manager);
+  g_free (old_group);
+  g_free (new_group);
+
+  return retval;
+}
+
+static void
+real_drag_individual_received_cb (EmpathyIndividualView *self,
+    GdkDragAction action,
+    FolksIndividual *individual,
+    const gchar *new_group,
+    const gchar *old_group)
+{
   DEBUG ("individual %s dragged from '%s' to '%s'",
       folks_individual_get_id (individual), old_group, new_group);
 
@@ -348,41 +371,29 @@ individual_view_contact_drag_received (GtkWidget *self,
     {
       /* Mark contact as favourite */
       folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual), TRUE);
+      return;
     }
-  else
-    {
-      if (!tp_strdiff (old_group, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
-        {
-          /* Remove contact as favourite */
-          folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual),
-              FALSE);
 
-          /* Don't try to remove it */
-          old_group = NULL;
-        }
-
-      if (new_group != NULL)
-        {
-          folks_groups_change_group (FOLKS_GROUPS (individual), new_group, TRUE,
-              groups_change_group_cb, NULL);
-        }
+  if (!tp_strdiff (old_group, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
+    {
+      /* Remove contact as favourite */
+      folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual), FALSE);
 
-      if (old_group != NULL &&
-          gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE)
-        {
-          folks_groups_change_group (FOLKS_GROUPS (individual), old_group,
-              FALSE, groups_change_group_cb, NULL);
-        }
+      /* Don't try to remove it */
+      old_group = NULL;
     }
 
-  retval = TRUE;
-
-finished:
-  tp_clear_object (&manager);
-  g_free (old_group);
-  g_free (new_group);
+  if (new_group != NULL)
+    {
+      folks_groups_change_group (FOLKS_GROUPS (individual), new_group, TRUE,
+          groups_change_group_cb, NULL);
+    }
 
-  return retval;
+  if (old_group != NULL && action == GDK_ACTION_MOVE)
+    {
+      folks_groups_change_group (FOLKS_GROUPS (individual), old_group,
+          FALSE, groups_change_group_cb, NULL);
+    }
 }
 
 static gboolean
@@ -1893,14 +1904,17 @@ empathy_individual_view_class_init (EmpathyIndividualViewClass *klass)
    * won't be called. */
   tree_view_class->row_activated = individual_view_row_activated;
 
-  signals[DRAG_CONTACT_RECEIVED] =
-      g_signal_new ("drag-contact-received",
+  klass->drag_individual_received = real_drag_individual_received_cb;
+
+  signals[DRAG_INDIVIDUAL_RECEIVED] =
+      g_signal_new ("drag-individual-received",
       G_OBJECT_CLASS_TYPE (klass),
       G_SIGNAL_RUN_LAST,
-      0,
+      G_STRUCT_OFFSET (EmpathyIndividualViewClass, drag_individual_received),
       NULL, NULL,
-      _empathy_gtk_marshal_VOID__OBJECT_STRING_STRING,
-      G_TYPE_NONE, 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING);
+      _empathy_gtk_marshal_VOID__UINT_OBJECT_STRING_STRING,
+      G_TYPE_NONE, 4, G_TYPE_UINT, FOLKS_TYPE_INDIVIDUAL,
+      G_TYPE_STRING, G_TYPE_STRING);
 
   g_object_class_install_property (object_class,
       PROP_STORE,
index a87848408c587ed31c60748741ff1ba96af0a67f..babe0a9396f1ea6dd7898398618e34fad91dbc63 100644 (file)
@@ -73,6 +73,12 @@ struct _EmpathyIndividualView
 struct _EmpathyIndividualViewClass
 {
   GtkTreeViewClass parent_class;
+
+  void (* drag_individual_received) (EmpathyIndividualView *self,
+      GdkDragAction action,
+      FolksIndividual *individual,
+      const gchar *new_group,
+      const gchar *old_group);
 };
 
 GType empathy_individual_view_get_type (void) G_GNUC_CONST;