More work on merging history view
[ephy-soc.git] / lib / ephy-dnd.c
blob2f76fcd9af89c9d552866be7294aea5ef88985e3
1 /*
2 * Copyright © 2000, 2001, 2002 Marco Pesenti Gritti
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * $Id: ephy-dnd.c 6952 2007-03-11 19:42:02Z chpe $
21 #include "config.h"
23 #include "ephy-dnd.h"
24 #include "ephy-node.h"
26 #include <gtk/gtkselection.h>
27 #include <gtk/gtktreeview.h>
28 #include <string.h>
30 /* Encode a "_NETSCAPE_URL_" selection.
31 * As far as I can tell, Netscape is expecting a single
32 * URL to be returned. I cannot discover a way to construct
33 * a list to be returned that Netscape can understand.
34 * GMC also fails to do this as well.
36 static void
37 add_one_netscape_url (const char *url, const char *title, gpointer data)
39 GString *result;
41 result = (GString *) data;
42 if (result->len == 0)
44 g_string_append (result, url);
45 if (title)
47 g_string_append (result, "\n");
48 g_string_append (result, title);
53 static void
54 add_one_uri (const char *uri, const char *title, gpointer data)
56 GString *result;
58 result = (GString *) data;
60 g_string_append (result, uri);
61 g_string_append (result, "\r\n");
64 static void
65 add_one_topic (const char *uri, const char *title, gpointer data)
67 GString *result;
69 result = (GString *) data;
71 g_string_append (result, uri);
72 g_string_append (result, "\r\n");
75 gboolean
76 ephy_dnd_drag_data_get (GtkWidget *widget,
77 GdkDragContext *context,
78 GtkSelectionData *selection_data,
79 guint32 time,
80 gpointer container_context,
81 EphyDragEachSelectedItemIterator each_selected_item_iterator)
83 GString *result = NULL;
84 GdkAtom target;
86 target = selection_data->target;
88 if (target == gdk_atom_intern (EPHY_DND_URI_LIST_TYPE, FALSE) ||
89 target == gdk_atom_intern (EPHY_DND_TEXT_TYPE, FALSE))
91 result = g_string_new (NULL);
92 (* each_selected_item_iterator) (add_one_uri, container_context, result);
94 else if (target == gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE))
96 result = g_string_new (NULL);
97 (* each_selected_item_iterator) (add_one_netscape_url, container_context, result);
99 else if (target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE))
101 result = g_string_new (NULL);
102 (* each_selected_item_iterator) (add_one_topic, container_context, result);
103 g_string_erase (result, result->len - 2, -1);
105 else
107 g_assert_not_reached ();
110 gtk_selection_data_set (selection_data,
111 selection_data->target,
112 8, (const guchar *) result->str, result->len);
114 g_string_free (result, TRUE);
116 return TRUE;