[gnome-commander] Use content type from GIO instead of mime type from GnomeVFS



commit 631446d33757a769395e7c4bd7c3bdae79d212e0
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sat Jul 10 21:19:22 2021 +0200

    Use content type from GIO instead of mime type from GnomeVFS

 src/gnome-cmd-file-list.cc | 11 ++++-------
 src/gnome-cmd-file.cc      | 36 ++++++++++++++++++++++++++----------
 src/gnome-cmd-file.h       |  4 ++--
 3 files changed, 32 insertions(+), 19 deletions(-)
---
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index 11c53b5e..1bf25a2d 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -1255,19 +1255,16 @@ static void on_tmp_download_response (GtkWidget *w, gint id, TmpDlData *dldata)
 static void mime_exec_single (GnomeCmdFile *f)
 {
     g_return_if_fail (f != nullptr);
-    g_return_if_fail (f->info != nullptr);
+    g_return_if_fail (f->gFileInfo != nullptr);
 
     gpointer *args;
     GnomeCmdApp *app;
 
-    if (!f->info->mime_type)
-        return;
-
     // Check if the file is a binary executable that lacks the executable bit
 
     if (!f->is_executable())
     {
-        if (f->has_mime_type("application/x-executable") || 
f->has_mime_type("application/x-executable-binary"))
+        if (f->has_content_type("application/x-executable") || 
f->has_content_type("application/x-executable-binary"))
         {
             gchar *msg = g_strdup_printf (_("ā€œ%sā€ seems to be a binary executable file but it lacks the 
executable bit. Do you want to set it and then run the file?"), f->get_name());
             gint ret = run_simple_dialog (*main_win, FALSE, GTK_MESSAGE_QUESTION, msg,
@@ -1291,13 +1288,13 @@ static void mime_exec_single (GnomeCmdFile *f)
 
     if (f->is_executable())
     {
-        if (f->has_mime_type("application/x-executable") || 
f->has_mime_type("application/x-executable-binary"))
+        if (f->has_content_type("application/x-executable") || 
f->has_content_type("application/x-executable-binary"))
         {
             f->execute();
             return;
         }
         else
-            if (f->mime_begins_with("text/"))
+            if (f->content_type_begins_with("text/"))
             {
                 gchar *msg = g_strdup_printf (_("ā€œ%sā€ is an executable text file. Do you want to run it, or 
display its contents?"), f->get_name());
                 gint ret = run_simple_dialog (*main_win, FALSE, GTK_MESSAGE_QUESTION, msg, _("Run or 
Display"),
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index ced6eff9..0fdb3ad4 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -829,23 +829,39 @@ gboolean GnomeCmdFile::get_type_pixmap_and_mask(GdkPixmap **pixmap, GdkBitmap **
 }
 
 
-gboolean GnomeCmdFile::has_mime_type(const gchar *mime_type)
+gboolean GnomeCmdFile::has_content_type(const gchar *contentType)
 {
-    g_return_val_if_fail (info != nullptr, FALSE);
-    g_return_val_if_fail (info->mime_type != nullptr, FALSE);
-    g_return_val_if_fail (mime_type != nullptr, FALSE);
+    g_return_val_if_fail (contentType != nullptr, FALSE);
 
-    return strcmp (info->mime_type, mime_type) == 0;
+    auto actualContentType = GetGfileAttributeString(G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+
+    if (!actualContentType)
+    {
+        return false;
+    }
+
+    auto compareValue = strcmp (actualContentType, contentType);
+    g_free(actualContentType);
+
+    return compareValue == 0;
 }
 
 
-gboolean GnomeCmdFile::mime_begins_with(const gchar *mime_type_start)
+gboolean GnomeCmdFile::content_type_begins_with(const gchar *contentTypeStart)
 {
-    g_return_val_if_fail (info != nullptr, FALSE);
-    g_return_val_if_fail (info->mime_type != nullptr, FALSE);
-    g_return_val_if_fail (mime_type_start != nullptr, FALSE);
+    g_return_val_if_fail (contentTypeStart != nullptr, FALSE);
+
+    auto actualContentType = GetGfileAttributeString(G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+
+    if (!actualContentType)
+    {
+        return false;
+    }
+
+    auto compareValue = strncmp (actualContentType, contentTypeStart, strlen(contentTypeStart));
+    g_free(actualContentType);
 
-    return strncmp (info->mime_type, mime_type_start, strlen(mime_type_start)) == 0;
+    return compareValue == 0;
 }
 
 
diff --git a/src/gnome-cmd-file.h b/src/gnome-cmd-file.h
index e14b52d1..af0a0a2b 100644
--- a/src/gnome-cmd-file.h
+++ b/src/gnome-cmd-file.h
@@ -82,8 +82,8 @@ struct GnomeCmdFile
     guint64 calc_tree_size (gulong *count);
     const gchar *get_tree_size_as_str();
     const gchar *get_perm();
-    gboolean has_mime_type(const gchar *mime_type);
-    gboolean mime_begins_with(const gchar *mime_type_start);
+    gboolean has_content_type(const gchar *contentType);
+    gboolean content_type_begins_with(const gchar *contentTypeStart);
 
     GnomeCmdDir *get_parent_dir();
 


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