Mercurial > gftp.yaz
annotate src/gtk/gftp-gtk.c @ 596:9a8dc6ec713d
2004-10-27 Brian Masney <masneyb@gftp.org>
* he.po - added Hebrew translation
(from tamir <alcohollica@linux-kinneret.org>). This translation was
tested and approved by the Israeli Linux users on
http://www.whatsup.co.il
author | masneyb |
---|---|
date | Wed, 27 Oct 2004 22:07:03 +0000 |
parents | 7937ade77c22 |
children | 5df5eac28f47 |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* gftp-gtk.c - GTK+ 1.2 port of gftp */ | |
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 |
23 static GtkItemFactory *log_factory, *dl_factory; | |
24 static GtkWidget * local_frame, * remote_frame, * log_table, * transfer_scroll, | |
341 | 25 * openurl_btn, * gftpui_command_toolbar; |
1 | 26 |
27 gftp_window_data window1, window2, *other_wdata, *current_wdata; | |
28 GtkWidget * stop_btn, * hostedit, * useredit, * passedit, * portedit, * logwdw, | |
587 | 29 * dlwdw, * protocol_menu, * optionmenu, * gftpui_command_widget, |
30 * download_left_arrow, * upload_right_arrow; | |
1 | 31 GtkAdjustment * logwdw_vadj; |
45 | 32 #if GTK_MAJOR_VERSION > 1 |
1 | 33 GtkTextMark * logwdw_textmark; |
34 #endif | |
35 int local_start, remote_start, trans_start, log_start, tools_start; | |
36 GHashTable * graphic_hash_table = NULL; | |
37 GtkItemFactoryEntry * menus = NULL; | |
38 GtkItemFactory * factory = NULL; | |
39 pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; | |
19 | 40 gftp_graphic * gftp_icon; |
56 | 41 pthread_t main_thread_id; |
129 | 42 GList * viewedit_processes = NULL; |
42 | 43 |
48 | 44 static int |
45 get_column (GtkCListColumn * col) | |
1 | 46 { |
48 | 47 if (col->auto_resize) |
48 return (0); | |
49 else if (!col->visible) | |
50 return (-1); | |
51 else | |
52 return (col->width); | |
53 } | |
42 | 54 |
1 | 55 |
48 | 56 static void |
505 | 57 _gftp_exit (GtkWidget * widget, gpointer data) |
48 | 58 { |
472 | 59 intptr_t ret; |
129 | 60 |
61 ret = GTK_WIDGET (local_frame)->allocation.width; | |
227 | 62 gftp_set_global_option ("listbox_local_width", GINT_TO_POINTER (ret)); |
129 | 63 ret = GTK_WIDGET (remote_frame)->allocation.width; |
227 | 64 gftp_set_global_option ("listbox_remote_width", GINT_TO_POINTER (ret)); |
129 | 65 ret = GTK_WIDGET (remote_frame)->allocation.height; |
227 | 66 gftp_set_global_option ("listbox_file_height", GINT_TO_POINTER (ret)); |
129 | 67 ret = GTK_WIDGET (log_table)->allocation.height; |
227 | 68 gftp_set_global_option ("log_height", GINT_TO_POINTER (ret)); |
129 | 69 ret = GTK_WIDGET (transfer_scroll)->allocation.height; |
227 | 70 gftp_set_global_option ("transfer_height", GINT_TO_POINTER (ret)); |
129 | 71 |
72 ret = get_column (>K_CLIST (dlwdw)->column[0]); | |
227 | 73 gftp_set_global_option ("file_trans_column", GINT_TO_POINTER (ret)); |
1 | 74 |
129 | 75 ret = get_column (>K_CLIST (window1.listbox)->column[1]); |
227 | 76 gftp_set_global_option ("local_file_width", GINT_TO_POINTER (ret)); |
129 | 77 ret = get_column (>K_CLIST (window1.listbox)->column[2]); |
227 | 78 gftp_set_global_option ("local_size_width", GINT_TO_POINTER (ret)); |
129 | 79 ret = get_column (>K_CLIST (window1.listbox)->column[3]); |
227 | 80 gftp_set_global_option ("local_user_width", GINT_TO_POINTER (ret)); |
129 | 81 ret = get_column (>K_CLIST (window1.listbox)->column[4]); |
227 | 82 gftp_set_global_option ("local_group_width", GINT_TO_POINTER (ret)); |
129 | 83 ret = get_column (>K_CLIST (window1.listbox)->column[5]); |
227 | 84 gftp_set_global_option ("local_date_width", GINT_TO_POINTER (ret)); |
129 | 85 ret = get_column (>K_CLIST (window1.listbox)->column[6]); |
227 | 86 gftp_set_global_option ("local_attribs_width", GINT_TO_POINTER (ret)); |
1 | 87 |
129 | 88 ret = get_column (>K_CLIST (window2.listbox)->column[1]); |
227 | 89 gftp_set_global_option ("remote_file_width", GINT_TO_POINTER (ret)); |
129 | 90 ret = get_column (>K_CLIST (window2.listbox)->column[2]); |
227 | 91 gftp_set_global_option ("remote_size_width", GINT_TO_POINTER (ret)); |
129 | 92 ret = get_column (>K_CLIST (window2.listbox)->column[3]); |
227 | 93 gftp_set_global_option ("remote_user_width", GINT_TO_POINTER (ret)); |
129 | 94 ret = get_column (>K_CLIST (window2.listbox)->column[4]); |
227 | 95 gftp_set_global_option ("remote_group_width", GINT_TO_POINTER (ret)); |
129 | 96 ret = get_column (>K_CLIST (window2.listbox)->column[5]); |
227 | 97 gftp_set_global_option ("remote_date_width", GINT_TO_POINTER (ret)); |
129 | 98 ret = get_column (>K_CLIST (window2.listbox)->column[6]); |
227 | 99 gftp_set_global_option ("remote_attribs_width", GINT_TO_POINTER (ret)); |
37 | 100 |
201 | 101 gftp_shutdown (); |
48 | 102 exit (0); |
1 | 103 } |
104 | |
105 | |
106 static gint | |
505 | 107 _gftp_try_close (GtkWidget * widget, GdkEvent * event, gpointer data) |
1 | 108 { |
129 | 109 if (gftp_file_transfers == NULL) |
505 | 110 { |
111 _gftp_exit (NULL, NULL); | |
112 return (0); | |
113 } | |
1 | 114 else |
115 { | |
505 | 116 MakeYesNoDialog (_("Exit"), _("There are file transfers in progress.\nAre you sure you want to exit?"), _gftp_exit, NULL, NULL, NULL); |
117 return (1); | |
1 | 118 } |
119 } | |
120 | |
121 | |
122 static void | |
505 | 123 _gftp_force_close (GtkWidget * widget, gpointer data) |
1 | 124 { |
125 exit (0); | |
126 } | |
127 | |
128 | |
48 | 129 static void |
505 | 130 _gftp_menu_exit (GtkWidget * widget, gpointer data) |
1 | 131 { |
505 | 132 if (!_gftp_try_close (widget, NULL, data)) |
133 _gftp_exit (widget, data); | |
48 | 134 } |
1 | 135 |
136 | |
374 | 137 static void |
138 change_setting (gftp_window_data * wdata, int menuitem, GtkWidget * checkmenu) | |
139 { | |
140 switch (menuitem) | |
141 { | |
505 | 142 case GFTP_MENU_ITEM_ASCII: |
374 | 143 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1)); |
144 break; | |
505 | 145 case GFTP_MENU_ITEM_BINARY: |
374 | 146 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0)); |
147 break; | |
505 | 148 case GFTP_MENU_ITEM_WIN1: |
374 | 149 current_wdata = &window1; |
150 other_wdata = &window2; | |
505 | 151 if (wdata->request != NULL) |
374 | 152 update_window_info (); |
153 break; | |
505 | 154 case GFTP_MENU_ITEM_WIN2: |
374 | 155 current_wdata = &window2; |
156 other_wdata = &window1; | |
505 | 157 if (wdata->request != NULL) |
374 | 158 update_window_info (); |
159 break; | |
160 } | |
161 } | |
162 | |
163 | |
164 static void | |
165 _gftpui_gtk_do_openurl (gftp_window_data * wdata, gftp_dialog_data * ddata) | |
166 { | |
425 | 167 const char *tempstr; |
168 char *buf; | |
374 | 169 |
425 | 170 tempstr = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
171 if (tempstr != NULL && *tempstr != '\0') | |
172 { | |
173 buf = g_strdup (tempstr); | |
174 destroy_dialog (ddata); | |
175 gftpui_common_cmd_open (wdata, wdata->request, NULL, NULL, buf); | |
176 g_free (buf); | |
177 } | |
374 | 178 } |
179 | |
180 | |
181 static void | |
182 openurl_dialog (gpointer data) | |
183 { | |
184 gftp_window_data * wdata; | |
185 | |
186 wdata = data; | |
187 MakeEditDialog (_("Connect via URL"), _("Enter a URL to connect to"), | |
188 NULL, 1, NULL, gftp_dialog_button_connect, | |
189 _gftpui_gtk_do_openurl, wdata, | |
190 NULL, NULL); | |
191 } | |
192 | |
193 | |
194 static void | |
195 tb_openurl_dialog (gpointer data) | |
196 { | |
197 const char *edttxt; | |
198 | |
199 if (current_wdata->request->stopable) | |
200 { | |
201 ftp_log (gftp_logging_misc, NULL, | |
202 _("%s: Please hit the stop button first to do anything else\n"), | |
203 _("OpenURL")); | |
204 return; | |
205 } | |
206 | |
207 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); | |
208 | |
209 if (GFTP_IS_CONNECTED (current_wdata->request)) | |
380 | 210 gftpui_disconnect (current_wdata); |
374 | 211 else if (edttxt != NULL && *edttxt != '\0') |
212 toolbar_hostedit (NULL, NULL); | |
213 else | |
214 openurl_dialog (current_wdata); | |
215 } | |
216 | |
217 | |
514 | 218 static void |
219 gftp_gtk_refresh (gftp_window_data * wdata) | |
220 { | |
221 gftpui_refresh (wdata, 1); | |
222 } | |
223 | |
224 | |
1 | 225 static GtkWidget * |
226 CreateMenus (GtkWidget * parent) | |
227 { | |
505 | 228 int local_len, remote_len, len, i, trans_len, log_len, tools_len; |
1 | 229 GtkAccelGroup *accel_group; |
505 | 230 intptr_t ascii_transfers; |
1 | 231 GtkWidget * tempwid; |
7 | 232 static GtkItemFactoryEntry menu_items[] = { |
12 | 233 {N_("/_FTP"), NULL, 0, 0, MN_("<Branch>")}, |
234 {N_("/FTP/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
505 | 235 {N_("/FTP/Window 1"), NULL, change_setting, GFTP_MENU_ITEM_WIN1, |
236 MN_("<RadioItem>")}, | |
237 {N_("/FTP/Window 2"), NULL, change_setting, GFTP_MENU_ITEM_WIN2, | |
238 MN_("/FTP/Window 1")}, | |
12 | 239 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, |
505 | 240 {N_("/FTP/Ascii"), NULL, change_setting, GFTP_MENU_ITEM_ASCII, |
241 MN_("<RadioItem>")}, | |
242 {N_("/FTP/Binary"), NULL, change_setting, GFTP_MENU_ITEM_BINARY, | |
243 MN_("/FTP/Ascii")}, | |
12 | 244 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, |
245 {N_("/FTP/_Options..."), "<control>O", options_dialog, 0, | |
246 MS_(GTK_STOCK_PREFERENCES)}, | |
247 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
505 | 248 {N_("/FTP/_Quit"), "<control>Q", _gftp_menu_exit, 0, MS_(GTK_STOCK_QUIT)}, |
12 | 249 {N_("/_Local"), NULL, 0, 0, MN_("<Branch>")}, |
250 {N_("/Local/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
536 | 251 {N_("/Local/Open URL..."), "", openurl_dialog, 0, MS_(GTK_STOCK_OPEN)}, |
252 {N_("/Local/Disconnect"), "", gftpui_disconnect, 0, MS_(GTK_STOCK_CLOSE)}, | |
12 | 253 {N_("/Local/sep"), NULL, 0, 0, MN_("<Separator>")}, |
254 {N_("/Local/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, | |
255 {N_("/Local/Show selected"), NULL, show_selected, 0, MN_(NULL)}, | |
256 {N_("/Local/Select All"), NULL, selectall, 0, MN_(NULL)}, | |
257 {N_("/Local/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, | |
258 {N_("/Local/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, | |
259 {N_("/Local/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
260 {N_("/Local/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, |
341 | 261 {N_("/Local/Send SITE Command..."), NULL, gftpui_site_dialog, 0, MN_(NULL)}, |
262 {N_("/Local/Change Directory"), NULL, gftpui_chdir_dialog, 0, MN_(NULL)}, | |
12 | 263 {N_("/Local/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, |
341 | 264 {N_("/Local/Make Directory..."), NULL, gftpui_mkdir_dialog, 0, MN_(NULL)}, |
265 {N_("/Local/Rename..."), NULL, gftpui_rename_dialog, 0, MN_(NULL)}, | |
12 | 266 {N_("/Local/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, |
267 {N_("/Local/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, | |
268 {N_("/Local/View..."), NULL, view_dialog, 0, MN_(NULL)}, | |
514 | 269 {N_("/Local/Refresh"), NULL, gftp_gtk_refresh, 0, MS_(GTK_STOCK_REFRESH)}, |
12 | 270 {N_("/_Remote"), NULL, 0, 0, MN_("<Branch>")}, |
271 {N_("/Remote/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
272 {N_("/Remote/Open _URL..."), "<control>U", openurl_dialog, 0, | |
273 MS_(GTK_STOCK_OPEN)}, | |
380 | 274 {N_("/Remote/Disconnect"), "<control>D", gftpui_disconnect, 0, |
12 | 275 MS_(GTK_STOCK_CLOSE)}, |
276 {N_("/Remote/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
277 {N_("/Remote/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, | |
278 {N_("/Remote/Show selected"), NULL, show_selected, 0, MN_(NULL)}, | |
279 {N_("/Remote/Select All"), NULL, selectall, 0, MN_(NULL)}, | |
280 {N_("/Remote/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, | |
281 {N_("/Remote/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, | |
282 {N_("/Remote/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
283 {N_("/Remote/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, |
341 | 284 {N_("/Remote/Send SITE Command..."), NULL, gftpui_site_dialog, 0, MN_(NULL)}, |
285 {N_("/Remote/Change Directory"), NULL, gftpui_chdir_dialog, 0, MN_(NULL)}, | |
12 | 286 {N_("/Remote/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, |
341 | 287 {N_("/Remote/Make Directory..."), NULL, gftpui_mkdir_dialog, 0, MN_(NULL)}, |
288 {N_("/Remote/Rename..."), NULL, gftpui_rename_dialog, 0, MN_(NULL)}, | |
12 | 289 {N_("/Remote/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, |
290 {N_("/Remote/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, | |
291 {N_("/Remote/View..."), NULL, view_dialog, 0, MN_(NULL)}, | |
514 | 292 {N_("/Remote/Refresh"), NULL, gftp_gtk_refresh, 0, MS_(GTK_STOCK_REFRESH)}, |
12 | 293 {N_("/_Bookmarks"), NULL, 0, 0, MN_("<Branch>")}, |
294 {N_("/Bookmarks/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
295 {N_("/Bookmarks/Add bookmark"), "<control>A", add_bookmark, 0, | |
296 MS_(GTK_STOCK_ADD)}, | |
297 {N_("/Bookmarks/Edit bookmarks"), NULL, edit_bookmarks, 0, MN_(NULL)}, | |
298 {N_("/Bookmarks/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
299 {N_("/_Transfers"), NULL, 0, 0, MN_("<Branch>")}, | |
300 {N_("/Transfers/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
301 {N_("/Transfers/Start Transfer"), NULL, start_transfer, 0, MN_(NULL)}, | |
302 {N_("/Transfers/Stop Transfer"), NULL, stop_transfer, 0, | |
303 MS_(GTK_STOCK_STOP)}, | |
304 {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
305 {N_("/Transfers/Skip Current File"), NULL, skip_transfer, 0, MN_(NULL)}, | |
306 {N_("/Transfers/Remove File"), NULL, remove_file_transfer, 0, | |
307 MS_(GTK_STOCK_DELETE)}, | |
586 | 308 {N_("/Transfers/Move File Up"), NULL, move_transfer_up, 0, |
12 | 309 MS_(GTK_STOCK_GO_UP)}, |
586 | 310 {N_("/Transfers/Move File Down"), NULL, move_transfer_down, 0, |
12 | 311 MS_(GTK_STOCK_GO_DOWN)}, |
312 {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
313 {N_("/Transfers/Retrieve Files"), "<control>R", get_files, 0, MN_(NULL)}, | |
314 {N_("/Transfers/Put Files"), "<control>P", put_files, 0, MN_(NULL)}, | |
315 {N_("/L_ogging"), NULL, 0, 0, MN_("<Branch>")}, | |
316 {N_("/Logging/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
317 {N_("/Logging/Clear"), NULL, clearlog, 0, MS_(GTK_STOCK_CLEAR)}, | |
562 | 318 {N_("/Logging/View log"), NULL, viewlog, 0, MN_(NULL)}, |
12 | 319 {N_("/Logging/Save log..."), NULL, savelog, 0, MS_(GTK_STOCK_SAVE)}, |
320 {N_("/Tool_s"), NULL, 0, 0, MN_("<Branch>")}, | |
321 {N_("/Tools/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
322 {N_("/Tools/Compare Windows"), NULL, compare_windows, 0, MN_(NULL)}, | |
323 {N_("/Tools/Clear Cache"), NULL, clear_cache, 0, MS_(GTK_STOCK_CLEAR)}, | |
278 | 324 {N_("/_Help"), NULL, 0, 0, MN_("<Branch>")}, |
12 | 325 {N_("/Help/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, |
562 | 326 {N_("/Help/About"), NULL, about_dialog, 0, MS_(GTK_STOCK_HELP)} |
1 | 327 }; |
328 | |
329 menus = menu_items; | |
330 | |
331 accel_group = gtk_accel_group_new (); | |
7 | 332 factory = item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group, NULL); |
1 | 333 |
334 i = 0; | |
335 len = 11; | |
336 /* FTP Menu */ | |
337 create_item_factory (factory, len, menu_items, &window2); | |
338 | |
339 i += len; | |
340 /* Local Menu */ | |
341 local_start = i; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
342 local_len = 21; |
1 | 343 create_item_factory (factory, local_len, menu_items + i, &window1); |
344 | |
345 i += local_len; | |
346 /* Remote Menu */ | |
347 remote_start = i; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
348 remote_len = 21; |
1 | 349 create_item_factory (factory, remote_len, menu_items + i, &window2); |
350 | |
351 i += remote_len; | |
352 len = 5; | |
353 /* Bookmarks Menu */ | |
354 create_item_factory (factory, len, menu_items + i, &window2); | |
355 | |
356 i += len; | |
357 /* Transfers Menu */ | |
358 trans_start = i; | |
359 trans_len = 12; | |
360 create_item_factory (factory, trans_len, menu_items + i, NULL); | |
361 | |
362 i += trans_len; | |
363 /* Logging Menu */ | |
364 log_start = i; | |
365 log_len = 5; | |
366 create_item_factory (factory, log_len, menu_items + i, NULL); | |
367 | |
368 i += log_len; | |
369 /* Tools Menu */ | |
370 tools_start = i; | |
371 tools_len = 4; | |
372 create_item_factory (factory, tools_len, menu_items + i, NULL); | |
373 | |
374 i += tools_len; | |
375 /* Help Menu */ | |
376 create_item_factory (factory, 3, menu_items + i, NULL); | |
377 | |
378 build_bookmarks_menu (); | |
379 | |
44 | 380 gtk_window_add_accel_group (GTK_WINDOW (parent), accel_group); |
1 | 381 |
245 | 382 gftp_lookup_global_option ("ascii_transfers", &ascii_transfers); |
383 if (ascii_transfers) | |
384 { | |
385 tempwid = gtk_item_factory_get_widget (factory, menu_items[5].path); | |
386 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (tempwid), TRUE); | |
387 } | |
388 else | |
389 { | |
390 tempwid = gtk_item_factory_get_widget (factory, menu_items[6].path); | |
391 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (tempwid), TRUE); | |
392 } | |
1 | 393 |
7 | 394 tempwid = gtk_item_factory_get_widget (factory, menu_items[3].path); |
1 | 395 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (tempwid), TRUE); |
396 | |
7 | 397 window1.ifactory = item_factory_new (GTK_TYPE_MENU, "<local>", NULL, "/Local"); |
398 create_item_factory (window1.ifactory, local_len - 2, menu_items + local_start + 2, &window1); | |
399 | |
400 window2.ifactory = item_factory_new (GTK_TYPE_MENU, "<remote>", NULL, "/Remote"); | |
401 create_item_factory (window2.ifactory, remote_len - 2, menu_items + remote_start + 2, &window2); | |
1 | 402 |
7 | 403 log_factory = item_factory_new (GTK_TYPE_MENU, "<log>", NULL, "/Logging"); |
404 create_item_factory (log_factory, log_len - 2, menu_items + log_start + 2, NULL); | |
1 | 405 |
7 | 406 dl_factory = item_factory_new (GTK_TYPE_MENU, "<download>", NULL, "/Transfers"); |
407 create_item_factory (dl_factory, trans_len - 2, menu_items + trans_start + 2, NULL); | |
1 | 408 |
409 return (factory->widget); | |
410 } | |
411 | |
412 | |
413 static GtkWidget * | |
341 | 414 CreateConnectToolbar (GtkWidget * parent) |
1 | 415 { |
416 const GtkTargetEntry possible_types[] = { | |
417 {"STRING", 0, 0}, | |
418 {"text/plain", 0, 0}, | |
419 {"application/x-rootwin-drop", 0, 1} | |
420 }; | |
421 GtkWidget *toolbar, *box, *tempwid; | |
129 | 422 gftp_config_list_vars * tmplistvar; |
423 char *default_protocol; | |
1 | 424 int i, num; |
425 | |
426 toolbar = gtk_handle_box_new (); | |
427 | |
428 box = gtk_hbox_new (FALSE, 4); | |
429 gtk_container_add (GTK_CONTAINER (toolbar), box); | |
430 gtk_container_border_width (GTK_CONTAINER (box), 5); | |
431 | |
432 tempwid = toolbar_pixmap (parent, "connect.xpm"); | |
433 openurl_btn = gtk_button_new (); | |
434 gtk_container_add (GTK_CONTAINER (openurl_btn), tempwid); | |
435 gtk_signal_connect_object (GTK_OBJECT (openurl_btn), "clicked", | |
436 GTK_SIGNAL_FUNC (tb_openurl_dialog), NULL); | |
437 gtk_signal_connect (GTK_OBJECT (openurl_btn), "drag_data_received", | |
438 GTK_SIGNAL_FUNC (openurl_get_drag_data), NULL); | |
439 gtk_drag_dest_set (openurl_btn, GTK_DEST_DEFAULT_ALL, possible_types, 2, | |
440 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
441 gtk_container_border_width (GTK_CONTAINER (openurl_btn), 1); | |
442 gtk_box_pack_start (GTK_BOX (box), openurl_btn, FALSE, FALSE, 0); | |
443 | |
444 tempwid = gtk_label_new (_("Host: ")); | |
445 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
446 | |
447 hostedit = gtk_combo_new (); | |
448 gtk_combo_set_case_sensitive (GTK_COMBO (hostedit), 1); | |
449 gtk_widget_set_size_request (hostedit, 130, -1); | |
450 | |
451 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (hostedit)->entry), "activate", | |
452 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
129 | 453 |
454 gftp_lookup_global_option ("hosthistory", &tmplistvar); | |
455 if (tmplistvar->list) | |
456 gtk_combo_set_popdown_strings (GTK_COMBO (hostedit), tmplistvar->list); | |
457 | |
1 | 458 gtk_combo_disable_activate (GTK_COMBO (hostedit)); |
459 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry), ""); | |
460 gtk_box_pack_start (GTK_BOX (box), hostedit, TRUE, TRUE, 0); | |
461 | |
462 tempwid = gtk_label_new (_("Port: ")); | |
463 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
464 | |
465 portedit = gtk_combo_new (); | |
466 gtk_combo_set_case_sensitive (GTK_COMBO (portedit), 1); | |
542 | 467 gtk_widget_set_size_request (portedit, 50, -1); |
1 | 468 |
469 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (portedit)->entry), "activate", | |
470 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
129 | 471 |
472 gftp_lookup_global_option ("porthistory", &tmplistvar); | |
473 if (tmplistvar->list) | |
474 gtk_combo_set_popdown_strings (GTK_COMBO (portedit), tmplistvar->list); | |
475 | |
1 | 476 gtk_combo_disable_activate (GTK_COMBO (portedit)); |
477 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (portedit)->entry), ""); | |
478 gtk_box_pack_start (GTK_BOX (box), portedit, FALSE, FALSE, 0); | |
479 | |
480 tempwid = gtk_label_new (_("User: ")); | |
481 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
482 | |
483 useredit = gtk_combo_new (); | |
484 gtk_combo_set_case_sensitive (GTK_COMBO (useredit), 1); | |
485 gtk_widget_set_size_request (useredit, 75, -1); | |
486 | |
487 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (useredit)->entry), "activate", | |
488 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
129 | 489 |
490 gftp_lookup_global_option ("userhistory", &tmplistvar); | |
491 if (tmplistvar->list) | |
492 gtk_combo_set_popdown_strings (GTK_COMBO (useredit), tmplistvar->list); | |
493 | |
1 | 494 gtk_combo_disable_activate (GTK_COMBO (useredit)); |
495 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (useredit)->entry), ""); | |
496 gtk_box_pack_start (GTK_BOX (box), useredit, TRUE, TRUE, 0); | |
497 | |
498 tempwid = gtk_label_new (_("Pass: ")); | |
499 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
500 | |
501 passedit = gtk_entry_new (); | |
502 gtk_widget_set_size_request (passedit, 55, -1); | |
503 | |
504 gtk_entry_set_visibility (GTK_ENTRY (passedit), FALSE); | |
505 gtk_signal_connect (GTK_OBJECT (passedit), "activate", | |
506 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
507 gtk_box_pack_start (GTK_BOX (box), passedit, FALSE, FALSE, 0); | |
508 | |
509 tempwid = gtk_vbox_new (FALSE, 0); | |
510 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
511 | |
512 optionmenu = gtk_option_menu_new (); | |
513 gtk_box_pack_start (GTK_BOX (tempwid), optionmenu, TRUE, FALSE, 0); | |
514 | |
515 num = 0; | |
129 | 516 gftp_lookup_global_option ("default_protocol", &default_protocol); |
1 | 517 protocol_menu = gtk_menu_new (); |
518 for (i = 0; gftp_protocols[i].name; i++) | |
519 { | |
520 if (!gftp_protocols[i].shown) | |
521 continue; | |
522 | |
129 | 523 if (default_protocol != NULL && |
524 strcmp (gftp_protocols[i].name, default_protocol) == 0) | |
1 | 525 num = i; |
526 | |
527 tempwid = gtk_menu_item_new_with_label (gftp_protocols[i].name); | |
129 | 528 gtk_object_set_user_data (GTK_OBJECT (tempwid), GINT_TO_POINTER(i)); |
1 | 529 gtk_menu_append (GTK_MENU (protocol_menu), tempwid); |
530 gtk_widget_show (tempwid); | |
531 } | |
532 gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), protocol_menu); | |
533 gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), num); | |
534 | |
45 | 535 #if GTK_MAJOR_VERSION == 1 |
21 | 536 tempwid = toolbar_pixmap (parent, "stop.xpm"); |
19 | 537 #else |
538 tempwid = gtk_image_new_from_stock (GTK_STOCK_STOP, | |
539 GTK_ICON_SIZE_LARGE_TOOLBAR); | |
540 #endif | |
541 | |
1 | 542 stop_btn = gtk_button_new (); |
543 gtk_container_add (GTK_CONTAINER (stop_btn), tempwid); | |
544 gtk_widget_set_sensitive (stop_btn, 0); | |
545 gtk_signal_connect_object (GTK_OBJECT (stop_btn), "clicked", | |
546 GTK_SIGNAL_FUNC (stop_button), NULL); | |
547 gtk_container_border_width (GTK_CONTAINER (stop_btn), 1); | |
548 gtk_box_pack_start (GTK_BOX (box), stop_btn, FALSE, FALSE, 0); | |
549 | |
326 | 550 gtk_widget_grab_focus (GTK_COMBO (hostedit)->entry); |
341 | 551 |
1 | 552 return (toolbar); |
553 } | |
554 | |
555 | |
341 | 556 static GtkWidget * |
557 CreateCommandToolbar (void) | |
558 { | |
559 GtkWidget * box, * tempwid; | |
560 | |
561 gftpui_command_toolbar = gtk_handle_box_new (); | |
562 | |
563 box = gtk_hbox_new (FALSE, 4); | |
564 gtk_container_add (GTK_CONTAINER (gftpui_command_toolbar), box); | |
565 gtk_container_border_width (GTK_CONTAINER (box), 5); | |
566 | |
567 tempwid = gtk_label_new (_("Command: ")); | |
568 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
569 | |
570 gftpui_command_widget = gtk_entry_new (); | |
571 gtk_box_pack_start (GTK_BOX (box), gftpui_command_widget, TRUE, TRUE, 0); | |
572 gtk_signal_connect (GTK_OBJECT (gftpui_command_widget), "activate", | |
573 GTK_SIGNAL_FUNC (gftpui_run_command), NULL); | |
574 | |
575 return (gftpui_command_toolbar); | |
576 } | |
577 | |
578 | |
1 | 579 static void |
48 | 580 setup_column (GtkWidget * listbox, int column, int width) |
1 | 581 { |
48 | 582 if (width == 0) |
583 gtk_clist_set_column_auto_resize (GTK_CLIST (listbox), column, TRUE); | |
584 else if (width == -1) | |
585 gtk_clist_set_column_visibility (GTK_CLIST (listbox), column, FALSE); | |
586 else | |
587 gtk_clist_set_column_width (GTK_CLIST (listbox), column, width); | |
1 | 588 } |
589 | |
590 | |
48 | 591 static void |
592 list_doaction (gftp_window_data * wdata) | |
1 | 593 { |
326 | 594 intptr_t list_dblclk_action; |
48 | 595 GList *templist, *filelist; |
596 gftp_file *tempfle; | |
499 | 597 int num, success; |
341 | 598 char *directory; |
48 | 599 |
129 | 600 gftp_lookup_request_option (wdata->request, "list_dblclk_action", |
601 &list_dblclk_action); | |
602 | |
48 | 603 filelist = wdata->files; |
525 | 604 templist = gftp_gtk_get_list_selection (wdata); |
48 | 605 num = 0; |
606 templist = get_next_selection (templist, &filelist, &num); | |
607 tempfle = (gftp_file *) filelist->data; | |
608 | |
337 | 609 if (check_reconnect (wdata) < 0) |
610 return; | |
611 | |
499 | 612 if (S_ISLNK (tempfle->st_mode) || S_ISDIR (tempfle->st_mode)) |
341 | 613 { |
555 | 614 directory = gftp_build_path (wdata->request, wdata->request->directory, |
615 tempfle->file, NULL); | |
341 | 616 success = gftpui_run_chdir (wdata, directory); |
617 g_free (directory); | |
618 } | |
619 else | |
620 success = 0; | |
1 | 621 |
499 | 622 if (!S_ISDIR (tempfle->st_mode) && !success) |
1 | 623 { |
129 | 624 switch (list_dblclk_action) |
48 | 625 { |
626 case 0: | |
627 view_dialog (wdata); | |
628 break; | |
629 case 1: | |
630 edit_dialog (wdata); | |
631 break; | |
632 case 2: | |
633 if (wdata == &window2) | |
634 get_files (wdata); | |
635 else | |
636 put_files (wdata); | |
637 break; | |
638 } | |
1 | 639 } |
640 } | |
641 | |
642 | |
48 | 643 static gint |
644 list_enter (GtkWidget * widget, GdkEventKey * event, gpointer data) | |
645 { | |
646 gftp_window_data * wdata; | |
647 | |
648 wdata = data; | |
649 if (!GFTP_IS_CONNECTED (wdata->request)) | |
650 return (TRUE); | |
651 | |
652 if (event->type == GDK_KEY_PRESS && | |
653 (event->keyval == GDK_KP_Delete || event->keyval == GDK_Delete)) | |
654 { | |
655 delete_dialog (wdata); | |
656 return (FALSE); | |
657 } | |
658 else if (IS_ONE_SELECTED (wdata) && event->type == GDK_KEY_PRESS && | |
659 event->keyval == GDK_Return) | |
660 { | |
661 list_doaction (wdata); | |
662 return (FALSE); | |
663 } | |
664 return (TRUE); | |
665 } | |
666 | |
667 | |
668 static gint | |
669 list_dblclick (GtkWidget * widget, GdkEventButton * event, gpointer data) | |
1 | 670 { |
48 | 671 gftp_window_data * wdata; |
672 | |
673 wdata = data; | |
51 | 674 |
48 | 675 if (event->button == 3) |
676 gtk_item_factory_popup (wdata->ifactory, (guint) event->x_root, | |
677 (guint) event->y_root, 3, event->time); | |
51 | 678 return (FALSE); |
679 } | |
680 | |
48 | 681 |
518 | 682 static void |
51 | 683 select_row_callback (GtkWidget *widget, gint row, gint column, |
684 GdkEventButton *event, gpointer data) | |
685 { | |
686 gftp_window_data * wdata; | |
50 | 687 |
51 | 688 wdata = data; |
50 | 689 |
51 | 690 if (event != NULL && event->type == GDK_2BUTTON_PRESS && event->button == 1 && |
691 GFTP_IS_CONNECTED (wdata->request) && IS_ONE_SELECTED (wdata)) | |
692 list_doaction (wdata); | |
1 | 693 } |
694 | |
695 | |
696 static GtkWidget * | |
129 | 697 CreateFTPWindow (gftp_window_data * wdata) |
1 | 698 { |
699 const GtkTargetEntry possible_types[] = { | |
700 {"STRING", 0, 0}, | |
701 {"text/plain", 0, 0}, | |
702 {"application/x-rootwin-drop", 0, 1} | |
703 }; | |
704 GtkWidget *box, *scroll_list, *parent; | |
326 | 705 intptr_t listbox_file_height, colwidth; |
129 | 706 char *titles[7], tempstr[50]; |
1 | 707 |
708 titles[0] = ""; | |
709 titles[1] = _("Filename"); | |
710 titles[2] = _("Size"); | |
711 titles[3] = _("User"); | |
712 titles[4] = _("Group"); | |
713 titles[5] = _("Date"); | |
714 titles[6] = _("Attribs"); | |
715 | |
716 wdata->request = gftp_request_new (); | |
717 wdata->request->logging_function = ftp_log; | |
718 wdata->filespec = g_malloc0 (2); | |
719 *wdata->filespec = '*'; | |
720 | |
721 parent = gtk_frame_new (NULL); | |
129 | 722 |
723 gftp_lookup_global_option ("listbox_file_height", &listbox_file_height); | |
724 g_snprintf (tempstr, sizeof (tempstr), "listbox_%s_width", wdata->prefix_col_str); | |
725 gftp_lookup_global_option (tempstr, &colwidth); | |
726 gtk_widget_set_size_request (parent, colwidth, listbox_file_height); | |
1 | 727 |
728 gtk_container_border_width (GTK_CONTAINER (parent), 5); | |
729 | |
730 box = gtk_vbox_new (FALSE, 0); | |
731 gtk_container_border_width (GTK_CONTAINER (box), 5); | |
732 gtk_container_add (GTK_CONTAINER (parent), box); | |
733 | |
734 wdata->combo = gtk_combo_new (); | |
735 gtk_combo_set_case_sensitive (GTK_COMBO (wdata->combo), 1); | |
736 gtk_box_pack_start (GTK_BOX (box), wdata->combo, FALSE, FALSE, 0); | |
737 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (wdata->combo)->entry), | |
738 "activate", GTK_SIGNAL_FUNC (chdir_edit), | |
739 (gpointer) wdata); | |
740 if (*wdata->history) | |
741 gtk_combo_set_popdown_strings (GTK_COMBO (wdata->combo), *wdata->history); | |
742 gtk_combo_disable_activate (GTK_COMBO (wdata->combo)); | |
743 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry), ""); | |
744 | |
745 wdata->hoststxt = gtk_label_new (NULL); | |
746 gtk_misc_set_alignment (GTK_MISC (wdata->hoststxt), 0, 0); | |
747 gtk_box_pack_start (GTK_BOX (box), wdata->hoststxt, FALSE, FALSE, 0); | |
748 | |
749 scroll_list = gtk_scrolled_window_new (NULL, NULL); | |
750 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_list), | |
751 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
752 wdata->listbox = gtk_clist_new_with_titles (7, titles); | |
753 gtk_container_add (GTK_CONTAINER (scroll_list), wdata->listbox); | |
754 gtk_drag_source_set (wdata->listbox, GDK_BUTTON1_MASK, possible_types, 3, | |
755 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
756 gtk_drag_dest_set (wdata->listbox, GTK_DEST_DEFAULT_ALL, possible_types, 2, | |
757 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
758 | |
759 gtk_clist_set_selection_mode (GTK_CLIST (wdata->listbox), | |
760 GTK_SELECTION_EXTENDED); | |
761 | |
762 gtk_clist_set_column_width (GTK_CLIST (wdata->listbox), 0, 16); | |
763 gtk_clist_set_column_justification (GTK_CLIST (wdata->listbox), 0, | |
764 GTK_JUSTIFY_CENTER); | |
129 | 765 |
766 g_snprintf (tempstr, sizeof (tempstr), "%s_file_width", wdata->prefix_col_str); | |
767 gftp_lookup_global_option (tempstr, &colwidth); | |
768 setup_column (wdata->listbox, 1, colwidth); | |
769 | |
1 | 770 gtk_clist_set_column_justification (GTK_CLIST (wdata->listbox), 2, |
771 GTK_JUSTIFY_RIGHT); | |
129 | 772 |
773 g_snprintf (tempstr, sizeof (tempstr), "%s_size_width", wdata->prefix_col_str); | |
774 gftp_lookup_global_option (tempstr, &colwidth); | |
775 setup_column (wdata->listbox, 2, colwidth); | |
776 | |
777 g_snprintf (tempstr, sizeof (tempstr), "%s_user_width", wdata->prefix_col_str); | |
778 gftp_lookup_global_option (tempstr, &colwidth); | |
779 setup_column (wdata->listbox, 3, colwidth); | |
780 | |
781 g_snprintf (tempstr, sizeof (tempstr), "%s_group_width", wdata->prefix_col_str); | |
782 gftp_lookup_global_option (tempstr, &colwidth); | |
783 setup_column (wdata->listbox, 4, colwidth); | |
784 | |
785 g_snprintf (tempstr, sizeof (tempstr), "%s_date_width", wdata->prefix_col_str); | |
786 gftp_lookup_global_option (tempstr, &colwidth); | |
787 setup_column (wdata->listbox, 5, colwidth); | |
788 | |
789 g_snprintf (tempstr, sizeof (tempstr), "%s_attribs_width", wdata->prefix_col_str); | |
790 gftp_lookup_global_option (tempstr, &colwidth); | |
791 setup_column (wdata->listbox, 6, colwidth); | |
792 | |
1 | 793 gtk_box_pack_start (GTK_BOX (box), scroll_list, TRUE, TRUE, 0); |
794 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "click_column", | |
795 GTK_SIGNAL_FUNC (sortrows), (gpointer) wdata); | |
796 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "drag_data_get", | |
797 GTK_SIGNAL_FUNC (listbox_drag), (gpointer) wdata); | |
798 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "drag_data_received", | |
799 GTK_SIGNAL_FUNC (listbox_get_drag_data), | |
800 (gpointer) wdata); | |
801 gtk_signal_connect_after (GTK_OBJECT (wdata->listbox), "key_press_event", | |
802 GTK_SIGNAL_FUNC (list_enter), (gpointer) wdata); | |
51 | 803 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "select_row", |
804 GTK_SIGNAL_FUNC(select_row_callback), | |
805 (gpointer) wdata); | |
1 | 806 gtk_signal_connect_after (GTK_OBJECT (wdata->listbox), "button_press_event", |
807 GTK_SIGNAL_FUNC (list_dblclick), (gpointer) wdata); | |
808 return (parent); | |
809 } | |
810 | |
811 | |
812 static gint | |
813 menu_mouse_click (GtkWidget * widget, GdkEventButton * event, gpointer data) | |
814 { | |
518 | 815 GtkItemFactory *mfactory; |
1 | 816 |
518 | 817 mfactory = (GtkItemFactory *) data; |
1 | 818 if (event->button == 3) |
518 | 819 gtk_item_factory_popup (mfactory, (guint) event->x_root, |
1 | 820 (guint) event->y_root, 3, event->time); |
821 return (FALSE); | |
822 } | |
823 | |
824 | |
48 | 825 static GtkWidget * |
826 CreateFTPWindows (GtkWidget * ui) | |
1 | 827 { |
587 | 828 GtkWidget *box, *dlbox, *winpane, *dlpane, *logpane, *mainvbox, *tempwid; |
129 | 829 gftp_config_list_vars * tmplistvar; |
48 | 830 char *dltitles[2]; |
326 | 831 intptr_t tmplookup; |
48 | 832 #if GTK_MAJOR_VERSION > 1 |
833 GtkTextBuffer * textbuf; | |
834 GtkTextIter iter; | |
835 GtkTextTag *tag; | |
129 | 836 GdkColor * fore; |
48 | 837 #endif |
838 | |
839 memset (&window1, 0, sizeof (window1)); | |
840 memset (&window2, 0, sizeof (window2)); | |
129 | 841 |
842 gftp_lookup_global_option ("localhistory", &tmplistvar); | |
843 window1.history = &tmplistvar->list; | |
844 window1.histlen = &tmplistvar->num_items; | |
845 | |
846 gftp_lookup_global_option ("remotehistory", &tmplistvar); | |
847 window2.history = &tmplistvar->list; | |
848 window2.histlen = &tmplistvar->num_items; | |
48 | 849 |
850 mainvbox = gtk_vbox_new (FALSE, 0); | |
851 | |
852 tempwid = CreateMenus (ui); | |
853 gtk_box_pack_start (GTK_BOX (mainvbox), tempwid, FALSE, FALSE, 0); | |
1 | 854 |
341 | 855 tempwid = CreateConnectToolbar (ui); |
856 gtk_box_pack_start (GTK_BOX (mainvbox), tempwid, FALSE, FALSE, 0); | |
857 | |
858 tempwid = CreateCommandToolbar (); | |
48 | 859 gtk_box_pack_start (GTK_BOX (mainvbox), tempwid, FALSE, FALSE, 0); |
860 | |
861 winpane = gtk_hpaned_new (); | |
862 | |
863 box = gtk_hbox_new (FALSE, 0); | |
864 | |
129 | 865 window1.prefix_col_str = "local"; |
866 local_frame = CreateFTPWindow (&window1); | |
48 | 867 gtk_box_pack_start (GTK_BOX (box), local_frame, TRUE, TRUE, 0); |
868 | |
869 dlbox = gtk_vbox_new (FALSE, 0); | |
870 gtk_container_border_width (GTK_CONTAINER (dlbox), 5); | |
871 gtk_box_pack_start (GTK_BOX (box), dlbox, FALSE, FALSE, 0); | |
872 | |
873 #if GTK_MAJOR_VERSION == 1 | |
874 tempwid = toolbar_pixmap (ui, "right.xpm"); | |
875 #else | |
876 tempwid = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, | |
877 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
878 #endif | |
879 | |
587 | 880 upload_right_arrow = gtk_button_new (); |
881 gtk_box_pack_start (GTK_BOX (dlbox), upload_right_arrow, TRUE, FALSE, 0); | |
882 gtk_signal_connect_object (GTK_OBJECT (upload_right_arrow), "clicked", | |
48 | 883 GTK_SIGNAL_FUNC (put_files), NULL); |
587 | 884 gtk_container_add (GTK_CONTAINER (upload_right_arrow), tempwid); |
1 | 885 |
45 | 886 #if GTK_MAJOR_VERSION == 1 |
48 | 887 tempwid = toolbar_pixmap (ui, "left.xpm"); |
1 | 888 #else |
48 | 889 tempwid = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, |
890 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
1 | 891 #endif |
48 | 892 |
587 | 893 download_left_arrow = gtk_button_new (); |
894 gtk_box_pack_start (GTK_BOX (dlbox), download_left_arrow, TRUE, FALSE, 0); | |
895 gtk_signal_connect_object (GTK_OBJECT (download_left_arrow), "clicked", | |
48 | 896 GTK_SIGNAL_FUNC (get_files), NULL); |
587 | 897 gtk_container_add (GTK_CONTAINER (download_left_arrow), tempwid); |
48 | 898 |
899 gtk_paned_pack1 (GTK_PANED (winpane), box, 1, 1); | |
900 | |
129 | 901 window2.prefix_col_str = "remote"; |
902 remote_frame = CreateFTPWindow (&window2); | |
903 | |
48 | 904 gtk_paned_pack2 (GTK_PANED (winpane), remote_frame, 1, 1); |
905 | |
906 dlpane = gtk_vpaned_new (); | |
907 gtk_paned_pack1 (GTK_PANED (dlpane), winpane, 1, 1); | |
908 | |
909 transfer_scroll = gtk_scrolled_window_new (NULL, NULL); | |
129 | 910 gftp_lookup_global_option ("transfer_height", &tmplookup); |
911 gtk_widget_set_size_request (transfer_scroll, -1, tmplookup); | |
48 | 912 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (transfer_scroll), |
913 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
914 | |
915 dltitles[0] = _("Filename"); | |
916 dltitles[1] = _("Progress"); | |
917 dlwdw = gtk_ctree_new_with_titles (2, 0, dltitles); | |
918 gtk_clist_set_selection_mode (GTK_CLIST (dlwdw), GTK_SELECTION_SINGLE); | |
919 gtk_clist_set_reorderable (GTK_CLIST (dlwdw), 0); | |
920 | |
129 | 921 gftp_lookup_global_option ("file_trans_column", &tmplookup); |
922 if (tmplookup == 0) | |
48 | 923 gtk_clist_set_column_auto_resize (GTK_CLIST (dlwdw), 0, TRUE); |
924 else | |
129 | 925 gtk_clist_set_column_width (GTK_CLIST (dlwdw), 0, tmplookup); |
48 | 926 |
115 | 927 gtk_container_add (GTK_CONTAINER (transfer_scroll), dlwdw); |
48 | 928 gtk_signal_connect (GTK_OBJECT (dlwdw), "button_press_event", |
929 GTK_SIGNAL_FUNC (menu_mouse_click), (gpointer) dl_factory); | |
930 gtk_paned_pack2 (GTK_PANED (dlpane), transfer_scroll, 1, 1); | |
931 | |
932 logpane = gtk_vpaned_new (); | |
933 gtk_paned_pack1 (GTK_PANED (logpane), dlpane, 1, 1); | |
934 | |
935 log_table = gtk_table_new (1, 2, FALSE); | |
129 | 936 gftp_lookup_global_option ("log_height", &tmplookup); |
937 gtk_widget_set_size_request (log_table, -1, tmplookup); | |
48 | 938 |
939 #if GTK_MAJOR_VERSION == 1 | |
940 logwdw = gtk_text_new (NULL, NULL); | |
941 | |
942 gtk_text_set_editable (GTK_TEXT (logwdw), FALSE); | |
943 gtk_text_set_word_wrap (GTK_TEXT (logwdw), TRUE); | |
944 | |
945 gtk_table_attach (GTK_TABLE (log_table), logwdw, 0, 1, 0, 1, | |
946 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
947 0, 0); | |
948 gtk_signal_connect (GTK_OBJECT (logwdw), "button_press_event", | |
949 GTK_SIGNAL_FUNC (menu_mouse_click), | |
950 (gpointer) log_factory); | |
951 | |
952 tempwid = gtk_vscrollbar_new (GTK_TEXT (logwdw)->vadj); | |
953 gtk_table_attach (GTK_TABLE (log_table), tempwid, 1, 2, 0, 1, | |
954 GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); | |
955 logwdw_vadj = GTK_TEXT (logwdw)->vadj; | |
956 #else | |
957 logwdw = gtk_text_view_new (); | |
958 gtk_text_view_set_editable (GTK_TEXT_VIEW (logwdw), FALSE); | |
959 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (logwdw), FALSE); | |
960 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (logwdw), GTK_WRAP_WORD); | |
961 | |
962 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
963 | |
964 tag = gtk_text_buffer_create_tag (textbuf, "send", NULL); | |
129 | 965 gftp_lookup_global_option ("send_color", &fore); |
966 g_object_set (G_OBJECT (tag), "foreground_gdk", fore, NULL); | |
48 | 967 |
968 tag = gtk_text_buffer_create_tag (textbuf, "recv", NULL); | |
129 | 969 gftp_lookup_global_option ("recv_color", &fore); |
970 g_object_set (G_OBJECT (tag), "foreground_gdk", fore, NULL); | |
48 | 971 |
972 tag = gtk_text_buffer_create_tag (textbuf, "error", NULL); | |
129 | 973 gftp_lookup_global_option ("error_color", &fore); |
974 g_object_set (G_OBJECT (tag), "foreground_gdk", fore, NULL); | |
48 | 975 |
976 tag = gtk_text_buffer_create_tag (textbuf, "misc", NULL); | |
129 | 977 gftp_lookup_global_option ("misc_color", &fore); |
48 | 978 g_object_set (G_OBJECT (tag), "foreground_gdk", &fore, NULL); |
979 | |
980 tempwid = gtk_scrolled_window_new (NULL, NULL); | |
981 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (tempwid), | |
982 GTK_POLICY_AUTOMATIC, | |
983 GTK_POLICY_AUTOMATIC); | |
984 gtk_container_add (GTK_CONTAINER (tempwid), logwdw); | |
985 gtk_table_attach (GTK_TABLE (log_table), tempwid, 0, 1, 0, 1, | |
986 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
987 0, 0); | |
988 logwdw_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tempwid)); | |
989 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
990 logwdw_textmark = gtk_text_buffer_create_mark (textbuf, "end", &iter, 1); | |
991 #endif | |
992 gtk_paned_pack2 (GTK_PANED (logpane), log_table, 1, 1); | |
993 gtk_box_pack_start (GTK_BOX (mainvbox), logpane, TRUE, TRUE, 0); | |
994 | |
995 gtk_widget_show_all (mainvbox); | |
341 | 996 gftpui_show_or_hide_command (); |
48 | 997 return (mainvbox); |
1 | 998 } |
999 | |
1000 | |
518 | 1001 static void |
48 | 1002 init_gftp (int argc, char *argv[], GtkWidget * parent) |
1 | 1003 { |
48 | 1004 if (argc == 2 && strncmp (argv[1], "--", 2) != 0) |
1 | 1005 { |
48 | 1006 if (gftp_parse_url (window2.request, argv[1]) == 0) |
1007 ftp_connect (&window2, window2.request, 1); | |
1008 else | |
1009 gftp_usage (); | |
1 | 1010 } |
1011 } | |
1012 | |
1013 | |
1014 void | |
1015 toolbar_hostedit (GtkWidget * widget, gpointer data) | |
1016 { | |
173 | 1017 int (*init) (gftp_request * request); |
129 | 1018 gftp_config_list_vars * tmplistvar; |
1 | 1019 GtkWidget *tempwid; |
1020 const char *txt; | |
1021 int num; | |
1022 | |
1023 if (current_wdata->request->stopable) | |
1024 { | |
1025 ftp_log (gftp_logging_misc, NULL, | |
1026 _("%s: Please hit the stop button first to do anything else\n"), | |
1027 _("Connect")); | |
1028 return; | |
1029 } | |
1030 | |
1031 if (GFTP_IS_CONNECTED (current_wdata->request)) | |
380 | 1032 gftpui_disconnect (current_wdata); |
1 | 1033 |
1034 tempwid = gtk_menu_get_active (GTK_MENU (protocol_menu)); | |
195 | 1035 num = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (tempwid))); |
1 | 1036 init = gftp_protocols[num].init; |
173 | 1037 if (init (current_wdata->request) < 0) |
1038 return; | |
1 | 1039 |
395 | 1040 txt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); |
1041 if (strchr (txt, '/') != NULL) | |
1042 { | |
1043 /* The user entered a URL in the host box... */ | |
1044 gftpui_common_cmd_open (current_wdata, current_wdata->request, NULL, NULL, txt); | |
1045 return; | |
1046 } | |
1047 | |
1048 gftp_set_hostname (current_wdata->request, txt); | |
218 | 1049 if (current_wdata->request->hostname == NULL) |
1050 return; | |
1 | 1051 alltrim (current_wdata->request->hostname); |
1052 | |
1053 if (current_wdata->request->need_hostport && | |
1054 *current_wdata->request->hostname == '\0') | |
1055 { | |
1056 ftp_log (gftp_logging_error, NULL, | |
1057 _("Error: You must type in a host to connect to\n")); | |
1058 return; | |
1059 } | |
1060 | |
129 | 1061 gftp_lookup_global_option ("hosthistory", &tmplistvar); |
1062 add_history (hostedit, &tmplistvar->list, &tmplistvar->num_items, | |
1 | 1063 current_wdata->request->hostname); |
1064 | |
1065 if (strchr (current_wdata->request->hostname, '/') != NULL && | |
1066 gftp_parse_url (current_wdata->request, | |
1067 current_wdata->request->hostname) == 0) | |
1068 { | |
1069 ftp_connect (current_wdata, current_wdata->request, 1); | |
1070 return; | |
1071 } | |
1072 | |
1073 txt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry)); | |
1074 gftp_set_port (current_wdata->request, strtol (txt, NULL, 10)); | |
129 | 1075 |
1076 gftp_lookup_global_option ("porthistory", &tmplistvar); | |
1077 add_history (portedit, &tmplistvar->list, &tmplistvar->num_items, txt); | |
1 | 1078 |
1079 gftp_set_username (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry))); | |
218 | 1080 if (current_wdata->request->username != NULL) |
1081 alltrim (current_wdata->request->username); | |
1082 | |
1 | 1083 |
129 | 1084 gftp_lookup_global_option ("userhistory", &tmplistvar); |
1085 add_history (useredit, &tmplistvar->list, &tmplistvar->num_items, | |
1 | 1086 current_wdata->request->username); |
1087 | |
1088 gftp_set_password (current_wdata->request, | |
1089 gtk_entry_get_text (GTK_ENTRY (passedit))); | |
1090 | |
1091 gftp_set_directory (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (current_wdata->combo)->entry))); | |
218 | 1092 if (current_wdata->request->directory != NULL) |
1093 alltrim (current_wdata->request->directory); | |
1 | 1094 |
1095 add_history (current_wdata->combo, current_wdata->history, | |
1096 current_wdata->histlen, current_wdata->request->directory); | |
1097 | |
1098 ftp_connect (current_wdata, current_wdata->request, 1); | |
1099 } | |
1100 | |
1101 | |
1102 void | |
1103 sortrows (GtkCList * clist, gint column, gpointer data) | |
1104 { | |
129 | 1105 char sortcol_name[25], sortasds_name[25]; |
326 | 1106 intptr_t sortcol, sortasds; |
1 | 1107 gftp_window_data * wdata; |
16 | 1108 GtkWidget * sort_wid; |
1109 GList * templist; | |
472 | 1110 int swap_col; |
1 | 1111 |
1112 wdata = data; | |
505 | 1113 g_snprintf (sortcol_name, sizeof (sortcol_name), "%s_sortcol", |
1114 wdata->prefix_col_str); | |
129 | 1115 gftp_lookup_global_option (sortcol_name, &sortcol); |
505 | 1116 g_snprintf (sortasds_name, sizeof (sortasds_name), "%s_sortasds", |
1117 wdata->prefix_col_str); | |
129 | 1118 gftp_lookup_global_option (sortasds_name, &sortasds); |
1119 | |
1120 if (column == -1) | |
1121 column = sortcol; | |
1122 | |
1123 if (column == 0 || (column == sortcol && wdata->sorted)) | |
1 | 1124 { |
129 | 1125 sortasds = !sortasds; |
227 | 1126 gftp_set_global_option (sortasds_name, GINT_TO_POINTER (sortasds)); |
19 | 1127 swap_col = 1; |
1128 } | |
1129 else | |
1130 swap_col = 0; | |
1131 | |
1132 if (swap_col || !wdata->sorted) | |
1133 { | |
1 | 1134 sort_wid = gtk_clist_get_column_widget (clist, 0); |
1135 gtk_widget_destroy (sort_wid); | |
45 | 1136 #if GTK_MAJOR_VERSION == 1 |
129 | 1137 if (sortasds) |
1 | 1138 sort_wid = toolbar_pixmap (wdata->listbox, "down.xpm"); |
1139 else | |
1140 sort_wid = toolbar_pixmap (wdata->listbox, "up.xpm"); | |
19 | 1141 #else |
129 | 1142 if (sortasds) |
19 | 1143 sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_ASCENDING, |
1144 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
1145 else | |
1146 sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_DESCENDING, | |
1147 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
1148 #endif | |
1149 | |
1 | 1150 gtk_clist_set_column_widget (clist, 0, sort_wid); |
1151 } | |
1152 else | |
129 | 1153 { |
1154 sortcol = column; | |
227 | 1155 gftp_set_global_option (sortcol_name, GINT_TO_POINTER (sortcol)); |
129 | 1156 } |
37 | 1157 |
1158 if (!GFTP_IS_CONNECTED (wdata->request)) | |
1159 return; | |
1 | 1160 |
1161 gtk_clist_freeze (clist); | |
1162 gtk_clist_clear (clist); | |
1163 | |
129 | 1164 wdata->files = gftp_sort_filelist (wdata->files, sortcol, sortasds); |
1 | 1165 |
16 | 1166 templist = wdata->files; |
1167 while (templist != NULL) | |
1 | 1168 { |
16 | 1169 add_file_listbox (wdata, templist->data); |
1170 templist = templist->next; | |
1 | 1171 } |
1172 | |
1173 wdata->sorted = 1; | |
1174 gtk_clist_thaw (clist); | |
1175 update_window_info (); | |
1176 } | |
1177 | |
1178 | |
1179 void | |
1180 stop_button (GtkWidget * widget, gpointer data) | |
1181 { | |
1182 pthread_t comptid; | |
1183 | |
1184 memset (&comptid, 0, sizeof (comptid)); | |
1185 if (!pthread_equal (comptid, window1.tid)) | |
1186 pthread_kill (window1.tid, SIGINT); | |
1187 else if (!pthread_equal (comptid, window2.tid)) | |
1188 pthread_kill (window2.tid, SIGINT); | |
1189 } | |
1190 | |
48 | 1191 |
198 | 1192 static int |
1193 gftp_gtk_config_file_read_color (char *str, gftp_config_vars * cv, int line) | |
1194 { | |
1195 char *red, *green, *blue; | |
1196 GdkColor * color; | |
1197 | |
1198 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL) | |
1199 g_free (cv->value); | |
1200 | |
1201 gftp_config_parse_args (str, 3, line, &red, &green, &blue); | |
1202 | |
1203 color = g_malloc (sizeof (*color)); | |
1204 color->red = strtol (red, NULL, 16); | |
1205 color->green = strtol (green, NULL, 16); | |
1206 color->blue = strtol (blue, NULL, 16); | |
447 | 1207 |
198 | 1208 g_free (red); |
1209 g_free (green); | |
1210 g_free (blue); | |
1211 | |
1212 cv->value = color; | |
1213 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM; | |
1214 | |
1215 return (0); | |
1216 } | |
1217 | |
1218 | |
1219 static int | |
387 | 1220 gftp_gtk_config_file_write_color (gftp_config_vars * cv, char *buf, |
1221 size_t buflen, int to_config_file) | |
198 | 1222 { |
1223 GdkColor * color; | |
1224 | |
1225 color = cv->value; | |
387 | 1226 g_snprintf (buf, buflen, "%x:%x:%x", color->red, color->green, color->blue); |
198 | 1227 return (0); |
1228 } | |
1229 | |
1230 | |
48 | 1231 int |
1232 main (int argc, char **argv) | |
1233 { | |
1234 GtkWidget *window, *ui; | |
1235 | |
447 | 1236 /* We override the read color functions because we are using a GdkColor |
1237 structures to store the color. If I put this in lib/config_file.c, then | |
1238 the core library would be dependant on Gtk+ being present */ | |
1239 gftp_option_types[gftp_option_type_color].read_function = gftp_gtk_config_file_read_color; | |
1240 gftp_option_types[gftp_option_type_color].write_function = gftp_gtk_config_file_write_color; | |
1241 | |
374 | 1242 gftpui_common_init (&argc, &argv, ftp_log); |
498 | 1243 gftpui_common_child_process_done = 0; |
374 | 1244 |
48 | 1245 g_thread_init (NULL); |
496 | 1246 |
1247 #if GTK_MAJOR_VERSION > 1 | |
460 | 1248 gdk_threads_init(); |
496 | 1249 #endif |
460 | 1250 |
56 | 1251 main_thread_id = pthread_self (); |
48 | 1252 gtk_set_locale (); |
1253 gtk_init (&argc, &argv); | |
1254 | |
374 | 1255 graphic_hash_table = g_hash_table_new (string_hash_function, |
1256 string_hash_compare); | |
198 | 1257 |
48 | 1258 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
1259 gtk_signal_connect (GTK_OBJECT (window), "delete_event", | |
505 | 1260 GTK_SIGNAL_FUNC (_gftp_try_close), NULL); |
48 | 1261 gtk_signal_connect (GTK_OBJECT (window), "destroy", |
505 | 1262 GTK_SIGNAL_FUNC (_gftp_force_close), NULL); |
129 | 1263 gtk_window_set_title (GTK_WINDOW (window), gftp_version); |
48 | 1264 gtk_window_set_wmclass (GTK_WINDOW(window), "main", "gFTP"); |
129 | 1265 gtk_widget_set_name (window, gftp_version); |
48 | 1266 gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE); |
1267 gtk_widget_realize (window); | |
1268 | |
1269 gftp_icon = open_xpm (window, "gftp.xpm"); | |
1270 if (gftp_icon != NULL) | |
1271 { | |
1272 gdk_window_set_icon (window->window, NULL, gftp_icon->pixmap, | |
1273 gftp_icon->bitmap); | |
168 | 1274 gdk_window_set_icon_name (window->window, gftp_version); |
48 | 1275 } |
1276 | |
1277 other_wdata = &window1; | |
1278 current_wdata = &window2; | |
1279 ui = CreateFTPWindows (window); | |
1280 gtk_container_add (GTK_CONTAINER (window), ui); | |
1281 gtk_widget_show (window); | |
1282 | |
341 | 1283 gftpui_common_about (ftp_log, NULL); |
48 | 1284 |
1285 gtk_timeout_add (1000, update_downloads, NULL); | |
173 | 1286 if (gftp_protocols[GFTP_LOCAL_NUM].init (window1.request) == 0) |
1287 { | |
422 | 1288 gftp_setup_startup_directory (window1.request); |
173 | 1289 gftp_connect (window1.request); |
496 | 1290 ftp_list_files (&window1); |
173 | 1291 } |
48 | 1292 |
1293 /* On the remote window, even though we aren't connected, draw the sort | |
1294 icon on that side */ | |
129 | 1295 sortrows (GTK_CLIST (window2.listbox), -1, &window2); |
48 | 1296 |
1297 init_gftp (argc, argv, window); | |
1298 | |
1299 GDK_THREADS_ENTER (); | |
1300 gtk_main (); | |
1301 GDK_THREADS_LEAVE (); | |
374 | 1302 |
48 | 1303 return (0); |
1304 } | |
1305 | |
374 | 1306 |
341 | 1307 void |
1308 gftpui_show_or_hide_command (void) | |
1309 { | |
1310 intptr_t cmd_in_gui; | |
48 | 1311 |
341 | 1312 gftp_lookup_global_option ("cmd_in_gui", &cmd_in_gui); |
1313 if (cmd_in_gui) | |
1314 gtk_widget_show (gftpui_command_toolbar); | |
1315 else | |
1316 gtk_widget_hide (gftpui_command_toolbar); | |
1317 } | |
1318 |