]> git.0d.be Git - empathy.git/commitdiff
Add an EmpathyIndividualView feature for changing Individuals' groups
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Tue, 24 Aug 2010 11:57:37 +0000 (12:57 +0100)
committerPhilip Withnall <philip.withnall@collabora.co.uk>
Fri, 27 Aug 2010 09:23:48 +0000 (10:23 +0100)
This separates drag and drop support from changing groups, so that
EmpathyIndividualView instances (such as the one in the linking dialogue)
may support dragging and dropping Individuals to and from another tree view,
but not support dragging them between groups inside the EmpathyIndividualView
instance. Helps: bgo#627715

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

index 926f4ddf799f19fbe3d61f49584cfa71658e8336..245ea16432bff1db90a4d4d7095125e332cc3aab 100644 (file)
@@ -293,8 +293,14 @@ individual_view_contact_drag_received (GtkWidget *self,
   if (!group_can_be_modified (new_group, new_group_is_fake, TRUE))
     goto finished;
 
-  /* Get source group information. */
-  if (priv->drag_row)
+  /* Get source group information iff the view has the FEATURE_GROUPS_CHANGE
+   * feature. Otherwise, we just add the dropped contact to whichever group
+   * they were dropped in, and don't remove them from their old group. This
+   * allows for Individual views which shouldn't allow Individuals to have
+   * their groups changed, and also for dragging Individuals between Individual
+   * views. */
+  if ((priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_CHANGE) &&
+      priv->drag_row != NULL)
     {
       source_path = gtk_tree_row_reference_get_path (priv->drag_row);
       if (source_path)
@@ -304,13 +310,20 @@ individual_view_contact_drag_received (GtkWidget *self,
               NULL, &old_group_is_fake);
           gtk_tree_path_free (source_path);
         }
-    }
 
-  if (!group_can_be_modified (old_group, old_group_is_fake, FALSE))
-    goto finished;
+      if (!group_can_be_modified (old_group, old_group_is_fake, FALSE))
+        goto finished;
 
-  if (!tp_strdiff (old_group, new_group))
-    goto finished;
+      if (!tp_strdiff (old_group, new_group))
+        goto finished;
+    }
+  else if (priv->drag_row != NULL)
+    {
+      /* We don't allow changing Individuals' groups, and this Individual was
+       * dragged from another group in *this* Individual view, so we disallow
+       * the drop. */
+      goto finished;
+    }
 
   /* XXX: for contacts, we used to ensure the account, create the contact
    * factory, and then wait on the contacts. But they should already be
@@ -503,7 +516,9 @@ individual_view_drag_motion (GtkWidget *widget,
   target = gtk_drag_dest_find_target (widget, context, priv->file_targets);
   gtk_tree_model_get_iter (model, &iter, path);
 
-  if (target == GDK_NONE)
+  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
@@ -511,6 +526,11 @@ individual_view_drag_motion (GtkWidget *widget,
          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_CONTACT_DRAG and
+         FEATURE_CONTACT_DROP.
        */
       GtkTreeIter group_iter;
       gboolean is_group;
@@ -543,7 +563,7 @@ individual_view_drag_motion (GtkWidget *widget,
               group_path, GTK_TREE_VIEW_DROP_BEFORE);
         }
     }
-  else
+  else if (target != GDK_NONE)
     {
       /* This is a file drag, and it can only be dropped on contacts,
        * not groups.
index 4a581c35c034f47847a9411b893fa63eeac0c851..6a65c7efafcf98dfd6d53d3c8f06287da15e46ff 100644 (file)
@@ -53,12 +53,15 @@ typedef enum
   EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_SAVE = 1 << 0,
   EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_RENAME = 1 << 1,
   EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_REMOVE = 1 << 2,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_REMOVE = 1 << 3,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_DROP = 1 << 4,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_DRAG = 1 << 5,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_TOOLTIP = 1 << 6,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_FILE_DROP = 1 << 7,
-  EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL = (1 << 8) - 1,
+  /* NOTE: For this to behave as expected, FEATURE_CONTACT_DRAG and
+   * FEATURE_CONTACT_DROP should also be specified. */
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_CHANGE = 1 << 3,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_REMOVE = 1 << 4,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_DROP = 1 << 5,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_DRAG = 1 << 6,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_CONTACT_TOOLTIP = 1 << 7,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_FILE_DROP = 1 << 8,
+  EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL = (1 << 9) - 1,
 } EmpathyIndividualViewFeatureFlags;
 
 struct _EmpathyIndividualView