aboutsummaryrefslogtreecommitdiffstats
path: root/shell/importer
diff options
context:
space:
mode:
authorIain Holmes <iain@src.gnome.org>2001-01-23 08:37:44 +0800
committerIain Holmes <iain@src.gnome.org>2001-01-23 08:37:44 +0800
commit9908f0dba12569b2b9fe0b48de9d46ec3f2386bc (patch)
tree70cb90835c03f9f38014008932e5695e63ae47e0 /shell/importer
parentff2d16601e0b4b71339b0820f4d2a5e0e92fdb92 (diff)
downloadgsoc2013-evolution-9908f0dba12569b2b9fe0b48de9d46ec3f2386bc.tar.gz
gsoc2013-evolution-9908f0dba12569b2b9fe0b48de9d46ec3f2386bc.tar.zst
gsoc2013-evolution-9908f0dba12569b2b9fe0b48de9d46ec3f2386bc.zip
New listener object. Plus some oneway stuff as well.
svn path=/trunk/; revision=7729
Diffstat (limited to 'shell/importer')
-rw-r--r--shell/importer/GNOME_Evolution_Importer.idl9
-rw-r--r--shell/importer/Makefile.am3
-rw-r--r--shell/importer/evolution-importer-client.c230
-rw-r--r--shell/importer/evolution-importer-client.h12
-rw-r--r--shell/importer/importer.c23
5 files changed, 38 insertions, 239 deletions
diff --git a/shell/importer/GNOME_Evolution_Importer.idl b/shell/importer/GNOME_Evolution_Importer.idl
index df6c7a22bf..b93c759c45 100644
--- a/shell/importer/GNOME_Evolution_Importer.idl
+++ b/shell/importer/GNOME_Evolution_Importer.idl
@@ -12,11 +12,12 @@
module GNOME {
module Evolution {
- interface ImporterListener {
+ interface ImporterListener : Bonobo::Unknown {
enum ImporterResult {
OK,
UNSUPPORTED_OPERATION,
NOT_READY,
+ BUSY,
UNKNOWN_DATA,
BAD_DATA,
BAD_FILE
@@ -30,8 +31,8 @@ module Evolution {
* Notifies the listener of the result and whether there are
* any more items to be imported.
*/
- void notifyResult (in ImporterResult result,
- in boolean more_items);
+ oneway void notifyResult (in ImporterResult result,
+ in boolean more_items);
};
interface Importer : Bonobo::Unknown {
@@ -50,7 +51,7 @@ module Evolution {
* Processes the next item.
*
*/
- void processItem (in ImporterListener listener)
+ oneway void processItem (in ImporterListener listener)
raises (Busy);
/**
diff --git a/shell/importer/Makefile.am b/shell/importer/Makefile.am
index 64f293eedf..96bbbafd5c 100644
--- a/shell/importer/Makefile.am
+++ b/shell/importer/Makefile.am
@@ -28,12 +28,15 @@ libevolution_importerincludedir = $(includedir)/evolution/importer
libevolution_importer_la_SOURCES = \
$(IDL_GENERATED) \
evolution-importer-client.c \
+ evolution-importer-listener.c \
evolution-importer.c \
importer.c \
importer.h
libevolution_importerinclude_HEADERS = \
+ GNOME_Evolution_Importer.h \
evolution-importer-client.h \
+ evolution-importer-listener.h \
evolution-importer.h
libevolution_importer_la_LIBADD = \
diff --git a/shell/importer/evolution-importer-client.c b/shell/importer/evolution-importer-client.c
index da17cecbfd..f702dd970c 100644
--- a/shell/importer/evolution-importer-client.c
+++ b/shell/importer/evolution-importer-client.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* evolution-importer-client.c
*
- * Copyright (C) 2000 Helix Code, Inc.
+ * Copyright (C) 2000 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -18,7 +18,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Author: Iain Holmes <iain@helixcode.com>
+ * Author: Iain Holmes <iain@ximian.com>
* Based on evolution-shell-component-client.c by Ettore Perazzoli
*/
@@ -39,195 +39,10 @@
#define PARENT_TYPE BONOBO_OBJECT_CLIENT_TYPE
static BonoboObjectClass *parent_class = NULL;
-struct _EvolutionImporterClientPrivate {
- EvolutionImporterClientCallback callback;
- void *closure;
-
- GNOME_Evolution_ImporterListener listener_interface;
- PortableServer_Servant listener_servant;
-};
-
-
-static PortableServer_ServantBase__epv Listener_base_epv;
-static POA_GNOME_Evolution_ImporterListener__epv Listener_epv;
-static POA_GNOME_Evolution_ImporterListener__vepv Listener_vepv;
-static gboolean Listener_vepv_initialized = FALSE;
-
-struct _ImporterListenerServant {
- POA_GNOME_Evolution_ImporterListener servant;
- EvolutionImporterClient *component_client;
-};
-typedef struct _ImporterListenerServant ImporterListenerServant;
-
-
static void
-dispatch_callback (EvolutionImporterClient *client,
- EvolutionImporterResult result,
- gboolean more_items)
-{
- EvolutionImporterClientPrivate *priv;
- EvolutionImporterClientCallback callback;
- PortableServer_ObjectId *oid;
- void *closure;
- CORBA_Environment ev;
-
- priv = client->private;
-
- g_return_if_fail (priv->callback != NULL);
- g_return_if_fail (priv->listener_servant != NULL);
-
- CORBA_exception_init (&ev);
-
- oid = PortableServer_POA_servant_to_id (bonobo_poa (), priv->listener_servant, &ev);
- PortableServer_POA_deactivate_object (bonobo_poa (), oid, &ev);
- POA_GNOME_Evolution_ImporterListener__fini (priv->listener_servant, &ev);
- CORBA_free (oid);
-
- CORBA_Object_release (priv->listener_interface, &ev);
- CORBA_exception_free (&ev);
-
- priv->listener_servant = NULL;
- priv->listener_interface = CORBA_OBJECT_NIL;
-
- callback = priv->callback;
- closure = priv->closure;
-
- priv->callback = NULL;
- priv->closure = NULL;
-
- (* callback) (client, result, more_items, closure);
-}
-
-static EvolutionImporterClient *
-component_client_from_ImporterListener_servant (PortableServer_Servant servant)
-{
- ImporterListenerServant *listener_servant;
-
- listener_servant = (ImporterListenerServant *) servant;
- return listener_servant->component_client;
-}
-
-static EvolutionImporterResult
-result_from_async_corba_result (GNOME_Evolution_ImporterListener_ImporterResult corba_result)
-{
- switch (corba_result) {
- case GNOME_Evolution_ImporterListener_OK:
- return EVOLUTION_IMPORTER_OK;
- case GNOME_Evolution_ImporterListener_UNSUPPORTED_OPERATION:
- return EVOLUTION_IMPORTER_UNSUPPORTED_OPERATION;
- case GNOME_Evolution_ImporterListener_UNKNOWN_DATA:
- return EVOLUTION_IMPORTER_UNKNOWN_DATA;
- case GNOME_Evolution_ImporterListener_BAD_DATA:
- return EVOLUTION_IMPORTER_BAD_DATA;
- case GNOME_Evolution_ImporterListener_BAD_FILE:
- return EVOLUTION_IMPORTER_BAD_FILE;
- case GNOME_Evolution_ImporterListener_NOT_READY:
- return EVOLUTION_IMPORTER_NOT_READY;
- default:
- return EVOLUTION_IMPORTER_UNKNOWN_ERROR;
- }
-}
-
-static void
-impl_ImporterListener_notifyResult (PortableServer_Servant servant,
- const GNOME_Evolution_ImporterListener_ImporterResult result,
- const CORBA_boolean more_items,
- CORBA_Environment *ev)
-{
- EvolutionImporterClient *client;
-
- client = component_client_from_ImporterListener_servant (servant);
- dispatch_callback (client, result_from_async_corba_result (result), more_items);
-}
-
-static void
-ImporterListener_vepv_initialize (void)
-{
- Listener_base_epv._private = NULL;
- Listener_base_epv.finalize = NULL;
- Listener_base_epv.default_POA = NULL;
-
- Listener_epv.notifyResult = impl_ImporterListener_notifyResult;
-
- Listener_vepv._base_epv = &Listener_base_epv;
- Listener_vepv.GNOME_Evolution_ImporterListener_epv = &Listener_epv;
-
- Listener_vepv_initialized = TRUE;
-}
-
-static PortableServer_Servant *
-create_listener_servant (EvolutionImporterClient *client)
-{
- ImporterListenerServant *servant;
-
- if (!Listener_vepv_initialized)
- ImporterListener_vepv_initialize ();
-
- servant = g_new0 (ImporterListenerServant, 1);
- servant->servant.vepv = &Listener_vepv;
- servant->component_client = client;
-
- return (PortableServer_Servant) servant;
-}
-
-static void
-free_listener_servant (PortableServer_Servant servant)
-{
- g_free (servant);
-}
-
-static void
-create_listener_interface (EvolutionImporterClient *client)
-{
- EvolutionImporterClientPrivate *priv;
- PortableServer_Servant listener_servant;
- GNOME_Evolution_ImporterListener corba_interface;
- CORBA_Environment ev;
-
- priv = client->private;
-
- listener_servant = create_listener_servant (client);
- CORBA_exception_init (&ev);
-
- POA_GNOME_Evolution_ImporterListener__init (listener_servant, &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION) {
- free_listener_servant (listener_servant);
- return;
- }
-
- CORBA_free (PortableServer_POA_activate_object (bonobo_poa (),
- listener_servant, &ev));
- corba_interface = PortableServer_POA_servant_to_reference (bonobo_poa (),
- listener_servant, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- corba_interface = CORBA_OBJECT_NIL;
- free_listener_servant (listener_servant);
- }
-
- CORBA_exception_free (&ev);
-
- priv->listener_servant = listener_servant;
- priv->listener_interface = corba_interface;
-}
-
-
-
-static void
destroy (GtkObject *object)
{
- EvolutionImporterClient *client;
- EvolutionImporterClientPrivate *priv;
-
- client = EVOLUTION_IMPORTER_CLIENT (object);
- priv = client->private;
-
- if (priv->callback != NULL)
- dispatch_callback (client, EVOLUTION_IMPORTER_INTERRUPTED, FALSE);
-
- g_free (priv);
-
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
@@ -245,15 +60,6 @@ class_init (EvolutionImporterClientClass *klass)
static void
init (EvolutionImporterClient *client)
{
- EvolutionImporterClientPrivate *priv;
-
- priv = g_new (EvolutionImporterClientPrivate, 1);
- priv->listener_interface = CORBA_OBJECT_NIL;
- priv->listener_servant = NULL;
- priv->callback = NULL;
- priv->closure = NULL;
-
- client->private = priv;
}
static void
@@ -384,42 +190,30 @@ evolution_importer_client_load_file (EvolutionImporterClient *client,
/**
* evolution_importer_client_process_item:
* @client: The EvolutionImporterClient.
- * @callback: The function to be called once the item has been processed.
- * @closure: The data to be passed to this function.
+ * @listener: The EvolutionImporterListener.
*
- * Starts importing the next item in the file and calls @callback when the
- * item has finished importing.
+ * Starts importing the next item in the file. @listener will be notified
+ * when the item has finished.
*/
void
evolution_importer_client_process_item (EvolutionImporterClient *client,
- EvolutionImporterClientCallback callback,
- void *closure)
+ EvolutionImporterListener *listener)
{
- EvolutionImporterClientPrivate *priv;
GNOME_Evolution_Importer corba_importer;
+ GNOME_Evolution_ImporterListener corba_listener;
CORBA_Environment ev;
g_return_if_fail (client != NULL);
g_return_if_fail (EVOLUTION_IS_IMPORTER_CLIENT (client));
- g_return_if_fail (callback != NULL);
-
- priv = client->private;
-
- if (priv->callback != NULL) {
- (* callback) (client, EVOLUTION_IMPORTER_BUSY, FALSE, closure);
- return;
- }
-
- create_listener_interface (client);
+ g_return_if_fail (listener != NULL);
+ g_return_if_fail (EVOLUTION_IS_IMPORTER_LISTENER (listener));
CORBA_exception_init (&ev);
corba_importer = bonobo_object_corba_objref (BONOBO_OBJECT (client));
- priv->callback = callback;
- priv->closure = closure;
-
+ corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener));
GNOME_Evolution_Importer_processItem (corba_importer,
- priv->listener_interface, &ev);
+ corba_listener, &ev);
CORBA_exception_free (&ev);
}
@@ -435,7 +229,6 @@ evolution_importer_client_process_item (EvolutionImporterClient *client,
const char *
evolution_importer_client_get_error (EvolutionImporterClient *client)
{
- EvolutionImporterClientPrivate *priv;
GNOME_Evolution_Importer corba_importer;
CORBA_char *str;
CORBA_Environment ev;
@@ -443,7 +236,6 @@ evolution_importer_client_get_error (EvolutionImporterClient *client)
g_return_val_if_fail (client != NULL, NULL);
g_return_val_if_fail (EVOLUTION_IS_IMPORTER_CLIENT (client), NULL);
- priv = client->private;
corba_importer = bonobo_object_corba_objref (BONOBO_OBJECT (client));
CORBA_exception_init (&ev);
diff --git a/shell/importer/evolution-importer-client.h b/shell/importer/evolution-importer-client.h
index e122a7cfdd..178d20254f 100644
--- a/shell/importer/evolution-importer-client.h
+++ b/shell/importer/evolution-importer-client.h
@@ -26,6 +26,7 @@
#include <bonobo/bonobo-object-client.h>
#include <importer/evolution-importer.h>
+#include <importer/evolution-importer-listener.h>
#ifdef __cplusplus
extern "C" {
@@ -40,24 +41,16 @@ extern "C" {
typedef struct _EvolutionImporterClient EvolutionImporterClient;
-typedef struct _EvolutionImporterClientPrivate EvolutionImporterClientPrivate;
typedef struct _EvolutionImporterClientClass EvolutionImporterClientClass;
struct _EvolutionImporterClient {
BonoboObjectClient parent;
-
- EvolutionImporterClientPrivate *private;
};
struct _EvolutionImporterClientClass {
BonoboObjectClientClass parent_class;
};
-typedef void (* EvolutionImporterClientCallback) (EvolutionImporterClient *client,
- EvolutionImporterResult result,
- gboolean more_items,
- void *data);
-
GtkType evolution_importer_client_get_type (void);
EvolutionImporterClient *evolution_importer_client_new (const CORBA_Object objref);
@@ -68,8 +61,7 @@ gboolean evolution_importer_client_support_format (EvolutionImporterClient *clie
gboolean evolution_importer_client_load_file (EvolutionImporterClient *client,
const char *filename);
void evolution_importer_client_process_item (EvolutionImporterClient *client,
- EvolutionImporterClientCallback callback,
- void *closure);
+ EvolutionImporterListener *listener);
const char *evolution_importer_client_get_error (EvolutionImporterClient *client);
#ifdef __cplusplus
diff --git a/shell/importer/importer.c b/shell/importer/importer.c
index 7bbec3aa66..1d245eb721 100644
--- a/shell/importer/importer.c
+++ b/shell/importer/importer.c
@@ -125,6 +125,7 @@ put_html (GtkHTML *html,
/* Data to be passed around */
typedef struct _ImporterComponentData {
EvolutionImporterClient *client;
+ EvolutionImporterListener *listener;
char *filename;
GnomeDialog *dialog;
@@ -138,7 +139,7 @@ typedef struct _ImporterComponentData {
static gboolean importer_timeout_fn (gpointer data);
static void
-import_cb (EvolutionImporterClient *client,
+import_cb (EvolutionImporterListener *listener,
EvolutionImporterResult result,
gboolean more_items,
void *data)
@@ -166,7 +167,13 @@ import_cb (EvolutionImporterClient *client,
return;
}
+ if (result == EVOLUTION_IMPORTER_BUSY) {
+ gtk_timeout_add (5000, importer_timeout_fn, data);
+ return;
+ }
+
if (more_items) {
+ g_warning ("Processing...\n");
label = g_strdup_printf (_("Importing %s\nImporting item %d."),
icd->filename, ++(icd->item));
gtk_label_set_text (GTK_LABEL (icd->contents), label);
@@ -174,14 +181,16 @@ import_cb (EvolutionImporterClient *client,
while (gtk_events_pending ())
gtk_main_iteration ();
- evolution_importer_client_process_item (client, import_cb, data);
+ g_idle_add_full (G_PRIORITY_LOW, importer_timeout_fn,
+ data, NULL);
return;
}
}
g_free (icd->filename);
if (!icd->destroyed)
- gtk_object_unref (GTK_OBJECT (icd->dialog));
+ gtk_object_destroy (GTK_OBJECT (icd->dialog));
+ bonobo_object_unref (BONOBO_OBJECT (icd->listener));
bonobo_object_unref (BONOBO_OBJECT (icd->client));
g_free (icd);
}
@@ -192,6 +201,7 @@ importer_timeout_fn (gpointer data)
ImporterComponentData *icd = (ImporterComponentData *) data;
char *label;
+ g_warning ("Idle called");
label = g_strdup_printf (_("Importing %s\nImporting item %d."),
icd->filename, icd->item);
gtk_label_set_text (GTK_LABEL (icd->contents), label);
@@ -199,7 +209,7 @@ importer_timeout_fn (gpointer data)
while (gtk_events_pending ())
gtk_main_iteration ();
- evolution_importer_client_process_item (icd->client, import_cb, data);
+ evolution_importer_client_process_item (icd->client, icd->listener);
return FALSE;
}
@@ -342,8 +352,9 @@ start_import (const char *filename,
g_free (label);
while (gtk_events_pending ())
gtk_main_iteration ();
-
- evolution_importer_client_process_item (icd->client, import_cb, icd);
+
+ icd->listener = evolution_importer_listener_new (import_cb, icd);
+ evolution_importer_client_process_item (icd->client, icd->listener);
}
static void