Mercurial > gftp.yaz
annotate src/gtk/gftp-gtk.c @ 209:d79e2782eb1b
2003-7-5 Brian Masney <masneyb@gftp.org>
* lib/protocols.c (gftp_get_line) - fixed bug where the read function
was being called one extra time after the end of file was reached
* lib/rfc2068.c - fixes for chunked file transfers. All known issues with the
HTTP protocol should be (hopefully) fixed now
* lib/httpcommon.h (struct rfc2068_params_tag) - added eof variable
author | masneyb |
---|---|
date | Sat, 05 Jul 2003 17:30:14 +0000 |
parents | 0098dae654a5 |
children | de6a2e8e51cb |
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; |
42 | 41 sigjmp_buf jmp_environment; |
42 volatile int use_jmp_environment = 0; | |
56 | 43 pthread_t main_thread_id; |
129 | 44 GList * viewedit_processes = NULL; |
45 volatile sig_atomic_t viewedit_process_done; | |
42 | 46 |
48 | 47 static int |
48 get_column (GtkCListColumn * col) | |
1 | 49 { |
48 | 50 if (col->auto_resize) |
51 return (0); | |
52 else if (!col->visible) | |
53 return (-1); | |
54 else | |
55 return (col->width); | |
56 } | |
42 | 57 |
1 | 58 |
48 | 59 static void |
60 doexit (GtkWidget * widget, gpointer data) | |
61 { | |
129 | 62 int ret; |
63 | |
64 ret = GTK_WIDGET (local_frame)->allocation.width; | |
65 gftp_set_global_option ("listbox_local_width", &ret); | |
66 ret = GTK_WIDGET (remote_frame)->allocation.width; | |
67 gftp_set_global_option ("listbox_remote_width", &ret); | |
68 ret = GTK_WIDGET (remote_frame)->allocation.height; | |
69 gftp_set_global_option ("listbox_file_height", &ret); | |
70 ret = GTK_WIDGET (log_table)->allocation.height; | |
71 gftp_set_global_option ("log_height", &ret); | |
72 ret = GTK_WIDGET (transfer_scroll)->allocation.height; | |
73 gftp_set_global_option ("transfer_height", &ret); | |
74 | |
75 ret = get_column (>K_CLIST (dlwdw)->column[0]); | |
76 gftp_set_global_option ("file_trans_column", &ret); | |
1 | 77 |
129 | 78 ret = get_column (>K_CLIST (window1.listbox)->column[1]); |
79 gftp_set_global_option ("local_file_width", &ret); | |
80 ret = get_column (>K_CLIST (window1.listbox)->column[2]); | |
81 gftp_set_global_option ("local_size_width", &ret); | |
82 ret = get_column (>K_CLIST (window1.listbox)->column[3]); | |
83 gftp_set_global_option ("local_user_width", &ret); | |
84 ret = get_column (>K_CLIST (window1.listbox)->column[4]); | |
85 gftp_set_global_option ("local_group_width", &ret); | |
86 ret = get_column (>K_CLIST (window1.listbox)->column[5]); | |
87 gftp_set_global_option ("local_date_width", &ret); | |
88 ret = get_column (>K_CLIST (window1.listbox)->column[6]); | |
89 gftp_set_global_option ("local_attribs_width", &ret); | |
1 | 90 |
129 | 91 ret = get_column (>K_CLIST (window2.listbox)->column[1]); |
92 gftp_set_global_option ("remote_file_width", &ret); | |
93 ret = get_column (>K_CLIST (window2.listbox)->column[2]); | |
94 gftp_set_global_option ("remote_size_width", &ret); | |
95 ret = get_column (>K_CLIST (window2.listbox)->column[3]); | |
96 gftp_set_global_option ("remote_user_width", &ret); | |
97 ret = get_column (>K_CLIST (window2.listbox)->column[4]); | |
98 gftp_set_global_option ("remote_group_width", &ret); | |
99 ret = get_column (>K_CLIST (window2.listbox)->column[5]); | |
100 gftp_set_global_option ("remote_date_width", &ret); | |
101 ret = get_column (>K_CLIST (window2.listbox)->column[6]); | |
102 gftp_set_global_option ("remote_attribs_width", &ret); | |
37 | 103 |
201 | 104 gftp_shutdown (); |
48 | 105 exit (0); |
1 | 106 } |
107 | |
108 | |
109 static gint | |
110 delete_event (GtkWidget * widget, GdkEvent * event, gpointer data) | |
111 { | |
129 | 112 if (gftp_file_transfers == NULL) |
1 | 113 doexit (NULL, NULL); |
114 else | |
115 { | |
19 | 116 MakeYesNoDialog (_("Exit"), _("There are file transfers in progress.\nAre you sure you want to exit?"), doexit, NULL, NULL, NULL); |
1 | 117 return (TRUE); |
118 } | |
119 return (FALSE); | |
120 } | |
121 | |
122 | |
123 static void | |
124 destroy (GtkWidget * widget, gpointer data) | |
125 { | |
126 exit (0); | |
127 } | |
128 | |
129 | |
130 static RETSIGTYPE | |
131 sig_child (int signo) | |
132 { | |
133 viewedit_process_done = 1; | |
134 } | |
135 | |
136 | |
48 | 137 static void |
138 menu_exit (GtkWidget * widget, gpointer data) | |
1 | 139 { |
48 | 140 if (!delete_event (widget, NULL, data)) |
141 doexit (widget, data); | |
142 } | |
1 | 143 |
144 | |
48 | 145 static void |
146 chfunc (gpointer data) | |
147 { | |
148 chdir_dialog (data); | |
1 | 149 } |
150 | |
151 | |
152 static GtkWidget * | |
153 CreateMenus (GtkWidget * parent) | |
154 { | |
155 int local_len, remote_len, len, i, trans_len, log_len, tools_len; | |
156 GtkAccelGroup *accel_group; | |
157 GtkWidget * tempwid; | |
7 | 158 static GtkItemFactoryEntry menu_items[] = { |
12 | 159 {N_("/_FTP"), NULL, 0, 0, MN_("<Branch>")}, |
160 {N_("/FTP/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
161 {N_("/FTP/Window 1"), NULL, change_setting, 3, MN_("<RadioItem>")}, | |
162 {N_("/FTP/Window 2"), NULL, change_setting, 4, MN_("/FTP/Window 1")}, | |
163 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
164 {N_("/FTP/Ascii"), NULL, change_setting, 1, MN_("<RadioItem>")}, | |
165 {N_("/FTP/Binary"), NULL, change_setting, 2, MN_("/FTP/Ascii")}, | |
166 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
167 {N_("/FTP/_Options..."), "<control>O", options_dialog, 0, | |
168 MS_(GTK_STOCK_PREFERENCES)}, | |
169 {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
170 {N_("/FTP/_Quit"), "<control>Q", menu_exit, 0, MS_(GTK_STOCK_QUIT)}, | |
171 {N_("/_Local"), NULL, 0, 0, MN_("<Branch>")}, | |
172 {N_("/Local/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
173 {N_("/Local/Open _URL..."), NULL, openurl_dialog, 0, MS_(GTK_STOCK_OPEN)}, | |
174 {N_("/Local/Disconnect"), NULL, disconnect, 0, MS_(GTK_STOCK_CLOSE)}, | |
175 {N_("/Local/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
176 {N_("/Local/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, | |
177 {N_("/Local/Show selected"), NULL, show_selected, 0, MN_(NULL)}, | |
178 {N_("/Local/Select All"), NULL, selectall, 0, MN_(NULL)}, | |
179 {N_("/Local/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, | |
180 {N_("/Local/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, | |
181 {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
|
182 {N_("/Local/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, |
12 | 183 {N_("/Local/Send SITE Command..."), NULL, site_dialog, 0, MN_(NULL)}, |
184 {N_("/Local/Change Directory"), NULL, chfunc, 0, MN_(NULL)}, | |
185 {N_("/Local/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, | |
186 {N_("/Local/Make Directory..."), NULL, mkdir_dialog, 0, MN_(NULL)}, | |
187 {N_("/Local/Rename..."), NULL, rename_dialog, 0, MN_(NULL)}, | |
188 {N_("/Local/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, | |
189 {N_("/Local/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, | |
190 {N_("/Local/View..."), NULL, view_dialog, 0, MN_(NULL)}, | |
191 {N_("/Local/Refresh"), NULL, refresh, 0, MS_(GTK_STOCK_REFRESH)}, | |
192 {N_("/_Remote"), NULL, 0, 0, MN_("<Branch>")}, | |
193 {N_("/Remote/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
194 {N_("/Remote/Open _URL..."), "<control>U", openurl_dialog, 0, | |
195 MS_(GTK_STOCK_OPEN)}, | |
196 {N_("/Remote/Disconnect"), "<control>D", disconnect, 0, | |
197 MS_(GTK_STOCK_CLOSE)}, | |
198 {N_("/Remote/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
199 {N_("/Remote/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, | |
200 {N_("/Remote/Show selected"), NULL, show_selected, 0, MN_(NULL)}, | |
201 {N_("/Remote/Select All"), NULL, selectall, 0, MN_(NULL)}, | |
202 {N_("/Remote/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, | |
203 {N_("/Remote/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, | |
204 {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
|
205 {N_("/Remote/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, |
12 | 206 {N_("/Remote/Send SITE Command..."), NULL, site_dialog, 0, MN_(NULL)}, |
207 {N_("/Remote/Change Directory"), NULL, chfunc, 0, MN_(NULL)}, | |
208 {N_("/Remote/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, | |
209 {N_("/Remote/Make Directory..."), NULL, mkdir_dialog, 0, MN_(NULL)}, | |
210 {N_("/Remote/Rename..."), NULL, rename_dialog, 0, MN_(NULL)}, | |
211 {N_("/Remote/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, | |
212 {N_("/Remote/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, | |
213 {N_("/Remote/View..."), NULL, view_dialog, 0, MN_(NULL)}, | |
214 {N_("/Remote/Refresh"), NULL, refresh, 0, MS_(GTK_STOCK_REFRESH)}, | |
215 {N_("/_Bookmarks"), NULL, 0, 0, MN_("<Branch>")}, | |
216 {N_("/Bookmarks/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
217 {N_("/Bookmarks/Add bookmark"), "<control>A", add_bookmark, 0, | |
218 MS_(GTK_STOCK_ADD)}, | |
219 {N_("/Bookmarks/Edit bookmarks"), NULL, edit_bookmarks, 0, MN_(NULL)}, | |
220 {N_("/Bookmarks/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
221 {N_("/_Transfers"), NULL, 0, 0, MN_("<Branch>")}, | |
222 {N_("/Transfers/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
223 {N_("/Transfers/Start Transfer"), NULL, start_transfer, 0, MN_(NULL)}, | |
224 {N_("/Transfers/Stop Transfer"), NULL, stop_transfer, 0, | |
225 MS_(GTK_STOCK_STOP)}, | |
226 {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
227 {N_("/Transfers/Skip Current File"), NULL, skip_transfer, 0, MN_(NULL)}, | |
228 {N_("/Transfers/Remove File"), NULL, remove_file_transfer, 0, | |
229 MS_(GTK_STOCK_DELETE)}, | |
230 {N_("/Transfers/Move File _Up"), NULL, move_transfer_up, 0, | |
231 MS_(GTK_STOCK_GO_UP)}, | |
232 {N_("/Transfers/Move File _Down"), NULL, move_transfer_down, 0, | |
233 MS_(GTK_STOCK_GO_DOWN)}, | |
234 {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, | |
235 {N_("/Transfers/Retrieve Files"), "<control>R", get_files, 0, MN_(NULL)}, | |
236 {N_("/Transfers/Put Files"), "<control>P", put_files, 0, MN_(NULL)}, | |
237 {N_("/L_ogging"), NULL, 0, 0, MN_("<Branch>")}, | |
238 {N_("/Logging/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
239 {N_("/Logging/Clear"), NULL, clearlog, 0, MS_(GTK_STOCK_CLEAR)}, | |
240 {N_("/Logging/View log..."), NULL, viewlog, 0, MN_(NULL)}, | |
241 {N_("/Logging/Save log..."), NULL, savelog, 0, MS_(GTK_STOCK_SAVE)}, | |
242 {N_("/Tool_s"), NULL, 0, 0, MN_("<Branch>")}, | |
243 {N_("/Tools/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
244 {N_("/Tools/Compare Windows"), NULL, compare_windows, 0, MN_(NULL)}, | |
245 {N_("/Tools/Clear Cache"), NULL, clear_cache, 0, MS_(GTK_STOCK_CLEAR)}, | |
246 {N_("/_Help"), NULL, 0, 0, MN_("<LastBranch>")}, | |
247 {N_("/Help/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
248 {N_("/Help/About..."), NULL, about_dialog, 0, MS_(GTK_STOCK_HELP)} | |
1 | 249 }; |
250 | |
251 menus = menu_items; | |
252 | |
253 accel_group = gtk_accel_group_new (); | |
7 | 254 factory = item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group, NULL); |
1 | 255 |
256 i = 0; | |
257 len = 11; | |
258 /* FTP Menu */ | |
259 create_item_factory (factory, len, menu_items, &window2); | |
260 | |
261 i += len; | |
262 /* Local Menu */ | |
263 local_start = i; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
264 local_len = 21; |
1 | 265 create_item_factory (factory, local_len, menu_items + i, &window1); |
266 | |
267 i += local_len; | |
268 /* Remote Menu */ | |
269 remote_start = i; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
12
diff
changeset
|
270 remote_len = 21; |
1 | 271 create_item_factory (factory, remote_len, menu_items + i, &window2); |
272 | |
273 i += remote_len; | |
274 len = 5; | |
275 /* Bookmarks Menu */ | |
276 create_item_factory (factory, len, menu_items + i, &window2); | |
277 | |
278 i += len; | |
279 /* Transfers Menu */ | |
280 trans_start = i; | |
281 trans_len = 12; | |
282 create_item_factory (factory, trans_len, menu_items + i, NULL); | |
283 | |
284 i += trans_len; | |
285 /* Logging Menu */ | |
286 log_start = i; | |
287 log_len = 5; | |
288 create_item_factory (factory, log_len, menu_items + i, NULL); | |
289 | |
290 i += log_len; | |
291 /* Tools Menu */ | |
292 tools_start = i; | |
293 tools_len = 4; | |
294 create_item_factory (factory, tools_len, menu_items + i, NULL); | |
295 | |
296 i += tools_len; | |
297 /* Help Menu */ | |
298 create_item_factory (factory, 3, menu_items + i, NULL); | |
299 | |
300 build_bookmarks_menu (); | |
301 | |
44 | 302 gtk_window_add_accel_group (GTK_WINDOW (parent), accel_group); |
1 | 303 |
7 | 304 tempwid = gtk_item_factory_get_widget (factory, menu_items[6].path); |
1 | 305 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (tempwid), TRUE); |
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 * | |
327 CreateToolbar (GtkWidget * parent) | |
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 | |
463 return (toolbar); | |
464 } | |
465 | |
466 | |
467 static void | |
48 | 468 setup_column (GtkWidget * listbox, int column, int width) |
1 | 469 { |
48 | 470 if (width == 0) |
471 gtk_clist_set_column_auto_resize (GTK_CLIST (listbox), column, TRUE); | |
472 else if (width == -1) | |
473 gtk_clist_set_column_visibility (GTK_CLIST (listbox), column, FALSE); | |
474 else | |
475 gtk_clist_set_column_width (GTK_CLIST (listbox), column, width); | |
1 | 476 } |
477 | |
478 | |
48 | 479 static void |
480 list_doaction (gftp_window_data * wdata) | |
1 | 481 { |
129 | 482 int num, dir, success, list_dblclk_action; |
48 | 483 GList *templist, *filelist; |
484 gftp_file *tempfle; | |
485 | |
129 | 486 gftp_lookup_request_option (wdata->request, "list_dblclk_action", |
487 &list_dblclk_action); | |
488 | |
48 | 489 filelist = wdata->files; |
490 templist = GTK_CLIST (wdata->listbox)->selection; | |
491 num = 0; | |
492 templist = get_next_selection (templist, &filelist, &num); | |
493 tempfle = (gftp_file *) filelist->data; | |
494 | |
495 dir = tempfle->isdir; | |
496 success = 0; | |
1 | 497 |
48 | 498 if (tempfle->islink || tempfle->isdir) |
499 success = chdir_dialog (wdata); | |
1 | 500 |
48 | 501 if (!dir && !success) |
1 | 502 { |
129 | 503 switch (list_dblclk_action) |
48 | 504 { |
505 case 0: | |
506 view_dialog (wdata); | |
507 break; | |
508 case 1: | |
509 edit_dialog (wdata); | |
510 break; | |
511 case 2: | |
512 if (wdata == &window2) | |
513 get_files (wdata); | |
514 else | |
515 put_files (wdata); | |
516 break; | |
517 } | |
1 | 518 } |
519 } | |
520 | |
521 | |
48 | 522 static gint |
523 list_enter (GtkWidget * widget, GdkEventKey * event, gpointer data) | |
524 { | |
525 gftp_window_data * wdata; | |
526 | |
527 wdata = data; | |
528 if (!GFTP_IS_CONNECTED (wdata->request)) | |
529 return (TRUE); | |
530 | |
531 if (event->type == GDK_KEY_PRESS && | |
532 (event->keyval == GDK_KP_Delete || event->keyval == GDK_Delete)) | |
533 { | |
534 delete_dialog (wdata); | |
535 return (FALSE); | |
536 } | |
537 else if (IS_ONE_SELECTED (wdata) && event->type == GDK_KEY_PRESS && | |
538 event->keyval == GDK_Return) | |
539 { | |
540 list_doaction (wdata); | |
541 return (FALSE); | |
542 } | |
543 return (TRUE); | |
544 } | |
545 | |
546 | |
547 static gint | |
548 list_dblclick (GtkWidget * widget, GdkEventButton * event, gpointer data) | |
1 | 549 { |
48 | 550 gftp_window_data * wdata; |
551 | |
552 wdata = data; | |
51 | 553 |
48 | 554 if (event->button == 3) |
555 gtk_item_factory_popup (wdata->ifactory, (guint) event->x_root, | |
556 (guint) event->y_root, 3, event->time); | |
51 | 557 return (FALSE); |
558 } | |
559 | |
48 | 560 |
51 | 561 void |
562 select_row_callback (GtkWidget *widget, gint row, gint column, | |
563 GdkEventButton *event, gpointer data) | |
564 { | |
565 gftp_window_data * wdata; | |
50 | 566 |
51 | 567 wdata = data; |
50 | 568 |
51 | 569 if (event != NULL && event->type == GDK_2BUTTON_PRESS && event->button == 1 && |
570 GFTP_IS_CONNECTED (wdata->request) && IS_ONE_SELECTED (wdata)) | |
571 list_doaction (wdata); | |
1 | 572 } |
573 | |
574 | |
575 static GtkWidget * | |
129 | 576 CreateFTPWindow (gftp_window_data * wdata) |
1 | 577 { |
578 const GtkTargetEntry possible_types[] = { | |
579 {"STRING", 0, 0}, | |
580 {"text/plain", 0, 0}, | |
581 {"application/x-rootwin-drop", 0, 1} | |
582 }; | |
583 GtkWidget *box, *scroll_list, *parent; | |
129 | 584 int listbox_file_height, colwidth; |
585 char *titles[7], tempstr[50]; | |
1 | 586 |
587 titles[0] = ""; | |
588 titles[1] = _("Filename"); | |
589 titles[2] = _("Size"); | |
590 titles[3] = _("User"); | |
591 titles[4] = _("Group"); | |
592 titles[5] = _("Date"); | |
593 titles[6] = _("Attribs"); | |
594 | |
595 wdata->request = gftp_request_new (); | |
596 wdata->request->logging_function = ftp_log; | |
597 wdata->filespec = g_malloc0 (2); | |
598 *wdata->filespec = '*'; | |
599 | |
600 parent = gtk_frame_new (NULL); | |
129 | 601 |
602 gftp_lookup_global_option ("listbox_file_height", &listbox_file_height); | |
603 g_snprintf (tempstr, sizeof (tempstr), "listbox_%s_width", wdata->prefix_col_str); | |
604 gftp_lookup_global_option (tempstr, &colwidth); | |
605 gtk_widget_set_size_request (parent, colwidth, listbox_file_height); | |
1 | 606 |
607 gtk_container_border_width (GTK_CONTAINER (parent), 5); | |
608 | |
609 box = gtk_vbox_new (FALSE, 0); | |
610 gtk_container_border_width (GTK_CONTAINER (box), 5); | |
611 gtk_container_add (GTK_CONTAINER (parent), box); | |
612 | |
613 wdata->combo = gtk_combo_new (); | |
614 gtk_combo_set_case_sensitive (GTK_COMBO (wdata->combo), 1); | |
615 gtk_box_pack_start (GTK_BOX (box), wdata->combo, FALSE, FALSE, 0); | |
616 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (wdata->combo)->entry), | |
617 "activate", GTK_SIGNAL_FUNC (chdir_edit), | |
618 (gpointer) wdata); | |
619 if (*wdata->history) | |
620 gtk_combo_set_popdown_strings (GTK_COMBO (wdata->combo), *wdata->history); | |
621 gtk_combo_disable_activate (GTK_COMBO (wdata->combo)); | |
622 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry), ""); | |
623 | |
624 wdata->hoststxt = gtk_label_new (NULL); | |
625 gtk_misc_set_alignment (GTK_MISC (wdata->hoststxt), 0, 0); | |
626 gtk_box_pack_start (GTK_BOX (box), wdata->hoststxt, FALSE, FALSE, 0); | |
627 | |
628 scroll_list = gtk_scrolled_window_new (NULL, NULL); | |
629 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_list), | |
630 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
631 wdata->listbox = gtk_clist_new_with_titles (7, titles); | |
632 gtk_container_add (GTK_CONTAINER (scroll_list), wdata->listbox); | |
633 gtk_drag_source_set (wdata->listbox, GDK_BUTTON1_MASK, possible_types, 3, | |
634 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
635 gtk_drag_dest_set (wdata->listbox, GTK_DEST_DEFAULT_ALL, possible_types, 2, | |
636 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
637 | |
638 gtk_clist_set_selection_mode (GTK_CLIST (wdata->listbox), | |
639 GTK_SELECTION_EXTENDED); | |
640 | |
641 gtk_clist_set_column_width (GTK_CLIST (wdata->listbox), 0, 16); | |
642 gtk_clist_set_column_justification (GTK_CLIST (wdata->listbox), 0, | |
643 GTK_JUSTIFY_CENTER); | |
129 | 644 |
645 g_snprintf (tempstr, sizeof (tempstr), "%s_file_width", wdata->prefix_col_str); | |
646 gftp_lookup_global_option (tempstr, &colwidth); | |
647 setup_column (wdata->listbox, 1, colwidth); | |
648 | |
1 | 649 gtk_clist_set_column_justification (GTK_CLIST (wdata->listbox), 2, |
650 GTK_JUSTIFY_RIGHT); | |
129 | 651 |
652 g_snprintf (tempstr, sizeof (tempstr), "%s_size_width", wdata->prefix_col_str); | |
653 gftp_lookup_global_option (tempstr, &colwidth); | |
654 setup_column (wdata->listbox, 2, colwidth); | |
655 | |
656 g_snprintf (tempstr, sizeof (tempstr), "%s_user_width", wdata->prefix_col_str); | |
657 gftp_lookup_global_option (tempstr, &colwidth); | |
658 setup_column (wdata->listbox, 3, colwidth); | |
659 | |
660 g_snprintf (tempstr, sizeof (tempstr), "%s_group_width", wdata->prefix_col_str); | |
661 gftp_lookup_global_option (tempstr, &colwidth); | |
662 setup_column (wdata->listbox, 4, colwidth); | |
663 | |
664 g_snprintf (tempstr, sizeof (tempstr), "%s_date_width", wdata->prefix_col_str); | |
665 gftp_lookup_global_option (tempstr, &colwidth); | |
666 setup_column (wdata->listbox, 5, colwidth); | |
667 | |
668 g_snprintf (tempstr, sizeof (tempstr), "%s_attribs_width", wdata->prefix_col_str); | |
669 gftp_lookup_global_option (tempstr, &colwidth); | |
670 setup_column (wdata->listbox, 6, colwidth); | |
671 | |
1 | 672 gtk_box_pack_start (GTK_BOX (box), scroll_list, TRUE, TRUE, 0); |
673 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "click_column", | |
674 GTK_SIGNAL_FUNC (sortrows), (gpointer) wdata); | |
675 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "drag_data_get", | |
676 GTK_SIGNAL_FUNC (listbox_drag), (gpointer) wdata); | |
677 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "drag_data_received", | |
678 GTK_SIGNAL_FUNC (listbox_get_drag_data), | |
679 (gpointer) wdata); | |
680 gtk_signal_connect_after (GTK_OBJECT (wdata->listbox), "key_press_event", | |
681 GTK_SIGNAL_FUNC (list_enter), (gpointer) wdata); | |
51 | 682 gtk_signal_connect (GTK_OBJECT (wdata->listbox), "select_row", |
683 GTK_SIGNAL_FUNC(select_row_callback), | |
684 (gpointer) wdata); | |
1 | 685 gtk_signal_connect_after (GTK_OBJECT (wdata->listbox), "button_press_event", |
686 GTK_SIGNAL_FUNC (list_dblclick), (gpointer) wdata); | |
687 return (parent); | |
688 } | |
689 | |
690 | |
691 static gint | |
692 menu_mouse_click (GtkWidget * widget, GdkEventButton * event, gpointer data) | |
693 { | |
694 GtkItemFactory *factory; | |
695 | |
696 factory = (GtkItemFactory *) data; | |
697 if (event->button == 3) | |
698 gtk_item_factory_popup (factory, (guint) event->x_root, | |
699 (guint) event->y_root, 3, event->time); | |
700 return (FALSE); | |
701 } | |
702 | |
703 | |
48 | 704 static GtkWidget * |
705 CreateFTPWindows (GtkWidget * ui) | |
1 | 706 { |
48 | 707 GtkWidget *box, *dlbox, *winpane, *dlpane, *logpane, *mainvbox, *tempwid, |
708 *button; | |
129 | 709 gftp_config_list_vars * tmplistvar; |
48 | 710 char *dltitles[2]; |
129 | 711 int tmplookup; |
48 | 712 #if GTK_MAJOR_VERSION > 1 |
713 GtkTextBuffer * textbuf; | |
714 GtkTextIter iter; | |
715 GtkTextTag *tag; | |
129 | 716 GdkColor * fore; |
48 | 717 #endif |
718 | |
719 memset (&window1, 0, sizeof (window1)); | |
720 memset (&window2, 0, sizeof (window2)); | |
129 | 721 |
722 gftp_lookup_global_option ("localhistory", &tmplistvar); | |
723 window1.history = &tmplistvar->list; | |
724 window1.histlen = &tmplistvar->num_items; | |
725 | |
726 gftp_lookup_global_option ("remotehistory", &tmplistvar); | |
727 window2.history = &tmplistvar->list; | |
728 window2.histlen = &tmplistvar->num_items; | |
48 | 729 |
730 mainvbox = gtk_vbox_new (FALSE, 0); | |
731 | |
732 tempwid = CreateMenus (ui); | |
733 gtk_box_pack_start (GTK_BOX (mainvbox), tempwid, FALSE, FALSE, 0); | |
1 | 734 |
48 | 735 tempwid = CreateToolbar (ui); |
736 gtk_box_pack_start (GTK_BOX (mainvbox), tempwid, FALSE, FALSE, 0); | |
737 | |
738 winpane = gtk_hpaned_new (); | |
739 | |
740 box = gtk_hbox_new (FALSE, 0); | |
741 | |
129 | 742 window1.prefix_col_str = "local"; |
743 local_frame = CreateFTPWindow (&window1); | |
48 | 744 gtk_box_pack_start (GTK_BOX (box), local_frame, TRUE, TRUE, 0); |
745 | |
746 dlbox = gtk_vbox_new (FALSE, 0); | |
747 gtk_container_border_width (GTK_CONTAINER (dlbox), 5); | |
748 gtk_box_pack_start (GTK_BOX (box), dlbox, FALSE, FALSE, 0); | |
749 | |
750 #if GTK_MAJOR_VERSION == 1 | |
751 tempwid = toolbar_pixmap (ui, "right.xpm"); | |
752 #else | |
753 tempwid = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, | |
754 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
755 #endif | |
756 | |
757 button = gtk_button_new (); | |
758 gtk_box_pack_start (GTK_BOX (dlbox), button, TRUE, FALSE, 0); | |
759 gtk_signal_connect_object (GTK_OBJECT (button), "clicked", | |
760 GTK_SIGNAL_FUNC (put_files), NULL); | |
761 gtk_container_add (GTK_CONTAINER (button), tempwid); | |
1 | 762 |
45 | 763 #if GTK_MAJOR_VERSION == 1 |
48 | 764 tempwid = toolbar_pixmap (ui, "left.xpm"); |
1 | 765 #else |
48 | 766 tempwid = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, |
767 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
1 | 768 #endif |
48 | 769 |
770 button = gtk_button_new (); | |
771 gtk_box_pack_start (GTK_BOX (dlbox), button, TRUE, FALSE, 0); | |
772 gtk_signal_connect_object (GTK_OBJECT (button), "clicked", | |
773 GTK_SIGNAL_FUNC (get_files), NULL); | |
774 gtk_container_add (GTK_CONTAINER (button), tempwid); | |
775 | |
776 gtk_paned_pack1 (GTK_PANED (winpane), box, 1, 1); | |
777 | |
129 | 778 window2.prefix_col_str = "remote"; |
779 remote_frame = CreateFTPWindow (&window2); | |
780 | |
48 | 781 gtk_paned_pack2 (GTK_PANED (winpane), remote_frame, 1, 1); |
782 | |
783 dlpane = gtk_vpaned_new (); | |
784 gtk_paned_pack1 (GTK_PANED (dlpane), winpane, 1, 1); | |
785 | |
786 transfer_scroll = gtk_scrolled_window_new (NULL, NULL); | |
129 | 787 gftp_lookup_global_option ("transfer_height", &tmplookup); |
788 gtk_widget_set_size_request (transfer_scroll, -1, tmplookup); | |
48 | 789 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (transfer_scroll), |
790 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
791 | |
792 dltitles[0] = _("Filename"); | |
793 dltitles[1] = _("Progress"); | |
794 dlwdw = gtk_ctree_new_with_titles (2, 0, dltitles); | |
795 gtk_clist_set_selection_mode (GTK_CLIST (dlwdw), GTK_SELECTION_SINGLE); | |
796 gtk_clist_set_reorderable (GTK_CLIST (dlwdw), 0); | |
797 | |
129 | 798 gftp_lookup_global_option ("file_trans_column", &tmplookup); |
799 if (tmplookup == 0) | |
48 | 800 gtk_clist_set_column_auto_resize (GTK_CLIST (dlwdw), 0, TRUE); |
801 else | |
129 | 802 gtk_clist_set_column_width (GTK_CLIST (dlwdw), 0, tmplookup); |
48 | 803 |
115 | 804 gtk_container_add (GTK_CONTAINER (transfer_scroll), dlwdw); |
48 | 805 gtk_signal_connect (GTK_OBJECT (dlwdw), "button_press_event", |
806 GTK_SIGNAL_FUNC (menu_mouse_click), (gpointer) dl_factory); | |
807 gtk_paned_pack2 (GTK_PANED (dlpane), transfer_scroll, 1, 1); | |
808 | |
809 logpane = gtk_vpaned_new (); | |
810 gtk_paned_pack1 (GTK_PANED (logpane), dlpane, 1, 1); | |
811 | |
812 log_table = gtk_table_new (1, 2, FALSE); | |
129 | 813 gftp_lookup_global_option ("log_height", &tmplookup); |
814 gtk_widget_set_size_request (log_table, -1, tmplookup); | |
48 | 815 |
816 #if GTK_MAJOR_VERSION == 1 | |
817 logwdw = gtk_text_new (NULL, NULL); | |
818 | |
819 gtk_text_set_editable (GTK_TEXT (logwdw), FALSE); | |
820 gtk_text_set_word_wrap (GTK_TEXT (logwdw), TRUE); | |
821 | |
822 gtk_table_attach (GTK_TABLE (log_table), logwdw, 0, 1, 0, 1, | |
823 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
824 0, 0); | |
825 gtk_signal_connect (GTK_OBJECT (logwdw), "button_press_event", | |
826 GTK_SIGNAL_FUNC (menu_mouse_click), | |
827 (gpointer) log_factory); | |
828 | |
829 tempwid = gtk_vscrollbar_new (GTK_TEXT (logwdw)->vadj); | |
830 gtk_table_attach (GTK_TABLE (log_table), tempwid, 1, 2, 0, 1, | |
831 GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); | |
832 logwdw_vadj = GTK_TEXT (logwdw)->vadj; | |
833 #else | |
834 logwdw = gtk_text_view_new (); | |
835 gtk_text_view_set_editable (GTK_TEXT_VIEW (logwdw), FALSE); | |
836 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (logwdw), FALSE); | |
837 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (logwdw), GTK_WRAP_WORD); | |
838 | |
839 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
840 | |
841 tag = gtk_text_buffer_create_tag (textbuf, "send", NULL); | |
129 | 842 gftp_lookup_global_option ("send_color", &fore); |
843 g_object_set (G_OBJECT (tag), "foreground_gdk", fore, NULL); | |
48 | 844 |
845 tag = gtk_text_buffer_create_tag (textbuf, "recv", NULL); | |
129 | 846 gftp_lookup_global_option ("recv_color", &fore); |
847 g_object_set (G_OBJECT (tag), "foreground_gdk", fore, NULL); | |
48 | 848 |
849 tag = gtk_text_buffer_create_tag (textbuf, "error", NULL); | |
129 | 850 gftp_lookup_global_option ("error_color", &fore); |
851 g_object_set (G_OBJECT (tag), "foreground_gdk", fore, NULL); | |
48 | 852 |
853 tag = gtk_text_buffer_create_tag (textbuf, "misc", NULL); | |
129 | 854 gftp_lookup_global_option ("misc_color", &fore); |
48 | 855 g_object_set (G_OBJECT (tag), "foreground_gdk", &fore, NULL); |
856 | |
857 tempwid = gtk_scrolled_window_new (NULL, NULL); | |
858 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (tempwid), | |
859 GTK_POLICY_AUTOMATIC, | |
860 GTK_POLICY_AUTOMATIC); | |
861 gtk_container_add (GTK_CONTAINER (tempwid), logwdw); | |
862 gtk_table_attach (GTK_TABLE (log_table), tempwid, 0, 1, 0, 1, | |
863 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
864 0, 0); | |
865 logwdw_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tempwid)); | |
866 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
867 logwdw_textmark = gtk_text_buffer_create_mark (textbuf, "end", &iter, 1); | |
868 #endif | |
869 gtk_paned_pack2 (GTK_PANED (logpane), log_table, 1, 1); | |
870 gtk_box_pack_start (GTK_BOX (mainvbox), logpane, TRUE, TRUE, 0); | |
871 | |
872 gtk_widget_show_all (mainvbox); | |
873 return (mainvbox); | |
1 | 874 } |
875 | |
876 | |
48 | 877 void |
878 init_gftp (int argc, char *argv[], GtkWidget * parent) | |
1 | 879 { |
48 | 880 if (argc == 2 && strncmp (argv[1], "--", 2) != 0) |
1 | 881 { |
48 | 882 if (gftp_parse_url (window2.request, argv[1]) == 0) |
883 ftp_connect (&window2, window2.request, 1); | |
884 else | |
885 gftp_usage (); | |
1 | 886 } |
887 } | |
888 | |
889 | |
890 void | |
891 toolbar_hostedit (GtkWidget * widget, gpointer data) | |
892 { | |
173 | 893 int (*init) (gftp_request * request); |
129 | 894 gftp_config_list_vars * tmplistvar; |
1 | 895 GtkWidget *tempwid; |
896 const char *txt; | |
897 int num; | |
898 | |
899 if (current_wdata->request->stopable) | |
900 { | |
901 ftp_log (gftp_logging_misc, NULL, | |
902 _("%s: Please hit the stop button first to do anything else\n"), | |
903 _("Connect")); | |
904 return; | |
905 } | |
906 | |
907 if (GFTP_IS_CONNECTED (current_wdata->request)) | |
908 disconnect (current_wdata); | |
909 | |
910 tempwid = gtk_menu_get_active (GTK_MENU (protocol_menu)); | |
195 | 911 num = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (tempwid))); |
1 | 912 init = gftp_protocols[num].init; |
173 | 913 if (init (current_wdata->request) < 0) |
914 return; | |
1 | 915 |
916 gftp_set_hostname (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry))); | |
917 alltrim (current_wdata->request->hostname); | |
918 | |
919 if (current_wdata->request->need_hostport && | |
920 *current_wdata->request->hostname == '\0') | |
921 { | |
922 ftp_log (gftp_logging_error, NULL, | |
923 _("Error: You must type in a host to connect to\n")); | |
924 return; | |
925 } | |
926 | |
129 | 927 gftp_lookup_global_option ("hosthistory", &tmplistvar); |
928 add_history (hostedit, &tmplistvar->list, &tmplistvar->num_items, | |
1 | 929 current_wdata->request->hostname); |
930 | |
931 if (strchr (current_wdata->request->hostname, '/') != NULL && | |
932 gftp_parse_url (current_wdata->request, | |
933 current_wdata->request->hostname) == 0) | |
934 { | |
935 ftp_connect (current_wdata, current_wdata->request, 1); | |
936 return; | |
937 } | |
938 | |
939 txt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry)); | |
940 gftp_set_port (current_wdata->request, strtol (txt, NULL, 10)); | |
129 | 941 |
942 gftp_lookup_global_option ("porthistory", &tmplistvar); | |
943 add_history (portedit, &tmplistvar->list, &tmplistvar->num_items, txt); | |
1 | 944 |
945 gftp_set_username (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry))); | |
946 alltrim (current_wdata->request->username); | |
947 | |
129 | 948 gftp_lookup_global_option ("userhistory", &tmplistvar); |
949 add_history (useredit, &tmplistvar->list, &tmplistvar->num_items, | |
1 | 950 current_wdata->request->username); |
951 | |
952 gftp_set_password (current_wdata->request, | |
953 gtk_entry_get_text (GTK_ENTRY (passedit))); | |
954 | |
955 gftp_set_directory (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (current_wdata->combo)->entry))); | |
956 alltrim (current_wdata->request->directory); | |
957 | |
958 add_history (current_wdata->combo, current_wdata->history, | |
959 current_wdata->histlen, current_wdata->request->directory); | |
960 | |
961 ftp_connect (current_wdata, current_wdata->request, 1); | |
962 } | |
963 | |
964 | |
965 void | |
966 sortrows (GtkCList * clist, gint column, gpointer data) | |
967 { | |
129 | 968 char sortcol_name[25], sortasds_name[25]; |
969 int swap_col, sortcol, sortasds; | |
1 | 970 gftp_window_data * wdata; |
16 | 971 GtkWidget * sort_wid; |
972 GList * templist; | |
1 | 973 |
974 wdata = data; | |
129 | 975 g_snprintf (sortcol_name, sizeof (sortcol_name), "%s_sortcol", wdata->prefix_col_str); |
976 gftp_lookup_global_option (sortcol_name, &sortcol); | |
977 g_snprintf (sortasds_name, sizeof (sortasds_name), "%s_sortasds", wdata->prefix_col_str); | |
978 gftp_lookup_global_option (sortasds_name, &sortasds); | |
979 | |
980 if (column == -1) | |
981 column = sortcol; | |
982 | |
983 if (column == 0 || (column == sortcol && wdata->sorted)) | |
1 | 984 { |
129 | 985 sortasds = !sortasds; |
986 gftp_set_global_option (sortasds_name, &sortasds); | |
19 | 987 swap_col = 1; |
988 } | |
989 else | |
990 swap_col = 0; | |
991 | |
992 if (swap_col || !wdata->sorted) | |
993 { | |
1 | 994 sort_wid = gtk_clist_get_column_widget (clist, 0); |
995 gtk_widget_destroy (sort_wid); | |
45 | 996 #if GTK_MAJOR_VERSION == 1 |
129 | 997 if (sortasds) |
1 | 998 sort_wid = toolbar_pixmap (wdata->listbox, "down.xpm"); |
999 else | |
1000 sort_wid = toolbar_pixmap (wdata->listbox, "up.xpm"); | |
19 | 1001 #else |
129 | 1002 if (sortasds) |
19 | 1003 sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_ASCENDING, |
1004 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
1005 else | |
1006 sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_DESCENDING, | |
1007 GTK_ICON_SIZE_SMALL_TOOLBAR); | |
1008 #endif | |
1009 | |
1 | 1010 gtk_clist_set_column_widget (clist, 0, sort_wid); |
1011 } | |
1012 else | |
129 | 1013 { |
1014 sortcol = column; | |
1015 gftp_set_global_option (sortcol_name, &sortcol); | |
1016 } | |
37 | 1017 |
1018 if (!GFTP_IS_CONNECTED (wdata->request)) | |
1019 return; | |
1 | 1020 |
1021 gtk_clist_freeze (clist); | |
1022 gtk_clist_clear (clist); | |
1023 | |
129 | 1024 wdata->files = gftp_sort_filelist (wdata->files, sortcol, sortasds); |
1 | 1025 |
16 | 1026 templist = wdata->files; |
1027 while (templist != NULL) | |
1 | 1028 { |
16 | 1029 add_file_listbox (wdata, templist->data); |
1030 templist = templist->next; | |
1 | 1031 } |
1032 | |
1033 wdata->sorted = 1; | |
1034 gtk_clist_thaw (clist); | |
1035 update_window_info (); | |
1036 } | |
1037 | |
1038 | |
1039 void | |
1040 stop_button (GtkWidget * widget, gpointer data) | |
1041 { | |
1042 pthread_t comptid; | |
1043 | |
1044 memset (&comptid, 0, sizeof (comptid)); | |
1045 if (!pthread_equal (comptid, window1.tid)) | |
1046 pthread_kill (window1.tid, SIGINT); | |
1047 else if (!pthread_equal (comptid, window2.tid)) | |
1048 pthread_kill (window2.tid, SIGINT); | |
1049 } | |
1050 | |
48 | 1051 |
198 | 1052 static int |
1053 gftp_gtk_config_file_read_color (char *str, gftp_config_vars * cv, int line) | |
1054 { | |
1055 char *red, *green, *blue; | |
1056 GdkColor * color; | |
1057 | |
1058 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL) | |
1059 g_free (cv->value); | |
1060 | |
1061 gftp_config_parse_args (str, 3, line, &red, &green, &blue); | |
1062 | |
1063 color = g_malloc (sizeof (*color)); | |
1064 color->red = strtol (red, NULL, 16); | |
1065 color->green = strtol (green, NULL, 16); | |
1066 color->blue = strtol (blue, NULL, 16); | |
1067 g_free (red); | |
1068 g_free (green); | |
1069 g_free (blue); | |
1070 | |
1071 cv->value = color; | |
1072 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM; | |
1073 | |
1074 return (0); | |
1075 } | |
1076 | |
1077 | |
1078 static int | |
1079 gftp_gtk_config_file_write_color (gftp_config_vars * cv, FILE * fd, int to_config_file) | |
1080 { | |
1081 GdkColor * color; | |
1082 | |
1083 color = cv->value; | |
1084 fprintf (fd, "%x:%x:%x", color->red, color->green, color->blue); | |
1085 return (0); | |
1086 } | |
1087 | |
1088 | |
48 | 1089 int |
1090 main (int argc, char **argv) | |
1091 { | |
129 | 1092 char *startup_directory; |
48 | 1093 GtkWidget *window, *ui; |
1094 | |
1095 #ifdef HAVE_GETTEXT | |
1096 setlocale (LC_ALL, ""); | |
1097 bindtextdomain ("gftp", LOCALE_DIR); | |
1098 #if GTK_MAJOR_VERSION > 1 | |
1099 bind_textdomain_codeset ("gftp", "UTF-8"); | |
1100 #endif | |
1101 textdomain ("gftp"); | |
1102 #endif | |
1103 | |
1104 g_thread_init (NULL); | |
56 | 1105 main_thread_id = pthread_self (); |
48 | 1106 gtk_set_locale (); |
1107 gtk_init (&argc, &argv); | |
1108 | |
1109 signal (SIGCHLD, sig_child); | |
1110 signal (SIGPIPE, SIG_IGN); | |
1111 signal (SIGALRM, signal_handler); | |
1112 signal (SIGINT, signal_handler); | |
1113 | |
1114 graphic_hash_table = g_hash_table_new (string_hash_function, string_hash_compare); | |
115 | 1115 |
198 | 1116 /* We override the read color functions because we are using a GdkColor |
1117 structures to store the color. If I put this in lib/config_file.c, then | |
1118 the core library would be dependant on Gtk+ being present */ | |
1119 gftp_option_types[gftp_option_type_color].read_function = gftp_gtk_config_file_read_color; | |
1120 gftp_option_types[gftp_option_type_color].write_function = gftp_gtk_config_file_write_color; | |
1121 | |
129 | 1122 gftp_read_config_file (SHARE_DIR); |
48 | 1123 if (gftp_parse_command_line (&argc, &argv) != 0) |
1124 exit (0); | |
1125 | |
1126 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
1127 gtk_signal_connect (GTK_OBJECT (window), "delete_event", | |
1128 GTK_SIGNAL_FUNC (delete_event), NULL); | |
1129 gtk_signal_connect (GTK_OBJECT (window), "destroy", | |
1130 GTK_SIGNAL_FUNC (destroy), NULL); | |
129 | 1131 gtk_window_set_title (GTK_WINDOW (window), gftp_version); |
48 | 1132 gtk_window_set_wmclass (GTK_WINDOW(window), "main", "gFTP"); |
129 | 1133 gtk_widget_set_name (window, gftp_version); |
48 | 1134 gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE); |
1135 gtk_widget_realize (window); | |
1136 | |
1137 gftp_icon = open_xpm (window, "gftp.xpm"); | |
1138 if (gftp_icon != NULL) | |
1139 { | |
1140 gdk_window_set_icon (window->window, NULL, gftp_icon->pixmap, | |
1141 gftp_icon->bitmap); | |
168 | 1142 gdk_window_set_icon_name (window->window, gftp_version); |
48 | 1143 } |
1144 | |
1145 other_wdata = &window1; | |
1146 current_wdata = &window2; | |
1147 ui = CreateFTPWindows (window); | |
1148 gtk_container_add (GTK_CONTAINER (window), ui); | |
1149 gtk_widget_show (window); | |
1150 | |
1151 ftp_log (gftp_logging_misc, NULL, | |
129 | 1152 "%s, Copyright (C) 1998-2002 Brian Masney <", gftp_version); |
48 | 1153 ftp_log (gftp_logging_recv, NULL, "masneyb@gftp.org"); |
1154 ftp_log (gftp_logging_misc, NULL, | |
1155 _(">. 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")); | |
1156 ftp_log (gftp_logging_misc, NULL, | |
1157 _("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")); | |
1158 | |
1159 gtk_timeout_add (1000, update_downloads, NULL); | |
173 | 1160 if (gftp_protocols[GFTP_LOCAL_NUM].init (window1.request) == 0) |
1161 { | |
1162 gftp_lookup_request_option (window1.request, "startup_directory", | |
1163 &startup_directory); | |
1164 if (*startup_directory != '\0') | |
1165 gftp_set_directory (window1.request, startup_directory); | |
129 | 1166 |
173 | 1167 gftp_connect (window1.request); |
1168 ftp_list_files (&window1, 0); | |
1169 } | |
48 | 1170 |
1171 /* On the remote window, even though we aren't connected, draw the sort | |
1172 icon on that side */ | |
129 | 1173 sortrows (GTK_CLIST (window2.listbox), -1, &window2); |
48 | 1174 |
1175 init_gftp (argc, argv, window); | |
1176 | |
1177 GDK_THREADS_ENTER (); | |
1178 gtk_main (); | |
1179 GDK_THREADS_LEAVE (); | |
1180 return (0); | |
1181 } | |
1182 | |
1183 |