[nautilus-actions] Refactoring: update NactICommandTab interface



commit f98956ebcc9432802387b669703f452808233485
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Feb 17 14:20:33 2010 +0100

    Refactoring: update NactICommandTab interface

 ChangeLog                    |    8 +++
 src/api/na-core-utils.h      |    4 ++
 src/core/na-core-utils.c     |   36 +++++++++++++
 src/core/na-iprefs.c         |  114 +----------------------------------------
 src/core/na-iprefs.h         |    2 -
 src/nact/nact-icommand-tab.c |   47 +++++++----------
 src/nact/nact-iprefs.c       |  108 ++++++++++++++++++++++++++++++++++------
 src/nact/nact-iprefs.h       |    2 +
 8 files changed, 165 insertions(+), 156 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f524cd8..c1f21b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2009-02-17 Pierre Wieser <pwieser trychlos org>
 
+	* src/api/na-core-utils.h:
+	* src/core/na-core-utils.c:
+	* src/core/na-iprefs.c:
+	* src/core/na-iprefs.h:
+	* src/nact/nact-icommand-tab.c:
+	* src/nact/nact-iprefs.c:
+	* src/nact/nact-iprefs.h: Update NactICommandTab interface.
+
 	* src/api/na-object-api.h:
 	* src/api/na-object-profile.h:
 	* src/core/na-object-profile.c:
diff --git a/src/api/na-core-utils.h b/src/api/na-core-utils.h
index 7ec2130..64ced8c 100644
--- a/src/api/na-core-utils.h
+++ b/src/api/na-core-utils.h
@@ -61,6 +61,10 @@ gboolean na_core_utils_slist_find( GSList *list, const gchar *str );
 gboolean na_core_utils_slist_are_equal( GSList *a, GSList *b );
 void     na_core_utils_slist_free( GSList *slist );
 
+/* some functions for GString manipulations.
+ */
+gchar   *na_core_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list );
+
 /* directory management
  */
 gboolean na_core_utils_dir_is_writable( const gchar *path );
diff --git a/src/core/na-core-utils.c b/src/core/na-core-utils.c
index 1591a79..fb48191 100644
--- a/src/core/na-core-utils.c
+++ b/src/core/na-core-utils.c
@@ -309,6 +309,42 @@ na_core_utils_slist_free( GSList *slist )
 	g_slist_free( slist );
 }
 
+/**
+ * na_core_utils_gstring_joinv:
+ * @start: a prefix to be written at the beginning of the output string.
+ * @separator: a string to be used as separator.
+ * @list: the list of strings to be concatenated.
+ *
+ * Concatenates a gchar **list of strings to a new string.
+ *
+ * Returns: a newly allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_core_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list )
+{
+	GString *tmp_string = g_string_new( "" );
+	int i;
+
+	g_return_val_if_fail( list != NULL, NULL );
+
+	if( start != NULL ){
+		tmp_string = g_string_append( tmp_string, start );
+	}
+
+	if( list[0] != NULL ){
+		tmp_string = g_string_append( tmp_string, list[0] );
+	}
+
+	for( i = 1 ; list[i] != NULL ; i++ ){
+		if( separator ){
+			tmp_string = g_string_append( tmp_string, separator );
+		}
+		tmp_string = g_string_append( tmp_string, list[i] );
+	}
+
+	return( g_string_free( tmp_string, FALSE ));
+}
+
 /*
  * split a text buffer in lines
  */
diff --git a/src/core/na-iprefs.c b/src/core/na-iprefs.c
index eb32e7f..2ed7a1b 100644
--- a/src/core/na-iprefs.c
+++ b/src/core/na-iprefs.c
@@ -52,22 +52,12 @@ static GConfEnumStringPair order_mode_table[] = {
 	{ 0, NULL }
 };
 
-#if 0
-#define NA_IPREFS_PRIVATE_DATA				"na-runtime-iprefs-private-data"
-#endif
-
 static gboolean st_initialized = FALSE;
 static gboolean st_finalized = FALSE;
 
-static GType       register_type( void );
-static void        interface_base_init( NAIPrefsInterface *klass );
-static void        interface_base_finalize( NAIPrefsInterface *klass );
-
-#if 0
-static void        setup_private_data( const NAIPrefs *instance );
-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 );
-#endif
+static GType register_type( void );
+static void  interface_base_init( NAIPrefsInterface *klass );
+static void  interface_base_finalize( NAIPrefsInterface *klass );
 
 GType
 na_iprefs_get_type( void )
@@ -534,101 +524,3 @@ na_iprefs_write_string_list( const NAIPrefs *instance, const gchar *name, GSList
 		g_free( path );
 	}
 }
-
-#if 0
-/**
- * na_iprefs_migrate_key:
- * @instance: the #NAIPrefs implementor.
- * @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
-na_iprefs_migrate_key( NAIPrefs *instance, const gchar *old_key, const gchar *new_key )
-{
-	static const gchar *thisfn = "na_iprefs_migrate_key";
-	GConfValue *value;
-
-	g_debug( "%s: instance=%p, old_key=%s, new_key=%s", thisfn, ( void * ) instance, old_key, new_key );
-	g_return_if_fail( NA_IS_IPREFS( instance ));
-
-	value = get_value( na_iprefs_get_gconf_client( instance ), NA_GCONF_PREFS_PATH, new_key );
-	if( !value ){
-		value = get_value( na_iprefs_get_gconf_client( instance ), NA_GCONF_PREFS_PATH, old_key );
-		if( value ){
-			set_value( na_iprefs_get_gconf_client( instance ), NA_GCONF_PREFS_PATH, new_key, value );
-			gconf_value_free( value );
-		}
-	}
-
-	/* do not remove entries which may be always used by another,
-	 * while older, version of NACT
-	 */
-	/*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 );*/
-}
-
-static void
-setup_private_data( const NAIPrefs *instance )
-{
-	NAIPrefsPrivate *ipp;
-
-	ipp = ( NAIPrefsPrivate * ) g_object_get_data( G_OBJECT( instance ), NA_IPREFS_PRIVATE_DATA );
-	if( !ipp ){
-		ipp = g_new0( NAIPrefsPrivate, 1 );
-		ipp->client = gconf_client_get_default();
-		g_object_set_data( G_OBJECT( instance ), NA_IPREFS_PRIVATE_DATA, ipp );
-	}
-}
-
-static GConfValue *
-get_value( GConfClient *client, const gchar *path, const gchar *entry )
-{
-	static const gchar *thisfn = "na_iprefs_get_value";
-	GError *error = NULL;
-	gchar *fullpath;
-	GConfValue *value;
-
-	fullpath = gconf_concat_dir_and_key( 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 = "na_iprefs_set_value";
-	GError *error = NULL;
-	gchar *fullpath;
-
-	g_return_if_fail( value );
-
-	fullpath = gconf_concat_dir_and_key( 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 );
-}
-#endif
diff --git a/src/core/na-iprefs.h b/src/core/na-iprefs.h
index 0ff5a2d..d03b30d 100644
--- a/src/core/na-iprefs.h
+++ b/src/core/na-iprefs.h
@@ -139,8 +139,6 @@ GSList      *na_iprefs_read_string_list ( const NAIPrefs *instance, const gchar
 /*void         na_iprefs_write_bool( NAIPrefs *instance, const gchar *key, gboolean value );*/
 void         na_iprefs_write_string_list( const NAIPrefs *instance, const gchar *key, GSList *value );
 
-/*void         na_iprefs_migrate_key( NAIPrefs *instance, const gchar *old_key, const gchar *new_key );*/
-
 G_END_DECLS
 
 #endif /* __CORE_NA_IPREFS_H__ */
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index 36ff825..81963b3 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -35,17 +35,15 @@
 #include <glib/gi18n.h>
 #include <string.h>
 
+#include <api/na-core-utils.h>
 #include <api/na-object-api.h>
 
-#include <runtime/na-iprefs.h>
-#include <runtime/na-pivot.h>
-#include <runtime/na-utils.h>
-
 #include "base-window.h"
 #include "base-iprefs.h"
 #include "nact-application.h"
 #include "nact-main-statusbar.h"
 #include "nact-gtk-utils.h"
+#include "nact-iprefs.h"
 #include "nact-iactions-list.h"
 #include "nact-main-tab.h"
 #include "nact-icommand-tab.h"
@@ -182,20 +180,15 @@ void
 nact_icommand_tab_initial_load_toplevel( NactICommandTab *instance )
 {
 	static const gchar *thisfn = "nact_icommand_tab_initial_load_toplevel";
-	NactApplication *application;
-	NAPivot *pivot;
 
 	g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	g_return_if_fail( NACT_IS_ICOMMAND_TAB( instance ));
 
 	if( st_initialized && !st_finalized ){
 
-		application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( instance )));
-		pivot = nact_application_get_pivot( application );
-
-		na_iprefs_migrate_key( NA_IPREFS( pivot ), "iconditions-legend-dialog", IPREFS_LEGEND_DIALOG );
-		na_iprefs_migrate_key( NA_IPREFS( pivot ), "iconditions-command-chooser", IPREFS_COMMAND_CHOOSER );
-		na_iprefs_migrate_key( NA_IPREFS( pivot ), "iconditions-folder-uri", IPREFS_FOLDER_URI );
+		nact_iprefs_migrate_key( BASE_WINDOW( instance ), "iconditions-legend-dialog", IPREFS_LEGEND_DIALOG );
+		nact_iprefs_migrate_key( BASE_WINDOW( instance ), "iconditions-command-chooser", IPREFS_COMMAND_CHOOSER );
+		nact_iprefs_migrate_key( BASE_WINDOW( instance ), "iconditions-folder-uri", IPREFS_FOLDER_URI );
 	}
 }
 
@@ -352,7 +345,7 @@ on_tab_updatable_selection_changed( NactICommandTab *instance, gint count_select
 		nact_gtk_utils_set_editable( GTK_OBJECT( label_entry ), editable );
 
 		path_entry = get_path_entry( instance );
-		path = profile ? na_object_profile_get_path( profile ) : g_strdup( "" );
+		path = profile ? na_object_get_path( profile ) : g_strdup( "" );
 		gtk_entry_set_text( GTK_ENTRY( path_entry ), path );
 		g_free( path );
 		gtk_widget_set_sensitive( path_entry, profile != NULL );
@@ -363,7 +356,7 @@ on_tab_updatable_selection_changed( NactICommandTab *instance, gint count_select
 		nact_gtk_utils_set_editable( GTK_OBJECT( path_button ), editable );
 
 		parameters_entry = get_parameters_entry( instance );
-		parameters = profile ? na_object_profile_get_parameters( profile ) : g_strdup( "" );
+		parameters = profile ? na_object_get_parameters( profile ) : g_strdup( "" );
 		gtk_entry_set_text( GTK_ENTRY( parameters_entry ), parameters );
 		g_free( parameters );
 		gtk_widget_set_sensitive( parameters_entry, profile != NULL );
@@ -548,7 +541,7 @@ on_parameters_changed( GtkEntry *entry, NactICommandTab *instance )
 
 		if( edited ){
 
-			na_object_profile_set_parameters( edited, gtk_entry_get_text( entry ));
+			na_object_set_parameters( edited, gtk_entry_get_text( entry ));
 			g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 			update_example_label( instance, edited );
 		}
@@ -561,7 +554,7 @@ on_path_browse( GtkButton *button, NactICommandTab *instance )
 	gboolean set_current_location = FALSE;
 	gchar *uri = NULL;
 	NactApplication *application;
-	NAPivot *pivot;
+	NAUpdater *updater;
 	GtkWindow *toplevel;
 	GtkWidget *dialog;
 	GtkWidget *path_entry;
@@ -569,7 +562,7 @@ on_path_browse( GtkButton *button, NactICommandTab *instance )
 	gchar *filename;
 
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( instance )));
-	pivot = nact_application_get_pivot( application );
+	updater = nact_application_get_updater( application );
 	toplevel = base_window_get_toplevel( BASE_WINDOW( instance ));
 
 	dialog = gtk_file_chooser_dialog_new(
@@ -590,7 +583,7 @@ on_path_browse( GtkButton *button, NactICommandTab *instance )
 		set_current_location = gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( dialog ), path );
 
 	} else {
-		uri = na_iprefs_read_string( NA_IPREFS( pivot ), IPREFS_FOLDER_URI, "file:///bin" );
+		uri = na_iprefs_read_string( NA_IPREFS( updater ), IPREFS_FOLDER_URI, "file:///bin" );
 		gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( dialog ), uri );
 		g_free( uri );
 	}
@@ -602,7 +595,7 @@ on_path_browse( GtkButton *button, NactICommandTab *instance )
 	  }
 
 	uri = gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( dialog ));
-	na_iprefs_write_string( NA_IPREFS( pivot ), IPREFS_FOLDER_URI, uri );
+	nact_iprefs_write_string( BASE_WINDOW( instance ), IPREFS_FOLDER_URI, uri );
 	g_free( uri );
 
 	base_iprefs_save_named_window_position( BASE_WINDOW( instance ), GTK_WINDOW( dialog ), IPREFS_COMMAND_CHOOSER );
@@ -624,7 +617,7 @@ on_path_changed( GtkEntry *entry, NactICommandTab *instance )
 
 		if( edited ){
 
-			na_object_profile_set_path( edited, gtk_entry_get_text( entry ));
+			na_object_set_path( edited, gtk_entry_get_text( entry ));
 			g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 			update_example_label( instance, edited );
 		}
@@ -696,20 +689,20 @@ parse_parameters( NactICommandTab *instance )
 	if( accept_multiple ){
 		if( is_file && is_dir ){
 			ex_one = ex_files[0];
-			ex_list = na_utils_gstring_joinv( NULL, " ", ex_mixed );
-			ex_path_list = na_utils_gstring_joinv( start, separator, ex_mixed );
+			ex_list = na_core_utils_gstring_joinv( NULL, " ", ex_mixed );
+			ex_path_list = na_core_utils_gstring_joinv( start, separator, ex_mixed );
 			ex_uri_list = g_strjoin( " ", ex_uri_file1, ex_uri_folder1, NULL );
 
 		} else if( is_dir ){
 			ex_one = ex_dirs[0];
-			ex_list = na_utils_gstring_joinv( NULL, " ", ex_dirs );
-			ex_path_list = na_utils_gstring_joinv( start, separator, ex_dirs );
+			ex_list = na_core_utils_gstring_joinv( NULL, " ", ex_dirs );
+			ex_path_list = na_core_utils_gstring_joinv( start, separator, ex_dirs );
 			ex_uri_list = g_strjoin( " ", ex_uri_folder1, ex_uri_folder2, NULL );
 
 		} else if( is_file ){
 			ex_one = ex_files[0];
-			ex_list = na_utils_gstring_joinv( NULL, " ", ex_files );
-			ex_path_list = na_utils_gstring_joinv( start, separator, ex_files );
+			ex_list = na_core_utils_gstring_joinv( NULL, " ", ex_files );
+			ex_path_list = na_core_utils_gstring_joinv( start, separator, ex_files );
 			ex_uri_list = g_strjoin( " ", ex_uri_file1, ex_uri_file2, NULL );
 		}
 	} else {
@@ -800,7 +793,7 @@ parse_parameters( NactICommandTab *instance )
 	}
 	tmp_string = g_string_append_len( tmp_string, old_iter, strlen( old_iter ));
 
-	na_utils_free_string_list( scheme_list );
+	na_core_utils_slist_free( scheme_list );
 
 	g_free( ex_list );
 	g_free( ex_path_list );
diff --git a/src/nact/nact-iprefs.c b/src/nact/nact-iprefs.c
index 98861c1..d16c2e3 100644
--- a/src/nact/nact-iprefs.c
+++ b/src/nact/nact-iprefs.c
@@ -43,19 +43,6 @@ struct NactIPrefsInterfacePrivate {
 	GConfClient *client;
 };
 
-#if 0
-#define DEFAULT_EXPORT_FORMAT_INT			IPREFS_EXPORT_FORMAT_GCONF_ENTRY
-#define DEFAULT_EXPORT_FORMAT_STR			"GConfEntry"
-
-static GConfEnumStringPair export_format_table[] = {
-	{ IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V1,	"GConfSchemaV1" },
-	{ IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V2,	"GConfSchemaV2" },
-	{ IPREFS_EXPORT_FORMAT_GCONF_ENTRY,		DEFAULT_EXPORT_FORMAT_STR },
-	{ IPREFS_EXPORT_FORMAT_ASK,				"Ask" },
-	{ 0, NULL }
-};
-#endif
-
 #define DEFAULT_IMPORT_MODE_INT				IPREFS_IMPORT_NO_IMPORT
 #define DEFAULT_IMPORT_MODE_STR				"NoImport"
 
@@ -70,9 +57,12 @@ static GConfEnumStringPair import_mode_table[] = {
 static gboolean st_initialized = FALSE;
 static gboolean st_finalized = FALSE;
 
-static GType   register_type( void );
-static void    interface_base_init( NactIPrefsInterface *klass );
-static void    interface_base_finalize( NactIPrefsInterface *klass );
+static GType       register_type( void );
+static void        interface_base_init( NactIPrefsInterface *klass );
+static void        interface_base_finalize( NactIPrefsInterface *klass );
+
+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 );
 
 GType
 nact_iprefs_get_type( void )
@@ -283,6 +273,45 @@ nact_iprefs_set_import_mode( const BaseWindow *window, const gchar *name, gint m
 }
 
 /**
+ * nact_iprefs_migrate_key:
+ * @window: a #BaseWindow 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
+nact_iprefs_migrate_key( const BaseWindow *window, const gchar *old_key, const gchar *new_key )
+{
+	static const gchar *thisfn = "nact_iprefs_migrate_key";
+	GConfClient *gconf_client;
+	GConfValue *value;
+
+	g_debug( "%s: window=%p, old_key=%s, new_key=%s", thisfn, ( void * ) window, old_key, new_key );
+	g_return_if_fail( NA_IS_IPREFS( instance ));
+
+	if( st_initialized && !st_finalized ){
+
+		gconf_client = NACT_IPREFS_GET_INTERFACE( window )->private->client;
+
+		value = get_value( gconf_client, IPREFS_GCONF_PREFS_PATH, new_key );
+		if( !value ){
+			value = get_value( gconf_client, IPREFS_GCONF_PREFS_PATH, old_key );
+			if( value ){
+				set_value( gconf_client, IPREFS_GCONF_PREFS_PATH, new_key, value );
+				gconf_value_free( value );
+			}
+		}
+
+		/* do not remove entries which may still be used by an older N-A version
+		 */
+	}
+}
+
+/**
  * nact_iprefs_write_string:
  * @window: this #BaseWindow-derived window.
  * @name: the preference key.
@@ -307,3 +336,50 @@ nact_iprefs_write_string( const BaseWindow *window, const gchar *name, const gch
 		g_free( path );
 	}
 }
+
+static GConfValue *
+get_value( GConfClient *client, const gchar *path, const gchar *entry )
+{
+	static const gchar *thisfn = "na_iprefs_get_value";
+	GError *error = NULL;
+	gchar *fullpath;
+	GConfValue *value;
+
+	fullpath = gconf_concat_dir_and_key( 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 = "na_iprefs_set_value";
+	GError *error = NULL;
+	gchar *fullpath;
+
+	g_return_if_fail( value );
+
+	fullpath = gconf_concat_dir_and_key( 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 );
+}
diff --git a/src/nact/nact-iprefs.h b/src/nact/nact-iprefs.h
index 13af329..5170751 100644
--- a/src/nact/nact-iprefs.h
+++ b/src/nact/nact-iprefs.h
@@ -89,6 +89,8 @@ void   nact_iprefs_set_export_format( const BaseWindow *window, const gchar *pre
 gint  nact_iprefs_get_import_mode   ( const BaseWindow *window, const gchar *pref );
 void  nact_iprefs_set_import_mode   ( const BaseWindow *window, const gchar *pref, gint mode );
 
+void  nact_iprefs_migrate_key       ( const BaseWindow *window, const gchar *old_key, const gchar *new_key );
+
 void  nact_iprefs_write_string      ( const BaseWindow *window, const gchar *name, const gchar *value );
 
 G_END_DECLS



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