1
|
1 /*****************************************************************************/
|
|
2 /* dnd.c - drag and drop functions */
|
255
|
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
|
1
|
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
|
382
|
25 dnd_remote_file (gftp_window_data * wdata, GList ** trans_list, char *url)
|
48
|
26 {
|
|
27 gftp_request * current_ftpdata;
|
518
|
28 gftp_window_data * fromwdata;
|
382
|
29 gftp_transfer * tdata;
|
48
|
30 gftp_file * newfle;
|
56
|
31 GList * templist;
|
|
32 char *pos;
|
48
|
33
|
56
|
34 if (wdata == &window1)
|
518
|
35 fromwdata = &window2;
|
56
|
36 else if (wdata == &window2)
|
518
|
37 fromwdata = &window1;
|
56
|
38 else
|
518
|
39 fromwdata = NULL;
|
56
|
40
|
48
|
41 newfle = g_malloc0 (sizeof (*newfle));
|
|
42 newfle->shown = 1;
|
|
43 if (url[strlen (url) - 1] == '/')
|
|
44 {
|
499
|
45 newfle->st_mode |= S_IFDIR;
|
48
|
46 url[strlen (url) - 1] = '\0';
|
|
47 }
|
|
48
|
|
49 current_ftpdata = gftp_request_new ();
|
|
50 current_ftpdata->logging_function = ftp_log;
|
|
51
|
56
|
52 if (gftp_parse_url (current_ftpdata, url) != 0 ||
|
|
53 current_ftpdata->directory == NULL ||
|
|
54 (pos = strrchr (current_ftpdata->directory, '/')) == NULL)
|
48
|
55 {
|
67
|
56 gftp_request_destroy (current_ftpdata, 1);
|
598
|
57 gftp_file_destroy (newfle, 1);
|
48
|
58 return (0);
|
|
59 }
|
|
60
|
56
|
61 *pos++ = '\0';
|
48
|
62 if (compare_request (current_ftpdata, wdata->request, 1))
|
50
|
63 {
|
67
|
64 gftp_request_destroy (current_ftpdata, 1);
|
598
|
65 gftp_file_destroy (newfle, 1);
|
50
|
66 return (0);
|
|
67 }
|
48
|
68
|
518
|
69 if (fromwdata != NULL &&
|
|
70 compare_request (current_ftpdata, fromwdata->request, 0))
|
48
|
71 {
|
518
|
72 if (fromwdata->request->password != NULL)
|
|
73 gftp_set_password (current_ftpdata, fromwdata->request->password);
|
48
|
74 }
|
|
75 else
|
56
|
76 fromwdata = NULL;
|
|
77
|
|
78 *(pos - 1) = '/';
|
129
|
79 newfle->file = g_strdup (current_ftpdata->directory);
|
56
|
80 *(pos - 1) = '\0';
|
48
|
81
|
555
|
82 newfle->destfile = gftp_build_path (wdata->request,
|
|
83 wdata->request->directory, pos, NULL);
|
382
|
84
|
518
|
85 tdata = NULL;
|
382
|
86 for (templist = *trans_list; templist != NULL; templist = templist->next)
|
|
87 {
|
|
88 tdata = templist->data;
|
|
89 if (compare_request (current_ftpdata, tdata->fromreq, 0))
|
|
90 break;
|
|
91 }
|
|
92
|
518
|
93 if (templist == NULL || tdata == NULL)
|
382
|
94 {
|
|
95 tdata = gftp_tdata_new ();
|
48
|
96
|
382
|
97 tdata->fromreq = current_ftpdata;
|
|
98 tdata->fromwdata = fromwdata;
|
|
99
|
|
100 tdata->toreq = wdata->request;
|
|
101 tdata->towdata = wdata;
|
|
102
|
|
103 *trans_list = g_list_append (*trans_list, tdata);
|
|
104 }
|
|
105 else
|
|
106 gftp_request_destroy (current_ftpdata, 1);
|
|
107
|
|
108 tdata->files = g_list_append (tdata->files, newfle);
|
58
|
109
|
48
|
110 return (1);
|
|
111 }
|
|
112
|
1
|
113
|
|
114 void
|
|
115 openurl_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
116 gint y, GtkSelectionData * selection_data, guint info,
|
|
117 guint32 clk_time, gpointer data)
|
|
118 {
|
660
|
119 if (current_wdata->request->stopable)
|
|
120 {
|
677
|
121 ftp_log (gftp_logging_error, NULL,
|
660
|
122 _("%s: Please hit the stop button first to do anything else\n"),
|
|
123 _("Connect"));
|
|
124 return;
|
|
125 }
|
|
126
|
1
|
127 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
128 {
|
329
|
129 if (GFTP_IS_CONNECTED (current_wdata->request))
|
380
|
130 gftpui_disconnect (current_wdata);
|
329
|
131
|
1
|
132 if (gftp_parse_url (current_wdata->request,
|
|
133 (char *) selection_data->data) == 0)
|
472
|
134 {
|
|
135 ftp_log (gftp_logging_misc, NULL,
|
|
136 _("Received URL %s\n"), (char *) selection_data->data);
|
|
137
|
|
138 ftp_connect (current_wdata, current_wdata->request, 1);
|
|
139 }
|
1
|
140 }
|
|
141 }
|
|
142
|
|
143
|
|
144 void
|
|
145 listbox_drag (GtkWidget * widget, GdkDragContext * context,
|
|
146 GtkSelectionData * selection_data, guint info, guint32 clk_time,
|
|
147 gpointer data)
|
|
148 {
|
|
149 GList * templist, * filelist;
|
303
|
150 char *tempstr, *str, *df;
|
1
|
151 gftp_window_data * wdata;
|
|
152 size_t totlen, oldlen;
|
|
153 gftp_file * tempfle;
|
|
154 int curpos;
|
|
155
|
|
156 totlen = 0;
|
|
157 str = NULL;
|
|
158 wdata = data;
|
|
159 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 1, 1))
|
|
160 return;
|
|
161
|
|
162 filelist = wdata->files;
|
525
|
163 templist = gftp_gtk_get_list_selection (wdata);
|
1
|
164 curpos = 0;
|
|
165 while (templist != NULL)
|
|
166 {
|
|
167 templist = get_next_selection (templist, &filelist, &curpos);
|
|
168 tempfle = filelist->data;
|
|
169
|
|
170 if (strcmp (tempfle->file, "..") == 0)
|
|
171 continue;
|
|
172
|
|
173 oldlen = totlen;
|
555
|
174 df = gftp_build_path (wdata->request, wdata->request->directory,
|
|
175 tempfle->file, NULL);
|
303
|
176
|
129
|
177 if (wdata->request->hostname == NULL ||
|
65
|
178 wdata->request->protonum == GFTP_LOCAL_NUM)
|
1
|
179 {
|
303
|
180 tempstr = g_strdup_printf ("%s://%s ",
|
|
181 wdata->request->url_prefix, df);
|
1
|
182 }
|
303
|
183 else if (wdata->request->username == NULL ||
|
|
184 *wdata->request->username == '\0')
|
1
|
185 {
|
303
|
186 tempstr = g_strdup_printf ("%s://%s:%d%s ",
|
129
|
187 wdata->request->url_prefix,
|
|
188 wdata->request->hostname,
|
303
|
189 wdata->request->port, df);
|
1
|
190 }
|
|
191 else
|
|
192 {
|
303
|
193 tempstr = g_strdup_printf ("%s://%s@%s:%d%s ",
|
129
|
194 wdata->request->url_prefix,
|
|
195 wdata->request->username,
|
|
196 wdata->request->hostname,
|
303
|
197 wdata->request->port, df);
|
1
|
198 }
|
56
|
199
|
303
|
200 g_free (df);
|
56
|
201
|
|
202 /* Note, I am allocating memory for this byte above. Note the extra space
|
|
203 at the end of the g_strdup_printf() format argument */
|
499
|
204 if (S_ISDIR (tempfle->st_mode))
|
56
|
205 tempstr[strlen (tempstr) - 1] = '/';
|
|
206 else
|
|
207 tempstr[strlen (tempstr) - 1] = '\0';
|
|
208
|
1
|
209 totlen += strlen (tempstr);
|
|
210 if (str != NULL)
|
|
211 {
|
|
212 totlen++;
|
|
213 str = g_realloc (str, totlen + 1);
|
|
214 strcpy (str + oldlen, "\n");
|
|
215 strcpy (str + oldlen + 1, tempstr);
|
|
216 }
|
|
217 else
|
|
218 {
|
|
219 str = g_malloc (totlen + 1);
|
|
220 strcpy (str, tempstr);
|
|
221 }
|
|
222 g_free (tempstr);
|
|
223 }
|
|
224
|
|
225 if (str != NULL)
|
|
226 {
|
|
227 gtk_selection_data_set (selection_data, selection_data->target, 8,
|
|
228 (unsigned char *) str, strlen (str));
|
|
229 g_free (str);
|
|
230 }
|
|
231 }
|
|
232
|
|
233
|
|
234 void
|
|
235 listbox_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
236 gint y, GtkSelectionData * selection_data, guint info,
|
|
237 guint32 clk_time, gpointer data)
|
|
238 {
|
296
|
239 char *newpos, *oldpos, *tempstr;
|
382
|
240 GList * trans_list, * templist;
|
1
|
241 gftp_window_data * wdata;
|
382
|
242 gftp_transfer * tdata;
|
1
|
243 int finish_drag;
|
296
|
244 size_t len;
|
1
|
245
|
|
246 wdata = data;
|
|
247 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 0, 1))
|
|
248 return;
|
|
249
|
382
|
250 trans_list = NULL;
|
1
|
251 finish_drag = 0;
|
|
252 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
253 {
|
|
254 oldpos = (char *) selection_data->data;
|
50
|
255 while ((newpos = strchr (oldpos, '\n')) ||
|
|
256 (newpos = strchr (oldpos, '\0')))
|
1
|
257 {
|
296
|
258 len = newpos - oldpos;
|
|
259 if (oldpos[len - 1] == '\r')
|
|
260 len--;
|
|
261
|
|
262 if (len == 0)
|
|
263 break;
|
|
264
|
|
265 tempstr = g_malloc (len + 1);
|
|
266 memcpy (tempstr, oldpos, len);
|
|
267 tempstr[len] = '\0';
|
|
268
|
|
269 ftp_log (gftp_logging_misc, NULL, _("Received URL %s\n"), tempstr);
|
|
270
|
382
|
271 if (dnd_remote_file (wdata, &trans_list, tempstr))
|
1
|
272 finish_drag = 1;
|
382
|
273
|
296
|
274 g_free (tempstr);
|
|
275
|
1
|
276 if (*newpos == '\0')
|
|
277 break;
|
296
|
278
|
1
|
279 oldpos = newpos + 1;
|
|
280 }
|
|
281 }
|
|
282
|
|
283 gtk_drag_finish (context, finish_drag, FALSE, clk_time);
|
382
|
284
|
|
285 for (templist = trans_list; templist != NULL; templist = templist->next)
|
|
286 {
|
|
287 tdata = templist->data;
|
|
288
|
|
289 if (tdata->files == NULL || gftp_get_all_subdirs (tdata, NULL) != 0)
|
|
290 {
|
|
291 g_free (tdata);
|
|
292 continue;
|
|
293 }
|
|
294
|
|
295 if (tdata->files == NULL)
|
|
296 {
|
|
297 g_free (tdata);
|
|
298 continue;
|
|
299 }
|
|
300
|
|
301 gftpui_common_add_file_transfer (tdata->fromreq, tdata->toreq,
|
|
302 tdata->fromwdata, tdata->towdata,
|
|
303 tdata->files);
|
|
304 g_free (tdata);
|
|
305 }
|
|
306
|
|
307 g_list_free (trans_list);
|
1
|
308 }
|