changeset 378:712d3810f4e1

2003-1-27 Brian Masney <masneyb@gftp.org> * lib/gftp.h lib/misc.c src/gtk/gtkui_transfer.c src/text/textui.c - added gftp_get_transfer_action(). When a file is to be transfered and already exists, this will return the default action that should be taken. * src/text/textui.c (gftpui_ask_transfer) - implemented this function so that whenever a file exists and is to be transfered, the user will be prompted on whether or not to overwrite/skip/resume * src/text/gftp-text.c (gftp_text_ask_question) - fixups for inputing a single character
author masneyb
date Tue, 27 Jan 2004 23:48:26 +0000
parents 14da115b149b
children c9aa122a1b92
files ChangeLog lib/gftp.h lib/misc.c src/gtk/gtkui_transfer.c src/text/gftp-text.c src/text/textui.c
diffstat 6 files changed, 151 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jan 24 11:45:11 2004 +0000
+++ b/ChangeLog	Tue Jan 27 23:48:26 2004 +0000
@@ -1,3 +1,16 @@
+2003-1-27 Brian Masney <masneyb@gftp.org>
+	* lib/gftp.h lib/misc.c src/gtk/gtkui_transfer.c src/text/textui.c - 
+	added gftp_get_transfer_action(). When a file is to be transfered and
+	already exists, this will return the default action that should be
+	taken.
+
+	* src/text/textui.c (gftpui_ask_transfer) - implemented this function
+	so that whenever a file exists and is to be transfered, the user will
+	be prompted on whether or not to overwrite/skip/resume
+
+	* src/text/gftp-text.c (gftp_text_ask_question) - fixups for inputing
+	a single character
+
 2003-1-23 Brian Masney <masneyb@gftp.org>
 	* src/text/gftp-text.c src/uicommon/gftpui.c - added file transfer
 	functions to the command line.
@@ -2077,7 +2090,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.208 2004/01/24 11:45:06 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.209 2004/01/27 23:48:24 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/gftp.h	Sat Jan 24 11:45:11 2004 +0000
+++ b/lib/gftp.h	Tue Jan 27 23:48:26 2004 +0000
@@ -741,6 +741,9 @@
 
 char * gftp_descramble_password		( const char *password );
 
+int gftp_get_transfer_action 		( gftp_request * request,
+					  gftp_file * fle );
+
 /* protocols.c */
 #define GFTP_FTP_NUM				0
 #define GFTP_HTTP_NUM				1
--- a/lib/misc.c	Sat Jan 24 11:45:11 2004 +0000
+++ b/lib/misc.c	Tue Jan 27 23:48:26 2004 +0000
@@ -1316,3 +1316,23 @@
   return (newstr);
 }
 
+
+int
+gftp_get_transfer_action (gftp_request * request, gftp_file * fle)
+{
+  intptr_t overwrite_default;
+
+  gftp_lookup_request_option (request, "overwrite_default", &overwrite_default);
+
+  if (overwrite_default)
+    fle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE;
+  else if (fle->startsize == fle->size)
+    fle->transfer_action = GFTP_TRANS_ACTION_SKIP;
+  else if (fle->startsize > fle->size)
+    fle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE;
+  else
+    fle->transfer_action = GFTP_TRANS_ACTION_RESUME;
+
+  return (fle->transfer_action);
+}
+
--- a/src/gtk/gtkui_transfer.c	Sat Jan 24 11:45:11 2004 +0000
+++ b/src/gtk/gtkui_transfer.c	Tue Jan 27 23:48:26 2004 +0000
@@ -208,7 +208,6 @@
   char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL },
        tempstr[50], temp1str[50], *pos;
   GtkWidget * dialog, * tempwid, * scroll, * hbox;
-  intptr_t overwrite_default;
   gftp_file * tempfle;
   GList * templist;
   size_t len;
@@ -276,9 +275,6 @@
   gtk_widget_show (tdata->clist);
   gtk_widget_show (scroll);
 
-  gftp_lookup_request_option (tdata->fromreq, "overwrite_default",
-                              &overwrite_default);
-
   for (templist = tdata->files; templist != NULL; 
        templist = templist->next)
     {
@@ -296,25 +292,21 @@
         pos = tempfle->destfile + len + 1;
       add_data[0] = pos;
 
-      if (overwrite_default)
-        {
-          add_data[3] = _("Overwrite");
-          tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE;
-        }
-      else if (tempfle->startsize == tempfle->size)
+      gftp_get_transfer_action (tdata->fromreq, tempfle);
+      switch (tempfle->transfer_action)
         {
-          add_data[3] = _("Skip");
-          tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP;
-        }
-      else if (tempfle->startsize > tempfle->size)
-        {
-          add_data[3] = _("Overwrite");
-          tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE;
-        }
-      else
-        {
-          add_data[3] = _("Resume");
-          tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME;
+          case GFTP_TRANS_ACTION_OVERWRITE:
+            add_data[3] = _("Overwrite");
+            break;
+          case GFTP_TRANS_ACTION_SKIP:
+            add_data[3] = _("Skip");
+            break;
+          case GFTP_TRANS_ACTION_RESUME:
+            add_data[3] = _("Resume");
+            break;
+          default:
+            add_data[3] = _("Error");
+            break;
         }
 
       add_data[1] = insert_commas (tempfle->size, tempstr, sizeof (tempstr));
--- a/src/text/gftp-text.c	Sat Jan 24 11:45:11 2004 +0000
+++ b/src/text/gftp-text.c	Tue Jan 27 23:48:26 2004 +0000
@@ -120,9 +120,9 @@
 char *
 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size)
 {
+  char *pos, *termname, singlechar;
   struct termios term, oldterm;
   sigset_t sig, sigsave;
-  char *pos, *termname;
   FILE *infd;
 
   if (!echo)
@@ -151,9 +151,19 @@
 
   printf ("%s%s%s ", GFTPUI_COMMON_COLOR_BLUE, question, GFTPUI_COMMON_COLOR_DEFAULT);
 
-  if (fgets (buf, size, infd) == NULL)
-    return (NULL);
-  buf[size - 1] = '\0';
+  if (size == 1)
+    {
+      singlechar = fgetc (infd);
+      *buf = singlechar;
+    }
+  else
+    {
+      if (fgets (buf, size, infd) == NULL)
+        return (NULL);
+
+      if (size > 1)
+        buf[size - 1] = '\0';
+    }
 
   if (!echo)
     {
@@ -163,15 +173,21 @@
       sigprocmask (SIG_SETMASK, &sigsave, NULL);
     }
 
-  for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
-                                     *pos == '\n'; pos--);
-  *(pos+1) = '\0';
+  if (size > 1)
+    {
+      for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
+                                         *pos == '\n'; pos--);
+      *(pos+1) = '\0';
+
+      for (pos = buf; *pos == ' '; pos++);  
 
-  for (pos = buf; *pos == ' '; pos++);  
-  if (*pos == '\0')
-    return (NULL);
+      if (*pos == '\0')
+        return (NULL);
 
-  return (pos);
+      return (pos);
+    }
+  else
+    return (buf);
 }
 
 
--- a/src/text/textui.c	Sat Jan 24 11:45:11 2004 +0000
+++ b/src/text/textui.c	Tue Jan 27 23:48:26 2004 +0000
@@ -92,7 +92,79 @@
 void
 gftpui_ask_transfer (gftp_transfer * tdata)
 {
-  /* FIXME */
+  char buf, question[1024], srcsize[50], destsize[50], *pos, defaction;
+  int action, newaction;
+  gftp_file * tempfle;
+  GList * templist;
+
+  action = newaction = -1;
+
+  for (templist = tdata->files; templist != NULL; templist = templist->next)
+    {
+      tempfle = templist->data;
+      if (tempfle->startsize == 0 || tempfle->isdir)
+        continue;
+
+      while (action == -1)
+        {
+          insert_commas (tempfle->size, srcsize, sizeof (srcsize));
+          insert_commas (tempfle->startsize, destsize, sizeof (destsize));
+
+          if ((pos = strrchr (tempfle->file, '/')) != NULL)
+            pos++;
+          else
+            pos = tempfle->file;
+
+          gftp_get_transfer_action (tdata->fromreq, tempfle);
+          switch (tempfle->transfer_action)
+            {
+              case GFTP_TRANS_ACTION_OVERWRITE:
+                action = GFTP_TRANS_ACTION_OVERWRITE;
+                defaction = 'o';
+                break;
+              case GFTP_TRANS_ACTION_SKIP:
+                action = GFTP_TRANS_ACTION_SKIP;
+                defaction = 's';
+                break;
+              case GFTP_TRANS_ACTION_RESUME:
+                action = GFTP_TRANS_ACTION_RESUME;
+                defaction = 'r';
+                break;
+              default:
+                defaction = ' ';
+                break;
+            }
+    
+          g_snprintf (question, sizeof (question), _("%s already exists. (%s source size, %s destination size):\n(o)verwrite, (r)esume, (s)kip, (O)verwrite All, (R)esume All, (S)kip All: (%c)"), pos, srcsize, destsize, defaction);
+
+          gftp_text_ask_question (question, 1, &buf, 1);
+
+          switch (buf)
+            {
+              case 'o':
+                action = GFTP_TRANS_ACTION_OVERWRITE;
+                break;
+              case 'O':
+                action = newaction = GFTP_TRANS_ACTION_OVERWRITE;
+                break;
+              case 'r':
+                action = GFTP_TRANS_ACTION_RESUME;
+                break;
+              case 'R':
+                action = newaction = GFTP_TRANS_ACTION_RESUME;
+                break;
+              case 's':
+                action = GFTP_TRANS_ACTION_SKIP;
+                break;
+              case 'S':
+                action = newaction = GFTP_TRANS_ACTION_SKIP;
+                break;
+            }
+        }
+
+      tempfle->transfer_action = action;
+      action = newaction;
+    }
 }