changeset 350:e5ad008e7ea8

2003-1-4 Brian Masney <masneyb@gftp.org> * src/uicommon/gftpui.c src/uicommon/gftpui.h src/uicommon/gftpuicallbacks.c - when switching between ascii/binary, set the option on a global basis. Converted chdir, chmod, delete, rename, rmdir commands over to using the new command run format so that it will work in the different UIs. Added site command to the command line.
author masneyb
date Sun, 04 Jan 2004 17:31:59 +0000
parents 3fccdc9eb16f
children ae7f8b9bd2e4
files ChangeLog src/uicommon/gftpui.c src/uicommon/gftpui.h src/uicommon/gftpuicallbacks.c
diffstat 4 files changed, 153 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jan 04 17:26:50 2004 +0000
+++ b/ChangeLog	Sun Jan 04 17:31:59 2004 +0000
@@ -1,4 +1,11 @@
 2003-1-4 Brian Masney <masneyb@gftp.org>
+	* src/uicommon/gftpui.c src/uicommon/gftpui.h
+	src/uicommon/gftpuicallbacks.c - when switching between ascii/binary,
+	set the option on a global basis. Converted chdir, chmod, delete,
+	rename, rmdir commands over to using the new command run format so that
+	it will work in the different UIs. Added site command to the command
+	line.
+
 	* lib/misc.c (gftp_parse_command_line) - unified this function so that
 	it is consistent for all arguments.
 
@@ -1898,7 +1905,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.191 2004/01/04 17:26:50 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.192 2004/01/04 17:31:58 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/src/uicommon/gftpui.c	Sun Jan 04 17:26:50 2004 +0000
+++ b/src/uicommon/gftpui.c	Sun Jan 04 17:31:59 2004 +0000
@@ -135,13 +135,7 @@
 static int
 gftpui_common_cmd_ascii (void *uidata, gftp_request * request, char *command)
 {
-  if (gftpui_common_local_request != NULL)
-    gftp_set_request_option (gftpui_common_local_request, "ascii_transfers",
-                             GINT_TO_POINTER(1));
-
-  if (gftpui_common_remote_request != NULL)
-    gftp_set_request_option (gftpui_common_remote_request, "ascii_transfers",
-                             GINT_TO_POINTER(1));
+  gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1));
   return (1);
 }
 
@@ -149,13 +143,7 @@
 static int
 gftpui_common_cmd_binary (void *uidata, gftp_request * request, char *command)
 {
-  if (gftpui_common_local_request != NULL)
-    gftp_set_request_option (gftpui_common_local_request, "ascii_transfers",
-                             GINT_TO_POINTER(0));
-
-  if (gftpui_common_remote_request != NULL)
-    gftp_set_request_option (gftpui_common_remote_request, "ascii_transfers",
-                             GINT_TO_POINTER(0));
+  gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0));
   return (1);
 }
 
@@ -163,6 +151,7 @@
 static int
 gftpui_common_cmd_chmod (void *uidata, gftp_request * request, char *command)
 {
+  gftpui_callback_data * cdata;
   char *pos;
 
   if (!GFTP_IS_CONNECTED (request))
@@ -183,8 +172,16 @@
     }
   else
     {
-      if (gftp_chmod (request, pos, strtol (command, NULL, 10)) == 0)
-        gftp_delete_cache_entry (request, NULL, 0);
+      cdata = g_malloc0 (sizeof (*cdata));
+      cdata->request = request;
+      cdata->uidata = uidata;
+      cdata->input_string = command;
+      cdata->source_string = pos;
+      cdata->run_function = gftpui_common_run_chmod;
+
+      gftpui_common_run_callback_function (cdata);
+
+      g_free (cdata);
     }
 
   return (1);
@@ -194,6 +191,7 @@
 static int
 gftpui_common_cmd_rename (void *uidata, gftp_request * request, char *command)
 {
+  gftpui_callback_data * cdata;
   char *pos;
   
   if (!GFTP_IS_CONNECTED (request))
@@ -213,8 +211,16 @@
     }
   else
     {
-      if (gftp_rename_file (request, command, pos) == 0)
-        gftp_delete_cache_entry (request, NULL, 0);
+      cdata = g_malloc0 (sizeof (*cdata));
+      cdata->request = request;
+      cdata->uidata = uidata;
+      cdata->source_string = command;
+      cdata->input_string = pos;
+      cdata->run_function = gftpui_common_run_rename;
+
+      gftpui_common_run_callback_function (cdata);
+
+      g_free (cdata);
     }
 
   return (1);
@@ -224,6 +230,8 @@
 static int
 gftpui_common_cmd_delete (void *uidata, gftp_request * request, char *command)
 {
+  gftpui_callback_data * cdata;
+
   if (!GFTP_IS_CONNECTED (request))
     {
       request->logging_function (gftp_logging_error, request,
@@ -237,8 +245,15 @@
     }
   else
     {
-      if (gftp_remove_file (request, command) == 0)
-        gftp_delete_cache_entry (request, NULL, 0);
+      cdata = g_malloc0 (sizeof (*cdata));
+      cdata->request = request;
+      cdata->uidata = uidata;
+      cdata->input_string = command;
+      cdata->run_function = gftpui_common_run_delete;
+
+      gftpui_common_run_callback_function (cdata);
+
+      g_free (cdata);
     }
 
   return (1);
@@ -248,6 +263,8 @@
 static int
 gftpui_common_cmd_rmdir (void *uidata, gftp_request * request, char *command)
 {
+  gftpui_callback_data * cdata;
+
   if (!GFTP_IS_CONNECTED (request))
     {
       request->logging_function (gftp_logging_error, request,
@@ -261,8 +278,48 @@
     }
   else
     {
-      if (gftp_remove_directory (request, command) == 0)
-        gftp_delete_cache_entry (request, NULL, 0);
+      cdata = g_malloc0 (sizeof (*cdata));
+      cdata->request = request;
+      cdata->uidata = uidata;
+      cdata->input_string = command;
+      cdata->run_function = gftpui_common_run_rmdir;
+
+      gftpui_common_run_callback_function (cdata);
+
+      g_free (cdata);
+    }
+
+  return (1);
+}
+
+
+static int
+gftpui_common_cmd_site (void *uidata, gftp_request * request, char *command)
+{
+  gftpui_callback_data * cdata;
+
+  if (!GFTP_IS_CONNECTED (request))
+    {
+      request->logging_function (gftp_logging_error, request,
+                                 _("Error: Not connected to a remote site\n"));
+      return (1);
+    }
+  else if (*command == '\0')
+    {
+      request->logging_function (gftp_logging_error, request,
+                     _("usage: site <site command>\n"));
+    }
+  else
+    {
+      cdata = g_malloc0 (sizeof (*cdata));
+      cdata->request = request;
+      cdata->uidata = uidata;
+      cdata->input_string = command;
+      cdata->run_function = gftpui_common_run_site;
+
+      gftpui_common_run_callback_function (cdata);
+
+      g_free (cdata);
     }
 
   return (1);
@@ -274,7 +331,6 @@
 {
   gftpui_callback_data * cdata;
 
-
   if (!GFTP_IS_CONNECTED (request))
     {
       request->logging_function (gftp_logging_error, request,
@@ -306,6 +362,7 @@
 static int
 gftpui_common_cmd_chdir (void *uidata, gftp_request * request, char *command)
 {
+  gftpui_callback_data * cdata;
   char *tempstr, *newdir = NULL;
 
   if (!GFTP_IS_CONNECTED (request))
@@ -324,7 +381,7 @@
     {
       if (*command != '/' && request->directory != NULL)
         {
-          tempstr = g_strconcat (request->directory, "/", command, NULL);
+          tempstr = gftp_build_path (request->directory, command, NULL);
           newdir = expand_path (tempstr);
           g_free (tempstr);
         }
@@ -339,8 +396,15 @@
         }
     }
 
-  if (gftp_set_directory (request, newdir != NULL ? newdir : command) == 0)
-    gftpui_refresh (uidata);
+  cdata = g_malloc0 (sizeof (*cdata));
+  cdata->request = request;
+  cdata->uidata = uidata;
+  cdata->input_string = newdir != NULL ? newdir : command;
+  cdata->run_function = gftpui_common_run_chdir;
+
+  gftpui_common_run_callback_function (cdata);
+
+  g_free (cdata);
 
   if (newdir != NULL)
     g_free (newdir);
@@ -460,7 +524,8 @@
   while ((got = gftp_get_next_file (request, NULL, fle)) > 0 ||
          got == GFTP_ERETRYABLE)
     {
-      if (got < 0 || strcmp (fle->file, ".") == 0)
+      if (got < 0 || strcmp (fle->file, ".") == 0 ||
+          !gftp_match_filespec (fle->file, filespec))
         {
           gftp_file_destroy (fle);
           continue;
@@ -695,7 +760,7 @@
          N_("Available options: cache"), gftpui_common_clear_show_subhelp},
         {N_("close"),   3, gftpui_common_cmd_close, gftpui_common_request_remote,
          N_("Disconnects from the remote site"), NULL},
-        {N_("delete"),  1, gftpui_common_cmd_delete,    gftpui_common_request_remote,
+        {N_("delete"),  1, gftpui_common_cmd_delete, gftpui_common_request_remote,
          N_("Removes a remote file"), NULL},
 /* FIXME
         {N_("get"),     1, gftp_text_mget_file, gftpui_common_request_none,
@@ -747,6 +812,8 @@
          N_("Remove a remote directory"), NULL},
         {N_("set"),     1, gftpui_common_cmd_set, gftpui_common_request_none,
          N_("Show configuration file variables. You can also set variables by set var=val"), gftpui_common_set_show_subhelp},
+        {N_("site"),    2, gftpui_common_cmd_site, gftpui_common_request_remote,
+         N_("Run a site specific command"), NULL},
         {NULL,          0, NULL,                gftpui_common_request_none,
 	 NULL, NULL}};
 
--- a/src/uicommon/gftpui.h	Sun Jan 04 17:26:50 2004 +0000
+++ b/src/uicommon/gftpui.h	Sun Jan 04 17:31:59 2004 +0000
@@ -98,6 +98,12 @@
 
 int gftpui_common_run_chdir 		( gftpui_callback_data * cdata );
 
+int gftpui_common_run_chmod		( gftpui_callback_data * cdata );
+
+int gftpui_common_run_delete		( gftpui_callback_data * cdata );
+
+int gftpui_common_run_rmdir 		( gftpui_callback_data * cdata );
+
 /* UI Functions that must be implemented by each distinct UI */
 void gftpui_lookup_file_colors 		( gftp_file * fle,
 					  char **start_color,
--- a/src/uicommon/gftpuicallbacks.c	Sun Jan 04 17:26:50 2004 +0000
+++ b/src/uicommon/gftpuicallbacks.c	Sun Jan 04 17:31:59 2004 +0000
@@ -65,3 +65,47 @@
   return (ret);
 }
 
+
+int
+gftpui_common_run_chmod (gftpui_callback_data * cdata)
+{
+  int ret;
+
+  ret = gftp_chmod (cdata->request, cdata->source_string,
+                    strtol (cdata->input_string, NULL, 10)) == 0;
+
+  return (ret);
+}
+
+
+int
+gftpui_common_run_delete (gftpui_callback_data * cdata)
+{
+  int ret;
+
+  if (cdata->input_string != NULL)
+    {
+      ret = gftp_remove_file (cdata->request, cdata->input_string) == 0;
+    }
+  else
+    ret = 0; /* FIXME */
+
+  return (ret);
+}
+
+
+int
+gftpui_common_run_rmdir (gftpui_callback_data * cdata)
+{
+  int ret;
+
+  if (cdata->input_string != NULL)
+    {
+      ret = gftp_remove_directory (cdata->request, cdata->input_string) == 0;
+    }
+  else
+    ret = 0; /* FIXME */
+
+  return (ret);
+}
+