aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend/ebook
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-08-14 10:17:04 +0800
committerChris Lahey <clahey@src.gnome.org>2001-08-14 10:17:04 +0800
commit476458f355b639cb725188d9d8e767affa71f4ab (patch)
tree8d6686abbf6334ad7b65aa8ea15895d58e88b6bd /addressbook/backend/ebook
parent3157a507b2074766bbd88300cec543a28418d443 (diff)
downloadgsoc2013-evolution-476458f355b639cb725188d9d8e767affa71f4ab.tar
gsoc2013-evolution-476458f355b639cb725188d9d8e767affa71f4ab.tar.gz
gsoc2013-evolution-476458f355b639cb725188d9d8e767affa71f4ab.tar.bz2
gsoc2013-evolution-476458f355b639cb725188d9d8e767affa71f4ab.tar.lz
gsoc2013-evolution-476458f355b639cb725188d9d8e767affa71f4ab.tar.xz
gsoc2013-evolution-476458f355b639cb725188d9d8e767affa71f4ab.tar.zst
gsoc2013-evolution-476458f355b639cb725188d9d8e767affa71f4ab.zip
Changed get_card to be asyncronous.
2001-08-13 Christopher James Lahey <clahey@ximian.com> * backend/ebook/e-book-listener.c, backend/ebook/e-book-listener.h, backend/ebook/e-book.c, backend/ebook/e-book.h, backend/idl/addressbook.idl, backend/pas/pas-backend-file.c, backend/pas/pas-book.c, backend/pas/pas-book.h: Changed get_card to be asyncronous. * backend/ebook/e-card.c, backend/ebook/test-client.c: Changed these to deal with the new get_card functionality. svn path=/trunk/; revision=11984
Diffstat (limited to 'addressbook/backend/ebook')
-rw-r--r--addressbook/backend/ebook/e-book-listener.c58
-rw-r--r--addressbook/backend/ebook/e-book-listener.h2
-rw-r--r--addressbook/backend/ebook/e-book.c117
-rw-r--r--addressbook/backend/ebook/e-book.h15
-rw-r--r--addressbook/backend/ebook/e-card.c15
-rw-r--r--addressbook/backend/ebook/test-client.c28
6 files changed, 141 insertions, 94 deletions
diff --git a/addressbook/backend/ebook/e-book-listener.c b/addressbook/backend/ebook/e-book-listener.c
index 285c6646b2..aa05a87a2b 100644
--- a/addressbook/backend/ebook/e-book-listener.c
+++ b/addressbook/backend/ebook/e-book-listener.c
@@ -149,6 +149,25 @@ e_book_listener_queue_create_card_response (EBookListener *listener,
}
static void
+e_book_listener_queue_get_vcard_response (EBookListener *listener,
+ EBookStatus status,
+ const char *vcard)
+{
+ EBookListenerResponse *resp;
+
+ if (listener->priv->stopped)
+ return;
+
+ resp = g_new0 (EBookListenerResponse, 1);
+
+ resp->op = GetCardResponse;
+ resp->status = status;
+ resp->vcard = g_strdup (vcard);
+
+ e_book_listener_queue_response (listener, resp);
+}
+
+static void
e_book_listener_queue_get_cursor_response (EBookListener *listener,
EBookStatus status,
GNOME_Evolution_Addressbook_CardCursor cursor)
@@ -319,6 +338,20 @@ impl_BookListener_respond_modify_card (PortableServer_Servant servant,
}
static void
+impl_BookListener_respond_get_vcard (PortableServer_Servant servant,
+ const GNOME_Evolution_Addressbook_BookListener_CallStatus status,
+ const GNOME_Evolution_Addressbook_VCard card,
+ CORBA_Environment *ev)
+{
+ EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant));
+
+ e_book_listener_queue_get_vcard_response (
+ listener,
+ e_book_listener_convert_status (status),
+ g_strdup (card));
+}
+
+static void
impl_BookListener_respond_get_cursor (PortableServer_Servant servant,
const GNOME_Evolution_Addressbook_BookListener_CallStatus status,
const GNOME_Evolution_Addressbook_CardCursor cursor,
@@ -692,24 +725,25 @@ e_book_listener_get_epv (void)
{
POA_GNOME_Evolution_Addressbook_BookListener__epv *epv;
- epv = g_new0 (POA_GNOME_Evolution_Addressbook_BookListener__epv, 1);
+ epv = g_new0 (POA_GNOME_Evolution_Addressbook_BookListener__epv, 1);
- epv->notifyOpenBookProgress = impl_BookListener_report_open_book_progress;
- epv->notifyBookOpened = impl_BookListener_respond_open_book;
+ epv->notifyOpenBookProgress = impl_BookListener_report_open_book_progress;
+ epv->notifyBookOpened = impl_BookListener_respond_open_book;
- epv->notifyCardCreated = impl_BookListener_respond_create_card;
- epv->notifyCardRemoved = impl_BookListener_respond_remove_card;
- epv->notifyCardModified = impl_BookListener_respond_modify_card;
+ epv->notifyCardCreated = impl_BookListener_respond_create_card;
+ epv->notifyCardRemoved = impl_BookListener_respond_remove_card;
+ epv->notifyCardModified = impl_BookListener_respond_modify_card;
epv->notifyAuthenticationResult = impl_BookListener_respond_authentication_result;
- epv->notifySupportedFields = impl_BookListener_response_get_supported_fields;
+ epv->notifySupportedFields = impl_BookListener_response_get_supported_fields;
- epv->notifyCursorRequested = impl_BookListener_respond_get_cursor;
- epv->notifyViewRequested = impl_BookListener_respond_get_view;
- epv->notifyChangesRequested = impl_BookListener_respond_get_changes;
+ epv->notifyCardRequested = impl_BookListener_respond_get_vcard;
+ epv->notifyCursorRequested = impl_BookListener_respond_get_cursor;
+ epv->notifyViewRequested = impl_BookListener_respond_get_view;
+ epv->notifyChangesRequested = impl_BookListener_respond_get_changes;
- epv->notifyConnectionStatus = impl_BookListener_report_connection_status;
- epv->notifyWritable = impl_BookListener_report_writable;
+ epv->notifyConnectionStatus = impl_BookListener_report_connection_status;
+ epv->notifyWritable = impl_BookListener_report_writable;
return epv;
}
diff --git a/addressbook/backend/ebook/e-book-listener.h b/addressbook/backend/ebook/e-book-listener.h
index 16cb518ce5..f546c9a029 100644
--- a/addressbook/backend/ebook/e-book-listener.h
+++ b/addressbook/backend/ebook/e-book-listener.h
@@ -44,6 +44,7 @@ typedef enum {
CreateCardResponse,
RemoveCardResponse,
ModifyCardResponse,
+ GetCardResponse,
GetCursorResponse,
GetBookViewResponse,
GetChangesResponse,
@@ -86,6 +87,7 @@ typedef struct {
/* For Card[Added|Removed|Modified]Event */
char *id;
+ char *vcard;
} EBookListenerResponse;
EBookListener *e_book_listener_new (void);
diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c
index 0046ad1730..1d5baf33a3 100644
--- a/addressbook/backend/ebook/e-book.c
+++ b/addressbook/backend/ebook/e-book.c
@@ -203,6 +203,44 @@ e_book_do_response_generic (EBook *book,
}
static void
+e_book_do_response_get_vcard (EBook *book,
+ EBookListenerResponse *resp)
+{
+ EBookOp *op;
+ ECard *card;
+
+ op = e_book_pop_op (book);
+
+ if (op == NULL) {
+ g_warning ("e_book_do_response_get_vcard: Cannot find operation "
+ "in local op queue!\n");
+ return;
+ }
+ if (resp->vcard != NULL) {
+
+ card = e_card_new(resp->vcard);
+
+ if (card != NULL) {
+ if (op->cb) {
+ if (op->active)
+ ((EBookCardCallback) op->cb) (book, resp->status, card, op->closure);
+ else
+ ((EBookCardCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure);
+ }
+
+ gtk_object_unref(GTK_OBJECT(card));
+ } else {
+ ((EBookCursorCallback) op->cb) (book, resp->status, NULL, op->closure);
+ }
+ } else {
+ ((EBookCardCallback) op->cb) (book, resp->status, NULL, op->closure);
+ }
+
+ g_free (resp->vcard);
+ e_book_op_free (op);
+}
+
+static void
e_book_do_response_get_cursor (EBook *book,
EBookListenerResponse *resp)
{
@@ -451,6 +489,9 @@ e_book_check_listener_queue (EBookListener *listener, EBook *book)
case AuthenticationResponse:
e_book_do_response_generic (book, resp);
break;
+ case GetCardResponse:
+ e_book_do_response_get_vcard (book, resp);
+ break;
case GetCursorResponse:
e_book_do_response_get_cursor (book, resp);
break;
@@ -744,80 +785,40 @@ e_book_authenticate_user (EBook *book,
/**
* e_book_get_card:
*/
-ECard *
-e_book_get_card (EBook *book,
- const char *id)
+guint
+e_book_get_card (EBook *book,
+ const char *id,
+ EBookCardCallback cb,
+ gpointer closure)
{
- char *vcard;
- ECard *card;
+ CORBA_Environment ev;
+ guint tag;
- g_return_val_if_fail (book != NULL, NULL);
- g_return_val_if_fail (E_IS_BOOK (book), NULL);
+ g_return_val_if_fail (book != NULL, 0);
+ g_return_val_if_fail (E_IS_BOOK (book), 0);
if (book->priv->load_state != URILoaded) {
g_warning ("e_book_get_card: No URI loaded!\n");
- return NULL;
- }
-
- vcard = e_book_get_vcard (book, id);
-
- if (vcard == NULL) {
- g_warning ("e_book_get_card: Got bogus VCard from PAS!\n");
- return NULL;
- }
-
- card = e_card_new (vcard);
- g_free(vcard);
-
- e_card_set_id(card, id);
- card->book = book;
- gtk_object_ref (GTK_OBJECT (card->book));
-
- return card;
-}
-
-/**
- * e_book_get_vcard:
- */
-char *
-e_book_get_vcard (EBook *book,
- const char *id)
-{
- CORBA_Environment ev;
- char *retval;
- char *vcard;
-
- g_return_val_if_fail (book != NULL, NULL);
- g_return_val_if_fail (E_IS_BOOK (book), NULL);
-
- if (book->priv->load_state != URILoaded) {
- g_warning ("e_book_get_vcard: No URI loaded!\n");
- return NULL;
+ return 0;
}
CORBA_exception_init (&ev);
- vcard = GNOME_Evolution_Addressbook_Book_getVCard (book->priv->corba_book,
- (GNOME_Evolution_Addressbook_CardId) id,
- &ev);
+ tag = e_book_queue_op (book, cb, closure, NULL);
+
+ GNOME_Evolution_Addressbook_Book_getVCard (book->priv->corba_book, (const GNOME_Evolution_Addressbook_VCard) id, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- g_warning ("e_book_get_vcard: Exception getting VCard from PAS!\n");
+ g_warning ("e_book_get_card: Exception "
+ "getting card!\n");
CORBA_exception_free (&ev);
- return NULL;
+ e_book_unqueue_op (book);
+ return 0;
}
CORBA_exception_free (&ev);
- if (vcard == NULL || strlen (vcard) == 0) {
- g_warning ("e_book_get_vcard: Got NULL VCard from PAS!\n");
- return NULL;
- }
-
- retval = g_strdup (vcard);
- CORBA_free (vcard);
-
- return retval;
+ return tag;
}
/* Deleting cards. */
diff --git a/addressbook/backend/ebook/e-book.h b/addressbook/backend/ebook/e-book.h
index 1c9386cfa7..cf90c8c57d 100644
--- a/addressbook/backend/ebook/e-book.h
+++ b/addressbook/backend/ebook/e-book.h
@@ -46,10 +46,11 @@ 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);
+typedef void (*EBookIdCallback) (EBook *book, EBookStatus status, const char *id, gpointer closure);
+typedef void (*EBookCardCallback) (EBook *book, EBookStatus status, ECard *card, gpointer closure);
+typedef void (*EBookCursorCallback) (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer closure);
typedef void (*EBookBookViewCallback) (EBook *book, EBookStatus status, EBookView *book_view, gpointer closure);
-typedef void (*EBookFieldsCallback) (EBook *book, EBookStatus status, EList *fields, gpointer closure);
+typedef void (*EBookFieldsCallback) (EBook *book, EBookStatus status, EList *fields, gpointer closure);
/* Creating a new addressbook. */
EBook *e_book_new (void);
@@ -77,10 +78,10 @@ void e_book_authenticate_user (EBook *book,
gpointer closure);
/* Fetching cards. */
-ECard *e_book_get_card (EBook *book,
- const char *id);
-char *e_book_get_vcard (EBook *book,
- const char *id);
+guint e_book_get_card (EBook *book,
+ const char *id,
+ EBookCardCallback cb,
+ gpointer closure);
/* Deleting cards. */
gboolean e_book_remove_card (EBook *book,
diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c
index 4b85c33868..5c1efb42f5 100644
--- a/addressbook/backend/ebook/e-card.c
+++ b/addressbook/backend/ebook/e-card.c
@@ -4171,13 +4171,9 @@ struct _CardLoadData {
};
static void
-card_load_cb (EBook *book, EBookStatus status, gpointer closure)
+card_get_cb (EBook *book, EBookStatus status, ECard *card, gpointer closure)
{
CardLoadData *data = (CardLoadData *) closure;
- ECard *card = NULL;
-
- if (status == E_BOOK_STATUS_SUCCESS)
- card = e_book_get_card (book, data->card_id);
if (data->cb != NULL)
data->cb (card, data->closure);
@@ -4186,6 +4182,15 @@ card_load_cb (EBook *book, EBookStatus status, gpointer closure)
g_free (data);
}
+static void
+card_load_cb (EBook *book, EBookStatus status, gpointer closure)
+{
+ CardLoadData *data = (CardLoadData *) closure;
+
+ if (status == E_BOOK_STATUS_SUCCESS)
+ e_book_get_card (book, data->card_id, card_get_cb, closure);
+}
+
void
e_card_load_uri (const gchar *uri, ECardCallback cb, gpointer closure)
{
diff --git a/addressbook/backend/ebook/test-client.c b/addressbook/backend/ebook/test-client.c
index 6ffa099ab3..cc7572c24c 100644
--- a/addressbook/backend/ebook/test-client.c
+++ b/addressbook/backend/ebook/test-client.c
@@ -66,10 +66,23 @@ get_cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer cl
}
static void
-add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure)
+get_card_cb (EBook *book, EBookStatus status, ECard *card, gpointer closure)
{
char *vcard;
- ECard *card;
+
+ vcard = e_card_get_vcard(card);
+ printf ("Card added: [%s]\n", vcard);
+ g_free(vcard);
+ gtk_object_unref(GTK_OBJECT(card));
+
+ printf ("Getting cards..\n");
+ e_book_get_cursor(book, "", get_cursor_cb, NULL);
+ printf ("Done getting all cards.\n");
+}
+
+static void
+add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure)
+{
GTimer *timer;
printf ("Status: %d\n", status);
@@ -78,18 +91,9 @@ add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure)
timer = g_timer_new ();
g_timer_start (timer);
- card = e_book_get_card (book, id);
+ e_book_get_card (book, id, get_card_cb, closure);
g_timer_stop (timer);
-
- vcard = e_card_get_vcard(card);
printf ("%g\n", g_timer_elapsed (timer, NULL));
- printf ("Card added: [%s]\n", vcard);
- g_free(vcard);
- gtk_object_unref(GTK_OBJECT(card));
-
- printf ("Getting cards..\n");
- e_book_get_cursor(book, "", get_cursor_cb, NULL);
- printf ("Done getting all cards.\n");
}
static void