[gnome-commander] Activated execution of downloaded files again which was commented out temporarily



commit 3d5a41211ff2a40430564505a34bb13d46b4ca1c
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Wed Sep 29 23:02:26 2021 +0200

    Activated execution of downloaded files again which was commented out temporarily
    
    At the same time, migrate the retrieval of paths and URI's to GIO

 src/gnome-cmd-file-list.cc    |  10 +--
 src/gnome-cmd-file-popmenu.cc | 138 +++++++++++++++++++++++-------------------
 src/gnome-cmd-file.cc         |  10 +--
 src/gnome-cmd-xfer.cc         |  17 +++---
 src/gnome-cmd-xfer.h          |  10 +--
 5 files changed, 98 insertions(+), 87 deletions(-)
---
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index 5e7086ef..4d844992 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -1275,11 +1275,11 @@ static void on_tmp_download_response (GtkWidget *w, gint id, TmpDlData *dldata)
         GnomeCmdPlainPath path(path_str);
         auto destGFile = gnome_cmd_con_create_gfile (get_home_con (), &path);
 
-        gnome_cmd_tmp_download (sourceGFile,
-                                     destGFile,
-                                     G_FILE_COPY_OVERWRITE,
-                                     GTK_SIGNAL_FUNC (do_mime_exec_single),
-                                     dldata->args);
+        gnome_cmd_tmp_download (g_list_append (nullptr, sourceGFile),
+                                g_list_append (nullptr, destGFile),
+                                G_FILE_COPY_OVERWRITE,
+                                GTK_SIGNAL_FUNC (do_mime_exec_single),
+                                dldata->args);
     }
     else
     {
diff --git a/src/gnome-cmd-file-popmenu.cc b/src/gnome-cmd-file-popmenu.cc
index 190b587e..1a58ec8f 100644
--- a/src/gnome-cmd-file-popmenu.cc
+++ b/src/gnome-cmd-file-popmenu.cc
@@ -88,17 +88,31 @@ static void do_mime_exec_multiple (gpointer *args)
             string cmdString = gnome_cmd_app_get_command (gnomeCmdApp);
 
             set<string> dirs;
-            auto files_tmp = files;
 
-            for (; files_tmp; files_tmp = files_tmp->next)
+            for (auto files_tmp = files; files_tmp; files_tmp = files_tmp->next)
             {
-                cmdString += ' ';
-                cmdString += stringify (g_shell_quote ( g_file_get_path((GFile *) files_tmp->data)));
+                auto gFile = (GFile *) files_tmp->data;
 
-                gchar *dpath = g_path_get_dirname (g_file_get_path((GFile *) files_tmp->data));
+                if (g_file_has_uri_scheme(gFile, "file"))
+                {
+                    auto localpath = g_file_get_path(gFile);
+
+                    cmdString += ' ';
+                    cmdString += stringify (g_shell_quote (localpath));
+
+                    auto dpath = g_path_get_dirname (localpath);
+
+                    if (dpath)
+                        dirs.insert (stringify (dpath));
 
-                if (dpath)
-                    dirs.insert (stringify (dpath));
+                    g_free(localpath);
+                }
+                else
+                {
+                    auto uri = g_file_get_uri(gFile);
+                    cmdString += ' ';
+                    cmdString += stringify (g_shell_quote (uri));
+                }
             }
 
             if (dirs.size()==1)
@@ -120,72 +134,72 @@ static void mime_exec_multiple (GList *files, GnomeCmdApp *app)
     g_return_if_fail (files != nullptr);
     g_return_if_fail (app != nullptr);
 
-//  GList *src_uri_list = nullptr;
-//  GList *dest_uri_list = nullptr;
-    GList *local_files = nullptr;
-//  gboolean asked = FALSE;
-//  guint no_of_remote_files = 0;
-//  gint retid;
+    GList *srcGFileList = nullptr;
+    GList *destGFileList = nullptr;
+    GList *localGFileList = nullptr;
+    gboolean asked = FALSE;
+    guint no_of_remote_files = 0;
+    gint retid;
 
     for (; files; files = files->next)
     {
         auto gnomeCmdFile = static_cast<GnomeCmdFile*> (files->data);
+        auto scheme = g_file_get_uri_scheme (gnomeCmdFile->gFile);
+
+        if (g_strcmp0(scheme, "file") == 0)
+        {
+            localGFileList = g_list_append (localGFileList, gnomeCmdFile->gFile);
+        }
+        else
+        {
+            ++no_of_remote_files;
+            if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
+            {
+                localGFileList = g_list_append (localGFileList, gnomeCmdFile->gFile);
+            }
+            else
+            {
+                if (!asked)
+                {
+                    gchar *msg = g_strdup_printf (ngettext("%s does not know how to open remote file. Do you 
want to download the file to a temporary location and then open it?",
+                                                           "%s does not know how to open remote files. Do 
you want to download the files to a temporary location and then open them?", no_of_remote_files),
+                                                  gnome_cmd_app_get_name (app));
+                    retid = run_simple_dialog (*main_win, TRUE, GTK_MESSAGE_QUESTION, msg, "", -1, _("No"), 
_("Yes"), nullptr);
+                    asked = TRUE;
+                }
+
+                if (retid==1)
+                {
+                    gchar *path_str = get_temp_download_filepath (gnomeCmdFile->get_name());
 
-//      if (gnome_vfs_uri_is_local (gnomeCmdFile->get_uri()))
-//      {
-        local_files = g_list_append (local_files, gnomeCmdFile->gFile);
-//      }
-        // TODO: Is this needed after gio / gvfs migration?
-//      else
-//      {
-//          ++no_of_remote_files;
-//          if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
-//          {
-//              local_files = g_list_append (local_files,  gnomeCmdFile->gFile);
-//          }
-//          else
-//          {
-//              if (!asked)
-//              {
-//                  gchar *msg = g_strdup_printf (ngettext("%s does not know how to open remote file. Do you 
want to download the file to a temporary location and then open it?",
-//                                                         "%s does not know how to open remote files. Do 
you want to download the files to a temporary location and then open them?", no_of_remote_files),
-//                                                gnome_cmd_app_get_name (app));
-//                  retid = run_simple_dialog (*main_win, TRUE, GTK_MESSAGE_QUESTION, msg, "", -1, _("No"), 
_("Yes"), nullptr);
-//                  asked = TRUE;
-//              }
-//
-//              if (retid==1)
-//              {
-//                  gchar *path_str = get_temp_download_filepath (gnomeCmdFile->get_name());
-//
-//                  if (!path_str) return;
-//
-//                  GnomeVFSURI *src_uri = gnome_vfs_uri_dup (gnomeCmdFile->get_uri());
-//                  GnomeCmdPlainPath path(path_str);
-//                  GnomeVFSURI *dest_uri = gnome_cmd_con_create_uri (get_home_con (), &path);
-//
-//                  src_uri_list = g_list_append (src_uri_list, src_uri);
-//                  dest_uri_list = g_list_append (dest_uri_list, dest_uri);
-//                  local_files = g_list_append (local_files, gnomeCmdFile->gFile);
-//              }
-//          }
-//      }
+                    if (!path_str) return;
+
+                    auto srcGFile = g_file_dup (gnomeCmdFile->get_gfile());
+                    GnomeCmdPlainPath path(path_str);
+                    auto destGFile = gnome_cmd_con_create_gfile (get_home_con (), &path);
+
+                    srcGFileList = g_list_append (srcGFileList, srcGFile);
+                    destGFileList = g_list_append (destGFileList, destGFile);
+                    localGFileList = g_list_append (localGFileList, destGFile);
+                }
+            }
+        }
+        g_free(scheme);
     }
 
     g_list_free (files);
 
     gpointer *args = g_new0 (gpointer, 2);
     args[0] = app;
-    args[1] = local_files;
-
-//  if (src_uri_list)
-//      gnome_cmd_xfer_tmp_download_multiple (src_uri_list,
-//                                            dest_uri_list,
-//                                            GNOME_VFS_XFER_FOLLOW_LINKS,
-//                                            GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
-//                                            GTK_SIGNAL_FUNC (do_mime_exec_multiple),
-//                                            args);
-//  else
+    args[1] = localGFileList;
+
+    if (srcGFileList)
+        gnome_cmd_tmp_download(srcGFileList,
+                               destGFileList,
+                               G_FILE_COPY_OVERWRITE,
+                               GTK_SIGNAL_FUNC (do_mime_exec_multiple),
+                               args);
+    else
       do_mime_exec_multiple (args);
 }
 
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index 715227c6..0b03d018 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -899,11 +899,11 @@ void gnome_cmd_file_view (GnomeCmdFile *f, gint internal_viewer)
     g_printerr ("Copying to: %s\n", path_str);
     g_free (path_str);
 
-    gnome_cmd_tmp_download (srcGFile,
-                                 destGFile,
-                                 G_FILE_COPY_OVERWRITE,
-                                 GTK_SIGNAL_FUNC (on_file_downloaded_for_view),
-                                 gFile);
+    gnome_cmd_tmp_download (g_list_append (nullptr, srcGFile),
+                            g_list_append (nullptr, destGFile),
+                            G_FILE_COPY_OVERWRITE,
+                            GTK_SIGNAL_FUNC (on_file_downloaded_for_view),
+                            gFile);
 }
 
 
diff --git a/src/gnome-cmd-xfer.cc b/src/gnome-cmd-xfer.cc
index e9b201d4..00706b5d 100644
--- a/src/gnome-cmd-xfer.cc
+++ b/src/gnome-cmd-xfer.cc
@@ -855,17 +855,14 @@ gnome_cmd_link_gfiles_start (GList *srcGFileGList,
 
 
 void
-gnome_cmd_tmp_download (GFile *srcGFile,
-                             GFile *destGFile,
-                             GFileCopyFlags copyFlags,
-                             GtkSignalFunc on_completed_func,
-                             gpointer on_completed_data)
+gnome_cmd_tmp_download (GList *srcGFileList,
+                        GList *destGFileList,
+                        GFileCopyFlags copyFlags,
+                        GtkSignalFunc on_completed_func,
+                        gpointer on_completed_data)
 {
-    g_return_if_fail (srcGFile != nullptr && G_IS_FILE(srcGFile));
-    g_return_if_fail (destGFile != nullptr && G_IS_FILE(destGFile));
-
-    auto srcGFileList = g_list_append (nullptr, srcGFile);
-    auto destGFileList = g_list_append (nullptr, destGFile);
+    g_return_if_fail (srcGFileList != nullptr && srcGFileList->data != nullptr);
+    g_return_if_fail (destGFileList != nullptr && destGFileList->data != nullptr);
 
     auto xferData = create_xfer_data (copyFlags, srcGFileList, destGFileList,
                              nullptr, nullptr, nullptr, GNOME_CMD_CONFIRM_OVERWRITE_QUERY,
diff --git a/src/gnome-cmd-xfer.h b/src/gnome-cmd-xfer.h
index 40a4f2ab..23d5b45e 100644
--- a/src/gnome-cmd-xfer.h
+++ b/src/gnome-cmd-xfer.h
@@ -139,11 +139,11 @@ gnome_cmd_link_gfiles_start (GList *src_uri_list,
                            gpointer on_completed_data);
 
 void
-gnome_cmd_tmp_download (GFile *srcGFile,
-                             GFile *destGFile,
-                             GFileCopyFlags copyFlags,
-                             GtkSignalFunc on_completed_func,
-                             gpointer on_completed_data);
+gnome_cmd_tmp_download (GList *srcGFileList,
+                        GList *destGFileList,
+                        GFileCopyFlags copyFlags,
+                        GtkSignalFunc on_completed_func,
+                        gpointer on_completed_data);
 
 void
 gnome_cmd_transfer_gfiles (XferData *xferData);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]