📄 gftp-gtk.c
字号:
/*****************************************************************************//* gftp-gtk.c - GTK+ 1.2 port of gftp *//* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> *//* *//* This program is free software; you can redistribute it and/or modify *//* it under the terms of the GNU General Public License as published by *//* the Free Software Foundation; either version 2 of the License, or *//* (at your option) any later version. *//* *//* This program is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *//* GNU General Public License for more details. *//* *//* You should have received a copy of the GNU General Public License *//* along with this program; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA *//*****************************************************************************/#include "gftp-gtk.h"static const char cvsid[] = "$Id: gftp-gtk.c,v 1.66 2005/01/25 02:34:19 masneyb Exp $";static GtkItemFactory *log_factory, *dl_factory;static GtkWidget * local_frame, * remote_frame, * log_table, * transfer_scroll, * gftpui_command_toolbar;gftp_window_data window1, window2, *other_wdata, *current_wdata;GtkWidget * stop_btn, * hostedit, * useredit, * passedit, * portedit, * logwdw, * dlwdw, * protocol_menu, * optionmenu, * gftpui_command_widget, * download_left_arrow, * upload_right_arrow, * openurl_btn;GtkTooltips * openurl_tooltip;GtkAdjustment * logwdw_vadj;#if GTK_MAJOR_VERSION > 1GtkTextMark * logwdw_textmark;#endifint local_start, remote_start, trans_start, log_start, tools_start;GHashTable * graphic_hash_table = NULL;GtkItemFactoryEntry * menus = NULL;GtkItemFactory * factory = NULL;pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;gftp_graphic * gftp_icon;pthread_t main_thread_id;GList * viewedit_processes = NULL;static intget_column (GtkCListColumn * col){ if (col->auto_resize) return (0); else if (!col->visible) return (-1); else return (col->width);}static void_gftp_exit (GtkWidget * widget, gpointer data){ const char *tempstr; intptr_t ret; ret = GTK_WIDGET (local_frame)->allocation.width; gftp_set_global_option ("listbox_local_width", GINT_TO_POINTER (ret)); ret = GTK_WIDGET (remote_frame)->allocation.width; gftp_set_global_option ("listbox_remote_width", GINT_TO_POINTER (ret)); ret = GTK_WIDGET (remote_frame)->allocation.height; gftp_set_global_option ("listbox_file_height", GINT_TO_POINTER (ret)); ret = GTK_WIDGET (log_table)->allocation.height; gftp_set_global_option ("log_height", GINT_TO_POINTER (ret)); ret = GTK_WIDGET (transfer_scroll)->allocation.height; gftp_set_global_option ("transfer_height", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (dlwdw)->column[0]); gftp_set_global_option ("file_trans_column", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window1.listbox)->column[1]); gftp_set_global_option ("local_file_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window1.listbox)->column[2]); gftp_set_global_option ("local_size_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window1.listbox)->column[3]); gftp_set_global_option ("local_user_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window1.listbox)->column[4]); gftp_set_global_option ("local_group_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window1.listbox)->column[5]); gftp_set_global_option ("local_date_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window1.listbox)->column[6]); gftp_set_global_option ("local_attribs_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window2.listbox)->column[1]); gftp_set_global_option ("remote_file_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window2.listbox)->column[2]); gftp_set_global_option ("remote_size_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window2.listbox)->column[3]); gftp_set_global_option ("remote_user_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window2.listbox)->column[4]); gftp_set_global_option ("remote_group_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window2.listbox)->column[5]); gftp_set_global_option ("remote_date_width", GINT_TO_POINTER (ret)); ret = get_column (>K_CLIST (window2.listbox)->column[6]); gftp_set_global_option ("remote_attribs_width", GINT_TO_POINTER (ret)); tempstr = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); gftp_set_global_option ("host_value", tempstr); tempstr = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry)); gftp_set_global_option ("port_value", tempstr); tempstr = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry)); gftp_set_global_option ("user_value", tempstr); gftp_shutdown (); exit (0);}static gint_gftp_try_close (GtkWidget * widget, GdkEvent * event, gpointer data){ if (gftp_file_transfers == NULL) { _gftp_exit (NULL, NULL); return (0); } else { MakeYesNoDialog (_("Exit"), _("There are file transfers in progress.\nAre you sure you want to exit?"), _gftp_exit, NULL, NULL, NULL); return (1); }}static void_gftp_force_close (GtkWidget * widget, gpointer data){ exit (0);}static void_gftp_menu_exit (GtkWidget * widget, gpointer data){ if (!_gftp_try_close (widget, NULL, data)) _gftp_exit (widget, data);}static voidchange_setting (gftp_window_data * wdata, int menuitem, GtkWidget * checkmenu){ switch (menuitem) { case GFTP_MENU_ITEM_ASCII: gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1)); break; case GFTP_MENU_ITEM_BINARY: gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0)); break; case GFTP_MENU_ITEM_WIN1: current_wdata = &window1; other_wdata = &window2; if (wdata->request != NULL) update_window_info (); break; case GFTP_MENU_ITEM_WIN2: current_wdata = &window2; other_wdata = &window1; if (wdata->request != NULL) update_window_info (); break; }}static void_gftpui_gtk_do_openurl (gftp_window_data * wdata, gftp_dialog_data * ddata){ const char *tempstr; char *buf; tempstr = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); if (tempstr != NULL && *tempstr != '\0') { buf = g_strdup (tempstr); destroy_dialog (ddata); gftpui_common_cmd_open (wdata, wdata->request, NULL, NULL, buf); g_free (buf); }}static voidopenurl_dialog (gpointer data){ gftp_window_data * wdata; wdata = data; MakeEditDialog (_("Connect via URL"), _("Enter a URL to connect to"), NULL, 1, NULL, gftp_dialog_button_connect, _gftpui_gtk_do_openurl, wdata, NULL, NULL);}static voidtb_openurl_dialog (gpointer data){ const char *edttxt; if (current_wdata->request->stopable) { ftp_log (gftp_logging_error, NULL, _("%s: Please hit the stop button first to do anything else\n"), _("OpenURL")); return; } edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); if (GFTP_IS_CONNECTED (current_wdata->request)) gftpui_disconnect (current_wdata); else if (edttxt != NULL && *edttxt != '\0') toolbar_hostedit (NULL, NULL); else openurl_dialog (current_wdata);}static voidgftp_gtk_refresh (gftp_window_data * wdata){ gftpui_refresh (wdata, 1);}static GtkWidget *CreateMenus (GtkWidget * parent){ int local_len, remote_len, len, i, trans_len, log_len, tools_len; GtkAccelGroup *accel_group; intptr_t ascii_transfers; GtkWidget * tempwid; static GtkItemFactoryEntry menu_items[] = { {N_("/_FTP"), NULL, 0, 0, MN_("<Branch>")}, {N_("/FTP/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/FTP/Window 1"), NULL, change_setting, GFTP_MENU_ITEM_WIN1, MN_("<RadioItem>")}, {N_("/FTP/Window 2"), NULL, change_setting, GFTP_MENU_ITEM_WIN2, MN_("/FTP/Window 1")}, {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/FTP/Ascii"), NULL, change_setting, GFTP_MENU_ITEM_ASCII, MN_("<RadioItem>")}, {N_("/FTP/Binary"), NULL, change_setting, GFTP_MENU_ITEM_BINARY, MN_("/FTP/Ascii")}, {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/FTP/_Options..."), "<control>O", options_dialog, 0, MS_(GTK_STOCK_PREFERENCES)}, {N_("/FTP/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/FTP/_Quit"), "<control>Q", _gftp_menu_exit, 0, MS_(GTK_STOCK_QUIT)}, {N_("/_Local"), NULL, 0, 0, MN_("<Branch>")}, {N_("/Local/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/Local/Open URL..."), "", openurl_dialog, 0, MS_(GTK_STOCK_OPEN)}, {N_("/Local/Disconnect"), "", gftpui_disconnect, 0, MS_(GTK_STOCK_CLOSE)}, {N_("/Local/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/Local/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, {N_("/Local/Show selected"), NULL, show_selected, 0, MN_(NULL)}, {N_("/Local/Select All"), NULL, selectall, 0, MN_(NULL)}, {N_("/Local/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, {N_("/Local/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, {N_("/Local/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/Local/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, {N_("/Local/Send SITE Command..."), NULL, gftpui_site_dialog, 0, MN_(NULL)}, {N_("/Local/Change Directory"), NULL, gftpui_chdir_dialog, 0, MN_(NULL)}, {N_("/Local/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, {N_("/Local/Make Directory..."), NULL, gftpui_mkdir_dialog, 0, MN_(NULL)}, {N_("/Local/Rename..."), NULL, gftpui_rename_dialog, 0, MN_(NULL)}, {N_("/Local/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, {N_("/Local/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, {N_("/Local/View..."), NULL, view_dialog, 0, MN_(NULL)}, {N_("/Local/Refresh"), NULL, gftp_gtk_refresh, 0, MS_(GTK_STOCK_REFRESH)}, {N_("/_Remote"), NULL, 0, 0, MN_("<Branch>")}, {N_("/Remote/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/Remote/Open _URL..."), "<control>U", openurl_dialog, 0, MS_(GTK_STOCK_OPEN)}, {N_("/Remote/Disconnect"), "<control>D", gftpui_disconnect, 0, MS_(GTK_STOCK_CLOSE)}, {N_("/Remote/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/Remote/Change Filespec..."), NULL, change_filespec, 0, MN_(NULL)}, {N_("/Remote/Show selected"), NULL, show_selected, 0, MN_(NULL)}, {N_("/Remote/Select All"), NULL, selectall, 0, MN_(NULL)}, {N_("/Remote/Select All Files"), NULL, selectallfiles, 0, MN_(NULL)}, {N_("/Remote/Deselect All"), NULL, deselectall, 0, MN_(NULL)}, {N_("/Remote/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/Remote/Save Directory Listing..."), NULL, save_directory_listing, 0, MN_(NULL)}, {N_("/Remote/Send SITE Command..."), NULL, gftpui_site_dialog, 0, MN_(NULL)}, {N_("/Remote/Change Directory"), NULL, gftpui_chdir_dialog, 0, MN_(NULL)}, {N_("/Remote/Chmod..."), NULL, chmod_dialog, 0, MN_(NULL)}, {N_("/Remote/Make Directory..."), NULL, gftpui_mkdir_dialog, 0, MN_(NULL)}, {N_("/Remote/Rename..."), NULL, gftpui_rename_dialog, 0, MN_(NULL)}, {N_("/Remote/Delete..."), NULL, delete_dialog, 0, MN_(NULL)}, {N_("/Remote/Edit..."), NULL, edit_dialog, 0, MN_(NULL)}, {N_("/Remote/View..."), NULL, view_dialog, 0, MN_(NULL)}, {N_("/Remote/Refresh"), NULL, gftp_gtk_refresh, 0, MS_(GTK_STOCK_REFRESH)}, {N_("/_Bookmarks"), NULL, 0, 0, MN_("<Branch>")}, {N_("/Bookmarks/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/Bookmarks/Add bookmark"), "<control>A", add_bookmark, 0, MS_(GTK_STOCK_ADD)}, {N_("/Bookmarks/Edit bookmarks"), NULL, edit_bookmarks, 0, MN_(NULL)}, {N_("/Bookmarks/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/_Transfers"), NULL, 0, 0, MN_("<Branch>")}, {N_("/Transfers/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/Transfers/Start Transfer"), NULL, start_transfer, 0, MN_(NULL)}, {N_("/Transfers/Stop Transfer"), NULL, stop_transfer, 0, MS_(GTK_STOCK_STOP)}, {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/Transfers/Skip Current File"), NULL, skip_transfer, 0, MN_(NULL)}, {N_("/Transfers/Remove File"), NULL, remove_file_transfer, 0, MS_(GTK_STOCK_DELETE)}, {N_("/Transfers/Move File Up"), NULL, move_transfer_up, 0, MS_(GTK_STOCK_GO_UP)}, {N_("/Transfers/Move File Down"), NULL, move_transfer_down, 0, MS_(GTK_STOCK_GO_DOWN)}, {N_("/Transfers/sep"), NULL, 0, 0, MN_("<Separator>")}, {N_("/Transfers/Retrieve Files"), "<control>R", get_files, 0, MN_(NULL)}, {N_("/Transfers/Put Files"), "<control>P", put_files, 0, MN_(NULL)}, {N_("/L_ogging"), NULL, 0, 0, MN_("<Branch>")}, {N_("/Logging/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/Logging/Clear"), NULL, clearlog, 0, MS_(GTK_STOCK_CLEAR)}, {N_("/Logging/View log"), NULL, viewlog, 0, MN_(NULL)}, {N_("/Logging/Save log..."), NULL, savelog, 0, MS_(GTK_STOCK_SAVE)}, {N_("/Tool_s"), NULL, 0, 0, MN_("<Branch>")}, {N_("/Tools/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/Tools/Compare Windows"), NULL, compare_windows, 0, MN_(NULL)}, {N_("/Tools/Clear Cache"), NULL, clear_cache, 0, MS_(GTK_STOCK_CLEAR)}, {N_("/Help"), NULL, 0, 0, MN_("<Branch>")}, {N_("/Help/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, {N_("/Help/About"), NULL, about_dialog, 0, MS_(GTK_STOCK_HELP)} };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -