[nautilus-actions] Let the user be asked for his preferred export format



commit 42a98f76f66f6b87c0cf89aae57198d4b9af35bb
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sat Oct 17 15:12:40 2009 +0200

    Let the user be asked for his preferred export format

 ChangeLog                                |   16 ++
 src/common/na-iprefs.h                   |    4 +-
 src/common/na-xml-writer.c               |    3 +
 src/nact/Makefile.am                     |    2 +
 src/nact/base-window.c                   |   14 +-
 src/nact/base-window.h                   |    2 +-
 src/nact/nact-assistant-export-ask.c     |  431 ++++++++++++++++++++++++++++++
 src/nact/nact-assistant-export-ask.h     |   79 ++++++
 src/nact/nact-assistant-export.c         |   25 ++-
 src/nact/nact-assistant-export.ui        |  248 +++++++++++++++++-
 src/nact/nact-assistant-import-ask.c     |   10 +-
 src/nact/nautilus-actions-config-tool.ui |   13 +-
 12 files changed, 821 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ccaeb9d..3b405ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2009-10-16 Pierre Wieser <pwieser trychlos org>
 
+	Let the user be asked when exporting actions.
+
+	* src/nact/base-window.c (instance_dispose):
+	Fix hiding widgets when toplevel has not been initialized.
+	(base_window_run): Now returns a boolean.
+
+	* src/nact/nact-assistant-export-ask.c:
+	* src/nact/nact-assistant-export-ask.h: New files.
+
+	* src/nact/Makefile.am:
+	* src/nact/nact-assistant-export.ui: Updated accordingly.
+
+	* src/nact/nact-assistant-export.c:
+	Ask the user if needed.
+	Reread the current export format for each action.
+
 	Record last export format as a preference.
 
 	* src/common/na-iprefs.c:
diff --git a/src/common/na-iprefs.h b/src/common/na-iprefs.h
index 656c1a0..0f30c50 100644
--- a/src/common/na-iprefs.h
+++ b/src/common/na-iprefs.h
@@ -48,6 +48,7 @@ G_BEGIN_DECLS
 /* GConf Preference keys managed by IPrefs interface
  */
 #define IPREFS_EXPORT_FORMAT				"export-format"
+#define IPREFS_EXPORT_ASK_LAST_FORMAT		"export-ask-user-last-format"
 #define IPREFS_IMPORT_ACTIONS_IMPORT_MODE	"import-mode"
 #define IPREFS_IMPORT_ASK_LAST_MODE			"import-ask-user-last-mode"
 
@@ -76,7 +77,8 @@ enum {
  * introduced in v 1.11
  */
 enum {
-	IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V1 = 1,
+	IPREFS_EXPORT_NO_EXPORT = 1,
+	IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V1,
 	IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V2,
 	IPREFS_EXPORT_FORMAT_GCONF_SCHEMA,
 	IPREFS_EXPORT_FORMAT_GCONF_ENTRY,
diff --git a/src/common/na-xml-writer.c b/src/common/na-xml-writer.c
index 971e8a0..271b790 100644
--- a/src/common/na-xml-writer.c
+++ b/src/common/na-xml-writer.c
@@ -328,6 +328,9 @@ na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint fo
 				filename = g_strdup( folder );
 			}
 			break;
+
+		default:
+			g_return_val_if_reached( NULL );
 	}
 
 	g_assert( filename || folder == NULL );
diff --git a/src/nact/Makefile.am b/src/nact/Makefile.am
index e5194a8..61ea31e 100644
--- a/src/nact/Makefile.am
+++ b/src/nact/Makefile.am
@@ -64,6 +64,8 @@ nautilus_actions_config_tool_SOURCES = \
 	nact-application.h									\
 	nact-assistant-export.c								\
 	nact-assistant-export.h								\
+	nact-assistant-export-ask.c							\
+	nact-assistant-export-ask.h							\
 	nact-assistant-import.c								\
 	nact-assistant-import.h								\
 	nact-assistant-import-ask.c							\
diff --git a/src/nact/base-window.c b/src/nact/base-window.c
index 86a18c6..9850ca4 100644
--- a/src/nact/base-window.c
+++ b/src/nact/base-window.c
@@ -500,11 +500,15 @@ instance_dispose( GObject *window )
 		} else if( GTK_IS_ASSISTANT( self->private->toplevel_window )){
 			g_debug( "%s: quitting assistant", thisfn );
 			gtk_main_quit();
-			gtk_widget_hide_all( GTK_WIDGET( self->private->toplevel_window ));
+			if( is_toplevel_initialized( self, self->private->toplevel_window )){
+				gtk_widget_hide_all( GTK_WIDGET( self->private->toplevel_window ));
+			}
 
 		} else {
 			g_debug( "%s: quitting dialog", thisfn );
-			gtk_widget_hide_all( GTK_WIDGET( self->private->toplevel_window ));
+			if( is_toplevel_initialized( self, self->private->toplevel_window )){
+				gtk_widget_hide_all( GTK_WIDGET( self->private->toplevel_window ));
+			}
 		}
 
 		self->private->dispose_has_run = TRUE;
@@ -620,7 +624,7 @@ base_window_init( BaseWindow *window )
  *
  * Runs the window.
  */
-void
+gboolean
 base_window_run( BaseWindow *window )
 {
 	static const gchar *thisfn = "base_window_run";
@@ -628,7 +632,7 @@ base_window_run( BaseWindow *window )
 	gboolean run_ok;
 	gint code;
 
-	g_return_if_fail( BASE_IS_WINDOW( window ));
+	g_return_val_if_fail( BASE_IS_WINDOW( window ), FALSE );
 
 	run_ok = TRUE;
 
@@ -678,6 +682,8 @@ base_window_run( BaseWindow *window )
 			while( !v_dialog_response( GTK_DIALOG( this_dialog ), code, window ));
 		}
 	}
+
+	return( run_ok );
 }
 
 /**
diff --git a/src/nact/base-window.h b/src/nact/base-window.h
index 5e10f7d..d36515a 100644
--- a/src/nact/base-window.h
+++ b/src/nact/base-window.h
@@ -75,7 +75,7 @@ G_BEGIN_DECLS
 #define BASE_WINDOW_SIGNAL_ALL_WIDGETS_SHOWED		"nact-base-window-all-widgets-showed"
 
 gboolean         base_window_init( BaseWindow *window );
-void             base_window_run( BaseWindow *window );
+gboolean         base_window_run( BaseWindow *window );
 
 BaseApplication *base_window_get_application( BaseWindow *window );
 GtkWindow       *base_window_get_named_toplevel( BaseWindow *window, const gchar *name );
diff --git a/src/nact/nact-assistant-export-ask.c b/src/nact/nact-assistant-export-ask.c
new file mode 100644
index 0000000..52bffcd
--- /dev/null
+++ b/src/nact/nact-assistant-export-ask.c
@@ -0,0 +1,431 @@
+/*
+ * 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 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 <glib/gi18n.h>
+
+#include <common/na-iprefs.h>
+#include <common/na-object-api.h>
+
+#include <runtime/na-pivot.h>
+
+#include "nact-application.h"
+#include "nact-assistant-export-ask.h"
+
+/* private class data
+ */
+struct NactAssistantExportAskClassPrivate {
+	void *empty;						/* so that gcc -pedantic is happy */
+};
+
+/* private instance data
+ */
+struct NactAssistantExportAskPrivate {
+	gboolean        dispose_has_run;
+	BaseWindow     *parent;
+	NAObjectAction *action;
+	gint            format;
+};
+
+static BaseDialogClass *st_parent_class = NULL;
+
+static GType    register_type( void );
+static void     class_init( NactAssistantExportAskClass *klass );
+static void     instance_init( GTypeInstance *instance, gpointer klass );
+static void     instance_dispose( GObject *dialog );
+static void     instance_finalize( GObject *dialog );
+
+static NactAssistantExportAsk *assistant_export_ask_new( BaseWindow *parent );
+
+static gchar   *base_get_iprefs_window_id( BaseWindow *window );
+static gchar   *base_get_dialog_name( BaseWindow *window );
+static gchar   *base_get_ui_filename( BaseWindow *dialog );
+static void     on_base_initial_load_dialog( NactAssistantExportAsk *editor, gpointer user_data );
+static void     on_base_runtime_init_dialog( NactAssistantExportAsk *editor, gpointer user_data );
+static void     on_base_all_widgets_showed( NactAssistantExportAsk *editor, gpointer user_data );
+static void     on_cancel_clicked( GtkButton *button, NactAssistantExportAsk *editor );
+static void     on_ok_clicked( GtkButton *button, NactAssistantExportAsk *editor );
+static gint     get_format( NactAssistantExportAsk *editor );
+static gboolean base_dialog_response( GtkDialog *dialog, gint code, BaseWindow *window );
+
+GType
+nact_assistant_export_ask_get_type( void )
+{
+	static GType dialog_type = 0;
+
+	if( !dialog_type ){
+		dialog_type = register_type();
+	}
+
+	return( dialog_type );
+}
+
+static GType
+register_type( void )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_register_type";
+	GType type;
+
+	static GTypeInfo info = {
+		sizeof( NactAssistantExportAskClass ),
+		( GBaseInitFunc ) NULL,
+		( GBaseFinalizeFunc ) NULL,
+		( GClassInitFunc ) class_init,
+		NULL,
+		NULL,
+		sizeof( NactAssistantExportAsk ),
+		0,
+		( GInstanceInitFunc ) instance_init
+	};
+
+	g_debug( "%s", thisfn );
+
+	type = g_type_register_static( BASE_DIALOG_TYPE, "NactAssistantExportAsk", &info, 0 );
+
+	return( type );
+}
+
+static void
+class_init( NactAssistantExportAskClass *klass )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_class_init";
+	GObjectClass *object_class;
+	BaseWindowClass *base_class;
+
+	g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
+
+	st_parent_class = g_type_class_peek_parent( klass );
+
+	object_class = G_OBJECT_CLASS( klass );
+	object_class->dispose = instance_dispose;
+	object_class->finalize = instance_finalize;
+
+	klass->private = g_new0( NactAssistantExportAskClassPrivate, 1 );
+
+	base_class = BASE_WINDOW_CLASS( klass );
+	base_class->dialog_response = base_dialog_response;
+	base_class->get_toplevel_name = base_get_dialog_name;
+	base_class->get_iprefs_window_id = base_get_iprefs_window_id;
+	base_class->get_ui_filename = base_get_ui_filename;
+}
+
+static void
+instance_init( GTypeInstance *instance, gpointer klass )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_instance_init";
+	NactAssistantExportAsk *self;
+
+	g_debug( "%s: instance=%p, klass=%p", thisfn, ( void * ) instance, ( void * ) klass );
+	g_return_if_fail( NACT_IS_ASSISTANT_EXPORT_ASK( instance ));
+	self = NACT_ASSISTANT_EXPORT_ASK( instance );
+
+	self->private = g_new0( NactAssistantExportAskPrivate, 1 );
+
+	base_window_signal_connect(
+			BASE_WINDOW( instance ),
+			G_OBJECT( instance ),
+			BASE_WINDOW_SIGNAL_INITIAL_LOAD,
+			G_CALLBACK( on_base_initial_load_dialog ));
+
+	base_window_signal_connect(
+			BASE_WINDOW( instance ),
+			G_OBJECT( instance ),
+			BASE_WINDOW_SIGNAL_RUNTIME_INIT,
+			G_CALLBACK( on_base_runtime_init_dialog ));
+
+	base_window_signal_connect(
+			BASE_WINDOW( instance ),
+			G_OBJECT( instance ),
+			BASE_WINDOW_SIGNAL_ALL_WIDGETS_SHOWED,
+			G_CALLBACK( on_base_all_widgets_showed));
+
+	self->private->dispose_has_run = FALSE;
+}
+
+static void
+instance_dispose( GObject *dialog )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_instance_dispose";
+	NactAssistantExportAsk *self;
+
+	g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );
+	g_return_if_fail( NACT_IS_ASSISTANT_EXPORT_ASK( dialog ));
+	self = NACT_ASSISTANT_EXPORT_ASK( dialog );
+
+	if( !self->private->dispose_has_run ){
+
+		self->private->dispose_has_run = TRUE;
+
+		/* chain up to the parent class */
+		if( G_OBJECT_CLASS( st_parent_class )->dispose ){
+			G_OBJECT_CLASS( st_parent_class )->dispose( dialog );
+		}
+	}
+}
+
+static void
+instance_finalize( GObject *dialog )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_instance_finalize";
+	NactAssistantExportAsk *self;
+
+	g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );
+	g_return_if_fail( NACT_IS_ASSISTANT_EXPORT_ASK( dialog ));
+	self = NACT_ASSISTANT_EXPORT_ASK( dialog );
+
+	g_free( self->private );
+
+	/* chain call to parent class */
+	if( G_OBJECT_CLASS( st_parent_class )->finalize ){
+		G_OBJECT_CLASS( st_parent_class )->finalize( dialog );
+	}
+}
+
+/*
+ * Returns a newly allocated NactAssistantExportAsk object.
+ */
+static NactAssistantExportAsk *
+assistant_export_ask_new( BaseWindow *parent )
+{
+	return( g_object_new( NACT_ASSISTANT_EXPORT_ASK_TYPE, BASE_WINDOW_PROP_PARENT, parent, NULL ));
+}
+
+/**
+ * nact_assistant_export_ask_run:
+ * @parent: the NactAssistant parent of this dialog.
+ *
+ * Initializes and runs the dialog.
+ *
+ * Returns: the mode choosen by the user ; it defaults to 'none' (no export).
+ *
+ * When the user selects 'Keep same choice without asking me', this choice
+ * becomes his preference export format.
+ */
+gint
+nact_assistant_export_ask_user( BaseWindow *parent, NAObjectAction *action )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_run";
+	NactApplication *application;
+	NAPivot *pivot;
+	NactAssistantExportAsk *editor;
+	gint format;
+
+	g_debug( "%s: parent=%p", thisfn, ( void * ) parent );
+	g_return_val_if_fail( BASE_IS_WINDOW( parent ), IPREFS_EXPORT_NO_EXPORT );
+
+	application = NACT_APPLICATION( base_window_get_application( parent ));
+	g_return_val_if_fail( NACT_IS_APPLICATION( application ), IPREFS_EXPORT_NO_EXPORT );
+
+	pivot = nact_application_get_pivot( application );
+	g_return_val_if_fail( NA_IS_PIVOT( pivot ), IPREFS_EXPORT_NO_EXPORT );
+
+	editor = assistant_export_ask_new( parent );
+	g_object_set( G_OBJECT( editor ), BASE_WINDOW_PROP_HAS_OWN_BUILDER, TRUE, NULL );
+
+	editor->private->parent = parent;
+	editor->private->action = action;
+	editor->private->format = na_iprefs_get_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_ASK_LAST_FORMAT );
+
+	if( !base_window_run( BASE_WINDOW( editor ))){
+		editor->private->format = IPREFS_EXPORT_NO_EXPORT;
+	}
+
+	na_iprefs_set_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_ASK_LAST_FORMAT, editor->private->format );
+	format = editor->private->format;
+	g_object_unref( editor );
+
+	return( format );
+}
+
+static gchar *
+base_get_iprefs_window_id( BaseWindow *window )
+{
+	return( g_strdup( "export-ask-user" ));
+}
+
+static gchar *
+base_get_dialog_name( BaseWindow *window )
+{
+	return( g_strdup( "AssistantExportAsk" ));
+}
+
+static gchar *
+base_get_ui_filename( BaseWindow *dialog )
+{
+	return( g_strdup( PKGDATADIR "/nact-assistant-export.ui" ));
+}
+
+static void
+on_base_initial_load_dialog( NactAssistantExportAsk *editor, gpointer user_data )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_on_initial_load_dialog";
+
+	g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
+	g_return_if_fail( NACT_IS_ASSISTANT_EXPORT_ASK( editor ));
+}
+
+static void
+on_base_runtime_init_dialog( NactAssistantExportAsk *editor, gpointer user_data )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_on_runtime_init_dialog";
+	gchar *action_label;
+	gchar *label;
+	GtkWidget *widget;
+	GtkWidget *button;
+
+	g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
+	g_return_if_fail( NACT_IS_ASSISTANT_EXPORT_ASK( editor ));
+
+	action_label = na_object_get_label( editor->private->action );
+
+	/* i18n: The action <action_label> is about to be exported */
+	label = g_strdup_printf( _( "The action \"%s\" is about to be exported." ), action_label );
+
+	widget = base_window_get_widget( BASE_WINDOW( editor ), "ExportAskLabel1" );
+	gtk_label_set_text( GTK_LABEL( widget ), label );
+	g_free( label );
+
+	switch( editor->private->format ){
+		case IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V1:
+			button = base_window_get_widget( BASE_WINDOW( editor ), "AskGConfSchemaV1Button" );
+			break;
+
+		case IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V2:
+			button = base_window_get_widget( BASE_WINDOW( editor ), "AskGConfSchemaV2Button" );
+			break;
+
+		case IPREFS_EXPORT_FORMAT_GCONF_ENTRY:
+		default:
+			button = base_window_get_widget( BASE_WINDOW( editor ), "AskGConfEntryButton" );
+			break;
+	}
+	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
+
+	button = base_window_get_widget( BASE_WINDOW( editor ), "AskKeepChoiceButton" );
+	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), FALSE );
+
+	base_window_signal_connect_by_name(
+			BASE_WINDOW( editor ),
+			"CancelButton",
+			"clicked",
+			G_CALLBACK( on_cancel_clicked ));
+
+	base_window_signal_connect_by_name(
+			BASE_WINDOW( editor ),
+			"OKButton",
+			"clicked",
+			G_CALLBACK( on_ok_clicked ));
+}
+
+static void
+on_base_all_widgets_showed( NactAssistantExportAsk *editor, gpointer user_data )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_on_all_widgets_showed";
+
+	g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
+	g_return_if_fail( NACT_IS_ASSISTANT_EXPORT_ASK( editor ));
+}
+
+static void
+on_cancel_clicked( GtkButton *button, NactAssistantExportAsk *editor )
+{
+	GtkWindow *toplevel = base_window_get_toplevel( BASE_WINDOW( editor ));
+	gtk_dialog_response( GTK_DIALOG( toplevel ), GTK_RESPONSE_CLOSE );
+}
+
+static void
+on_ok_clicked( GtkButton *button, NactAssistantExportAsk *editor )
+{
+	GtkWindow *toplevel = base_window_get_toplevel( BASE_WINDOW( editor ));
+	gtk_dialog_response( GTK_DIALOG( toplevel ), GTK_RESPONSE_OK );
+}
+
+static gint
+get_format( NactAssistantExportAsk *editor )
+{
+	gint export_format;
+	NactApplication *application;
+	NAPivot *pivot;
+	GtkWidget *button;
+	gboolean keep;
+
+	export_format = IPREFS_EXPORT_FORMAT_GCONF_ENTRY;
+	button = base_window_get_widget( BASE_WINDOW( editor ), "AskGConfSchemaV1Button" );
+	if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ))){
+		export_format = IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V1;
+	} else {
+		button = base_window_get_widget( BASE_WINDOW( editor ), "AskGConfSchemaV2Button" );
+		if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ))){
+			export_format = IPREFS_EXPORT_FORMAT_GCONF_SCHEMA_V2;
+		}
+	}
+
+	button = base_window_get_widget( BASE_WINDOW( editor ), "AskKeepChoiceButton" );
+	keep = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ));
+	if( keep ){
+		application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( editor )));
+		pivot = nact_application_get_pivot( application );
+		na_iprefs_set_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_FORMAT, export_format );
+	}
+
+	return( export_format );
+}
+
+static gboolean
+base_dialog_response( GtkDialog *dialog, gint code, BaseWindow *window )
+{
+	static const gchar *thisfn = "nact_assistant_export_ask_on_dialog_response";
+	NactAssistantExportAsk *editor;
+
+	g_debug( "%s: dialog=%p, code=%d, window=%p", thisfn, ( void * ) dialog, code, ( void * ) window );
+	g_assert( NACT_IS_ASSISTANT_EXPORT_ASK( window ));
+	editor = NACT_ASSISTANT_EXPORT_ASK( window );
+
+	switch( code ){
+		case GTK_RESPONSE_NONE:
+		case GTK_RESPONSE_DELETE_EVENT:
+		case GTK_RESPONSE_CLOSE:
+		case GTK_RESPONSE_CANCEL:
+
+			editor->private->format = IPREFS_EXPORT_NO_EXPORT;
+			return( TRUE );
+			break;
+
+		case GTK_RESPONSE_OK:
+			editor->private->format = get_format( editor );
+			return( TRUE );
+			break;
+	}
+
+	return( FALSE );
+}
diff --git a/src/nact/nact-assistant-export-ask.h b/src/nact/nact-assistant-export-ask.h
new file mode 100644
index 0000000..6458d09
--- /dev/null
+++ b/src/nact/nact-assistant-export-ask.h
@@ -0,0 +1,79 @@
+/*
+ * 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 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 __NACT_ASSISTANT_EXPORT_ASK_H__
+#define __NACT_ASSISTANT_EXPORT_ASK_H__
+
+/**
+ * SECTION: nact_assistant_export_ask
+ * @short_description: #NactAssistantExportAsk class definition.
+ * @include: nact/nact-assistant-export-ask.h
+ *
+ * This class is derived from BaseDialog.
+ * It is ran each time an action is to be exported, and the user want
+ * to be ask to choose the export format.
+ */
+
+#include <runtime/na-object-action-class.h>
+
+#include "base-dialog.h"
+
+G_BEGIN_DECLS
+
+#define NACT_ASSISTANT_EXPORT_ASK_TYPE					( nact_assistant_export_ask_get_type())
+#define NACT_ASSISTANT_EXPORT_ASK( object )				( G_TYPE_CHECK_INSTANCE_CAST( object, NACT_ASSISTANT_EXPORT_ASK_TYPE, NactAssistantExportAsk ))
+#define NACT_ASSISTANT_EXPORT_ASK_CLASS( klass )		( G_TYPE_CHECK_CLASS_CAST( klass, NACT_ASSISTANT_EXPORT_ASK_TYPE, NactAssistantExportAskClass ))
+#define NACT_IS_ASSISTANT_EXPORT_ASK( object )			( G_TYPE_CHECK_INSTANCE_TYPE( object, NACT_ASSISTANT_EXPORT_ASK_TYPE ))
+#define NACT_IS_ASSISTANT_EXPORT_ASK_CLASS( klass )		( G_TYPE_CHECK_CLASS_TYPE(( klass ), NACT_ASSISTANT_EXPORT_ASK_TYPE ))
+#define NACT_ASSISTANT_EXPORT_ASK_GET_CLASS( object )	( G_TYPE_INSTANCE_GET_CLASS(( object ), NACT_ASSISTANT_EXPORT_ASK_TYPE, NactAssistantExportAskClass ))
+
+typedef struct NactAssistantExportAskPrivate NactAssistantExportAskPrivate;
+
+typedef struct {
+	BaseDialog                     parent;
+	NactAssistantExportAskPrivate *private;
+}
+	NactAssistantExportAsk;
+
+typedef struct NactAssistantExportAskClassPrivate NactAssistantExportAskClassPrivate;
+
+typedef struct {
+	BaseDialogClass                     parent;
+	NactAssistantExportAskClassPrivate *private;
+}
+	NactAssistantExportAskClass;
+
+GType nact_assistant_export_ask_get_type( void );
+
+gint  nact_assistant_export_ask_user( BaseWindow *window, NAObjectAction *action );
+
+G_END_DECLS
+
+#endif /* __NACT_ASSISTANT_EXPORT_ASK_H__ */
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 072f854..57a7b6f 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -48,6 +48,7 @@
 #include "nact-application.h"
 #include "nact-main-window.h"
 #include "nact-assistant-export.h"
+#include "nact-assistant-export-ask.h"
 #include "nact-iactions-list.h"
 
 /* Export Assistant
@@ -85,7 +86,6 @@ struct NactAssistantExportPrivate {
 	GSList         *fnames;
 	gint            errors;
 	gchar          *reason;
-	gint            format;
 };
 
 #define IPREFS_EXPORT_ACTIONS_FOLDER_URI		"export-folder-uri"
@@ -763,7 +763,6 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
 			break;
 	}
 	na_iprefs_set_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_FORMAT, format );
-	window->private->format = format;
 
 	tmp = g_strdup_printf( "%s\n\n<b>%s</b>\n\n%s", text, label1, label2 );
 	g_free( label2 );
@@ -787,23 +786,41 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 {
 	static const gchar *thisfn = "nact_assistant_export_on_apply";
 	NactAssistantExport *window;
+	NactApplication *application;
+	NAPivot *pivot;
 	GList *actions, *ia;
 	gchar *msg = NULL;
 	gchar *reason = NULL;
 	gchar *tmp, *fname;
 	NAObjectAction *action;
+	gint format;
 
 	g_debug( "%s: window=%p, assistant=%p", thisfn, ( void * ) wnd, ( void * ) assistant );
 	g_assert( NACT_IS_ASSISTANT_EXPORT( wnd ));
 	window = NACT_ASSISTANT_EXPORT( wnd );
 
+	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	pivot = nact_application_get_pivot( application );
+
 	actions = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
 
 	g_assert( window->private->uri && strlen( window->private->uri ));
 
 	for( ia = actions ; ia ; ia = ia->next ){
 		action = NA_OBJECT_ACTION( ia->data );
-		fname = na_xml_writer_export( action, window->private->uri, window->private->format, &msg );
+		fname = NULL;
+
+		format = na_iprefs_get_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_FORMAT );
+		if( format == IPREFS_EXPORT_FORMAT_ASK ){
+			format = nact_assistant_export_ask_user( BASE_WINDOW( wnd ), action );
+			if( format == IPREFS_EXPORT_NO_EXPORT ){
+				msg = g_strdup( _( "Export canceled due to user action." ));
+			}
+		}
+
+		if( format != IPREFS_EXPORT_NO_EXPORT ){
+			fname = na_xml_writer_export( action, window->private->uri, format, &msg );
+		}
 
 		if( fname && strlen( fname )){
 			window->private->fnames = g_slist_prepend( window->private->fnames, fname );
@@ -817,7 +834,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 					g_free( reason );
 					reason = tmp;
 				}
-				tmp = g_strdup_printf( "%s%s", reason, msg );
+				tmp = g_strdup_printf( "%s%s", reason ? reason : "", msg );
 				g_free( reason );
 				reason = tmp;
 				g_free( msg );
diff --git a/src/nact/nact-assistant-export.ui b/src/nact/nact-assistant-export.ui
index e77cad7..b389271 100644
--- a/src/nact/nact-assistant-export.ui
+++ b/src/nact/nact-assistant-export.ui
@@ -114,7 +114,10 @@ to extend a selection.</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
-                <property name="active">True</property>
+                <property name="tooltip_text" translatable="yes">This used to be the historical export format.
+The exported file may later be imported via :
+- Import assistant of the Nautilus Actions Configuration Tool,
+- or via the gconftool-2 --import-schema-file command-line tool.</property>
                 <property name="draw_indicator">True</property>
               </object>
               <packing>
@@ -159,8 +162,10 @@ The exported file may later be imported via :
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
+                <property name="tooltip_text" translatable="yes">The exported file may later be imported via :
+- Import assistant of the Nautilus Actions Configuration Tool,
+- or via the gconftool-2 --import-schema-file command-line tool.</property>
                 <property name="xalign">0</property>
-                <property name="active">True</property>
                 <property name="draw_indicator">True</property>
                 <property name="group">ExportSchemaV1Button</property>
               </object>
@@ -205,8 +210,11 @@ The exported file may later be imported via :
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
+                <property name="tooltip_text" translatable="yes">This should be the preferred format for newly exported actions.
+The exported file may later be imported via :
+- Import assistant of the Nautilus Actions Configuration Tool,
+- or via the gconftool-2 --load command-line tool.</property>
                 <property name="xalign">0</property>
-                <property name="active">True</property>
                 <property name="draw_indicator">True</property>
                 <property name="group">ExportSchemaV1Button</property>
               </object>
@@ -243,6 +251,51 @@ The exported file may later be imported via :
             <property name="position">3</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkVBox" id="vbox5">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkRadioButton" id="ExportAskButton">
+                <property name="label" translatable="yes">Ask me.</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="tooltip_text" translatable="yes">You will be asked each time an action is about to be exported.</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">ExportSchemaV1Button</property>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkLabel" id="ExportAskLabel">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">16</property>
+                    <property name="label" translatable="yes">You will be asked each time an action is about to be exported.</property>
+                  </object>
+                  <packing>
+                    <property name="padding">4</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">4</property>
+          </packing>
+        </child>
       </object>
       <packing>
         <property name="title">Selecting the export format</property>
@@ -269,4 +322,193 @@ The exported file may later be imported via :
       </packing>
     </child>
   </object>
+  <object class="GtkDialog" id="AssistantExportAsk">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Exporting an action</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkVBox" id="vbox37">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkVBox" id="vbox39">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="ExportAskLabel1">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">6</property>
+                    <property name="wrap">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label47">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">6</property>
+                    <property name="label" translatable="yes">Which format should I choose to export it ?</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVBox" id="vbox38">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkRadioButton" id="AskGConfSchemaV1Button">
+                    <property name="label" translatable="yes">Export as a GConf schema (v_1) file</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">This used to be the historical export format.
+The exported file may later be imported via :
+- Import assistant of the Nautilus Actions Configuration Tool,
+- or via the gconftool-2 --import-schema-file command-line tool.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="AskGConfSchemaV2Button">
+                    <property name="label" translatable="yes">Export as a GConf _schema (v2) file</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">The exported file may later be imported via :
+- Import assistant of the Nautilus Actions Configuration Tool,
+- or via the gconftool-2 --import-schema-file command-line tool.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">AskGConfSchemaV1Button</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="AskGConfEntryButton">
+                    <property name="label" translatable="yes">Export as a GConf _entry file</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">This should be the preferred format for newly exported actions.
+The exported file may later be imported via :
+- Import assistant of the Nautilus Actions Configuration Tool,
+- or via the gconftool-2 --load command-line tool.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">AskGConfSchemaV1Button</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHSeparator" id="hseparator1">
+                <property name="visible">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVBox" id="vbox40">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkCheckButton" id="AskKeepChoiceButton">
+                    <property name="label" translatable="yes">Re_member my choice in future import operations</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">3</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="CancelButton">
+                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="OKButton">
+                <property name="label" translatable="yes">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">CancelButton</action-widget>
+      <action-widget response="0">OKButton</action-widget>
+    </action-widgets>
+  </object>
 </interface>
diff --git a/src/nact/nact-assistant-import-ask.c b/src/nact/nact-assistant-import-ask.c
index bf8a2cf..804960a 100644
--- a/src/nact/nact-assistant-import-ask.c
+++ b/src/nact/nact-assistant-import-ask.c
@@ -61,11 +61,11 @@ struct NactAssistantImportAskPrivate {
 
 static BaseDialogClass *st_parent_class = NULL;
 
-static GType register_type( void );
-static void  class_init( NactAssistantImportAskClass *klass );
-static void  instance_init( GTypeInstance *instance, gpointer klass );
-static void  instance_dispose( GObject *dialog );
-static void  instance_finalize( GObject *dialog );
+static GType    register_type( void );
+static void     class_init( NactAssistantImportAskClass *klass );
+static void     instance_init( GTypeInstance *instance, gpointer klass );
+static void     instance_dispose( GObject *dialog );
+static void     instance_finalize( GObject *dialog );
 
 static NactAssistantImportAsk *assistant_import_ask_new( BaseWindow *parent );
 
diff --git a/src/nact/nautilus-actions-config-tool.ui b/src/nact/nautilus-actions-config-tool.ui
index 706e7dd..3d94f91 100644
--- a/src/nact/nautilus-actions-config-tool.ui
+++ b/src/nact/nautilus-actions-config-tool.ui
@@ -1017,8 +1017,8 @@ Defining several profiles lets you have several commands, each applying with a d
         <child>
           <object class="GtkFileChooserWidget" id="ImportFileChooser">
             <property name="visible">True</property>
-            <property name="preview_widget_active">False</property>
             <property name="select_multiple">True</property>
+            <property name="preview_widget_active">False</property>
             <property name="use_preview_label">False</property>
             <property name="local_only">False</property>
           </object>
@@ -1062,7 +1062,6 @@ Defining several profiles lets you have several commands, each applying with a d
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="active">True</property>
                         <property name="draw_indicator">True</property>
                       </object>
                       <packing>
@@ -1105,7 +1104,6 @@ The existing action will not be modified.</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="active">True</property>
                         <property name="draw_indicator">True</property>
                         <property name="group">NoImportButton</property>
                       </object>
@@ -1149,7 +1147,6 @@ The existing action will not be modified.</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="active">True</property>
                         <property name="draw_indicator">True</property>
                         <property name="group">NoImportButton</property>
                       </object>
@@ -2400,16 +2397,16 @@ Be warned: this mode may be dangerous. You will not be prompted another time.</p
   </object>
   <object class="GtkSizeGroup" id="CommandLabelSizeGroup">
     <widgets>
-      <widget name="ProfileLabelLabel"/>
-      <widget name="CommandPathLabel"/>
-      <widget name="CommandParametersLabel"/>
       <widget name="CommandExamplePreLabel"/>
+      <widget name="CommandParametersLabel"/>
+      <widget name="CommandPathLabel"/>
+      <widget name="ProfileLabelLabel"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="CommandButtonSizeGroup">
     <widgets>
-      <widget name="CommandPathButton"/>
       <widget name="CommandLegendButton"/>
+      <widget name="CommandPathButton"/>
     </widgets>
   </object>
 </interface>



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