[nautilus-actions] Rename three GConf preference keys
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Rename three GConf preference keys
- Date: Sat, 26 Sep 2009 22:49:26 +0000 (UTC)
commit 02c404b8f08ff1eaaac4477d0f78ebaab71381e4
Author: pierre <pierre vfedora10 virtuals pwi>
Date: Wed Sep 23 14:07:26 2009 +0200
Rename three GConf preference keys
Some GConf preference keys were misnamed since 1.11.1 :
- iconditions-command-chooser,
- iconditions-legend-dialog,
- iconditions-folder-uri.
These are now migrated. Unfortunately, the migration code
will have to stay inline for some time.
ChangeLog | 10 +++
data/nautilus-actions.schemas.in | 10 ++--
src/nact/base-iprefs.c | 136 +++++++++++++++++++++++++++++++++----
src/nact/base-iprefs.h | 13 +++-
src/nact/nact-icommand-tab.c | 22 ++++--
src/nact/nact-main-statusbar.h | 4 +
6 files changed, 166 insertions(+), 29 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f60cdde..d313392 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-09-23 Pierre Wieser <pwieser trychlos org>
+
+ * data/nautilus-actions.schemas.in: Migrate misnamed keys.
+
+ * src/nact/base-iprefs.c:
+ * src/nact/base-iprefs.h (base_iprefs_migrate_key): New function.
+
+ * src/nact/nact-icommand-tab.c
+ (nact_icommand_tab_initial_load_toplevel): Migrate misnamed keys.
+
2009-09-22 Pierre Wieser <pwieser trychlos org>
* configure.ac: Add a comment about GtkActivatable.
diff --git a/data/nautilus-actions.schemas.in b/data/nautilus-actions.schemas.in
index 79cf694..6382798 100644
--- a/data/nautilus-actions.schemas.in
+++ b/data/nautilus-actions.schemas.in
@@ -240,30 +240,30 @@ All schemes used by Nautilus can be used here.</long>
</schema>
<schema>
- <key>/schemas/apps/nautilus-actions/preferences/iconditions-command-chooser</key>
+ <key>/schemas/apps/nautilus-actions/preferences/icommand-command-chooser</key>
<owner>nautilus-actions</owner>
<type>list</type>
<list_type>int</list_type>
<locale name="C">
<short>Position and size of the command chooser window</short>
- <long>Position and size of the command chooser window in the Conditions tab ; default is set by the window manager</long>
+ <long>Position and size of the command chooser window in the Command tab ; default is set by the window manager</long>
</locale>
<default>[]</default>
</schema>
<schema>
- <key>/schemas/apps/nautilus-actions/preferences/iconditions-folder-uri</key>
+ <key>/schemas/apps/nautilus-actions/preferences/icommand-folder-uri</key>
<owner>nautilus-actions</owner>
<type>string</type>
<locale name="C">
<short>Last selected folder</short>
- <long>Last folder selected when browsing for a command in the Conditions tab</long>
+ <long>Last folder selected when browsing for a command in the Command tab</long>
</locale>
<default>/bin</default>
</schema>
<schema>
- <key>/schemas/apps/nautilus-actions/preferences/iconditions-legend-dialog</key>
+ <key>/schemas/apps/nautilus-actions/preferences/icommand-legend-dialog</key>
<owner>nautilus-actions</owner>
<type>list</type>
<list_type>int</list_type>
diff --git a/src/nact/base-iprefs.c b/src/nact/base-iprefs.c
index 8835284..b49b144 100644
--- a/src/nact/base-iprefs.c
+++ b/src/nact/base-iprefs.c
@@ -33,6 +33,7 @@
#include <config.h>
#endif
+#include <common/na-gconf-keys-schemas.h>
#include <common/na-gconf-utils.h>
#include <common/na-iprefs.h>
@@ -44,25 +45,31 @@ struct BaseIPrefsInterfacePrivate {
GConfClient *client;
};
-static GType register_type( void );
-static void interface_base_init( BaseIPrefsInterface *klass );
-static void interface_base_finalize( BaseIPrefsInterface *klass );
+#define BASE_IPREFS_SCHEMAS_PATH NAUTILUS_ACTIONS_GCONF_SCHEMASDIR NA_GCONF_PREFS_PATH
-static gchar *v_iprefs_get_window_id( BaseWindow *window );
+static GType register_type( void );
+static void interface_base_init( BaseIPrefsInterface *klass );
+static void interface_base_finalize( BaseIPrefsInterface *klass );
-static gboolean read_bool( BaseWindow *window, const gchar *name );
-static gint read_int( BaseWindow *window, const gchar *name );
-static GSList *read_int_list( BaseWindow *window, const gchar *key );
-static gchar *read_str( BaseWindow *window, const gchar *key );
+static gchar *v_iprefs_get_window_id( BaseWindow *window );
-static void write_bool( BaseWindow *window, const gchar *name, gboolean value );
-static void write_int( BaseWindow *window, const gchar *name, gint value );
-static void write_int_list( BaseWindow *window, const gchar *key, GSList *list );
-static void write_str( BaseWindow *window, const gchar *key, const gchar *text );
+static GConfValue *get_value( GConfClient *client, const gchar *path, const gchar *entry );
+static void set_value( GConfClient *client, const gchar *path, const gchar *entry, GConfValue *value );
+static gboolean remove_entry( GConfClient *client, const gchar *path, const gchar *entry );
-static void int_list_to_position( BaseWindow *window, GSList *list, gint *x, gint *y, gint *width, gint *height );
-static GSList *position_to_int_list( BaseWindow *window, gint x, gint y, gint width, gint height );
-static void free_int_list( GSList *list );
+static gboolean read_bool( BaseWindow *window, const gchar *name );
+static gint read_int( BaseWindow *window, const gchar *name );
+static GSList *read_int_list( BaseWindow *window, const gchar *key );
+static gchar *read_str( BaseWindow *window, const gchar *key );
+
+static void write_bool( BaseWindow *window, const gchar *name, gboolean value );
+static void write_int( BaseWindow *window, const gchar *name, gint value );
+static void write_int_list( BaseWindow *window, const gchar *key, GSList *list );
+static void write_str( BaseWindow *window, const gchar *key, const gchar *text );
+
+static void int_list_to_position( BaseWindow *window, GSList *list, gint *x, gint *y, gint *width, gint *height );
+static GSList *position_to_int_list( BaseWindow *window, gint x, gint y, gint width, gint height );
+static void free_int_list( GSList *list );
GType
base_iprefs_get_type( void )
@@ -138,6 +145,36 @@ interface_base_finalize( BaseIPrefsInterface *klass )
}
/**
+ * base_iprefs_migrate_key:
+ * @window: this #BaseWindow-derived window.
+ * @old_key: the old preference entry.
+ * @new_key: the new preference entry.
+ *
+ * Migrates the content of an entry from an obsoleted key to a new one.
+ * Removes the old key, along with the schema associated to it,
+ * considering that the version which asks for this migration has
+ * installed a schema corresponding to the new key.
+ */
+void
+base_iprefs_migrate_key( BaseWindow *window, const gchar *old_key, const gchar *new_key )
+{
+ static const gchar *thisfn = "base_iprefs_migrate_key";
+ GConfValue *value;
+
+ g_debug( "%s: window=%p, old_key=%s, new_key=%s", thisfn, ( void * ) window, old_key, new_key );
+
+ value = get_value( BASE_IPREFS_GET_INTERFACE( window )->private->client, NA_GCONF_PREFS_PATH, old_key );
+
+ if( value ){
+ set_value( BASE_IPREFS_GET_INTERFACE( window )->private->client, NA_GCONF_PREFS_PATH, new_key, value );
+ gconf_value_free( value );
+ }
+
+ remove_entry( BASE_IPREFS_GET_INTERFACE( window )->private->client, NA_GCONF_PREFS_PATH, old_key );
+ remove_entry( BASE_IPREFS_GET_INTERFACE( window )->private->client, BASE_IPREFS_SCHEMAS_PATH, old_key );
+}
+
+/**
* base_iprefs_position_window:
* @window: this #BaseWindow-derived window.
*
@@ -303,6 +340,75 @@ v_iprefs_get_window_id( BaseWindow *window )
return( NULL );
}
+static GConfValue *
+get_value( GConfClient *client, const gchar *path, const gchar *entry )
+{
+ static const gchar *thisfn = "base_iprefs_get_value";
+ GError *error = NULL;
+ gchar *fullpath;
+ GConfValue *value;
+
+ fullpath = g_strdup_printf( "%s/%s", path, entry );
+
+ value = gconf_client_get_without_default( client, fullpath, &error );
+
+ if( error ){
+ g_warning( "%s: key=%s, %s", thisfn, fullpath, error->message );
+ g_error_free( error );
+ if( value ){
+ gconf_value_free( value );
+ value = NULL;
+ }
+ }
+
+ g_free( fullpath );
+
+ return( value );
+}
+
+static void
+set_value( GConfClient *client, const gchar *path, const gchar *entry, GConfValue *value )
+{
+ static const gchar *thisfn = "base_iprefs_set_value";
+ GError *error = NULL;
+ gchar *fullpath;
+
+ g_return_if_fail( value );
+
+ fullpath = g_strdup_printf( "%s/%s", path, entry );
+
+ gconf_client_set( client, fullpath, value, &error );
+
+ if( error ){
+ g_warning( "%s: key=%s, %s", thisfn, fullpath, error->message );
+ g_error_free( error );
+ }
+
+ g_free( fullpath );
+}
+
+static gboolean
+remove_entry( GConfClient *client, const gchar *path, const gchar *entry )
+{
+ static const gchar *thisfn = "base_iprefs_remove_entry";
+ GError *error = NULL;
+ gchar *fullpath;
+ gboolean ret;
+
+ fullpath = g_strdup_printf( "%s/%s", path, entry );
+
+ ret = gconf_client_unset( client, fullpath, &error );
+
+ if( error ){
+ g_warning( "%s: key=%s, %s", thisfn, fullpath, error->message );
+ g_error_free( error );
+ }
+
+ g_free( fullpath );
+
+ return( ret );
+}
+
static gboolean
read_bool( BaseWindow *window, const gchar *name )
{
diff --git a/src/nact/base-iprefs.h b/src/nact/base-iprefs.h
index 0e9758e..5e7c457 100644
--- a/src/nact/base-iprefs.h
+++ b/src/nact/base-iprefs.h
@@ -31,11 +31,18 @@
#ifndef __BASE_IPREFS_H__
#define __BASE_IPREFS_H__
-/*
- * BaseIPrefs interface definition.
+/**
+ * SECTION: base_iprefs
+ * @short_description: #BaseIPrefs interface definition.
+ * @include: nact/base-iprefs.h
*
* This interface may be implemented by all dialogs which wish take
* benefit of preferences management.
+ *
+ * As a side effect, it cooperates with #BaseWindow to automatically
+ * save, then restore, size and position of window on the display.
+ * This is made possible by identifying each window by an id specific
+ * to this function.
*/
#include "base-window.h"
@@ -62,6 +69,8 @@ typedef struct {
GType base_iprefs_get_type( void );
+void base_iprefs_migrate_key( BaseWindow *window, const gchar *old_key, const gchar *new_key );
+
void base_iprefs_position_window( BaseWindow *window );
void base_iprefs_position_named_window( BaseWindow *window, GtkWindow *toplevel, const gchar *name );
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index 34ada8f..e74106e 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -62,8 +62,8 @@ struct NactICommandTabInterfacePrivate {
/* a data set in the LegendDialog GObject
*/
-#define LEGEND_DIALOG_IS_VISIBLE "nact-icommand-tab-legend-dialog-visible"
-#define PROP_ICOMMAND_TAB_STATUS_CONTEXT "nact-icommand-tab-status-context"
+#define ICOMMAND_TAB_LEGEND_VISIBLE "nact-icommand-tab-legend-dialog-visible"
+#define ICOMMAND_TAB_STATUSBAR_CONTEXT "nact-icommand-tab-statusbar-context"
static GType register_type( void );
static void interface_base_init( NactICommandTabInterface *klass );
@@ -162,6 +162,10 @@ interface_base_finalize( NactICommandTabInterface *klass )
* @window: this #NactICommandTab instance.
*
* Initializes the tab widget at initial load.
+ *
+ * The GConf preference keys used in this tab were misnamed from v1.11.1
+ * up to and including v1.12.0. Starting with v1.12.1, these are migrated
+ * here, so that the normal code only makes use of 'good' keys.
*/
void
nact_icommand_tab_initial_load_toplevel( NactICommandTab *instance )
@@ -169,6 +173,10 @@ nact_icommand_tab_initial_load_toplevel( NactICommandTab *instance )
static const gchar *thisfn = "nact_icommand_tab_initial_load_toplevel";
g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
+
+ base_iprefs_migrate_key( BASE_WINDOW( instance ), "iconditions-legend-dialog", IPREFS_LEGEND_DIALOG );
+ base_iprefs_migrate_key( BASE_WINDOW( instance ), "iconditions-command-chooser", IPREFS_COMMAND_CHOOSER );
+ base_iprefs_migrate_key( BASE_WINDOW( instance ), "iconditions-folder-uri", IPREFS_FOLDER_URI );
}
/**
@@ -314,7 +322,7 @@ check_for_label( NactICommandTab *instance, GtkEntry *entry, const gchar *label
nact_main_statusbar_hide_status(
NACT_MAIN_WINDOW( instance ),
- PROP_ICOMMAND_TAB_STATUS_CONTEXT );
+ ICOMMAND_TAB_STATUSBAR_CONTEXT );
set_label_label( instance, "black" );
@@ -328,7 +336,7 @@ check_for_label( NactICommandTab *instance, GtkEntry *entry, const gchar *label
/* i18n: status bar message when the profile label is empty */
nact_main_statusbar_display_status(
NACT_MAIN_WINDOW( instance ),
- PROP_ICOMMAND_TAB_STATUS_CONTEXT,
+ ICOMMAND_TAB_STATUSBAR_CONTEXT,
_( "Caution: a label is mandatory for the profile." ));
set_label_label( instance, "red" );
@@ -380,7 +388,7 @@ legend_dialog_hide( NactICommandTab *instance )
legend_dialog = get_legend_dialog( instance );
is_visible = ( gboolean ) GPOINTER_TO_INT(
- g_object_get_data( G_OBJECT( legend_dialog ), LEGEND_DIALOG_IS_VISIBLE ));
+ g_object_get_data( G_OBJECT( legend_dialog ), ICOMMAND_TAB_LEGEND_VISIBLE ));
if( is_visible ){
g_assert( GTK_IS_WINDOW( legend_dialog ));
@@ -393,7 +401,7 @@ legend_dialog_hide( NactICommandTab *instance )
legend_button = get_legend_button( instance );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( legend_button ), FALSE );
- g_object_set_data( G_OBJECT( legend_dialog ), LEGEND_DIALOG_IS_VISIBLE, GINT_TO_POINTER( FALSE ));
+ g_object_set_data( G_OBJECT( legend_dialog ), ICOMMAND_TAB_LEGEND_VISIBLE, GINT_TO_POINTER( FALSE ));
}
}
@@ -412,7 +420,7 @@ legend_dialog_show( NactICommandTab *instance )
base_iprefs_position_named_window( BASE_WINDOW( instance ), legend_dialog, IPREFS_LEGEND_DIALOG );
gtk_widget_show( GTK_WIDGET( legend_dialog ));
- g_object_set_data( G_OBJECT( legend_dialog ), LEGEND_DIALOG_IS_VISIBLE, GINT_TO_POINTER( TRUE ));
+ g_object_set_data( G_OBJECT( legend_dialog ), ICOMMAND_TAB_LEGEND_VISIBLE, GINT_TO_POINTER( TRUE ));
}
static void
diff --git a/src/nact/nact-main-statusbar.h b/src/nact/nact-main-statusbar.h
index 8b2e36f..0433636 100644
--- a/src/nact/nact-main-statusbar.h
+++ b/src/nact/nact-main-statusbar.h
@@ -31,6 +31,10 @@
#ifndef __NACT_MAIN_STATUSBAR_H__
#define __NACT_MAIN_STATUSBAR_H__
+/*
+ * Status bar management.
+ */
+
#include "nact-main-window.h"
G_BEGIN_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]