]> git.0d.be Git - empathy.git/commitdiff
Add an EmpathyIndividualView feature for receiving Persona drops
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Wed, 25 Aug 2010 11:08:02 +0000 (12:08 +0100)
committerPhilip Withnall <philip.withnall@collabora.co.uk>
Fri, 27 Aug 2010 09:23:48 +0000 (10:23 +0100)
This is necessary to avoid Personas being droppable on the main contact list,
which makes no sense (for the time being). Helps: bgo#627715

libempathy-gtk/empathy-individual-view.c
libempathy-gtk/empathy-individual-view.h
src/empathy-main-window.c

index 96f6c38f411400a2b5c431c18f5b7769b4f88043..9ef9c103a615a62cc32a3558c6938c2073b1d84f 100644 (file)
@@ -70,7 +70,6 @@ typedef struct
   EmpathyIndividualViewFeatureFlags view_features;
   EmpathyIndividualFeatureFlags individual_features;
   GtkWidget *tooltip_widget;
-  GtkTargetList *file_targets;
 
   gboolean show_offline;
 
@@ -119,17 +118,12 @@ enum DndDragType
   { (gchar *) T, 0, I }
 
 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),
-};
-
-static const GtkTargetEntry drag_types_dest_file[] = {
   DRAG_TYPE ("text/path-list", DND_DRAG_TYPE_URI_LIST),
   DRAG_TYPE ("text/uri-list", DND_DRAG_TYPE_URI_LIST),
+  DRAG_TYPE ("text/plain", DND_DRAG_TYPE_STRING),
+  DRAG_TYPE ("STRING", DND_DRAG_TYPE_STRING),
 };
 
 static const GtkTargetEntry drag_types_source[] = {
@@ -597,57 +591,11 @@ individual_view_drag_motion (GtkWidget *widget,
       gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), NULL, 0);
       return FALSE;
     }
-  target = gtk_drag_dest_find_target (widget, context, priv->file_targets);
+  target = gtk_drag_dest_find_target (widget, context, NULL);
   gtk_tree_model_get_iter (model, &iter, path);
 
-  if (target == GDK_NONE &&
-      (priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_CHANGE ||
-       priv->drag_row == NULL))
-    {
-      /* If target == GDK_NONE, then we don't have a target that can be
-         dropped on a contact.  This means a contact drag.  If we're
-         pointing to a group, highlight it.  Otherwise, if the contact
-         we're pointing to is in a group, highlight that.  Otherwise,
-         set the drag position to before the first row for a drag into
-         the "non-group" at the top.
-         We only highlight things if the contact is from a different Individual
-         view, or if this Individual view has FEATURE_GROUPS_CHANGE. This
-         prevents highlighting in Individual views which don't have
-         FEATURE_GROUPS_CHANGE, but do have FEATURE_INDIVIDUAL_DRAG and
-         FEATURE_INDIVIDUAL_DROP.
-       */
-      GtkTreeIter group_iter;
-      gboolean is_group;
-      GtkTreePath *group_path;
-      gtk_tree_model_get (model, &iter,
-          EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
-      if (is_group)
-        {
-          group_iter = iter;
-        }
-      else
-        {
-          if (gtk_tree_model_iter_parent (model, &group_iter, &iter))
-            gtk_tree_model_get (model, &group_iter,
-                EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
-        }
-      if (is_group)
-        {
-          gdk_drag_status (context, GDK_ACTION_MOVE, time_);
-          group_path = gtk_tree_model_get_path (model, &group_iter);
-          gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
-              group_path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
-          gtk_tree_path_free (group_path);
-        }
-      else
-        {
-          group_path = gtk_tree_path_new_first ();
-          gdk_drag_status (context, GDK_ACTION_MOVE, time_);
-          gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
-              group_path, GTK_TREE_VIEW_DROP_BEFORE);
-        }
-    }
-  else if (target != GDK_NONE)
+  if (target == drag_atoms_dest[DND_DRAG_TYPE_URI_LIST] ||
+      target == drag_atoms_dest[DND_DRAG_TYPE_STRING])
     {
       /* This is a file drag, and it can only be dropped on contacts,
        * not groups.
@@ -691,6 +639,58 @@ individual_view_drag_motion (GtkWidget *widget,
       if (individual != NULL)
         g_object_unref (individual);
     }
+  else if (((target == drag_atoms_dest[DND_DRAG_TYPE_STRING] ||
+       target == drag_atoms_dest[DND_DRAG_TYPE_INDIVIDUAL_ID]) &&
+      (priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_CHANGE ||
+       priv->drag_row == NULL)) ||
+      (target == drag_atoms_dest[DND_DRAG_TYPE_PERSONA_ID] &&
+       priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP))
+    {
+      /* If target != GDK_NONE, then we have a contact (individual or persona)
+         drag.  If we're pointing to a group, highlight it.  Otherwise, if the
+         contact we're pointing to is in a group, highlight that.  Otherwise,
+         set the drag position to before the first row for a drag into
+         the "non-group" at the top.
+         If it's an Individual:
+           We only highlight things if the contact is from a different
+           Individual view, or if this Individual view has
+           FEATURE_GROUPS_CHANGE. This prevents highlighting in Individual views
+           which don't have FEATURE_GROUPS_CHANGE, but do have
+           FEATURE_INDIVIDUAL_DRAG and FEATURE_INDIVIDUAL_DROP.
+         If it's a Persona:
+           We only highlight things if we have FEATURE_PERSONA_DROP.
+       */
+      GtkTreeIter group_iter;
+      gboolean is_group;
+      GtkTreePath *group_path;
+      gtk_tree_model_get (model, &iter,
+          EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
+      if (is_group)
+        {
+          group_iter = iter;
+        }
+      else
+        {
+          if (gtk_tree_model_iter_parent (model, &group_iter, &iter))
+            gtk_tree_model_get (model, &group_iter,
+                EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
+        }
+      if (is_group)
+        {
+          gdk_drag_status (context, GDK_ACTION_MOVE, time_);
+          group_path = gtk_tree_model_get_path (model, &group_iter);
+          gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
+              group_path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
+          gtk_tree_path_free (group_path);
+        }
+      else
+        {
+          group_path = gtk_tree_path_new_first ();
+          gdk_drag_status (context, GDK_ACTION_MOVE, time_);
+          gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
+              group_path, GTK_TREE_VIEW_DROP_BEFORE);
+        }
+    }
 
   if (!is_different && !cleanup)
     return retval;
@@ -1875,7 +1875,6 @@ individual_view_dispose (GObject *object)
   tp_clear_object (&priv->store);
   tp_clear_object (&priv->filter);
   tp_clear_pointer (&priv->tooltip_widget, gtk_widget_destroy);
-  tp_clear_pointer (&priv->file_targets, gtk_target_list_unref);
 
   empathy_individual_view_set_live_search (view, NULL);
 
@@ -2045,10 +2044,6 @@ empathy_individual_view_init (EmpathyIndividualView *view)
   gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view),
       empathy_individual_store_row_separator_func, NULL, NULL);
 
-  /* Set up drag target lists. */
-  priv->file_targets = gtk_target_list_new (drag_types_dest_file,
-      G_N_ELEMENTS (drag_types_dest_file));
-
   /* Connect to tree view signals rather than override. */
   g_signal_connect (view, "button-press-event",
       G_CALLBACK (individual_view_button_press_event_cb), NULL);
index 5222eb1a4ed9586ff81dd4be8879b52470653a31..8a250bf20e1248533c8a9b2805066c8b983d81c5 100644 (file)
@@ -60,8 +60,9 @@ typedef enum
   EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DROP = 1 << 5,
   EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DRAG = 1 << 6,
   EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_TOOLTIP = 1 << 7,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_FILE_DROP = 1 << 8,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL = (1 << 9) - 1,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP = 1 << 8,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_FILE_DROP = 1 << 9,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL = (1 << 10) - 1,
 } EmpathyIndividualViewFeatureFlags;
 
 struct _EmpathyIndividualView
index 0efa4a97d13c054ab4423402137c9b9439ea4abe..07725fa3b8e22ebbffa566efb6579c2f48b1b470 100644 (file)
@@ -1673,9 +1673,12 @@ empathy_main_window_init (EmpathyMainWindow *window)
                        individual_manager);
        g_object_unref (individual_manager);
 
+       /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
+        * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
+        * drop, so allowing them would achieve nothing except confusion. */
        priv->individual_view = empathy_individual_view_new (
                        priv->individual_store,
-                       EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL,
+                       EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
                        EMPATHY_INDIVIDUAL_FEATURE_ALL);
 
        priv->butterfly_log_migration_members_changed_id = g_signal_connect (