gthumb r2481 - in trunk: . libgthumb src



Author: mjc
Date: Sat Dec 27 11:13:25 2008
New Revision: 2481
URL: http://svn.gnome.org/viewvc/gthumb?rev=2481&view=rev

Log:
2008-12-27  Michael J. Chudobiak  <mjc svn gnome org>

        * libgthumb/file-utils.c: (get_filename_extension),
        (get_temp_file_name), (get_cache_full_path),
        (get_cache_filename_from_uri):
        * libgthumb/file-utils.h:
        * libgthumb/gfile-utils.c: (gfile_get_file_mime_type):
        * libgthumb/gfile-utils.h:
        * libgthumb/pixbuf-utils.c: (_gdk_pixbuf_savev):
        * src/dlg-photo-importer.c: (valid_mime_type),
        (load_images_preview__step):
        * src/gth-window-actions-callbacks.c:
        (gth_window_activate_action_file_print):
        Use the gfile functions to determine the file extension. Return the
        extension as a char*, rather than const char*. Treat the dot before
        the extension more consistently.



Modified:
   trunk/ChangeLog
   trunk/libgthumb/file-utils.c
   trunk/libgthumb/file-utils.h
   trunk/libgthumb/gfile-utils.c
   trunk/libgthumb/gfile-utils.h
   trunk/libgthumb/pixbuf-utils.c
   trunk/src/dlg-photo-importer.c
   trunk/src/gth-window-actions-callbacks.c

Modified: trunk/libgthumb/file-utils.c
==============================================================================
--- trunk/libgthumb/file-utils.c	(original)
+++ trunk/libgthumb/file-utils.c	Sat Dec 27 11:13:25 2008
@@ -2132,7 +2132,7 @@
 }
 
 
-/* extesion */
+/* extension */
 
 
 gboolean
@@ -2143,16 +2143,17 @@
 }
 
 
-const char *
+char *
 get_filename_extension (const char *filename)
 {
-	char *last_dot;
+        GFile  *gfile;
+	char   *result;
 
-	last_dot = strrchr (filename, '.');
-	if (last_dot == NULL)
-		return NULL;
+        gfile = gfile_new (filename);
+        result = gfile_get_filename_extension (gfile);
+        g_object_unref (gfile);
 
-	return last_dot + 1;
+        return result;
 }
 
 
@@ -2220,7 +2221,7 @@
 
 	g_static_mutex_lock (&count_mutex);
 	if (ext != NULL)
-		name = g_strdup_printf ("%d%s", count++, ext);
+		name = g_strdup_printf ("%d.%s", count++, ext);
 	else
 		name = g_strdup_printf ("%d", count++);
 	g_static_mutex_unlock (&count_mutex);
@@ -2537,13 +2538,22 @@
 get_cache_full_path (const char *filename, 
 		     const char *extension)
 {
-	return g_strconcat (g_get_home_dir (),
-			    "/",
-			    RC_REMOTE_CACHE_DIR,
-			    ((filename == NULL) ? "" : "/"),
-			    filename,
-			    extension,
-			    NULL);
+	if (extension == NULL)
+                return g_strconcat (g_get_home_dir (),
+                                    "/",
+                                    RC_REMOTE_CACHE_DIR,
+                                    ((filename == NULL) ? "" : "/"),
+                                    filename,
+                                    NULL);	
+	else
+		return g_strconcat (g_get_home_dir (),
+				    "/",
+				    RC_REMOTE_CACHE_DIR,
+				    ((filename == NULL) ? "" : "/"),
+				    filename,
+				    ".",
+				    extension,
+				    NULL);
 }
 
 
@@ -2552,6 +2562,7 @@
 {
 	char *name;
 	char *path;
+	char *ext;
 	
 	if (is_local_file (uri))
 		return get_local_path_from_uri (uri);
@@ -2560,8 +2571,10 @@
 	if (name == NULL)
 		return NULL;
 
-	path = get_cache_full_path (name, NULL);
+	ext = get_filename_extension (uri);
+	path = get_cache_full_path (name, ext);
 	g_free (name);
+	g_free (ext);
 	
 	return path;	
 }

Modified: trunk/libgthumb/file-utils.h
==============================================================================
--- trunk/libgthumb/file-utils.h	(original)
+++ trunk/libgthumb/file-utils.h	Sat Dec 27 11:13:25 2008
@@ -217,7 +217,7 @@
 
 gboolean            file_extension_is             (const char       *filename,
 						   const char       *ext);
-const char *        get_filename_extension        (const char       *filename);
+char *              get_filename_extension        (const char       *filename);
 char *              remove_extension_from_path    (const char       *path);
 
 /* temp */

Modified: trunk/libgthumb/gfile-utils.c
==============================================================================
--- trunk/libgthumb/gfile-utils.c	(original)
+++ trunk/libgthumb/gfile-utils.c	Sat Dec 27 11:13:25 2008
@@ -236,7 +236,6 @@
         const char *value;
         const char *result = NULL;
         GFileInfo  *info;
-        GError     *error = NULL;
 
         g_assert (file != NULL);
 
@@ -246,7 +245,7 @@
                                   G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
                                   G_FILE_QUERY_INFO_NONE,
                                   NULL,
-                                  &error);
+                                  NULL);
         if (info != NULL) {
                 if (fast_file_type)
                         value = g_file_info_get_attribute_string (info,
@@ -276,14 +275,8 @@
                         }
                 }
 
-
-                result = get_static_string  (value);
-        } else {
-                gfile_warning ("Could not get content type", file, error);
-                g_clear_error (&error);
-        }
-
-        g_object_unref (info);
+        	g_object_unref (info);
+	}
 
         return result;
 }

Modified: trunk/libgthumb/gfile-utils.h
==============================================================================
--- trunk/libgthumb/gfile-utils.h	(original)
+++ trunk/libgthumb/gfile-utils.h	Sat Dec 27 11:13:25 2008
@@ -66,6 +66,7 @@
                                                 ...);
 
 gboolean      gfile_is_local                   (GFile      *file);
+char *        gfile_get_filename_extension     (GFile      *file);
 const char*   gfile_get_file_mime_type         (GFile      *file,
                                                 gboolean    fast_file_type);
 gboolean      gfile_image_is_jpeg              (GFile      *file);

Modified: trunk/libgthumb/pixbuf-utils.c
==============================================================================
--- trunk/libgthumb/pixbuf-utils.c	(original)
+++ trunk/libgthumb/pixbuf-utils.c	Sat Dec 27 11:13:25 2008
@@ -1204,7 +1204,6 @@
 {
 	char     *temp_backup = NULL;
 	char     *temp_dir = NULL;
-	char     *ext;
 
 	gboolean  is_overwrite;
 	gboolean  result;
@@ -1222,11 +1221,13 @@
 		if (!strcmp (local_file, original_local_file)) {
 		        temp_dir = get_temp_dir_name ();
         		if (temp_dir != NULL) {
+				char *ext;
+
 				is_overwrite = TRUE;
-				ext = g_strdup_printf (".%s",get_filename_extension (local_file));
+				ext = get_filename_extension (original_local_file);
 				temp_backup = get_temp_file_name (temp_dir, ext);
 				g_free (ext);
-				file_copy (local_file, temp_backup);
+				file_copy (original_local_file, temp_backup);
 			}
 		}
 	}

Modified: trunk/src/dlg-photo-importer.c
==============================================================================
--- trunk/src/dlg-photo-importer.c	(original)
+++ trunk/src/dlg-photo-importer.c	Sat Dec 27 11:13:25 2008
@@ -501,8 +501,8 @@
 valid_mime_type (const char *name,
 		 const char *type)
 {
-	int         i;
-	const char *name_ext;
+	int   i;
+	char *name_ext;
 
 	if ((type != NULL) && (strcmp (type, "") != 0)) {
 		const char *mime_types[] = { "image",
@@ -524,11 +524,14 @@
 				       "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)
+			if (strncasecmp (ext, name_ext, strlen (name_ext)) == 0) {
+				g_free (name_ext);
 				return TRUE;
+			}
 		}
 	}
 
+	g_free (name_ext);
 	return FALSE;
 }
 
@@ -808,6 +811,7 @@
 	const char *camera_filename;
 	char       *tmp_dir;
 	char       *tmp_filename;
+	char	   *ext;
 
 	gp_file_new (&file);
 
@@ -824,8 +828,10 @@
 	if (tmp_dir == NULL) 
 		/* should we display an error message here? */
 		return;
-	
-	tmp_filename = get_temp_file_name (tmp_dir, get_filename_extension (camera_filename));
+
+	ext = get_filename_extension (camera_filename);	
+	tmp_filename = get_temp_file_name (tmp_dir, ext);
+	g_free (ext);
 
 	if (gp_file_save (file, tmp_filename) >= 0) {
 		FileData  *tmp_file;

Modified: trunk/src/gth-window-actions-callbacks.c
==============================================================================
--- trunk/src/gth-window-actions-callbacks.c	(original)
+++ trunk/src/gth-window-actions-callbacks.c	Sat Dec 27 11:13:25 2008
@@ -220,7 +220,7 @@
 			return;
 		}
 			
-		tmp_filename = get_temp_file_name (tmp_dir, ".jpeg");
+		tmp_filename = get_temp_file_name (tmp_dir, "jpeg");
 		if (! _gdk_pixbuf_save (pixbuf,
 					tmp_filename,
 					NULL,



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