From 5120d7098b94b95a75993be8faa3377507a50b45 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 27 Sep 2001 14:39:39 +0000 Subject: Change "gboolean connected" to "CamelServiceConnectionStatus status", * camel-service.c: Change "gboolean connected" to "CamelServiceConnectionStatus status", which can be disconnected, connecting, connected, or disconnecting. (camel_service_init, camel_service_finalize): create/destroy the connect_op_lock. Refer to service->status rather than service->connected. (camel_service_connect): When connecting, note the current operation (and create a new one if there's none registered) and mark the connection "connecting" until we succeed or fail. (camel_service_disconnect): Likewise in reverse. (camel_service_cancel_connect): New function to cancel a connection attempt. (cancel_connect): Default implementation: Call camel_operation_cancel on the connect_op. * camel-disco-store.c (disco_connect): Only call CamelRemoteStore's connect func if we're online. (disco_cancel_connect): Fall back to offline if a connection gets cancelled. (disco_get_folder_info): Kludge: call connect explicitly before deciding whether to do the online or offline version, so if the connect fails, we fall back correctly. * camel-session.c (camel_session_get_service_connected): s/svc->connected/svc->status/ * camel-remote-store.c (camel_remote_store_finalise): Change service->connected check to service->status check. (remote_connect): Don't set service->connected here: camel_service_connect() itself does that. * camel-operation.c (camel_operation_registered): Deal with the possibility that there's no registered op. svn path=/trunk/; revision=13191 --- camel/camel-disco-store.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'camel/camel-disco-store.c') diff --git a/camel/camel-disco-store.c b/camel/camel-disco-store.c index 0cc5f4feea..145636f58d 100644 --- a/camel/camel-disco-store.c +++ b/camel/camel-disco-store.c @@ -39,6 +39,7 @@ static void disco_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex); static gboolean disco_connect (CamelService *service, CamelException *ex); +static void disco_cancel_connect (CamelService *service); static gboolean disco_disconnect (CamelService *service, gboolean clean, CamelException *ex); static CamelFolder *disco_get_folder (CamelStore *store, const char *name, guint32 flags, CamelException *ex); @@ -68,6 +69,7 @@ camel_disco_store_class_init (CamelDiscoStoreClass *camel_disco_store_class) camel_service_class->construct = disco_construct; camel_service_class->connect = disco_connect; camel_service_class->disconnect = disco_disconnect; + camel_service_class->cancel_connect = disco_cancel_connect; camel_store_class->get_folder = disco_get_folder; camel_store_class->get_folder_info = disco_get_folder_info; @@ -111,11 +113,19 @@ static gboolean disco_connect (CamelService *service, CamelException *ex) { CamelDiscoStore *store = CAMEL_DISCO_STORE (service); + CamelDiscoStoreStatus status; + + status = camel_disco_store_status (store); + if (status != CAMEL_DISCO_STORE_OFFLINE) { + if (!CAMEL_SERVICE_CLASS (remote_store_class)->connect (service, ex)) { + status = camel_disco_store_status (store); + if (status != CAMEL_DISCO_STORE_OFFLINE) + return FALSE; + camel_exception_clear (ex); + } + } - if (!CAMEL_SERVICE_CLASS (remote_store_class)->connect (service, ex)) - return FALSE; - - switch (camel_disco_store_status (store)) { + switch (status) { case CAMEL_DISCO_STORE_ONLINE: case CAMEL_DISCO_STORE_RESYNCING: if (!CDS_CLASS (service)->connect_online (service, ex)) @@ -142,6 +152,17 @@ disco_connect (CamelService *service, CamelException *ex) return FALSE; } +static void +disco_cancel_connect (CamelService *service) +{ + CamelDiscoStore *store = CAMEL_DISCO_STORE (service); + + /* Fall back */ + store->status = CAMEL_DISCO_STORE_OFFLINE; + + CAMEL_SERVICE_CLASS (remote_store_class)->cancel_connect (service); +} + static gboolean disco_disconnect (CamelService *service, gboolean clean, CamelException *ex) { @@ -190,7 +211,17 @@ disco_get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex) { CamelDiscoStore *disco_store = CAMEL_DISCO_STORE (store); - + + /* Do this first so if we get forced offline, we'll switch to + * the correct branch below. (FIXME: This only works because + * we know that get_folder_info is the first call that the + * mailer makes on a store.) + */ + if (CAMEL_SERVICE (store)->status == CAMEL_SERVICE_DISCONNECTED) { + if (!camel_service_connect (CAMEL_SERVICE (store), ex)) + return NULL; + } + switch (camel_disco_store_status (disco_store)) { case CAMEL_DISCO_STORE_ONLINE: return CDS_CLASS (store)->get_folder_info_online (store, top, flags, ex); -- cgit v1.2.3