diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 11 | ||||
-rw-r--r-- | e-util/e-error.h | 2 | ||||
-rw-r--r-- | e-util/e-import.c | 137 | ||||
-rw-r--r-- | e-util/e-import.h | 37 |
4 files changed, 103 insertions, 84 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index bdde3b3347..c80f44b93a 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -11,6 +11,17 @@ * e-util/e-account-list.[ch]: Add functions to remove proxy accounts and account's proxies. +2005-07-06 Not Zed <NotZed@Ximian.com> + + * e-import.c (e_import_status): added callback for importers to + report status. + (e_import_cancel): added function for driver to abort an import. + (eih_cancel): implemented for hook. + +2005-07-05 Not Zed <NotZed@Ximian.com> + + * e-import.c: cleaned up/finished api. + 2005-06-18 Tor Lillqvist <tml@novell.com> * Makefile.am (WIN32_BOOTSTRAP_LIBS): Use bootstrap library for diff --git a/e-util/e-error.h b/e-util/e-error.h index fe097656ab..a09f7b4236 100644 --- a/e-util/e-error.h +++ b/e-util/e-error.h @@ -33,6 +33,8 @@ struct _GtkWindow; * Several more basic ones are needed. */ +#define E_ERROR_INFO "builtin:info" +#define E_ERROR_INFO_PRIMARY "builtin:info-primary" #define E_ERROR_WARNING "builtin:warning" #define E_ERROR_WARNING_PRIMARY "builtin:warning-primary" #define E_ERROR_ERROR "builtin:error" diff --git a/e-util/e-import.c b/e-util/e-import.c index 717805203e..042dd53680 100644 --- a/e-util/e-import.c +++ b/e-util/e-import.c @@ -106,37 +106,12 @@ ec_target_free(EImport *ep, EImportTarget *t) break; } } + g_datalist_clear(&t->data); g_free(t); g_object_unref(ep); } static void -ec_set_target(EImport *emp, EImportTarget *target) -{ - EImportClass *k = (EImportClass *)G_OBJECT_GET_CLASS(emp); - struct _EImportImporters *ei; - - if (emp->target) - e_import_target_free(emp, target); - - emp->target = target; - emp->importer = NULL; - - if (target== NULL) - return; - - for (ei = (struct _EImportImporters *)k->importers.head; - ei->next; - ei = ei->next) { - if (ei->importer->type == target->type - && ei->importer->supported(emp, ei->importer, ei->importer->user_data)) { - emp->importer = ei->importer; - break; - } - } -} - -static void ep_class_init(GObjectClass *klass) { d(printf("EImport class init %p '%s'\n", klass, g_type_name(((GObjectClass *)klass)->g_type_class.g_type))); @@ -144,7 +119,6 @@ ep_class_init(GObjectClass *klass) g_type_class_add_private(klass, sizeof(struct _EImportPrivate)); klass->finalize = ep_finalise; - ((EImportClass *)klass)->set_target = ec_set_target; ((EImportClass *)klass)->target_free = ec_target_free; } @@ -198,10 +172,20 @@ EImport *e_import_construct(EImport *ep, const char *id) return ep; } +EImport *e_import_new(const char *id) +{ + EImport *ei = g_object_new(e_import_get_type(), NULL); + + return e_import_construct(ei, id); +} + /** * e_import_import: * @ei: - * @done: + * @t: Target to import. + * @im: Importer to use. + * @status: Status callback, called with progress information. + * @done: Complete callback, will always be called once complete. * @data: * * Run the import function of the selected importer. Once the @@ -212,66 +196,64 @@ EImport *e_import_construct(EImport *ep, const char *id) * When complete, the @done callback will be called. **/ void -e_import_import(EImport *ei, EImportCompleteFunc done, void *data) +e_import_import(EImport *ei, EImportTarget *t, EImportImporter *im, EImportStatusFunc status, EImportCompleteFunc done, void *data) { - g_return_if_fail(ei->importer != NULL); - g_return_if_fail(ei->target != NULL); + g_return_if_fail(im != NULL); + g_return_if_fail(im != NULL); + ei->status = status; ei->done = done; ei->done_data = data; - ei->importer->import(ei, ei->importer, ei->importer->user_data); + im->import(ei, t, im); +} + +void e_import_cancel(EImport *ei, EImportTarget *t, EImportImporter *im) +{ + if (im->cancel) + im->cancel(ei, t, im); } /** * e_import_get_widget: - * @ei: An import object on which the target has been set. + * @ei: + * @target: Target of interest + * @im: Importer to get widget of * * Gets a widget that the importer uses to configure its * destination. This widget should be packed into a container - * widget. + * widget. It should not be shown_all. * * Return value: NULL if the importer doesn't support/require * a destination. **/ struct _GtkWidget * -e_import_get_widget(EImport *ei) +e_import_get_widget(EImport *ei, EImportTarget *target, EImportImporter *im) { - g_return_val_if_fail(ei->importer != NULL, NULL); - g_return_val_if_fail(ei->target != NULL, NULL); + g_return_val_if_fail(im != NULL, NULL); + g_return_val_if_fail(target != NULL, NULL); - return ei->importer->get_widget(ei, ei->importer, ei->importer->user_data); + return im->get_widget(ei, target, im); } /** * e_import_complete: * @ei: + * @target: Target just completed (unused currently) * * Signify that an import is complete. This must be called by * importer implementations when they are done. **/ -void e_import_complete(EImport *ei) +void e_import_complete(EImport *ei, EImportTarget *target) { if (ei->done) ei->done(ei, ei->done_data); } -/** - * e_import_set_target: - * @emp: An initialised EImport. - * @target: A target allocated from @emp. - * - * Sets the target object for the import window. Generally the target - * is set only once, and will supply its own "changed" signal which - * can be used to drive the modal. This is a virtual method so that - * the implementing class can connect to the changed signal and - * initiate a e_import_target_changed() call where appropriate. - **/ -void -e_import_set_target(EImport *emp, EImportTarget *target) +void e_import_status(EImport *ei, EImportTarget *target, const char *what, int pc) { - if (emp->target != target) - ((EImportClass *)G_OBJECT_GET_CLASS(emp))->set_target(emp, target); + if (ei->status) + ei->status(ei, what, pc, ei->done_data); } /** @@ -280,8 +262,9 @@ e_import_set_target(EImport *emp, EImportTarget *target) * @target: * * Get a list of importers. If @target is supplied, then only - * importers which support the location specified by the target are - * listed. If @target is NULL, then all importers are listed. + * importers which support the type and location specified by the + * target are listed. If @target is NULL, then all importers are + * listed. * * Return value: A list of importers. The list should be freed when * no longer needed. @@ -298,9 +281,8 @@ e_import_get_importers(EImport *emp, EImportTarget *target) ei = ei->next) { if (target == NULL || (ei->importer->type == target->type - && ei->importer->supported(emp, ei->importer, ei->importer->user_data))) { + && ei->importer->supported(emp, target, ei->importer))) { importers = g_slist_append(importers, ei->importer); - break; } } @@ -334,10 +316,14 @@ e_import_class_add_importer(EImportClass *klass, EImportImporter *importer, EImp en = en->next; } - node->next = ei->next; - node->next->prev = node; - node->prev = ei; - ei->next = node; + if (en == NULL) + e_dlist_addtail(&klass->importers, (EDListNode *)node); + else { + node->next = ei->next; + node->next->prev = node; + node->prev = ei; + ei->next = node; + } } void e_import_class_remove_importer(EImportClass *klass, EImportImporter *f) @@ -377,6 +363,7 @@ void *e_import_target_new(EImport *ep, int type, size_t size) t->import = ep; g_object_ref(ep); t->type = type; + g_datalist_init(&t->data); return t; } @@ -452,32 +439,40 @@ static const EImportHookTargetMask eih_no_masks[] = { static const EImportHookTargetMap eih_targets[] = { { "uri", E_IMPORT_TARGET_URI, eih_no_masks }, - { "home", E_IMPORT_TARGET_URI, eih_no_masks }, + { "home", E_IMPORT_TARGET_HOME, eih_no_masks }, { 0 } }; -static gboolean eih_supported(EImport *ei, EImportImporter *im, void *data) +static gboolean eih_supported(EImport *ei, EImportTarget *target, EImportImporter *im) +{ + struct _EImportHookImporter *ihook = (EImportHookImporter *)im; + EImportHook *hook = im->user_data; + + return e_plugin_invoke(hook->hook.plugin, ihook->supported, target) != NULL; +} + +static struct _GtkWidget *eih_get_widget(EImport *ei, EImportTarget *target, EImportImporter *im) { struct _EImportHookImporter *ihook = (EImportHookImporter *)im; EImportHook *hook = im->user_data; - return e_plugin_invoke(hook->hook.plugin, ihook->supported, ei) != NULL; + return e_plugin_invoke(hook->hook.plugin, ihook->get_widget, target); } -static struct _GtkWidget *eih_get_widget(EImport *ei, EImportImporter *im, void *data) +static void eih_import(EImport *ei, EImportTarget *target, EImportImporter *im) { struct _EImportHookImporter *ihook = (EImportHookImporter *)im; EImportHook *hook = im->user_data; - return e_plugin_invoke(hook->hook.plugin, ihook->get_widget, ei); + e_plugin_invoke(hook->hook.plugin, ihook->import, target); } -static void eih_import(EImport *ei, EImportImporter *im, void *data) +static void eih_cancel(EImport *ei, EImportTarget *target, EImportImporter *im) { struct _EImportHookImporter *ihook = (EImportHookImporter *)im; EImportHook *hook = im->user_data; - e_plugin_invoke(hook->hook.plugin, ihook->import, ei); + e_plugin_invoke(hook->hook.plugin, ihook->cancel, target); } static void @@ -514,6 +509,7 @@ emph_construct_importer(EPluginHook *eph, xmlNodePtr root) item->supported = e_plugin_xml_prop(root, "supported"); item->get_widget = e_plugin_xml_prop(root, "get-widget"); item->import = e_plugin_xml_prop(root, "import"); + item->cancel = e_plugin_xml_prop(root, "cancel"); item->importer.name = e_plugin_xml_prop(root, "name"); item->importer.description = e_plugin_xml_prop(root, "description"); @@ -527,6 +523,8 @@ emph_construct_importer(EPluginHook *eph, xmlNodePtr root) item->importer.import = eih_import; if (item->get_widget) item->importer.get_widget = eih_get_widget; + if (item->cancel) + item->importer.cancel = eih_cancel; return item; error: @@ -585,7 +583,6 @@ emph_class_init(EPluginHookClass *klass) ((GObjectClass *)klass)->finalize = emph_finalise; klass->construct = emph_construct; - /* this is actually an abstract implementation but list it anyway */ klass->id = "org.gnome.evolution.import:1.0"; d(printf("EImportHook: init class %p '%s'\n", klass, g_type_name(((GObjectClass *)klass)->g_type_class.g_type))); diff --git a/e-util/e-import.h b/e-util/e-import.h index e5bf9b393a..4d913c232b 100644 --- a/e-util/e-import.h +++ b/e-util/e-import.h @@ -44,12 +44,13 @@ typedef struct _EImportFactory EImportFactory; typedef struct _EImportTarget EImportTarget; typedef void (*EImportCompleteFunc)(EImport *ei, void *data); +typedef void (*EImportStatusFunc)(EImport *ei, const char *what, int pc, void *data); typedef void (*EImportFactoryFunc)(EImport *ei, void *data); typedef void (*EImportImporterFunc)(EImportImporter *importer, void *data); -typedef gboolean (*EImportSupportedFunc)(EImport *ei, EImportImporter *im, void *data); -typedef struct _GtkWidget *(*EImportWidgetFunc)(EImport *ei, EImportImporter *im, void *data); -typedef void (*EImportImportFunc)(EImport *ei, EImportImporter *im, void *data); +typedef gboolean (*EImportSupportedFunc)(EImport *ei, EImportTarget *, EImportImporter *im); +typedef struct _GtkWidget *(*EImportWidgetFunc)(EImport *ei, EImportTarget *, EImportImporter *im); +typedef void (*EImportImportFunc)(EImport *ei, EImportTarget *, EImportImporter *im); /* The global target types, implementors may add additional ones */ enum _e_import_target_t { @@ -78,6 +79,7 @@ struct _EImportImporter { EImportSupportedFunc supported; EImportWidgetFunc get_widget; EImportImportFunc import; + EImportImportFunc cancel; void *user_data; @@ -91,6 +93,9 @@ struct _EImportImporter { * * @import: The parent object. * @type: The type of target, defined by implementing classes. + * @data: This can be used to store run-time information + * about this target. Any allocated data must be set so + * as to free it when the target is freed. * * The base target object is used as the parent and placeholder for * import context for a given importer. @@ -100,6 +105,8 @@ struct _EImportTarget { guint32 type; + GData *data; + /* implementation fields follow, depends on target type */ }; @@ -124,8 +131,9 @@ struct _EImportTargetHome { * * @object: Superclass. * @id: ID of importer. - * @target: The current target. - * @importer: The chosen importer for the target. + * @status: Status callback of current running import. + * @done: Completion callback of current running import. + * @done_data: Callback data for both of above. * **/ struct _EImport { @@ -133,9 +141,7 @@ struct _EImport { char *id; - EImportTarget *target; - EImportImporter *importer; - + EImportStatusFunc status; EImportCompleteFunc done; void *done_data; }; @@ -158,12 +164,13 @@ struct _EImportClass { EDList importers; - void (*set_target)(EImport *ep, EImportTarget *t); void (*target_free)(EImport *ep, EImportTarget *t); }; GType e_import_get_type(void); +EImport *e_import_new(const char *id); + /* Static class methods */ void e_import_class_add_importer(EImportClass *klass, EImportImporter *importer, EImportImporterFunc freefunc, void *data); void e_import_class_remove_importer(EImportClass *klass, EImportImporter *f); @@ -171,13 +178,14 @@ void e_import_class_remove_importer(EImportClass *klass, EImportImporter *f); GSList *e_import_get_importers(EImport *emp, EImportTarget *target); EImport *e_import_construct(EImport *, const char *id); -void e_import_import(EImport *ei, EImportCompleteFunc done, void *data); -struct _GtkWidget *e_import_get_widget(EImport *ei); +void e_import_import(EImport *ei, EImportTarget *, EImportImporter *, EImportStatusFunc status, EImportCompleteFunc done, void *data); +void e_import_cancel(EImport *, EImportTarget *, EImportImporter *); + +struct _GtkWidget *e_import_get_widget(EImport *ei, EImportTarget *, EImportImporter *); -void e_import_set_target(EImport *emp, EImportTarget *target); -struct _GtkWidget *e_import_create_window(EImport *emp, struct _GtkWindow *parent, const char *title); -void e_import_complete(EImport *); +void e_import_status(EImport *, EImportTarget *, const char *what, int pc); +void e_import_complete(EImport *, EImportTarget *); void *e_import_target_new(EImport *ep, int type, size_t size); void e_import_target_free(EImport *ep, void *o); @@ -210,6 +218,7 @@ struct _EImportHookImporter { char *supported; char *get_widget; char *import; + char *cancel; }; /** |