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
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) {
*
* Return value: #TRUE on success, #FALSE otherwise.
*/
-gboolean
+static gboolean
e_book_unload_uri (EBook *book,
GError **error)
{
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);
const char *
e_book_get_uri (EBook *book)
{
+ g_return_val_if_fail (book && E_IS_BOOK (book), NULL);
+
return book->priv->uri;
}
ESource *
e_book_get_source (EBook *book)
{
+ g_return_val_if_fail (book && E_IS_BOOK (book), NULL);
+
return book->priv->source;
}
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;
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);
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))
gboolean
e_book_is_writable (EBook *book)
{
+ g_return_val_if_fail (book && E_IS_BOOK (book), FALSE);
+
return book->priv->writable;
}
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;
}
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);
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;
* 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);
}
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)) {
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;
}
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);