📄 fe_gtk_main.c
字号:
/* * XSitecopy, for managing remote web sites with a GNOME interface. * Copyright (C) 1999, Lee Mallabone <lee0@callnetuk.com> * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * *//* This is biggggggggggg on externs and stuff... Not all that sure that they * can be weened down either.. :\ */#include <stdio.h>#include <sys/stat.h>#include "config.h"#include "rcfile.h"#include <gnome.h>#include "protocol.h"#include "fe_gtk_main.h"#include "fe_gnome_common.h"#include "fe_gtk_changes.h"#include "fe_gtk_excludes.h"#include "fe_gtk_site_widgets.h"#include "fe_gtk_file_widgets.h"#include "fe_gtk_site_ops.h"int generate_pixmaps (void);extern struct site_t *all_sites;extern GtkWidget *site_tree, *status_bar;bool rcfile_saved = true;extern char *copypath, *rcfile;/* Global widgets */extern GtkWidget *main_area_box, *area_data;extern GtkWidget *the_tree, *popup_win;GtkWidget *error_log_list, *error_log_window;/* External widgets */extern GtkWidget *excludes_clist, *excludes_entry;/*extern GtkWidget *name_map_clist, *name_map_local_entry, *name_map_remote_entry;*/extern GtkWidget *main_app_window;/* External icons */extern GdkPixmap *closed_dir, *open_dir;extern GdkPixmap *red_file, *green_file, *orange_file;extern GdkBitmap *dir1_map, *dir2_map;extern GdkBitmap *red_file_map, *green_file_map, *orange_file_map;struct site_info *area_contents_s;struct site_t *selected_site;GtkCTreeNode *current_site_node;GtkCTreeNode *site_item, *file_item;extern int exclude_row;extern struct proto_driver ftp_driver;#ifdef USE_DAVextern struct proto_driver dav_driver;#endifGList *errors;GtkWidget *sitename_entry, *localpath_entry, *remotepath_entry;/******************************************/void color_site_node (GtkCTreeNode *node, struct site_t *site) { /* Implement this once you can auto generate code for a prefs dialog * to make it configurable. if (site->is_different) { gtk_ctree_node_set_foreground (the_tree, node, color); }*/}/* Copies selected_site's infofile to infofile.bak */void backup_infofile(void) { gchar *backup_name; int ret; if (!selected_site) { fe_status ("No site selected. Cannot backup anything."); return; } backup_name = malloc (BUFSIZ); strcpy(backup_name, selected_site->infofile); strcat (backup_name, ".bak"); DEBUG(DEBUG_GNOME, "selected infofile is %s\n", selected_site->infofile); ret = copy_a_file(selected_site->infofile, backup_name); free (backup_name); switch (ret) { case 1: fe_status ("Could not open infofile"); break; case 2: fe_status ("Could not write backup file"); break; case 0: fe_status ("The state of your files has been backed up.\nCare should be taken if restoring this state, which may be done at a later date from the backup menu."); break; default: fe_status ("Something is probably broken here."); }}void backup_rcfile (void) { gchar *rcbackup; gint ret; rcbackup = malloc (BUFSIZ); strcpy (rcbackup, rcfile); strcat (rcbackup, ".bak"); ret = copy_a_file (rcfile, rcbackup); free (rcbackup); switch (ret) { case 1: fe_status ("Could not open the rcfile. That is not good."); break; case 2: fe_status ("Could not create backup file."); break; case 0: fe_status ("The details of your sites have been backed up."); break; default: break; }}void restore_rcfile (void) { struct stat *backup_file; gchar *question, *backup_name; backup_name = malloc (BUFSIZ); strcpy(backup_name, rcfile); strcat (backup_name, ".bak"); backup_file = malloc (sizeof (struct stat)); if ( stat (backup_name, backup_file) == -1) { fe_status ("Could not find backup rcfile. Site configurations not restored."); free (backup_name); free (backup_file); return; } question = malloc (BUFSIZ); sprintf (question, "The last backup of your rcfile was modified on %s.\nAre you sure you wish to restore the site details from that date?", ctime(&(backup_file->st_ctime))); fe_gtk_question (question, (GnomeReplyCallback) restore_rc); free (question); free (backup_name); free (backup_file);}void restore_rc (gint button_number) { gint ret; gchar *rcfile_backup; if (button_number == GNOME_YES) { rcfile_backup = malloc (strlen (rcfile) + 5); strcpy(rcfile_backup, rcfile); strcat (rcfile_backup, ".bak"); ret = copy_a_file (rcfile_backup, rcfile); switch (ret) { case 1: fe_status ("Could not open a backup"); break; case 2: fe_status ("Could not write to your rcfile"); break; case 0: fe_status ("Backup restored. Currently you will need to restart XSitecopy now."); break; default: printf ("there was a problem restoring.\n"); break; } free (rcfile_backup); }}int copy_a_file (gchar *input_name, gchar *output_name) { FILE *input, *output; gchar *buffer, *backup_name; if ( (input = fopen ( input_name, "r")) == NULL) { return 1; } else if ( (output = fopen (output_name, "w")) == NULL) { return 2; } else { buffer = malloc (BUFSIZ); while (fgets(buffer, BUFSIZ, input) != NULL) { fputs (buffer, output); memset (buffer, 0, BUFSIZ); } free(buffer); fclose (input); fclose (output); return 0; }}void restore_infofile(void) { struct stat *backup_file; gchar *question, *backup_name; if (!selected_site) { fe_status ("You must select a site to restore information about."); return; } backup_name = malloc (BUFSIZ); strcpy(backup_name, selected_site->infofile); strcat (backup_name, ".bak"); backup_file = malloc (sizeof (struct stat)); DEBUG(DEBUG_GNOME, "backup is %s\n", strcat (selected_site->infofile, ".bak")); if ( stat (backup_name, backup_file) == -1) { fe_status ("Could not find backup info file. File state not restored."); free (backup_name); free (backup_file); return; } question = malloc (BUFSIZ); sprintf (question, "The last backup of your files' state was modified on %s.\nAre you sure you wish to restore the file states from that date?", ctime(&(backup_file->st_ctime))); fe_gtk_question (question, (GnomeReplyCallback) actual_restoration); free (question); free (backup_name); free (backup_file);}void actual_restoration (gint button_number) { gint ret; gchar *buffer, *backup_name; if (button_number == 0) { backup_name = malloc (BUFSIZ); strcpy(backup_name, selected_site->infofile); strcat (backup_name, ".bak"); ret = copy_a_file (backup_name, selected_site->infofile); switch (ret) { case 1: fe_status ("Could not open the backup."); break; case 2: fe_status ("Could not open the infofile."); break; case 0: fe_status ("Backup restored. Currently you will need to restart XSitecopy now.");/* site_destroy (selected_site); site_readfiles (selected_site); refresh_selected();*/ break; default: break; } free(backup_name); }}/* If mode is 0, the buttons will be save, quit, cancel. * otherwise just quit & cancel. */GtkWidget*create_quit_save_question (const char *question, int mode){ GtkWidget *quit_save_question; GtkWidget *dialog_vbox6; GtkWidget *button12; GtkWidget *button13; GtkWidget *button14; GtkWidget *dialog_action_area6; quit_save_question = gnome_message_box_new (question, GNOME_MESSAGE_BOX_INFO, NULL); gtk_object_set_data (GTK_OBJECT (quit_save_question), "quit_save_question", quit_save_question); gtk_window_set_policy (GTK_WINDOW (quit_save_question), FALSE, FALSE, FALSE); gnome_dialog_set_close (GNOME_DIALOG (quit_save_question), TRUE); dialog_vbox6 = GNOME_DIALOG (quit_save_question)->vbox; gtk_object_set_data (GTK_OBJECT (quit_save_question), "dialog_vbox6", dialog_vbox6); gtk_widget_show (dialog_vbox6); if (!mode) { gnome_dialog_append_button_with_pixmap (GNOME_DIALOG (quit_save_question), "Save then quit", GNOME_STOCK_PIXMAP_SAVE_AS); button12 = g_list_last (GNOME_DIALOG (quit_save_question)->buttons)->data; gtk_widget_ref (button12); gtk_object_set_data_full (GTK_OBJECT (quit_save_question), "button12", button12, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button12); GTK_WIDGET_SET_FLAGS (button12, GTK_CAN_DEFAULT); } gnome_dialog_append_button_with_pixmap (GNOME_DIALOG (quit_save_question), "Just quit", GNOME_STOCK_PIXMAP_EXIT); button13 = g_list_last (GNOME_DIALOG (quit_save_question)->buttons)->data; gtk_widget_ref (button13); gtk_object_set_data_full (GTK_OBJECT (quit_save_question), "button13", button13, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button13); GTK_WIDGET_SET_FLAGS (button13, GTK_CAN_DEFAULT); gnome_dialog_append_button (GNOME_DIALOG (quit_save_question), GNOME_STOCK_BUTTON_CANCEL); button14 = g_list_last (GNOME_DIALOG (quit_save_question)->buttons)->data; gtk_widget_ref (button14); gtk_object_set_data_full (GTK_OBJECT (quit_save_question), "button14", button14, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button14); GTK_WIDGET_SET_FLAGS (button14, GTK_CAN_DEFAULT); dialog_action_area6 = GNOME_DIALOG (quit_save_question)->action_area; gtk_widget_ref (dialog_action_area6); gtk_object_set_data_full (GTK_OBJECT (quit_save_question), "dialog_action_area6", dialog_action_area6, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_grab_default (button14); return quit_save_question;}void quit_please (void) { GtkWidget *qs; int button; if (!rcfile_saved) { /* if user wants question */ qs = create_quit_save_question("Some of your site definitions may not be saved.\nWhat would you like to do?", 0); button = gnome_dialog_run_and_close (GNOME_DIALOG(qs)); switch(button) { case -1: break; case 0: /* How should we handle this if it fails? */ rcfile_write (rcfile, all_sites); gtk_main_quit(); case 1: gtk_main_quit(); case 2: /* Dialog is already closed by default. */ return; default: return; } } else { qs = create_quit_save_question("Are you sure you want to quit?", 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -