⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fe_gtk_main.c

📁 站点映像程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	 button = gnome_dialog_run_and_close (GNOME_DIALOG(qs));	 switch(button) {	 case -1:		break;	 case 0:		gtk_main_quit();	 case 1:		return;		break;	 default:	 }  }}gint exit_handler (GtkWidget *widget, GdkEvent *event, gpointer data) {   return (TRUE);}void open_new_request (void) {  filename_request (OPENNEW);}/* Reads the filename from the GtkFileSelection named passed to it, and takes  * appropriate action depending upon the filename. * * Success: the global variable all_sites now contains the sites held within * the filename selected in the FileSelection. The main ctree is also rebuilt. */void open_newrc (GtkWidget *ok, GtkFileSelection *fileb) {  struct site_t *new_sites, *old_sites;  gchar *old_rcfile, *new_rcfile;  gchar *tmp;  gint new_status;  struct stat *stat_tmp;  if ( (new_rcfile = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fileb))) == NULL)    return;  stat_tmp = malloc (sizeof (struct stat));    if (stat((const char *) new_rcfile, stat_tmp) != 0) {    fe_status ("File does not exist!!");    free (stat_tmp);    return;  }  if (! S_ISREG(stat_tmp->st_mode)) {    fe_status ("You must select an actual sitecopy configuration file, (rcfile).");    free (stat_tmp);    return;  }  DEBUG(DEBUG_GNOME, "new rcfile is %s.\n", new_rcfile);  old_rcfile = strdup (rcfile);  rcfile = new_rcfile;  DEBUG(DEBUG_GNOME, "About to parse new rcfile...\n");  new_status = rcfile_read(&new_sites);  switch (new_status) {  case RC_OPENFILE:    fe_status ("Could not open file");    return;  case RC_DIROPEN:    fe_status ("Could not open directory.");    return;  case RC_PERMS:    fe_status ("Configuration file is not valid:\nPermissions are insecure.");    return;  case 0:    DEBUG(DEBUG_GNOME, "New rcfile successfully loaded into memory.\n");    break;  case RC_CORRUPT:    fe_status ("Not a valid sitecopy configuration file.\n");    rcfile = old_rcfile;    free (new_rcfile);    return;  }  if (new_sites == NULL) {    fe_status ("Creation of new sites failed - not a valid sitecopy configuration file?");    /* Free up some memory */    return;  }  old_sites = all_sites;  all_sites = new_sites;  free (old_sites);  gtk_clist_clear (GTK_CLIST (the_tree));  fill_tree_from_all_sites(the_tree);}void saveas_request (void) {  filename_request (SAVEAS);}void save_sites_as (GtkWidget *ok, GtkFileSelection *fileb) {  gchar *file_to_saveas;    file_to_saveas = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fileb));  DEBUG(DEBUG_GNOME, "saving as file: %s\n", file_to_saveas);  if (rcfile_write (file_to_saveas, all_sites) != 0) {    fe_status ("There was a problem saving your sites.");  } else {    fe_status ("Site definitions saved.");  }  gtk_widget_destroy (GTK_WIDGET (fileb));}void filename_request (gint mode_num) {  GtkWidget *filebox;  if (mode_num == OPENNEW) {    filebox = gtk_file_selection_new ("Choose a new sitecopy rcfile to load.");  } else if (mode_num == SAVEAS) {    filebox = gtk_file_selection_new ("Save your site definitions to a file.");  } else {    fe_status ("error with dialog creation.");  }  gtk_signal_connect_object (GTK_OBJECT (filebox), "destroy",			     GTK_SIGNAL_FUNC (gtk_widget_destroy), 			     GTK_OBJECT (filebox));  gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filebox)->cancel_button), "clicked",			     GTK_SIGNAL_FUNC (gtk_widget_destroy), 			     GTK_OBJECT (filebox));  if (mode_num == OPENNEW) {    gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filebox)->ok_button),			"clicked", GTK_SIGNAL_FUNC (open_newrc), filebox);  } else if (mode_num == SAVEAS) {    gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filebox)->ok_button),			"clicked", GTK_SIGNAL_FUNC (save_sites_as), filebox);  } else {    fe_status ("there was an error");  }  gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filebox)->ok_button), "clicked",			     GTK_SIGNAL_FUNC (gtk_widget_destroy), 			     GTK_OBJECT (filebox));  gtk_widget_show (filebox);}int make_defaults (struct site_t *a_site) {   a_site->server = (char *) malloc (140);   strcpy (a_site->server, "new_server_name");   a_site->username = (char *) malloc (40);   strcpy (a_site->username, "your_username");   a_site->password = (char *) malloc (40);   strcpy (a_site->password, "password");   a_site->url = (char *) malloc (250);   strcpy (a_site->url, "http://localhost/");   a_site->nodelete = TRUE;   a_site->nooverwrite = FALSE;   a_site->checkmoved = TRUE;   a_site->ftp_pasv_mode = TRUE;   a_site->files = NULL;   a_site->files_tail = NULL;   a_site->renames = NULL;   a_site->excludes = NULL;   a_site->numascii = 0;   a_site->protocol = siteproto_ftp;   a_site->driver = &ftp_driver;   a_site->port = 0;   a_site->perms = sitep_ignore;   a_site->symlinks = sitesym_ignore;   a_site->infofile = malloc (260);   strcpy (a_site->infofile, copypath);   /* Didn't think we'd have to set these, but now I think we do. */   a_site->numnew = 0;   a_site->numchanged = 0;   a_site->numdeleted = 0;   a_site->nummoved = 0;   a_site->numunchanged = 0;   return 1;}void add_site (GtkButton *apply_button, gpointer user_data) {   int ret;   /* popup because site_readfiles() usually takes bloody ages. */   extern GtkWidget *popup_win;   struct site_t *site_to_add;   GtkCTreeNode *site_im_adding;   gchar *name, *path, *tmppath, *remotepath, *tmp, *node_label[1];   struct ctree_attachment *extra_info;   struct create_site_widget_set *widgets;   /* A couple of global variables used to find what has been selected with    * respect to the wizard's option menus. These wouldn't be necessary if    * the (option)menu API didn't suck so bad.    */   extern gchar *new_proto, *new_perms, *new_sym;   DEBUG(DEBUG_GNOME, "started add_site.\n");   widgets = (struct create_site_widget_set *) user_data;      name = gtk_entry_get_text (GTK_ENTRY (widgets->name));   if (name == NULL) {      fe_status ("You must supply a name for the site.");      return;   }   if (strlen (name) < 2) {      fe_status ("You must supply a name for the site.");      return;   }   DEBUG(DEBUG_GNOME, "Hi! My name is %s.\n", name);   if (strstr (name, " ") != NULL) {     fe_status ("The site's friendly name must contain no spaces.");     return;   }   path = gnome_file_entry_get_full_path (GNOME_FILE_ENTRY (widgets->local_choice), 1);   if (path == NULL) {      fe_status ("You must provide a local path for the site.");      return;   }   DEBUG(DEBUG_GNOME, "local path is %s.\n", path);   tmppath = gtk_entry_get_text (GTK_ENTRY (widgets->remotedir_choice));   if (tmppath == NULL) {      fe_status ("You must provide a remote directory for the site.");      return;   }   DEBUG(DEBUG_GNOME, "remote path is %s.\n", tmppath);   /* Create a site with the correct defaults */   site_to_add = malloc (sizeof (struct site_t));   site_to_add->name = (char *) strdup (name);   make_defaults(site_to_add);   /* Sort out the remote directory */   site_to_add->remote_root_user = malloc (strlen(tmppath)+1);   strcpy (site_to_add->remote_root_user, tmppath);      if (*tmppath == '~') {      site_to_add->remote_isrel = TRUE;   } else if (*tmppath == '/') {      site_to_add->remote_isrel = FALSE;   } else {      fe_status ("The remote directory must begin with either a '/' or '~/'.");      return;   }      /* Sort out the local directory */   if (*path == '~') {     site_to_add->local_isrel = TRUE;   } else if (*path == '/') {     site_to_add->local_isrel = FALSE;   } else {      fe_status ("The local directory must begin with either a '/' or '~/'.");      return;   }   site_to_add->local_root_user = (char *) malloc (strlen(path) + 1);   strcpy (site_to_add->local_root_user, path);   strcat (site_to_add->infofile, name);   DEBUG(DEBUG_GNOME, "infofile is %s\n", site_to_add->infofile);   /* server/host name */   tmp = gtk_entry_get_text (GTK_ENTRY (widgets->hostname_choice));   if (tmp && (strlen(tmp)>2) ) {      /* Now we know exactly how much mem to use, we can free the       * arbitrary amount alloc'd in make_defaults() */     free (site_to_add->server);     site_to_add->server = (char *) malloc (strlen(tmp) + 1);     strcpy (site_to_add->server, tmp);   }   #ifdef USE_DAV   /* Protocol */   if (strcmp (new_proto, "webdav") == 0) {     site_to_add->protocol = siteproto_http;     site_to_add->driver = &dav_driver;   }     #endif /* USE_DAV */   /* User name */   tmp = gtk_entry_get_text (GTK_ENTRY (widgets->username_choice));   if (tmp && (strlen(tmp)>1) ) {      free (site_to_add->username);     site_to_add->username = (char *) malloc (strlen(tmp) + 1);     strcpy (site_to_add->username, tmp);   }      /* Password */   tmp = gtk_entry_get_text (GTK_ENTRY (widgets->password_choice));   if (tmp && (strlen(tmp)>2) ) {      free (site_to_add->password);     site_to_add->password = (char *) malloc (strlen(tmp) + 1);     strcpy (site_to_add->password, tmp);   }   /* URL */   tmp = gtk_entry_get_text (GTK_ENTRY (widgets->url_choice));   if (tmp && (strlen(tmp)>2) ) {      free (site_to_add->url);     site_to_add->url = (char *) malloc (strlen(tmp) + 1);     strcpy (site_to_add->url, tmp);   }   /* 'update attributes' */   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widgets->checkdelete_choice)))     site_to_add->nodelete = FALSE;   if (!GTK_TOGGLE_BUTTON (widgets->checkmove_choice)->active)     site_to_add->checkmoved = FALSE;   if (!GTK_TOGGLE_BUTTON (widgets->passiveftp_choice)->active)     site_to_add->ftp_pasv_mode = FALSE;   if (GTK_TOGGLE_BUTTON (widgets->deletefirst_choice)->active)     site_to_add->nooverwrite = TRUE;      /* Permissions */   if (strcmp (new_perms, "ignore") == 0) {     site_to_add->perms = sitep_ignore;   } else if (strcmp (new_perms, "exec") == 0) {     site_to_add->perms = sitep_exec;   } else if (strcmp (new_perms, "all") == 0) {     site_to_add->perms = sitep_all;   }   /* Sym links */   if (strcmp (new_sym, "ignore") == 0) {     site_to_add->symlinks = sitesym_ignore;   } else if (strcmp (new_sym, "follow") == 0) {     site_to_add->symlinks = sitesym_follow;   } else if (strcmp (new_sym, "maintain") == 0) {     site_to_add->symlinks = sitesym_maintain;   }   /* We need to make sure we're not adding a pile of poo to the sites list. */      ret = verifysite_gnome (site_to_add);   DEBUG(DEBUG_GNOME, "verify site produced code %d on the new site.\n", ret);      /* Tag this site onto the start of the sites list */   site_to_add->next = all_sites;   all_sites = site_to_add;      /* Add the entry to the ctree */   tmp = malloc (strlen(site_to_add->name) +		 strlen(site_to_add->local_root_user) + 7);   sprintf (tmp, "%s  (%s)", site_to_add->name, site_to_add->local_root);   node_label[0] = tmp;   site_im_adding = gtk_ctree_insert_node (GTK_CTREE (the_tree), NULL, NULL, node_label,					   0, NULL, NULL, NULL, NULL, false, false);   DEBUG(DEBUG_GNOME, "added node, now freeing memory and reading file information.\n");   free (tmp);   /* For some highly irritating reason this never worked even when i was      creating the dialog properly.   gtk_widget_show_all (popup_win);   while (gtk_events_pending() > 0)   gtk_main_iteration();*/   site_readfiles (site_to_add);      /* Create the file entries */   populate_site_node (site_im_adding, site_to_add);   gtk_ctree_sort_node (GTK_CTREE (the_tree), GTK_CTREE_NODE (site_im_adding));   /* Add the pointer to the site */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -