diff options
Diffstat (limited to 'addressbook')
-rw-r--r-- | addressbook/backend/ebook/Makefile.am | 2 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book-listener.c | 71 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book-listener.h | 5 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book.c | 121 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book.h | 36 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-cursor.c | 196 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-cursor.h | 33 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-pairs.h | 9 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.c | 2 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.h | 2 | ||||
-rw-r--r-- | addressbook/backend/ebook/test-card.c | 2 | ||||
-rw-r--r-- | addressbook/backend/ebook/test-client.c | 31 | ||||
-rw-r--r-- | addressbook/backend/idl/addressbook.idl | 9 | ||||
-rw-r--r-- | addressbook/backend/pas/Makefile.am | 6 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 106 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.c | 53 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.h | 9 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-card-cursor.c | 224 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-card-cursor.h | 58 |
19 files changed, 911 insertions, 64 deletions
diff --git a/addressbook/backend/ebook/Makefile.am b/addressbook/backend/ebook/Makefile.am index 84b85a8099..5619e9ca84 100644 --- a/addressbook/backend/ebook/Makefile.am +++ b/addressbook/backend/ebook/Makefile.am @@ -42,6 +42,7 @@ libebook_la_SOURCES = \ $(CORBA_SOURCE) \ e-book-listener.c \ e-book.c \ + e-card-cursor.c \ e-card.c libebookincludedir = $(includedir)/backend @@ -49,6 +50,7 @@ libebookincludedir = $(includedir)/backend libebookinclude_HEADERS = \ e-book.h \ e-book-listener.h \ + e-card-cursor.h \ e-card.h test_client_SOURCES = \ diff --git a/addressbook/backend/ebook/e-book-listener.c b/addressbook/backend/ebook/e-book-listener.c index 107f71fedc..826a070148 100644 --- a/addressbook/backend/ebook/e-book-listener.c +++ b/addressbook/backend/ebook/e-book-listener.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Exports the BookListener interface. Maintains a queue of messages * which come in on the interface. @@ -109,6 +110,38 @@ e_book_listener_queue_open_progress (EBookListener *listener, static void +e_book_listener_queue_create_card_response (EBookListener *listener, + EBookStatus status, + const char *id) +{ + EBookListenerResponse *resp; + + resp = g_new0 (EBookListenerResponse, 1); + + resp->op = CreateCardResponse; + resp->status = status; + resp->id = g_strdup (id); + + e_book_listener_queue_response (listener, resp); +} + +static void +e_book_listener_queue_get_cursor_response (EBookListener *listener, + EBookStatus status, + Evolution_CardCursor cursor) +{ + EBookListenerResponse *resp; + + resp = g_new0 (EBookListenerResponse, 1); + + resp->op = GetCursorResponse; + resp->status = status; + resp->cursor = cursor; + + e_book_listener_queue_response (listener, resp); +} + +static void e_book_listener_queue_link_status (EBookListener *listener, gboolean connected) { @@ -139,15 +172,17 @@ e_book_listener_queue_generic_event (EBookListener *listener, } static void -impl_BookListener_respond_create_card (PortableServer_Servant servant, - const Evolution_BookListener_CallStatus status, - CORBA_Environment *ev) +impl_BookListener_respond_create_card (PortableServer_Servant servant, + const Evolution_BookListener_CallStatus status, + const Evolution_CardId id, + CORBA_Environment *ev) { EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); - e_book_listener_queue_generic_response ( - listener, CreateCardResponse, - e_book_listener_convert_status (status)); + e_book_listener_queue_create_card_response ( + listener, + e_book_listener_convert_status (status), + id); } static void @@ -175,6 +210,28 @@ impl_BookListener_respond_modify_card (PortableServer_Servant servant, } static void +impl_BookListener_respond_get_cursor (PortableServer_Servant servant, + const Evolution_BookListener_CallStatus status, + const Evolution_CardCursor cursor, + CORBA_Environment *ev) +{ + EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); + Evolution_CardCursor cursor_copy; + + cursor_copy = CORBA_Object_duplicate (cursor, ev); + + if (ev->_major != CORBA_NO_EXCEPTION) { + g_warning ("EBookListener: Exception while duplicating CardCursor!\n"); + return; + } + + e_book_listener_queue_get_cursor_response ( + listener, + e_book_listener_convert_status (status), + cursor_copy); +} + +static void impl_BookListener_respond_open_book (PortableServer_Servant servant, const Evolution_BookListener_CallStatus status, const Evolution_Book book, @@ -446,6 +503,8 @@ e_book_listener_get_epv (void) epv->respond_remove_card = impl_BookListener_respond_remove_card; epv->respond_modify_card = impl_BookListener_respond_modify_card; + epv->respond_get_cursor = impl_BookListener_respond_get_cursor; + epv->report_connection_status = impl_BookListener_report_connection_status; epv->signal_card_changed = impl_BookListener_signal_card_changed; diff --git a/addressbook/backend/ebook/e-book-listener.h b/addressbook/backend/ebook/e-book-listener.h index 62ff8a3e09..27dd0df10f 100644 --- a/addressbook/backend/ebook/e-book-listener.h +++ b/addressbook/backend/ebook/e-book-listener.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * A client-side GtkObject which exposes the * Evolution:BookListener interface. @@ -40,6 +41,7 @@ typedef enum { CreateCardResponse, RemoveCardResponse, ModifyCardResponse, + GetCursorResponse, /* Async events */ CardAddedEvent, @@ -58,6 +60,9 @@ typedef struct { /* For OpenBookResponse */ Evolution_Book book; + /* For GetCursorResponse */ + Evolution_CardCursor cursor; + /* For OpenProgressEvent */ char *msg; short percent; diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c index b3c2e12b57..e95ff8f751 100644 --- a/addressbook/backend/ebook/e-book.c +++ b/addressbook/backend/ebook/e-book.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * The Evolution addressbook client object. * @@ -97,6 +98,25 @@ e_book_pop_op (EBook *book) } static void +e_book_do_response_create_card (EBook *book, + EBookListenerResponse *resp) +{ + EBookOp *op; + + op = e_book_pop_op (book); + + if (op == NULL) { + g_warning ("e_book_do_response_create_card: Cannot find operation " + "in local op queue!\n"); + return; + } + + ((EBookIdCallback) op->cb) (book, resp->status, resp->id, op->closure); + g_free (resp->id); + g_free (op); +} + +static void e_book_do_response_generic (EBook *book, EBookListenerResponse *resp) { @@ -115,6 +135,52 @@ e_book_do_response_generic (EBook *book, } static void +e_book_do_response_get_cursor (EBook *book, + EBookListenerResponse *resp) +{ + CORBA_Environment ev; + EBookOp *op; + ECardCursor *cursor; + + op = e_book_pop_op (book); + + if (op == NULL) { + g_warning ("e_book_do_response_create_card: Cannot find operation " + "in local op queue!\n"); + return; + } + + cursor = e_card_cursor_new(resp->cursor); + + ((EBookCursorCallback) op->cb) (book, resp->status, cursor, op->closure); + + /* + * Release the remote Evolution_Book in the PAS. + */ + CORBA_exception_init (&ev); + + Bonobo_Unknown_unref (resp->cursor, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("e_book_do_response_get_curosr: Exception unref'ing " + "remote Evolution_CardCursor interface!\n"); + CORBA_exception_free (&ev); + CORBA_exception_init (&ev); + } + + CORBA_Object_release (resp->cursor, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("e_book_do_response_get_cursor: Exception releasing " + "remote Evolution_CardCursor interface!\n"); + } + + CORBA_exception_free (&ev); + + g_free (op); +} + +static void e_book_do_response_open (EBook *book, EBookListenerResponse *resp) { @@ -205,10 +271,15 @@ e_book_check_listener_queue (EBookListener *listener) switch (resp->op) { case CreateCardResponse: + e_book_do_response_create_card (book, resp); + break; case RemoveCardResponse: case ModifyCardResponse: e_book_do_response_generic (book, resp); break; + case GetCursorResponse: + e_book_do_response_get_cursor (book, resp); + break; case OpenBookResponse: e_book_do_response_open (book, resp); break; @@ -541,10 +612,10 @@ e_book_remove_card_by_id (EBook *book, * e_book_add_card: */ gboolean -e_book_add_card (EBook *book, - ECard *card, - EBookCallback cb, - gpointer closure) +e_book_add_card (EBook *book, + ECard *card, + EBookIdCallback cb, + gpointer closure) { char *vcard; @@ -579,10 +650,10 @@ e_book_add_card (EBook *book, * e_book_add_vcard: */ gboolean -e_book_add_vcard (EBook *book, - const char *vcard, - EBookCallback cb, - gpointer closure) +e_book_add_vcard (EBook *book, + const char *vcard, + EBookIdCallback cb, + gpointer closure) { CORBA_Environment ev; @@ -609,7 +680,7 @@ e_book_add_vcard (EBook *book, CORBA_exception_free (&ev); - e_book_queue_op (book, cb, closure); + e_book_queue_op (book, (EBookCallback) cb, closure); return TRUE; } @@ -726,6 +797,38 @@ e_book_check_connection (EBook *book) return TRUE; } +gboolean e_book_get_all_cards (EBook *book, + EBookCursorCallback cb, + gpointer closure) +{ + CORBA_Environment ev; + + g_return_val_if_fail (book != NULL, FALSE); + g_return_val_if_fail (E_IS_BOOK (book), FALSE); + + if (book->priv->load_state != URILoaded) { + g_warning ("e_book_check_connection: No URI loaded!\n"); + return FALSE; + } + + CORBA_exception_init (&ev); + + Evolution_Book_get_all_cards (book->priv->corba_book, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("e_book_get_all_cards: Exception " + "querying list of cards!\n"); + CORBA_exception_free (&ev); + return FALSE; + } + + CORBA_exception_free (&ev); + + e_book_queue_op (book, cb, closure); + + return TRUE; +} + /** * e_book_get_name: */ diff --git a/addressbook/backend/ebook/e-book.h b/addressbook/backend/ebook/e-book.h index 8a3fb311c1..48756ff00c 100644 --- a/addressbook/backend/ebook/e-book.h +++ b/addressbook/backend/ebook/e-book.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * The Evolution addressbook client object. * @@ -14,6 +15,10 @@ #include <e-card.h> +typedef struct _EBook EBook; + +#include <e-card-cursor.h> + BEGIN_GNOME_DECLS typedef enum { @@ -24,14 +29,15 @@ typedef enum { E_BOOK_STATUS_CARD_NOT_FOUND } EBookStatus; +typedef struct _EBookClass EBookClass; typedef struct _EBookPrivate EBookPrivate; -typedef struct { +struct _EBook { GtkObject parent; EBookPrivate *priv; -} EBook; +}; -typedef struct { +struct _EBookClass { GtkObjectClass parent; /* @@ -42,7 +48,7 @@ typedef struct { void (* card_changed) (const char *id); void (* card_removed) (const char *id); void (* card_added) (const char *id); -} EBookClass; +}; /* Callbacks for asynchronous functions. */ typedef void (*EBookCallback) (EBook *book, EBookStatus status, gpointer closure); @@ -50,6 +56,8 @@ typedef void (*EBookOpenProgressCallback) (EBook *book, const char *status_message, short percent, gpointer closure); +typedef void (*EBookIdCallback) (EBook *book, EBookStatus status, const char *id, gpointer closure); +typedef void (*EBookCursorCallback) (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer closure); /* Creating a new addressbook. */ @@ -77,14 +85,14 @@ gboolean e_book_remove_card_by_id (EBook *book, gpointer closure); /* Adding cards. */ -gboolean e_book_add_card (EBook *book, - ECard *card, - EBookCallback cb, - gpointer closure); -gboolean e_book_add_vcard (EBook *book, - const char *vcard, - EBookCallback cb, - gpointer closure); +gboolean e_book_add_card (EBook *book, + ECard *card, + EBookIdCallback cb, + gpointer closure); +gboolean e_book_add_vcard (EBook *book, + const char *vcard, + EBookIdCallback cb, + gpointer closure); /* Modifying cards. */ gboolean e_book_commit_card (EBook *book, @@ -99,6 +107,10 @@ gboolean e_book_commit_vcard (EBook *book, /* Checking to see if we're connected to the card repository. */ gboolean e_book_check_connection (EBook *book); +gboolean e_book_get_all_cards (EBook *book, + EBookCursorCallback cb, + gpointer closure); + /* Getting the name of the repository. */ char *e_book_get_name (EBook *book); diff --git a/addressbook/backend/ebook/e-card-cursor.c b/addressbook/backend/ebook/e-card-cursor.c new file mode 100644 index 0000000000..7a51698d54 --- /dev/null +++ b/addressbook/backend/ebook/e-card-cursor.c @@ -0,0 +1,196 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-card-cursor.c: Implements card cursors. + * + * Author: + * Christopher James Lahey <clahey@helixcode.com. + */ + +#include <config.h> +#include <bonobo.h> +#include "addressbook.h" +#include "e-card-cursor.h" + +struct _ECardCursorPrivate { + Evolution_CardCursor corba_cursor; +}; + +/* + * A pointer to our parent object class + */ +static GtkObjectClass *parent_class; + +/* + * Implemented GtkObject::destroy + */ +static void +e_card_cursor_destroy (GtkObject *object) +{ + ECardCursor *cursor = E_CARD_CURSOR (object); + CORBA_Environment ev; + + CORBA_exception_init (&ev); + + Evolution_CardCursor_unref( cursor->priv->corba_cursor, &ev ); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("e_card_cursor_destroy: Exception unreffing " + "corba cursor.\n"); + } + + CORBA_exception_free (&ev); + + if ( cursor->priv ) + g_free ( cursor->priv ); + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + +/* + * CORBA Demo::Echo::echo method implementation + */ +long +e_card_cursor_get_length (ECardCursor *cursor) +{ + if ( cursor->priv->corba_cursor != CORBA_OBJECT_NIL ) { + CORBA_Environment ev; + long ret_val; + + CORBA_exception_init (&ev); + + ret_val = Evolution_CardCursor_get_length(cursor->priv->corba_cursor, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("e_card_cursor_get_length: Exception during " + "get_length corba call.\n"); + } + + CORBA_exception_free (&ev); + + return ret_val; + } + else + return 0; +} + +/* + * CORBA Demo::Echo::echo method implementation + */ +ECard * +e_card_cursor_get_nth (ECardCursor *cursor, + const long n) +{ + if ( cursor->priv->corba_cursor != CORBA_OBJECT_NIL ) { + CORBA_Environment ev; + CORBA_char * ret_val; + ECard *card; + + CORBA_exception_init (&ev); + + ret_val = Evolution_CardCursor_get_nth(cursor->priv->corba_cursor, n, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("e_card_cursor_get_nth: Exception during " + "get_nth corba call.\n"); + CORBA_exception_free (&ev); + CORBA_exception_init (&ev); + } + + card = e_card_new(ret_val); +#if 0 + CORBA_string__free(ret_val, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("e_card_cursor_get_nth: Exception freeing " + "string.\n"); + } +#endif + CORBA_exception_free (&ev); + + return card; + } + else + return e_card_new(""); +} + +static void +e_card_cursor_class_init (ECardCursorClass *klass) +{ + GtkObjectClass *object_class = (GtkObjectClass *) klass; + + parent_class = gtk_type_class (bonobo_object_get_type ()); + + object_class->destroy = e_card_cursor_destroy; +} + +static void +e_card_cursor_init (ECardCursor *cursor) +{ + cursor->priv = g_new(ECardCursorPrivate, 1); + cursor->priv->corba_cursor = CORBA_OBJECT_NIL; +} + +GtkType +e_card_cursor_get_type (void) +{ + static GtkType type = 0; + + if (!type){ + GtkTypeInfo info = { + "ECardCursor", + sizeof (ECardCursor), + sizeof (ECardCursorClass), + (GtkClassInitFunc) e_card_cursor_class_init, + (GtkObjectInitFunc) e_card_cursor_init, + NULL, /* reserved 1 */ + NULL, /* reserved 2 */ + (GtkClassInitFunc) NULL + }; + + type = gtk_type_unique (gtk_object_get_type (), &info); + } + + return type; +} + +ECardCursor * +e_card_cursor_construct (ECardCursor *cursor, + Evolution_CardCursor corba_cursor) +{ + CORBA_Environment ev; + g_return_val_if_fail (cursor != NULL, NULL); + g_return_val_if_fail (E_IS_CARD_CURSOR (cursor), NULL); + g_return_val_if_fail (corba_cursor != CORBA_OBJECT_NIL, NULL); + + /* + * Initialize cursor + */ + cursor->priv->corba_cursor = corba_cursor; + + CORBA_exception_init (&ev); + + Evolution_CardCursor_ref(corba_cursor, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("e_card_cursor_construct: Exception reffing " + "corba cursor.\n"); + } + + CORBA_exception_free (&ev); + + /* + * Success: return the GtkType we were given + */ + return cursor; +} + +ECardCursor * +e_card_cursor_new (Evolution_CardCursor corba_cursor) +{ + ECardCursor *cursor; + + cursor = gtk_type_new (e_card_cursor_get_type ()); + + return e_card_cursor_construct (cursor, + corba_cursor); +} diff --git a/addressbook/backend/ebook/e-card-cursor.h b/addressbook/backend/ebook/e-card-cursor.h index 5477a4f615..3e9523e86f 100644 --- a/addressbook/backend/ebook/e-card-cursor.h +++ b/addressbook/backend/ebook/e-card-cursor.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * * Author: @@ -6,36 +7,42 @@ * Copyright 2000, Helix Code, Inc. */ -#include <gtk/gtkobject.h> +#ifndef __E_CARD_CURSOR_H__ +#define __E_CARD_CURSOR_H__ + #include <libgnome/gnome-defs.h> +#include <gtk/gtk.h> +#include "addressbook.h" -#include <e-book.h> +typedef struct _ECardCursor ECardCursor; -#ifndef __E_CARD_CURSOR_H__ -#define __E_CARD_CURSOR_H__ +#include <e-book.h> BEGIN_GNOME_DECLS typedef struct _ECardCursorPrivate ECardCursorPrivate; +typedef struct _ECardCursorClass ECardCursorClass; -typedef struct { - GtkObject parent; +struct _ECardCursor { + GtkObject parent; ECardCursorPrivate *priv; -} ECardCursor; +}; -typedef struct { +struct _ECardCursorClass { GtkObjectClass parent; -} ECardCursorClass; +}; /* Creating a new addressbook. */ -ECardCursor *e_card_cursor_new (EBook *book, - Evolution_CardCursor corba_cursor); +ECardCursor *e_card_cursor_new (Evolution_CardCursor corba_cursor); +ECardCursor *e_card_cursor_construct (ECardCursor *cursor, + Evolution_CardCursor corba_cursor); + GtkType e_card_cursor_get_type (void); /* Fetching cards. */ -int e_card_cursor_get_length (ECardCursor *cursor); +long e_card_cursor_get_length (ECardCursor *cursor); ECard *e_card_cursor_get_nth (ECardCursor *cursor, - int nth); + const long nth); #define E_CARD_CURSOR_TYPE (e_card_cursor_get_type ()) #define E_CARD_CURSOR(o) (GTK_CHECK_CAST ((o), E_CARD_CURSOR_TYPE, ECardCursor)) #define E_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CARD_CURSOR_TYPE, ECardCursorClass)) diff --git a/addressbook/backend/ebook/e-card-pairs.h b/addressbook/backend/ebook/e-card-pairs.h index e9a7f089f7..2c7635b8a4 100644 --- a/addressbook/backend/ebook/e-card-pairs.h +++ b/addressbook/backend/ebook/e-card-pairs.h @@ -68,15 +68,6 @@ struct pair prop_lookup[] = { { VCCharSetProp, PROP_CHARSET }, { NULL, PROP_NONE} }; -struct pair addr_pairs[] = { - { VCDomesticProp, ADDR_DOM }, - { VCInternationalProp, ADDR_INTL }, - { VCPostalProp, ADDR_POSTAL }, - { VCParcelProp, ADDR_PARCEL }, - { VCHomeProp, ADDR_HOME }, - { VCWorkProp, ADDR_WORK }, - { NULL, 0} }; - struct pair photo_pairs[] = { { VCGIFProp, PHOTO_GIF }, { VCCGMProp, PHOTO_CGM }, diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index c259ea5193..282f1fe215 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -130,7 +130,7 @@ e_card_get_id (ECard *card) } void -e_card_set_id (ECard *card, char *id) +e_card_set_id (ECard *card, const char *id) { if ( card->id ) g_free(card->id); diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h index b5abf34e24..200d4c3b3e 100644 --- a/addressbook/backend/ebook/e-card.h +++ b/addressbook/backend/ebook/e-card.h @@ -86,7 +86,7 @@ struct _ECardClass { ECard *e_card_new (char *vcard); char *e_card_get_id (ECard *card); -void e_card_set_id (ECard *card, gchar *character); +void e_card_set_id (ECard *card, const gchar *character); char *e_card_get_vcard (ECard *card); /* Standard Gtk function */ diff --git a/addressbook/backend/ebook/test-card.c b/addressbook/backend/ebook/test-card.c index 1da02bad18..d032dfe707 100644 --- a/addressbook/backend/ebook/test-card.c +++ b/addressbook/backend/ebook/test-card.c @@ -85,7 +85,7 @@ main (int argc, char **argv) } #endif card = e_card_new (cardstr); - gtk_object_get(card, + gtk_object_get(GTK_OBJECT(card), "full_name", &fname, "name", &name, "address", &address, diff --git a/addressbook/backend/ebook/test-client.c b/addressbook/backend/ebook/test-client.c index 365019f7bd..945df3f53c 100644 --- a/addressbook/backend/ebook/test-client.c +++ b/addressbook/backend/ebook/test-client.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ #include <config.h> #include <bonobo.h> #include <gnome.h> @@ -47,8 +48,26 @@ init_bonobo (int argc, char **argv) } +#if 0 static void -add_card_cb (EBook *book, EBookStatus status, gpointer closure) +get_cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer closure) +{ + long length = e_card_cursor_get_length(cursor); + long i; + + for ( i = 0; i < length; i++ ) { + ECard *card = e_card_cursor_get_nth(cursor, i); + char *vcard = e_card_get_vcard(card); + printf("[%s]\n", vcard); + g_free(vcard); + gtk_object_unref(GTK_OBJECT(card)); + } + gtk_object_unref(GTK_OBJECT(cursor)); +} +#endif + +static void +add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) { char *vcard; ECard *card; @@ -56,9 +75,11 @@ add_card_cb (EBook *book, EBookStatus status, gpointer closure) printf ("Status: %d\n", status); + printf ("Id: %s\n", id); + timer = g_timer_new (); g_timer_start (timer); - card = e_book_get_card (book, "foo"); + card = e_book_get_card (book, id); g_timer_stop (timer); vcard = e_card_get_vcard(card); @@ -66,12 +87,16 @@ add_card_cb (EBook *book, EBookStatus status, gpointer closure) printf ("[%s]\n", vcard); g_free(vcard); gtk_object_unref(GTK_OBJECT(card)); + +#if 0 + e_book_get_all_cards(book, get_cursor_cb, NULL); +#endif } static void book_open_cb (EBook *book, EBookStatus status, gpointer closure) { - e_book_add_vcard(book, TEST_VCARD, add_card_cb, NULL); + e_book_add_vcard(book, TEST_VCARD, add_card_cb, NULL); } static guint diff --git a/addressbook/backend/idl/addressbook.idl b/addressbook/backend/idl/addressbook.idl index 076216c9cf..5fd0dbbf2e 100644 --- a/addressbook/backend/idl/addressbook.idl +++ b/addressbook/backend/idl/addressbook.idl @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * * Author: @@ -12,7 +13,7 @@ module Evolution { typedef string CardId; - interface CardCursor { + interface CardCursor : Bonobo::Unknown { long get_length (); string get_nth (in long n); }; @@ -34,6 +35,8 @@ module Evolution { */ void modify_card (in string vcard); + void get_all_cards (); + void check_connection (); string get_name (); @@ -48,7 +51,7 @@ module Evolution { CardNotFound }; - void respond_create_card (in CallStatus status); + void respond_create_card (in CallStatus status, in CardId Id); void respond_remove_card (in CallStatus status); @@ -58,6 +61,8 @@ module Evolution { void respond_open_book (in CallStatus status, in Book book); + void respond_get_cursor (in CallStatus status, in CardCursor cursor); + /** * report_connection_status: * diff --git a/addressbook/backend/pas/Makefile.am b/addressbook/backend/pas/Makefile.am index 36eeab0782..20b2d85531 100644 --- a/addressbook/backend/pas/Makefile.am +++ b/addressbook/backend/pas/Makefile.am @@ -43,7 +43,8 @@ libpas_la_SOURCES = \ pas-book.c \ pas-book-factory.c \ pas-backend.c \ - pas-backend-file.c + pas-backend-file.c \ + pas-card-cursor.c libpasincludedir = $(includedir)/backend @@ -51,7 +52,8 @@ libpasinclude_HEADERS = \ pas-book.h \ pas-book-factory.h \ pas-backend.h \ - pas-backend-file.h + pas-backend-file.h \ + pas-card-cursor.h wombat_SOURCES = \ pas.c diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index bf5ef55c2f..04f59d40f8 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -17,11 +17,13 @@ #include <pas-backend-file.h> #include <pas-book.h> +#include <pas-card-cursor.h> #define PAS_BACKEND_FILE_VERSION_NAME "PAS-DB-VERSION" #define PAS_BACKEND_FILE_VERSION "0.1" static PASBackendClass *pas_backend_file_parent_class; +typedef struct _PASBackendFileCursorPrivate PASBackendFileCursorPrivate; struct _PASBackendFilePrivate { GList *clients; @@ -29,6 +31,52 @@ struct _PASBackendFilePrivate { DB *file_db; }; +struct _PASBackendFileCursorPrivate { + PASBackend *backend; + PASBook *book; +}; + +static long +get_length(PASCardCursor *cursor, gpointer data) +{ +#if 0 + PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; +#endif + return 0; +} + +static char * +get_nth(PASCardCursor *cursor, long n, gpointer data) +{ +#if 0 + PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; +#endif + return ""; +} + +static void +cursor_destroy(GtkObject *object, gpointer data) +{ + CORBA_Environment ev; + Evolution_Book corba_book; + PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; + + corba_book = bonobo_object_corba_objref(cursor_data->book); + + CORBA_exception_init(&ev); + + Evolution_Book_unref(corba_book, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("cursor_destroy: Exception unreffing " + "corba book.\n"); + } + + CORBA_exception_free(&ev); + + g_free(cursor_data); +} + static void string_to_dbt(const char *str, DBT *dbt) { @@ -65,7 +113,8 @@ pas_backend_file_process_create_card (PASBackend *backend, pas_book_respond_create ( book, - Evolution_BookListener_Success); + Evolution_BookListener_Success, + id); db_error = db->sync (db, 0); if (db_error != 0) @@ -76,7 +125,8 @@ pas_backend_file_process_create_card (PASBackend *backend, think */ pas_book_respond_create ( book, - Evolution_BookListener_CardNotFound); + Evolution_BookListener_CardNotFound, + ""); } g_free (id); @@ -154,6 +204,54 @@ pas_backend_file_process_modify_card (PASBackend *backend, } static void +pas_backend_file_process_get_all_cards (PASBackend *backend, + PASBook *book, + PASRequest *req) +{ + /* + PASBackendFile *bf = PAS_BACKEND_FILE (backend); + DB *db = bf->priv->file_db; + DBT id_dbt, vcard_dbt; + */ + CORBA_Environment ev; + int db_error = 0; + PASBackendFileCursorPrivate *cursor_data; + PASCardCursor *cursor; + Evolution_Book corba_book; + + cursor_data = g_new(PASBackendFileCursorPrivate, 1); + cursor_data->backend = backend; + cursor_data->book = book; + + corba_book = bonobo_object_corba_objref(book); + + CORBA_exception_init(&ev); + + Evolution_Book_ref(corba_book, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("pas_backend_file_process_get_all_cards: Exception reffing " + "corba book.\n"); + } + + CORBA_exception_free(&ev); + + cursor = pas_card_cursor_new(get_length, + get_nth, + cursor_data); + + gtk_signal_connect(GTK_OBJECT(cursor), "destroy", + GTK_SIGNAL_FUNC(cursor_destroy), cursor_data); + + pas_book_respond_get_cursor ( + book, + (db_error == 0 + ? Evolution_BookListener_Success + : Evolution_BookListener_CardNotFound), + cursor); +} + +static void pas_backend_file_process_check_connection (PASBackend *backend, PASBook *book, PASRequest *req) @@ -191,6 +289,10 @@ pas_backend_file_process_client_requests (PASBook *book) case CheckConnection: pas_backend_file_process_check_connection (backend, book, req); break; + + case GetAllCards: + pas_backend_file_process_get_all_cards (backend, book, req); + break; } g_free (req); diff --git a/addressbook/backend/pas/pas-book.c b/addressbook/backend/pas/pas-book.c index 907ff6482a..f571bc4044 100644 --- a/addressbook/backend/pas/pas-book.c +++ b/addressbook/backend/pas/pas-book.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * pas-book.c * @@ -90,6 +91,17 @@ pas_book_queue_modify_card (PASBook *book, const char *vcard) } static void +pas_book_queue_get_all_cards (PASBook *book) +{ + PASRequest *req; + + req = g_new0 (PASRequest, 1); + req->op = GetAllCards; + + pas_book_queue_request (book, req); +} + +static void pas_book_queue_check_connection (PASBook *book) { PASRequest *req; @@ -147,6 +159,15 @@ impl_Evolution_Book_modify_card (PortableServer_Servant servant, } static void +impl_Evolution_Book_get_all_cards (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); + + pas_book_queue_get_all_cards (book); +} + +static void impl_Evolution_Book_check_connection (PortableServer_Servant servant, CORBA_Environment *ev) { @@ -253,14 +274,15 @@ pas_book_respond_open (PASBook *book, */ void pas_book_respond_create (PASBook *book, - Evolution_BookListener_CallStatus status) + Evolution_BookListener_CallStatus status, + const char *id) { CORBA_Environment ev; CORBA_exception_init (&ev); Evolution_BookListener_respond_create_card ( - book->priv->listener, status, &ev); + book->priv->listener, status, (char *)id, &ev); if (ev._major != CORBA_NO_EXCEPTION) { g_warning ("pas_book_respond_create: Exception " @@ -315,6 +337,32 @@ pas_book_respond_modify (PASBook *book, } /** + * pas_book_respond_get_cursor: + */ +void +pas_book_respond_get_cursor (PASBook *book, + Evolution_BookListener_CallStatus status, + PASCardCursor *cursor) +{ + CORBA_Environment ev; + CORBA_Object object; + + CORBA_exception_init (&ev); + + object = bonobo_object_corba_objref(BONOBO_OBJECT(cursor)); + + Evolution_BookListener_respond_get_cursor ( + book->priv->listener, status, object, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("pas_book_respond_get_cursor: Exception " + "responding to BookListener!\n"); + } + + CORBA_exception_free (&ev); +} + +/** * pas_book_report_connection: */ void @@ -502,6 +550,7 @@ pas_book_get_epv (void) epv->remove_card = impl_Evolution_Book_remove_card; epv->modify_card = impl_Evolution_Book_modify_card; epv->check_connection = impl_Evolution_Book_check_connection; + epv->get_all_cards = impl_Evolution_Book_get_all_cards; return epv; diff --git a/addressbook/backend/pas/pas-book.h b/addressbook/backend/pas/pas-book.h index c4763d1654..ab0dced4e4 100644 --- a/addressbook/backend/pas/pas-book.h +++ b/addressbook/backend/pas/pas-book.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * A wrapper object which exports the Evolution_Book CORBA interface * and which maintains a request queue. @@ -19,11 +20,13 @@ typedef struct _PASBook PASBook; typedef struct _PASBookPrivate PASBookPrivate; #include <pas-backend.h> +#include <pas-card-cursor.h> typedef enum { CreateCard, RemoveCard, ModifyCard, + GetAllCards, CheckConnection } PASOperation; @@ -58,11 +61,15 @@ PASRequest *pas_book_pop_request (PASBook void pas_book_respond_open (PASBook *book, Evolution_BookListener_CallStatus status); void pas_book_respond_create (PASBook *book, - Evolution_BookListener_CallStatus status); + Evolution_BookListener_CallStatus status, + const char *id); void pas_book_respond_remove (PASBook *book, Evolution_BookListener_CallStatus status); void pas_book_respond_modify (PASBook *book, Evolution_BookListener_CallStatus status); +void pas_book_respond_get_cursor (PASBook *book, + Evolution_BookListener_CallStatus status, + PASCardCursor *cursor); void pas_book_report_connection (PASBook *book, gboolean connected); diff --git a/addressbook/backend/pas/pas-card-cursor.c b/addressbook/backend/pas/pas-card-cursor.c new file mode 100644 index 0000000000..b6ef91f41c --- /dev/null +++ b/addressbook/backend/pas/pas-card-cursor.c @@ -0,0 +1,224 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * pas-card-cursor.c: Implements card cursors. + * + * Author: + * Christopher James Lahey <clahey@helixcode.com. + */ + +#include <config.h> +#include <bonobo.h> +#include "addressbook.h" +#include "pas-card-cursor.h" + +struct _PASCardCursorPrivate { + long (*get_length) (PASCardCursor *cursor, gpointer data); + char * (*get_nth) (PASCardCursor *cursor, long n, gpointer data); + gpointer data; +}; + +/* + * A pointer to our parent object class + */ +static BonoboObjectClass *parent_class; + +/* + * The VEPV for the CardCursor object + */ +static POA_Evolution_CardCursor__vepv cursor_vepv; + +/* + * Implemented GtkObject::destroy + */ +static void +pas_card_cursor_destroy (GtkObject *object) +{ + PASCardCursor *cursor = PAS_CARD_CURSOR (object); + + if ( cursor->priv ) + g_free ( cursor->priv ); + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + +/* + * CORBA Demo::Echo::echo method implementation + */ +static CORBA_long +impl_pas_card_cursor_get_length (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant)); + if ( cursor->priv->get_length ) + return cursor->priv->get_length( cursor, cursor->priv->data ); + else + return 0; +} + +/* + * CORBA Demo::Echo::echo method implementation + */ +static char * +impl_pas_card_cursor_get_nth (PortableServer_Servant servant, + const CORBA_long n, + CORBA_Environment *ev) +{ + PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant)); + if ( cursor->priv->get_nth ) + return cursor->priv->get_nth( cursor, n, cursor->priv->data ); + else + return ""; +} + +/* + * If you want users to derive classes from your implementation + * you need to support this method. + */ +POA_Evolution_CardCursor__epv * +pas_card_cursor_get_epv (void) +{ + POA_Evolution_CardCursor__epv *epv; + + epv = g_new0 (POA_Evolution_CardCursor__epv, 1); + + /* + * This is the method invoked by CORBA + */ + epv->get_length = impl_pas_card_cursor_get_length; + epv->get_nth = impl_pas_card_cursor_get_nth; + + return epv; +} + +static void +init_pas_card_cursor_corba_class (void) +{ + cursor_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); + cursor_vepv.Evolution_CardCursor_epv = pas_card_cursor_get_epv (); +} + +static void +pas_card_cursor_class_init (PASCardCursorClass *klass) +{ + GtkObjectClass *object_class = (GtkObjectClass *) klass; + + parent_class = gtk_type_class (bonobo_object_get_type ()); + + object_class->destroy = pas_card_cursor_destroy; + + init_pas_card_cursor_corba_class (); +} + +static void +pas_card_cursor_init (PASCardCursor *cursor) +{ + cursor->priv = g_new(PASCardCursorPrivate, 1); + cursor->priv->get_length = NULL; + cursor->priv->get_nth = NULL; + cursor->priv->data = NULL; +} + +GtkType +pas_card_cursor_get_type (void) +{ + static GtkType type = 0; + + if (!type){ + GtkTypeInfo info = { + "PASCardCursor", + sizeof (PASCardCursor), + sizeof (PASCardCursorClass), + (GtkClassInitFunc) pas_card_cursor_class_init, + (GtkObjectInitFunc) pas_card_cursor_init, + NULL, /* reserved 1 */ + NULL, /* reserved 2 */ + (GtkClassInitFunc) NULL + }; + + type = gtk_type_unique (bonobo_object_get_type (), &info); + } + + return type; +} + +PASCardCursor * +pas_card_cursor_construct (PASCardCursor *cursor, + Evolution_CardCursor corba_cursor, + PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data) +{ + g_return_val_if_fail (cursor != NULL, NULL); + g_return_val_if_fail (PAS_IS_CARD_CURSOR (cursor), NULL); + g_return_val_if_fail (corba_cursor != CORBA_OBJECT_NIL, NULL); + + /* + * Call parent constructor + */ + if (!bonobo_object_construct (BONOBO_OBJECT (cursor), (CORBA_Object) corba_cursor)) + return NULL; + + /* + * Initialize cursor + */ + cursor->priv->get_length = get_length; + cursor->priv->get_nth = get_nth; + cursor->priv->data = data; + + /* + * Success: return the GtkType we were given + */ + return cursor; +} + +/* + * This routine creates the ORBit CORBA server and initializes the + * CORBA side of things + */ +static Evolution_CardCursor +create_cursor (BonoboObject *cursor) +{ + POA_Evolution_CardCursor *servant; + CORBA_Environment ev; + + servant = (POA_Evolution_CardCursor *) g_new (BonoboObjectServant, 1); + servant->vepv = &cursor_vepv; + + CORBA_exception_init (&ev); + POA_Evolution_CardCursor__init ((PortableServer_Servant) servant, &ev); + if (ev._major != CORBA_NO_EXCEPTION){ + g_free (servant); + CORBA_exception_free (&ev); + return CORBA_OBJECT_NIL; + } + + CORBA_exception_free (&ev); + + /* + * Activates the CORBA object. + */ + return (Evolution_CardCursor) bonobo_object_activate_servant (cursor, servant); +} + +PASCardCursor * +pas_card_cursor_new (PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data) +{ + PASCardCursor *cursor; + Evolution_CardCursor corba_cursor; + + cursor = gtk_type_new (pas_card_cursor_get_type ()); + corba_cursor = create_cursor (BONOBO_OBJECT (cursor)); + + if (corba_cursor == CORBA_OBJECT_NIL){ + gtk_object_destroy (GTK_OBJECT (cursor)); + return NULL; + } + + return pas_card_cursor_construct (cursor, + corba_cursor, + get_length, + get_nth, + data); +} diff --git a/addressbook/backend/pas/pas-card-cursor.h b/addressbook/backend/pas/pas-card-cursor.h new file mode 100644 index 0000000000..a829d2c838 --- /dev/null +++ b/addressbook/backend/pas/pas-card-cursor.h @@ -0,0 +1,58 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * + * Author: + * Nat Friedman (nat@helixcode.com) + * + * Copyright 2000, Helix Code, Inc. + */ + +#ifndef __PAS_CARD_CURSOR_H__ +#define __PAS_CARD_CURSOR_H__ + +#include <libgnome/gnome-defs.h> +#include <bonobo/bonobo-object.h> +#include "addressbook.h" + +BEGIN_GNOME_DECLS + +typedef struct _PASCardCursor PASCardCursor; +typedef struct _PASCardCursorPrivate PASCardCursorPrivate; +typedef struct _PASCardCursorClass PASCardCursorClass; + +typedef long (*PASCardCursorLengthFunc) (PASCardCursor *cursor, gpointer data); +typedef char * (*PASCardCursorNthFunc) (PASCardCursor *cursor, long n, gpointer data); + +struct _PASCardCursor { + BonoboObject parent; + PASCardCursorPrivate *priv; +}; + +struct _PASCardCursorClass { + BonoboObjectClass parent; +}; + +/* Creating a new addressbook. */ +PASCardCursor *pas_card_cursor_new (PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data); +PASCardCursor *pas_card_cursor_construct (PASCardCursor *cursor, + Evolution_CardCursor corba_cursor, + PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data); + +GtkType pas_card_cursor_get_type (void); +POA_Evolution_CardCursor__epv * + pas_card_cursor_get_epv (void); + +/* Fetching cards. */ +#define PAS_CARD_CURSOR_TYPE (pas_card_cursor_get_type ()) +#define PAS_CARD_CURSOR(o) (GTK_CHECK_CAST ((o), PAS_CARD_CURSOR_TYPE, PASCardCursor)) +#define PAS_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_CARD_CURSOR_TYPE, PASCardCursorClass)) +#define PAS_IS_CARD_CURSOR(o) (GTK_CHECK_TYPE ((o), PAS_CARD_CURSOR_TYPE)) +#define PAS_IS_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_CARD_CURSOR_TYPE)) + +END_GNOME_DECLS + +#endif /* ! __PAS_CARD_CURSOR_H__ */ |