[gnome-commander] Get file content type depending on URI scheme



commit 052a012a148894539b46111f450b9a9371d7ef1f
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sun Dec 5 22:40:51 2021 +0100

    Get file content type depending on URI scheme
    
    This is needed for finding default application

 src/gnome-cmd-file-popmenu.cc |  2 +-
 src/gnome-cmd-file.cc         | 26 +++++++++++++++++++++++---
 src/gnome-cmd-file.h          |  1 +
 3 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/src/gnome-cmd-file-popmenu.cc b/src/gnome-cmd-file-popmenu.cc
index 119a0c47..24834d3d 100644
--- a/src/gnome-cmd-file-popmenu.cc
+++ b/src/gnome-cmd-file-popmenu.cc
@@ -863,7 +863,7 @@ guint add_open_with_entries(GtkUIManager *ui_manager, GnomeCmdFileList *gnomeCmd
     // Add menu items in the "Open with" submenu
     gint ii = -1;
     GList *gAppInfos, *tmp_list;
-    auto contentTypeString = gnomeCmdFile->GetGfileAttributeString(G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+    auto contentTypeString = gnomeCmdFile->GetContentType();
     gAppInfos = tmp_list = g_app_info_get_all_for_type(contentTypeString);
     g_free(contentTypeString);
     for (; gAppInfos && ii < MAX_OPEN_WITH_APPS; gAppInfos = gAppInfos->next)
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index 6a3e7ceb..ec1b45c8 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -553,8 +553,14 @@ gchar *GnomeCmdFile::get_dirname()
 
 GAppInfo *GnomeCmdFile::GetAppInfoForContentType()
 {
-    auto contentTypeString = this->GetGfileAttributeString(G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
-    auto appInfo = g_app_info_get_default_for_type (contentTypeString, false);
+    auto contentTypeString = GetContentType();
+    GAppInfo *appInfo = nullptr;
+
+    if (g_file_has_uri_scheme(this->gFile, "file"))
+        appInfo = g_app_info_get_default_for_type (contentTypeString, false);
+    else
+        appInfo = g_app_info_get_default_for_type (contentTypeString, true);
+
     g_free(contentTypeString);
 
     return appInfo;
@@ -585,10 +591,24 @@ guint64 GnomeCmdFile::GetGfileAttributeUInt64(const char *attribute)
 }
 
 
-gchar *GnomeCmdFile::GetDefaultApplicationNameString()
+gchar *GnomeCmdFile::GetContentType()
 {
     auto contentType = GetGfileAttributeString (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
 
+    if (!contentType)
+        contentType = GetGfileAttributeString(G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
+
+    return contentType;
+}
+
+
+gchar *GnomeCmdFile::GetDefaultApplicationNameString()
+{
+    auto contentType = GetContentType();
+
+    if (!contentType)
+        return nullptr;
+
     auto appInfo = g_app_info_get_default_for_type (contentType, false);
 
     g_free(contentType);
diff --git a/src/gnome-cmd-file.h b/src/gnome-cmd-file.h
index 016acff6..99f4f7de 100644
--- a/src/gnome-cmd-file.h
+++ b/src/gnome-cmd-file.h
@@ -109,6 +109,7 @@ struct GnomeCmdFile
     guint64 GetGfileAttributeUInt64(const char *attribute);
     gchar *GetGfileAttributeString(const char *attribute);
     gchar *GetDefaultApplicationNameString();
+    gchar *GetContentType();
     gchar *get_default_application_action_label(GAppInfo *gAppInfo);
     gchar *get_default_application_name(GAppInfo *gAppInfo);
     GAppInfo *GetAppInfoForContentType();


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