[Xfce4-commits] <ristretto:ristretto-0.0> Improve performance when opening a lot of files (Bug #6677) - Reduce I/O. - Apply patch by Ala Luszczak <ala.luszczak at gmail.com>

Stephan Arts noreply at xfce.org
Sun Oct 23 19:28:55 CEST 2011


Updating branch refs/heads/ristretto-0.0
         to f94dfd551f71a792686b580cdfb357a5581dfc65 (commit)
       from f529ab4578e71917841cc2e1d095e3243bc06808 (commit)

commit f94dfd551f71a792686b580cdfb357a5581dfc65
Author: Stephan Arts <stephan at xfce.org>
Date:   Mon Nov 15 20:23:27 2010 +0100

    Improve performance when opening a lot of files (Bug #6677) - Reduce I/O.
     - Apply patch by Ala Luszczak <ala.luszczak at gmail.com>

 src/image.c          |   48 ++++++++++++++++++++---------------
 src/image.h          |    1 +
 src/main_window.c    |   68 ++++++++++++++++++++++++++++++++++---------------
 src/main_window.h    |    2 +
 src/picture_viewer.c |    3 ++
 5 files changed, 80 insertions(+), 42 deletions(-)

diff --git a/src/image.c b/src/image.c
index 9b3c2ce..f4f5019 100644
--- a/src/image.c
+++ b/src/image.c
@@ -261,33 +261,14 @@ RsttoImage *
 rstto_image_new (GFile *file)
 {
     RsttoImage *image = g_object_new (RSTTO_TYPE_IMAGE, NULL);
-    gchar *file_path = g_file_get_path (file);
-    ExifEntry *exif_entry = NULL;
 
     g_object_ref (file);
 
     image->priv->file = file;
-    image->priv->exif_data = exif_data_new_from_file (file_path);
+    image->priv->exif_data = NULL;
     image->priv->thumbnail = NULL;
     image->priv->pixbuf = NULL;
-
-    if (image->priv->exif_data) {
-        exif_entry = exif_data_get_entry (image->priv->exif_data, EXIF_TAG_ORIENTATION);
-    }
-    /* Check if the image has exif-data available */
-    if (exif_entry && exif_entry->data != NULL)
-    {
-        /* Get the image-orientation from EXIF data */
-        image->priv->orientation = exif_get_short (exif_entry->data, exif_data_get_byte_order (exif_entry->parent->parent));
-        if (image->priv->orientation == 0)
-            /* Default orientation */
-            image->priv->orientation = RSTTO_IMAGE_ORIENT_NONE;
-    }
-    else
-    {
-        /* Default orientation */
-        image->priv->orientation = RSTTO_IMAGE_ORIENT_NONE;
-    }
+    image->priv->orientation = RSTTO_IMAGE_ORIENT_NOT_DETERMINED;
 
     return image;
 }
@@ -554,6 +535,31 @@ rstto_image_get_size (RsttoImage *image)
 RsttoImageOrientation
 rstto_image_get_orientation (RsttoImage *image)
 {
+	if (image->priv->orientation == RSTTO_IMAGE_ORIENT_NOT_DETERMINED){
+	    gchar *file_path = g_file_get_path (image->priv->file);
+		ExifEntry *exif_entry = NULL;
+
+		image->priv->exif_data = exif_data_new_from_file (file_path);
+
+	    if (image->priv->exif_data) {
+	        exif_entry = exif_data_get_entry (image->priv->exif_data, EXIF_TAG_ORIENTATION);
+	    }
+	    /* Check if the image has exif-data available */
+	    if (exif_entry && exif_entry->data != NULL)
+	    {
+	        /* Get the image-orientation from EXIF data */
+	        image->priv->orientation = exif_get_short (exif_entry->data, exif_data_get_byte_order (exif_entry->parent->parent));
+	        if (image->priv->orientation == 0)
+	            /* Default orientation */
+	            image->priv->orientation = RSTTO_IMAGE_ORIENT_NONE;
+	    }
+	    else
+	    {
+	        /* Default orientation */
+	        image->priv->orientation = RSTTO_IMAGE_ORIENT_NONE;
+	    }
+	}
+
     return image->priv->orientation;
 }
 
diff --git a/src/image.h b/src/image.h
index a36659b..c6a8407 100644
--- a/src/image.h
+++ b/src/image.h
@@ -31,6 +31,7 @@ typedef enum
   RSTTO_IMAGE_ORIENT_90,
   RSTTO_IMAGE_ORIENT_TRANSVERSE,
   RSTTO_IMAGE_ORIENT_270,
+  RSTTO_IMAGE_ORIENT_NOT_DETERMINED,
 } RsttoImageOrientation;
 
 #define RSTTO_TYPE_IMAGE rstto_image_get_type()
diff --git a/src/main_window.c b/src/main_window.c
index c4f9bb6..8aa40ac 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -55,6 +55,9 @@
 #define ZOOM_FACTOR 1.2
 #endif
 
+#define RSTTO_RECENT_FILES_APP_NAME "ristretto"
+#define RSTTO_RECENT_FILES_GROUP "Graphics"
+
 struct _RsttoMainWindowPriv
 {
     struct {
@@ -262,6 +265,10 @@ cb_rstto_main_window_vpaned_pos_changed (GtkWidget *widget, gpointer user_data);
 static void
 cb_rstto_main_window_hpaned_pos_changed (GtkWidget *widget, gpointer user_data);
 
+gboolean
+rstto_main_window_add_file_to_recent_files (GFile *file);
+
+
 static GtkWidgetClass *parent_class = NULL;
 
 static GtkActionEntry action_entries[] =
@@ -2016,13 +2023,7 @@ cb_rstto_main_window_open_image (GtkWidget *widget, RsttoMainWindow *window)
                     gtk_dialog_run(GTK_DIALOG(dialog));
                     gtk_widget_destroy(dialog);
                 }
-                else
-                {
-                    uri = g_file_get_uri (_files_iter->data);
-                    gtk_recent_manager_add_item (window->priv->recent_manager, uri);
-                    g_free (uri);
-                    uri = NULL;
-                }
+
                 _files_iter = g_slist_next (_files_iter);
             }
         }
@@ -2039,15 +2040,6 @@ cb_rstto_main_window_open_image (GtkWidget *widget, RsttoMainWindow *window)
                 gtk_dialog_run(GTK_DIALOG(dialog));
                 gtk_widget_destroy(dialog);
             }
-            else
-            {
-
-                uri = g_file_get_uri (files->data);
-                gtk_recent_manager_add_item (window->priv->recent_manager, uri);
-                g_free (uri);
-                uri = NULL;
-
-            }
         }
 
         if (pos == -1)
@@ -2082,7 +2074,6 @@ cb_rstto_main_window_open_folder (GtkWidget *widget, RsttoMainWindow *window)
     GFileInfo *file_info = NULL;
     const gchar *filename = NULL;
     const gchar *content_type = NULL;
-    gchar *uri = NULL;
     gint pos = 0;
     GtkWidget *dialog;
     gchar *current_uri = rstto_settings_get_string_property (RSTTO_SETTINGS (window->priv->settings_manager), "current-uri");
@@ -2127,10 +2118,8 @@ cb_rstto_main_window_open_folder (GtkWidget *widget, RsttoMainWindow *window)
         if (pos == -1)
             rstto_image_list_iter_set_position (window->priv->iter, 0);
 
-        uri = g_file_get_uri (file);
-        gtk_recent_manager_add_item (window->priv->recent_manager, uri);
-        g_free (uri);
-        uri = NULL;
+        g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) rstto_main_window_add_file_to_recent_files,
+        file, NULL);
 
         rstto_settings_set_string_property (RSTTO_SETTINGS (window->priv->settings_manager),
                                             "current-uri",
@@ -2522,3 +2511,40 @@ cb_rstto_main_window_hpaned_pos_changed (GtkWidget *widget, gpointer user_data)
 
     rstto_settings_set_uint_property (RSTTO_SETTINGS (window->priv->settings_manager), "thumbnailbar-size", size);
 }
+
+gboolean
+rstto_main_window_add_file_to_recent_files (GFile *file)
+{
+    GFileInfo *file_info;
+    GtkRecentData *recent_data;
+    gchar* uri;
+    static gchar *groups[2] = { RSTTO_RECENT_FILES_GROUP , NULL };
+
+    if (file == NULL) return FALSE;
+
+    uri = g_file_get_uri (file);
+    if(uri == NULL) return FALSE;
+
+    file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+            0, NULL, NULL);
+    if (file_info == NULL) return FALSE;
+
+    recent_data = g_slice_new (GtkRecentData);
+    recent_data->display_name = NULL;
+    recent_data->description = NULL; //NULL
+    recent_data->mime_type = (gchar *) g_file_info_get_content_type (file_info);
+    recent_data->app_name = RSTTO_RECENT_FILES_APP_NAME;
+    recent_data->app_exec = g_strjoin(" ", g_get_prgname (), "%u", NULL);
+    recent_data->groups = groups;
+    recent_data->is_private = FALSE;
+
+    gtk_recent_manager_add_full (gtk_recent_manager_get_default(), uri, recent_data);
+
+    g_free (recent_data->app_exec);
+    g_free (uri);
+    g_object_unref (file_info);
+
+    g_slice_free (GtkRecentData, recent_data);
+
+    return FALSE;
+}
diff --git a/src/main_window.h b/src/main_window.h
index b618a71..8a724f5 100644
--- a/src/main_window.h
+++ b/src/main_window.h
@@ -69,6 +69,8 @@ GType      rstto_main_window_get_type();
 
 GtkWidget *rstto_main_window_new (RsttoImageList *, gboolean);
 
+gboolean   rstto_main_window_add_file_to_recent_files (GFile *);
+
 G_END_DECLS
 
 #endif /* __RISTRETTO_MAIN_WINDOW_H__ */
diff --git a/src/picture_viewer.c b/src/picture_viewer.c
index 3e6b9ce..b0c0942 100644
--- a/src/picture_viewer.c
+++ b/src/picture_viewer.c
@@ -29,6 +29,7 @@
 #include "image_list.h"
 #include "picture_viewer.h"
 #include "settings.h"
+#include "main_window.h"
 #include "marshal.h"
 
 typedef enum
@@ -1609,6 +1610,8 @@ rstto_picture_viewer_set_image (RsttoPictureViewer *viewer, RsttoImage *image)
         }
 
         rstto_image_load (viewer->priv->image, FALSE, *scale, FALSE, NULL);
+
+        g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) rstto_main_window_add_file_to_recent_files, rstto_image_get_file(viewer->priv->image), NULL);
     }
     else
     {


More information about the Xfce4-commits mailing list