evolution r36793 - in trunk: addressbook addressbook/gui/component calendar calendar/gui



Author: mbarnes
Date: Mon Nov 17 21:09:36 2008
New Revision: 36793
URL: http://svn.gnome.org/viewvc/evolution?rev=36793&view=rev

Log:
2008-11-17  Matthew Barnes  <mbarnes redhat com>

	** Fixes bug #557818

	* addressbook/gui/component/addressbook-view.c:
	* calendar/gui/calendar-component.c:
	* calendar/gui/memos-component.c:
	* calendar/gui/tasks-component.c:
	ESourceSelector now handles most of the drag-and-drop signals.
	We just have to listen for the new "data-dropped" signal and
	deal with it.  Gets rid of a lot of duplicate logic.



Modified:
   trunk/addressbook/ChangeLog
   trunk/addressbook/gui/component/addressbook-view.c
   trunk/calendar/ChangeLog
   trunk/calendar/gui/calendar-component.c
   trunk/calendar/gui/memos-component.c
   trunk/calendar/gui/tasks-component.c

Modified: trunk/addressbook/gui/component/addressbook-view.c
==============================================================================
--- trunk/addressbook/gui/component/addressbook-view.c	(original)
+++ trunk/addressbook/gui/component/addressbook-view.c	Mon Nov 17 21:09:36 2008
@@ -997,88 +997,6 @@
 	return TRUE;
 }
 
-static gboolean
-selector_tree_drag_drop (GtkWidget *widget,
-			 GdkDragContext *context,
-			 int x,
-			 int y,
-			 guint time,
-			 AddressbookView *view)
-{
-	GtkTreeViewColumn *column;
-	int cell_x;
-	int cell_y;
-	GtkTreePath *path;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	gpointer data;
-
-	if (!gtk_tree_view_get_path_at_pos  (GTK_TREE_VIEW (widget), x, y, &path, &column, &cell_x, &cell_y))
-		return FALSE;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path)) {
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data)) {
-		g_object_unref (data);
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_path_free (path);
-	return TRUE;
-}
-
-static gboolean
-selector_tree_drag_motion (GtkWidget *widget,
-			   GdkDragContext *context,
-			   int x,
-			   int y)
-{
-	GtkTreePath *path = NULL;
-	gpointer data = NULL;
-	GtkTreeViewDropPosition pos;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	GdkDragAction action = { 0, };
-
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data) || e_source_get_readonly (data))
-		goto finish;
-
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
-	/* Make default action move, not copy */
-	if (context->actions & GDK_ACTION_MOVE)
-		action = GDK_ACTION_MOVE;
-	else
-		action = context->suggested_action;
-
- finish:
-	if (path)
-		gtk_tree_path_free (path);
-	if (data)
-		g_object_unref (data);
-
-	gdk_drag_status (context, action, GDK_CURRENT_TIME);
-	return TRUE;
-}
-
 typedef struct
 {
 	guint     remove_from_source : 1;
@@ -1153,42 +1071,19 @@
 }
 
 static gboolean
-selector_tree_drag_data_received (GtkWidget *widget,
-				  GdkDragContext *context,
-				  gint x,
-				  gint y,
-				  GtkSelectionData *data,
-				  guint info,
-				  guint time,
-				  gpointer user_data)
-{
-	GtkTreePath *path = NULL;
-	GtkTreeViewDropPosition pos;
-	gpointer target = NULL;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	gboolean success = FALSE;
+selector_tree_data_dropped (ESourceSelector *selector,
+                            GtkSelectionData *data,
+                            ESource *destination,
+                            GdkDragAction action,
+                            guint info,
+                            AddressbookView *view)
+{
 	EBook *source_book, *target_book;
 	MergeContext *merge_context = NULL;
 	GList *contactlist;
-	AddressbookView *view;
 	EABView *v;
 
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-	gtk_tree_model_get (model, &iter, 0, &target, -1);
-
-	if (E_IS_SOURCE_GROUP (target) || e_source_get_readonly (target))
-		goto finish;
-
-	target_book = e_book_new (target, NULL);
+	target_book = e_book_new (destination, NULL);
 	if (!target_book) {
 		g_message (G_STRLOC ":Couldn't create EBook.");
 		return FALSE;
@@ -1197,7 +1092,6 @@
 
 	eab_book_and_contact_list_from_string ((char *)data->data, &source_book, &contactlist);
 
-	view = (AddressbookView *) user_data;
 	v = get_current_view (view);
 	g_object_get (v->model, "book",&source_book, NULL);
 
@@ -1211,32 +1105,17 @@
 	merge_context->current_contact = contactlist->data;
 	merge_context->remaining_contacts = g_list_delete_link (contactlist, contactlist);
 
-	merge_context->remove_from_source = context->action == GDK_ACTION_MOVE ? TRUE : FALSE;
+	merge_context->remove_from_source = action == GDK_ACTION_MOVE ? TRUE : FALSE;
 
 	/* Start merge */
 
 	eab_merging_book_add_contact (target_book, merge_context->current_contact,
 				      merged_contact_cb, merge_context);
 
- finish:
-	if (path)
-		gtk_tree_path_free (path);
-	if (target)
-		g_object_unref (target);
-
-	gtk_drag_finish (context, success, merge_context->remove_from_source, time);
-
 	return TRUE;
 }
 
 static void
-selector_tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
-{
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), NULL, GTK_TREE_VIEW_DROP_BEFORE);
-}
-
-
-static void
 destroy_callback(gpointer data, GObject *where_object_was)
 {
 	AddressbookView *view = data;
@@ -1338,10 +1217,9 @@
 
 	priv->selector = e_source_selector_new (priv->source_list);
 
-	g_signal_connect  (priv->selector, "drag-motion", G_CALLBACK (selector_tree_drag_motion), view);
-	g_signal_connect  (priv->selector, "drag-leave", G_CALLBACK (selector_tree_drag_leave), view);
-	g_signal_connect  (priv->selector, "drag-drop", G_CALLBACK (selector_tree_drag_drop), view);
-	g_signal_connect  (priv->selector, "drag-data-received", G_CALLBACK (selector_tree_drag_data_received), view);
+	g_signal_connect (
+		priv->selector, "data-dropped",
+		G_CALLBACK (selector_tree_data_dropped), view);
 	gtk_drag_dest_set (priv->selector, GTK_DEST_DEFAULT_ALL, drag_types, num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE);
 	a11y = gtk_widget_get_accessible (GTK_WIDGET (priv->selector));
 	atk_object_set_name (a11y, _("Contact Source Selector"));

Modified: trunk/calendar/gui/calendar-component.c
==============================================================================
--- trunk/calendar/gui/calendar-component.c	(original)
+++ trunk/calendar/gui/calendar-component.c	Mon Nov 17 21:09:36 2008
@@ -1002,88 +1002,6 @@
 }
 
 static gboolean
-selector_tree_drag_drop (GtkWidget *widget,
-			 GdkDragContext *context,
-			 int x,
-			 int y,
-			 guint time,
-			 CalendarComponent *component)
-{
-	GtkTreeViewColumn *column;
-	int cell_x;
-	int cell_y;
-	GtkTreePath *path;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	gpointer data;
-
-	if (!gtk_tree_view_get_path_at_pos  (GTK_TREE_VIEW (widget), x, y, &path,
-					     &column, &cell_x, &cell_y))
-		return FALSE;
-
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path)) {
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data)) {
-		g_object_unref (data);
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_path_free (path);
-	return TRUE;
-}
-
-static gboolean
-selector_tree_drag_motion (GtkWidget *widget,
-			   GdkDragContext *context,
-			   int x,
-			   int y,
-			   guint time,
-			   gpointer user_data)
-{
-	GtkTreePath *path = NULL;
-	gpointer data = NULL;
-	GtkTreeViewDropPosition pos;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	GdkDragAction action = GDK_ACTION_DEFAULT;
-
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data) || e_source_get_readonly (data))
-		goto finish;
-
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
-	action = context->suggested_action;
-
- finish:
-	if (path)
-		gtk_tree_path_free (path);
-	if (data)
-		g_object_unref (data);
-
-	gdk_drag_status (context, action, time);
-	return TRUE;
-}
-
-static gboolean
 update_single_object (ECal *client, icalcomponent *icalcomp)
 {
 	char *uid;
@@ -1137,52 +1055,29 @@
 	return TRUE;
 }
 
-static void
-selector_tree_drag_data_received (GtkWidget *widget,
-				  GdkDragContext *context,
-				  gint x,
-				  gint y,
-				  GtkSelectionData *data,
-				  guint info,
-				  guint time,
-				  gpointer user_data)
-{
-	GtkTreePath *path = NULL;
-	GtkTreeViewDropPosition pos;
-	gpointer source = NULL;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
+static gboolean
+selector_tree_data_dropped (ESourceSelector *selector,
+                            GtkSelectionData *data,
+                            ESource *destination,
+                            GdkDragAction action,
+                            guint info)
+{
 	gboolean success = FALSE;
 	icalcomponent *icalcomp = NULL;
 	ECal *client = NULL;
 
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-
-	gtk_tree_model_get (model, &iter, 0, &source, -1);
-
-	if (E_IS_SOURCE_GROUP (source) || e_source_get_readonly (source))
-		goto finish;
-
 	icalcomp = icalparser_parse_string ((char *)data->data);
 
 	if (icalcomp) {
 		char * uid;
 
 		/* FIXME deal with GDK_ACTION_ASK */
-		if (context->action == GDK_ACTION_COPY) {
+		if (action == GDK_ACTION_COPY) {
 			uid = e_cal_component_gen_uid ();
 			icalcomponent_set_uid (icalcomp, uid);
 		}
 
-		client = auth_new_cal_from_source (source,
+		client = auth_new_cal_from_source (destination,
 						   E_CAL_SOURCE_TYPE_EVENT);
 
 		if (client) {
@@ -1197,20 +1092,7 @@
 		icalcomponent_free (icalcomp);
 	}
 
- finish:
-	if (source)
-		g_object_unref (source);
-	if (path)
-		gtk_tree_path_free (path);
-
-	gtk_drag_finish (context, success, context->action == GDK_ACTION_MOVE, time);
-}
-
-static void
-selector_tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
-{
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget),
-					NULL, GTK_TREE_VIEW_DROP_BEFORE);
+	return success;
 }
 
 static void
@@ -1422,14 +1304,9 @@
 	a11y = gtk_widget_get_accessible (GTK_WIDGET (component_view->source_selector));
 	atk_object_set_name (a11y, _("Calendar Source Selector"));
 
-	g_signal_connect (component_view->source_selector, "drag-motion", G_CALLBACK (selector_tree_drag_motion),
-			  calendar_component);
-	g_signal_connect (component_view->source_selector, "drag-leave", G_CALLBACK (selector_tree_drag_leave),
-			  calendar_component);
-	g_signal_connect (component_view->source_selector, "drag-drop", G_CALLBACK (selector_tree_drag_drop),
-			  calendar_component);
-	g_signal_connect (component_view->source_selector, "drag-data-received",
-			  G_CALLBACK (selector_tree_drag_data_received), calendar_component);
+	g_signal_connect (
+		component_view->source_selector, "data-dropped",
+		G_CALLBACK (selector_tree_data_dropped), NULL);
 
 	gtk_drag_dest_set(component_view->source_selector, GTK_DEST_DEFAULT_ALL, drag_types,
 			  num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE);

Modified: trunk/calendar/gui/memos-component.c
==============================================================================
--- trunk/calendar/gui/memos-component.c	(original)
+++ trunk/calendar/gui/memos-component.c	Mon Nov 17 21:09:36 2008
@@ -638,90 +638,6 @@
 }
 
 static gboolean
-selector_tree_drag_drop (GtkWidget *widget,
-			 GdkDragContext *context,
-			 int x,
-			 int y,
-			 guint time,
-			 CalendarComponent *component)
-{
-	GtkTreeViewColumn *column;
-	int cell_x;
-	int cell_y;
-	GtkTreePath *path;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	gpointer data;
-
-	if (!gtk_tree_view_get_path_at_pos  (GTK_TREE_VIEW (widget), x, y, &path,
-					     &column, &cell_x, &cell_y))
-		return FALSE;
-
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path)) {
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data)) {
-		g_object_unref (data);
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_path_free (path);
-	return TRUE;
-}
-
-static gboolean
-selector_tree_drag_motion (GtkWidget *widget,
-			   GdkDragContext *context,
-			   int x,
-			   int y,
-			   guint time,
-			   gpointer user_data)
-{
-	GtkTreePath *path = NULL;
-	gpointer data = NULL;
-	GtkTreeViewDropPosition pos;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	GdkDragAction action = GDK_ACTION_DEFAULT;
-
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data) || e_source_get_readonly (data))
-		goto finish;
-
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
-	action = context->suggested_action;
-	if (action == GDK_ACTION_COPY && (context->actions & GDK_ACTION_MOVE))
-		action=GDK_ACTION_MOVE;
-
- finish:
-	if (path)
-		gtk_tree_path_free (path);
-	if (data)
-		g_object_unref (data);
-
-	gdk_drag_status (context, action, time);
-	return TRUE;
-}
-
-static gboolean
 update_single_object (ECal *client, icalcomponent *icalcomp, gboolean fail_on_modify)
 {
 	char *uid;
@@ -782,43 +698,21 @@
 	return TRUE;
 }
 
-static void
-selector_tree_drag_data_received (GtkWidget *widget,
-				  GdkDragContext *context,
-				  gint x,
-				  gint y,
-				  GtkSelectionData *data,
-				  guint info,
-				  guint time,
-				  gpointer user_data)
-{
-	GtkTreePath *path = NULL;
-	GtkTreeViewDropPosition pos;
-	gpointer source = NULL;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
+static gboolean
+selector_tree_data_dropped (ESourceSelector *selector,
+                            GtkSelectionData *data,
+                            ESource *destination,
+                            GdkDragAction action,
+                            guint info,
+                            MemosComponent *component)
+{
 	gboolean success = FALSE;
 	icalcomponent *icalcomp = NULL;
 	ECal *client = NULL;
 	GSList *components, *p;
-	MemosComponent *component = MEMOS_COMPONENT (user_data);
-
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
 
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-
-	gtk_tree_model_get (model, &iter, 0, &source, -1);
-
-	if (E_IS_SOURCE_GROUP (source) || e_source_get_readonly (source) || !data->data)
-		goto finish;
-
-	client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_JOURNAL);
+	client = auth_new_cal_from_source (
+		destination, E_CAL_SOURCE_TYPE_JOURNAL);
 
 	if (!client || !e_cal_open (client, TRUE, NULL))
 		goto  finish;
@@ -844,7 +738,7 @@
 			continue;
 
 		/* FIXME deal with GDK_ACTION_ASK */
-		if (context->action == GDK_ACTION_COPY) {
+		if (action == GDK_ACTION_COPY) {
 			old_uid = g_strdup (icalcomponent_get_uid (icalcomp));
 			uid = e_cal_component_gen_uid ();
 			icalcomponent_set_uid (icalcomp, uid);
@@ -861,7 +755,7 @@
 				/* this will report success by last item, but we don't care */
 				success = update_objects (client, icalcomp);
 
-				if (success && context->action == GDK_ACTION_MOVE) {
+				if (success && action == GDK_ACTION_MOVE) {
 					/* remove components rather here, because we know which has been moved */
 					ESource *source_source;
 					ECal *source_client;
@@ -901,23 +795,11 @@
  finish:
 	if (client)
 		g_object_unref (client);
-	if (source)
-		g_object_unref (source);
-	if (path)
-		gtk_tree_path_free (path);
 
-	gtk_drag_finish (context, success, success && context->action == GDK_ACTION_MOVE, time);
+	return success;
 }
 
 static void
-selector_tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
-{
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget),
-					NULL, GTK_TREE_VIEW_DROP_BEFORE);
-}
-
-
-static void
 control_activate_cb (BonoboControl *control, gboolean activate, gpointer data)
 {
 	MemosComponentView *component_view = data;
@@ -1113,14 +995,9 @@
 	a11y = gtk_widget_get_accessible (GTK_WIDGET (component_view->source_selector));
 	atk_object_set_name (a11y, _("Memo Source Selector"));
 
-	g_signal_connect (component_view->source_selector, "drag-motion", G_CALLBACK (selector_tree_drag_motion),
-			  memos_component);
-	g_signal_connect (component_view->source_selector, "drag-leave", G_CALLBACK (selector_tree_drag_leave),
-			  memos_component);
-	g_signal_connect (component_view->source_selector, "drag-drop", G_CALLBACK (selector_tree_drag_drop),
-			  memos_component);
-	g_signal_connect (component_view->source_selector, "drag-data-received",
-			  G_CALLBACK (selector_tree_drag_data_received), memos_component);
+	g_signal_connect (
+		component_view->source_selector, "data-dropped",
+		G_CALLBACK (selector_tree_data_dropped), memos_component);
 
 	gtk_drag_dest_set(component_view->source_selector, GTK_DEST_DEFAULT_ALL, drag_types,
 			  num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE);

Modified: trunk/calendar/gui/tasks-component.c
==============================================================================
--- trunk/calendar/gui/tasks-component.c	(original)
+++ trunk/calendar/gui/tasks-component.c	Mon Nov 17 21:09:36 2008
@@ -629,90 +629,6 @@
 }
 
 static gboolean
-selector_tree_drag_drop (GtkWidget *widget,
-			 GdkDragContext *context,
-			 int x,
-			 int y,
-			 guint time,
-			 CalendarComponent *component)
-{
-	GtkTreeViewColumn *column;
-	int cell_x;
-	int cell_y;
-	GtkTreePath *path;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	gpointer data;
-
-	if (!gtk_tree_view_get_path_at_pos  (GTK_TREE_VIEW (widget), x, y, &path,
-					     &column, &cell_x, &cell_y))
-		return FALSE;
-
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path)) {
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data)) {
-		g_object_unref (data);
-		gtk_tree_path_free (path);
-		return FALSE;
-	}
-
-	gtk_tree_path_free (path);
-	return TRUE;
-}
-
-static gboolean
-selector_tree_drag_motion (GtkWidget *widget,
-			   GdkDragContext *context,
-			   int x,
-			   int y,
-			   guint time,
-			   gpointer user_data)
-{
-	GtkTreePath *path = NULL;
-	gpointer data = NULL;
-	GtkTreeViewDropPosition pos;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	GdkDragAction action = GDK_ACTION_DEFAULT;
-
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
-
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-	gtk_tree_model_get (model, &iter, 0, &data, -1);
-
-	if (E_IS_SOURCE_GROUP (data) || e_source_get_readonly (data))
-		goto finish;
-
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
-	action = context->suggested_action;
-	if (action == GDK_ACTION_COPY && (context->actions & GDK_ACTION_MOVE))
-		action=GDK_ACTION_MOVE;
-
- finish:
-	if (path)
-		gtk_tree_path_free (path);
-	if (data)
-		g_object_unref (data);
-
-	gdk_drag_status (context, action, time);
-	return TRUE;
-}
-
-static gboolean
 update_single_object (ECal *client, icalcomponent *icalcomp)
 {
 	char *uid;
@@ -766,43 +682,21 @@
 	return TRUE;
 }
 
-static void
-selector_tree_drag_data_received (GtkWidget *widget,
-				  GdkDragContext *context,
-				  gint x,
-				  gint y,
-				  GtkSelectionData *data,
-				  guint info,
-				  guint time,
-				  gpointer user_data)
-{
-	GtkTreePath *path = NULL;
-	GtkTreeViewDropPosition pos;
-	gpointer source = NULL;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
+static gboolean
+selector_tree_data_dropped (ESourceSelector *selector,
+                            GtkSelectionData *data,
+                            ESource *destination,
+                            GdkDragAction action,
+                            guint info,
+                            TasksComponent *component)
+{
 	gboolean success = FALSE;
 	icalcomponent *icalcomp = NULL;
 	ECal *client = NULL;
 	GSList *components, *p;
-	TasksComponent *component = TASKS_COMPONENT (user_data);
-
-	if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
-						x, y, &path, &pos))
-		goto finish;
-
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
 
-	if (!gtk_tree_model_get_iter (model, &iter, path))
-		goto finish;
-
-
-	gtk_tree_model_get (model, &iter, 0, &source, -1);
-
-	if (E_IS_SOURCE_GROUP (source) || e_source_get_readonly (source) || !data->data)
-		goto finish;
-
-	client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_TODO);
+	client = auth_new_cal_from_source (
+		destination, E_CAL_SOURCE_TYPE_TODO);
 
 	if (!client || !e_cal_open (client, TRUE, NULL))
 		goto  finish;
@@ -828,7 +722,7 @@
 			continue;
 
 		/* FIXME deal with GDK_ACTION_ASK */
-		if (context->action == GDK_ACTION_COPY) {
+		if (action == GDK_ACTION_COPY) {
 			old_uid = g_strdup (icalcomponent_get_uid (icalcomp));
 			uid = e_cal_component_gen_uid ();
 			icalcomponent_set_uid (icalcomp, uid);
@@ -845,7 +739,7 @@
 				/* this will report success by last item, but we don't care */
 				success = update_objects (client, icalcomp);
 
-				if (success && context->action == GDK_ACTION_MOVE) {
+				if (success && action == GDK_ACTION_MOVE) {
 					/* remove components rather here, because we know which has been moved */
 					ESource *source_source;
 					ECal *source_client;
@@ -885,23 +779,11 @@
  finish:
 	if (client)
 		g_object_unref (client);
-	if (source)
-		g_object_unref (source);
-	if (path)
-		gtk_tree_path_free (path);
 
-	gtk_drag_finish (context, success, context->action == GDK_ACTION_MOVE, time);
+	return success;
 }
 
 static void
-selector_tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
-{
-	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW (widget),
-					NULL, GTK_TREE_VIEW_DROP_BEFORE);
-}
-
-
-static void
 control_activate_cb (BonoboControl *control, gboolean activate, gpointer data)
 {
 	TasksComponentView *component_view = data;
@@ -1102,14 +984,9 @@
 	a11y = gtk_widget_get_accessible (GTK_WIDGET (component_view->source_selector));
 	atk_object_set_name (a11y, _("Task Source Selector"));
 
-	g_signal_connect (component_view->source_selector, "drag-motion", G_CALLBACK (selector_tree_drag_motion),
-			  tasks_component);
-	g_signal_connect (component_view->source_selector, "drag-leave", G_CALLBACK (selector_tree_drag_leave),
-			  tasks_component);
-	g_signal_connect (component_view->source_selector, "drag-drop", G_CALLBACK (selector_tree_drag_drop),
-			  tasks_component);
-	g_signal_connect (component_view->source_selector, "drag-data-received",
-			  G_CALLBACK (selector_tree_drag_data_received), tasks_component);
+	g_signal_connect (
+		component_view->source_selector, "data-dropped",
+		G_CALLBACK (selector_tree_data_dropped), tasks_component);
 
 	gtk_drag_dest_set(component_view->source_selector, GTK_DEST_DEFAULT_ALL, drag_types,
 			  num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE);



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