[nautilus-actions] Fix reading from GConf



commit e92b5885696248056da81a623fcd2ddf15ef15b4
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Feb 25 18:48:39 2010 +0100

    Fix reading from GConf

 ChangeLog                            |   24 +++
 src/api/na-object-api.h              |    2 +-
 src/core/Makefile.am                 |    2 +
 src/core/na-data-boxed.c             |    2 +
 src/core/na-gconf-monitor.c          |    9 +-
 src/core/na-gtk-utils.c              |   77 ++++++++++
 src/core/na-gtk-utils.h              |   48 ++++++
 src/core/na-importer-ask.c           |   67 +++-------
 src/io-gconf/nagp-gconf-provider.c   |    5 +-
 src/io-gconf/nagp-reader.c           |  265 +++++++++++++++++++++++++++++++++-
 src/io-gconf/nagp-reader.h           |    5 +-
 src/nact/nact-assistant-import.c     |   22 ++--
 src/nact/nact-iprefs.c               |    2 +
 src/nact/nact-preferences-editor.c   |   15 +-
 src/nact/nact-tree-model-dnd.c       |    1 +
 src/utils/nautilus-actions-schemas.c |    1 +
 16 files changed, 470 insertions(+), 77 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 23a5b56..75a6349 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2009-02-25 Pierre Wieser <pwieser trychlos org>
+
+	* src/api/na-object-api.h:
+	Distinguish between profile and item on get_label.
+
+	* src/core/na-gtk-utils.c:
+	* src/core/na-gtk-utils.h: New files.
+	* src/core/Makefile.am: Updated accordingly.
+
+	* src/core/na-data-boxed.c:
+	* src/core/na-gconf-monitor.c:
+	* src/core/na-importer-ask.c:
+	* src/io-gconf/nagp-gconf-provider.c:
+	* src/io-gconf/nagp-reader.c:
+	* src/io-gconf/nagp-reader.h:
+	Fix objects reading from GConf.
+
+	* src/nact/nact-assistant-import.c:
+	* src/nact/nact-iprefs.c:
+	* src/nact/nact-preferences-editor.c:
+	* src/nact/nact-tree-model-dnd.c:
+	* src/utils/nautilus-actions-schemas.c:
+	Move GConfClient to private object data, unref on dispose.
+
 2009-02-24 Pierre Wieser <pwieser trychlos org>
 
 	* src/api/na-iimporter.h:
diff --git a/src/api/na-object-api.h b/src/api/na-object-api.h
index caa544d..fd94cc6 100644
--- a/src/api/na-object-api.h
+++ b/src/api/na-object-api.h
@@ -78,7 +78,7 @@ G_BEGIN_DECLS
 /* NAObjectId
  */
 #define na_object_get_id( obj )							(( gchar * ) na_ifactory_object_get_as_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_ID ))
-#define na_object_get_label( obj )						(( gchar * ) na_ifactory_object_get_as_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_LABEL ))
+#define na_object_get_label( obj )						(( gchar * ) na_ifactory_object_get_as_void( NA_IFACTORY_OBJECT( obj ), ( NA_IS_OBJECT_PROFILE( obj ) ? NAFO_DATA_DESCNAME : NAFO_DATA_LABEL )))
 #define na_object_get_parent( obj )						(( NAObjectItem * ) na_ifactory_object_get_as_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_PARENT ))
 
 #define na_object_set_id( obj, id )						na_ifactory_object_set_from_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_ID, ( const void * )( id ))
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index bfdfd5b..3130d43 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -54,6 +54,8 @@ libna_core_la_SOURCES = \
 	na-gconf-utils.c									\
 	na-gnome-vfs-uri.c									\
 	na-gnome-vfs-uri.h									\
+	na-gtk-utils.c										\
+	na-gtk-utils.h										\
 	na-iabout.c											\
 	na-iabout.h											\
 	na-iduplicable.c									\
diff --git a/src/core/na-data-boxed.c b/src/core/na-data-boxed.c
index 3a341a6..d7d7208 100644
--- a/src/core/na-data-boxed.c
+++ b/src/core/na-data-boxed.c
@@ -312,6 +312,8 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self = NA_DATA_BOXED( instance );
 
 	self->private = g_new0( NADataBoxedPrivate, 1 );
+
+	self->private->dispose_has_run = FALSE;
 }
 
 static void
diff --git a/src/core/na-gconf-monitor.c b/src/core/na-gconf-monitor.c
index 1de407b..c527c8e 100644
--- a/src/core/na-gconf-monitor.c
+++ b/src/core/na-gconf-monitor.c
@@ -129,6 +129,10 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self = NA_GCONF_MONITOR( instance );
 
 	self->private = g_new0( NAGConfMonitorPrivate, 1 );
+
+	self->private->gconf = gconf_client_get_default();
+
+	self->private->dispose_has_run = FALSE;
 }
 
 static void
@@ -148,6 +152,8 @@ instance_dispose( GObject *object )
 
 		self->private->dispose_has_run = TRUE;
 
+		g_object_unref( self->private->gconf );
+
 		/* chain up to the parent class */
 		if( G_OBJECT_CLASS( st_parent_class )->dispose ){
 			G_OBJECT_CLASS( st_parent_class )->dispose( object );
@@ -192,7 +198,6 @@ na_gconf_monitor_new( const gchar *path, GConfClientNotifyFunc handler, gpointer
 
 	monitor = g_object_new( NA_GCONF_MONITOR_TYPE, NULL );
 
-	monitor->private->gconf = gconf_client_get_default();
 	monitor->private->path = g_strdup( path );
 	monitor->private->preload = GCONF_CLIENT_PRELOAD_RECURSIVE;
 	monitor->private->handler = handler;
@@ -279,7 +284,5 @@ release_monitor( NAGConfMonitor *monitor )
 			g_warning( "%s: path=%s, error=%s", thisfn, monitor->private->path, error->message );
 			g_error_free( error );
 		}
-
-		g_object_unref( monitor->private->gconf );
 	}
 }
diff --git a/src/core/na-gtk-utils.c b/src/core/na-gtk-utils.c
new file mode 100644
index 0000000..6c9d684
--- /dev/null
+++ b/src/core/na-gtk-utils.c
@@ -0,0 +1,77 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Frederic Ruaudel <grumz grumz net>
+ *   Rodrigo Moya <rodrigo gnome-db org>
+ *   Pierre Wieser <pwieser trychlos org>
+ *   ... and many others (see AUTHORS)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include "na-gtk-utils.h"
+
+/**
+ * na_gtk_utils_search_for_child_widget:
+ * @container: a #GtkContainer, usually the #GtkWindow toplevel.
+ * @name: the name of the searched widget.
+ *
+ * Returns: the searched widget.
+ */
+GtkWidget *
+na_gtk_utils_search_for_child_widget( GtkContainer *container, const gchar *name )
+{
+	GList *children = gtk_container_get_children( container );
+	GList *ic;
+	GtkWidget *found = NULL;
+	GtkWidget *child;
+	const gchar *child_name;
+
+	for( ic = children ; ic && !found ; ic = ic->next ){
+
+		if( GTK_IS_WIDGET( ic->data )){
+			child = GTK_WIDGET( ic->data );
+			child_name = gtk_buildable_get_name( GTK_BUILDABLE( child ));
+
+			if( child_name && strlen( child_name )){
+				/*g_debug( "%s: child=%s", thisfn, child_name );*/
+
+				if( !g_ascii_strcasecmp( name, child_name )){
+					found = child;
+					break;
+
+				} else if( GTK_IS_CONTAINER( child )){
+					found = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( child ), name );
+				}
+			}
+		}
+	}
+
+	g_list_free( children );
+	return( found );
+}
diff --git a/src/core/na-gtk-utils.h b/src/core/na-gtk-utils.h
new file mode 100644
index 0000000..a985d8c
--- /dev/null
+++ b/src/core/na-gtk-utils.h
@@ -0,0 +1,48 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Frederic Ruaudel <grumz grumz net>
+ *   Rodrigo Moya <rodrigo gnome-db org>
+ *   Pierre Wieser <pwieser trychlos org>
+ *   ... and many others (see AUTHORS)
+ */
+
+#ifndef __CORE_API_NA_GTK_UTILS_H__
+#define __CORE_API_NA_GTK_UTILS_H__
+
+/**
+ * SECTION: na_core_utils
+ * @short_description: Core library utilities.
+ * @include: nautilus-action/na-core-utils.h
+ */
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GtkWidget *na_gtk_utils_search_for_child_widget( GtkContainer *container, const gchar *name );
+
+G_END_DECLS
+
+#endif /* __CORE_API_NA_GTK_UTILS_H__ */
diff --git a/src/core/na-importer-ask.c b/src/core/na-importer-ask.c
index 7420b16..b474a73 100644
--- a/src/core/na-importer-ask.c
+++ b/src/core/na-importer-ask.c
@@ -38,6 +38,7 @@
 
 #include <api/na-object-api.h>
 
+#include "na-gtk-utils.h"
 #include "na-iprefs.h"
 #include "na-importer-ask.h"
 
@@ -75,7 +76,6 @@ static void       on_cancel_clicked( GtkButton *button, NAImporterAsk *editor );
 static void       on_ok_clicked( GtkButton *button, NAImporterAsk *editor );
 static void       get_selected_mode( NAImporterAsk *editor );
 static gboolean   on_dialog_response( NAImporterAsk *editor, gint code );
-static GtkWidget *search_for_child_widget( GtkContainer *container, const gchar *name );
 
 GType
 na_importer_ask_get_type( void )
@@ -146,8 +146,6 @@ instance_init( GTypeInstance *instance, gpointer klass )
 
 	self->private = g_new0( NAImporterAskPrivate, 1 );
 
-	self->private->dispose_has_run = FALSE;
-
 	self->private->builder = gtk_builder_new();
 
 	error = NULL;
@@ -159,6 +157,10 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	} else {
 		self->private->toplevel = GTK_WINDOW( gtk_builder_get_object( self->private->builder, "ImporterAskDialog" ));
 	}
+
+	self->private->gconf = gconf_client_get_default();
+
+	self->private->dispose_has_run = FALSE;
 }
 
 static void
@@ -174,10 +176,11 @@ instance_dispose( GObject *dialog )
 
 	if( !self->private->dispose_has_run ){
 
-		g_object_unref( self->private->builder );
-
 		self->private->dispose_has_run = TRUE;
 
+		g_object_unref( self->private->gconf );
+		g_object_unref( self->private->builder );
+
 		/* chain up to the parent class */
 		if( G_OBJECT_CLASS( st_parent_class )->dispose ){
 			G_OBJECT_CLASS( st_parent_class )->dispose( dialog );
@@ -245,7 +248,6 @@ na_importer_ask_user( const NAIImporterParms *parms, const NAObjectItem *existin
 
 		dialog->private->parms = ( NAIImporterParms * ) parms;
 		dialog->private->existing = ( NAObjectItem * ) existing;
-		dialog->private->gconf = gconf_client_get_default();
 		dialog->private->mode = na_iprefs_get_import_mode( dialog->private->gconf, IPREFS_IMPORT_ASK_LAST_MODE );
 
 		init_dialog( dialog );
@@ -297,37 +299,37 @@ init_dialog( NAImporterAsk *editor )
 				imported_label, editor->private->parms->uri, existing_label );
 	}
 
-	widget = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "ImporterAskLabel" );
+	widget = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "ImporterAskLabel" );
 	gtk_label_set_text( GTK_LABEL( widget ), label );
 	g_free( label );
 
 	switch( editor->private->mode ){
 		case IMPORTER_MODE_RENUMBER:
-			button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskRenumberButton" );
+			button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskRenumberButton" );
 			break;
 
 		case IMPORTER_MODE_OVERRIDE:
-			button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskOverrideButton" );
+			button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskOverrideButton" );
 			break;
 
 		case IMPORTER_MODE_NO_IMPORT:
 		default:
-			button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskNoImportButton" );
+			button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskNoImportButton" );
 			break;
 	}
 	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
 
-	button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskKeepChoiceButton" );
+	button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskKeepChoiceButton" );
 	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), FALSE );
 
-	button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "OKButton" );
+	button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "OKButton" );
 	g_signal_connect(
 			G_OBJECT( button ),
 			"clicked",
 			G_CALLBACK( on_ok_clicked ),
 			editor );
 
-	button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "CancelButton" );
+	button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "CancelButton" );
 	g_signal_connect(
 			G_OBJECT( button ),
 			"clicked",
@@ -366,12 +368,12 @@ get_selected_mode( NAImporterAsk *editor )
 
 	import_mode = IMPORTER_MODE_NO_IMPORT;
 
-	button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskRenumberButton" );
+	button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskRenumberButton" );
 	if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ))){
 		import_mode = IMPORTER_MODE_RENUMBER;
 
 	} else {
-		button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskOverrideButton" );
+		button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskOverrideButton" );
 		if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ))){
 			import_mode = IMPORTER_MODE_OVERRIDE;
 		}
@@ -380,7 +382,7 @@ get_selected_mode( NAImporterAsk *editor )
 	editor->private->mode = import_mode;
 	na_iprefs_set_import_mode( editor->private->gconf, IPREFS_IMPORT_ASK_LAST_MODE, editor->private->mode );
 
-	button = search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskKeepChoiceButton" );
+	button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskKeepChoiceButton" );
 	keep = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ));
 	if( keep ){
 		na_iprefs_set_import_mode( editor->private->gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE, import_mode );
@@ -419,36 +421,3 @@ on_dialog_response( NAImporterAsk *editor, gint code )
 
 	return( FALSE );
 }
-
-static GtkWidget *
-search_for_child_widget( GtkContainer *container, const gchar *name )
-{
-	GList *children = gtk_container_get_children( container );
-	GList *ic;
-	GtkWidget *found = NULL;
-	GtkWidget *child;
-	const gchar *child_name;
-
-	for( ic = children ; ic ; ic = ic->next ){
-		if( GTK_IS_WIDGET( ic->data )){
-			child = GTK_WIDGET( ic->data );
-			child_name = gtk_buildable_get_name( GTK_BUILDABLE( child ));
-			if( child_name && strlen( child_name )){
-				/*g_debug( "%s: child=%s", thisfn, child_name );*/
-				if( !g_ascii_strcasecmp( name, child_name )){
-					found = child;
-					break;
-
-				} else if( GTK_IS_CONTAINER( child )){
-					found = search_for_child_widget( GTK_CONTAINER( child ), name );
-					if( found ){
-						break;
-					}
-				}
-			}
-		}
-	}
-
-	g_list_free( children );
-	return( found );
-}
diff --git a/src/io-gconf/nagp-gconf-provider.c b/src/io-gconf/nagp-gconf-provider.c
index 4448c5a..253e0d5 100644
--- a/src/io-gconf/nagp-gconf-provider.c
+++ b/src/io-gconf/nagp-gconf-provider.c
@@ -151,6 +151,7 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self->private = g_new0( NagpGConfProviderPrivate, 1 );
 
 	self->private->dispose_has_run = FALSE;
+
 	self->private->gconf = gconf_client_get_default();
 	self->private->monitors = install_monitors( self );
 }
@@ -242,8 +243,8 @@ ifactory_provider_iface_init( NAIFactoryProviderInterface *iface )
 
 	iface->get_version = ifactory_provider_get_version;
 	iface->read_start = NULL;
-	iface->read_data = NULL;
-	iface->read_done = NULL;
+	iface->read_data = nagp_reader_read_data;
+	iface->read_done = nagp_reader_read_done;
 	iface->write_start = NULL;
 	iface->write_data = NULL;
 	iface->write_done = NULL;
diff --git a/src/io-gconf/nagp-reader.c b/src/io-gconf/nagp-reader.c
index 42cb237..601ff32 100644
--- a/src/io-gconf/nagp-reader.c
+++ b/src/io-gconf/nagp-reader.c
@@ -34,6 +34,9 @@
 
 #include <string.h>
 
+#include <api/na-data-def.h>
+#include <api/na-data-types.h>
+#include <api/na-ifactory-provider.h>
 #include <api/na-iio-provider.h>
 #include <api/na-object-api.h>
 #include <api/na-core-utils.h>
@@ -43,7 +46,21 @@
 #include "nagp-keys.h"
 #include "nagp-reader.h"
 
-static NAObjectItem  *read_item( NagpGConfProvider *provider, const gchar *path );
+typedef struct {
+	gchar        *path;
+	NAObjectItem *parent;
+}
+	ReaderData;
+
+static NAObjectItem  *read_item( NagpGConfProvider *provider, const gchar *path, GSList **messages );
+
+static NADataBoxed   *read_data_item_properties( const NAIFactoryProvider *provider, NAObjectItem *item, ReaderData *reader_data, const NADataDef *def );
+static NADataBoxed   *read_data_profile_properties( const NAIFactoryProvider *provider, NAObjectProfile *profile, ReaderData *reader_data, const NADataDef *def );
+static void           read_done_item( const NAIFactoryProvider *provider, NAObjectItem *item, ReaderData *data, GSList **messages );
+static void           read_done_action( const NAIFactoryProvider *provider, NAObjectAction *action, ReaderData *data, GSList **messages );
+static void           read_done_action_load_profile( const NAIFactoryProvider *provider, ReaderData *data, const gchar *path, GSList **messages );
+static void           read_done_profile( const NAIFactoryProvider *provider, NAObjectProfile *profile, ReaderData *data, GSList **messages );
+#if 0
 static void           read_item_action( NagpGConfProvider *provider, const gchar *path, NAObjectAction *action );
 static void           read_item_action_properties( NagpGConfProvider *provider, GSList *entries, NAObjectAction *action );
 static void           read_item_action_properties_v1( NagpGConfProvider *gconf, GSList *entries, NAObjectAction *action );
@@ -52,7 +69,8 @@ static void           read_item_action_profile_properties( NagpGConfProvider *pr
 static void           read_item_menu( NagpGConfProvider *provider, const gchar *path, NAObjectMenu *menu );
 static void           read_item_menu_properties( NagpGConfProvider *provider, GSList *entries, NAObjectMenu *menu );
 static void           read_object_item_properties( NagpGConfProvider *provider, GSList *entries, NAObjectItem *item );
-
+#endif
+static NADataBoxed   *get_boxed_from_path( const NagpGConfProvider *provider, const gchar *path, ReaderData *reader_data, const NADataDef *def );
 static gboolean       is_key_writable( NagpGConfProvider *gconf, const gchar *key );
 
 /*
@@ -83,7 +101,7 @@ nagp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages )
 
 		for( ip = listpath ; ip ; ip = ip->next ){
 
-			item = read_item( self, ( const gchar * ) ip->data );
+			item = read_item( self, ( const gchar * ) ip->data, messages );
 			if( item ){
 				items_list = g_list_prepend( items_list, item );
 			}
@@ -100,13 +118,15 @@ nagp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages )
  * path is here the full path to an item
  */
 static NAObjectItem *
-read_item( NagpGConfProvider *provider, const gchar *path )
+read_item( NagpGConfProvider *provider, const gchar *path, GSList **messages )
 {
 	static const gchar *thisfn = "nagp_gconf_provider_read_item";
 	NAObjectItem *item;
 	gboolean have_type;
 	gchar *full_path;
 	gchar *type;
+	gchar *id;
+	ReaderData *data;
 
 	g_debug( "%s: provider=%p, path=%s", thisfn, ( void * ) provider, path );
 	g_return_val_if_fail( NAGP_IS_GCONF_PROVIDER( provider ), NULL );
@@ -123,13 +143,17 @@ read_item( NagpGConfProvider *provider, const gchar *path )
 	 */
 	if( have_type && !strcmp( type, NAGP_VALUE_TYPE_MENU )){
 		item = NA_OBJECT_ITEM( na_object_menu_new());
+#if 0
 		read_item_menu( provider, path, NA_OBJECT_MENU( item ));
+#endif
 
 	/* else this should be an action (no type, or type='Action')
 	 */
 	} else if( !have_type || !strcmp( type, NAGP_VALUE_TYPE_ACTION )){
 		item = NA_OBJECT_ITEM( na_object_action_new());
+#if 0
 		read_item_action( provider, path, NA_OBJECT_ACTION( item ));
+#endif
 
 	} else {
 		g_warning( "%s: unknown type '%s' at %s", thisfn, type, path );
@@ -137,9 +161,186 @@ read_item( NagpGConfProvider *provider, const gchar *path )
 
 	g_free( type );
 
+	if( item ){
+		id = g_path_get_basename( path );
+		na_object_set_id( item, id );
+		g_free( id );
+
+		data = g_new0( ReaderData, 1 );
+		data->path = ( gchar * ) path;
+
+		na_ifactory_provider_read_item(
+				NA_IFACTORY_PROVIDER( provider ),
+				data,
+				NA_IFACTORY_OBJECT( item ),
+				messages );
+
+		g_free( data );
+	}
+
 	return( item );
 }
 
+NADataBoxed *
+nagp_reader_read_data( const NAIFactoryProvider *provider, void *reader_data, const NAIFactoryObject *object, const NADataDef *def, GSList **messages )
+{
+	static const gchar *thisfn = "nagp_reader_read_data";
+	NADataBoxed *boxed;
+
+	g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( provider ), NULL );
+	g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
+
+	g_debug( "%s: reader_data=%p, object=%p (%s), data=%s",
+			thisfn,
+			( void * ) reader_data,
+			( void * ) object, G_OBJECT_TYPE_NAME( object ),
+			def->name );
+
+	if( !def->gconf_entry || !strlen( def->gconf_entry )){
+		g_warning( "%s: GConf entry is not set for NADataDef %s", thisfn, def->name );
+		return( NULL );
+	}
+
+	boxed = NULL;
+
+	if( NA_IS_OBJECT_ITEM( object )){
+		boxed = read_data_item_properties( provider, NA_OBJECT_ITEM( object ), ( ReaderData * ) reader_data, def );
+	}
+
+	if( NA_IS_OBJECT_PROFILE( object )){
+		boxed = read_data_profile_properties( provider, NA_OBJECT_PROFILE( object ), ( ReaderData * ) reader_data, def );
+	}
+
+	return( boxed );
+}
+
+static NADataBoxed *
+read_data_item_properties( const NAIFactoryProvider *provider, NAObjectItem *item, ReaderData *reader_data, const NADataDef *def )
+{
+	return( get_boxed_from_path( NAGP_GCONF_PROVIDER( provider ), reader_data->path, reader_data, def ));
+}
+
+static NADataBoxed *
+read_data_profile_properties( const NAIFactoryProvider *provider, NAObjectProfile *profile, ReaderData *reader_data, const NADataDef *def )
+{
+	return( get_boxed_from_path( NAGP_GCONF_PROVIDER( provider ), reader_data->path, reader_data, def ));
+}
+
+void
+nagp_reader_read_done( const NAIFactoryProvider *provider, void *reader_data, const NAIFactoryObject *object, GSList **messages  )
+{
+	static const gchar *thisfn = "nagp_reader_read_done";
+
+	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( provider ));
+	g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
+
+	g_debug( "%s: provider=%p, reader_data=%p, object=%p (%s), messages=%p",
+			thisfn,
+			( void * ) provider,
+			( void * ) reader_data,
+			( void * ) object, G_OBJECT_TYPE_NAME( object ),
+			( void * ) messages );
+
+	if( NA_IS_OBJECT_ITEM( object )){
+		read_done_item( provider, NA_OBJECT_ITEM( object ), ( ReaderData * ) reader_data, messages );
+	}
+
+	if( NA_IS_OBJECT_ACTION( object )){
+		read_done_action( provider, NA_OBJECT_ACTION( object ), ( ReaderData * ) reader_data, messages );
+	}
+
+	if( NA_IS_OBJECT_PROFILE( object )){
+		read_done_profile( provider, NA_OBJECT_PROFILE( object ), ( ReaderData * ) reader_data, messages );
+	}
+
+	g_debug( "quitting nagp_read_done for %s at %p", G_OBJECT_TYPE_NAME( object ), ( void * ) object );
+}
+
+static void
+read_done_item( const NAIFactoryProvider *provider, NAObjectItem *item, ReaderData *data, GSList **messages )
+{
+	GSList *entries, *ie;
+	gboolean writable;
+	GConfEntry *gconf_entry;
+	const gchar *key;
+
+	data->parent = item;
+
+	entries = na_gconf_utils_get_entries( NAGP_GCONF_PROVIDER( provider )->private->gconf, data->path );
+
+	writable = TRUE;
+	for( ie = entries ; ie && writable ; ie = ie->next ){
+		gconf_entry = ( GConfEntry * ) ie->data;
+		key = gconf_entry_get_key( gconf_entry );
+		writable = is_key_writable( NAGP_GCONF_PROVIDER( provider ), key );
+	}
+
+	g_debug( "nagp_reader_read_done_item: writable=%s", writable ? "True":"False" );
+	na_object_set_readonly( item, !writable );
+}
+
+static void
+read_done_action( const NAIFactoryProvider *provider, NAObjectAction *action, ReaderData *data, GSList **messages )
+{
+	GSList *order;
+	GSList *list_profiles;
+	GSList *ip;
+	gchar *profile_path;
+
+	order = na_object_get_items_slist( action );
+	list_profiles = na_gconf_utils_get_subdirs( NAGP_GCONF_PROVIDER( provider )->private->gconf, data->path );
+
+	/* read profiles in the specified order
+	 */
+	for( ip = order ; ip ; ip = ip->next ){
+		profile_path = gconf_concat_dir_and_key( data->path, ( gchar * ) ip->data );
+		g_debug( "nagp_reader_read_done_action: loading profile=%s", ( gchar * ) ip->data );
+		read_done_action_load_profile( provider, data, profile_path, messages );
+		list_profiles = na_core_utils_slist_remove_ascii( list_profiles, profile_path );
+		g_free( profile_path );
+	}
+
+	/* append other profiles
+	 * this is mandatory for pre-2.29 actions which introduced order of profiles
+	 */
+	for( ip = list_profiles ; ip ; ip = ip->next ){
+		g_debug( "nagp_reader_read_done_action: loading profile=%s", ( gchar * ) ip->data );
+		read_done_action_load_profile( provider, data, ( const gchar * ) ip->data, messages );
+	}
+}
+
+static void
+read_done_action_load_profile( const NAIFactoryProvider *provider, ReaderData *data, const gchar *path, GSList **messages )
+{
+	gchar *id;
+	ReaderData *profile_data;
+
+	NAObjectProfile *profile = na_object_profile_new();
+
+	id = g_path_get_basename( path );
+	na_object_set_id( profile, id );
+	g_free( id );
+
+	profile_data = g_new0( ReaderData, 1 );
+	profile_data->parent = data->parent;
+	profile_data->path = ( gchar * ) path;
+
+	na_ifactory_provider_read_item(
+			NA_IFACTORY_PROVIDER( provider ),
+			profile_data,
+			NA_IFACTORY_OBJECT( profile ),
+			messages );
+
+	g_free( profile_data );
+}
+
+static void
+read_done_profile( const NAIFactoryProvider *provider, NAObjectProfile *profile, ReaderData *data, GSList **messages )
+{
+	na_object_attach_profile( data->parent, profile );
+}
+
+#if 0
 /*
  * load and set the properties of the specified action
  * at least we must have a label, as all other entries can have
@@ -448,6 +649,62 @@ read_object_item_properties( NagpGConfProvider *provider, GSList *entries, NAObj
 	}
 	na_object_set_readonly( item, !writable );
 }
+#endif
+
+static NADataBoxed *
+get_boxed_from_path( const NagpGConfProvider *provider, const gchar *path, ReaderData *reader_data, const NADataDef *def )
+{
+	static const gchar *thisfn = "nagp_reader_get_boxed_from_path";
+	NADataBoxed *boxed;
+	gboolean have_entry;
+	gchar *str_value;
+	gboolean bool_value;
+	GSList *slist_value;
+	gint int_value;
+
+	boxed = NULL;
+	have_entry = na_gconf_utils_has_entry( provider->private->gconf, path, def->gconf_entry );
+
+	if( have_entry ){
+		boxed = na_data_boxed_new( def );
+		gchar *entry_path = gconf_concat_dir_and_key( path, def->gconf_entry );
+
+		switch( def->type ){
+
+			case NAFD_TYPE_STRING:
+			case NAFD_TYPE_LOCALE_STRING:
+				str_value = na_gconf_utils_read_string( provider->private->gconf, entry_path, FALSE, NULL );
+				na_data_boxed_set_from_string( boxed, str_value );
+				g_free( str_value );
+				break;
+
+			case NAFD_TYPE_BOOLEAN:
+				bool_value = na_gconf_utils_read_bool( provider->private->gconf, entry_path, FALSE, FALSE );
+				na_data_boxed_set_from_void( boxed, GUINT_TO_POINTER( bool_value ));
+				break;
+
+			case NAFD_TYPE_STRING_LIST:
+				slist_value = na_gconf_utils_read_string_list( provider->private->gconf, entry_path );
+				na_data_boxed_set_from_void( boxed, slist_value );
+				na_core_utils_slist_free( slist_value );
+				break;
+
+			case NAFD_TYPE_UINT:
+				int_value = na_gconf_utils_read_int( provider->private->gconf, entry_path, FALSE, 0 );
+				na_data_boxed_set_from_void( boxed, GUINT_TO_POINTER( int_value ));
+				break;
+
+			default:
+				g_warning( "%s: unknown type=%u for %s", thisfn, def->type, def->name );
+				g_free( boxed );
+				boxed = NULL;
+		}
+
+		g_free( entry_path );
+	}
+
+	return( boxed );
+}
 
 /*
  * key must be an existing entry (not a dir) to get a relevant return
diff --git a/src/io-gconf/nagp-reader.h b/src/io-gconf/nagp-reader.h
index 6b48523..fc3693e 100644
--- a/src/io-gconf/nagp-reader.h
+++ b/src/io-gconf/nagp-reader.h
@@ -35,7 +35,10 @@
 
 G_BEGIN_DECLS
 
-GList *nagp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages );
+GList       *nagp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages );
+
+NADataBoxed *nagp_reader_read_data( const NAIFactoryProvider *provider, void *reader_data, const NAIFactoryObject *object, const NADataDef *def, GSList **messages );
+void         nagp_reader_read_done( const NAIFactoryProvider *provider, void *reader_data, const NAIFactoryObject *object, GSList **messages  );
 
 G_END_DECLS
 
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index 28e5f26..9e0d652 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -92,9 +92,10 @@ struct NactAssistantImportClassPrivate {
 /* private instance data
  */
 struct NactAssistantImportPrivate {
-	gboolean  dispose_has_run;
-	GSList   *results;
-	GList    *items;
+	gboolean     dispose_has_run;
+	GConfClient *gconf;
+	GSList      *results;
+	GList       *items;
 };
 
 static BaseAssistantClass *st_parent_class = NULL;
@@ -205,7 +206,6 @@ instance_init( GTypeInstance *instance, gpointer klass )
 
 	self->private = g_new0( NactAssistantImportPrivate, 1 );
 
-	self->private->dispose_has_run = FALSE;
 	self->private->results = NULL;
 
 	base_window_signal_connect(
@@ -219,6 +219,10 @@ instance_init( GTypeInstance *instance, gpointer klass )
 			G_OBJECT( instance ),
 			BASE_WINDOW_SIGNAL_RUNTIME_INIT,
 			G_CALLBACK( on_runtime_init_dialog ));
+
+	self->private->gconf = gconf_client_get_default();
+
+	self->private->dispose_has_run = FALSE;
 }
 
 static void
@@ -235,6 +239,8 @@ instance_dispose( GObject *window )
 
 		self->private->dispose_has_run = TRUE;
 
+		g_object_unref( self->private->gconf );
+
 		/* chain up to the parent class */
 		if( G_OBJECT_CLASS( st_parent_class )->dispose ){
 			G_OBJECT_CLASS( st_parent_class )->dispose( window );
@@ -477,12 +483,10 @@ runtime_init_duplicates( NactAssistantImport *window, GtkAssistant *assistant )
 	static const gchar *thisfn = "nact_assistant_import_runtime_init_duplicates";
 	GtkWidget *page;
 	guint mode;
-	GConfClient *gconf;
 
 	g_debug( "%s: window=%p", thisfn, ( void * ) window );
 
-	gconf = gconf_client_get_default();
-	mode = na_iprefs_get_import_mode( gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE );
+	mode = na_iprefs_get_import_mode( window->private->gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE );
 	set_import_mode( window, mode );
 
 	page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_DUPLICATES );
@@ -778,7 +782,6 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 	ImportUriStruct *str;
 	GFile *file;
 	guint mode;
-	GConfClient *gconf;
 
 	g_debug( "%s: window=%p, assistant=%p, page=%p",
 			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
@@ -842,8 +845,7 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 	g_free( text );
 
 	mode = get_import_mode( window );
-	gconf = gconf_client_get_default();
-	na_iprefs_set_import_mode( gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE, mode );
+	na_iprefs_set_import_mode( window->private->gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE, mode );
 
 	gtk_assistant_set_page_complete( assistant, page, TRUE );
 	base_assistant_set_warn_on_cancel( BASE_ASSISTANT( window ), FALSE );
diff --git a/src/nact/nact-iprefs.c b/src/nact/nact-iprefs.c
index ddec69e..92a69e8 100644
--- a/src/nact/nact-iprefs.c
+++ b/src/nact/nact-iprefs.c
@@ -123,6 +123,8 @@ interface_base_finalize( NactIPrefsInterface *klass )
 
 		st_finalized = TRUE;
 
+		g_object_unref( klass->private->client );
+
 		g_free( klass->private );
 	}
 }
diff --git a/src/nact/nact-preferences-editor.c b/src/nact/nact-preferences-editor.c
index cccea6f..97187c0 100644
--- a/src/nact/nact-preferences-editor.c
+++ b/src/nact/nact-preferences-editor.c
@@ -52,7 +52,8 @@ struct NactPreferencesEditorClassPrivate {
 /* private instance data
  */
 struct NactPreferencesEditorPrivate {
-	gboolean dispose_has_run;
+	gboolean     dispose_has_run;
+	GConfClient *gconf;
 };
 
 static GObjectClass *st_parent_class = NULL;
@@ -169,6 +170,8 @@ instance_init( GTypeInstance *instance, gpointer klass )
 			BASE_WINDOW_SIGNAL_ALL_WIDGETS_SHOWED,
 			G_CALLBACK( on_base_all_widgets_showed));
 
+	self->private->gconf = gconf_client_get_default();
+
 	self->private->dispose_has_run = FALSE;
 }
 
@@ -186,6 +189,8 @@ instance_dispose( GObject *dialog )
 
 		self->private->dispose_has_run = TRUE;
 
+		g_object_unref( self->private->gconf );
+
 		nact_schemes_list_dispose( BASE_WINDOW( self ));
 		nact_providers_list_dispose( BASE_WINDOW( self ));
 
@@ -305,7 +310,6 @@ on_base_runtime_init_dialog( NactPreferencesEditor *editor, gpointer user_data )
 	GtkWidget *button;
 	gboolean esc_quit, esc_confirm;
 	GtkTreeView *listview;
-	GConfClient *gconf;
 
 	g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
 
@@ -370,8 +374,7 @@ on_base_runtime_init_dialog( NactPreferencesEditor *editor, gpointer user_data )
 
 	/* third tab: import tool
 	 */
-	gconf = gconf_client_get_default();
-	import_mode = na_iprefs_get_import_mode( gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE );
+	import_mode = na_iprefs_get_import_mode( editor->private->gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE );
 	switch( import_mode ){
 		case IMPORTER_MODE_ASK:
 			button = base_window_get_widget( BASE_WINDOW( editor ), "PrefsAskButton" );
@@ -474,7 +477,6 @@ save_preferences( NactPreferencesEditor *editor )
 	GtkWidget *container;
 	GQuark export_format;
 	gboolean esc_quit, esc_confirm;
-	GConfClient *gconf;
 
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( editor )));
 	updater = nact_application_get_updater( application );
@@ -545,8 +547,7 @@ save_preferences( NactPreferencesEditor *editor )
 			}
 		}
 	}
-	gconf = gconf_client_get_default();
-	na_iprefs_set_import_mode( gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE, import_mode );
+	na_iprefs_set_import_mode( editor->private->gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE, import_mode );
 
 	/* fourth tab: export tool
 	 */
diff --git a/src/nact/nact-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c
index 79649c2..3a33101 100644
--- a/src/nact/nact-tree-model-dnd.c
+++ b/src/nact/nact-tree-model-dnd.c
@@ -772,6 +772,7 @@ drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selec
 	uri_list = g_slist_reverse( na_core_utils_slist_from_split(( const gchar * ) selection_data->data, "\n" ));
 	gconf = gconf_client_get_default();
 	import_mode = na_iprefs_get_import_mode( gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE );
+	g_object_unref( gconf );
 	object_list = NULL;
 
 	for( is = uri_list ; is ; is = is->next ){
diff --git a/src/utils/nautilus-actions-schemas.c b/src/utils/nautilus-actions-schemas.c
index 1c7e573..19a7706 100644
--- a/src/utils/nautilus-actions-schemas.c
+++ b/src/utils/nautilus-actions-schemas.c
@@ -213,6 +213,7 @@ write_to_gconf( gchar **msg )
 	g_free( prefix_config );
 
 	gconf_client_suggest_sync( gconf, NULL );
+	g_object_unref( gconf );
 	return( ret );
 }
 



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