diff options
Diffstat (limited to 'addressbook/backend')
-rw-r--r-- | addressbook/backend/ebook/e-book-listener.c | 25 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book-listener.h | 4 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book.c | 21 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book.h | 5 | ||||
-rw-r--r-- | addressbook/backend/idl/addressbook.idl | 14 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 48 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-ldap.c | 3 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.c | 22 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.h | 3 |
9 files changed, 129 insertions, 16 deletions
diff --git a/addressbook/backend/ebook/e-book-listener.c b/addressbook/backend/ebook/e-book-listener.c index 0aaf5483a5..e1d47d70d2 100644 --- a/addressbook/backend/ebook/e-book-listener.c +++ b/addressbook/backend/ebook/e-book-listener.c @@ -188,6 +188,20 @@ e_book_listener_queue_link_status (EBookListener *listener, } static void +e_book_listener_queue_writable_status (EBookListener *listener, + gboolean writable) +{ + EBookListenerResponse *resp; + + resp = g_new0 (EBookListenerResponse, 1); + + resp->op = WritableStatusEvent; + resp->writable = writable; + + e_book_listener_queue_response (listener, resp); +} + +static void e_book_listener_queue_authentication_response (EBookListener *listener, EBookStatus status) { @@ -394,6 +408,16 @@ impl_BookListener_report_connection_status (PortableServer_Servant servant, listener, connected); } +static void +impl_BookListener_report_writable (PortableServer_Servant servant, + const CORBA_boolean writable, + CORBA_Environment *ev) +{ + EBookListener *listener = E_BOOK_LISTENER (bonobo_object_from_servant (servant)); + + e_book_listener_queue_writable_status (listener, writable); +} + /** * e_book_listener_check_pending: * @listener: the #EBookListener @@ -627,6 +651,7 @@ e_book_listener_get_epv (void) epv->notifyChangesRequested = impl_BookListener_respond_get_changes; 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 0390f7fcb2..84cdfecced 100644 --- a/addressbook/backend/ebook/e-book-listener.h +++ b/addressbook/backend/ebook/e-book-listener.h @@ -52,6 +52,7 @@ typedef enum { /* Async events */ LinkStatusEvent, + WritableStatusEvent, OpenProgressEvent, } EBookListenerOperation; @@ -80,6 +81,9 @@ typedef struct { /* For LinkStatusEvent */ gboolean connected; + /* For WritableStatusEvent */ + gboolean writable; + /* For Card[Added|Removed|Modified]Event */ char *id; } EBookListenerResponse; diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c index 2a02b78fbf..25fb42a37b 100644 --- a/addressbook/backend/ebook/e-book.c +++ b/addressbook/backend/ebook/e-book.c @@ -50,6 +50,7 @@ struct _EBookPrivate { enum { OPEN_PROGRESS, + WRITABLE_STATUS, LINK_STATUS, LAST_SIGNAL }; @@ -336,6 +337,14 @@ e_book_do_link_event (EBook *book, } static void +e_book_do_writable_event (EBook *book, + EBookListenerResponse *resp) +{ + gtk_signal_emit (GTK_OBJECT (book), e_book_signals [WRITABLE_STATUS], + resp->writable); +} + +static void e_book_do_response_get_supported_fields (EBook *book, EBookListenerResponse *resp) { @@ -398,6 +407,9 @@ e_book_check_listener_queue (EBookListener *listener, EBook *book) case LinkStatusEvent: e_book_do_link_event (book, resp); break; + case WritableStatusEvent: + e_book_do_writable_event (book, resp); + break; default: g_error ("EBook: Unknown operation %d in listener queue!\n", resp->op); @@ -1184,6 +1196,15 @@ e_book_class_init (EBookClass *klass) GTK_TYPE_NONE, 1, GTK_TYPE_BOOL); + e_book_signals [WRITABLE_STATUS] = + gtk_signal_new ("writable_status", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EBookClass, writable_status), + gtk_marshal_NONE__BOOL, + GTK_TYPE_NONE, 1, + GTK_TYPE_BOOL); + gtk_object_class_add_signals (object_class, e_book_signals, LAST_SIGNAL); diff --git a/addressbook/backend/ebook/e-book.h b/addressbook/backend/ebook/e-book.h index 0713bc6bdb..9e25c9d9a5 100644 --- a/addressbook/backend/ebook/e-book.h +++ b/addressbook/backend/ebook/e-book.h @@ -35,8 +35,9 @@ struct _EBookClass { /* * Signals. */ - void (* open_progress) (EBook *book, const char *msg, short percent); - void (* link_status) (EBook *book, gboolean connected); + void (* open_progress) (EBook *book, const char *msg, short percent); + void (* link_status) (EBook *book, gboolean connected); + void (* writable_status) (EBook *book, gboolean writable); }; /* Callbacks for asynchronous functions. */ diff --git a/addressbook/backend/idl/addressbook.idl b/addressbook/backend/idl/addressbook.idl index 6d8da64163..877813e5d3 100644 --- a/addressbook/backend/idl/addressbook.idl +++ b/addressbook/backend/idl/addressbook.idl @@ -142,6 +142,20 @@ module Addressbook { * being asked. */ void notifyConnectionStatus (in boolean connected); + + /** + * notifyWritable: + * + * Used to report whether or not a backend can write + * to a given addressbook. All books default to + * read-only, so unless you receive a notification + * saying otherwise, treat the book as read-only. It + * is presumed that this notification will be sent + * early (just after a connection is opened, usually), + * but it may also be sent later, if/when the backend + * notices a change. + */ + void notifyWritable (in boolean writable); }; interface BookFactory : Bonobo::Unknown { diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index 74b8613d3d..a42a1fa499 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -1330,30 +1330,43 @@ pas_backend_file_load_uri (PASBackend *backend, { PASBackendFile *bf = PAS_BACKEND_FILE (backend); char *filename; + gboolean writable = FALSE; + GList *l; g_assert (bf->priv->loaded == FALSE); filename = pas_backend_file_extract_path_from_uri (uri); bf->priv->file_db = dbopen (filename, O_RDWR, 0666, DB_HASH, NULL); - if (bf->priv->file_db == NULL) { - bf->priv->file_db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); + if (bf->priv->file_db) { + writable = TRUE; + } + else { + /* try to open the file read-only */ + bf->priv->file_db = dbopen (filename, O_RDONLY, 0666, DB_HASH, NULL); - if (bf->priv->file_db) { - char *create_initial_file; - char *dir; + if (!bf->priv->file_db) { + /* lastly, try and create the file */ + bf->priv->file_db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); - dir = g_dirname(filename); - create_initial_file = g_concat_dir_and_file(dir, "create-initial"); + if (bf->priv->file_db) { + char *create_initial_file; + char *dir; - if (g_file_exists(create_initial_file)) { - char *id; - id = do_create(backend, INITIAL_VCARD, NULL); - g_free (id); - } + dir = g_dirname(filename); + create_initial_file = g_concat_dir_and_file(dir, "create-initial"); + + if (g_file_exists(create_initial_file)) { + char *id; + id = do_create(backend, INITIAL_VCARD, NULL); + g_free (id); + } - g_free(create_initial_file); - g_free(dir); + g_free(create_initial_file); + g_free(dir); + + writable = TRUE; + } } } @@ -1369,6 +1382,13 @@ pas_backend_file_load_uri (PASBackend *backend, } else return FALSE; + /* report the writable status of the book to all its clients */ + for (l = bf->priv->clients; l; l = g_list_next (l)) { + PASBook *book = l->data; + + pas_book_report_writable (book, writable); + } + return TRUE; } diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c index 0478c59ece..0fb5347ca3 100644 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ b/addressbook/backend/pas/pas-backend-ldap.c @@ -2036,6 +2036,9 @@ pas_backend_ldap_process_authenticate_user (PASBackend *backend, pas_book_respond_authenticate_user (book, ldap_error_to_response (ldap_error)); + if (ldap_error == LDAP_SUCCESS) + pas_book_report_writable (book, TRUE); + if (!bl->priv->evolutionPersonChecked) check_schema_support (bl); } diff --git a/addressbook/backend/pas/pas-book.c b/addressbook/backend/pas/pas-book.c index 6add0987fc..d115e9062f 100644 --- a/addressbook/backend/pas/pas-book.c +++ b/addressbook/backend/pas/pas-book.c @@ -656,6 +656,28 @@ pas_book_report_connection (PASBook *book, CORBA_exception_free (&ev); } +/** + * pas_book_report_writable: + */ +void +pas_book_report_writable (PASBook *book, + gboolean writable) +{ + CORBA_Environment ev; + + CORBA_exception_init (&ev); + + GNOME_Evolution_Addressbook_BookListener_notifyWritable ( + book->priv->listener, (CORBA_boolean) writable, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("pas_book_report_writable: Exception " + "responding to BookListener!\n"); + } + + CORBA_exception_free (&ev); +} + static gboolean pas_book_construct (PASBook *book, PASBackend *backend, diff --git a/addressbook/backend/pas/pas-book.h b/addressbook/backend/pas/pas-book.h index 1d401d33a4..12c780e282 100644 --- a/addressbook/backend/pas/pas-book.h +++ b/addressbook/backend/pas/pas-book.h @@ -100,6 +100,9 @@ void pas_book_respond_get_changes (PASBook void pas_book_report_connection (PASBook *book, gboolean connected); +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); |