[nautilus-actions] Keep last user choice in import operations
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Keep last user choice in import operations
- Date: Thu, 15 Oct 2009 20:49:41 +0000 (UTC)
commit 7f2a0e74078ac964325922ca7f0acb45c52e6736
Author: pierre <pierre vfedora10 virtuals pwi>
Date: Thu Oct 15 16:23:55 2009 +0200
Keep last user choice in import operations
ChangeLog | 6 +++
data/nautilus-actions.schemas.in | 30 ++++++++++++++-
src/common/na-iprefs.h | 1 +
src/nact/base-window.c | 66 ++++++++++++++++++---------------
src/nact/nact-assistant-import-ask.c | 37 +++++++++++++++++--
5 files changed, 105 insertions(+), 35 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9157a3b..3cca5bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,7 +4,10 @@
* data/nautilus-actions.schemas.in:
Define new 'import-ask-user' preference schema.
+ Define new 'import-ask-user-last-mode' preference schema.
+ Define new 'import-ask-user-keep-mode' preference schema.
Add 'Ask user' new value for 'import-mode' preference.
+ Fix type and default value of 'import-mode'.
* po/POTFILES.in:
* src/nact/Makefile.am:
@@ -17,6 +20,8 @@
Define IPREFS_IMPORT_ASK new import mode.
na_iprefs_get_import_mode, na_iprefs_set_import_mode now take
the preference name as an argument.
+ Define IPREFS_IMPORT_ASK_LAST_MODE, IPREFS_IMPORT_ASK_KEEP_MODE
+ new preferences.
* src/nact/nact-main-window.c
(nact_main_window_action_exists): Renamed as
@@ -26,6 +31,7 @@
* src/nact/nact-assistant-import-ask.c:
* src/nact/nact-assistant-import-ask.h:
New AssistantImportAsk dialog box.
+ Keep the last users's choice to prevent ask too many times.
* src/nact/nact-xml-reader.c (manager_import_mode):
Now may ask the user to know what to do.
diff --git a/data/nautilus-actions.schemas.in b/data/nautilus-actions.schemas.in
index b72fe04..a3b3240 100644
--- a/data/nautilus-actions.schemas.in
+++ b/data/nautilus-actions.schemas.in
@@ -287,6 +287,32 @@ All schemes used by Nautilus can be used here.</long>
</schema>
<schema>
+ <key>/schemas/apps/nautilus-actions/preferences/import-ask-user-keep-mode</key>
+ <owner>nautilus-actions</owner>
+ <type>boolean</type>
+ <locale name="C">
+ <short>Keep the last choosen import mode</short>
+ <long>Whether the last choosen import mode should be kept on next import operations.
+This value is always reinitialized at the first import operation, so that the user may choose another import mode.</long>
+ </locale>
+ <default>false</default>
+ </schema>
+
+ <schema>
+ <key>/schemas/apps/nautilus-actions/preferences/import-ask-user-last-mode</key>
+ <owner>nautilus-actions</owner>
+ <type>string</type>
+ <locale name="C">
+ <short>Last import mode choosen by the user</short>
+ <long>Last import mode choosen by the user when he is asked for in import mode. Possible values are :
+- "NoImport": do not import an action whose UUID already exists,
+- "Renumber": allocate a new UUID if the imported UUID already exists,
+- "Override": override the existing action with the imported one.</long>
+ </locale>
+ <default>NoImport</default>
+ </schema>
+
+ <schema>
<key>/schemas/apps/nautilus-actions/preferences/import-assistant</key>
<owner>nautilus-actions</owner>
<type>list</type>
@@ -312,7 +338,7 @@ All schemes used by Nautilus can be used here.</long>
<schema>
<key>/schemas/apps/nautilus-actions/preferences/import-mode</key>
<owner>nautilus-actions</owner>
- <type>int</type>
+ <type>string</type>
<locale name="C">
<short>Import mode</short>
<long>Last import mode choosen in the Import assistant. Possible values are :
@@ -321,7 +347,7 @@ All schemes used by Nautilus can be used here.</long>
- "Override": override the existing action with the imported one,
- "Ask": ask the user each time.</long>
</locale>
- <default>/tmp</default>
+ <default>NoImport</default>
</schema>
<schema>
diff --git a/src/common/na-iprefs.h b/src/common/na-iprefs.h
index 5a92fc2..af821fb 100644
--- a/src/common/na-iprefs.h
+++ b/src/common/na-iprefs.h
@@ -49,6 +49,7 @@ G_BEGIN_DECLS
*/
#define IPREFS_IMPORT_ACTIONS_IMPORT_MODE "import-mode"
#define IPREFS_IMPORT_ASK_LAST_MODE "import-ask-user-last-mode"
+#define IPREFS_IMPORT_ASK_KEEP_MODE "import-ask-user-keep-mode"
/* import mode
*/
diff --git a/src/nact/base-window.c b/src/nact/base-window.c
index 983b1e7..a4e7f1f 100644
--- a/src/nact/base-window.c
+++ b/src/nact/base-window.c
@@ -602,7 +602,6 @@ base_window_init( BaseWindow *window )
if( !is_toplevel_initialized( window, toplevel )){
g_signal_emit_by_name( window, BASE_WINDOW_SIGNAL_INITIAL_LOAD, NULL );
-
set_toplevel_initialized( window, toplevel, TRUE );
}
window->private->initialized = TRUE;
@@ -626,50 +625,57 @@ base_window_run( BaseWindow *window )
{
static const gchar *thisfn = "base_window_run";
GtkWidget *this_dialog;
+ gboolean run_ok;
gint code;
g_return_if_fail( BASE_IS_WINDOW( window ));
- if( !window->private->dispose_has_run ){
+ run_ok = TRUE;
- if( !window->private->initialized ){
- base_window_init( window );
- }
-
- this_dialog = GTK_WIDGET( window->private->toplevel_window );
- if( this_dialog ){
+ if( window->private->dispose_has_run ){
+ run_ok = FALSE;
+ }
- g_debug( "%s: window=%p", thisfn, ( void * ) window );
+ if( run_ok && !window->private->initialized ){
+ run_ok = base_window_init( window );
+ }
- g_signal_emit_by_name( window, BASE_WINDOW_SIGNAL_RUNTIME_INIT, NULL );
+ if( run_ok ){
+ this_dialog = GTK_WIDGET( window->private->toplevel_window );
+ if( !this_dialog ){
+ run_ok = FALSE;
+ }
+ }
- gtk_widget_show_all( this_dialog );
+ if( run_ok ){
+ g_debug( "%s: window=%p", thisfn, ( void * ) window );
+ g_signal_emit_by_name( window, BASE_WINDOW_SIGNAL_RUNTIME_INIT, NULL );
- g_signal_emit_by_name( window, BASE_WINDOW_SIGNAL_ALL_WIDGETS_SHOWED, NULL );
+ gtk_widget_show_all( this_dialog );
+ g_signal_emit_by_name( window, BASE_WINDOW_SIGNAL_ALL_WIDGETS_SHOWED, NULL );
- if( is_main_window( window )){
+ if( is_main_window( window )){
- if( GTK_IS_DIALOG( this_dialog )){
- g_signal_connect( G_OBJECT( this_dialog ), "response", G_CALLBACK( v_dialog_response ), window );
- } else {
- g_signal_connect( G_OBJECT( this_dialog ), "delete-event", G_CALLBACK( on_delete_event ), window );
- }
+ if( GTK_IS_DIALOG( this_dialog )){
+ g_signal_connect( G_OBJECT( this_dialog ), "response", G_CALLBACK( v_dialog_response ), window );
+ } else {
+ g_signal_connect( G_OBJECT( this_dialog ), "delete-event", G_CALLBACK( on_delete_event ), window );
+ }
- g_debug( "%s: application=%p, starting gtk_main", thisfn, ( void * ) window->private->application );
- gtk_main();
+ g_debug( "%s: application=%p, starting gtk_main", thisfn, ( void * ) window->private->application );
+ gtk_main();
- } else if( GTK_IS_ASSISTANT( this_dialog )){
- g_debug( "%s: starting gtk_main", thisfn );
- gtk_main();
+ } else if( GTK_IS_ASSISTANT( this_dialog )){
+ g_debug( "%s: starting gtk_main", thisfn );
+ gtk_main();
- } else {
- g_assert( GTK_IS_DIALOG( this_dialog ));
- g_debug( "%s: starting gtk_dialog_run", thisfn );
- do {
- code = gtk_dialog_run( GTK_DIALOG( this_dialog ));
- }
- while( !v_dialog_response( GTK_DIALOG( this_dialog ), code, window ));
+ } else {
+ g_assert( GTK_IS_DIALOG( this_dialog ));
+ g_debug( "%s: starting gtk_dialog_run", thisfn );
+ do {
+ code = gtk_dialog_run( GTK_DIALOG( this_dialog ));
}
+ while( !v_dialog_response( GTK_DIALOG( this_dialog ), code, window ));
}
}
}
diff --git a/src/nact/nact-assistant-import-ask.c b/src/nact/nact-assistant-import-ask.c
index 1023293..573128f 100644
--- a/src/nact/nact-assistant-import-ask.c
+++ b/src/nact/nact-assistant-import-ask.c
@@ -37,6 +37,8 @@
#include <common/na-iprefs.h>
#include <common/na-object-api.h>
+#include <runtime/na-pivot.h>
+
#include "nact-application.h"
#include "nact-assistant-import-ask.h"
@@ -55,6 +57,7 @@ struct NactAssistantImportAskPrivate {
NAObjectAction *action;
NAObjectItem *exist;
gint mode;
+ gboolean keep_mode;
};
static BaseDialogClass *st_parent_class = NULL;
@@ -226,29 +229,53 @@ assistant_import_ask_new( NactApplication *application )
* Initializes and runs the dialog.
*
* Returns: the mode choosen by the user ; it defaults to NO_IMPORT.
+ *
+ * A flag is set against the dialog box widget itself. When this flag
+ * is not present (the first time this dialog is ran), we ask the user
+ * for its choices. Next time, the flag will be set and we will follow
+ * the user's preferences, i.e. whether last choice should be
+ * automatically applied or not.
*/
gint
nact_assistant_import_ask_user( NactMainWindow *parent, const gchar *uri, NAObjectAction *action, NAObjectItem *exist )
{
static const gchar *thisfn = "nact_assistant_import_ask_run";
NactApplication *application;
+ NAPivot *pivot;
NactAssistantImportAsk *editor;
+ GtkWindow *window;
gint mode;
+ gboolean already_ran;
g_debug( "%s: parent=%p", thisfn, ( void * ) parent );
g_return_val_if_fail( BASE_IS_WINDOW( parent ), IPREFS_IMPORT_NO_IMPORT );
application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( parent )));
- g_assert( NACT_IS_APPLICATION( application ));
+ g_return_val_if_fail( NACT_IS_APPLICATION( application ), IPREFS_IMPORT_NO_IMPORT );
+
+ pivot = nact_application_get_pivot( application );
+ g_return_val_if_fail( NA_IS_PIVOT( pivot ), IPREFS_IMPORT_NO_IMPORT );
editor = assistant_import_ask_new( application );
editor->private->parent = parent;
editor->private->uri = uri;
editor->private->action = action;
editor->private->exist = exist;
- editor->private->mode = IPREFS_IMPORT_NO_IMPORT;
+ editor->private->mode = na_iprefs_get_import_mode( NA_IPREFS( pivot ), IPREFS_IMPORT_ASK_LAST_MODE );
+ editor->private->keep_mode = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_IMPORT_ASK_KEEP_MODE, FALSE );
+
+ if( base_window_init( BASE_WINDOW( editor ))){
+ g_object_get( G_OBJECT( editor ), BASE_WINDOW_PROP_TOPLEVEL_WIDGET, &window, NULL );
+ if( window && GTK_IS_WINDOW( window )){
+ already_ran = ( gboolean ) GPOINTER_TO_INT( g_object_get_data( G_OBJECT( window ), "nact-assistant-import-ask-user" ));
+ if( !already_ran || editor->private->keep_mode ){
+ base_window_run( BASE_WINDOW( editor ));
+ }
+ }
+ }
- base_window_run( BASE_WINDOW( editor ));
+ na_iprefs_set_import_mode( NA_IPREFS( pivot ), IPREFS_IMPORT_ASK_LAST_MODE, editor->private->mode );
+ na_iprefs_write_bool( NA_IPREFS( pivot ), IPREFS_IMPORT_ASK_KEEP_MODE, editor->private->keep_mode );
mode = editor->private->mode;
g_object_unref( editor );
@@ -286,6 +313,7 @@ on_base_runtime_init_dialog( NactAssistantImportAsk *editor, gpointer user_data
gchar *label;
GtkWidget *widget;
GtkWidget *button;
+ GtkWindow *window;
g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
g_return_if_fail( NACT_IS_ASSISTANT_IMPORT_ASK( editor ));
@@ -329,6 +357,9 @@ on_base_runtime_init_dialog( NactAssistantImportAsk *editor, gpointer user_data
"OKButton1",
"clicked",
G_CALLBACK( on_ok_clicked ));
+
+ window = base_window_get_toplevel( BASE_WINDOW( editor ));
+ g_object_set_data( G_OBJECT( window ), "nact-assistant-import-ask-user", GINT_TO_POINTER( TRUE ));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]