From abff579b7000224c8d0d5efb25a904ea768c2dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 20 Jun 2024 19:43:40 +0200 Subject: [PATCH] clapper-app: Fix missing media in file dialog on Windows Windows does not support mime-types file filters, so use file extensions instead --- src/bin/clapper-app/clapper-app-file-dialog.c | 17 ++++++++++++- src/bin/clapper-app/clapper-app-utils.c | 24 +++++++++++++++++++ src/bin/clapper-app/clapper-app-utils.h | 8 +++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/bin/clapper-app/clapper-app-file-dialog.c b/src/bin/clapper-app/clapper-app-file-dialog.c index 3bbf2bf6..e8da0178 100644 --- a/src/bin/clapper-app/clapper-app-file-dialog.c +++ b/src/bin/clapper-app/clapper-app-file-dialog.c @@ -80,8 +80,15 @@ _dialog_add_mime_types (GtkFileDialog *dialog, const gchar *filter_name, GtkFileFilter *filter = gtk_file_filter_new (); guint i; - for (i = 0; mime_types[i]; ++i) + /* XXX: Windows does not support mime-types file + * filters, so use file extensions instead */ + for (i = 0; mime_types[i]; ++i) { +#ifndef G_OS_WIN32 gtk_file_filter_add_mime_type (filter, mime_types[i]); +#else + gtk_file_filter_add_suffix (filter, mime_types[i]); +#endif + } gtk_file_filter_set_name (filter, filter_name); g_list_store_append (filters, filter); @@ -99,7 +106,11 @@ clapper_app_file_dialog_open_files (GtkApplication *gtk_app) GtkFileDialog *dialog = gtk_file_dialog_new (); _dialog_add_mime_types (dialog, "Media Files", +#ifndef G_OS_WIN32 clapper_app_utils_get_mime_types ()); +#else + clapper_app_utils_get_extensions ()); +#endif gtk_file_dialog_set_modal (dialog, TRUE); gtk_file_dialog_set_title (dialog, "Add Files"); @@ -118,7 +129,11 @@ clapper_app_file_dialog_open_subtitles (GtkApplication *gtk_app, ClapperMediaIte GtkFileDialog *dialog = gtk_file_dialog_new (); _dialog_add_mime_types (dialog, "Subtitles", +#ifndef G_OS_WIN32 clapper_app_utils_get_subtitles_mime_types ()); +#else + clapper_app_utils_get_subtitles_extensions ()); +#endif gtk_file_dialog_set_modal (dialog, TRUE); gtk_file_dialog_set_title (dialog, "Open Subtitles"); diff --git a/src/bin/clapper-app/clapper-app-utils.c b/src/bin/clapper-app/clapper-app-utils.c index 6816ea2c..9b85900f 100644 --- a/src/bin/clapper-app/clapper-app-utils.c +++ b/src/bin/clapper-app/clapper-app-utils.c @@ -23,6 +23,30 @@ #include "clapper-app-utils.h" #include "clapper-app-media-item-box.h" +/* Useful only on Windows */ +#ifdef G_OS_WIN32 +const gchar *const * +clapper_app_utils_get_extensions (void) +{ + static const gchar *const all_extensions[] = { + "avi", "claps", "m2ts", "mkv", "mov", + "mp4", "webm", "wmv", NULL + }; + + return all_extensions; +} + +const gchar *const * +clapper_app_utils_get_subtitles_extensions (void) +{ + static const gchar *const subs_extensions[] = { + "srt", "vtt", NULL + }; + + return subs_extensions; +} +#endif + const gchar *const * clapper_app_utils_get_mime_types (void) { diff --git a/src/bin/clapper-app/clapper-app-utils.h b/src/bin/clapper-app/clapper-app-utils.h index 4044b573..86d57356 100644 --- a/src/bin/clapper-app/clapper-app-utils.h +++ b/src/bin/clapper-app/clapper-app-utils.h @@ -26,6 +26,14 @@ G_BEGIN_DECLS typedef void (* ClapperAppUtilsIterRanks) (const gchar *feature_name, GstRank rank, gboolean from_env, gpointer user_data); +#ifdef G_OS_WIN32 +G_GNUC_INTERNAL +const gchar *const * clapper_app_utils_get_extensions (void); + +G_GNUC_INTERNAL +const gchar *const * clapper_app_utils_get_subtitles_extensions (void); +#endif + G_GNUC_INTERNAL const gchar *const * clapper_app_utils_get_mime_types (void);