[gnome-commander: 159/170] Use gio instead of gnome-vfs to open files with applications




commit c3659a0726788fc1787fd4f34ce457841c2da04d
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Tue Dec 22 23:59:44 2020 +0100

    Use gio instead of gnome-vfs to open files with applications

 src/gnome-cmd-file-list.cc    | 41 +++++++++++++++++++++--------------------
 src/gnome-cmd-file-popmenu.cc | 42 ++++++++++++++++--------------------------
 2 files changed, 37 insertions(+), 46 deletions(-)
---
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index 375782af..015e6349 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -1188,19 +1188,20 @@ static void do_mime_exec_single (gpointer *args)
 {
     g_return_if_fail (args != nullptr);
 
-    auto app = static_cast<GnomeCmdApp*> (args[0]);
+    auto gnomeCmdApp = static_cast<GnomeCmdApp*> (args[0]);
     auto path = (gchar *) args[1];
     auto dpath = (gchar *) args[2];
 
-    string cmd = gnome_cmd_app_get_command (app);
-    cmd += ' ';
-    cmd += stringify (g_shell_quote (path));
-
-    run_command_indir (cmd.c_str(), dpath, gnome_cmd_app_get_requires_terminal (app));
+    auto gnomeCmdFile = gnome_cmd_file_new(path);
+    auto gFileList = new GList();
+    g_list_append(gFileList, gnomeCmdFile->gFile);
+    g_app_info_launch (gnomeCmdFile->GetAppInfoForContentType(), gFileList, nullptr, nullptr);
 
+    g_list_free(gFileList);
+    gnome_cmd_file_unref(gnomeCmdFile);
     g_free (path);
     g_free (dpath);
-    gnome_cmd_app_free (app);
+    gnome_cmd_app_free (gnomeCmdApp);
     g_free (args);
 }
 
@@ -1243,7 +1244,6 @@ static void mime_exec_single (GnomeCmdFile *f)
     g_return_if_fail (f->info != nullptr);
 
     gpointer *args;
-    GnomeVFSMimeApplication *vfs_app;
     GnomeCmdApp *app;
 
     if (!f->info->mime_type)
@@ -1300,8 +1300,8 @@ static void mime_exec_single (GnomeCmdFile *f)
             }
     }
 
-    vfs_app = gnome_vfs_mime_get_default_application (f->info->mime_type);
-    if (!vfs_app)
+    auto gAppInfo = f->GetAppInfoForContentType();
+    if (gAppInfo == nullptr)
     {
         gchar *msg = g_strdup_printf (_("No default application found for the MIME type %s."), 
f->info->mime_type);
         gnome_cmd_show_message (nullptr, msg, "Open the \"File types and programs\" page in the Control 
Center to add one.");
@@ -1309,26 +1309,27 @@ static void mime_exec_single (GnomeCmdFile *f)
         return;
     }
 
-    app = gnome_cmd_app_new_from_vfs_app (vfs_app);
-    gnome_vfs_mime_application_free (vfs_app);
+    app = gnome_cmd_app_new_from_app_info (gAppInfo);
 
     args = g_new0 (gpointer, 3);
 
     if (f->is_local())
     {
-        args[0] = (gpointer) app;
-        args[1] = (gpointer) f->get_real_path();
-        args[2] = (gpointer) g_path_get_dirname ((gchar *) args[1]);            // set exec dir for local 
files
-        do_mime_exec_single (args);
+        auto gFileList = new GList();
+        g_list_append(gFileList, f->gFile);
+        g_app_info_launch (gAppInfo, gFileList, nullptr, nullptr);
+        g_list_free(gFileList);
     }
     else
     {
         if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
         {
-            args[0] = (gpointer) app;
-            args[1] = (gpointer) f->get_uri_str();
-            // args[2] is NULL here (don't set exec dir for remote files)
-            do_mime_exec_single (args);
+            auto gFileFromUri = g_file_new_for_uri(f->get_uri_str());
+            auto gFileList = new GList();
+            g_list_append(gFileList, gFileFromUri);
+            g_app_info_launch (gAppInfo, gFileList, nullptr, nullptr);
+            g_object_unref(gFileFromUri);
+            g_list_free(gFileList);
         }
         else
         {
diff --git a/src/gnome-cmd-file-popmenu.cc b/src/gnome-cmd-file-popmenu.cc
index 5162c90f..395f424b 100644
--- a/src/gnome-cmd-file-popmenu.cc
+++ b/src/gnome-cmd-file-popmenu.cc
@@ -79,23 +79,9 @@ static void do_mime_exec_multiple (gpointer *args)
     {
         string cmdString = gnome_cmd_app_get_command (app);
 
-        set<string> dirs;
+        DEBUG('g', "Launching \"%s\"\n", g_app_info_get_commandline(app->gAppInfo));
 
-        for (; files; files = files->next)
-        {
-            cmdString += ' ';
-            cmdString += stringify (g_shell_quote ((gchar *) files->data));
-
-            gchar *dpath = g_path_get_dirname ((gchar *) files->data);
-
-            if (dpath)
-                dirs.insert (stringify (dpath));
-        }
-
-        if (dirs.size()==1)
-            run_command_indir (cmdString.c_str(), dirs.begin()->c_str(), gnome_cmd_app_get_requires_terminal 
(app));
-        else
-            run_command_indir (cmdString.c_str(), nullptr, gnome_cmd_app_get_requires_terminal (app));
+        g_app_info_launch(app->gAppInfo, files, nullptr, nullptr);
 
         g_list_free (files);
     }
@@ -122,13 +108,15 @@ static void mime_exec_multiple (GList *files, GnomeCmdApp *app)
         auto f = static_cast<GnomeCmdFile*> (files->data);
 
         if (gnome_vfs_uri_is_local (f->get_uri()))
-            local_files = g_list_append (local_files, f->get_real_path());
+        {
+            local_files = g_list_append (local_files, f->gFile);
+        }
         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,  f->get_uri_str());
+                local_files = g_list_append (local_files,  f->gFile);
             }
             else
             {
@@ -153,7 +141,7 @@ static void mime_exec_multiple (GList *files, GnomeCmdApp *app)
 
                     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, path_str);
+                    local_files = g_list_append (local_files, f->gFile);
                 }
             }
         }
@@ -821,18 +809,20 @@ guint add_open_with_entries(GtkUIManager *ui_manager, GnomeCmdFileList *gnomeCmd
 
     // Add menu items in the "Open with" submenu
     gint ii = -1;
-    GList *vfs_apps, *tmp_list;
-    vfs_apps = tmp_list = gnome_vfs_mime_get_all_applications (gnomeCmdFile->info->mime_type);
-    for (; vfs_apps && ii < MAX_OPEN_WITH_APPS; vfs_apps = vfs_apps->next)
+    GList *gAppInfos, *tmp_list;
+    auto contentTypeString = gnomeCmdFile->GetGfileContentTypeString();
+    gAppInfos = tmp_list = g_app_info_get_all_for_type(contentTypeString);
+    g_free(contentTypeString);
+    for (; gAppInfos && ii < MAX_OPEN_WITH_APPS; gAppInfos = gAppInfos->next)
     {
-        auto vfs_app = (GnomeVFSMimeApplication *) vfs_apps->data;
+        auto gAppInfoItem = (GAppInfo *) gAppInfos->data;
 
-        if (vfs_app)
+        if (gAppInfoItem)
         {
             OpenWithData *data = g_new0 (OpenWithData, 1);
 
             data->files = files;
-            data->app = gnome_cmd_app_new_from_vfs_app (vfs_app);
+            data->app = gnome_cmd_app_new_from_app_info (gAppInfoItem);
 
             gchar* openWithAppName  = g_strdup (gnome_cmd_app_get_name (data->app));
 
@@ -868,7 +858,7 @@ guint add_open_with_entries(GtkUIManager *ui_manager, GnomeCmdFileList *gnomeCmd
     }
 
     g_free(openWithDefaultAppName);
-    gnome_vfs_mime_application_list_free (tmp_list);
+    g_list_free (tmp_list);
     return newTopMenuItems;
 }
 


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