diff src/uicommon/gftpuicallbacks.c @ 507:34a4c6ec453c

2004-7-19 Brian Masney <masneyb@gftp.org> * src/gtk/delete_dialog.c src/uicommon/gftpuicallbacks.c - use the new thread callback functions for deleting items from the GTK+ GUI
author masneyb
date Tue, 20 Jul 2004 01:23:19 +0000
parents 39e9945288ea
children e55d8b35d809
line wrap: on
line diff
--- a/src/uicommon/gftpuicallbacks.c	Mon Jul 19 23:09:23 2004 +0000
+++ b/src/uicommon/gftpuicallbacks.c	Tue Jul 20 01:23:19 2004 +0000
@@ -133,17 +133,79 @@
 }
 
 
+static void
+_gftpui_common_del_purge_cache (gpointer key, gpointer value,
+                                gpointer user_data)
+{
+  gftp_delete_cache_entry (NULL, key, 0);
+  g_free (key);
+}
+
+
+static int
+_gftpui_common_rm_list (gftpui_callback_data * cdata)
+{
+  char *tempstr, description[BUFSIZ];
+  gftp_file * tempfle;
+  GHashTable * rmhash;
+  GList * templist;
+  int success, ret;
+
+  for (templist = cdata->files;
+       templist->next != NULL;
+       templist = templist->next); 
+
+  if (cdata->request->use_cache)
+    rmhash = g_hash_table_new (string_hash_function, string_hash_compare);
+  else
+    rmhash = NULL;
+
+  ret = 1;
+  for (; templist != NULL; templist = templist->prev)
+    { 
+      tempfle = templist->data;
+
+      if (S_ISDIR (tempfle->st_mode))
+        success = gftp_remove_directory (cdata->request, tempfle->file);
+      else
+        success = gftp_remove_file (cdata->request, tempfle->file);
+
+      if (success < 0)
+        ret = success;
+      else if (rmhash != NULL)
+        {
+          gftp_generate_cache_description (cdata->request, description,
+                                           sizeof (description), 0);
+          if (g_hash_table_lookup (rmhash, description) == NULL)
+            {
+              tempstr = g_strdup (description);
+              g_hash_table_insert (rmhash, tempstr, NULL);
+            }
+        }
+
+      if (!GFTP_IS_CONNECTED (cdata->request))
+        break;
+    }
+
+  if (rmhash != NULL)
+    {
+      g_hash_table_foreach (rmhash, _gftpui_common_del_purge_cache, NULL);
+      g_hash_table_destroy (rmhash);
+    }
+
+  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);
-    }
+  if (cdata->files != NULL)
+    ret = _gftpui_common_rm_list (cdata);
   else
-    ret = 0; /* FIXME */
+    ret = gftp_remove_file (cdata->request, cdata->input_string);
 
   return (ret);
 }
@@ -154,12 +216,10 @@
 {
   int ret;
 
-  if (cdata->input_string != NULL)
-    {
-      ret = gftp_remove_directory (cdata->request, cdata->input_string);
-    }
+  if (cdata->files != NULL)
+    ret = _gftpui_common_rm_list (cdata);
   else
-    ret = 0; /* FIXME */
+    ret = gftp_remove_directory (cdata->request, cdata->input_string);
 
   return (ret);
 }