[gthumb] Various importer fixes, added more debug statements
- From: Michael J. Chudobiak <mjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gthumb] Various importer fixes, added more debug statements
- Date: Mon, 15 Jun 2009 09:06:24 -0400 (EDT)
commit 1cc66a478fd0e7d2e3e86d87f023ddc1b0c94c40
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Mon Jun 15 09:05:57 2009 -0400
Various importer fixes, added more debug statements
libgthumb/gfile-utils.c | 14 ++++-
src/dlg-photo-importer.c | 121 ++++++++++++++++++++++++++++++-----
src/dlg-photo-importer.h | 1 +
src/gth-application.c | 3 +-
src/gth-browser-actions-callbacks.c | 2 +-
src/main.c | 11 ++--
6 files changed, 125 insertions(+), 27 deletions(-)
---
diff --git a/libgthumb/gfile-utils.c b/libgthumb/gfile-utils.c
index 74e9798..55e8372 100644
--- a/libgthumb/gfile-utils.c
+++ b/libgthumb/gfile-utils.c
@@ -80,7 +80,7 @@ gfile_debug (const char *cfile,
if (file == NULL)
uri = g_strdup ("(null)");
else
- uri = gfile_get_uri (file);
+ uri = g_file_get_parse_name (file);
dbg = g_strdup_printf ("%s: %s\n", msg, uri);
@@ -262,6 +262,7 @@ gfile_get_mime_type (GFile *file,
const char *value;
const char *result = NULL;
GFileInfo *info;
+ GError *error = NULL;
g_assert (file != NULL);
@@ -271,7 +272,15 @@ gfile_get_mime_type (GFile *file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE,
NULL,
- NULL);
+ &error);
+ if (error) {
+ char *utf8_path = g_file_get_parse_name (file);
+ g_warning ("Error getting mime_type for %s: %s", utf8_path, error->message);
+ g_error_free (error);
+ g_free (utf8_path);
+ return NULL;
+ }
+
if (info != NULL) {
if (fast_file_type)
value = g_file_info_get_attribute_string (info,
@@ -282,6 +291,7 @@ gfile_get_mime_type (GFile *file,
if (!value) {
char *utf8_path = g_file_get_parse_name (file);
debug (DEBUG_INFO, "%s returned a NULL mime type", utf8_path);
+ g_free (utf8_path);
return NULL;
}
diff --git a/src/dlg-photo-importer.c b/src/dlg-photo-importer.c
index 70c6bfd..a3b968e 100644
--- a/src/dlg-photo-importer.c
+++ b/src/dlg-photo-importer.c
@@ -453,15 +453,20 @@ gfile_import_dir_list_recursive (GFile *gfile,
if (error != NULL) {
gfile_warning ("Error while reading contents of directory", gfile, error);
g_error_free (error);
- }
+ } else {
+ gfile_debug (DEBUG_INFO, "Looking for folders at", gfile);
+ }
+
if (file_enum == NULL)
return dcim_dirs;
while ((info = g_file_enumerator_next_file (file_enum, NULL, NULL)) != NULL) {
GFile *child;
+ const char *name = g_file_info_get_name (info);
+ debug (DEBUG_INFO, "child name is %s", name);
- child = g_file_get_child (gfile, g_file_info_get_name (info));
+ child = g_file_get_child (gfile, name);
gfile_debug (DEBUG_INFO, "Scanning directory", child);
switch (g_file_info_get_file_type (info)) {
@@ -495,6 +500,76 @@ gfile_import_dir_list_recursive (GFile *gfile,
}
+static gboolean
+is_relevant_mime_type (GFile *gfile,
+ gboolean just_images)
+{
+ const char *mime_type;
+ char *basename;
+ char *name_ext;
+ int i;
+
+ /* For some reason, this does not always succeed. I think the gphoto2
+ backend has a mime type detection bug. */
+ mime_type = gfile_get_mime_type (gfile, FALSE);
+ if (mime_type != NULL) {
+ if (mime_type_is_image (mime_type))
+ return TRUE;
+ if (just_images)
+ return FALSE;
+ if (mime_type_is_audio (mime_type) || mime_type_is_video (mime_type))
+ return TRUE;
+ }
+
+ basename = g_file_get_basename (gfile);
+ name_ext = get_filename_extension (basename);
+ g_free (basename);
+
+ if ((name_ext == NULL) || (strcmp (name_ext, "") == 0))
+ return FALSE;
+
+ const char *image_exts[] = { "JPG", "JPEG", "PNG", "TIF", "TIFF", "GIF", "PPM", /* images */
+ "CR2", "CRW", "RAF", "DCR", "MOS", "RAW", "DNG", /* RAW images */
+ "XCF", "SRF", "ORF", "MRW", "NEF", "PEF", "ARW" }; /* RAW images */
+ for (i = 0; i < G_N_ELEMENTS (image_exts); i++) {
+ const char *ext = image_exts[i];
+ if (strncasecmp (ext, name_ext, strlen (name_ext)) == 0) {
+ g_free (name_ext);
+ return TRUE;
+ }
+ }
+
+ if (!just_images) {
+ const char *exts[] = { "AVI", "MPG", "MPEG", "ASF", /* video */
+ "AU", "WAV", "OGG", "MP3", "FLAC" }; /* audio */
+ for (i = 0; i < G_N_ELEMENTS (exts); i++) {
+ const char *ext = exts[i];
+ if (strncasecmp (ext, name_ext, strlen (name_ext)) == 0) {
+ g_free (name_ext);
+ return TRUE;
+ }
+ }
+ }
+
+ g_free (name_ext);
+ return FALSE;
+}
+
+
+static gboolean
+is_image_audio_video (GFile *gfile)
+{
+ return is_relevant_mime_type (gfile, FALSE);
+}
+
+
+static gboolean
+is_image (GFile *gfile)
+{
+ return is_relevant_mime_type (gfile, TRUE);
+}
+
+
static GList *
gfile_import_file_list_recursive (GFile *gfile,
GList *files)
@@ -512,26 +587,28 @@ gfile_import_file_list_recursive (GFile *gfile,
gfile_warning ("Error while reading contents of directory", gfile, error);
g_error_free (error);
return files;
- }
-
- files = g_list_reverse (files);
+ } else {
+ gfile_debug (DEBUG_INFO, "Reading folder", gfile);
+ }
while ((info = g_file_enumerator_next_file (file_enum, NULL, NULL)) != NULL) {
GFile *child;
- const char *mime_type;
- child = g_file_get_child (gfile, g_file_info_get_name (info));
+ const char *name = g_file_info_get_name (info);
+ debug (DEBUG_INFO, "child name is %s", name);
+ child = g_file_get_child (gfile, name);
switch (g_file_info_get_file_type (info)) {
case G_FILE_TYPE_DIRECTORY:
+ gfile_debug (DEBUG_INFO, "Found new sub-folder", child);
files = gfile_import_file_list_recursive (child, files);
break;
case G_FILE_TYPE_REGULAR:
- mime_type = gfile_get_mime_type (child, FALSE);
- if ((mime_type_is_image (mime_type) ||
- mime_type_is_video (mime_type) ||
- mime_type_is_audio (mime_type)))
+ gfile_debug (DEBUG_INFO, "Found new file", child);
+ if (is_image_audio_video (child)) {
+ gfile_debug (DEBUG_INFO, "It is importable", child);
files = g_list_prepend (files, g_file_dup (child));
+ }
break;
default:
break;
@@ -541,7 +618,6 @@ gfile_import_file_list_recursive (GFile *gfile,
g_object_unref (info);
}
- files = g_list_reverse (files);
g_object_unref (file_enum);
return files;
@@ -711,11 +787,15 @@ gfile_get_preview (DialogData *data,
theme = gtk_icon_theme_get_default ();
gfile_debug (DEBUG_INFO, "need preview for", gfile);
+ if (mime_type != NULL)
+ debug (DEBUG_INFO, "which has mime type %s", mime_type);
+ else
+ debug (DEBUG_INFO, "which has a NULL mime type - FIXME");
if (gfile == NULL)
return NULL;
- if (data->generate_previews && mime_type_is_image (mime_type)) {
+ if (data->generate_previews && is_image (gfile)) {
uri = g_file_get_uri (gfile);
pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (data->factory, uri, mime_type);
g_free (uri);
@@ -1588,6 +1668,7 @@ help_cb (GtkWidget *widget,
void
dlg_photo_importer (GthBrowser *browser,
GFile *gfile_import_from,
+ const char *uri,
gboolean dcim_dirs_only)
{
DialogData *data;
@@ -1596,6 +1677,8 @@ dlg_photo_importer (GthBrowser *browser,
char *default_path;
char *default_uri;
+ /* Use one or the other, not both */
+ g_assert (!(uri && gfile_import_from));
data = g_new0 (DialogData, 1);
data->browser = browser;
@@ -1620,9 +1703,15 @@ dlg_photo_importer (GthBrowser *browser,
data->dcim_dirs = NULL;
data->dcim_dirs_only = dcim_dirs_only;
- data->gfile_import_from = gfile_import_from;
- if (gfile_import_from)
- g_object_ref (gfile_import_from);
+
+ if (gfile_import_from) {
+ data->gfile_import_from = gfile_import_from;
+ if (gfile_import_from) {
+ g_object_ref (gfile_import_from);
+ }
+ } else if (uri) {
+ data->gfile_import_from = gfile_new (uri);
+ }
data->generate_previews = eel_gconf_get_boolean (PREF_PHOTO_IMPORT_PREVIEWS, TRUE);
diff --git a/src/dlg-photo-importer.h b/src/dlg-photo-importer.h
index 303a271..0531259 100644
--- a/src/dlg-photo-importer.h
+++ b/src/dlg-photo-importer.h
@@ -27,6 +27,7 @@
void dlg_photo_importer (GthBrowser *browser,
GFile *gfile_import_from,
+ const char *uri,
gboolean dcim_dirs_only);
#endif /* DLG_PHOTO_IMPORTER_H */
diff --git a/src/gth-application.c b/src/gth-application.c
index 8836505..e10a36b 100644
--- a/src/gth-application.c
+++ b/src/gth-application.c
@@ -166,8 +166,7 @@ impl_gth_application_import_photos (PortableServer_Servant _servant,
{
gth_browser_activate_action_file_camera_import (NULL, NULL);
- /* This is broken, because I'm not sure how to pass a gfile */
- dlg_photo_importer (NULL, NULL, TRUE);
+ dlg_photo_importer (NULL, NULL, uri, TRUE);
}
diff --git a/src/gth-browser-actions-callbacks.c b/src/gth-browser-actions-callbacks.c
index f80bd7b..c2f8b28 100644
--- a/src/gth-browser-actions-callbacks.c
+++ b/src/gth-browser-actions-callbacks.c
@@ -126,7 +126,7 @@ void
gth_browser_activate_action_file_camera_import (GtkAction *action,
GthBrowser *browser)
{
- dlg_photo_importer (browser, NULL, TRUE);
+ dlg_photo_importer (browser, NULL, NULL, TRUE);
}
diff --git a/src/main.c b/src/main.c
index 5ce3636..e9f009b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -644,12 +644,11 @@ prepare_app (void)
if (dir_gfiles)
import_dir = (GFile *) dir_gfiles->data;
-// This is broken, because I don't know how to use bonobo to pass a gfile argument.
-// FIXME
-// if (use_factory)
-// GNOME_GThumb_Application_import_photos (app, import_dir, &env);
-// else
- dlg_photo_importer (NULL, import_dir, TRUE);
+ if (use_factory)
+ /* can this be gfiled? */
+ GNOME_GThumb_Application_import_photos (app, (char *) dir_urls->data, &env);
+ else
+ dlg_photo_importer (NULL, import_dir, NULL, TRUE);
}
else if (! view_comline_catalog
&& (n_dirs == 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]