comparison src/gtk/dnd.c @ 56:a12bcbc2fce4

2002-11-11 Brian Masney <masneyb@gftp.org> * src/gtk/dnd.c - fixes to DnD code * src/gtk/gftp-gtk.[ch] - added main_thread_id variable * src/gtk/misc-gtk.c (ftp_log) - don't check the user_data to see if we're in a child thread, instead compare the value of pthread_self() with main_thread_id * src/gtk/chmod_dialog.c src/gtk/delete_dialog.c src/gtk/menu-items.c src/gtk/mkdir_dialog.c src/gtk/rename_dialog.c src/gtk/transfer.c - don't set user_data to 0x1 if we're in a child thread * lib/gftp.h src/gtk/misc-gtk.c src/text/gftp-text.c - make r_getservbyname() available even if HAVE_GERADDRINFO is defined * lib/misc.c (make_ssh_exec_args) - if port is zero, lookup the default port for the ssh service * lib/protocols.c (gftp_connect_server) - if the port is zero, store the default port for that protocol there * src/gtk/transfer.c - added function update_window_transfer_bytes(). Be able to update the directory download progress in window1 now * lib/config_file.c lib/misc.c lib/protocols.c lib/ssh.c lib/sshv2.c src/text/gftp-text.c - use g_strdup() instead of g_strconcat() where needed
author masneyb
date Mon, 11 Nov 2002 23:16:12 +0000
parents d433c1417d7d
children c01d91c10f6c
comparison
equal deleted inserted replaced
55:518c3872d198 56:a12bcbc2fce4
22 22
23 23
24 static int 24 static int
25 dnd_remote_file (char *url, gftp_window_data * wdata) 25 dnd_remote_file (char *url, gftp_window_data * wdata)
26 { 26 {
27 gftp_window_data * other_wdata, * fromwdata;
27 gftp_request * current_ftpdata; 28 gftp_request * current_ftpdata;
28 gftp_file * newfle; 29 gftp_file * newfle;
29 char *str, *pos; 30 GList * templist;
30 GList templist; 31 char *pos;
31 int i; 32
32 33 if (wdata == &window1)
33 printf ("FIXME - in dnd_remote file\n"); 34 other_wdata = &window2;
35 else if (wdata == &window2)
36 other_wdata = &window1;
37 else
38 other_wdata = NULL;
39
34 newfle = g_malloc0 (sizeof (*newfle)); 40 newfle = g_malloc0 (sizeof (*newfle));
35 newfle->shown = 1; 41 newfle->shown = 1;
36 if (url[strlen (url) - 1] == '/') 42 if (url[strlen (url) - 1] == '/')
37 { 43 {
38 newfle->isdir = 1; 44 newfle->isdir = 1;
40 } 46 }
41 47
42 current_ftpdata = gftp_request_new (); 48 current_ftpdata = gftp_request_new ();
43 current_ftpdata->logging_function = ftp_log; 49 current_ftpdata->logging_function = ftp_log;
44 50
45 if (gftp_parse_url (current_ftpdata, url) != 0) 51 if (gftp_parse_url (current_ftpdata, url) != 0 ||
52 current_ftpdata->directory == NULL ||
53 (pos = strrchr (current_ftpdata->directory, '/')) == NULL)
46 { 54 {
47 ftp_log (gftp_logging_misc, NULL, 55 ftp_log (gftp_logging_misc, NULL,
48 _("Drag-N-Drop: Ignoring url %s: Not a valid url\n"), url); 56 _("Drag-N-Drop: Ignoring url %s: Not a valid url\n"), url);
49 gftp_request_destroy (current_ftpdata); 57 gftp_request_destroy (current_ftpdata);
50 free_fdata (newfle); 58 free_fdata (newfle);
51 return (0); 59 return (0);
52 } 60 }
53 61
54 if ((str = GFTP_GET_DIRECTORY (current_ftpdata)) != NULL) 62 *pos++ = '\0';
55 {
56 if ((pos = strrchr (str, '/')) == NULL)
57 pos = str;
58 else pos++;
59 *(pos - 1) = '\0';
60 i = 1;
61 }
62 else
63 {
64 pos = str = GFTP_GET_DIRECTORY (current_ftpdata);
65 i = 0;
66 }
67
68 if (compare_request (current_ftpdata, wdata->request, 1)) 63 if (compare_request (current_ftpdata, wdata->request, 1))
69 { 64 {
70 gftp_request_destroy (current_ftpdata); 65 gftp_request_destroy (current_ftpdata);
71 return (0); 66 return (0);
72 } 67 }
73 68
74 if (i) 69 if (other_wdata != NULL &&
75 { 70 compare_request (current_ftpdata, other_wdata->request, 1))
76 *(pos - 1) = '/'; 71 {
77 newfle->file = g_malloc (strlen (str) + 1); 72 gftp_set_password (current_ftpdata, other_wdata->request->password);
78 strcpy (newfle->file, str); 73 fromwdata = other_wdata;
79 *(pos - 1) = '\0';
80 } 74 }
81 else 75 else
82 { 76 fromwdata = NULL;
83 newfle->file = g_malloc (strlen (str) + 1); 77
84 strcpy (newfle->file, str); 78 *(pos - 1) = '/';
85 } 79 newfle->file = g_malloc (strlen (current_ftpdata->directory) + 1);
80 strcpy (newfle->file, current_ftpdata->directory);
81 *(pos - 1) = '\0';
86 82
87 newfle->destfile = g_strconcat (GFTP_GET_DIRECTORY (wdata->request), 83 newfle->destfile = g_strconcat (GFTP_GET_DIRECTORY (wdata->request),
88 "/", pos, NULL); 84 "/", pos, NULL);
89 newfle->ascii = gftp_get_file_transfer_mode (newfle->file, 85 newfle->ascii = gftp_get_file_transfer_mode (newfle->file,
90 wdata->request->data_type) == GFTP_TYPE_ASCII; 86 wdata->request->data_type) == GFTP_TYPE_ASCII;
91 87
92 templist.data = newfle; 88 templist = g_malloc0 (sizeof (*templist));
93 templist.next = NULL; 89 templist->data = newfle;
94 add_file_transfer (current_ftpdata, wdata->request, NULL, 90 templist->next = NULL;
95 wdata, &templist, 1); 91 add_file_transfer (current_ftpdata, wdata->request, fromwdata,
92 wdata, templist, 1);
96 gftp_request_destroy (current_ftpdata); 93 gftp_request_destroy (current_ftpdata);
97 94
98 if (newfle->isdir) 95 if (newfle->isdir)
99 { 96 {
100 /* FIXME - need to fix this 97 /* FIXME - need to fix this
101 add_entire_directory (tdata, newfle, 98 add_entire_directory (tdata, newfle,
102 GFTP_GET_DIRECTORY (tdata->fromhdata->ftpdata), 99 GFTP_GET_DIRECTORY (tdata->fromhdata->ftpdata),
103 GFTP_GET_DIRECTORY (tdata->tohdata->ftpdata), 100 GFTP_GET_DIRECTORY (tdata->tohdata->ftpdata),
104 tdata->fromhdata->ftpdata); 101 tdata->fromhdata->ftpdata);
105 */ 102 */
162 continue; 159 continue;
163 160
164 oldlen = totlen; 161 oldlen = totlen;
165 if (GFTP_GET_HOSTNAME (wdata->request) == NULL) 162 if (GFTP_GET_HOSTNAME (wdata->request) == NULL)
166 { 163 {
167 tempstr = g_strdup_printf ("%s://%s/%s%c", 164 tempstr = g_strdup_printf ("%s://%s/%s ",
168 GFTP_GET_URL_PREFIX (wdata->request), 165 GFTP_GET_URL_PREFIX (wdata->request),
169 GFTP_GET_DIRECTORY (wdata->request), 166 GFTP_GET_DIRECTORY (wdata->request),
170 tempfle->file, tempfle->isdir ? '/' : '\0'); 167 tempfle->file);
171 } 168 }
172 else if (GFTP_GET_USERNAME (wdata->request) == NULL 169 else if (GFTP_GET_USERNAME (wdata->request) == NULL
173 || *GFTP_GET_USERNAME (wdata->request) == '\0') 170 || *GFTP_GET_USERNAME (wdata->request) == '\0')
174 { 171 {
175 tempstr = g_strdup_printf ("%s://%s:%d%s/%s%c", 172 tempstr = g_strdup_printf ("%s://%s:%d%s/%s ",
176 GFTP_GET_URL_PREFIX (wdata->request), 173 GFTP_GET_URL_PREFIX (wdata->request),
177 GFTP_GET_HOSTNAME (wdata->request), 174 GFTP_GET_HOSTNAME (wdata->request),
178 GFTP_GET_PORT (wdata->request), 175 GFTP_GET_PORT (wdata->request),
179 GFTP_GET_DIRECTORY (wdata->request), 176 GFTP_GET_DIRECTORY (wdata->request),
180 tempfle->file, tempfle->isdir ? '/' : '\0'); 177 tempfle->file);
181 } 178 }
182 else 179 else
183 { 180 {
184 tempstr = g_strdup_printf ("%s://%s@%s:%d%s/%s%c", 181 tempstr = g_strdup_printf ("%s://%s@%s:%d%s/%s ",
185 GFTP_GET_URL_PREFIX (wdata->request), 182 GFTP_GET_URL_PREFIX (wdata->request),
186 GFTP_GET_USERNAME (wdata->request), 183 GFTP_GET_USERNAME (wdata->request),
187 GFTP_GET_HOSTNAME (wdata->request), 184 GFTP_GET_HOSTNAME (wdata->request),
188 GFTP_GET_PORT (wdata->request), 185 GFTP_GET_PORT (wdata->request),
189 GFTP_GET_DIRECTORY (wdata->request), 186 GFTP_GET_DIRECTORY (wdata->request),
190 tempfle->file, tempfle->isdir ? '/' : '\0'); 187 tempfle->file);
191 } 188 }
189
192 if ((pos = strchr (tempstr, ':')) != NULL) 190 if ((pos = strchr (tempstr, ':')) != NULL)
193 pos += 2; 191 pos += 2;
194 else 192 else
195 pos = tempstr; 193 pos = tempstr;
196 remove_double_slashes (pos); 194 remove_double_slashes (pos);
195
196 /* Note, I am allocating memory for this byte above. Note the extra space
197 at the end of the g_strdup_printf() format argument */
198 if (tempfle->isdir)
199 tempstr[strlen (tempstr) - 1] = '/';
200 else
201 tempstr[strlen (tempstr) - 1] = '\0';
202
197 totlen += strlen (tempstr); 203 totlen += strlen (tempstr);
198 if (str != NULL) 204 if (str != NULL)
199 { 205 {
200 totlen++; 206 totlen++;
201 str = g_realloc (str, totlen + 1); 207 str = g_realloc (str, totlen + 1);
234 240
235 finish_drag = 0; 241 finish_drag = 0;
236 if ((selection_data->length >= 0) && (selection_data->format == 8)) 242 if ((selection_data->length >= 0) && (selection_data->format == 8))
237 { 243 {
238 oldpos = (char *) selection_data->data; 244 oldpos = (char *) selection_data->data;
239 printf ("FIXME - got data %s\n", oldpos);
240 while ((newpos = strchr (oldpos, '\n')) || 245 while ((newpos = strchr (oldpos, '\n')) ||
241 (newpos = strchr (oldpos, '\0'))) 246 (newpos = strchr (oldpos, '\0')))
242 { 247 {
243 tempchar = *newpos; 248 tempchar = *newpos;
244 *newpos = '\0'; 249 *newpos = '\0';