+2003-11-26 Hans Petter Jansson <hpj@ximian.com>
+
+ * libedataserver/e-source.c (impl_finalize): Support absolute URI.
+ (e_source_update_from_xml_node): Ditto.
+ (e_source_get_uri): Ditto.
+ (dump_common_to_xml_node): Implement for parameters common to
+ dependent and standalone ESources.
+ (e_source_dump_to_xml_node): Use dump_common_to_xml_node ().
+ (e_source_to_standalone_xml): Implement.
+ (e_source_new_from_standalone_xml): Implement.
+
2003-11-26 Rodney Dawes <dobey@ximian.com>
* Makefile.am: remove \ on last line of LIBDB_FILES
+2003-11-26 Hans Petter Jansson <hpj@ximian.com>
+
+ * backends/file/e-book-backend-file.c (e_book_backend_file_load_uri):
+ Rename to e_book_backend_file_load_source () and take an ESource
+ instead of an URI.
+ (e_book_backend_file_dispose): Don't free URI anymore.
+ (e_book_backend_file_class_init): load_uri -> load_source.
+ (e_book_backend_file_init): Don't init URI anymore.
+
+ * backends/ldap/e-book-backend-ldap.c (e_book_backend_ldap_load_uri):
+ Rename to e_book_backend_ldap_load_uri () and take an ESource instead
+ of an URI.
+ (e_book_backend_ldap_dispose): Don't free URI anymore.
+ (e_book_backend_ldap_class_init): load_uri -> load_source.
+
+ * backends/vcf/e-book-backend-vcf.c (e_book_backend_vcf_load_uri):
+ Rename to e_book_backend_vcf_load_source () and take an ESource
+ instead of an URI.
+ (e_book_backend_vcf_dispose): Don't free URI anymore.
+ (e_book_backend_vcf_class_init): load_uri -> load_source.
+ (e_book_backend_vcf_init): Don't init URI anymore.
+
+ * idl/Evolution-DataServer-Addressbook.idl (getBook): In parameter
+ "uri" renamed to "source". Takes standalone source XML.
+
+ * libebook/e-book.c (fetch_corba_book): Implement, taking ESource.
+ (e_book_load_source): Implement.
+ (e_book_load_uri): Create a source based on the URI and use
+ e_book_load_source () to load that.
+
+ * libedata-book/e-book-backend.c (e_book_backend_load_uri): Renamed
+ to e_book_backend_load_source () and takes ESource instead of URI.
+ (e_book_backend_get_uri): Renamed to e_book_backend_get_source ()
+ and returns ESource instead of URI.
+ (e_book_backend_open): Use e_book_backend_load_source ().
+ (e_book_backend_init): Don't init URI anymore.
+ (e_book_backend_dispose): Don't free URI anymore.
+
+ * libedata-book/e-data-book-factory.c (backend_last_client_gone_cb):
+ Get URI from backend's ESource.
+ (impl_GNOME_Evolution_Addressbook_BookFactory_getBook): Take
+ standalone source XML, construct an ESource, and fetch a backend
+ with that.
+
+ * libedata-book/e-data-book.c (e_data_book_get_uri): Renamed to
+ e_data_book_get_source () and return ESource.
+ (e_data_book_construct): Take ESource instead of URI.
+ (e_data_book_new): Take ESource instead of URI.
+ (e_data_book_dispose): Don't free URI. Instead, unref ESource.
+
2003-11-25 Chris Toshok <toshok@ximian.com>
* tests/ebook/test-self.c: new file/test, print out the current
static EBookBackendSyncClass *e_book_backend_file_parent_class;
struct _EBookBackendFilePrivate {
- char *uri;
char *dirname;
char *filename;
char *summary_filename;
#include <libedata-book/ximian-vcard.h>
static GNOME_Evolution_Addressbook_CallStatus
-e_book_backend_file_load_uri (EBookBackend *backend,
- const char *uri,
- gboolean only_if_exists)
+e_book_backend_file_load_source (EBookBackend *backend,
+ ESource *source,
+ gboolean only_if_exists)
{
EBookBackendFile *bf = E_BOOK_BACKEND_FILE (backend);
char *dirname, *filename;
DB *db;
time_t db_mtime;
struct stat sb;
+ gchar *uri;
- g_free(bf->priv->uri);
- bf->priv->uri = g_strdup (uri);
+ uri = e_source_get_uri (source);
dirname = e_book_backend_file_extract_path_from_uri (uri);
filename = g_build_filename (dirname, "addressbook.db", NULL);
+ g_free (uri);
db_error = e_db3_utils_maybe_recover (filename);
if (db_error != 0)
if (bf->priv) {
if (bf->priv->summary)
g_object_unref(bf->priv->summary);
- g_free (bf->priv->uri);
g_free (bf->priv->filename);
g_free (bf->priv->dirname);
g_free (bf->priv->summary_filename);
backend_class = E_BOOK_BACKEND_CLASS (klass);
/* Set the virtual methods. */
- backend_class->load_uri = e_book_backend_file_load_uri;
+ backend_class->load_source = e_book_backend_file_load_source;
backend_class->get_static_capabilities = e_book_backend_file_get_static_capabilities;
backend_class->start_book_view = e_book_backend_file_start_book_view;
backend_class->stop_book_view = e_book_backend_file_stop_book_view;
EBookBackendFilePrivate *priv;
priv = g_new0 (EBookBackendFilePrivate, 1);
- priv->uri = NULL;
backend->priv = priv;
}
struct _EBookBackendLDAPPrivate {
- char *uri;
gboolean connected;
gchar *ldap_host; /* the hostname of the server */
}
static GNOME_Evolution_Addressbook_CallStatus
-e_book_backend_ldap_load_uri (EBookBackend *backend,
- const char *uri,
- gboolean only_if_exists)
+e_book_backend_ldap_load_source (EBookBackend *backend,
+ ESource *source,
+ gboolean only_if_exists)
{
EBookBackendLDAP *bl = E_BOOK_BACKEND_LDAP (backend);
LDAPURLDesc *lud;
int i;
int limit = 100;
int timeout = 60; /* 1 minute */
+ gchar *uri;
g_assert (bl->priv->connected == FALSE);
+ uri = e_source_get_uri (source);
+
attributes = g_strsplit (uri, ";", 0);
- if (attributes[0] == NULL)
+ if (attributes[0] == NULL) {
+ g_free (uri);
return FALSE;
+ }
for (i = 1; attributes[i]; i++) {
char *equals;
ldap_error = ldap_url_parse ((char*)attributes[0], &lud);
g_strfreev (attributes);
+ g_free (uri);
+
if (ldap_error == LDAP_SUCCESS) {
- g_free(bl->priv->uri);
- bl->priv->uri = g_strdup (uri);
bl->priv->ldap_host = g_strdup(lud->lud_host);
bl->priv->ldap_port = lud->lud_port;
/* if a port wasn't specified, default to LDAP_PORT */
g_list_free (bl->priv->supported_auth_methods);
}
- g_free (bl->priv->uri);
-
g_free (bl->priv);
bl->priv = NULL;
}
parent_class = E_BOOK_BACKEND_CLASS (klass);
/* Set the virtual methods. */
- parent_class->load_uri = e_book_backend_ldap_load_uri;
+ parent_class->load_source = e_book_backend_ldap_load_source;
parent_class->get_static_capabilities = e_book_backend_ldap_get_static_capabilities;
parent_class->create_contact = e_book_backend_ldap_create_contact;
typedef struct _EBookBackendVCFSearchContext EBookBackendVCFSearchContext;
struct _EBookBackendVCFPrivate {
- char *uri;
char *filename;
GMutex *mutex;
GHashTable *contacts;
#include <libedata-book/ximian-vcard.h>
static GNOME_Evolution_Addressbook_CallStatus
-e_book_backend_vcf_load_uri (EBookBackend *backend,
- const char *uri,
- gboolean only_if_exists)
+e_book_backend_vcf_load_source (EBookBackend *backend,
+ ESource *source,
+ gboolean only_if_exists)
{
EBookBackendVCF *bvcf = E_BOOK_BACKEND_VCF (backend);
char *dirname;
gboolean writable = FALSE;
+ gchar *uri;
int fd;
- g_free(bvcf->priv->uri);
- bvcf->priv->uri = g_strdup (uri);
+ uri = e_source_get_uri (source);
dirname = e_book_backend_vcf_extract_path_from_uri (uri);
bvcf->priv->filename = g_build_filename (dirname, "addressbook.vcf", NULL);
if (fd == -1) {
g_warning ("Failed to open addressbook at uri `%s'", uri);
g_warning ("error == %s", strerror(errno));
+ g_free (uri);
return GNOME_Evolution_Addressbook_OtherError;
}
e_book_backend_set_is_loaded (backend, TRUE);
e_book_backend_set_is_writable (backend, writable);
+ g_free (uri);
return GNOME_Evolution_Addressbook_Success;
}
g_hash_table_destroy (bvcf->priv->contacts);
- g_free (bvcf->priv->uri);
g_free (bvcf->priv->filename);
g_mutex_unlock (bvcf->priv->mutex);
backend_class = E_BOOK_BACKEND_CLASS (klass);
/* Set the virtual methods. */
- backend_class->load_uri = e_book_backend_vcf_load_uri;
+ backend_class->load_source = e_book_backend_vcf_load_source;
backend_class->get_static_capabilities = e_book_backend_vcf_get_static_capabilities;
backend_class->start_book_view = e_book_backend_vcf_start_book_view;
backend_class->stop_book_view = e_book_backend_vcf_stop_book_view;
EBookBackendVCFPrivate *priv;
priv = g_new0 (EBookBackendVCFPrivate, 1);
- priv->uri = NULL;
priv->mutex = g_mutex_new();
backend->priv = priv;
interface BookFactory : Bonobo::Unknown {
exception ProtocolNotSupported {};
- Book getBook (in string uri, in BookListener listener)
+ Book getBook (in string source, in BookListener listener)
raises (ProtocolNotSupported);
};
};
return factories;
}
-gboolean
-e_book_load_uri (EBook *book,
- const char *uri,
- gboolean only_if_exists,
- GError **error)
+static gboolean
+fetch_corba_book (EBook *book,
+ ESource *source,
+ gboolean only_if_exists,
+ GError **error)
{
+ GNOME_Evolution_Addressbook_Book corba_book = CORBA_OBJECT_NIL;
+ gchar *uri;
+ gchar *source_xml;
GList *factories;
GList *l;
gboolean rv = FALSE;
- GNOME_Evolution_Addressbook_Book corba_book = CORBA_OBJECT_NIL;
-
- e_return_error_if_fail (book && E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
- e_return_error_if_fail (uri, E_BOOK_ERROR_INVALID_ARG);
- /* XXX this needs to happen while holding the book's lock i would think... */
- e_return_error_if_fail (book->priv->load_state == E_BOOK_URI_NOT_LOADED, E_BOOK_ERROR_URI_ALREADY_LOADED);
+ uri = e_source_get_uri (source);
+ if (!uri) {
+ g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_OTHER_ERROR,
+ _("e_book_load_uri: Invalid source."));
+ return FALSE;
+ }
/* try to find a list of factories that can handle the protocol */
- if (! (factories = activate_factories_for_uri (book, uri))) {
+ factories = activate_factories_for_uri (book, uri);
+ if (!factories) {
g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_PROTOCOL_NOT_SUPPORTED,
_("e_book_load_uri: no factories available for uri `%s'"), uri);
return FALSE;
G_CALLBACK (e_book_handle_response), book);
g_free (book->priv->uri);
- book->priv->uri = g_strdup (uri);
+ book->priv->uri = uri;
+
+ source_xml = e_source_to_standalone_xml (source);
for (l = factories; l; l = l->next) {
GNOME_Evolution_Addressbook_BookFactory factory = l->data;
CORBA_exception_init (&ev);
- corba_book = GNOME_Evolution_Addressbook_BookFactory_getBook (factory, book->priv->uri,
+ corba_book = GNOME_Evolution_Addressbook_BookFactory_getBook (factory, source_xml,
bonobo_object_corba_objref (BONOBO_OBJECT (book->priv->listener)),
&ev);
}
}
+ g_free (source_xml);
+
/* free up the factories */
for (l = factories; l; l = l->next)
CORBA_Object_release ((CORBA_Object)l->data, NULL);
}
gboolean
+e_book_load_source (EBook *book,
+ ESource *source,
+ gboolean only_if_exists,
+ GError **error)
+{
+ e_return_error_if_fail (book && E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
+ e_return_error_if_fail (source && E_IS_SOURCE (source), E_BOOK_ERROR_INVALID_ARG);
+
+ /* XXX this needs to happen while holding the book's lock i would think... */
+ e_return_error_if_fail (book->priv->load_state == E_BOOK_URI_NOT_LOADED, E_BOOK_ERROR_URI_ALREADY_LOADED);
+
+ return fetch_corba_book (book, source, only_if_exists, error);
+}
+
+gboolean
+e_book_load_uri (EBook *book,
+ const char *uri,
+ gboolean only_if_exists,
+ GError **error)
+{
+ ESourceGroup *group;
+ ESource *source;
+ gboolean rv;
+
+ e_return_error_if_fail (book && E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
+ e_return_error_if_fail (uri, E_BOOK_ERROR_INVALID_ARG);
+
+ /* XXX this needs to happen while holding the book's lock i would think... */
+ e_return_error_if_fail (book->priv->load_state == E_BOOK_URI_NOT_LOADED, E_BOOK_ERROR_URI_ALREADY_LOADED);
+
+ group = e_source_group_new ("", uri);
+ source = e_source_new ("", "");
+ e_source_set_group (source, group);
+
+ rv = e_book_load_source (book, source, only_if_exists, error);
+
+ g_object_unref (source);
+ g_object_unref (group);
+
+ return rv;
+}
+
+gboolean
e_book_load_local_addressbook (EBook *book,
GError **error)
{
#include <glib.h>
#include <glib-object.h>
+#include <libedataserver/e-source.h>
#include <libebook/Evolution-DataServer-Addressbook.h>
#include <libebook/e-contact.h>
#include <libebook/e-book-query.h>
EBook *e_book_new (void);
/* loading arbitrary addressbooks */
+gboolean e_book_load_source (EBook *book,
+ ESource *source,
+ gboolean only_if_exists,
+ GError **error);
+
gboolean e_book_load_uri (EBook *book,
const char *uri,
gboolean only_if_exists,
GMutex *clients_mutex;
GList *clients;
- char *uri;
+ ESource *source;
gboolean loaded, writable, removed;
GMutex *views_mutex;
}
GNOME_Evolution_Addressbook_CallStatus
-e_book_backend_load_uri (EBookBackend *backend,
- const char *uri,
- gboolean only_if_exists)
+e_book_backend_load_source (EBookBackend *backend,
+ ESource *source,
+ gboolean only_if_exists)
{
GNOME_Evolution_Addressbook_CallStatus status;
g_return_val_if_fail (E_IS_BOOK_BACKEND (backend), FALSE);
- g_return_val_if_fail (uri, FALSE);
+ g_return_val_if_fail (source, FALSE);
g_return_val_if_fail (backend->priv->loaded == FALSE, FALSE);
- g_assert (E_BOOK_BACKEND_GET_CLASS (backend)->load_uri);
+ g_assert (E_BOOK_BACKEND_GET_CLASS (backend)->load_source);
- status = (* E_BOOK_BACKEND_GET_CLASS (backend)->load_uri) (backend, uri, only_if_exists);
+ status = (* E_BOOK_BACKEND_GET_CLASS (backend)->load_source) (backend, source, only_if_exists);
- if (status == GNOME_Evolution_Addressbook_Success)
- backend->priv->uri = g_strdup (uri);
+ if (status == GNOME_Evolution_Addressbook_Success) {
+ g_object_ref (source);
+ backend->priv->source = source;
+ }
return status;
}
/**
- * e_book_backend_get_uri:
+ * e_book_backend_get_source:
* @backend: An addressbook backend.
*
- * Queries the URI that an addressbook backend is serving.
+ * Queries the source that an addressbook backend is serving.
*
- * Return value: URI for the backend.
+ * Return value: ESource for the backend.
**/
-const char *
-e_book_backend_get_uri (EBookBackend *backend)
+ESource *
+e_book_backend_get_source (EBookBackend *backend)
{
g_return_val_if_fail (E_IS_BOOK_BACKEND (backend), NULL);
- return backend->priv->uri;
+ return backend->priv->source;
}
void
e_data_book_report_writable (book, backend->priv->writable);
} else {
GNOME_Evolution_Addressbook_CallStatus status =
- e_book_backend_load_uri (backend, e_data_book_get_uri (book), only_if_exists);
+ e_book_backend_load_source (backend, e_data_book_get_source (book), only_if_exists);
e_data_book_respond_open (book, status);
EBookBackendPrivate *priv;
priv = g_new0 (EBookBackendPrivate, 1);
- priv->uri = NULL;
priv->clients = NULL;
priv->views = e_list_new((EListCopyFunc) g_object_ref, (EListFreeFunc) g_object_unref, NULL);
priv->open_mutex = g_mutex_new ();
if (backend->priv) {
g_list_free (backend->priv->clients);
- if (backend->priv->uri)
- g_free (backend->priv->uri);
-
if (backend->priv->views) {
g_object_unref (backend->priv->views);
backend->priv->views = NULL;
GObjectClass parent_class;
/* Virtual methods */
- GNOME_Evolution_Addressbook_CallStatus (*load_uri) (EBookBackend *backend, const char *uri, gboolean only_if_exists);
+ GNOME_Evolution_Addressbook_CallStatus (*load_source) (EBookBackend *backend, ESource *source, gboolean only_if_exists);
void (*remove) (EBookBackend *backend, EDataBook *book);
char *(*get_static_capabilities) (EBookBackend *backend);
gboolean e_book_backend_construct (EBookBackend *backend);
GNOME_Evolution_Addressbook_CallStatus
- e_book_backend_load_uri (EBookBackend *backend,
- const char *uri,
- gboolean only_if_exists);
-const char *e_book_backend_get_uri (EBookBackend *backend);
+ e_book_backend_load_source (EBookBackend *backend,
+ ESource *source,
+ gboolean only_if_exists);
+ESource *e_book_backend_get_source (EBookBackend *backend);
gboolean e_book_backend_add_client (EBookBackend *backend,
EDataBook *book);
backend_last_client_gone_cb (EBookBackend *backend, gpointer data)
{
EDataBookFactory *factory;
- const char *uri;
+ ESource *source;
+ gchar *uri;
factory = E_DATA_BOOK_FACTORY (data);
/* Remove the backend from the active server map */
- uri = e_book_backend_get_uri (backend);
+ source = e_book_backend_get_source (backend);
+ if (source)
+ uri = e_source_get_uri (source);
+ else
+ uri = NULL;
+
if (uri) {
gpointer orig_key;
gboolean result;
/* Notify upstream if there are no more backends */
g_signal_emit (G_OBJECT (factory), factory_signals[LAST_BOOK_GONE], 0);
}
+
+ g_free (uri);
}
\f
static GNOME_Evolution_Addressbook_Book
impl_GNOME_Evolution_Addressbook_BookFactory_getBook (PortableServer_Servant servant,
- const CORBA_char *uri,
+ const CORBA_char *source_xml,
const GNOME_Evolution_Addressbook_BookListener listener,
CORBA_Environment *ev)
{
EDataBookFactory *factory = E_DATA_BOOK_FACTORY (bonobo_object (servant));
+ GNOME_Evolution_Addressbook_Book corba_book;
EBookBackend *backend;
EDataBook *book;
+ ESource *source;
+ gchar *uri;
printf ("impl_GNOME_Evolution_Addressbook_BookFactory_getBook\n");
+ source = e_source_new_from_standalone_xml (source_xml);
+ if (!source) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_GNOME_Evolution_Addressbook_BookFactory_ProtocolNotSupported,
+ NULL);
+ return CORBA_OBJECT_NIL;
+ }
+
+ uri = e_source_get_uri (source);
+ if (!uri) {
+ g_object_unref (source);
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_GNOME_Evolution_Addressbook_BookFactory_ProtocolNotSupported,
+ NULL);
+ return CORBA_OBJECT_NIL;
+ }
+
/* Look up the backend and create one if needed */
g_mutex_lock (factory->priv->map_mutex);
g_mutex_unlock (factory->priv->map_mutex);
+ g_free (uri);
return CORBA_OBJECT_NIL;
}
backend = e_data_book_factory_launch_backend (factory, backend_factory, listener, uri);
}
+ g_free (uri);
+
if (backend) {
GNOME_Evolution_Addressbook_BookListener listener_copy;
g_mutex_unlock (factory->priv->map_mutex);
- book = e_data_book_new (backend, uri, listener);
+ book = e_data_book_new (backend, source, listener);
e_book_backend_add_client (backend, book);
- return bonobo_object_corba_objref (BONOBO_OBJECT (book));
+ corba_book = bonobo_object_corba_objref (BONOBO_OBJECT (book));
}
else {
/* probably need a more descriptive exception here */
NULL);
g_mutex_unlock (factory->priv->map_mutex);
- return CORBA_OBJECT_NIL;
+ corba_book = CORBA_OBJECT_NIL;
}
+
+ g_object_unref (source);
+ return corba_book;
}
static void
struct _EDataBookPrivate {
EBookBackend *backend;
GNOME_Evolution_Addressbook_BookListener listener;
- char *uri;
+ ESource *source;
};
static void
return book->priv->listener;
}
-const char*
-e_data_book_get_uri (EDataBook *book)
+ESource *
+e_data_book_get_source (EDataBook *book)
{
- return book->priv->uri;
+ return book->priv->source;
}
/**
static void
e_data_book_construct (EDataBook *book,
EBookBackend *backend,
- const char *uri,
+ ESource *source,
GNOME_Evolution_Addressbook_BookListener listener)
{
EDataBookPrivate *priv;
CORBA_Environment ev;
g_return_if_fail (book != NULL);
+ g_return_if_fail (source != NULL);
priv = book->priv;
CORBA_exception_free (&ev);
- priv->backend = backend;
- priv->uri = g_strdup (uri);
+ g_object_ref (source);
+ priv->backend = backend;
+ priv->source = source;
}
/**
*/
EDataBook *
e_data_book_new (EBookBackend *backend,
- const char *uri,
+ ESource *source,
GNOME_Evolution_Addressbook_BookListener listener)
{
EDataBook *book;
"poa", bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL),
NULL);
- e_data_book_construct (book, backend, uri, listener);
+ e_data_book_construct (book, backend, source, listener);
g_free (caps);
CORBA_exception_free (&ev);
- g_free (book->priv->uri);
+ g_object_unref (book->priv->source);
g_free (book->priv);
book->priv = NULL;
}
#include <bonobo/bonobo-object.h>
#include <libedataserver/e-list.h>
+#include <libedataserver/e-source.h>
#include <libedata-book/Evolution-DataServer-Addressbook.h>
#include <libedata-book/e-data-book-types.h>
EDataBook *e_data_book_new (EBookBackend *backend,
- const char *uri,
+ ESource *source,
GNOME_Evolution_Addressbook_BookListener listener);
GNOME_Evolution_Addressbook_BookListener e_data_book_get_listener (EDataBook *book);
EBookBackend *e_data_book_get_backend (EDataBook *book);
-const char *e_data_book_get_uri (EDataBook *book);
+ESource *e_data_book_get_source (EDataBook *book);
void e_data_book_respond_open (EDataBook *book,
GNOME_Evolution_Addressbook_CallStatus status);
+2003-11-26 Hans Petter Jansson <hpj@ximian.com>
+
+ * idl/Evolution-DataServer-Calendar.idl (getCal): Take source XML
+ instead of URI.
+
+ * libecal/client-test.c (create_client): Adapt to API changes.
+ (main): Ditto.
+
+ * libecal/e-cal.c (fetch_corba_cal): Move to ESource.
+ (e_cal_new): Take ESource.
+ (e_cal_new_from_uri): Implement convenience call that takes URI.
+
+ * libedata-cal/e-cal-backend.c (e_cal_backend_set_property):
+ Implement PROP_SOURCE.
+ (e_cal_backend_get_property): Same.
+ (e_cal_backend_class_init): Same.
+ (e_cal_backend_get_source): Same.
+
+ * libedata-cal/e-data-cal-factory.c (impl_CalFactory_getCal): Take
+ source XML and construct an ESource. Init backend with that.
+
2003-11-25 Rodrigo Moya <rodrigo@ximian.com>
* backends/groupwise/e-gw-message.[ch]: new files to contain utility
priv = cbfile->priv;
master_uri = e_cal_backend_get_uri (backend);
-
+
/* FIXME Check the error conditions a little more elegantly here */
if (g_strrstr ("tasks.ics", master_uri) || g_strrstr ("calendar.ics", master_uri)) {
g_warning (G_STRLOC ": Existing file name %s", master_uri);
exception InvalidURI {};
exception UnsupportedMethod {};
- Cal getCal (in string uri, in CalObjType type, in CalListener listener)
+ Cal getCal (in string source, in CalObjType type, in CalListener listener)
raises (NilListener, InvalidURI, UnsupportedMethod);
};
};
/* Creates a calendar client and tries to load the specified URI into it */
static void
-create_client (ECal **client, const char *uri, CalObjType type, gboolean only_if_exists)
+create_client (ECal **client, const gchar *uri, CalObjType type, gboolean only_if_exists)
{
ECalView *query;
GError *error = NULL;
- *client = e_cal_new (uri, type);
+ *client = e_cal_new_from_uri (uri, type);
if (!*client) {
g_message (G_STRLOC ": could not create the client");
exit (1);
g_object_weak_ref (G_OBJECT (*client), client_destroy_cb, NULL);
cl_printf (*client, "Calendar loading `%s'...\n", uri);
+
if (!e_cal_open (*client, only_if_exists, &error)) {
cl_printf (*client, "Load/create %s\n", error->message);
exit (1);
e_cal_view_start (query);
g_idle_add (list_uids, *client);
+
}
int
exit (1);
}
- create_client (&client1, "file:///home/gnome24-evolution-new-calendar/evolution/local/Calendar",
- CALOBJ_TYPE_EVENT, FALSE);
+#if 0
+ source = e_source_new ("test-source", "file:///home/gnome24-evolution-new-calendar/evolution/local/Calendar");
+#endif
+ create_client (&client1, "file:///home/hpj/.evolution/calendar/local/OnThisComputer/Pakk", CALOBJ_TYPE_EVENT, FALSE);
// create_client (&client2, "file:///tmp/tasks", TRUE);
bonobo_main ();
static gboolean
-fetch_corba_cal (ECal *ecal, const char *str_uri, CalObjType type)
+fetch_corba_cal (ECal *ecal, ESource *source, CalObjType type)
{
ECalPrivate *priv;
GList *f;
CORBA_Environment ev;
+ gchar *source_xml;
+ gchar *str_uri;
+ gboolean result = FALSE;
priv = ecal->priv;
g_return_val_if_fail (priv->load_state == E_CAL_LOAD_NOT_LOADED, FALSE);
g_assert (priv->uri == NULL);
+ g_return_val_if_fail (source != NULL, FALSE);
- g_return_val_if_fail (str_uri != NULL, FALSE);
+ str_uri = e_source_get_uri (source);
+ if (!str_uri)
+ return FALSE;
- if (!get_factories (str_uri, &priv->factories))
+ if (!get_factories (str_uri, &priv->factories)) {
+ g_free (str_uri);
return FALSE;
+ }
priv->uri = g_strdup (str_uri);
priv->type = type;
+ source_xml = e_source_to_standalone_xml (source);
+
for (f = priv->factories; f; f = f->next) {
GNOME_Evolution_Calendar_Cal cal;
CORBA_exception_init (&ev);
- cal = GNOME_Evolution_Calendar_CalFactory_getCal (f->data, priv->uri, priv->type,
+ cal = GNOME_Evolution_Calendar_CalFactory_getCal (f->data, source_xml, priv->type,
BONOBO_OBJREF (priv->listener), &ev);
if (BONOBO_EX (&ev))
continue;
priv->cal = cal;
- return TRUE;
+ result = TRUE;
+ break;
}
- return FALSE;
+ g_free (str_uri);
+ g_free (source_xml);
+ return result;
}
/**
* e_cal_new:
- * @uri:
+ * @source:
* @type:
*
* Creates a new calendar ecal. It should be initialized by calling
* not be constructed because it could not contact the calendar server.
**/
ECal *
-e_cal_new (const char *uri, CalObjType type)
+e_cal_new (ESource *source, CalObjType type)
{
ECal *ecal;
ecal = g_object_new (E_TYPE_CAL, NULL);
- if (!fetch_corba_cal (ecal, uri, type)) {
+ if (!fetch_corba_cal (ecal, source, type)) {
g_object_unref (ecal);
return NULL;
}
/**
+ * e_cal_new_from_uri:
+ * @uri:
+ * @type:
+ *
+ * Creates a new calendar ecal. It should be initialized by calling
+ * e_cal_open().
+ *
+ * Return value: A newly-created calendar ecal, or NULL if the ecal could
+ * not be constructed because it could not contact the calendar server.
+ **/
+ECal *
+e_cal_new_from_uri (const gchar *uri, CalObjType type)
+{
+ ESourceGroup *group;
+ ESource *source;
+ ECal *cal;
+
+ group = e_source_group_new ("", uri);
+ source = e_source_new ("", "");
+ e_source_set_group (source, group);
+
+ cal = e_cal_new (source, type);
+
+ g_object_unref (source);
+ g_object_unref (group);
+
+ return cal;
+}
+
+/**
* e_cal_set_auth_func
* @ecal: A calendar ecal.
* @func: The authentication function
#define E_CAL_H
#include <glib-object.h>
+#include <libedataserver/e-source.h>
#include <libecal/e-cal-recur.h>
#include <libecal/e-cal-util.h>
#include <libecal/e-cal-view.h>
GType e_cal_set_mode_status_enum_get_type (void);
GType cal_mode_enum_get_type (void);
-ECal *e_cal_new (const char *uri, CalObjType type);
+ECal *e_cal_new (ESource *source, CalObjType type);
+ECal *e_cal_new_from_uri (const gchar *uri, CalObjType type);
void e_cal_set_auth_func (ECal *ecal, ECalAuthFunc func, gpointer data);
/* Private part of the CalBackend structure */
struct _ECalBackendPrivate {
- /* The uri for this backend */
+ /* The source for this backend */
+ ESource *source;
+
+ /* URI, from source. This is cached, since we return const. */
char *uri;
/* The kind of components for this backend */
/* Property IDs */
enum props {
PROP_0,
+ PROP_SOURCE,
PROP_URI,
PROP_KIND
};
priv = backend->priv;
switch (property_id) {
+ case PROP_SOURCE:
+ {
+ ESource *new_source;
+
+ new_source = g_value_get_object (value);
+ if (new_source)
+ g_object_ref (new_source);
+
+ if (priv->source)
+ g_object_unref (priv->source);
+
+ priv->source = new_source;
+
+ /* Cache the URI */
+ if (new_source) {
+ g_free (priv->uri);
+ priv->uri = e_source_get_uri (priv->source);
+ }
+ }
+ break;
case PROP_URI:
- g_free (priv->uri);
- priv->uri = g_value_dup_string (value);
+ if (!priv->source) {
+ g_free (priv->uri);
+ priv->uri = g_value_dup_string (value);
+ }
break;
case PROP_KIND:
priv->kind = g_value_get_ulong (value);
priv = backend->priv;
switch (property_id) {
+ case PROP_SOURCE:
+ g_value_set_object (value, e_cal_backend_get_source (backend));
+ break;
case PROP_URI:
g_value_set_string (value, e_cal_backend_get_uri (backend));
break;
object_class->get_property = e_cal_backend_get_property;
object_class->finalize = e_cal_backend_finalize;
+ g_object_class_install_property (object_class, PROP_SOURCE,
+ g_param_spec_object ("source", NULL, NULL, E_TYPE_SOURCE,
+ G_PARAM_READABLE | G_PARAM_WRITABLE
+ | G_PARAM_CONSTRUCT_ONLY));
+
g_object_class_install_property (object_class, PROP_URI,
g_param_spec_string ("uri", NULL, NULL, "",
G_PARAM_READABLE | G_PARAM_WRITABLE
\f
+ESource *
+e_cal_backend_get_source (ECalBackend *backend)
+{
+ ECalBackendPrivate *priv;
+
+ g_return_val_if_fail (backend != NULL, NULL);
+ g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
+
+ priv = backend->priv;
+
+ return priv->source;
+}
+
/**
* e_cal_backend_get_uri:
* @backend: A calendar backend.
#define E_CAL_BACKEND_H
#include <libedataserver/e-list.h>
+#include <libedataserver/e-source.h>
#include <libecal/e-cal-util.h>
#include <libecal/e-cal-component.h>
#include <libedata-cal/Evolution-DataServer-Calendar.h>
GType e_cal_backend_get_type (void);
+ESource *e_cal_backend_get_source (ECalBackend *backend);
const char *e_cal_backend_get_uri (ECalBackend *backend);
icalcomponent_kind e_cal_backend_get_kind (ECalBackend *backend);
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-main.h>
#include <libedataserver/e-url.h>
+#include <libedataserver/e-source.h>
#include "e-cal-backend.h"
#include "e-data-cal.h"
#include "e-data-cal-factory.h"
static GNOME_Evolution_Calendar_Cal
impl_CalFactory_getCal (PortableServer_Servant servant,
- const CORBA_char *str_uri,
+ const CORBA_char *source_xml,
const GNOME_Evolution_Calendar_CalObjType type,
const GNOME_Evolution_Calendar_CalListener listener,
CORBA_Environment *ev)
CORBA_Environment ev2;
GNOME_Evolution_Calendar_CalListener listener_copy;
GType backend_type;
+ ESource *source;
+ char *str_uri;
EUri *uri;
char *uri_string;
factory = E_DATA_CAL_FACTORY (bonobo_object_from_servant (servant));
priv = factory->priv;
+ source = e_source_new_from_standalone_xml (source_xml);
+ if (!source) {
+ bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CalFactory_InvalidURI);
+
+ return CORBA_OBJECT_NIL;
+ }
+
+ /* Get the URI so we can extract the protocol */
+ str_uri = e_source_get_uri (source);
+ if (!str_uri) {
+ g_object_unref (source);
+ bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CalFactory_InvalidURI);
+
+ return CORBA_OBJECT_NIL;
+ }
+
/* Parse the uri */
uri = e_uri_new (str_uri);
+ g_free (str_uri);
+
if (!uri) {
bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CalFactory_InvalidURI);
backend = lookup_backend (factory, uri_string);
if (!backend) {
/* There was no existing backend, create a new one */
- backend = g_object_new (backend_type, "uri", uri_string, "kind", calobjtype_to_icalkind (type), NULL);
+ backend = g_object_new (backend_type, "source", source, "kind", calobjtype_to_icalkind (type), NULL);
if (!backend) {
g_warning (G_STRLOC ": could not instantiate backend");
bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CalFactory_UnsupportedMethod);
cleanup:
e_uri_free (uri);
g_free (uri_string);
+ g_object_unref (source);
return CORBA_Object_duplicate (BONOBO_OBJREF (cal), ev);
}
return TRUE;
case Bonobo_ACTIVATION_REG_NOT_LISTED:
- g_warning (G_STRLOC ": cannot register the calendar factory (not listed)");
+ g_warning (G_STRLOC ": cannot register the calendar factory %s (not listed)", tmp_iid);
break;
case Bonobo_ACTIVATION_REG_ALREADY_ACTIVE:
char *uid;
char *name;
char *relative_uri;
+ char *absolute_uri;
gboolean has_color;
guint32 color;
g_free (priv->uid);
g_free (priv->name);
g_free (priv->relative_uri);
+ g_free (priv->absolute_uri);
g_free (priv);
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
{
xmlChar *name;
xmlChar *relative_uri;
+ xmlChar *absolute_uri;
xmlChar *color_string;
gboolean retval;
gboolean changed = FALSE;
name = xmlGetProp (node, "name");
relative_uri = xmlGetProp (node, "relative_uri");
+ absolute_uri = xmlGetProp (node, "uri");
color_string = xmlGetProp (node, "color");
- if (name == NULL || relative_uri == NULL) {
+ if (name == NULL || (relative_uri == NULL && absolute_uri == NULL)) {
retval = FALSE;
goto done;
}
changed = TRUE;
}
+ if (absolute_uri != NULL) {
+ g_free (source->priv->absolute_uri);
+ source->priv->absolute_uri = g_strdup (absolute_uri);
+ changed = TRUE;
+ }
+
if (color_string == NULL) {
if (source->priv->has_color) {
source->priv->has_color = FALSE;
xmlFree (name);
if (relative_uri != NULL)
xmlFree (relative_uri);
+ if (absolute_uri != NULL)
+ xmlFree (absolute_uri);
if (color_string != NULL)
xmlFree (color_string);
g_return_val_if_fail (E_IS_SOURCE (source), NULL);
- if (source->priv->group == NULL)
+ if (source->priv->group == NULL) {
+ if (source->priv->absolute_uri != NULL)
+ return g_strdup (source->priv->absolute_uri);
+
return NULL;
+ }
base_uri_str = e_source_group_peek_base_uri (source->priv->group);
}
-void
-e_source_dump_to_xml_node (ESource *source,
- xmlNodePtr parent_node)
+static xmlNodePtr
+dump_common_to_xml_node (ESource *source,
+ xmlNodePtr parent_node)
{
gboolean has_color;
guint32 color;
- xmlNodePtr node = xmlNewChild (parent_node, NULL, "source", NULL);
-
- g_return_if_fail (E_IS_SOURCE (source));
+ xmlNodePtr node;
+ if (parent_node)
+ node = xmlNewChild (parent_node, NULL, "source", NULL);
+ else
+ node = xmlNewNode (NULL, "source");
xmlSetProp (node, "uid", e_source_peek_uid (source));
xmlSetProp (node, "name", e_source_peek_name (source));
xmlSetProp (node, "color", color_string);
g_free (color_string);
}
+
+ return node;
+}
+
+
+void
+e_source_dump_to_xml_node (ESource *source,
+ xmlNodePtr parent_node)
+{
+ g_return_if_fail (E_IS_SOURCE (source));
+
+ dump_common_to_xml_node (source, parent_node);
+}
+
+
+char *
+e_source_to_standalone_xml (ESource *source)
+{
+ xmlDocPtr doc;
+ xmlNodePtr node;
+ xmlChar *xml_buffer;
+ char *returned_buffer;
+ int xml_buffer_size;
+ gchar *uri;
+
+ g_return_val_if_fail (E_IS_SOURCE (source), NULL);
+ g_return_val_if_fail (source->priv->group != NULL, NULL);
+
+ doc = xmlNewDoc ("1.0");
+ node = dump_common_to_xml_node (source, NULL);
+
+ xmlDocSetRootElement (doc, node);
+
+ uri = e_source_get_uri (source);
+ xmlSetProp (node, "uri", uri);
+ g_free (uri);
+
+ xmlDocDumpMemory (doc, &xml_buffer, &xml_buffer_size);
+ xmlFreeDoc (doc);
+
+ returned_buffer = g_malloc (xml_buffer_size + 1);
+ memcpy (returned_buffer, xml_buffer, xml_buffer_size);
+ returned_buffer [xml_buffer_size] = '\0';
+ xmlFree (xml_buffer);
+
+ return returned_buffer;
+}
+
+
+ESource *
+e_source_new_from_standalone_xml (const char *xml)
+{
+ xmlDocPtr doc;
+ xmlNodePtr root;
+ ESource *source;
+
+ doc = xmlParseDoc ((char *) xml);
+ if (doc == NULL)
+ return NULL;
+
+ root = doc->children;
+ if (strcmp (root->name, "source") != 0)
+ return NULL;
+
+ source = e_source_new_from_xml_node (root);
+ xmlFreeDoc (doc);
+
+ return source;
}
ESource *e_source_new (const char *name,
const char *relative_uri);
ESource *e_source_new_from_xml_node (xmlNodePtr node);
+ESource *e_source_new_from_standalone_xml (const char *xml);
gboolean e_source_update_from_xml_node (ESource *source,
xmlNodePtr node,
void e_source_dump_to_xml_node (ESource *source,
xmlNodePtr parent_node);
+char *e_source_to_standalone_xml (ESource *source);
#endif /* _E_SOURCE_H_ */