diff options
| author | Chris Toshok <toshok@ximian.com> | 2004-01-26 17:51:47 +0000 |
|---|---|---|
| committer | Chris Toshok <toshok@src.gnome.org> | 2004-01-26 17:51:47 +0000 |
| commit | 8478effd9affe4a40b909625297017d6a2ffabf1 (patch) | |
| tree | 3aa899d27f9112e59da6f9ce8c4ebff23993f926 | |
| parent | 61be22b1b56f75b2080b4ec5aa566d7cd7c7b46e (diff) | |
| download | evolution-data-server-8478effd9affe4a40b909625297017d6a2ffabf1.tar.gz | |
implement this the right way by searching for the "default" property over
2004-01-26 Chris Toshok <toshok@ximian.com>
* libebook/e-book.c (e_book_get_default_addressbook): implement
this the right way by searching for the "default" property over
all sources, and returning that source, or the local addressbook
if there isn't a default source.
(e_book_set_default_addressbook): new function.
(e_book_set_default_source): new function.
* libebook/e-book.h: add prototypes for
e_book_set_default_addressbook/e_book_set_default_source.
| -rw-r--r-- | addressbook/ChangeLog | 12 | ||||
| -rw-r--r-- | addressbook/libebook/e-book.c | 133 | ||||
| -rw-r--r-- | addressbook/libebook/e-book.h | 2 |
3 files changed, 133 insertions, 14 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 397181a6a..9393c6996 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,15 @@ +2004-01-26 Chris Toshok <toshok@ximian.com> + + * libebook/e-book.c (e_book_get_default_addressbook): implement + this the right way by searching for the "default" property over + all sources, and returning that source, or the local addressbook + if there isn't a default source. + (e_book_set_default_addressbook): new function. + (e_book_set_default_source): new function. + + * libebook/e-book.h: add prototypes for + e_book_set_default_addressbook/e_book_set_default_source. + 2004-01-23 Chris Toshok <toshok@ximian.com> * libebook/e-vcard.c (e_vcard_unescape_string): make public. diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c index 7181b6442..d22c4d4d7 100644 --- a/addressbook/libebook/e-book.c +++ b/addressbook/libebook/e-book.c @@ -2137,33 +2137,138 @@ e_book_is_self (EContact *contact) gboolean e_book_get_default_addressbook (EBook **book, GError **error) { - /* XXX for now just load the local ~/evolution/local/Contacts, - this should really use properties on the ESource's that - represent the addressbooks we have available. */ - char *path, *uri; - gboolean rv; + ESourceList *sources; + GSList *g; + GError *err = NULL; + ESource *default_source = NULL; + gboolean rv = TRUE; + + if (!e_book_get_addressbooks (&sources, &err)) { + g_propagate_error (error, err); + return FALSE; + } - *book = e_book_new (); + for (g = e_source_list_peek_groups (sources); g; g = g->next) { + ESourceGroup *group = E_SOURCE_GROUP (g->data); + GSList *s; + for (s = e_source_group_peek_sources (group); s; s = s->next) { + ESource *source = E_SOURCE (s->data); + + if (e_source_get_property (source, "default")) { + default_source = source; + break; + } + } - path = g_build_filename (g_get_home_dir (), - ".evolution/addressbook/local/OnThisComputer/Personal", - NULL); - uri = g_strdup_printf ("file://%s", path); - g_free (path); + if (default_source) + break; + } - rv = e_book_load_uri (*book, uri, FALSE, error); + *book = e_book_new (); - g_free (uri); + if (default_source) { + if (!e_book_load_source (*book, default_source, TRUE, &err)) { + g_propagate_error (error, err); + rv = FALSE; + goto done; + } + } + else { + if (!e_book_load_local_addressbook (*book, &err)) { + g_propagate_error (error, err); + rv = FALSE; + goto done; + } + } + done: if (!rv) { g_object_unref (*book); *book = NULL; } - + g_object_unref (sources); return rv; } /** + * e_book_set_default_addressbook: + * @book: An #EBook pointer + * @error: A #GError pointer + * + * sets the #ESource of the #EBook as the "default" addressbook. This is the source + * that will be loaded in the e_book_get_default_addressbook call. + * + * Return value: #TRUE if the setting was stored in libebook's ESourceList, otherwise #FALSE. + */ +gboolean +e_book_set_default_addressbook (EBook *book, GError **error) +{ + ESource *source = e_book_get_source (book); + if (!source) { + /* XXX gerror */ + return FALSE; + } + + return e_book_set_default_source (source, error); +} + + +/** + * e_book_set_default_addressbook: + * @source: An #ESource pointer + * @error: A #GError pointer + * + * sets @source as the "default" addressbook. This is the source that + * will be loaded in the e_book_get_default_addressbook call. + * + * Return value: #TRUE if the setting was stored in libebook's ESourceList, otherwise #FALSE. + */ +gboolean +e_book_set_default_source (ESource *source, GError **error) +{ + ESourceList *sources; + const char *uid; + GError *err = NULL; + GSList *g; + + uid = e_source_peek_uid (source); + + if (!e_book_get_addressbooks (&sources, &err)) { + g_propagate_error (error, err); + return FALSE; + } + + /* make sure the source is actually in the ESourceList. if + 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_object_unref (sources); + return FALSE; + } + + /* loop over all the sources clearing out any "default" + properties we find */ + for (g = e_source_list_peek_groups (sources); g; g = g->next) { + GSList *s; + for (s = e_source_group_peek_sources (E_SOURCE_GROUP (g->data)); + s; s = s->next) { + e_source_set_property (E_SOURCE (s->data), "default", NULL); + } + } + + /* set the "default" property on the source */ + e_source_set_property (source, "default", "true"); + + if (!e_source_list_sync (sources, &err)) { + g_propagate_error (error, err); + return FALSE; + } + + return TRUE; +} + +/** * e_book_get_addressbooks: * @addressbook_sources: A pointer to a ESourceList* to set * @error: A pointer to a GError* to set on error diff --git a/addressbook/libebook/e-book.h b/addressbook/libebook/e-book.h index 015976256..a1bdf758d 100644 --- a/addressbook/libebook/e-book.h +++ b/addressbook/libebook/e-book.h @@ -163,6 +163,8 @@ gboolean e_book_is_self (EContact *contact); /* Addressbook Discovery */ gboolean e_book_get_default_addressbook (EBook **book, GError **error); +gboolean e_book_set_default_addressbook (EBook *book, GError **error); +gboolean e_book_set_default_source (ESource *source, GError **error); gboolean e_book_get_addressbooks (ESourceList** addressbook_sources, GError **error); GType e_book_get_type (void); |
