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);
|
48
|
57 free_fdata (newfle);
|
|
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);
|
382
|
65 free_fdata (newfle);
|
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
|
245
|
82 newfle->destfile = gftp_build_path (wdata->request->directory, pos, NULL);
|
382
|
83
|
518
|
84 tdata = NULL;
|
382
|
85 for (templist = *trans_list; templist != NULL; templist = templist->next)
|
|
86 {
|
|
87 tdata = templist->data;
|
|
88 if (compare_request (current_ftpdata, tdata->fromreq, 0))
|
|
89 break;
|
|
90 }
|
|
91
|
518
|
92 if (templist == NULL || tdata == NULL)
|
382
|
93 {
|
|
94 tdata = gftp_tdata_new ();
|
48
|
95
|
382
|
96 tdata->fromreq = current_ftpdata;
|
|
97 tdata->fromwdata = fromwdata;
|
|
98
|
|
99 tdata->toreq = wdata->request;
|
|
100 tdata->towdata = wdata;
|
|
101
|
|
102 *trans_list = g_list_append (*trans_list, tdata);
|
|
103 }
|
|
104 else
|
|
105 gftp_request_destroy (current_ftpdata, 1);
|
|
106
|
|
107 tdata->files = g_list_append (tdata->files, newfle);
|
58
|
108
|
48
|
109 return (1);
|
|
110 }
|
|
111
|
1
|
112
|
|
113 void
|
|
114 openurl_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
115 gint y, GtkSelectionData * selection_data, guint info,
|
|
116 guint32 clk_time, gpointer data)
|
|
117 {
|
|
118 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
119 {
|
329
|
120 if (GFTP_IS_CONNECTED (current_wdata->request))
|
380
|
121 gftpui_disconnect (current_wdata);
|
329
|
122
|
1
|
123 if (gftp_parse_url (current_wdata->request,
|
|
124 (char *) selection_data->data) == 0)
|
472
|
125 {
|
|
126 ftp_log (gftp_logging_misc, NULL,
|
|
127 _("Received URL %s\n"), (char *) selection_data->data);
|
|
128
|
|
129 ftp_connect (current_wdata, current_wdata->request, 1);
|
|
130 }
|
1
|
131 }
|
|
132 }
|
|
133
|
|
134
|
|
135 void
|
|
136 listbox_drag (GtkWidget * widget, GdkDragContext * context,
|
|
137 GtkSelectionData * selection_data, guint info, guint32 clk_time,
|
|
138 gpointer data)
|
|
139 {
|
|
140 GList * templist, * filelist;
|
303
|
141 char *tempstr, *str, *df;
|
1
|
142 gftp_window_data * wdata;
|
|
143 size_t totlen, oldlen;
|
|
144 gftp_file * tempfle;
|
|
145 int curpos;
|
|
146
|
|
147 totlen = 0;
|
|
148 str = NULL;
|
|
149 wdata = data;
|
|
150 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 1, 1))
|
|
151 return;
|
|
152
|
|
153 filelist = wdata->files;
|
525
|
154 templist = gftp_gtk_get_list_selection (wdata);
|
1
|
155 curpos = 0;
|
|
156 while (templist != NULL)
|
|
157 {
|
|
158 templist = get_next_selection (templist, &filelist, &curpos);
|
|
159 tempfle = filelist->data;
|
|
160
|
|
161 if (strcmp (tempfle->file, "..") == 0)
|
|
162 continue;
|
|
163
|
|
164 oldlen = totlen;
|
303
|
165 df = gftp_build_path (wdata->request->directory, tempfle->file, NULL);
|
|
166
|
129
|
167 if (wdata->request->hostname == NULL ||
|
65
|
168 wdata->request->protonum == GFTP_LOCAL_NUM)
|
1
|
169 {
|
303
|
170 tempstr = g_strdup_printf ("%s://%s ",
|
|
171 wdata->request->url_prefix, df);
|
1
|
172 }
|
303
|
173 else if (wdata->request->username == NULL ||
|
|
174 *wdata->request->username == '\0')
|
1
|
175 {
|
303
|
176 tempstr = g_strdup_printf ("%s://%s:%d%s ",
|
129
|
177 wdata->request->url_prefix,
|
|
178 wdata->request->hostname,
|
303
|
179 wdata->request->port, df);
|
1
|
180 }
|
|
181 else
|
|
182 {
|
303
|
183 tempstr = g_strdup_printf ("%s://%s@%s:%d%s ",
|
129
|
184 wdata->request->url_prefix,
|
|
185 wdata->request->username,
|
|
186 wdata->request->hostname,
|
303
|
187 wdata->request->port, df);
|
1
|
188 }
|
56
|
189
|
303
|
190 g_free (df);
|
56
|
191
|
|
192 /* Note, I am allocating memory for this byte above. Note the extra space
|
|
193 at the end of the g_strdup_printf() format argument */
|
499
|
194 if (S_ISDIR (tempfle->st_mode))
|
56
|
195 tempstr[strlen (tempstr) - 1] = '/';
|
|
196 else
|
|
197 tempstr[strlen (tempstr) - 1] = '\0';
|
|
198
|
1
|
199 totlen += strlen (tempstr);
|
|
200 if (str != NULL)
|
|
201 {
|
|
202 totlen++;
|
|
203 str = g_realloc (str, totlen + 1);
|
|
204 strcpy (str + oldlen, "\n");
|
|
205 strcpy (str + oldlen + 1, tempstr);
|
|
206 }
|
|
207 else
|
|
208 {
|
|
209 str = g_malloc (totlen + 1);
|
|
210 strcpy (str, tempstr);
|
|
211 }
|
|
212 g_free (tempstr);
|
|
213 }
|
|
214
|
|
215 if (str != NULL)
|
|
216 {
|
|
217 gtk_selection_data_set (selection_data, selection_data->target, 8,
|
|
218 (unsigned char *) str, strlen (str));
|
|
219 g_free (str);
|
|
220 }
|
|
221 }
|
|
222
|
|
223
|
|
224 void
|
|
225 listbox_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
226 gint y, GtkSelectionData * selection_data, guint info,
|
|
227 guint32 clk_time, gpointer data)
|
|
228 {
|
296
|
229 char *newpos, *oldpos, *tempstr;
|
382
|
230 GList * trans_list, * templist;
|
1
|
231 gftp_window_data * wdata;
|
382
|
232 gftp_transfer * tdata;
|
1
|
233 int finish_drag;
|
296
|
234 size_t len;
|
1
|
235
|
|
236 wdata = data;
|
|
237 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 0, 1))
|
|
238 return;
|
|
239
|
382
|
240 trans_list = NULL;
|
1
|
241 finish_drag = 0;
|
|
242 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
243 {
|
|
244 oldpos = (char *) selection_data->data;
|
50
|
245 while ((newpos = strchr (oldpos, '\n')) ||
|
|
246 (newpos = strchr (oldpos, '\0')))
|
1
|
247 {
|
296
|
248 len = newpos - oldpos;
|
|
249 if (oldpos[len - 1] == '\r')
|
|
250 len--;
|
|
251
|
|
252 if (len == 0)
|
|
253 break;
|
|
254
|
|
255 tempstr = g_malloc (len + 1);
|
|
256 memcpy (tempstr, oldpos, len);
|
|
257 tempstr[len] = '\0';
|
|
258
|
|
259 ftp_log (gftp_logging_misc, NULL, _("Received URL %s\n"), tempstr);
|
|
260
|
382
|
261 if (dnd_remote_file (wdata, &trans_list, tempstr))
|
1
|
262 finish_drag = 1;
|
382
|
263
|
296
|
264 g_free (tempstr);
|
|
265
|
1
|
266 if (*newpos == '\0')
|
|
267 break;
|
296
|
268
|
1
|
269 oldpos = newpos + 1;
|
|
270 }
|
|
271 }
|
|
272
|
|
273 gtk_drag_finish (context, finish_drag, FALSE, clk_time);
|
382
|
274
|
|
275 for (templist = trans_list; templist != NULL; templist = templist->next)
|
|
276 {
|
|
277 tdata = templist->data;
|
|
278
|
|
279 if (tdata->files == NULL || gftp_get_all_subdirs (tdata, NULL) != 0)
|
|
280 {
|
|
281 g_free (tdata);
|
|
282 continue;
|
|
283 }
|
|
284
|
|
285 if (tdata->files == NULL)
|
|
286 {
|
|
287 g_free (tdata);
|
|
288 continue;
|
|
289 }
|
|
290
|
|
291 gftpui_common_add_file_transfer (tdata->fromreq, tdata->toreq,
|
|
292 tdata->fromwdata, tdata->towdata,
|
|
293 tdata->files);
|
|
294 g_free (tdata);
|
|
295 }
|
|
296
|
|
297 g_list_free (trans_list);
|
1
|
298 }
|