[nautilus] Revert "Remove gtk accel map functionality"



commit c857f6b1f96cb03e4c0e645cc676bcc03e8c5ab8
Author: Holger Berndt <hb gnome org>
Date:   Sun May 13 20:14:17 2012 +0200

    Revert "Remove gtk accel map functionality"
    
    This reverts commit b3fc292bceb64c1a4799df320bd235b314466aef.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646584

 libnautilus-private/nautilus-file-utilities.c |   21 ++++++++++
 src/nautilus-application.c                    |   51 +++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index 05859b3..16ec80e 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -115,6 +115,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 *override;
+
+	override = g_getenv ("GNOME22_USER_DIR");
+
+	if (override) {
+		return g_build_filename (override, "accels/nautilus", NULL);
+	} else {
+		return g_build_filename (g_get_home_dir (), ".gnome2/accels/nautilus", NULL);
+	}
+}
 
 typedef struct {
 	char *type;
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index d46624f..f98700f 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -84,9 +84,14 @@
 
 #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;
 
+/* 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     mount_removed_callback            (GVolumeMonitor            *monitor,
 						   GMount                    *mount,
@@ -1103,6 +1108,50 @@ init_desktop (NautilusApplication *self)
 				  self);
 }
 
+static 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);
+	}
+}
+
+static void
+init_gtk_accels (void)
+{
+	char *accel_map_filename;
+
+	/* 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);
+}
+
 static void
 nautilus_application_startup (GApplication *app)
 {
@@ -1137,6 +1186,7 @@ nautilus_application_startup (GApplication *app)
 
 	/* initialize theming */
 	init_icons_and_styles ();
+	init_gtk_accels ();
 	
 	/* initialize nautilus modules */
 	nautilus_module_setup ();
@@ -1173,6 +1223,7 @@ nautilus_application_quit_mainloop (GApplication *app)
 	DEBUG ("Quitting mainloop");
 
 	nautilus_icon_info_clear_caches ();
+ 	nautilus_application_save_accel_map (NULL);
 
 	G_APPLICATION_CLASS (nautilus_application_parent_class)->quit_mainloop (app);
 }



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