remove the prototype for e_book_unload_uri. If you want to unload the uri,
authorChris Toshok <toshok@ximian.com>
Tue, 27 Jan 2004 22:04:15 +0000 (22:04 +0000)
committerChris Toshok <toshok@src.gnome.org>
Tue, 27 Jan 2004 22:04:15 +0000 (22:04 +0000)
2004-01-27  Chris Toshok  <toshok@ximian.com>

* libebook/e-book.h: remove the prototype for e_book_unload_uri.
If you want to unload the uri, unref the book and create a new
one.

* libebook/e-book.c (e_book_cancel): add some preconditions.
(e_book_load_local_addressbook): same.
(e_book_get_source): same.
(e_book_get_static_capabilities): same.  also, set the GError
instead of generating a g_warning.  This should probably return
NULL in the error cases instead of g_strdup(""), but i'm not sure
if that'll break things.
(e_book_check_static_capability): add some preconditions.
(e_book_is_writable): same.
(e_book_set_self): same.
(e_book_is_self): same.
(e_book_set_default_addressbook): same.
(e_book_set_default_source): same.
(e_book_get_addressbooks): same.
(e_book_unload_uri): make this static.

* libebook/e-book-types.h (EBookStatus): add
E_BOOK_ERROR_NO_SUCH_SOURCE.

addressbook/ChangeLog
addressbook/libebook/e-book-types.h
addressbook/libebook/e-book.c
addressbook/libebook/e-book.h
addressbook/tests/ebook/test-untyped-phones.c

index 3c15219..9627029 100644 (file)
@@ -1,5 +1,30 @@
 2004-01-27  Chris Toshok  <toshok@ximian.com>
 
+       * libebook/e-book.h: remove the prototype for e_book_unload_uri.
+       If you want to unload the uri, unref the book and create a new
+       one.
+
+       * libebook/e-book.c (e_book_cancel): add some preconditions.
+       (e_book_load_local_addressbook): same.
+       (e_book_get_source): same.
+       (e_book_get_static_capabilities): same.  also, set the GError
+       instead of generating a g_warning.  This should probably return
+       NULL in the error cases instead of g_strdup(""), but i'm not sure
+       if that'll break things.
+       (e_book_check_static_capability): add some preconditions.
+       (e_book_is_writable): same.
+       (e_book_set_self): same.
+       (e_book_is_self): same.
+       (e_book_set_default_addressbook): same.
+       (e_book_set_default_source): same.
+       (e_book_get_addressbooks): same.
+       (e_book_unload_uri): make this static.
+       
+       * libebook/e-book-types.h (EBookStatus): add
+       E_BOOK_ERROR_NO_SUCH_SOURCE.
+
+2004-01-27  Chris Toshok  <toshok@ximian.com>
+
        * libebook/e-book.c (e_book_load_local_addressbook): change the
        local addressbook path to .evolution/addressbook/local/system, and
        pass FALSE for @only_if_exists, so it'll always be created if it's
index b7e76f6..d23820d 100644 (file)
@@ -40,6 +40,7 @@ typedef enum {
        E_BOOK_ERROR_AUTHENTICATION_REQUIRED,
        E_BOOK_ERROR_TLS_NOT_AVAILABLE,
        E_BOOK_ERROR_CORBA_EXCEPTION,
+       E_BOOK_ERROR_NO_SUCH_SOURCE,
        E_BOOK_ERROR_OTHER_ERROR
 } EBookStatus;
 
index 87fe8bf..15c2d3b 100644 (file)
@@ -1340,6 +1340,8 @@ e_book_cancel (EBook   *book,
        gboolean rv;
        CORBA_Environment ev;
 
+       e_return_error_if_fail (book && E_IS_BOOK (book),       E_BOOK_ERROR_INVALID_ARG);
+
        g_mutex_lock (book->priv->mutex);
 
        if (book->priv->current_op == NULL) {
@@ -1601,7 +1603,7 @@ e_book_handle_response (EBookListener *listener, EBookListenerResponse *resp, EB
  *
  * Return value: #TRUE on success, #FALSE otherwise.
  */
-gboolean
+static gboolean
 e_book_unload_uri (EBook   *book,
                   GError **error)
 {
@@ -1943,6 +1945,8 @@ e_book_load_local_addressbook (EBook   *book,
        char *uri;
        gboolean rv;
 
+       e_return_error_if_fail (book && E_IS_BOOK (book),       E_BOOK_ERROR_INVALID_ARG);
+
        filename = g_build_filename (g_get_home_dir(),
                                     ".evolution/addressbook/local/system",
                                     NULL);
@@ -1968,6 +1972,8 @@ e_book_load_local_addressbook (EBook   *book,
 const char *
 e_book_get_uri (EBook *book)
 {
+       g_return_val_if_fail (book && E_IS_BOOK (book), NULL);
+
        return book->priv->uri;
 }
 
@@ -1982,6 +1988,8 @@ e_book_get_uri (EBook *book)
 ESource *
 e_book_get_source (EBook *book)
 {
+       g_return_val_if_fail (book && E_IS_BOOK (book), NULL);
+
        return book->priv->source;
 }
 
@@ -1999,6 +2007,8 @@ const char *
 e_book_get_static_capabilities (EBook   *book,
                                GError **error)
 {
+       g_return_val_if_fail (book && E_IS_BOOK (book), NULL);
+
        if (!book->priv->cap_queried) {
                CORBA_Environment ev;
                char *temp;
@@ -2006,17 +2016,20 @@ e_book_get_static_capabilities (EBook   *book,
                CORBA_exception_init (&ev);
 
                if (book->priv->load_state != E_BOOK_URI_LOADED) {
-                       g_warning ("e_book_unload_uri: No URI is loaded!\n");
-                       return g_strdup("");
+                       g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_URI_NOT_LOADED,
+                                    _("\"%s\" on book before \"%s\""),
+                                    "e_book_get_static_capabilities", "e_book_load_uri");
+                       return g_strdup ("");
                }
 
                temp = GNOME_Evolution_Addressbook_Book_getStaticCapabilities(book->priv->corba_book, &ev);
 
                if (ev._major != CORBA_NO_EXCEPTION) {
-                       g_warning ("e_book_get_static_capabilities: Exception "
-                                  "during get_static_capabilities!\n");
+                       g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION,
+                                    _("CORBA exception making \"%s\" call"),
+                                    "Book::getStaticCapabilities");
                        CORBA_exception_free (&ev);
-                       return g_strdup("");
+                       return g_strdup ("");
                }
 
                book->priv->cap = g_strdup(temp);
@@ -2044,7 +2057,11 @@ gboolean
 e_book_check_static_capability (EBook *book,
                                const char  *cap)
 {
-       const char *caps = e_book_get_static_capabilities (book, NULL);
+       const char *caps;
+
+       g_return_val_if_fail (book && E_IS_BOOK (book), FALSE);
+
+       caps = e_book_get_static_capabilities (book, NULL);
 
        /* XXX this is an inexact test but it works for our use */
        if (caps && strstr (caps, cap))
@@ -2064,6 +2081,8 @@ e_book_check_static_capability (EBook *book,
 gboolean
 e_book_is_writable (EBook *book)
 {
+       g_return_val_if_fail (book && E_IS_BOOK (book), FALSE);
+
        return book->priv->writable;
 }
 
@@ -2110,11 +2129,15 @@ e_book_get_self (EContact **contact, EBook **book, GError **error)
 gboolean
 e_book_set_self (EBook *book, EContact *contact, GError **error)
 {
-       GConfClient *gconf = gconf_client_get_default();
+       GConfClient *gconf;
 
-       gconf_client_set_string (gconf, SELF_UID_KEY, e_contact_get_const (contact, E_CONTACT_UID), NULL);
+       e_return_error_if_fail (book && E_IS_BOOK (book),          E_BOOK_ERROR_INVALID_ARG);
+       e_return_error_if_fail (contact && E_IS_CONTACT (contact), E_BOOK_ERROR_INVALID_ARG);
 
+       gconf = gconf_client_get_default();
+       gconf_client_set_string (gconf, SELF_UID_KEY, e_contact_get_const (contact, E_CONTACT_UID), NULL);
        g_object_unref (gconf);
+
        return TRUE;
 }
 
@@ -2125,6 +2148,10 @@ e_book_is_self (EContact *contact)
        char *uid;
        gboolean rv;
 
+       /* XXX this should probably be e_return_error_if_fail, but we
+          need a GError** arg for that */
+       g_return_val_if_fail (contact && E_IS_CONTACT (contact), FALSE);
+
        gconf = gconf_client_get_default();
        uid = gconf_client_get_string (gconf, SELF_UID_KEY, NULL);
        g_object_unref (gconf);
@@ -2157,6 +2184,8 @@ e_book_get_default_addressbook (EBook **book, GError **error)
        ESource *default_source = NULL;
        gboolean rv = TRUE;
 
+       e_return_error_if_fail (*book, E_BOOK_ERROR_INVALID_ARG);
+
        if (!e_book_get_addressbooks (&sources, &err)) {
                g_propagate_error (error, err);
                return FALSE;
@@ -2215,13 +2244,14 @@ e_book_get_default_addressbook (EBook **book, GError **error)
  * Return value: #TRUE if the setting was stored in libebook's ESourceList, otherwise #FALSE.
  */
 gboolean
-e_book_set_default_addressbook (EBook  *book, GError **error)
+e_book_set_default_addressbook (EBook *book, GError **error)
 {
-       ESource *source = e_book_get_source (book);
-       if (!source) {
-               /* XXX gerror */
-               return FALSE;
-       }
+       ESource *source;
+
+       e_return_error_if_fail (book && E_IS_BOOK (book),                        E_BOOK_ERROR_INVALID_ARG);
+       e_return_error_if_fail (book->priv->load_state == E_BOOK_URI_NOT_LOADED, E_BOOK_ERROR_URI_ALREADY_LOADED);
+
+       source = e_book_get_source (book);
 
        return e_book_set_default_source (source, error);
 }
@@ -2245,6 +2275,8 @@ e_book_set_default_source (ESource *source, GError **error)
        GError *err = NULL;
        GSList *g;
 
+       e_return_error_if_fail (source && E_IS_SOURCE (source), E_BOOK_ERROR_INVALID_ARG);
+
        uid = e_source_peek_uid (source);
 
        if (!e_book_get_addressbooks (&sources, &err)) {
@@ -2256,7 +2288,8 @@ e_book_set_default_source (ESource *source, GError **error)
           it's not we don't bother adding it, just return an error */
        source = e_source_list_peek_source_by_uid (sources, uid);
        if (!source) {
-               /* XXX gerror */
+               g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_NO_SUCH_SOURCE,
+                            _("e_book_set_default_source: there was no source for uid `%s' stored in gconf."), uid);
                g_object_unref (sources);
                return FALSE;
        }
@@ -2295,8 +2328,11 @@ e_book_set_default_source (ESource *source, GError **error)
 gboolean
 e_book_get_addressbooks (ESourceList **addressbook_sources, GError **error)
 {
-       GConfClient *gconf = gconf_client_get_default();
+       GConfClient *gconf;
 
+       e_return_error_if_fail (*addressbook_sources, E_BOOK_ERROR_INVALID_ARG);
+
+       gconf = gconf_client_get_default();
        *addressbook_sources = e_source_list_new_for_gconf (gconf, "/apps/evolution/addressbook/sources");
        g_object_unref (gconf);
 
index a1bdf75..066288d 100644 (file)
@@ -72,9 +72,6 @@ gboolean e_book_load_uri                   (EBook       *book,
                                            gboolean     only_if_exists,
                                            GError     **error);
 
-gboolean e_book_unload_uri                 (EBook       *book,
-                                           GError     **error);
-
 gboolean e_book_remove                     (EBook       *book,
                                            GError     **error);
 
index 56f385f..adc5747 100644 (file)
@@ -13,6 +13,7 @@ VERSION:3.0\r\n\
 X-EVOLUTION-FILE-AS:test\\, 40013\r\n\
 FN:40013 test\r\n\
 N:40013;test;;;\r\n\
+TEL;VOICE:456-456-4567\r\n\
 TEL;WORK:123-123-1234\r\n\
 TEL;FAX:321-321-4321\r\n\
 END:vCard"
@@ -20,7 +21,7 @@ END:vCard"
 static void
 check(gboolean test, char *msg)
 {
-  printf ("%s - %s\n", test ? "passed" : "failed", msg);
+       printf ("%s - %s\n", test ? "passed" : "failed", msg);
 }
 
 int
@@ -37,9 +38,11 @@ main (int argc, char **argv)
        contact = e_contact_new_from_vcard (VCARD);
 
        phone = e_contact_get_const (contact, E_CONTACT_PHONE_BUSINESS);
+       if (phone) printf ("business phone: %s\n", phone);
        check (phone && !strcmp ("123-123-1234", phone), "business phone");
 
        phone = e_contact_get_const (contact, E_CONTACT_PHONE_OTHER_FAX);
+       if (phone) printf ("other fax: %s\n", phone);
        check (phone && !strcmp ("321-321-4321", phone), "other fax");
        
        return 0;