[frogr] Use MIME types for checking file types in the Mac, instead of file extensions.
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Use MIME types for checking file types in the Mac, instead of file extensions.
- Date: Tue, 18 Dec 2012 16:16:31 +0000 (UTC)
commit ec7869cca6d348f02266bba8442ce8c53369426a
Author: Mario Sanchez Prada <msanchez gnome org>
Date: Mon Dec 17 09:52:40 2012 +0100
Use MIME types for checking file types in the Mac, instead of file extensions.
To have this properly working, we just need to have shared-mime-info build
and installed in the internal jhbuild we use to build it with gtk-osx.
frogr.bundle | 12 +++-
src/frogr-file-loader.c | 183 -----------------------------------------------
src/frogr-main-view.c | 23 ------
src/frogr-util.c | 42 -----------
src/frogr-util.h | 6 --
5 files changed, 10 insertions(+), 256 deletions(-)
---
diff --git a/frogr.bundle b/frogr.bundle
index 5dd1789..30f6246 100644
--- a/frogr.bundle
+++ b/frogr.bundle
@@ -41,7 +41,6 @@
${prefix}/share/locale
</translations>
- <!-- Other data to copy in, usually Glade/UI files, images, sounds files... -->
<data>
${prefix}/share/frogr
</data>
@@ -57,12 +56,21 @@
${prefix}/share/icons/Cheser
</data>
-
<!-- GSettings schemas -->
<data>
${prefix}/share/glib-2.0/schemas
</data>
+ <!-- MIME types database information -->
+ <data>
+ ${prefix}/share/mime
+ </data>
+
+ <!-- Other data to copy in, usually Glade/UI files, images, sounds files... -->
+ <data>
+ ${prefix}/share/frogr
+ </data>
+
<!-- Copy icons. -->
<data dest="${bundle}/Contents/Resources">
${project}/macosx/frogr.icns
diff --git a/src/frogr-file-loader.c b/src/frogr-file-loader.c
index 0c185ee..ac4918d 100644
--- a/src/frogr-file-loader.c
+++ b/src/frogr-file-loader.c
@@ -197,7 +197,6 @@ _load_current_file (FrogrFileLoader *self)
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
-#ifndef PLATFORM_MAC
const gchar *mime_type;
gint i;
@@ -224,7 +223,6 @@ _load_current_file (FrogrFileLoader *self)
g_object_unref (file_info);
}
-#endif
/* Asynchronously load the file if mime is valid */
if (file_info && valid_mime)
@@ -336,193 +334,13 @@ _load_current_file_cb (GObject *object,
_finish_task_and_self_destruct (self);
}
-#ifdef PLATFORM_MAC
-/* The following functions get_char() and _file_matches_pattern() are
- based in code from GTK+'s gtkfilefilter.c and fnmatch.c, licensed
- as GPL version 2 or later (Copyright (C) 1991, 1992, 1993 Free
- Software Foundation, Inc.) */
-static gunichar
-get_char (const char **str)
-{
- gunichar c = g_utf8_get_char (*str);
- *str = g_utf8_next_char (*str);
-
- return c;
-}
-
-static gboolean
-_file_matches_pattern (const char *pattern,
- const char *string,
- gboolean component_start)
-{
- const char *p = pattern, *n = string;
-
- while (*p)
- {
- const char *last_n = n;
-
- gunichar c = get_char (&p);
- gunichar nc = get_char (&n);
-
- switch (c)
- {
- case '?':
- if (nc == '\0')
- return FALSE;
- else if (nc == G_DIR_SEPARATOR)
- return FALSE;
- break;
- case '\\':
- if (nc != c)
- return FALSE;
- break;
- case '*':
- {
- const char *last_p = p;
-
- for (last_p = p, c = get_char (&p);
- c == '?' || c == '*';
- last_p = p, c = get_char (&p))
- {
- if (c == '?')
- {
- if (nc == '\0')
- return FALSE;
- else if (nc == G_DIR_SEPARATOR)
- return FALSE;
- else
- {
- last_n = n; nc = get_char (&n);
- }
- }
- }
-
- /* If the pattern ends with wildcards, we have a
- * guaranteed match unless there is a dir separator
- * in the remainder of the string.
- */
- if (c == '\0')
- {
- if (strchr (last_n, G_DIR_SEPARATOR) != NULL)
- return FALSE;
- else
- return TRUE;
- }
-
- for (p = last_p; nc != '\0';)
- {
- if ((c == '[' || nc == c) &&
- _file_matches_pattern (p, last_n, component_start))
- return TRUE;
-
- component_start = (nc == G_DIR_SEPARATOR);
- last_n = n;
- nc = get_char (&n);
- }
-
- return FALSE;
- }
-
- case '[':
- {
- /* Nonzero if the sense of the character class is inverted. */
- gboolean not;
-
- if (nc == '\0' || nc == G_DIR_SEPARATOR)
- return FALSE;
-
- not = (*p == '!' || *p == '^');
- if (not)
- ++p;
-
- c = get_char (&p);
- for (;;)
- {
- register gunichar cstart = c, cend = c;
- if (c == '\0')
- /* [ (unterminated) loses. */
- return FALSE;
-
- c = get_char (&p);
-
- if (c == '-' && *p != ']')
- {
- cend = get_char (&p);
- if (cend == '\0')
- return FALSE;
-
- c = get_char (&p);
- }
-
- if (nc >= cstart && nc <= cend)
- goto matched;
-
- if (c == ']')
- break;
- }
- if (!not)
- return FALSE;
- break;
-
- matched:;
- /* Skip the rest of the [...] that already matched. */
- while (c != ']')
- {
- if (c == '\0')
- /* [... (unterminated) loses. */
- return FALSE;
-
- c = get_char (&p);
- }
- if (not)
- return FALSE;
- }
- break;
-
- default:
- if (c != nc)
- return FALSE;
- }
-
- component_start = (nc == G_DIR_SEPARATOR);
- }
-
- if (*n == '\0')
- return TRUE;
-
- return FALSE;
-}
-#endif /* PLATFORM_MAC */
-
static gboolean
_is_video_file (GFile *file)
{
-#ifdef PLATFORM_MAC
- const gchar * const *supported_videos = NULL;
- gchar *basename = NULL;
- gint i;
-#else
GFileInfo* file_info = NULL;
GError *error = NULL;
-#endif
gboolean is_video = FALSE;
-#ifdef PLATFORM_MAC
- /* In the Mac we can't use mime types so we match against the list
- of supported file extensions for videos. */
- basename = g_file_get_basename (file);
- supported_videos = frogr_util_get_supported_videos ();
- for (i = 0; supported_videos[i]; i++)
- {
- if (_file_matches_pattern (supported_videos[i], basename, TRUE))
- {
- is_video = TRUE;
- break;
- }
- }
- g_free (basename);
-
-#else
/* Use mime types when not in the Mac */
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -539,7 +357,6 @@ _is_video_file (GFile *file)
g_warning ("Not able to read file information: %s", error->message);
g_error_free (error);
}
-#endif
return is_video;
}
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 22801f5..aec0b51 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -1375,12 +1375,7 @@ _load_pictures_dialog (FrogrMainView *self)
GtkFileFilter *video_filter;
gint i;
-#ifdef PLATFORM_MAC
- const gchar * const *supported_images;
- const gchar * const *supported_videos;
-#else
const gchar * const *supported_mimetypes;
-#endif
dialog = gtk_file_chooser_dialog_new (_("Select a Picture"),
GTK_WINDOW (self),
@@ -1394,23 +1389,6 @@ _load_pictures_dialog (FrogrMainView *self)
image_filter = gtk_file_filter_new ();
video_filter = gtk_file_filter_new ();
-#ifdef PLATFORM_MAC
- /* Workaround for Mac OSX, where GNOME VFS daemon won't be running,
- so we can't check filter by mime type (will be text/plain) */
- supported_images = frogr_util_get_supported_images ();
- for (i = 0; supported_images[i]; i++)
- {
- gtk_file_filter_add_pattern (image_filter, supported_images[i]);
- gtk_file_filter_add_pattern (all_filter, supported_images[i]);
- }
-
- supported_videos = frogr_util_get_supported_videos ();
- for (i = 0; supported_videos[i]; i++)
- {
- gtk_file_filter_add_pattern (video_filter, supported_videos[i]);
- gtk_file_filter_add_pattern (all_filter, supported_videos[i]);
- }
-#else
supported_mimetypes = frogr_util_get_supported_mimetypes ();
for (i = 0; supported_mimetypes[i]; i++)
{
@@ -1421,7 +1399,6 @@ _load_pictures_dialog (FrogrMainView *self)
gtk_file_filter_add_mime_type (all_filter, supported_mimetypes[i]);
}
-#endif
gtk_file_filter_set_name (all_filter, _("All Files"));
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all_filter);
diff --git a/src/frogr-util.c b/src/frogr-util.c
index 1222203..8d59b84 100644
--- a/src/frogr-util.c
+++ b/src/frogr-util.c
@@ -561,47 +561,6 @@ frogr_util_get_datasize_string (gulong datasize)
return result;
}
-#ifdef PLATFORM_MAC
-const gchar * const *
-frogr_util_get_supported_images (void)
-{
- static const gchar *supported_images[] = {
- "*.[jJ][pP][gG]",
- "*.[jJ][pP][eE][gG]",
- "*.[pP][nN][gG]",
- "*.[bB][mM][pP]",
- "*.[gG][iI][fF]",
- NULL
- };
-
- return supported_images;
-}
-
-const gchar * const *
-frogr_util_get_supported_videos (void)
-{
- static const gchar *supported_videos[] = {
- "*.[mM][pP]4",
- "*.[mM]4[vV]",
- "*.[mM][oO][vV]",
- "*.[qQ][tT]",
- "*.[mM][pP][eE]",
- "*.[mM][pP][eE][gG]",
- "*.[mM][pP][gG]",
- "*.[aA][vV][iI]",
- "*.[wW][mM][vV]",
- "*.[oO][gG][vV]",
- "*.[oO][gG][gG]",
- "*.[mM]2[tT][sS]",
- "*.3[gG][pP]",
- NULL
- };
-
- return supported_videos;
-}
-
-#else
-
const gchar * const *
frogr_util_get_supported_mimetypes (void)
{
@@ -628,4 +587,3 @@ frogr_util_get_supported_mimetypes (void)
return supported_mimetypes;
}
-#endif /* PLATFORM_MAC */
diff --git a/src/frogr-util.h b/src/frogr-util.h
index 7c3b841..3c553ed 100644
--- a/src/frogr-util.h
+++ b/src/frogr-util.h
@@ -47,13 +47,7 @@ GdkPixbuf *frogr_util_get_pixbuf_from_image_contents (const guchar *contents, gs
gchar *frogr_util_get_datasize_string (gulong datasize);
-#ifdef PLATFORM_MAC
-const gchar * const *frogr_util_get_supported_images (void);
-
-const gchar * const *frogr_util_get_supported_videos (void);
-#else
const gchar * const *frogr_util_get_supported_mimetypes (void);
-#endif
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]