📄 gftp-gtk.c
字号:
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (tempwid), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (tempwid), logwdw); gtk_table_attach (GTK_TABLE (log_table), tempwid, 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0); logwdw_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tempwid)); gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); logwdw_textmark = gtk_text_buffer_create_mark (textbuf, "end", &iter, 1);#endif gtk_paned_pack2 (GTK_PANED (logpane), log_table, 1, 1); gtk_box_pack_start (GTK_BOX (mainvbox), logpane, TRUE, TRUE, 0); gtk_widget_show_all (mainvbox); gftpui_show_or_hide_command (); return (mainvbox);}static voidinit_gftp (int argc, char *argv[], GtkWidget * parent){ if (argc == 2 && strncmp (argv[1], "--", 2) != 0) { if (gftp_parse_url (window2.request, argv[1]) == 0) ftp_connect (&window2, window2.request, 1); else gftp_usage (); }}voidtoolbar_hostedit (GtkWidget * widget, gpointer data){ int (*init) (gftp_request * request); gftp_config_list_vars * tmplistvar; GtkWidget *tempwid; const char *txt; int num; if (current_wdata->request->stopable) { ftp_log (gftp_logging_misc, NULL, _("%s: Please hit the stop button first to do anything else\n"), _("Connect")); return; } if (GFTP_IS_CONNECTED (current_wdata->request)) gftpui_disconnect (current_wdata); tempwid = gtk_menu_get_active (GTK_MENU (protocol_menu)); num = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (tempwid))); init = gftp_protocols[num].init; if (init (current_wdata->request) < 0) return; txt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); if (strchr (txt, '/') != NULL) { /* The user entered a URL in the host box... */ gftpui_common_cmd_open (current_wdata, current_wdata->request, NULL, NULL, txt); return; } gftp_set_hostname (current_wdata->request, txt); if (current_wdata->request->hostname == NULL) return; alltrim (current_wdata->request->hostname); if (current_wdata->request->need_hostport && *current_wdata->request->hostname == '\0') { ftp_log (gftp_logging_error, NULL, _("Error: You must type in a host to connect to\n")); return; } gftp_lookup_global_option ("hosthistory", &tmplistvar); add_history (hostedit, &tmplistvar->list, &tmplistvar->num_items, current_wdata->request->hostname); if (strchr (current_wdata->request->hostname, '/') != NULL && gftp_parse_url (current_wdata->request, current_wdata->request->hostname) == 0) { ftp_connect (current_wdata, current_wdata->request, 1); return; } txt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry)); gftp_set_port (current_wdata->request, strtol (txt, NULL, 10)); gftp_lookup_global_option ("porthistory", &tmplistvar); add_history (portedit, &tmplistvar->list, &tmplistvar->num_items, txt); gftp_set_username (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry))); if (current_wdata->request->username != NULL) alltrim (current_wdata->request->username); gftp_lookup_global_option ("userhistory", &tmplistvar); add_history (useredit, &tmplistvar->list, &tmplistvar->num_items, current_wdata->request->username); gftp_set_password (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (passedit))); gftp_set_directory (current_wdata->request, gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (current_wdata->combo)->entry))); if (current_wdata->request->directory != NULL) alltrim (current_wdata->request->directory); add_history (current_wdata->combo, current_wdata->history, current_wdata->histlen, current_wdata->request->directory); ftp_connect (current_wdata, current_wdata->request, 1);}voidsortrows (GtkCList * clist, gint column, gpointer data){ char sortcol_name[25], sortasds_name[25]; intptr_t sortcol, sortasds; gftp_window_data * wdata; GtkWidget * sort_wid; GList * templist; int swap_col; wdata = data; g_snprintf (sortcol_name, sizeof (sortcol_name), "%s_sortcol", wdata->prefix_col_str); gftp_lookup_global_option (sortcol_name, &sortcol); g_snprintf (sortasds_name, sizeof (sortasds_name), "%s_sortasds", wdata->prefix_col_str); gftp_lookup_global_option (sortasds_name, &sortasds); if (column == -1) column = sortcol; if (column == 0 || (column == sortcol && wdata->sorted)) { sortasds = !sortasds; gftp_set_global_option (sortasds_name, GINT_TO_POINTER (sortasds)); swap_col = 1; } else swap_col = 0; if (swap_col || !wdata->sorted) { sort_wid = gtk_clist_get_column_widget (clist, 0); gtk_widget_destroy (sort_wid);#if GTK_MAJOR_VERSION == 1 if (sortasds) sort_wid = toolbar_pixmap (wdata->listbox, "down.xpm"); else sort_wid = toolbar_pixmap (wdata->listbox, "up.xpm");#else if (sortasds) sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_ASCENDING, GTK_ICON_SIZE_SMALL_TOOLBAR); else sort_wid = gtk_image_new_from_stock (GTK_STOCK_SORT_DESCENDING, GTK_ICON_SIZE_SMALL_TOOLBAR);#endif gtk_clist_set_column_widget (clist, 0, sort_wid); } else { sortcol = column; gftp_set_global_option (sortcol_name, GINT_TO_POINTER (sortcol)); } if (!GFTP_IS_CONNECTED (wdata->request)) return; gtk_clist_freeze (clist); gtk_clist_clear (clist); wdata->files = gftp_sort_filelist (wdata->files, sortcol, sortasds); templist = wdata->files; while (templist != NULL) { add_file_listbox (wdata, templist->data); templist = templist->next; } wdata->sorted = 1; gtk_clist_thaw (clist); update_window_info ();}voidstop_button (GtkWidget * widget, gpointer data){ pthread_t comptid; memset (&comptid, 0, sizeof (comptid)); if (!pthread_equal (comptid, window1.tid)) pthread_kill (window1.tid, SIGINT); else if (!pthread_equal (comptid, window2.tid)) pthread_kill (window2.tid, SIGINT);}static intgftp_gtk_config_file_read_color (char *str, gftp_config_vars * cv, int line){ char *red, *green, *blue; GdkColor * color; if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL) g_free (cv->value); gftp_config_parse_args (str, 3, line, &red, &green, &blue); color = g_malloc (sizeof (*color)); color->red = strtol (red, NULL, 16); color->green = strtol (green, NULL, 16); color->blue = strtol (blue, NULL, 16); g_free (red); g_free (green); g_free (blue); cv->value = color; cv->flags |= GFTP_CVARS_FLAGS_DYNMEM; return (0);}static intgftp_gtk_config_file_write_color (gftp_config_vars * cv, char *buf, size_t buflen, int to_config_file){ GdkColor * color; color = cv->value; g_snprintf (buf, buflen, "%x:%x:%x", color->red, color->green, color->blue); return (0);}intmain (int argc, char **argv){ GtkWidget *window, *ui; /* We override the read color functions because we are using a GdkColor structures to store the color. If I put this in lib/config_file.c, then the core library would be dependant on Gtk+ being present */ gftp_option_types[gftp_option_type_color].read_function = gftp_gtk_config_file_read_color; gftp_option_types[gftp_option_type_color].write_function = gftp_gtk_config_file_write_color; gftpui_common_init (&argc, &argv, ftp_log); gftpui_common_child_process_done = 0; g_thread_init (NULL);#if GTK_MAJOR_VERSION > 1 gdk_threads_init();#endif main_thread_id = pthread_self (); gtk_set_locale (); gtk_init (&argc, &argv); graphic_hash_table = g_hash_table_new (string_hash_function, string_hash_compare); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (_gftp_try_close), NULL); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (_gftp_force_close), NULL); gtk_window_set_title (GTK_WINDOW (window), gftp_version); gtk_window_set_wmclass (GTK_WINDOW(window), "main", "gFTP"); gtk_widget_set_name (window, gftp_version); gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE); gtk_widget_realize (window); gftp_icon = open_xpm (window, "gftp.xpm"); if (gftp_icon != NULL) { gdk_window_set_icon (window->window, NULL, gftp_icon->pixmap, gftp_icon->bitmap); gdk_window_set_icon_name (window->window, gftp_version); } other_wdata = &window1; current_wdata = &window2; ui = CreateFTPWindows (window); gtk_container_add (GTK_CONTAINER (window), ui); gtk_widget_show (window); gftpui_common_about (ftp_log, NULL); gtk_timeout_add (1000, update_downloads, NULL); if (gftp_protocols[GFTP_LOCAL_NUM].init (window1.request) == 0) { gftp_setup_startup_directory (window1.request); gftp_connect (window1.request); ftp_list_files (&window1); } /* On the remote window, even though we aren't connected, draw the sort icon on that side */ sortrows (GTK_CLIST (window2.listbox), -1, &window2); init_gftp (argc, argv, window); GDK_THREADS_ENTER (); gtk_main (); GDK_THREADS_LEAVE (); return (0);}voidgftpui_show_or_hide_command (void){ intptr_t cmd_in_gui; gftp_lookup_global_option ("cmd_in_gui", &cmd_in_gui); if (cmd_in_gui) gtk_widget_show (gftpui_command_toolbar); else gtk_widget_hide (gftpui_command_toolbar);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -