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