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

📄 bookmarks.c

📁 一个linux下的ftp程序。它是使用文件传输协议的一系列程序的集合。
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************//*  bookmarks.c - routines for the bookmarks                                 *//*  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: bookmarks.c,v 1.40 2004/11/05 02:11:59 masneyb Exp $";static GtkWidget * bm_dialog = NULL, * edit_bookmarks_dialog = NULL;static GtkWidget * bm_hostedit, * bm_portedit, * bm_localdiredit,                 * bm_remotediredit, * bm_useredit, * bm_passedit, * tree,                 * bm_acctedit, * anon_chk, * bm_pathedit, * bm_protocol;static GHashTable * new_bookmarks_htable = NULL;static gftp_bookmarks_var * new_bookmarks = NULL;static GtkItemFactory * edit_factory;voidrun_bookmark (gpointer data){  int refresh_local;  if (window1.request->stopable || window2.request->stopable)    {      ftp_log (gftp_logging_misc, NULL,               _("%s: Please hit the stop button first to do anything else\n"),               _("Run Bookmark"));      return;    }  if (GFTP_IS_CONNECTED (current_wdata->request))    gftpui_disconnect (current_wdata);  if (gftp_parse_bookmark (current_wdata->request, other_wdata->request,                           (char *) data, &refresh_local) < 0)    return;  if (refresh_local)    gftpui_refresh (other_wdata, 0);  ftp_connect (current_wdata, current_wdata->request, 1);}static voiddoadd_bookmark (gpointer * data, gftp_dialog_data * ddata){  GtkItemFactoryEntry test = { NULL, NULL, run_bookmark, 0, MN_(NULL) };  const char *edttxt, *spos;  gftp_bookmarks_var * tempentry;  char *dpos, *proto;  edttxt = gtk_entry_get_text (GTK_ENTRY (ddata->edit));  if (*edttxt == '\0')    {      ftp_log (gftp_logging_error, NULL,	       _("Add Bookmark: You must enter a name for the bookmark\n"));      return;    }  if (g_hash_table_lookup (gftp_bookmarks_htable, edttxt) != NULL)    {      ftp_log (gftp_logging_error, NULL,	       _("Add Bookmark: Cannot add bookmark %s because that name already exists\n"), edttxt);      return;    }  tempentry = g_malloc0 (sizeof (*tempentry));  dpos = tempentry->path = g_malloc (strlen (edttxt) + 1);  for (spos = edttxt; *spos != '\0';)    {      *dpos++ = *spos++;      if (*spos == '/')        {          *dpos++ = '/';          for (; *spos == '/'; spos++);        }    }  *dpos = '\0';  edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry));  tempentry->hostname = g_strdup (edttxt);  edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry));  tempentry->port = strtol (edttxt, NULL, 10);  proto = gftp_protocols[current_wdata->request->protonum].name;  tempentry->protocol = g_strdup (proto);  edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (other_wdata->combo)->entry));  tempentry->local_dir = g_strdup (edttxt);  edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (current_wdata->combo)->entry));  tempentry->remote_dir = g_strdup (edttxt);  if ((edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry))) != NULL)    {      tempentry->user = g_strdup (edttxt);      edttxt = gtk_entry_get_text (GTK_ENTRY (passedit));      tempentry->pass = g_strdup (edttxt);      tempentry->save_password = GTK_TOGGLE_BUTTON (ddata->checkbox)->active;    }  gftp_add_bookmark (tempentry);  test.path = g_strconcat ("/Bookmarks/", tempentry->path, NULL);  gtk_item_factory_create_item (factory, &test, (gpointer) tempentry->path,				1);  g_free (test.path);  gftp_write_bookmarks_file ();}voidadd_bookmark (gpointer data){  const char *edttxt;  if (!check_status (_("Add Bookmark"), current_wdata, 0, 0, 0, 1))    return;  edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry));  if (*edttxt == '\0')    {      ftp_log (gftp_logging_error, NULL,	       _("Add Bookmark: You must enter a hostname\n"));      return;    }  MakeEditDialog (_("Add Bookmark"), _("Enter the name of the bookmark you want to add\nYou can separate items by a / to put it into a submenu\n(ex: Linux Sites/Debian)"), NULL, 1, _("Remember password"), gftp_dialog_button_create, doadd_bookmark, data, NULL, NULL);}voidbuild_bookmarks_menu (void){  GtkItemFactoryEntry test = { NULL, NULL, NULL, 0, MN_(NULL) };  gftp_bookmarks_var * tempentry;  tempentry = gftp_bookmarks->children;  while (tempentry != NULL)    {      test.path = g_strconcat ("/Bookmarks/", tempentry->path, NULL);      if (tempentry->isfolder)        {          test.item_type = "<Branch>";          test.callback = NULL;        }      else        {          test.item_type = "";          test.callback = run_bookmark;        }      gtk_item_factory_create_item (factory, &test,                                    (gpointer) tempentry->path, 1);      g_free (test.path);      if (tempentry->children != NULL)        {          tempentry = tempentry->children;          continue;        }      while (tempentry->next == NULL && tempentry->prev != NULL)        tempentry = tempentry->prev;      tempentry = tempentry->next;    }}static gftp_bookmarks_var *copy_bookmarks (gftp_bookmarks_var * bookmarks){  gftp_bookmarks_var * new_bm, * preventry, * tempentry, * sibling, * newentry,                 * tentry;  new_bm = g_malloc0 (sizeof (*new_bm));  new_bm->path = g_malloc0 (1);  new_bm->isfolder = bookmarks->isfolder;  preventry = new_bm;  tempentry = bookmarks->children;  sibling = NULL;  while (tempentry != NULL)    {      newentry = g_malloc0 (sizeof (*newentry));      newentry->isfolder = tempentry->isfolder;      newentry->save_password = tempentry->save_password;      newentry->cnode = tempentry->cnode;      if (tempentry->path)	newentry->path = g_strdup (tempentry->path);      if (tempentry->hostname)	newentry->hostname = g_strdup (tempentry->hostname);      if (tempentry->protocol)	newentry->protocol = g_strdup (tempentry->protocol);      if (tempentry->local_dir)	newentry->local_dir = g_strdup (tempentry->local_dir);      if (tempentry->remote_dir)	newentry->remote_dir = g_strdup (tempentry->remote_dir);      if (tempentry->user)	newentry->user = g_strdup (tempentry->user);      if (tempentry->pass)	newentry->pass = g_strdup (tempentry->pass);      if (tempentry->acct)	newentry->acct = g_strdup (tempentry->acct);      newentry->port = tempentry->port;      gftp_copy_local_options (&newentry->local_options_vars,                               &newentry->local_options_hash,                               &newentry->num_local_options_vars,                               tempentry->local_options_vars,                               tempentry->num_local_options_vars);      newentry->num_local_options_vars = tempentry->num_local_options_vars;      if (sibling == NULL)	{	  if (preventry->children == NULL)	    preventry->children = newentry;	  else	    {	      tentry = preventry->children;	      while (tentry->next != NULL)		tentry = tentry->next;	      tentry->next = newentry;	    }	}      else	sibling->next = newentry;      newentry->prev = preventry;      if (tempentry->children != NULL)	{	  preventry = newentry;	  sibling = NULL;	  tempentry = tempentry->children;	}      else	{	  if (tempentry->next == NULL)	    {	      sibling = NULL;	      while (tempentry->next == NULL && tempentry->prev != NULL)		{		  tempentry = tempentry->prev;		  preventry = preventry->prev;		}	      tempentry = tempentry->next;	    }	  else	    {	      sibling = newentry;	      tempentry = tempentry->next;	    }	}    }  return (new_bm);}static void_free_menu_entry (gftp_bookmarks_var * entry){  GtkWidget * tempwid;  char *tempstr;  if (entry->oldpath != NULL)    tempstr = gftp_build_path (NULL, "/Bookmarks", entry->oldpath, NULL);  else    tempstr = gftp_build_path (NULL, "/Bookmarks", entry->path, NULL);  tempwid = gtk_item_factory_get_item (factory, tempstr);  if (GTK_IS_WIDGET (tempwid))    gtk_widget_destroy (tempwid);  g_free (tempstr);}static voidbm_apply_changes (GtkWidget * widget, gpointer backup_data){  gftp_bookmarks_var * tempentry, * delentry;  if (bm_dialog != NULL)    {      gtk_widget_grab_focus (bm_dialog);      return;    }  if (gftp_bookmarks != NULL)    {      tempentry = gftp_bookmarks->children;      while (tempentry != NULL)        {          if (tempentry->children != NULL)            tempentry = tempentry->children;          else            {              while (tempentry->next == NULL && tempentry->prev != NULL)                {                  delentry = tempentry;                  tempentry = tempentry->prev;                  _free_menu_entry (delentry);                  gftp_free_bookmark (delentry, 1);                }              delentry = tempentry;              tempentry = tempentry->next;              if (tempentry != NULL)                _free_menu_entry (delentry);              gftp_free_bookmark (delentry, 1);            }        }      g_hash_table_destroy (gftp_bookmarks_htable);    }  if (backup_data)    {      gftp_bookmarks = copy_bookmarks (new_bookmarks);      gftp_bookmarks_htable = build_bookmarks_hash_table (gftp_bookmarks);    }  else    {      gftp_bookmarks = new_bookmarks;      gftp_bookmarks_htable = new_bookmarks_htable;      new_bookmarks = NULL;      new_bookmarks_htable = NULL;    }  build_bookmarks_menu ();  gftp_write_bookmarks_file ();}static voidbm_close_dialog (GtkWidget * widget, GtkWidget * dialog){  if (bm_dialog != NULL)    return;  if (new_bookmarks_htable != NULL)    {      g_hash_table_destroy (new_bookmarks_htable);      new_bookmarks_htable = NULL;    }  if (new_bookmarks != NULL)    {      gftp_bookmarks_destroy (new_bookmarks);      new_bookmarks = NULL;    }  if (edit_bookmarks_dialog != NULL)    {      gtk_widget_destroy (edit_bookmarks_dialog);      edit_bookmarks_dialog = NULL;    }}#if GTK_MAJOR_VERSION > 1 static voideditbm_action (GtkWidget * widget, gint response, gpointer user_data){  switch (response)    {      case GTK_RESPONSE_OK:        bm_apply_changes (widget, NULL);        /* no break */      default:        bm_close_dialog (NULL, widget);    }}#endifstatic voiddo_make_new (gpointer data, gftp_dialog_data * ddata){  GdkPixmap * closedir_pixmap, * opendir_pixmap;  GdkBitmap * closedir_bitmap, * opendir_bitmap;    gftp_bookmarks_var * tempentry, * newentry;  char *pos, *text[2];  const char *str;#if GTK_MAJOR_VERSION > 1  gsize bread, bwrite;#endif  gftp_get_pixmap (tree, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap);  gftp_get_pixmap (tree, "dir.xpm", &closedir_pixmap, &closedir_bitmap);  str = gtk_entry_get_text (GTK_ENTRY (ddata->edit));  newentry = g_malloc0 (sizeof (*newentry));#if GTK_MAJOR_VERSION == 1  newentry->path = g_strdup (str);  while ((pos = strchr (str, '/')) != NULL)    *pos++ = ' ';#else  if (g_utf8_validate (str, -1, NULL))    newentry->path = g_strdup (str);  else    newentry->path = g_locale_to_utf8 (str, -1, &bread, &bwrite, NULL);  while ((pos = g_utf8_strchr (str, -1, '/')) != NULL)    *pos++ = ' ';#endif  newentry->prev = new_bookmarks;  if (data)    newentry->isfolder = 1;  if (new_bookmarks->children == NULL)    new_bookmarks->children = newentry;  else

⌨️ 快捷键说明

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