diff options
Diffstat (limited to 'addressbook/backend/pas')
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 107 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.c | 74 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.h | 13 |
3 files changed, 63 insertions, 131 deletions
diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index 56ce7dcd3d..f385f45ad7 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -600,13 +600,13 @@ pas_backend_file_search (PASBackendFile *bf, if (card_count >= card_threshold) { cards = g_list_reverse (cards); pas_book_view_notify_add (view->book_view, cards); - /* Clean up the handed-off data. */ + /* Clean up the handed-off data. */ g_list_foreach (cards, (GFunc)g_free, NULL); g_list_free (cards); cards = NULL; card_count = 0; - /* Yeah, this scheme is over-complicated. But I like it. */ + /* Yeah, this scheme is overly complicated. But I like it. */ if (card_threshold < card_threshold_max) { card_threshold = MIN (2*card_threshold, card_threshold_max); } @@ -1024,6 +1024,39 @@ pas_backend_file_build_all_cards_list(PASBackend *backend, } static void +pas_backend_file_process_get_vcard (PASBackend *backend, + PASBook *book, + PASRequest *req) +{ + PASBackendFile *bf; + DB *db; + DBT id_dbt, vcard_dbt; + int db_error = 0; + char *card; + GNOME_Evolution_Addressbook_BookListener_CallStatus status; + + bf = PAS_BACKEND_FILE (pas_book_get_backend (book)); + db = bf->priv->file_db; + + string_to_dbt (req->id, &id_dbt); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); + + db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); + + if (db_error == 0) { + card = vcard_dbt.data; + status = GNOME_Evolution_Addressbook_BookListener_Success; + } else { + card = NULL; + status = GNOME_Evolution_Addressbook_BookListener_CardNotFound; + } + + pas_book_respond_get_vcard (book, + status, + card); +} + +static void pas_backend_file_process_get_cursor (PASBackend *backend, PASBook *book, PASRequest *req) @@ -1242,37 +1275,6 @@ pas_backend_file_process_get_supported_fields (PASBackend *backend, fields); } -static gboolean -can_write (PASBackend *backend) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - char *path = pas_backend_file_extract_path_from_uri (bf->priv->uri); - gboolean retval; - - retval = (access (path, W_OK) != -1); - - g_free (path); - - return retval; -} - -static gboolean -pas_backend_file_can_write (PASBook *book) -{ - PASBackend* backend = pas_book_get_backend (book); - - return can_write(backend); -} - -static gboolean -pas_backend_file_can_write_card (PASBook *book, - const char *id) -{ - PASBackend* backend = pas_book_get_backend (book); - - return can_write(backend); -} - static void pas_backend_file_process_client_requests (PASBook *book) { @@ -1301,6 +1303,10 @@ pas_backend_file_process_client_requests (PASBook *book) case CheckConnection: pas_backend_file_process_check_connection (backend, book, req); break; + + case GetVCard: + pas_backend_file_process_get_vcard (backend, book, req); + break; case GetCursor: pas_backend_file_process_get_cursor (backend, book, req); @@ -1336,35 +1342,6 @@ pas_backend_file_book_destroy_cb (PASBook *book, gpointer data) pas_backend_remove_client (PAS_BACKEND (backend), book); } -static char * -pas_backend_file_get_vcard (PASBook *book, const char *id) -{ - PASBackendFile *bf; - DBT id_dbt, vcard_dbt; - DB *db; - int db_error; - - bf = PAS_BACKEND_FILE (pas_book_get_backend (book)); - db = bf->priv->file_db; - - string_to_dbt (id, &id_dbt); - memset (&vcard_dbt, 0, sizeof (vcard_dbt)); - - db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); - if (db_error == 0) { - /* success */ - return g_strdup (vcard_dbt.data); - } - else if (db_error == 1) { - /* key was not in file */ - return g_strdup (""); /* XXX */ - } - else /* if (db_error < 0)*/ { - /* error */ - return g_strdup (""); /* XXX */ - } -} - static gboolean pas_backend_file_upgrade_db (PASBackendFile *bf, char *old_version) { @@ -1565,11 +1542,7 @@ pas_backend_file_add_client (PASBackend *backend, bf = PAS_BACKEND_FILE (backend); - book = pas_book_new ( - backend, listener, - pas_backend_file_get_vcard, - pas_backend_file_can_write, - pas_backend_file_can_write_card); + book = pas_book_new (backend, listener); if (!book) { if (!bf->priv->clients) diff --git a/addressbook/backend/pas/pas-book.c b/addressbook/backend/pas/pas-book.c index ec8842135d..4461d63c44 100644 --- a/addressbook/backend/pas/pas-book.c +++ b/addressbook/backend/pas/pas-book.c @@ -23,9 +23,6 @@ static guint pas_book_signals [LAST_SIGNAL]; struct _PASBookPrivate { PASBackend *backend; GNOME_Evolution_Addressbook_BookListener listener; - PASBookGetVCardFn get_vcard; - PASBookCanWriteFn can_write; - PASBookCanWriteCardFn can_write_card; GList *request_queue; gint idle_id; @@ -107,6 +104,18 @@ pas_book_queue_get_cursor (PASBook *book, const char *search) } static void +pas_book_queue_get_vcard (PASBook *book, const char *id) +{ + PASRequest *req; + + req = g_new0 (PASRequest, 1); + req->op = GetVCard; + req->id = g_strdup(id); + + pas_book_queue_request (book, req); +} + +static void pas_book_queue_authenticate_user (PASBook *book, const char *user, const char *passwd) { @@ -191,45 +200,14 @@ pas_book_queue_check_connection (PASBook *book) pas_book_queue_request (book, req); } -static CORBA_char * +static void impl_GNOME_Evolution_Addressbook_Book_getVCard (PortableServer_Servant servant, const GNOME_Evolution_Addressbook_CardId id, CORBA_Environment *ev) { - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - char *vcard; - CORBA_char *retval; - - vcard = (book->priv->get_vcard) (book, (const char *) id); - retval = CORBA_string_dup (vcard); - g_free (vcard); - - return retval; -} - -static CORBA_boolean -impl_GNOME_Evolution_Addressbook_Book_isWriteable (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - CORBA_boolean retval; - - retval = (book->priv->can_write) (book); - - return retval; -} - -static CORBA_boolean -impl_GNOME_Evolution_Addressbook_Book_isCardWriteable (PortableServer_Servant servant, - const GNOME_Evolution_Addressbook_CardId id, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - CORBA_boolean retval; - - retval = (book->priv->can_write_card) (book, (const char *) id); + PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - return retval; + pas_book_queue_get_vcard (book, id); } static void @@ -681,10 +659,7 @@ pas_book_report_writable (PASBook *book, static gboolean pas_book_construct (PASBook *book, PASBackend *backend, - GNOME_Evolution_Addressbook_BookListener listener, - PASBookGetVCardFn get_vcard, - PASBookCanWriteFn can_write, - PASBookCanWriteCardFn can_write_card) + GNOME_Evolution_Addressbook_BookListener listener) { POA_GNOME_Evolution_Addressbook_Book *servant; CORBA_Environment ev; @@ -693,9 +668,6 @@ pas_book_construct (PASBook *book, g_assert (book != NULL); g_assert (PAS_IS_BOOK (book)); g_assert (listener != CORBA_OBJECT_NIL); - g_assert (get_vcard != NULL); - g_assert (can_write != NULL); - g_assert (can_write_card != NULL); servant = (POA_GNOME_Evolution_Addressbook_Book *) g_new0 (BonoboObjectServant, 1); servant->vepv = &pas_book_vepv; @@ -730,9 +702,6 @@ pas_book_construct (PASBook *book, CORBA_exception_free (&ev); book->priv->listener = listener; - book->priv->get_vcard = get_vcard; - book->priv->can_write = can_write; - book->priv->can_write_card = can_write_card; book->priv->backend = backend; return TRUE; @@ -743,20 +712,15 @@ pas_book_construct (PASBook *book, */ PASBook * pas_book_new (PASBackend *backend, - GNOME_Evolution_Addressbook_BookListener listener, - PASBookGetVCardFn get_vcard, - PASBookCanWriteFn can_write, - PASBookCanWriteCardFn can_write_card) + GNOME_Evolution_Addressbook_BookListener listener) { PASBook *book; g_return_val_if_fail (listener != CORBA_OBJECT_NIL, NULL); - g_return_val_if_fail (get_vcard != NULL, NULL); book = gtk_type_new (pas_book_get_type ()); - if (! pas_book_construct (book, backend, listener, - get_vcard, can_write, can_write_card)) { + if (! pas_book_construct (book, backend, listener)) { gtk_object_unref (GTK_OBJECT (book)); return NULL; @@ -802,8 +766,6 @@ pas_book_get_epv (void) epv = g_new0 (POA_GNOME_Evolution_Addressbook_Book__epv, 1); epv->getVCard = impl_GNOME_Evolution_Addressbook_Book_getVCard; - epv->isWriteable = impl_GNOME_Evolution_Addressbook_Book_isWriteable; - epv->isCardWriteable = impl_GNOME_Evolution_Addressbook_Book_isCardWriteable; epv->authenticateUser = impl_GNOME_Evolution_Addressbook_Book_authenticateUser; epv->addCard = impl_GNOME_Evolution_Addressbook_Book_addCard; epv->removeCard = impl_GNOME_Evolution_Addressbook_Book_removeCard; diff --git a/addressbook/backend/pas/pas-book.h b/addressbook/backend/pas/pas-book.h index 6cb6268553..6f5832d914 100644 --- a/addressbook/backend/pas/pas-book.h +++ b/addressbook/backend/pas/pas-book.h @@ -28,6 +28,7 @@ typedef enum { CreateCard, RemoveCard, ModifyCard, + GetVCard, GetCursor, GetBookView, GetChanges, @@ -60,15 +61,11 @@ typedef struct { void (*requests_queued) (void); } PASBookClass; -typedef char * (*PASBookGetVCardFn) (PASBook *book, const char *id); typedef gboolean (*PASBookCanWriteFn) (PASBook *book); typedef gboolean (*PASBookCanWriteCardFn) (PASBook *book, const char *id); PASBook *pas_book_new (PASBackend *backend, - GNOME_Evolution_Addressbook_BookListener listener, - PASBookGetVCardFn get_vcard, - PASBookCanWriteFn can_write, - PASBookCanWriteCardFn can_write_card); + GNOME_Evolution_Addressbook_BookListener listener); PASBackend *pas_book_get_backend (PASBook *book); GNOME_Evolution_Addressbook_BookListener pas_book_get_listener (PASBook *book); int pas_book_check_pending (PASBook *book); @@ -94,6 +91,9 @@ void pas_book_respond_get_cursor (PASBook void pas_book_respond_get_book_view (PASBook *book, GNOME_Evolution_Addressbook_BookListener_CallStatus status, PASBookView *book_view); +void pas_book_respond_get_vcard (PASBook *book, + GNOME_Evolution_Addressbook_BookListener_CallStatus status, + char *vcard); void pas_book_respond_get_changes (PASBook *book, GNOME_Evolution_Addressbook_BookListener_CallStatus status, PASBookView *book_view); @@ -103,9 +103,6 @@ void pas_book_report_connection (PASBook void pas_book_report_writable (PASBook *book, gboolean writable); -gboolean pas_book_can_write (PASBook *book); -gboolean pas_book_can_write_card (PASBook *book, - const char *id); GtkType pas_book_get_type (void); #define PAS_BOOK_TYPE (pas_book_get_type ()) |