[empathy] Add an EmpathyIndividualView feature for changing Individuals' groups



commit 5b5f330cef05c8ebaa5ded6c74992910d7d85999
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Aug 24 12:57:37 2010 +0100

    Add an EmpathyIndividualView feature for changing Individuals' groups
    
    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 |   38 ++++++++++++++++++++++-------
 libempathy-gtk/empathy-individual-view.h |   15 +++++++----
 2 files changed, 38 insertions(+), 15 deletions(-)
---
diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c
index 926f4dd..245ea16 100644
--- a/libempathy-gtk/empathy-individual-view.c
+++ b/libempathy-gtk/empathy-individual-view.c
@@ -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.
diff --git a/libempathy-gtk/empathy-individual-view.h b/libempathy-gtk/empathy-individual-view.h
index 4a581c3..6a65c7e 100644
--- a/libempathy-gtk/empathy-individual-view.h
+++ b/libempathy-gtk/empathy-individual-view.h
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]