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
|
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 {
|
67
|
55 gftp_request_destroy (current_ftpdata, 1);
|
48
|
56 free_fdata (newfle);
|
|
57 return (0);
|
|
58 }
|
|
59
|
56
|
60 *pos++ = '\0';
|
48
|
61 if (compare_request (current_ftpdata, wdata->request, 1))
|
50
|
62 {
|
67
|
63 gftp_request_destroy (current_ftpdata, 1);
|
50
|
64 return (0);
|
|
65 }
|
48
|
66
|
56
|
67 if (other_wdata != NULL &&
|
|
68 compare_request (current_ftpdata, other_wdata->request, 1))
|
48
|
69 {
|
65
|
70 if (other_wdata->request->password != NULL)
|
|
71 gftp_set_password (current_ftpdata, other_wdata->request->password);
|
|
72
|
56
|
73 fromwdata = other_wdata;
|
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);
|
56
|
83 templist = g_malloc0 (sizeof (*templist));
|
|
84 templist->data = newfle;
|
|
85 templist->next = NULL;
|
|
86 add_file_transfer (current_ftpdata, wdata->request, fromwdata,
|
|
87 wdata, templist, 1);
|
67
|
88 gftp_request_destroy (current_ftpdata, 1);
|
48
|
89
|
58
|
90 /* FIXME resume files and download entire directories */
|
|
91
|
48
|
92 return (1);
|
|
93 }
|
|
94
|
1
|
95
|
|
96 void
|
|
97 openurl_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
98 gint y, GtkSelectionData * selection_data, guint info,
|
|
99 guint32 clk_time, gpointer data)
|
|
100 {
|
|
101 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
102 {
|
|
103 if (gftp_parse_url (current_wdata->request,
|
|
104 (char *) selection_data->data) == 0)
|
|
105 {
|
|
106 if (GFTP_IS_CONNECTED (current_wdata->request))
|
|
107 disconnect (current_wdata);
|
|
108
|
|
109 ftp_connect (current_wdata, current_wdata->request, 1);
|
|
110 }
|
|
111 }
|
|
112 }
|
|
113
|
|
114
|
|
115 void
|
|
116 listbox_drag (GtkWidget * widget, GdkDragContext * context,
|
|
117 GtkSelectionData * selection_data, guint info, guint32 clk_time,
|
|
118 gpointer data)
|
|
119 {
|
|
120 GList * templist, * filelist;
|
|
121 char *tempstr, *str, *pos;
|
|
122 gftp_window_data * wdata;
|
|
123 size_t totlen, oldlen;
|
|
124 gftp_file * tempfle;
|
|
125 int curpos;
|
|
126
|
|
127 totlen = 0;
|
|
128 str = NULL;
|
|
129 wdata = data;
|
|
130 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 1, 1))
|
|
131 return;
|
|
132
|
|
133 filelist = wdata->files;
|
|
134 templist = GTK_CLIST (wdata->listbox)->selection;
|
|
135 curpos = 0;
|
|
136 while (templist != NULL)
|
|
137 {
|
|
138 templist = get_next_selection (templist, &filelist, &curpos);
|
|
139 tempfle = filelist->data;
|
|
140
|
|
141 if (strcmp (tempfle->file, "..") == 0)
|
|
142 continue;
|
|
143
|
|
144 oldlen = totlen;
|
129
|
145 if (wdata->request->hostname == NULL ||
|
65
|
146 wdata->request->protonum == GFTP_LOCAL_NUM)
|
1
|
147 {
|
56
|
148 tempstr = g_strdup_printf ("%s://%s/%s ",
|
129
|
149 wdata->request->url_prefix,
|
|
150 wdata->request->directory,
|
56
|
151 tempfle->file);
|
1
|
152 }
|
129
|
153 else if (wdata->request->username == NULL
|
|
154 || *wdata->request->username == '\0')
|
1
|
155 {
|
56
|
156 tempstr = g_strdup_printf ("%s://%s:%d%s/%s ",
|
129
|
157 wdata->request->url_prefix,
|
|
158 wdata->request->hostname,
|
|
159 wdata->request->port,
|
|
160 wdata->request->directory,
|
56
|
161 tempfle->file);
|
1
|
162 }
|
|
163 else
|
|
164 {
|
56
|
165 tempstr = g_strdup_printf ("%s://%s@%s:%d%s/%s ",
|
129
|
166 wdata->request->url_prefix,
|
|
167 wdata->request->username,
|
|
168 wdata->request->hostname,
|
|
169 wdata->request->port,
|
|
170 wdata->request->directory,
|
56
|
171 tempfle->file);
|
1
|
172 }
|
56
|
173
|
1
|
174 if ((pos = strchr (tempstr, ':')) != NULL)
|
65
|
175 pos += 3;
|
1
|
176 else
|
|
177 pos = tempstr;
|
|
178 remove_double_slashes (pos);
|
56
|
179
|
|
180 /* Note, I am allocating memory for this byte above. Note the extra space
|
|
181 at the end of the g_strdup_printf() format argument */
|
|
182 if (tempfle->isdir)
|
|
183 tempstr[strlen (tempstr) - 1] = '/';
|
|
184 else
|
|
185 tempstr[strlen (tempstr) - 1] = '\0';
|
|
186
|
1
|
187 totlen += strlen (tempstr);
|
|
188 if (str != NULL)
|
|
189 {
|
|
190 totlen++;
|
|
191 str = g_realloc (str, totlen + 1);
|
|
192 strcpy (str + oldlen, "\n");
|
|
193 strcpy (str + oldlen + 1, tempstr);
|
|
194 }
|
|
195 else
|
|
196 {
|
|
197 str = g_malloc (totlen + 1);
|
|
198 strcpy (str, tempstr);
|
|
199 }
|
|
200 g_free (tempstr);
|
|
201 }
|
|
202
|
|
203 if (str != NULL)
|
|
204 {
|
|
205 gtk_selection_data_set (selection_data, selection_data->target, 8,
|
|
206 (unsigned char *) str, strlen (str));
|
|
207 g_free (str);
|
|
208 }
|
|
209 }
|
|
210
|
|
211
|
|
212 void
|
|
213 listbox_get_drag_data (GtkWidget * widget, GdkDragContext * context, gint x,
|
|
214 gint y, GtkSelectionData * selection_data, guint info,
|
|
215 guint32 clk_time, gpointer data)
|
|
216 {
|
|
217 char *newpos, *oldpos, tempchar;
|
|
218 gftp_window_data * wdata;
|
|
219 int finish_drag;
|
|
220
|
|
221 wdata = data;
|
|
222 if (!check_status (_("Drag-N-Drop"), wdata, 1, 0, 0, 1))
|
|
223 return;
|
|
224
|
|
225 finish_drag = 0;
|
|
226 if ((selection_data->length >= 0) && (selection_data->format == 8))
|
|
227 {
|
|
228 oldpos = (char *) selection_data->data;
|
50
|
229 while ((newpos = strchr (oldpos, '\n')) ||
|
|
230 (newpos = strchr (oldpos, '\0')))
|
1
|
231 {
|
|
232 tempchar = *newpos;
|
|
233 *newpos = '\0';
|
|
234 ftp_log (gftp_logging_misc, NULL, _("Received URL %s\n"), oldpos);
|
50
|
235 if (dnd_remote_file (oldpos, wdata))
|
1
|
236 finish_drag = 1;
|
|
237
|
|
238 if (*newpos == '\0')
|
|
239 break;
|
|
240 oldpos = newpos + 1;
|
|
241 }
|
|
242 }
|
|
243
|
|
244 gtk_drag_finish (context, finish_drag, FALSE, clk_time);
|
|
245 }
|