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