[gthumb] automatically select the last viewed file on startup if "Go to last visited folder or catalogue" op



commit adf94ad4ffb1187beeb4646b91978500b6e1b975
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Jul 13 01:14:10 2011 +0200

    automatically select the last viewed file on startup if  "Go to last visited folder or catalogue" option is on
    
    [bug #451883, new feature]

 data/gthumb.schemas.in   |   13 +++++++++++++
 gthumb/gth-browser.c     |    9 ++++++++-
 gthumb/gth-preferences.h |    1 +
 gthumb/main.c            |   23 +++++++++++++++++------
 4 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/data/gthumb.schemas.in b/data/gthumb.schemas.in
index 33b5475..f2d67db 100644
--- a/data/gthumb.schemas.in
+++ b/data/gthumb.schemas.in
@@ -43,6 +43,19 @@
       </schema>
 
       <schema>
+	<key>/schemas/apps/gthumb/general/startup_current_file</key>
+	<applyto>/apps/gthumb/general/startup_current_file</applyto>
+	<owner>gthumb</owner>
+	<type>string</type>
+	<default></default>
+	<locale name="C">
+	  <short></short>
+	  <long>
+	  </long>
+	</locale>
+      </schema>
+
+      <schema>
 	<key>/schemas/apps/gthumb/general/active_extensions</key>
 	<applyto>/apps/gthumb/general/active_extensions</applyto>
 	<owner>gthumb</owner>
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 17c9ff9..bb62686 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -2085,8 +2085,15 @@ _gth_browser_close_final_step (gpointer user_data)
 
 			uri = g_file_get_uri (browser->priv->location->file);
 			eel_gconf_set_path (PREF_STARTUP_LOCATION, uri);
-
 			g_free (uri);
+
+			if (browser->priv->current_file != NULL) {
+				uri = g_file_get_uri (browser->priv->current_file->file);
+				eel_gconf_set_path (PREF_STARTUP_CURRENT_FILE, uri);
+				g_free (uri);
+			}
+			else
+				eel_gconf_set_path (PREF_STARTUP_CURRENT_FILE, NULL);
 		}
 
 		if (browser->priv->default_sort_type != NULL) {
diff --git a/gthumb/gth-preferences.h b/gthumb/gth-preferences.h
index e110bf1..338827c 100644
--- a/gthumb/gth-preferences.h
+++ b/gthumb/gth-preferences.h
@@ -33,6 +33,7 @@ G_BEGIN_DECLS
 #define PREF_GO_TO_LAST_LOCATION            "/apps/gthumb/general/go_to_last_location"
 #define PREF_USE_STARTUP_LOCATION           "/apps/gthumb/general/use_startup_location"
 #define PREF_STARTUP_LOCATION               "/apps/gthumb/general/startup_location"
+#define PREF_STARTUP_CURRENT_FILE           "/apps/gthumb/general/startup_current_file"
 #define PREF_ACTIVE_EXTENSIONS              "/apps/gthumb/general/active_extensions"
 #define PREF_STORE_METADATA_IN_FILES        "/apps/gthumb/general/store_metadata_in_files"
 
diff --git a/gthumb/main.c b/gthumb/main.c
index a6e6001..1c647b4 100644
--- a/gthumb/main.c
+++ b/gthumb/main.c
@@ -31,6 +31,7 @@
 #include <clutter-gtk/clutter-gtk.h>
 #endif
 #include "eggsmclient.h"
+#include "gconf-utils.h"
 #include "glib-utils.h"
 #include "gth-browser.h"
 #include "gth-file-data.h"
@@ -345,7 +346,8 @@ unique_app_message_received_cb (UniqueApp         *unique_app,
 
 
 static void
-open_browser_window (GFile *location)
+open_browser_window (GFile *location,
+		     GFile *current_file)
 {
 #ifdef HAVE_UNIQUE
 	if (unique_app_is_running (gthumb_app)) {
@@ -370,7 +372,10 @@ open_browser_window (GFile *location)
 		window = gth_browser_new (NULL);
 		if (! StartSlideshow)
 			gtk_window_present (GTK_WINDOW (window));
-		gth_browser_load_location (GTH_BROWSER (window), location);
+		if (current_file != NULL)
+			gth_browser_go_to (GTH_BROWSER (window), location, current_file);
+		else
+			gth_browser_load_location (GTH_BROWSER (window), location);
 	}
 }
 
@@ -457,10 +462,16 @@ prepare_application (void)
 
 	if (remaining_args == NULL) { /* No location specified. */
 		GFile *location;
+		char  *current_file_uri;
+		GFile  *current_file;
 
 		location = g_file_new_for_uri (gth_pref_get_startup_location ());
-		open_browser_window (location);
+		current_file_uri = eel_gconf_get_path (PREF_STARTUP_CURRENT_FILE, NULL);
+		current_file = g_file_new_for_uri (current_file_uri);
+		open_browser_window (location, current_file);
 
+		g_object_unref (current_file);
+		g_free (current_file_uri);
 		g_object_unref (location);
 
 		return;
@@ -486,17 +497,17 @@ prepare_application (void)
 
 	location = gth_hook_invoke_get ("command-line-files", files);
 	if (location != NULL) {
-		open_browser_window (location);
+		open_browser_window (location, NULL);
 		g_object_unref (location);
 	}
 	else /* Open each file in a new window */
 		for (scan = files; scan; scan = scan->next)
-			open_browser_window ((GFile *) scan->data);
+			open_browser_window ((GFile *) scan->data, NULL);
 
 	/* Open each dir in a new window */
 
 	for (scan = dirs; scan; scan = scan->next)
-		open_browser_window ((GFile *) scan->data);
+		open_browser_window ((GFile *) scan->data, NULL);
 
 	_g_object_list_unref (dirs);
 	_g_object_list_unref (files);



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