Commit 1c29f9af authored by Pierre Wieser's avatar Pierre Wieser

Review keep last user choice when importing items

parent 11e4d407
2010-07-02 Pierre Wieser <pwieser@trychlos.org>
* data/nautilus-actions-prefs.schemas.in:
* src/core/na-iprefs.h:
* src/core/na-importer-ask.c:
* src/core/na-importer-ask.h:
Define a new GConf preference 'keep last user choice'.
* src/api/na-iimporter.h:
* src/core/na-iimporter.c:
from_uri() interface is renamed as import_from_uri().
Only define na_iimporter_import_from_uri() public API.
* src/core/na-importer.c:
* src/core/na-importer.h:
Define here na_importer_import_from_list() internal API.
* src/io-xml/naxml-provider.c:
* src/io-xml/naxml-reader.c:
* src/io-xml/naxml-reader.h:
* src/nact/nact-assistant-import.c:
* src/nact/nact-tree-model-dnd.c:
* src/test/test-reader.c: Updated accordingly.
* src/core/na-object-id.c (na_object_id_set_new_id):
Fix object type test.
* src/core/na-object-item.c (object_id_new_id):
Fix minor typo.
* src/core/na-object-profile.c (object_id_new_id):
Fix order of validity test.
Only get a new profile name when a new parent is provided.
2010-06-29 Pierre Wieser <pwieser@trychlos.org>
* src/nact/nact-tree-model-dnd.c (drop_uri_list):
......
......@@ -129,8 +129,8 @@ Possible values are:
<type>list</type>
<list_type>int</list_type>
<locale name="C">
<short>Position and size of the import assistant window</short>
<long>Position and size of the import assistant window ; default is set by the window manager.</long>
<short>Position and size of the interaction dialog at import time</short>
<long>Position and size of the interaction dialog at import time ; default is set by the window manager.</long>
</locale>
<default>[]</default>
</schema>
......@@ -155,8 +155,8 @@ Possible values are:
<type>list</type>
<list_type>int</list_type>
<locale name="C">
<short>Position and size of the interaction dialog at import time</short>
<long>Position and size of the interaction dialog at import time ; default is set by the window manager.</long>
<short>Position and size of the import assistant window</short>
<long>Position and size of the import assistant window ; default is set by the window manager.</long>
</locale>
<default>[]</default>
</schema>
......@@ -172,6 +172,17 @@ Possible values are:
<default>/tmp</default>
</schema>
<schema>
<key>/schemas/apps/nautilus-actions/preferences/import-keep-choicee</key>
<owner>nautilus-actions</owner>
<type>bool</type>
<locale name="C">
<short>Keep last choosen import mode</short>
<long>Whether the import system should reuse the last choosen import mode.</long>
</locale>
<default>false</default>
</schema>
<schema>
<key>/schemas/apps/nautilus-actions/preferences/import-mode</key>
<owner>nautilus-actions</owner>
......
......@@ -36,13 +36,11 @@
* @short_description: #NAIImporter interface definition.
* @include: nautilus-actions/na-iimporter.h
*
* The #NAIImporter interface imports items from the outside world.
* The #NAIImporter interface imports items from the outside world.
*
* Nautilus-Actions v 2.30 - API version: 1
*/
#include <gtk/gtk.h>
#include "na-object-item.h"
G_BEGIN_DECLS
......@@ -52,11 +50,10 @@ G_BEGIN_DECLS
#define NA_IS_IIMPORTER( instance ) ( G_TYPE_CHECK_INSTANCE_TYPE( instance, NA_IIMPORTER_TYPE ))
#define NA_IIMPORTER_GET_INTERFACE( instance ) ( G_TYPE_INSTANCE_GET_INTERFACE(( instance ), NA_IIMPORTER_TYPE, NAIImporterInterface ))
typedef struct NAIImporter NAIImporter;
typedef struct NAIImporterUriParms NAIImporterUriParms;
typedef struct NAIImporterListParms NAIImporterListParms;
typedef struct NAIImporter NAIImporter;
typedef struct NAIImporterInterfacePrivate NAIImporterInterfacePrivate;
typedef struct NAIImporterInterfacePrivate NAIImporterInterfacePrivate;
typedef struct NAIImporterImportFromUriParms NAIImporterImportFromUriParms;
typedef struct {
GTypeInterface parent;
......@@ -70,18 +67,18 @@ typedef struct {
*
* Defaults to 1.
*/
guint ( *get_version )( const NAIImporter *instance );
guint ( *get_version ) ( const NAIImporter *instance );
/**
* import_from_uri:
* @instance: the #NAIImporter provider.
* @parms: a #NAIImporterUriParms structure.
* @parms: a #NAIImporterImportFromUriParms structure.
*
* Imports an item.
*
* Returns: the return code of the operation.
*/
guint ( *from_uri ) ( const NAIImporter *instance, NAIImporterUriParms *parms );
guint ( *import_from_uri )( const NAIImporter *instance, NAIImporterImportFromUriParms *parms );
}
NAIImporterInterface;
......@@ -106,50 +103,61 @@ enum {
IMPORTER_CODE_CANCELLED
};
/* the function which should be provided by the caller in order the
* #NAIImporter provider be able to check for pre-existance of the
* imported item
*
* the function should return the already existing item which has the
/**
* This function may be provided by the caller in order the #NAIImporter
* provider be able to check for pre-existence of the imported item.
* This function should return the already existing item which has the
* same id than the currently being imported one, or %NULL if the
* imported id will be unique
* imported id will be unique.
* If this function is not provided, then the #NAIImporter provider will not
* be able to check for duplicates. In this case, the id of the imported item
* should be systematically regenerated as a unique id (uuid), regardless of
* the asked import mode.
*
* (E): - currently imported item
* - fn_data
* (S): - already existing item with same id, or %NULL.
*/
typedef NAObjectItem * ( *NAIImporterCheckFn )( const NAObjectItem *, const void *fn_data );
typedef NAObjectItem * ( *NAIImporterCheckFn ) ( const NAObjectItem *, void *fn_data );
/* parameters via a structure
* ... when importing a single uri
/**
* This function may be provided by the caller in order the #NAIImporter
* provider be able to ask the user to know what to do in the case of a
* duplicate id.
* This function should return an mode import (not ASK!).
* If this function is not provided, then the #NAIImporter provider will
* not be able to ask the user. In this case, the duplicated id should be
* systematically regenerated as a unique id (uuid).
*
* (E): - currently imported item
* - already existing item with same id
* - fn_data
* (S): - import mode choosen by the user
*/
struct NAIImporterUriParms {
guint version; /* i 1: version of this structure */
gchar *uri; /* i 1: uri of the file to be imported */
guint mode; /* i 1: import mode */
GtkWindow *window; /* i 1: a window which will act as a parent of the ask dialog */
NAObjectItem *imported; /* o1: eventually imported NAObjectItem-derived object */
NAIImporterCheckFn check_fn; /* i 1: a function to check the existance of the imported item */
void *check_fn_data; /* i 1: data function */
GSList *messages; /* io1: a #GSList list of localized strings;
* the provider may append messages to this list,
* but shouldn't reinitialize it. */
};
typedef guint ( *NAIImporterAskUserFn )( const NAObjectItem *, const NAObjectItem *, void *fn_data );
/* ... when importing a list of uris
/*
* parameters used in input/output are passed or received through a single structure
*/
struct NAIImporterListParms {
guint version; /* i 1: version of this structure */
GSList *uris; /* i 1: list of uris of the files to be imported */
guint mode; /* i 1: import mode */
GtkWindow *window; /* i 1: a window which will act as a parent of the ask dialog */
GList *imported; /* o1: list of eventually imported NAObjectItem-derived objects */
NAIImporterCheckFn check_fn; /* i 1: a function to check the existance of each imported item */
void *check_fn_data; /* i 1: data function */
GSList *messages; /* io1: a #GSList list of localized strings;
struct NAIImporterImportFromUriParms {
guint version; /* i 1: version of this structure */
gchar *uri; /* i 1: uri of the file to be imported */
guint asked_mode; /* i 1: asked import mode */
gboolean exist; /* o1: whether the imported Id already existed */
guint import_mode; /* o1: actually used import mode */
NAObjectItem *imported; /* o1: the imported NAObjectItem-derived object, or %NULL */
NAIImporterCheckFn check_fn; /* i 1: a function to check the existence of the imported id */
void *check_fn_data; /* i 1: data function */
NAIImporterAskUserFn ask_fn; /* i 1: a function to ask the user what to do in case of a duplicate id */
void *ask_fn_data; /* i 1: data function */
GSList *messages; /* io1: a #GSList list of localized strings;
* the provider may append messages to this list,
* but shouldn't reinitialize it. */
};
GType na_iimporter_get_type( void );
guint na_iimporter_ask_user( const NAIImporter *importer, const NAIImporterUriParms *parms, const NAObjectItem *existing );
guint na_iimporter_import_from_uri( const NAIImporter *importer, NAIImporterImportFromUriParms *parms );
G_END_DECLS
......
......@@ -34,8 +34,6 @@
#include <api/na-iimporter.h>
#include "na-importer-ask.h"
/* private interface data
*/
struct NAIImporterInterfacePrivate {
......@@ -112,7 +110,7 @@ interface_base_init( NAIImporterInterface *klass )
klass->private = g_new0( NAIImporterInterfacePrivate, 1 );
klass->get_version = iimporter_get_version;
klass->from_uri = NULL;
klass->import_from_uri = NULL;
iimporter_initialized = TRUE;
}
......@@ -140,22 +138,34 @@ iimporter_get_version( const NAIImporter *instance )
}
/**
* na_iimporter_ask_user:
* na_iimporter_import_from_uri:
* @importer: this #NAIImporter instance.
* @parms: a #NAIImporterUriParms structure.
* @existing: the #NAObjectItem-derived already existing object.
* @parms: a #NAIImporterImportFromUriParms structure.
*
* Ask the user for what to do when an imported item has the same ID
* that an already existing one.
* Tries to import a #NAObjectItem from the URI specified in @parms, returning
* the result in @parms->imported.
*
* Returns: the definitive import mode.
* Returns: the return code of the operation.
*/
guint
na_iimporter_ask_user( const NAIImporter *importer, const NAIImporterUriParms *parms, const NAObjectItem *existing )
na_iimporter_import_from_uri( const NAIImporter *importer, NAIImporterImportFromUriParms *parms )
{
guint mode;
static const gchar *thisfn = "na_iimporter_import_from_uri";
guint code;
g_return_val_if_fail( NA_IS_IIMPORTER( importer ), IMPORTER_CODE_PROGRAM_ERROR );
code = IMPORTER_CODE_NOT_WILLING_TO;
mode = na_importer_ask_user( parms, existing );
if( iimporter_initialized && !iimporter_finalized ){
g_debug( "%s: importer=%p, parms=%p", thisfn, ( void * ) importer, ( void * ) parms );
if( NA_IIMPORTER_GET_INTERFACE( importer )->import_from_uri ){
code = NA_IIMPORTER_GET_INTERFACE( importer )->import_from_uri( importer, parms );
}
}
return( mode );
return( code );
}
......@@ -36,6 +36,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <api/na-gconf-utils.h>
#include <api/na-iimporter.h>
#include <api/na-object-api.h>
#include "na-gtk-utils.h"
......@@ -51,14 +53,15 @@ struct NAImporterAskClassPrivate {
/* private instance data
*/
struct NAImporterAskPrivate {
gboolean dispose_has_run;
GtkBuilder *builder;
GtkWindow *toplevel;
NAIImporterUriParms *parms;
NAObjectItem *existing;
guint mode;
GConfClient *gconf;
gint dialog_code;
gboolean dispose_has_run;
GtkBuilder *builder;
GtkWindow *toplevel;
NAObjectItem *importing;
NAObjectItem *existing;
NAImporterAskUserParms *parms;
guint mode;
GConfClient *gconf;
gint dialog_code;
};
static GtkDialogClass *st_parent_class = NULL;
......@@ -199,6 +202,7 @@ instance_finalize( GObject *dialog )
g_return_if_fail( NA_IS_IMPORTER_ASK( dialog ));
g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );
self = NA_IMPORTER_ASK( dialog );
g_free( self->private );
......@@ -233,24 +237,27 @@ import_ask_new()
* becomes his preference import mode.
*/
guint
na_importer_ask_user( const NAIImporterUriParms *parms, const NAObjectItem *existing )
na_importer_ask_user( const NAObjectItem *importing, const NAObjectItem *existing, NAImporterAskUserParms *parms )
{
static const gchar *thisfn = "na_importer_ask_user";
NAImporterAsk *dialog;
guint mode;
gint code;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( importing ), IMPORTER_MODE_NO_IMPORT );
g_return_val_if_fail( NA_IS_OBJECT_ITEM( existing ), IMPORTER_MODE_NO_IMPORT );
g_debug( "%s: parms=%p, existing=%p", thisfn, ( void * ) parms, ( void * ) existing );
g_debug( "%s: importing=%p, existing=%p, parms=%p",
thisfn, ( void * ) importing, ( void * ) existing, ( void * ) parms );
mode = IMPORTER_MODE_NO_IMPORT;
dialog = import_ask_new();
if( dialog->private->toplevel ){
dialog->private->parms = ( NAIImporterUriParms * ) parms;
dialog->private->importing = ( NAObjectItem * ) importing;
dialog->private->existing = ( NAObjectItem * ) existing;
dialog->private->parms = parms;
dialog->private->mode = na_iprefs_get_import_mode( dialog->private->gconf, IPREFS_IMPORT_ASK_LAST_MODE );
init_dialog( dialog );
......@@ -286,10 +293,10 @@ init_dialog( NAImporterAsk *editor )
g_debug( "%s: editor=%p", thisfn, ( void * ) editor );
imported_label = na_object_get_label( editor->private->parms->imported );
imported_label = na_object_get_label( editor->private->importing );
existing_label = na_object_get_label( editor->private->existing );
if( NA_IS_OBJECT_ACTION( editor->private->parms->imported )){
if( NA_IS_OBJECT_ACTION( editor->private->importing )){
/* i18n: The action <action_label> imported from <file> has the same id than <existing_label> */
label = g_strdup_printf(
_( "The action \"%s\" imported from \"%s\" has the same identifiant than the already existing \"%s\"." ),
......@@ -323,7 +330,7 @@ init_dialog( NAImporterAsk *editor )
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "AskKeepChoiceButton" );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), FALSE );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), editor->private->parms->keep_choice );
button = na_gtk_utils_search_for_child_widget( GTK_CONTAINER( editor->private->toplevel ), "OKButton" );
g_signal_connect(
......@@ -339,8 +346,8 @@ init_dialog( NAImporterAsk *editor )
G_CALLBACK( on_cancel_clicked ),
editor );
if( editor->private->parms->window ){
gtk_window_set_transient_for( editor->private->toplevel, editor->private->parms->window );
if( editor->private->parms->parent ){
gtk_window_set_transient_for( editor->private->toplevel, editor->private->parms->parent );
}
gtk_widget_show_all( GTK_WIDGET( editor->private->toplevel ));
......@@ -350,7 +357,9 @@ static void
on_cancel_clicked( GtkButton *button, NAImporterAsk *editor )
{
g_debug( "na_importer_ask_on_cancel_clicked" );
editor->private->dialog_code = GTK_RESPONSE_CANCEL;
gtk_dialog_response( GTK_DIALOG( editor ), GTK_RESPONSE_CANCEL );
}
......@@ -358,7 +367,9 @@ static void
on_ok_clicked( GtkButton *button, NAImporterAsk *editor )
{
g_debug( "na_importer_ask_on_ok_clicked" );
editor->private->dialog_code = GTK_RESPONSE_OK;
gtk_dialog_response( GTK_DIALOG( editor ), GTK_RESPONSE_OK );
}
......@@ -368,6 +379,7 @@ get_selected_mode( NAImporterAsk *editor )
guint import_mode;
GtkWidget *button;
gboolean keep;
gchar *path;
import_mode = IMPORTER_MODE_NO_IMPORT;
......@@ -387,9 +399,9 @@ get_selected_mode( NAImporterAsk *editor )
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 );
}
path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, IPREFS_IMPORT_KEEP_CHOICE );
na_gconf_utils_write_bool( editor->private->gconf, path, keep, NULL );
g_free( path );
}
/*
......
......@@ -41,10 +41,12 @@
* want to be ask to known what to do with it.
*/
#include <api/na-iimporter.h>
G_BEGIN_DECLS
#include <gtk/gtk.h>
#include <api/na-object-item.h>
#define NA_IMPORTER_ASK_TYPE ( na_importer_ask_get_type())
#define NA_IMPORTER_ASK( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, NA_IMPORTER_ASK_TYPE, NAImporterAsk ))
#define NA_IMPORTER_ASK_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, NA_IMPORTER_ASK_TYPE, NAImporterAskClass ))
......@@ -68,9 +70,17 @@ typedef struct {
}
NAImporterAskClass;
typedef struct {
GtkWindow *parent;
gchar *uri;
guint count;
gboolean keep_choice;
}
NAImporterAskUserParms;
GType na_importer_ask_get_type( void );
guint na_importer_ask_user( const NAIImporterUriParms *parms, const NAObjectItem *existing );
guint na_importer_ask_user( const NAObjectItem *importing, const NAObjectItem *existing, NAImporterAskUserParms *parms );
G_END_DECLS
......
......@@ -34,136 +34,183 @@
#include <string.h>
#include <api/na-core-utils.h>
#include <api/na-object-api.h>
#include "na-iprefs.h"
#include "na-importer.h"
#include "na-importer-ask.h"
typedef struct {
GList *just_imported;
NAIImporterCheckFn check_fn;
void *check_fn_data;
}
ImporterExistsStr;
extern gboolean iimporter_initialized; /* defined in na-iimporter.c */
extern gboolean iimporter_finalized; /* defined in na-iimporter.c */
static NAObjectItem *is_importing_already_exists( const NAObjectItem *importing, const NAIImporterListParms *parms );
static guint import_from_uri( const NAPivot *pivot, GList *modules, NAImporterParms *parms, const gchar *uri, NAImporterResult **result );
static NAObjectItem *is_importing_already_exists( const NAObjectItem *importing, ImporterExistsStr *parms );
static guint ask_user_for_mode( const NAObjectItem *importing, const NAObjectItem *existing, NAImporterAskUserParms *parms );
/**
* na_importer_import_from_uri:
* na_importer_import_from_list:
* @pivot: the #NAPivot pivot for this application.
* @parms: a #NAIImporterUriParms structure.
* @parms: a #NAImporterParms structure.
*
* Imports a list of URIs.
*
* For each URI to import, we search through the available #NAIImporter
* providers until the first which respond something different from
* "not_willing_to" code.
*
* Each import operation will have its corresponding newly allocated
* #NAImporterResult structure which will contain:
* - the imported URI
* - a #NAObjectItem item if import was successfull, or %NULL
* - a list of error messages, or %NULL.
*
* Returns: the import operation code.
* Returns: the last import operation code.
*/
/*
* Importing a list of URIs:
* if asked mode is 'ask', then ask the user at least the first time
* the 'keep my choice' is active or not, depending of the last time used
* then the 'keep my chose' is kept for other times
* so preferences are:
* - asked import mode (may be 'ask') -> import-mode
* - keep my choice -> import-keep-choice
* - last choosen import mode -> import-ask-user-last-mode
*/
guint
na_importer_import_from_uri( const NAPivot *pivot, NAIImporterUriParms *parms )
na_importer_import_from_list( const NAPivot *pivot, NAImporterParms *parms )
{
static const gchar *thisfn = "na_importer_import_from_uri";
GList *modules, *im;
static const gchar *thisfn = "na_importer_import_from_list";
GList *modules;
GSList *iuri;
NAImporterResult *result;
guint code;
g_return_val_if_fail( NA_IS_PIVOT( pivot ), IMPORTER_CODE_PROGRAM_ERROR );
code = IMPORTER_CODE_PROGRAM_ERROR;
code = IMPORTER_CODE_NOT_WILLING_TO;
parms->results = NULL;
if( iimporter_initialized && !iimporter_finalized ){
g_debug( "%s: pivot=%p, parms=%p", thisfn, ( void * ) pivot, ( void * ) parms );
code = IMPORTER_CODE_NOT_WILLING_TO;
modules = na_pivot_get_providers( pivot, NA_IIMPORTER_TYPE );
for( im = modules ; im && code == IMPORTER_CODE_NOT_WILLING_TO ; im = im->next ){
if( NA_IIMPORTER_GET_INTERFACE( NA_IIMPORTER( im->data ))->from_uri ){
code = NA_IIMPORTER_GET_INTERFACE( NA_IIMPORTER( im->data ))->from_uri( NA_IIMPORTER( im->data ), parms );
}
for( iuri = parms->uris ; iuri ; iuri = iuri->next ){
code = import_from_uri( pivot, modules, parms, ( const gchar * ) iuri->data, &result );
parms->results = g_list_prepend( parms->results, result );
}
na_pivot_free_providers( modules );
parms->results = g_list_reverse( parms->results );
}
return( code );
}
/**
* na_importer_import_from_list:
* @pivot: the #NAPivot pivot for this application.
* @parms: a #NAIImporterListParms structure.
*
* Imports a list of URIs.
*
* Each successfully imported #NAObjectItem-derived object is added to
* the 'imported' list of the structure, in the same order than the URIs.
*
* Messages which may be generated by each individual import operation
* are added to the 'messages' member of @parms.
* na_importer_free_result:
* @result: the #NAImporterResult structure to be released.
*
* Returns: the last import operation code.
* Release the structure.
*/
guint
na_importer_import_from_list( const NAPivot *pivot, NAIImporterListParms *parms )
void
na_importer_free_result( NAImporterResult *result )
{
static const gchar *thisfn = "na_importer_import_from_list";
GSList *iuri;
NAIImporterUriParms uri_parms;
guint code;
g_return_val_if_fail( NA_IS_PIVOT( pivot ), IMPORTER_CODE_PROGRAM_ERROR );
g_free( result->uri );
na_core_utils_slist_free( result->messages );
code = IMPORTER_CODE_PROGRAM_ERROR;
parms->imported = NULL;
if( iimporter_initialized && !iimporter_finalized ){
g_debug( "%s: pivot=%p, parms=%p", thisfn, ( void * ) pivot, ( void * ) parms );
code = IMPORTER_CODE_NOT_WILLING_TO;
uri_parms.version = 1;
uri_parms.mode = parms->mode;
uri_parms.window = parms->window;
uri_parms.check_fn = ( NAIImporterCheckFn ) is_importing_already_exists;
uri_parms.check_fn_data = parms;
uri_parms.messages = parms->messages;
for( iuri = parms->uris ; iuri ; iuri = iuri->next ){
uri_parms.uri = ( gchar * ) iuri->data;
uri_parms.imported = NULL;
code = na_importer_import_from_uri( pivot, &uri_parms );
if( uri_parms.imported ){
parms->imported = g_list_prepend( parms->imported, uri_parms.imported );
}
}
g_free( result );
}
parms->imported = g_list_reverse( parms->imported );
static guint
import_from_uri( const NAPivot *pivot, GList *modules, NAImporterParms *parms, const gchar *uri, NAImporterResult **result )
{
guint code;
GList *im;
NAIImporterImportFromUriParms provider_parms;
ImporterExistsStr exists_parms;
NAImporterAskUserParms ask_parms;
code = IMPORTER_CODE_NOT_WILLING_TO;
memset( &exists_parms, '\0', sizeof( ImporterExistsStr ));
exists_parms.just_imported = parms->results;
exists_parms.check_fn = parms->check_fn;
exists_parms.check_fn_data = parms->check_fn_data;
memset( &ask_parms, '\0', sizeof( NAImporterAskUserParms ));
ask_parms.parent = parms->parent;
ask_parms.uri = ( gchar * ) uri;
ask_parms.count = g_list_length( parms->results );
ask_parms.keep_choice = na_iprefs_read_bool( NA_IPREFS( pivot ), IPREFS_IMPORT_KEEP_CHOICE, FALSE );
memset( &provider_parms, '\0', sizeof( NAIImporterImportFromUriParms ));
provider_parms.version = 1;
provider_parms.uri = ( gchar * ) uri;
provider_parms.asked_mode = parms->mode;
provider_parms.check_fn = ( NAIImporterCheckFn ) is_importing_already_exists;
provider_parms.check_fn_data = &exists_parms;
provider_parms.ask_fn = ( NAIImporterAskUserFn ) ask_user_for_mode;
provider_parms.ask_fn_data = &ask_parms;
for( im = modules ; im && code == IMPORTER_CODE_NOT_WILLING_TO ; im = im->next ){
code = na_iimporter_import_from_uri( NA_IIMPORTER( im->data ), &provider_parms );
}
*result = g_new0( NAImporterResult, 1 );
( *result )->uri = g_strdup( uri );
( *result )->mode = provider_parms.import_mode;
( *result )->exist = provider_parms.exist;
( *result )->imported = provider_parms.imported;
( *result )->messages = provider_parms.messages;
return( code );
}
/*
* to see if an imported item already exists, we have to check
* - the current list of just imported items
* - the main window (if any), which contains the in-memory list of items
* - the tree in pivot which contains the 'actual' items
*/
static NAObjectItem *
is_importing_already_exists( const NAObjectItem *importing, const NAIImporterListParms *parms )
is_importing_already_exists( const NAObjectItem *importing, ImporterExistsStr *parms )
{
static const gchar *thisfn = "na_importer_is_importing_already_exists";
NAObjectItem *exists;
GList *ip;
exists = NULL;
gchar *importing_id = na_object_get_id( importing );
g_debug( "na_importer_is_importing_already_exists: importing_id=%s", importing_id );
g_debug( "%s: importing=%p, id=%s", thisfn, ( void * ) importing, importing_id );
/* is the importing item already in the current importation list ?
*/
for( ip = parms->imported ; ip && !exists ; ip = ip->next ){
gchar *id = na_object_get_id( ip->data );
if( !strcmp( importing_id, id )){
exists = NA_OBJECT_ITEM( ip->data );
for( ip = parms->just_imported ; ip && !exists ; ip = ip->next ){
NAImporterResult *result = ( NAImporterResult * ) ip->data;
if( result->imported ){
gchar *id = na_object_get_id( result->imported );
if( !strcmp( importing_id, id )){
exists = NA_OBJECT_ITEM( result->imported );
}
g_free( id );
}
g_free( id );
}
g_free( importing_id );
/* if not found in our current importation list,
* then check the via provided function and data
* then check the existence via provided function and data
*/
if( !exists ){
exists = parms->check_fn( importing, parms->check_fn_data );
......@@ -171,3 +218,21 @@ is_importing_already_exists( const NAObjectItem *importing, const NAIImporterLis
return( exists );
}
static guint
ask_user_for_mode( const NAObjectItem *importing, const NAObjectItem *existing, NAImporterAskUserParms *parms )
{
guint mode;
GConfClient *gconf;
if( parms->count == 0 || !parms->keep_choice ){
mode = na_importer_ask_user( importing, existing, parms );
} else {
gconf = gconf_client_get_default();
mode = na_iprefs_get_import_mode( gconf, IPREFS_IMPORT_ASK_LAST_MODE );
g_object_unref( gconf );
}
return( mode );