Mercurial > gftp.yaz
annotate src/gtk/gftp-gtk.c @ 58:c01d91c10f6c
2002-11-20 Brian Masney <masneyb@gftp.org>
* lib/protocols.c lib/gftp.h - added gftp_get_line(), gftp_read(),
gftp_write(), gftp_writefmt(), and gftp_set_sockblocking() functions.
Added struct_gftp_getline_buffer for gftp_get_line function()
* lib/cache.c lib/gftp.h lib/local.c lib/misc.c lib/protocols.c
lib/rfc2068.c lib/rfc959.c lib/ssh.c lib/sshv2.c - *_get_file() returns
off_t instead of long. *_{get,put}_next_file_chunk returns ssize_t
instead of size_t. Added *_set_config_options function to gftp_request
structure and protocol files. Use the new network functions
documented above. Convert usage of ANSI C IO (FILE *) to standard BSD
sockets so that I can use timeouts properly with select
* lib/misc.c (ssh_start_login_sequence) - use gftp_set_sockblock(),
gftp_read() and gftp_write() functions
* lib/protocols.c - move some protocol specific code to the protocol
specific files
* lib/local.c - log succesful messages to gftp_logging_misc instead
of gftp_logging_error
* lib/cache.c - log some more error conditions to the user
* lib/rfc959.c - added rfc959_getcwd(). In,
rfc959_accept_active_connection(), set set socket to blocking mode
before calling accept()
* src/text/gftk-text.c - If we get no files in gftp_text_ls(),
return instead of segfaulting
* src/gtk/gftp-gtk.c - expand the port field in the toolbar to be 45
pixels wide
* src/text/gftp-text.c src/gtk/misc-gtk.c src/gtk/transfer.c
src/gtk/view_dialog.c - changes for conversion of request->{sock,data}
from ANSI C IO (FILE *) to standard BSD sockets
author | masneyb |
---|---|
date | Thu, 21 Nov 2002 00:33:51 +0000 |
parents | a12bcbc2fce4 |
children | 41b71c4e5076 |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* gftp-gtk.c - GTK+ 1.2 port of gftp */ | |
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */ | |
4 /* */ | |
5 /* This program is free software; you can redistribute it and/or modify */ | |
6 /* it under the terms of the GNU General Public License as published by */ | |
7 /* the Free Software Foundation; either version 2 of the License, or */ | |
8 /* (at your option) any later version. */ | |
9 /* */ | |
10 /* This program is distributed in the hope that it will be useful, */ | |
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
13 /* GNU General Public License for more details. */ | |
14 /* */ | |
15 /* You should have received a copy of the GNU General Public License */ | |
16 /* along with this program; if not, write to the Free Software */ | |
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ | |
18 /*****************************************************************************/ | |
19 | |
20 #include "gftp-gtk.h" | |
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, | |
25 * openurl_btn; | |
26 | |
27 gftp_window_data window1, window2, *other_wdata, *current_wdata; | |
28 GtkWidget * stop_btn, * hostedit, * useredit, * passedit, * portedit, * logwdw, | |
29 * dlwdw, * protocol_menu, * optionmenu; | |
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 transfer_mutex = PTHREAD_MUTEX_INITIALIZER; | |
39 pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; | |
19 | 40 gftp_graphic * gftp_icon; |
33 | 41 int gftp_is_started = 0; |
42 | 42 sigjmp_buf jmp_environment; |
43 volatile int use_jmp_environment = 0; | |
56 | 44 pthread_t main_thread_id; |
42 | 45 |
48 | 46 static int |
47 get_column (GtkCListColumn * col) | |
1 | 48 { |
48 | 49 if (col->auto_resize) |
50 return (0); | |
51 else if (!col->visible) | |
52 return (-1); | |
53 else | |
54 return (col->width); | |
55 } | |
42 | 56 |
1 | 57 |
48 | 58 static void |
59 doexit (GtkWidget * widget, gpointer data) | |
60 { | |
61 listbox_local_width = GTK_WIDGET (local_frame)->allocation.width; | |
62 listbox_remote_width = GTK_WIDGET (remote_frame)->allocation.width; | |
63 listbox_file_height = GTK_WIDGET (remote_frame)->allocation.height; | |
64 log_height = GTK_WIDGET (log_table)->allocation.height; | |
65 transfer_height = GTK_WIDGET (transfer_scroll)->allocation.height; | |
1 | 66 |
48 | 67 local_columns[0] = get_column (>K_CLIST (window1.listbox)->column[1]); |
68 local_columns[1] = get_column (>K_CLIST (window1.listbox)->column[2]); | |
69 local_columns[2] = get_column (>K_CLIST (window1.listbox)->column[3]); | |
70 local_columns[3] = get_column (>K_CLIST (window1.listbox)->column[4]); | |
71 local_columns[4] = get_column (>K_CLIST (window1.listbox)->column[5]); | |
72 local_columns[5] = get_column (>K_CLIST (window1.listbox)->column[6]); | |
1 | 73 |
48 | 74 remote_columns[0] = get_column (>K_CLIST (window2.listbox)->column[1]); |
75 remote_columns[1] = get_column (>K_CLIST (window2.listbox)->column[2]); | |
76 remote_columns[2] = get_column (>K_CLIST (window2.listbox)->column[3]); | |
77 remote_columns[3] = get_column (>K_CLIST (window2.listbox)->column[4]); | |
78 remote_columns[4] = get_column (>K_CLIST (window2.listbox)->column[5]); | |
79 remote_columns[5] = get_column (>K_CLIST (window2.listbox)->column[6]); | |
37 | 80 |
48 | 81 file_trans_column = get_column (>K_CLIST (dlwdw)->column[0]); |
37 | 82 |
48 | 83 gftp_write_config_file (); |
84 gftp_clear_cache_files (); | |
85 exit (0); | |
1 | 86 } |
87 | |
88 | |
89 static gint | |
90 delete_event (GtkWidget * widget, GdkEvent * event, gpointer data) | |
91 { | |
92 if (file_transfers == NULL) | |
93 doexit (NULL, NULL); | |
94 else | |
95 { | |
19 | 96 MakeYesNoDialog (_("Exit"), _("There are file transfers in progress.\nAre you sure you want to exit?"), doexit, NULL, NULL, NULL); |
1 | 97 return (TRUE); |
98 } | |
99 return (FALSE); | |
100 } | |
101 | |
102 | |
103 static void | |
104 destroy (GtkWidget * widget, gpointer data) | |
105 { | |
106 exit (0); | |
107 } | |
108 | |
109 | |
110 static RETSIGTYPE | |
111 sig_child (int signo) | |
112 { | |
113 viewedit_process_done = 1; | |
114 } | |
115 | |
116 | |
48 | 117 static void |
118 menu_exit (GtkWidget * widget, gpointer data) | |
1 | 119 { |
48 | 120 if (!delete_event (widget, NULL, data)) |
121 doexit (widget, data); | |
122 } | |
1 | 123 |
124 | |
48 | 125 static void |
126 chfunc (gpointer data) | |
127 { | |
128 chdir_dialog (data); | |
1 | 129 } |
130 | |
131 | |
132 static GtkWidget * | |
133 CreateMenus (GtkWidget * parent) | |
134 { | |
135 int local_len, remote_len, len, i, trans_len, log_len, tools_len; | |
136 GtkAccelGroup *accel_group; | |
137 GtkWidget * tempwid; | |
7 | 138 static GtkItemFactoryEntry menu_items[] = { |
12 | 139 {N_("/_FTP"), NULL, 0, 0, MN_("<Branch>")}, |
140 {N_("/FTP/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
141 {N_("/FTP/Window 1"), NULL, change_setting, 3, MN_("<RadioItem>")}, | |
142 {N_("/FTP/Window 2"), NULL, change_setting, 4, MN_("/FTP/Window 1")}, | |
143 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
144 {N_("/FTP/Ascii"), NULL, change_setting, 1, MN_("<RadioItem>")}, | |
145 {N_("/FTP/Binary"), NULL, change_setting, 2, MN_("/FTP/Ascii")}, | |
146 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
147 {N_("/FTP/_Options..."), "<control>O", options_dialog, 0, | |
148 MS_(GTK_STOCK_PREFERENCES)}, | |
149 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
150 {N_("/FTP/_Quit"), "<control>Q", menu_exit, 0, MS_(GTK_STOCK_QUIT)}, | |
151 {N_("/_Local"), NULL, 0, 0, MN_("<Branch>")}, | |
152 {N_("/Local/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
153 {N_("/Local/Open _URL..."), NULL, openurl_dialog, 0, MS_(GTK_STOCK_OPEN)}, | |
154 {N_("/Local/Disconnect"), NULL, disconnect, 0, MS_(GTK_STOCK_CLOSE)}, | |
155 {N_("/Local/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
156 {N_("/Local/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, | |
157 {N_("/Local/Show selected"), NULL, show_selected, 0, MN_(NULL)}, | |
158 {N_("/Local/Select All"), NULL, selectall, 0, MN_(NULL)}, | |
159 {N_("/Local/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, | |
160 {N_("/Local/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, | |
161 {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
|
162 {N_("/Local/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, |
12 | 163 {N_("/Local/Send SITE Command..."), NULL, site_dialog, 0, MN_(NULL)}, |
164 {N_("/Local/Change Directory"), NULL, chfunc, 0, MN_(NULL)}, | |
165 {N_("/Local/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, | |
166 {N_("/Local/Make Directory..."), NULL, mkdir_dialog, 0, MN_(NULL)}, | |
167 {N_("/Local/Rename..."), NULL, rename_dialog, 0, MN_(NULL)}, | |
168 {N_("/Local/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, | |
169 {N_("/Local/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, | |
170 {N_("/Local/View..."), NULL, view_dialog, 0, MN_(NULL)}, | |
171 {N_("/Local/Refresh"), NULL, refresh, 0, MS_(GTK_STOCK_REFRESH)}, | |
172 {N_("/_Remote"), NULL, 0, 0, MN_("<Branch>")}, | |
173 {N_("/Remote/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
174 {N_("/Remote/Open _URL..."), "<control>U", openurl_dialog, 0, | |
175 MS_(GTK_STOCK_OPEN)}, | |
176 {N_("/Remote/Disconnect"), "<control>D", disconnect, 0, | |
177 MS_(GTK_STOCK_CLOSE)}, | |
178 {N_("/Remote/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
179 {N_("/Remote/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, | |
180 {N_("/Remote/Show selected"), NULL, show_selected, 0, MN_(NULL)}, | |
181 {N_("/Remote/Select All"), NULL, selectall, 0, MN_(NULL)}, | |
182 {N_("/Remote/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, | |
183 {N_("/Remote/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, | |
184 {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
|
185 {N_("/Remote/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, |
12 | 186 {N_("/Remote/Send SITE Command..."), NULL, site_dialog, 0, MN_(NULL)}, |
187 {N_("/Remote/Change Directory"), NULL, chfunc, 0, MN_(NULL)}, | |
188 {N_("/Remote/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, | |
189 {N_("/Remote/Make Directory..."), NULL, mkdir_dialog, 0, MN_(NULL)}, | |
190 {N_("/Remote/Rename..."), NULL, rename_dialog, 0, MN_(NULL)}, | |
191 {N_("/Remote/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, | |
192 {N_("/Remote/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, | |
193 {N_("/Remote/View..."), NULL, view_dialog, 0, MN_(NULL)}, | |
194 {N_("/Remote/Refresh"), NULL, refresh, 0, MS_(GTK_STOCK_REFRESH)}, | |
195 {N_("/_Bookmarks"), NULL, 0, 0, MN_("<Branch>")}, | |
196 {N_("/Bookmarks/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
197 {N_("/Bookmarks/Add bookmark"), "<control>A", add_bookmark, 0, | |
198 MS_(GTK_STOCK_ADD)}, | |
199 {N_("/Bookmarks/Edit bookmarks"), NULL, edit_bookmarks, 0, MN_(NULL)}, | |
200 {N_("/Bookmarks/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
201 {N_("/_Transfers"), NULL, 0, 0, MN_("<Branch>")}, | |
202 {N_("/Transfers/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
203 {N_("/Transfers/Start Transfer"), NULL, start_transfer, 0, MN_(NULL)}, | |
204 {N_("/Transfers/Stop Transfer"), NULL, stop_transfer, 0, | |
205 MS_(GTK_STOCK_STOP)}, | |
206 {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
207 {N_("/Transfers/Skip Current File"), NULL, skip_transfer, 0, MN_(NULL)}, | |
208 {N_("/Transfers/Remove File"), NULL, remove_file_transfer, 0, | |
209 MS_(GTK_STOCK_DELETE)}, | |
210 {N_("/Transfers/Move File _Up"), NULL, move_transfer_up, 0, | |
211 MS_(GTK_STOCK_GO_UP)}, | |
212 {N_("/Transfers/Move File _Down"), NULL, move_transfer_down, 0, | |
213 MS_(GTK_STOCK_GO_DOWN)}, | |
214 {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
215 {N_("/Transfers/Retrieve Files"), "<control>R", get_files, 0, MN_(NULL)}, | |
216 {N_("/Transfers/Put Files"), "<control>P", put_files, 0, MN_(NULL)}, | |
217 {N_("/L_ogging"), NULL, 0, 0, MN_("<Branch>")}, | |
218 {N_("/Logging/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
219 {N_("/Logging/Clear"), NULL, clearlog, 0, MS_(GTK_STOCK_CLEAR)}, | |
220 {N_("/Logging/View log..."), NULL, viewlog, 0, MN_(NULL)}, | |
221 {N_("/Logging/Save log..."), NULL, savelog, 0, MS_(GTK_STOCK_SAVE)}, | |
222 {N_("/Tool_s"), NULL, 0, 0, MN_("<Branch>")}, | |
223 {N_("/Tools/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
224 {N_("/Tools/Compare Windows"), NULL, compare_windows, 0, MN_(NULL)}, | |
225 {N_("/Tools/Clear Cache"), NULL, clear_cache, 0, MS_(GTK_STOCK_CLEAR)}, | |
226 {N_("/_Help"), NULL, 0, 0, MN_("<LastBranch>")}, | |
227 {N_("/Help/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
228 {N_("/Help/About..."), NULL, about_dialog, 0, MS_(GTK_STOCK_HELP)} | |
1 | 229 }; |
230 | |
231 menus = menu_items; | |
232 | |
233 accel_group = gtk_accel_group_new (); | |
7 | 234 factory = item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group, NULL); |
1 | 235 |
236 i = 0; | |
237 len = 11; | |
238 /* FTP Menu */ | |
239 create_item_factory (factory, len, menu_items, &window2); | |
240 | |
241 i += len; | |
242 /* Local Menu */ | |
243 local_start = i; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
244 local_len = 21; |
1 | 245 create_item_factory (factory, local_len, menu_items + i, &window1); |
246 | |
247 i += local_len; | |
248 /* Remote Menu */ | |
249 remote_start = i; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
250 remote_len = 21; |
1 | 251 create_item_factory (factory, remote_len, menu_items + i, &window2); |
252 | |
253 i += remote_len; | |
254 len = 5; | |
255 /* Bookmarks Menu */ | |
256 create_item_factory (factory, len, menu_items + i, &window2); | |
257 | |
258 i += len; | |
259 /* Transfers Menu */ | |
260 trans_start = i; | |
261 trans_len = 12; | |
262 create_item_factory (factory, trans_len, menu_items + i, NULL); | |
263 | |
264 i += trans_len; | |
265 /* Logging Menu */ | |
266 log_start = i; | |
267 log_len = 5; | |
268 create_item_factory (factory, log_len, menu_items + i, NULL); | |
269 | |
270 i += log_len; | |
271 /* Tools Menu */ | |
272 tools_start = i; | |
273 tools_len = 4; | |
274 create_item_factory (factory, tools_len, menu_items + i, NULL); | |
275 | |
276 i += tools_len; | |
277 /* Help Menu */ | |
278 create_item_factory (factory, 3, menu_items + i, NULL); | |
279 | |
280 build_bookmarks_menu (); | |
281 | |
44 | 282 gtk_window_add_accel_group (GTK_WINDOW (parent), accel_group); |
1 | 283 |
7 | 284 tempwid = gtk_item_factory_get_widget (factory, menu_items[6].path); |
1 | 285 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (tempwid), TRUE); |
286 | |
7 | 287 tempwid = gtk_item_factory_get_widget (factory, menu_items[3].path); |
1 | 288 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (tempwid), TRUE); |
289 | |
7 | 290 window1.ifactory = item_factory_new (GTK_TYPE_MENU, "<local>", NULL, "/Local"); |
291 create_item_factory (window1.ifactory, local_len - 2, menu_items + local_start + 2, &window1); | |
292 | |
293 window2.ifactory = item_factory_new (GTK_TYPE_MENU, "<remote>", NULL, "/Remote"); | |
294 create_item_factory (window2.ifactory, remote_len - 2, menu_items + remote_start + 2, &window2); | |
1 | 295 |
7 | 296 log_factory = item_factory_new (GTK_TYPE_MENU, "<log>", NULL, "/Logging"); |
297 create_item_factory (log_factory, log_len - 2, menu_items + log_start + 2, NULL); | |
1 | 298 |
7 | 299 dl_factory = item_factory_new (GTK_TYPE_MENU, "<download>", NULL, "/Transfers"); |
300 create_item_factory (dl_factory, trans_len - 2, menu_items + trans_start + 2, NULL); | |
1 | 301 |
302 return (factory->widget); | |
303 } | |
304 | |
305 | |
306 static GtkWidget * | |
307 CreateToolbar (GtkWidget * parent) | |
308 { | |
309 const GtkTargetEntry possible_types[] = { | |
310 {"STRING", 0, 0}, | |
311 {"text/plain", 0, 0}, | |
312 {"application/x-rootwin-drop", 0, 1} | |
313 }; | |
314 GtkWidget *toolbar, *box, *tempwid; | |
315 int i, num; | |
316 | |
317 toolbar = gtk_handle_box_new (); | |
318 | |
319 box = gtk_hbox_new (FALSE, 4); | |
320 gtk_container_add (GTK_CONTAINER (toolbar), box); | |
321 gtk_container_border_width (GTK_CONTAINER (box), 5); | |
322 | |
323 tempwid = toolbar_pixmap (parent, "connect.xpm"); | |
324 openurl_btn = gtk_button_new (); | |
325 gtk_container_add (GTK_CONTAINER (openurl_btn), tempwid); | |
326 gtk_signal_connect_object (GTK_OBJECT (openurl_btn), "clicked", | |
327 GTK_SIGNAL_FUNC (tb_openurl_dialog), NULL); | |
328 gtk_signal_connect (GTK_OBJECT (openurl_btn), "drag_data_received", | |
329 GTK_SIGNAL_FUNC (openurl_get_drag_data), NULL); | |
330 gtk_drag_dest_set (openurl_btn, GTK_DEST_DEFAULT_ALL, possible_types, 2, | |
331 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
332 gtk_container_border_width (GTK_CONTAINER (openurl_btn), 1); | |
333 gtk_box_pack_start (GTK_BOX (box), openurl_btn, FALSE, FALSE, 0); | |
334 | |
335 tempwid = gtk_label_new (_("Host: ")); | |
336 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
337 | |
338 hostedit = gtk_combo_new (); | |
339 gtk_combo_set_case_sensitive (GTK_COMBO (hostedit), 1); | |
340 gtk_widget_set_size_request (hostedit, 130, -1); | |
341 | |
342 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (hostedit)->entry), "activate", | |
343 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
344 if (host_history) | |
345 gtk_combo_set_popdown_strings (GTK_COMBO (hostedit), host_history); | |
346 gtk_combo_disable_activate (GTK_COMBO (hostedit)); | |
347 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry), ""); | |
348 gtk_box_pack_start (GTK_BOX (box), hostedit, TRUE, TRUE, 0); | |
349 | |
350 tempwid = gtk_label_new (_("Port: ")); | |
351 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
352 | |
353 portedit = gtk_combo_new (); | |
354 gtk_combo_set_case_sensitive (GTK_COMBO (portedit), 1); | |
58 | 355 gtk_widget_set_size_request (portedit, 45, -1); |
1 | 356 |
357 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (portedit)->entry), "activate", | |
358 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
359 if (port_history) | |
360 gtk_combo_set_popdown_strings (GTK_COMBO (portedit), port_history); | |
361 gtk_combo_disable_activate (GTK_COMBO (portedit)); | |
362 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (portedit)->entry), ""); | |
363 gtk_box_pack_start (GTK_BOX (box), portedit, FALSE, FALSE, 0); | |
364 | |
365 tempwid = gtk_label_new (_("User: ")); | |
366 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
367 | |
368 useredit = gtk_combo_new (); | |
369 gtk_combo_set_case_sensitive (GTK_COMBO (useredit), 1); | |
370 gtk_widget_set_size_request (useredit, 75, -1); | |
371 | |
372 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (useredit)->entry), "activate", | |
373 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
374 if (user_history) | |
375 gtk_combo_set_popdown_strings (GTK_COMBO (useredit), user_history); | |
376 gtk_combo_disable_activate (GTK_COMBO (useredit)); | |
377 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (useredit)->entry), ""); | |
378 gtk_box_pack_start (GTK_BOX (box), useredit, TRUE, TRUE, 0); | |
379 | |
380 tempwid = gtk_label_new (_("Pass: ")); | |
381 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
382 | |
383 passedit = gtk_entry_new (); | |
384 gtk_widget_set_size_request (passedit, 55, -1); | |
385 | |
386 gtk_entry_set_visibility (GTK_ENTRY (passedit), FALSE); | |
387 gtk_signal_connect (GTK_OBJECT (passedit), "activate", | |
388 GTK_SIGNAL_FUNC (toolbar_hostedit), NULL); | |
389 gtk_box_pack_start (GTK_BOX (box), passedit, FALSE, FALSE, 0); | |
390 | |
391 tempwid = gtk_vbox_new (FALSE, 0); | |
392 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
393 | |
394 optionmenu = gtk_option_menu_new (); | |
395 gtk_box_pack_start (GTK_BOX (tempwid), optionmenu, TRUE, FALSE, 0); | |
396 | |
397 num = 0; | |
398 protocol_menu = gtk_menu_new (); | |
399 for (i = 0; gftp_protocols[i].name; i++) | |
400 { | |
401 if (!gftp_protocols[i].shown) | |
402 continue; | |
403 | |
404 if (strcmp (gftp_protocols[i].name, default_protocol) == 0) | |
405 num = i; | |
406 | |
407 tempwid = gtk_menu_item_new_with_label (gftp_protocols[i].name); | |
408 gtk_object_set_user_data (GTK_OBJECT (tempwid), (gpointer) i); | |
409 gtk_menu_append (GTK_MENU (protocol_menu), tempwid); | |
410 gtk_widget_show (tempwid); | |
411 } | |
412 gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), protocol_menu); | |
413 gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), num); | |
414 | |
45 | 415 #if GTK_MAJOR_VERSION == 1 |
21 | 416 tempwid = toolbar_pixmap (parent, "stop.xpm"); |
19 | 417 #else |
418 tempwid = gtk_image_new_from_stock (GTK_STOCK_STOP, | |
419 GTK_ICON_SIZE_LARGE_TOOLBAR); | |
420 #endif | |
421 | |
1 | 422 stop_btn = gtk_button_new (); |
423 gtk_container_add (GTK_CONTAINER (stop_btn), tempwid); | |
424 gtk_widget_set_sensitive (stop_btn, 0); | |
425 gtk_signal_connect_object (GTK_OBJECT (stop_btn), "clicked", | |
426 GTK_SIGNAL_FUNC (stop_button), NULL); | |
427 gtk_container_border_width (GTK_CONTAINER (stop_btn), 1); | |
428 gtk_box_pack_start (GTK_BOX (box), stop_btn, FALSE, FALSE, 0); | |
429 | |
430 return (toolbar); | |
431 } | |
432 | |
433 | |
434 static void | |
48 | 435 setup_column (GtkWidget * listbox, int column, int width) |
1 | 436 { |
48 | 437 if (width == 0) |
438 gtk_clist_set_column_auto_resize (GTK_CLIST (listbox), column, TRUE); | |
439 else if (width == -1) | |
440 gtk_clist_set_column_visibility (GTK_CLIST (listbox), column, FALSE); | |
441 else | |
442 gtk_clist_set_column_width (GTK_CLIST (listbox), column, width); | |
1 | 443 } |
444 | |
445 | |
48 | 446 static void |
447 list_doaction (gftp_window_data * wdata) | |
1 | 448 { |
48 | 449 GList *templist, *filelist; |
450 int num, dir, success; | |
451 gftp_file *tempfle; | |
452 | |
453 filelist = wdata->files; | |
454 templist = GTK_CLIST (wdata->listbox)->selection; | |
455 num = 0; | |
456 templist = get_next_selection (templist, &filelist, &num); | |
457 tempfle = (gftp_file *) filelist->data; | |
458 | |
459 dir = tempfle->isdir; | |
460 success = 0; | |
1 | 461 |
48 | 462 if (tempfle->islink || tempfle->isdir) |
463 success = chdir_dialog (wdata); | |
1 | 464 |
48 | 465 if (!dir && !success) |
1 | 466 { |
48 | 467 switch (listbox_dblclick_action) |
468 { | |
469 case 0: | |
470 view_dialog (wdata); | |
471 break; | |
472 case 1: | |
473 edit_dialog (wdata); | |
474 break; | |
475 case 2: | |
476 if (wdata == &window2) | |
477 get_files (wdata); | |
478 else | |
479 put_files (wdata); | |
480 break; | |
481 } | |
1 | 482 } |
483 } | |
484 | |
485 | |
48 | 486 static gint |
487 list_enter (GtkWidget * widget, GdkEventKey * event, gpointer data) | |
488 { | |
489 gftp_window_data * wdata; | |
490 | |
491 wdata = data; | |
492 if (!GFTP_IS_CONNECTED (wdata->request)) | |
493 return (TRUE); | |
494 | |
495 if (event->type == GDK_KEY_PRESS && | |
496 (event->keyval == GDK_KP_Delete || event->keyval == GDK_Delete)) | |
497 { | |
498 delete_dialog (wdata); | |
499 return (FALSE); | |
500 } | |
501 else if (IS_ONE_SELECTED (wdata) && event->type == GDK_KEY_PRESS && | |
502 event->keyval == GDK_Return) | |
503 { | |
504 list_doaction (wdata); | |
505 return (FALSE); | |
506 } | |
507 return (TRUE); | |
508 } | |
509 | |
510 | |
511 static gint | |
512 list_dblclick (GtkWidget * widget, GdkEventButton * event, gpointer data) | |
1 | 513 { |
48 | 514 gftp_window_data * wdata; |
515 | |
516 wdata = data; | |
51 | 517 |
48 | 518 if (event->button == 3) |
519 gtk_item_factory_popup (wdata->ifactory, (guint) event->x_root, | |
520 (guint) event->y_root, 3, event->time); | |
51 | 521 return (FALSE); |
522 } | |
523 | |
48 | 524 |
51 | 525 void |
526 select_row_callback (GtkWidget *widget, gint row, gint column, | |
527 GdkEventButton *event, gpointer data) | |
528 { | |
529 gftp_window_data * wdata; | |
50 | 530 |
51 | 531 wdata = data; |
50 | 532 |
51 | 533 if (event != NULL && event->type == GDK_2BUTTON_PRESS && event->button == 1 && |
534 GFTP_IS_CONNECTED (wdata->request) && IS_ONE_SELECTED (wdata)) | |
535 list_doaction (wdata); | |
1 | 536 } |
537 | |
538 | |
539 static GtkWidget * | |
540 CreateFTPWindow (gftp_window_data * wdata, int width, int columns[6]) | |
541 { | |
542 const GtkTargetEntry possible_types[] = { | |
543 {"STRING", 0, 0}, | |
544 {"text/plain", 0, 0}, | |
545 {"application/x-rootwin-drop", 0, 1} | |
546 }; | |
547 GtkWidget *box, *scroll_list, *parent; | |
548 char *titles[7]; | |
549 | |
550 titles[0] = ""; | |
551 titles[1] = _("Filename"); | |
552 titles[2] = _("Size"); | |
553 titles[3] = _("User"); | |
554 titles[4] = _("Group"); | |
555 titles[5] = _("Date"); | |
556 titles[6] = _("Attribs"); | |
557 | |
558 wdata->request = gftp_request_new (); | |
559 wdata->request->logging_function = ftp_log; | |
560 wdata->filespec = g_malloc0 (2); | |
561 *wdata->filespec = '*'; | |
562 | |
563 parent = gtk_frame_new (NULL); | |
564 gtk_widget_set_size_request (parent, width, listbox_file_height); | |
565 | |
566 gtk_container_border_width (GTK_CONTAINER (parent), 5); | |
567 | |
568 box = gtk_vbox_new (FALSE, 0); | |
569 gtk_container_border_width (GTK_CONTAINER (box), 5); | |
570 gtk_container_add (GTK_CONTAINER (parent), box); | |
571 | |
572 wdata->combo = gtk_combo_new (); | |
573 gtk_combo_set_case_sensitive (GTK_COMBO (wdata->combo), 1); | |
574 gtk_box_pack_start (GTK_BOX (box), wdata->combo, FALSE, FALSE, 0); | |
575 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (wdata->combo)->entry), | |
576 "activate", GTK_SIGNAL_FUNC (chdir_edit), | |
577 (gpointer) wdata); | |
578 if (*wdata->history) | |
579 gtk_combo_set_popdown_strings (GTK_COMBO (wdata->combo), *wdata->history); | |
580 gtk_combo_disable_activate (GTK_COMBO (wdata->combo)); | |
581 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry), ""); | |
582 | |
583 wdata->hoststxt = gtk_label_new (NULL); | |
584 gtk_misc_set_alignment (GTK_MISC (wdata->hoststxt), 0, 0); | |
585 gtk_box_pack_start (GTK_BOX (box), wdata->hoststxt, FALSE, FALSE, 0); | |
586 | |
587 scroll_list = gtk_scrolled_window_new (NULL, NULL); | |
588 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_list), | |
589 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
590 wdata->listbox = gtk_clist_new_with_titles (7, titles); | |
591 gtk_container_add (GTK_CONTAINER (scroll_list), wdata->listbox); | |
592 gtk_drag_source_set (wdata->listbox, GDK_BUTTON1_MASK, possible_types, 3, | |
593 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
594 gtk_drag_dest_set (wdata->listbox, GTK_DEST_DEFAULT_ALL, possible_types, 2, | |
595 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
596 | |
597 gtk_clist_set_selection_mode (GTK_CLIST (wdata->listbox), | |
598 GTK_SELECTION_EXTENDED); | |
599 | |
600 gtk_clist_set_column_width (GTK_CLIST (wdata->listbox), 0, 16); | |
601 gtk_clist_set_column_justification (GTK_CLIST (wdata->listbox), 0, | |
602 GTK_JUSTIFY_CENTER); | |
603 setup_column (wdata->listbox, 1, columns[0]); | |
604 gtk_clist_set_column_justification (GTK_CLIST (wdata->listbox), 2, | |
605 GTK_JUSTIFY_RIGHT); | |
606 setup_column (wdata->listbox, 2, columns[1]); | |
607 setup_column (wdata->listbox, 3, columns[2]); | |
608 setup_column (wdata->listbox, 4, columns[3]); | |
609 setup_column (wdata->listbox, 5, columns[4]); | |
610 setup_column (wdata->listbox, 6, columns[5]); | |
611 gtk_box_pack_start (GTK_BOX (box), scroll_list, TRUE, TRUE, 0); | |
612 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "click_column", | |
613 GTK_SIGNAL_FUNC (sortrows), (gpointer) wdata); | |
614 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "drag_data_get", | |
615 GTK_SIGNAL_FUNC (listbox_drag), (gpointer) wdata); | |
616 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "drag_data_received", | |
617 GTK_SIGNAL_FUNC (listbox_get_drag_data), | |
618 (gpointer) wdata); | |
619 gtk_signal_connect_after (GTK_OBJECT (wdata->listbox), "key_press_event", | |
620 GTK_SIGNAL_FUNC (list_enter), (gpointer) wdata); | |
51 | 621 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "select_row", |
622 GTK_SIGNAL_FUNC(select_row_callback), | |
623 (gpointer) wdata); | |
1 | 624 gtk_signal_connect_after (GTK_OBJECT (wdata->listbox), "button_press_event", |
625 GTK_SIGNAL_FUNC (list_dblclick), (gpointer) wdata); | |
626 return (parent); | |
627 } | |
628 | |
629 | |
630 static gint | |
631 menu_mouse_click (GtkWidget * widget, GdkEventButton * event, gpointer data) | |
632 { | |
633 GtkItemFactory *factory; | |
634 | |
635 factory = (GtkItemFactory *) data; | |
636 if (event->button == 3) | |
637 gtk_item_factory_popup (factory, (guint) event->x_root, | |
638 (guint) event->y_root, 3, event->time); | |
639 return (FALSE); | |
640 } | |
641 | |
642 | |
48 | 643 static GtkWidget * |
644 CreateFTPWindows (GtkWidget * ui) | |
1 | 645 { |
48 | 646 GtkWidget *box, *dlbox, *winpane, *dlpane, *logpane, *mainvbox, *tempwid, |
647 *button; | |
648 char *dltitles[2]; | |
649 #if GTK_MAJOR_VERSION > 1 | |
650 GtkTextBuffer * textbuf; | |
651 GtkTextIter iter; | |
652 GtkTextTag *tag; | |
653 GdkColor fore; | |
654 #endif | |
655 | |
656 memset (&window1, 0, sizeof (window1)); | |
657 memset (&window2, 0, sizeof (window2)); | |
658 window1.history = &localhistory; | |
659 window1.histlen = &localhistlen; | |
660 window2.history = &remotehistory; | |
661 window2.histlen = &remotehistlen; | |
662 | |
663 mainvbox = gtk_vbox_new (FALSE, 0); | |
664 | |
665 tempwid = CreateMenus (ui); | |
666 gtk_box_pack_start (GTK_BOX (mainvbox), tempwid, FALSE, FALSE, 0); | |
1 | 667 |
48 | 668 tempwid = CreateToolbar (ui); |
669 gtk_box_pack_start (GTK_BOX (mainvbox), tempwid, FALSE, FALSE, 0); | |
670 | |
671 winpane = gtk_hpaned_new (); | |
672 | |
673 box = gtk_hbox_new (FALSE, 0); | |
674 | |
675 local_frame = CreateFTPWindow (&window1, listbox_local_width, local_columns); | |
676 window1.sortcol = &local_sortcol; | |
677 window1.sortasds = &local_sortasds; | |
678 gtk_box_pack_start (GTK_BOX (box), local_frame, TRUE, TRUE, 0); | |
679 | |
680 dlbox = gtk_vbox_new (FALSE, 0); | |
681 gtk_container_border_width (GTK_CONTAINER (dlbox), 5); | |
682 gtk_box_pack_start (GTK_BOX (box), dlbox, FALSE, FALSE, 0); | |
683 | |
684 #if GTK_MAJOR_VERSION == 1 | |
685 tempwid = toolbar_pixmap (ui, "right.xpm"); | |
686 #else | |
687 tempwid = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, | |
688 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
689 #endif | |
690 | |
691 button = gtk_button_new (); | |
692 gtk_box_pack_start (GTK_BOX (dlbox), button, TRUE, FALSE, 0); | |
693 gtk_signal_connect_object (GTK_OBJECT (button), "clicked", | |
694 GTK_SIGNAL_FUNC (put_files), NULL); | |
695 gtk_container_add (GTK_CONTAINER (button), tempwid); | |
1 | 696 |
45 | 697 #if GTK_MAJOR_VERSION == 1 |
48 | 698 tempwid = toolbar_pixmap (ui, "left.xpm"); |
1 | 699 #else |
48 | 700 tempwid = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, |
701 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
1 | 702 #endif |
48 | 703 |
704 button = gtk_button_new (); | |
705 gtk_box_pack_start (GTK_BOX (dlbox), button, TRUE, FALSE, 0); | |
706 gtk_signal_connect_object (GTK_OBJECT (button), "clicked", | |
707 GTK_SIGNAL_FUNC (get_files), NULL); | |
708 gtk_container_add (GTK_CONTAINER (button), tempwid); | |
709 | |
710 gtk_paned_pack1 (GTK_PANED (winpane), box, 1, 1); | |
711 | |
712 remote_frame = CreateFTPWindow (&window2, listbox_remote_width, | |
713 remote_columns); | |
714 window2.sortcol = &remote_sortcol; | |
715 window2.sortasds = &remote_sortasds; | |
716 gtk_paned_pack2 (GTK_PANED (winpane), remote_frame, 1, 1); | |
717 | |
718 dlpane = gtk_vpaned_new (); | |
719 gtk_paned_pack1 (GTK_PANED (dlpane), winpane, 1, 1); | |
720 | |
721 transfer_scroll = gtk_scrolled_window_new (NULL, NULL); | |
722 gtk_widget_set_size_request (transfer_scroll, -1, transfer_height); | |
723 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (transfer_scroll), | |
724 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
725 | |
726 dltitles[0] = _("Filename"); | |
727 dltitles[1] = _("Progress"); | |
728 dlwdw = gtk_ctree_new_with_titles (2, 0, dltitles); | |
729 gtk_clist_set_selection_mode (GTK_CLIST (dlwdw), GTK_SELECTION_SINGLE); | |
730 gtk_clist_set_reorderable (GTK_CLIST (dlwdw), 0); | |
731 | |
732 if (file_trans_column == 0) | |
733 gtk_clist_set_column_auto_resize (GTK_CLIST (dlwdw), 0, TRUE); | |
734 else | |
735 gtk_clist_set_column_width (GTK_CLIST (dlwdw), 0, file_trans_column); | |
736 | |
737 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (transfer_scroll), dlwdw); | |
738 gtk_signal_connect (GTK_OBJECT (dlwdw), "button_press_event", | |
739 GTK_SIGNAL_FUNC (menu_mouse_click), (gpointer) dl_factory); | |
740 gtk_paned_pack2 (GTK_PANED (dlpane), transfer_scroll, 1, 1); | |
741 | |
742 logpane = gtk_vpaned_new (); | |
743 gtk_paned_pack1 (GTK_PANED (logpane), dlpane, 1, 1); | |
744 | |
745 log_table = gtk_table_new (1, 2, FALSE); | |
746 gtk_widget_set_size_request (log_table, -1, log_height); | |
747 | |
748 #if GTK_MAJOR_VERSION == 1 | |
749 logwdw = gtk_text_new (NULL, NULL); | |
750 | |
751 gtk_text_set_editable (GTK_TEXT (logwdw), FALSE); | |
752 gtk_text_set_word_wrap (GTK_TEXT (logwdw), TRUE); | |
753 | |
754 gtk_table_attach (GTK_TABLE (log_table), logwdw, 0, 1, 0, 1, | |
755 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
756 0, 0); | |
757 gtk_signal_connect (GTK_OBJECT (logwdw), "button_press_event", | |
758 GTK_SIGNAL_FUNC (menu_mouse_click), | |
759 (gpointer) log_factory); | |
760 | |
761 tempwid = gtk_vscrollbar_new (GTK_TEXT (logwdw)->vadj); | |
762 gtk_table_attach (GTK_TABLE (log_table), tempwid, 1, 2, 0, 1, | |
763 GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); | |
764 logwdw_vadj = GTK_TEXT (logwdw)->vadj; | |
765 #else | |
766 logwdw = gtk_text_view_new (); | |
767 gtk_text_view_set_editable (GTK_TEXT_VIEW (logwdw), FALSE); | |
768 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (logwdw), FALSE); | |
769 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (logwdw), GTK_WRAP_WORD); | |
770 | |
771 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
772 | |
773 tag = gtk_text_buffer_create_tag (textbuf, "send", NULL); | |
774 fore.red = send_color.red; | |
775 fore.green = send_color.green; | |
776 fore.blue = send_color.blue; | |
777 g_object_set (G_OBJECT (tag), "foreground_gdk", &fore, NULL); | |
778 | |
779 tag = gtk_text_buffer_create_tag (textbuf, "recv", NULL); | |
780 fore.red = recv_color.red; | |
781 fore.green = recv_color.green; | |
782 fore.blue = recv_color.blue; | |
783 g_object_set (G_OBJECT (tag), "foreground_gdk", &fore, NULL); | |
784 | |
785 tag = gtk_text_buffer_create_tag (textbuf, "error", NULL); | |
786 fore.red = error_color.red; | |
787 fore.green = error_color.green; | |
788 fore.blue = error_color.blue; | |
789 g_object_set (G_OBJECT (tag), "foreground_gdk", &fore, NULL); | |
790 | |
791 tag = gtk_text_buffer_create_tag (textbuf, "misc", NULL); | |
792 fore.red = misc_color.red; | |
793 fore.green = misc_color.green; | |
794 fore.blue = misc_color.blue; | |
795 g_object_set (G_OBJECT (tag), "foreground_gdk", &fore, NULL); | |
796 | |
797 tempwid = gtk_scrolled_window_new (NULL, NULL); | |
798 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (tempwid), | |
799 GTK_POLICY_AUTOMATIC, | |
800 GTK_POLICY_AUTOMATIC); | |
801 gtk_container_add (GTK_CONTAINER (tempwid), logwdw); | |
802 gtk_table_attach (GTK_TABLE (log_table), tempwid, 0, 1, 0, 1, | |
803 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
804 0, 0); | |
805 logwdw_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tempwid)); | |
806 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
807 logwdw_textmark = gtk_text_buffer_create_mark (textbuf, "end", &iter, 1); | |
808 #endif | |
809 gtk_paned_pack2 (GTK_PANED (logpane), log_table, 1, 1); | |
810 gtk_box_pack_start (GTK_BOX (mainvbox), logpane, TRUE, TRUE, 0); | |
811 | |
812 gtk_widget_show_all (mainvbox); | |
813 return (mainvbox); | |
1 | 814 } |
815 | |
816 | |
48 | 817 void |
818 init_gftp (int argc, char *argv[], GtkWidget * parent) | |
1 | 819 { |
48 | 820 if (argc == 2 && strncmp (argv[1], "--", 2) != 0) |
1 | 821 { |
48 | 822 if (gftp_parse_url (window2.request, argv[1]) == 0) |
823 ftp_connect (&window2, window2.request, 1); | |
824 else | |
825 gftp_usage (); | |
1 | 826 } |
827 } | |
828 | |
829 | |
830 void | |
831 toolbar_hostedit (GtkWidget * widget, gpointer data) | |
832 { | |
833 void (*init) (gftp_request * request); | |
834 GtkWidget *tempwid; | |
835 const char *txt; | |
836 int num; | |
837 | |
838 if (current_wdata->request->stopable) | |
839 { | |
840 ftp_log (gftp_logging_misc, NULL, | |
841 _("%s: Please hit the stop button first to do anything else\n"), | |
842 _("Connect")); | |
843 return; | |
844 } | |
845 | |
846 if (GFTP_IS_CONNECTED (current_wdata->request)) | |
847 disconnect (current_wdata); | |
848 | |
849 tempwid = gtk_menu_get_active (GTK_MENU (protocol_menu)); | |
850 num = (int) gtk_object_get_user_data (GTK_OBJECT (tempwid)); | |
851 init = gftp_protocols[num].init; | |
852 init (current_wdata->request); | |
853 | |
854 gftp_set_hostname (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry))); | |
855 alltrim (current_wdata->request->hostname); | |
856 | |
857 if (current_wdata->request->need_hostport && | |
858 *current_wdata->request->hostname == '\0') | |
859 { | |
860 ftp_log (gftp_logging_error, NULL, | |
861 _("Error: You must type in a host to connect to\n")); | |
862 return; | |
863 } | |
864 | |
865 add_history (hostedit, &host_history, &host_len, | |
866 current_wdata->request->hostname); | |
867 | |
868 if (strchr (current_wdata->request->hostname, '/') != NULL && | |
869 gftp_parse_url (current_wdata->request, | |
870 current_wdata->request->hostname) == 0) | |
871 { | |
872 ftp_connect (current_wdata, current_wdata->request, 1); | |
873 return; | |
874 } | |
875 | |
876 txt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry)); | |
877 gftp_set_port (current_wdata->request, strtol (txt, NULL, 10)); | |
878 add_history (portedit, &port_history, &port_len, txt); | |
879 | |
880 gftp_set_username (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry))); | |
881 alltrim (current_wdata->request->username); | |
882 | |
883 add_history (useredit, &user_history, &user_len, | |
884 current_wdata->request->username); | |
885 | |
886 gftp_set_password (current_wdata->request, | |
887 gtk_entry_get_text (GTK_ENTRY (passedit))); | |
888 | |
889 gftp_set_directory (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (current_wdata->combo)->entry))); | |
890 alltrim (current_wdata->request->directory); | |
891 | |
892 add_history (current_wdata->combo, current_wdata->history, | |
893 current_wdata->histlen, current_wdata->request->directory); | |
894 | |
895 ftp_connect (current_wdata, current_wdata->request, 1); | |
896 } | |
897 | |
898 | |
899 void | |
900 sortrows (GtkCList * clist, gint column, gpointer data) | |
901 { | |
902 gftp_window_data * wdata; | |
16 | 903 GtkWidget * sort_wid; |
904 GList * templist; | |
19 | 905 int swap_col; |
1 | 906 |
907 wdata = data; | |
37 | 908 if (column == 0 || (column == *wdata->sortcol && wdata->sorted)) |
1 | 909 { |
37 | 910 *wdata->sortasds = !(*wdata->sortasds); |
19 | 911 swap_col = 1; |
912 } | |
913 else | |
914 swap_col = 0; | |
915 | |
916 if (swap_col || !wdata->sorted) | |
917 { | |
1 | 918 sort_wid = gtk_clist_get_column_widget (clist, 0); |
919 gtk_widget_destroy (sort_wid); | |
45 | 920 #if GTK_MAJOR_VERSION == 1 |
37 | 921 if (*wdata->sortasds) |
1 | 922 sort_wid = toolbar_pixmap (wdata->listbox, "down.xpm"); |
923 else | |
924 sort_wid = toolbar_pixmap (wdata->listbox, "up.xpm"); | |
19 | 925 #else |
37 | 926 if (*wdata->sortasds) |
19 | 927 sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_ASCENDING, |
928 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
929 else | |
930 sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_DESCENDING, | |
931 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
932 #endif | |
933 | |
1 | 934 gtk_clist_set_column_widget (clist, 0, sort_wid); |
935 } | |
936 else | |
37 | 937 *wdata->sortcol = column; |
938 | |
939 if (!GFTP_IS_CONNECTED (wdata->request)) | |
940 return; | |
1 | 941 |
942 gtk_clist_freeze (clist); | |
943 gtk_clist_clear (clist); | |
944 | |
37 | 945 wdata->files = gftp_sort_filelist (wdata->files, *wdata->sortcol, |
946 *wdata->sortasds); | |
1 | 947 |
16 | 948 templist = wdata->files; |
949 while (templist != NULL) | |
1 | 950 { |
16 | 951 add_file_listbox (wdata, templist->data); |
952 templist = templist->next; | |
1 | 953 } |
954 | |
955 wdata->sorted = 1; | |
956 gtk_clist_thaw (clist); | |
957 update_window_info (); | |
958 } | |
959 | |
960 | |
961 void | |
962 stop_button (GtkWidget * widget, gpointer data) | |
963 { | |
964 pthread_t comptid; | |
965 | |
966 memset (&comptid, 0, sizeof (comptid)); | |
967 if (!pthread_equal (comptid, window1.tid)) | |
968 pthread_kill (window1.tid, SIGINT); | |
969 else if (!pthread_equal (comptid, window2.tid)) | |
970 pthread_kill (window2.tid, SIGINT); | |
971 } | |
972 | |
48 | 973 |
974 int | |
975 main (int argc, char **argv) | |
976 { | |
977 GtkWidget *window, *ui; | |
978 | |
979 #ifdef HAVE_GETTEXT | |
980 setlocale (LC_ALL, ""); | |
981 bindtextdomain ("gftp", LOCALE_DIR); | |
982 #if GTK_MAJOR_VERSION > 1 | |
983 bind_textdomain_codeset ("gftp", "UTF-8"); | |
984 #endif | |
985 textdomain ("gftp"); | |
986 #endif | |
987 | |
988 g_thread_init (NULL); | |
56 | 989 main_thread_id = pthread_self (); |
48 | 990 gtk_set_locale (); |
991 gtk_init (&argc, &argv); | |
992 | |
993 signal (SIGCHLD, sig_child); | |
994 signal (SIGPIPE, SIG_IGN); | |
995 signal (SIGALRM, signal_handler); | |
996 signal (SIGINT, signal_handler); | |
997 | |
998 graphic_hash_table = g_hash_table_new (string_hash_function, string_hash_compare); | |
999 gftp_read_config_file (argv, 1); | |
1000 if (gftp_parse_command_line (&argc, &argv) != 0) | |
1001 exit (0); | |
1002 | |
1003 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
1004 gtk_signal_connect (GTK_OBJECT (window), "delete_event", | |
1005 GTK_SIGNAL_FUNC (delete_event), NULL); | |
1006 gtk_signal_connect (GTK_OBJECT (window), "destroy", | |
1007 GTK_SIGNAL_FUNC (destroy), NULL); | |
1008 gtk_window_set_title (GTK_WINDOW (window), version); | |
1009 gtk_window_set_wmclass (GTK_WINDOW(window), "main", "gFTP"); | |
1010 gtk_widget_set_name (window, version); | |
1011 gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE); | |
1012 gtk_widget_realize (window); | |
1013 | |
1014 gftp_icon = open_xpm (window, "gftp.xpm"); | |
1015 if (gftp_icon != NULL) | |
1016 { | |
1017 gdk_window_set_icon (window->window, NULL, gftp_icon->pixmap, | |
1018 gftp_icon->bitmap); | |
1019 gdk_window_set_icon_name (window->window, _("gFTP Icon")); | |
1020 } | |
1021 | |
1022 other_wdata = &window1; | |
1023 current_wdata = &window2; | |
1024 ui = CreateFTPWindows (window); | |
1025 gtk_container_add (GTK_CONTAINER (window), ui); | |
1026 gtk_widget_show (window); | |
1027 | |
1028 ftp_log (gftp_logging_misc, NULL, | |
1029 "%s, Copyright (C) 1998-2002 Brian Masney <", version); | |
1030 ftp_log (gftp_logging_recv, NULL, "masneyb@gftp.org"); | |
1031 ftp_log (gftp_logging_misc, NULL, | |
1032 _(">. If you have any questions, comments, or suggestions about this program, please feel free to email them to me. You can always find out the latest news about gFTP from my website at http://www.gftp.org/\n")); | |
1033 ftp_log (gftp_logging_misc, NULL, | |
1034 _("gFTP comes with ABSOLUTELY NO WARRANTY; for details, see the COPYING file. This is free software, and you are welcome to redistribute it under certain conditions; for details, see the COPYING file\n")); | |
1035 | |
1036 gtk_timeout_add (1000, update_downloads, NULL); | |
1037 gftp_protocols[GFTP_LOCAL_NUM].init (window1.request); | |
1038 if (startup_directory != NULL && *startup_directory != '\0') | |
1039 gftp_set_directory (window1.request, startup_directory); | |
1040 gftp_connect (window1.request); | |
1041 ftp_list_files (&window1, 0); | |
1042 | |
1043 /* On the remote window, even though we aren't connected, draw the sort | |
1044 icon on that side */ | |
1045 sortrows (GTK_CLIST (window2.listbox), *window2.sortcol, &window2); | |
1046 | |
1047 init_gftp (argc, argv, window); | |
1048 gftp_is_started = 1; | |
1049 | |
1050 GDK_THREADS_ENTER (); | |
1051 gtk_main (); | |
1052 GDK_THREADS_LEAVE (); | |
1053 return (0); | |
1054 } | |
1055 | |
1056 |