[PATCH] save and restore custom keyboard shortcuts



---
 libnautilus-private/nautilus-file-utilities.c |   21 ++++++++++++
 libnautilus-private/nautilus-file-utilities.h |    2 +
 src/nautilus-application.c                    |   44 +++++++++++++++++++++++++
 src/nautilus-application.h                    |    3 ++
 src/nautilus-main.c                           |    2 +
 5 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index b3ccc53..755598a 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -111,6 +111,27 @@ nautilus_get_user_directory (void)
 	return user_directory;
 }
 
+/**
+ * nautilus_get_accel_map_file:
+ * 
+ * Get the path for the filename containing nautilus accelerator map.
+ * The filename need not exist.
+ *
+ * Return value: the filename path, or NULL if the home directory could not be found
+ **/
+char *
+nautilus_get_accel_map_file (void)
+{
+	const gchar *home;
+
+	home = g_get_home_dir();
+	if (home != NULL) {
+		return g_build_filename (home, ".gnome2/accels/nautilus", NULL);
+	}
+
+	return NULL;
+}
+
 typedef struct {
 	char *type;
 	char *path;
diff --git a/libnautilus-private/nautilus-file-utilities.h b/libnautilus-private/nautilus-file-utilities.h
index 245d106..53c397d 100644
--- a/libnautilus-private/nautilus-file-utilities.h
+++ b/libnautilus-private/nautilus-file-utilities.h
@@ -95,4 +95,6 @@ GFile *  nautilus_find_existing_uri_in_hierarchy     (GFile *location);
 GFile *
 nautilus_find_file_insensitive (GFile *parent, const gchar *name);
 
+char * nautilus_get_accel_map_file (void);
+
 #endif /* NAUTILUS_FILE_UTILITIES_H */
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index a3618b3..3fdeaec 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -94,6 +94,8 @@ enum
 
 #define START_STATE_CONFIG "start-state"
 
+#define NAUTILUS_ACCEL_MAP_SAVE_DELAY 30
+
 /* Keeps track of all the desktop windows. */
 static GList *nautilus_application_desktop_windows;
 
@@ -103,6 +105,9 @@ static GList *nautilus_application_window_list;
 /* Keeps track of all the object windows */
 static GList *nautilus_application_spatial_window_list;
 
+/* The saving of the accelerator map was requested  */
+static gboolean save_of_accel_map_requested = FALSE;
+
 static void     desktop_changed_callback          (gpointer                  user_data);
 static void     desktop_location_changed_callback (gpointer                  user_data);
 static void     mount_removed_callback            (GVolumeMonitor            *monitor,
@@ -663,6 +668,35 @@ message_received_cb (UniqueApp         *unique_app,
 	return res;
 }
 
+gboolean 
+nautilus_application_save_accel_map (gpointer data)
+{
+	if (save_of_accel_map_requested) {
+		char *accel_map_filename;
+	 	accel_map_filename = nautilus_get_accel_map_file ();
+	 	if (accel_map_filename) {
+	 		gtk_accel_map_save (accel_map_filename);
+	 		g_free (accel_map_filename);
+	 	}
+		save_of_accel_map_requested = FALSE;
+	}
+
+	return FALSE;
+}
+
+
+static void 
+queue_accel_map_save_callback (GtkAccelMap *object, gchar *accel_path,
+		guint accel_key, GdkModifierType accel_mods,
+		gpointer user_data)
+{
+	if (!save_of_accel_map_requested) {
+		save_of_accel_map_requested = TRUE;
+		g_timeout_add_seconds (NAUTILUS_ACCEL_MAP_SAVE_DELAY, 
+				nautilus_application_save_accel_map, NULL);
+	}
+}
+
 void
 nautilus_application_startup (NautilusApplication *application,
 			      gboolean kill_shell,
@@ -690,6 +724,8 @@ nautilus_application_startup (NautilusApplication *application,
 			
 		}
 	} else {
+		char *accel_map_filename;
+
 		/* If KDE desktop is running, then force no_desktop */
 		if (is_kdesktop_present ()) {
 			no_desktop = TRUE;
@@ -745,6 +781,14 @@ nautilus_application_startup (NautilusApplication *application,
 
 		/* Load session info if availible */
 		nautilus_application_load_session (application);
+		
+		/* load accelerator map, and register save callback */
+		accel_map_filename = nautilus_get_accel_map_file ();
+		if (accel_map_filename) {
+			gtk_accel_map_load (accel_map_filename);
+			g_free (accel_map_filename);
+		}
+		g_signal_connect (gtk_accel_map_get (), "changed", G_CALLBACK (queue_accel_map_save_callback), NULL);
 	}
 }
 
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index ed3fd33..1328e9d 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -100,4 +100,7 @@ void                 nautilus_application_close_parent_windows     (NautilusSpat
 void                 nautilus_application_close_all_spatial_windows  (void);
 void                 nautilus_application_open_desktop      (NautilusApplication *application);
 void                 nautilus_application_close_desktop     (void);
+gboolean             nautilus_application_save_accel_map    (gpointer data);
+
+
 #endif /* NAUTILUS_APPLICATION_H */
diff --git a/src/nautilus-main.c b/src/nautilus-main.c
index b9b1fd8..25bef26 100644
--- a/src/nautilus-main.c
+++ b/src/nautilus-main.c
@@ -504,6 +504,8 @@ main (int argc, char *argv[])
 	}
 
  	eel_debug_shut_down ();
+ 	
+ 	nautilus_application_save_accel_map (NULL);
 	
 	return EXIT_SUCCESS;
 }
-- 
1.5.6.3


--MP_/S0GJ+E/AJW+Dm+H9EGIzMA2--


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