1
|
1 /*****************************************************************************/
|
|
2 /* dnd.c - drag and drop functions */
|
|
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
|
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp-gtk.h"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
48
|
23
|
|
24 static int
|
50
|
25 dnd_remote_file (char *url, gftp_window_data * wdata)
|
48
|
26 {
|
56
|
27 gftp_window_data * other_wdata, * fromwdata;
|
48
|
28 gftp_request * current_ftpdata;
|
|
29 gftp_file * newfle;
|
56
|
30 GList * templist;
|
|
31 char *pos;
|
48
|
32
|
56
|
33 if (wdata == &window1)
|
|
34 other_wdata = &window2;
|
|
35 else if (wdata == &window2)
|
|
36 other_wdata = &window1;
|
|
37 else
|
|
38 other_wdata = NULL;
|
|
39
|
48
|
40 newfle = g_malloc0 (sizeof (*newfle));
|
|
41 newfle->shown = 1;
|
|
42 if (url[strlen (url) - 1] == '/')
|
|
43 {
|
|
44 newfle->isdir = 1;
|
|
45 url[strlen (url) - 1] = '\0';
|
|
46 }
|
|
47
|
|
48 current_ftpdata = gftp_request_new ();
|
|
49 current_ftpdata->logging_function = ftp_log;
|
|
50
|
56
|
51 if (gftp_parse_url (current_ftpdata, url) != 0 ||
|
|
52 current_ftpdata->directory == NULL ||
|
|
53 (pos = strrchr (current_ftpdata->directory, '/')) == NULL)
|
48
|
54 {
|
|
55 ftp_log (gftp_logging_misc, NULL,
|
|
56 _("Drag-N-Drop: Ignoring url %s: Not a valid url\n"), url);
|
67
|
57 gftp_request_destroy (current_ftpdata, 1);
|
48
|
58 free_fdata (newfle);
|
|
59 return (0);
|
|
60 }
|
|
61
|
56
|
62 *pos++ = '\0';
|
48
|
63 if (compare_request (current_ftpdata, wdata->request, 1))
|
50
|
64 {
|
67
|
65 gftp_request_destroy (current_ftpdata, 1);
|
50
|
66 return (0);
|
|
67 }
|
48
|
68
|
56
|
69 if (other_wdata != NULL &&
|
|
70 compare_request (current_ftpdata, other_wdata->request, 1))
|
48
|
71 {
|
65
|
72 if (other_wdata->request->password != NULL)
|
|
73 gftp_set_password (current_ftpdata, other_wdata->request->password);
|
|
74
|
56
|
75 fromwdata = other_wdata;
|
48
|
76 }
|
|
77 else
|
56
|
78 fromwdata = NULL;
|
|
79
|
|
80 *(pos - 1) = '/';
|
|
81 newfle->file = g_malloc (strlen (current_ftpdata->directory) + 1);
|
|
82 strcpy (newfle->file, current_ftpdata->directory);
|
|
83 *(pos - 1) = '\0';
|
48
|
84
|
|
85 newfle->destfile = g_strconcat (GFTP_GET_DIRECTORY (wdata->request),
|
|
86 "/", pos, NULL);
|
56
|
87 templist = g_malloc0 (sizeof (*templist));
|
|
88 templist->data = newfle;
|
|
89 templist->next = NULL;
|
|
90 add_file_transfer (current_ftpdata, wdata->request, fromwdata,
|
|
91 wdata, templist, 1);
|
67
|
92 gftp_request_destroy (current_ftpdata, 1);
|
48
|
93
|
58
|
94 /* FIXME resume files and download entire directories */
|
|
95
|
48
|
96 return (1);
|
|
97 }
|
|
98
|
1
|
99
|
|
100 void
|
|
101 openurl_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
102 gint y, GtkSelectionData * selection_data, guint info,
|
|
103 guint32 clk_time, gpointer data)
|
|
104 {
|
|
105 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
106 {
|
|
107 if (gftp_parse_url (current_wdata->request,
|
|
108 (char *) selection_data->data) == 0)
|
|
109 {
|
|
110 if (GFTP_IS_CONNECTED (current_wdata->request))
|
|
111 disconnect (current_wdata);
|
|
112
|
|
113 ftp_connect (current_wdata, current_wdata->request, 1);
|
|
114 }
|
|
115 else
|
|
116 {
|
|
117 ftp_log (gftp_logging_misc, NULL, _("Could not parse URL %s\n"),
|
|
118 selection_data->data);
|
|
119 }
|
|
120 }
|
|
121 }
|
|
122
|
|
123
|
|
124 void
|
|
125 listbox_drag (GtkWidget * widget, GdkDragContext * context,
|
|
126 GtkSelectionData * selection_data, guint info, guint32 clk_time,
|
|
127 gpointer data)
|
|
128 {
|
|
129 GList * templist, * filelist;
|
|
130 char *tempstr, *str, *pos;
|
|
131 gftp_window_data * wdata;
|
|
132 size_t totlen, oldlen;
|
|
133 gftp_file * tempfle;
|
|
134 int curpos;
|
|
135
|
|
136 totlen = 0;
|
|
137 str = NULL;
|
|
138 wdata = data;
|
|
139 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 1, 1))
|
|
140 return;
|
|
141
|
|
142 filelist = wdata->files;
|
|
143 templist = GTK_CLIST (wdata->listbox)->selection;
|
|
144 curpos = 0;
|
|
145 while (templist != NULL)
|
|
146 {
|
|
147 templist = get_next_selection (templist, &filelist, &curpos);
|
|
148 tempfle = filelist->data;
|
|
149
|
|
150 if (strcmp (tempfle->file, "..") == 0)
|
|
151 continue;
|
|
152
|
|
153 oldlen = totlen;
|
65
|
154 if (GFTP_GET_HOSTNAME (wdata->request) == NULL ||
|
|
155 wdata->request->protonum == GFTP_LOCAL_NUM)
|
1
|
156 {
|
56
|
157 tempstr = g_strdup_printf ("%s://%s/%s ",
|
1
|
158 GFTP_GET_URL_PREFIX (wdata->request),
|
|
159 GFTP_GET_DIRECTORY (wdata->request),
|
56
|
160 tempfle->file);
|
1
|
161 }
|
|
162 else if (GFTP_GET_USERNAME (wdata->request) == NULL
|
|
163 || *GFTP_GET_USERNAME (wdata->request) == '\0')
|
|
164 {
|
56
|
165 tempstr = g_strdup_printf ("%s://%s:%d%s/%s ",
|
1
|
166 GFTP_GET_URL_PREFIX (wdata->request),
|
|
167 GFTP_GET_HOSTNAME (wdata->request),
|
|
168 GFTP_GET_PORT (wdata->request),
|
|
169 GFTP_GET_DIRECTORY (wdata->request),
|
56
|
170 tempfle->file);
|
1
|
171 }
|
|
172 else
|
|
173 {
|
56
|
174 tempstr = g_strdup_printf ("%s://%s@%s:%d%s/%s ",
|
1
|
175 GFTP_GET_URL_PREFIX (wdata->request),
|
|
176 GFTP_GET_USERNAME (wdata->request),
|
|
177 GFTP_GET_HOSTNAME (wdata->request),
|
|
178 GFTP_GET_PORT (wdata->request),
|
|
179 GFTP_GET_DIRECTORY (wdata->request),
|
56
|
180 tempfle->file);
|
1
|
181 }
|
56
|
182
|
1
|
183 if ((pos = strchr (tempstr, ':')) != NULL)
|
65
|
184 pos += 3;
|
1
|
185 else
|
|
186 pos = tempstr;
|
|
187 remove_double_slashes (pos);
|
56
|
188
|
|
189 /* Note, I am allocating memory for this byte above. Note the extra space
|
|
190 at the end of the g_strdup_printf() format argument */
|
|
191 if (tempfle->isdir)
|
|
192 tempstr[strlen (tempstr) - 1] = '/';
|
|
193 else
|
|
194 tempstr[strlen (tempstr) - 1] = '\0';
|
|
195
|
1
|
196 totlen += strlen (tempstr);
|
|
197 if (str != NULL)
|
|
198 {
|
|
199 totlen++;
|
|
200 str = g_realloc (str, totlen + 1);
|
|
201 strcpy (str + oldlen, "\n");
|
|
202 strcpy (str + oldlen + 1, tempstr);
|
|
203 }
|
|
204 else
|
|
205 {
|
|
206 str = g_malloc (totlen + 1);
|
|
207 strcpy (str, tempstr);
|
|
208 }
|
|
209 g_free (tempstr);
|
|
210 }
|
|
211
|
|
212 if (str != NULL)
|
|
213 {
|
|
214 gtk_selection_data_set (selection_data, selection_data->target, 8,
|
|
215 (unsigned char *) str, strlen (str));
|
|
216 g_free (str);
|
|
217 }
|
|
218 }
|
|
219
|
|
220
|
|
221 void
|
|
222 listbox_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
223 gint y, GtkSelectionData * selection_data, guint info,
|
|
224 guint32 clk_time, gpointer data)
|
|
225 {
|
|
226 char *newpos, *oldpos, tempchar;
|
|
227 gftp_window_data * wdata;
|
|
228 int finish_drag;
|
|
229
|
|
230 wdata = data;
|
|
231 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 0, 1))
|
|
232 return;
|
|
233
|
|
234 finish_drag = 0;
|
|
235 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
236 {
|
|
237 oldpos = (char *) selection_data->data;
|
50
|
238 while ((newpos = strchr (oldpos, '\n')) ||
|
|
239 (newpos = strchr (oldpos, '\0')))
|
1
|
240 {
|
|
241 tempchar = *newpos;
|
|
242 *newpos = '\0';
|
|
243 ftp_log (gftp_logging_misc, NULL, _("Received URL %s\n"), oldpos);
|
50
|
244 if (dnd_remote_file (oldpos, wdata))
|
1
|
245 finish_drag = 1;
|
|
246
|
|
247 if (*newpos == '\0')
|
|
248 break;
|
|
249 oldpos = newpos + 1;
|
|
250 }
|
|
251 }
|
|
252
|
|
253 gtk_drag_finish (context, finish_drag, FALSE, clk_time);
|
|
254 }
|
|
255
|