342
|
1 /*****************************************************************************/
|
|
2 /* gtkui.c - GTK+ UI related functions for gFTP */
|
|
3 /* Copyright (C) 1998-2003 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"
|
|
21 static const char cvsid[] = "$Id$";
|
|
22
|
|
23
|
|
24 void
|
|
25 gftpui_lookup_file_colors (gftp_file * fle, char **start_color,
|
|
26 char ** end_color)
|
|
27 {
|
|
28 *start_color = GFTPUI_COMMON_COLOR_NONE;
|
|
29 *end_color = GFTPUI_COMMON_COLOR_NONE;
|
|
30 }
|
|
31
|
|
32
|
|
33 void
|
|
34 gftpui_run_command (GtkWidget * widget, gpointer data)
|
|
35 {
|
|
36 const char *txt;
|
|
37
|
|
38 txt = gtk_entry_get_text (GTK_ENTRY (gftpui_command_widget));
|
374
|
39 gftpui_common_process_command (&window1, window1.request,
|
|
40 &window2, window2.request, txt);
|
342
|
41 gtk_entry_set_text (GTK_ENTRY (gftpui_command_widget), "");
|
|
42 }
|
|
43
|
|
44
|
|
45 void
|
|
46 gftpui_refresh (void *uidata)
|
|
47 {
|
|
48 gftp_window_data * wdata;
|
|
49
|
|
50 wdata = uidata;
|
|
51 if (!check_status (_("Refresh"), wdata, 0, 0, 0, 1))
|
|
52 return;
|
|
53
|
|
54 if (check_reconnect (wdata) < 0)
|
|
55 return;
|
|
56
|
|
57 gtk_clist_freeze (GTK_CLIST (wdata->listbox));
|
|
58 remove_files_window (wdata);
|
|
59 gftp_delete_cache_entry (wdata->request, NULL, 0);
|
|
60 ftp_list_files (wdata, 0);
|
|
61 gtk_clist_thaw (GTK_CLIST (wdata->listbox));
|
|
62 }
|
|
63
|
|
64
|
356
|
65 #define _GFTPUI_GTK_USER_PW_SIZE 256
|
|
66
|
|
67 static void
|
380
|
68 _gftpui_gtk_set_username (gftp_request * request, gftp_dialog_data * ddata)
|
356
|
69 {
|
380
|
70 gftp_set_username (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit)));
|
|
71 request->stopable = 0;
|
|
72 }
|
|
73
|
|
74
|
|
75 static void
|
|
76 _gftpui_gtk_set_password (gftp_request * request, gftp_dialog_data * ddata)
|
|
77 {
|
|
78 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit)));
|
|
79 request->stopable = 0;
|
356
|
80 }
|
|
81
|
|
82
|
|
83 static void
|
380
|
84 _gftpui_gtk_abort (gftp_request * request, gftp_dialog_data * ddata)
|
356
|
85 {
|
380
|
86 request->stopable = 0;
|
356
|
87 }
|
|
88
|
|
89
|
380
|
90 void
|
356
|
91 gftpui_prompt_username (void *uidata, gftp_request * request)
|
|
92 {
|
|
93 MakeEditDialog (_("Enter Username"),
|
|
94 _("Please enter your username for this site"), NULL,
|
|
95 0, NULL, gftp_dialog_button_connect,
|
380
|
96 _gftpui_gtk_set_username, request,
|
|
97 _gftpui_gtk_abort, request);
|
356
|
98
|
380
|
99 request->stopable = 1;
|
|
100 while (request->stopable)
|
356
|
101 {
|
|
102 GDK_THREADS_LEAVE ();
|
|
103 #if GTK_MAJOR_VERSION == 1
|
|
104 g_main_iteration (TRUE);
|
|
105 #else
|
|
106 g_main_context_iteration (NULL, TRUE);
|
|
107 #endif
|
|
108 }
|
|
109 }
|
|
110
|
|
111
|
380
|
112 void
|
356
|
113 gftpui_prompt_password (void *uidata, gftp_request * request)
|
|
114 {
|
|
115 MakeEditDialog (_("Enter Password"),
|
|
116 _("Please enter your password for this site"), NULL,
|
|
117 0, NULL, gftp_dialog_button_connect,
|
380
|
118 _gftpui_gtk_set_password, request,
|
|
119 _gftpui_gtk_abort, request);
|
356
|
120
|
380
|
121 request->stopable = 1;
|
|
122 while (request->stopable)
|
356
|
123 {
|
|
124 GDK_THREADS_LEAVE ();
|
|
125 #if GTK_MAJOR_VERSION == 1
|
|
126 g_main_iteration (TRUE);
|
|
127 #else
|
|
128 g_main_context_iteration (NULL, TRUE);
|
|
129 #endif
|
|
130 }
|
|
131 }
|
|
132
|
|
133
|
355
|
134 /* The wakeup main thread functions are so that after the thread terminates
|
|
135 there won't be a delay in updating the GUI */
|
|
136 static void
|
|
137 _gftpui_wakeup_main_thread (gpointer data, gint source,
|
|
138 GdkInputCondition condition)
|
|
139 {
|
|
140 gftp_request * request;
|
|
141 char c;
|
|
142
|
|
143 request = data;
|
|
144 if (request->wakeup_main_thread[0] > 0)
|
|
145 read (request->wakeup_main_thread[0], &c, 1);
|
|
146 }
|
|
147
|
|
148
|
|
149 static gint
|
|
150 _gftpui_setup_wakeup_main_thread (gftp_request * request)
|
|
151 {
|
|
152 gint handler;
|
|
153
|
|
154 if (socketpair (AF_UNIX, SOCK_STREAM, 0, request->wakeup_main_thread) == 0)
|
|
155 {
|
|
156 handler = gdk_input_add (request->wakeup_main_thread[0],
|
|
157 GDK_INPUT_READ, _gftpui_wakeup_main_thread,
|
|
158 request);
|
|
159 }
|
|
160 else
|
|
161 {
|
|
162 request->wakeup_main_thread[0] = 0;
|
|
163 request->wakeup_main_thread[1] = 0;
|
|
164 handler = 0;
|
|
165 }
|
|
166
|
|
167 return (handler);
|
|
168 }
|
|
169
|
|
170
|
|
171 static void
|
|
172 _gftpui_teardown_wakeup_main_thread (gftp_request * request, gint handler)
|
|
173 {
|
|
174 if (request->wakeup_main_thread[0] > 0 && request->wakeup_main_thread[1] > 0)
|
|
175 {
|
|
176 gdk_input_remove (handler);
|
|
177 close (request->wakeup_main_thread[0]);
|
|
178 close (request->wakeup_main_thread[1]);
|
|
179 request->wakeup_main_thread[0] = 0;
|
|
180 request->wakeup_main_thread[1] = 0;
|
|
181 }
|
|
182 }
|
|
183
|
|
184 static void *
|
|
185 _gftpui_gtk_thread_func (void *data)
|
|
186 {
|
|
187 gftpui_gtk_thread_data * thread_data;
|
|
188 void *ret;
|
|
189
|
|
190 thread_data = data;
|
|
191 ret = thread_data->func (thread_data->cdata);
|
|
192
|
|
193 if (thread_data->cdata->request->wakeup_main_thread[1] > 0)
|
|
194 write (thread_data->cdata->request->wakeup_main_thread[1], " ", 1);
|
|
195
|
|
196 return (ret);
|
|
197 }
|
|
198
|
|
199
|
342
|
200 void *
|
|
201 gftpui_generic_thread (void * (*func) (void *), void *data)
|
|
202 {
|
355
|
203 gftpui_gtk_thread_data * thread_data;
|
342
|
204 gftpui_callback_data * cdata;
|
|
205 gftp_window_data * wdata;
|
355
|
206 guint handler;
|
342
|
207 void * ret;
|
|
208
|
|
209 cdata = data;
|
|
210 wdata = cdata->uidata;
|
|
211
|
|
212 wdata->request->stopable = 1;
|
|
213 gtk_widget_set_sensitive (stop_btn, 1);
|
355
|
214
|
|
215 thread_data = g_malloc0 (sizeof (*thread_data));
|
|
216 thread_data->func = func;
|
|
217 thread_data->cdata = cdata;
|
|
218
|
|
219 handler = _gftpui_setup_wakeup_main_thread (cdata->request);
|
|
220 pthread_create (&wdata->tid, NULL, _gftpui_gtk_thread_func, thread_data);
|
342
|
221
|
|
222 while (wdata->request->stopable)
|
|
223 {
|
|
224 GDK_THREADS_LEAVE ();
|
|
225 #if GTK_MAJOR_VERSION == 1
|
|
226 g_main_iteration (TRUE);
|
|
227 #else
|
|
228 g_main_context_iteration (NULL, TRUE);
|
|
229 #endif
|
|
230 }
|
|
231
|
355
|
232 _gftpui_teardown_wakeup_main_thread (cdata->request, handler);
|
|
233 g_free (thread_data);
|
|
234
|
342
|
235 pthread_join (wdata->tid, &ret);
|
|
236 gtk_widget_set_sensitive (stop_btn, 0);
|
|
237
|
|
238 if (!GFTP_IS_CONNECTED (wdata->request))
|
380
|
239 gftpui_disconnect (wdata);
|
342
|
240
|
|
241 return (ret);
|
|
242 }
|
|
243
|
|
244
|
|
245 int
|
|
246 gftpui_check_reconnect (gftpui_callback_data * cdata)
|
|
247 {
|
|
248 gftp_window_data * wdata;
|
|
249
|
|
250 wdata = cdata->uidata;
|
|
251 return (wdata->request->cached && wdata->request->datafd < 0 &&
|
|
252 !wdata->request->always_connected &&
|
|
253 !ftp_connect (wdata, wdata->request, 0) ? -1 : 0);
|
|
254 }
|
|
255
|
|
256
|
|
257 void
|
|
258 gftpui_run_function_callback (gftp_window_data * wdata,
|
|
259 gftp_dialog_data * ddata)
|
|
260 {
|
|
261 gftpui_callback_data * cdata;
|
|
262 const char *edttext;
|
|
263 int ret;
|
|
264
|
|
265 cdata = ddata->yespointer;
|
|
266 if (ddata->edit != NULL)
|
|
267 {
|
|
268 edttext = gtk_entry_get_text (GTK_ENTRY (ddata->edit));
|
|
269 if (*edttext == '\0')
|
|
270 {
|
|
271 ftp_log (gftp_logging_misc, NULL,
|
|
272 _("Operation canceled...you must enter a string\n"));
|
|
273 return;
|
|
274 }
|
|
275
|
|
276 cdata->input_string = g_strdup (edttext);
|
|
277 }
|
|
278
|
|
279 ret = gftpui_common_run_callback_function (cdata);
|
|
280 }
|
|
281
|
|
282
|
|
283 void
|
|
284 gftpui_run_function_cancel_callback (gftp_window_data * wdata,
|
|
285 gftp_dialog_data * ddata)
|
|
286 {
|
|
287 gftpui_callback_data * cdata;
|
|
288
|
|
289 cdata = ddata->yespointer;
|
|
290 if (cdata->input_string != NULL)
|
|
291 g_free (cdata->input_string);
|
|
292 if (cdata->source_string != NULL)
|
|
293 g_free (cdata->source_string);
|
|
294 g_free (cdata);
|
|
295 }
|
|
296
|
|
297
|
|
298 void
|
|
299 gftpui_mkdir_dialog (gpointer data)
|
|
300 {
|
|
301 gftpui_callback_data * cdata;
|
|
302 gftp_window_data * wdata;
|
|
303
|
|
304 wdata = data;
|
|
305 cdata = g_malloc0 (sizeof (*cdata));
|
|
306 cdata->request = wdata->request;
|
|
307 cdata->uidata = wdata;
|
|
308 cdata->run_function = gftpui_common_run_mkdir;
|
|
309
|
|
310 if (!check_status (_("Mkdir"), wdata, gftpui_common_use_threads (wdata->request), 0, 0, wdata->request->mkdir != NULL))
|
|
311 return;
|
|
312
|
|
313 MakeEditDialog (_("Make Directory"), _("Enter name of directory to create"),
|
|
314 NULL, 1, NULL, gftp_dialog_button_create,
|
|
315 gftpui_run_function_callback, cdata,
|
|
316 gftpui_run_function_cancel_callback, cdata);
|
|
317 }
|
|
318
|
|
319
|
|
320 void
|
|
321 gftpui_rename_dialog (gpointer data)
|
|
322 {
|
|
323 gftpui_callback_data * cdata;
|
|
324 GList *templist, *filelist;
|
|
325 gftp_window_data * wdata;
|
|
326 gftp_file * curfle;
|
|
327 char *tempstr;
|
|
328 int num;
|
|
329
|
|
330 wdata = data;
|
|
331 cdata = g_malloc0 (sizeof (*cdata));
|
|
332 cdata->request = wdata->request;
|
|
333 cdata->uidata = wdata;
|
|
334 cdata->run_function = gftpui_common_run_rename;
|
|
335
|
|
336 if (!check_status (_("Rename"), wdata, gftpui_common_use_threads (wdata->request), 1, 1, wdata->request->rename != NULL))
|
|
337 return;
|
|
338
|
|
339 templist = GTK_CLIST (wdata->listbox)->selection;
|
|
340 num = 0;
|
|
341 filelist = wdata->files;
|
|
342 templist = get_next_selection (templist, &filelist, &num);
|
|
343 curfle = filelist->data;
|
|
344 cdata->source_string = g_strdup (curfle->file);
|
|
345
|
|
346 tempstr = g_strdup_printf (_("What would you like to rename %s to?"),
|
|
347 cdata->source_string);
|
|
348 MakeEditDialog (_("Rename"), tempstr, cdata->source_string, 1, NULL,
|
|
349 gftp_dialog_button_rename,
|
|
350 gftpui_run_function_callback, cdata,
|
|
351 gftpui_run_function_cancel_callback, cdata);
|
|
352 g_free (tempstr);
|
|
353 }
|
|
354
|
|
355
|
|
356 void
|
|
357 gftpui_site_dialog (gpointer data)
|
|
358 {
|
|
359 gftpui_callback_data * cdata;
|
|
360 gftp_window_data * wdata;
|
|
361
|
|
362 wdata = data;
|
|
363 cdata = g_malloc0 (sizeof (*cdata));
|
|
364 cdata->request = wdata->request;
|
|
365 cdata->uidata = wdata;
|
|
366 cdata->run_function = gftpui_common_run_site;
|
|
367
|
|
368 if (!check_status (_("Site"), wdata, 0, 0, 0, wdata->request->site != NULL))
|
|
369 return;
|
|
370
|
|
371 MakeEditDialog (_("Site"), _("Enter site-specific command"), NULL, 1,
|
|
372 NULL, gftp_dialog_button_ok,
|
|
373 gftpui_run_function_callback, cdata,
|
|
374 gftpui_run_function_cancel_callback, cdata);
|
|
375 }
|
|
376
|
|
377
|
|
378 int
|
|
379 gftpui_run_chdir (gpointer uidata, char *directory)
|
|
380 {
|
|
381 gftpui_callback_data * cdata;
|
|
382 gftp_window_data * wdata;
|
|
383 int ret;
|
|
384
|
|
385 wdata = uidata;
|
|
386 cdata = g_malloc0 (sizeof (*cdata));
|
|
387 cdata->request = wdata->request;
|
|
388 cdata->uidata = wdata;
|
|
389 cdata->run_function = gftpui_common_run_chdir;
|
|
390 cdata->input_string = directory;
|
|
391
|
|
392 ret = gftpui_common_run_callback_function (cdata);
|
|
393
|
|
394 g_free (cdata);
|
|
395 return (ret);
|
|
396 }
|
|
397
|
|
398
|
|
399 void
|
|
400 gftpui_chdir_dialog (gpointer data)
|
|
401 {
|
|
402 GList *templist, *filelist;
|
|
403 gftp_window_data * wdata;
|
|
404 gftp_file * curfle;
|
|
405 char *tempstr;
|
|
406 int num;
|
|
407
|
|
408 wdata = data;
|
|
409 if (!check_status (_("Chdir"), wdata, gftpui_common_use_threads (wdata->request), 1, 0,
|
|
410 wdata->request->chdir != NULL))
|
|
411 return;
|
|
412
|
|
413 templist = GTK_CLIST (wdata->listbox)->selection;
|
|
414 num = 0;
|
|
415 filelist = wdata->files;
|
|
416 templist = get_next_selection (templist, &filelist, &num);
|
|
417 curfle = filelist->data;
|
|
418
|
|
419 tempstr = gftp_build_path (wdata->request->directory, curfle->file, NULL);
|
|
420 gftpui_run_chdir (wdata, tempstr);
|
|
421 g_free (tempstr);
|
|
422 }
|
|
423
|
380
|
424
|
|
425 void
|
|
426 gftpui_disconnect (void *uidata)
|
|
427 {
|
|
428 gftp_window_data * wdata;
|
|
429
|
|
430 wdata = uidata;
|
|
431 gftp_delete_cache_entry (wdata->request, NULL, 1);
|
|
432 gftp_disconnect (wdata->request);
|
|
433 remove_files_window (wdata);
|
|
434 update_window (wdata);
|
|
435 }
|
|
436
|
397
|
437
|
|
438 char *
|
|
439 gftpui_gtk_get_utf8_file_pos (gftp_file * fle)
|
|
440 {
|
|
441 char *disp_item, *pos;
|
|
442
|
|
443 if (fle->utf8_file != NULL)
|
|
444 disp_item = fle->utf8_file;
|
|
445 else
|
|
446 disp_item = fle->file;
|
|
447
|
|
448 if ((pos = strrchr (disp_item, '/')) != NULL)
|
|
449 pos++;
|
|
450 else
|
|
451 pos = disp_item;
|
|
452
|
|
453 return (pos);
|
|
454 }
|
|
455
|