From e443c59bcd8f28c2aaae449aa9276cc80f9f1b6e Mon Sep 17 00:00:00 2001 From: Shreyas Srinivasan Date: Thu, 22 Dec 2005 01:48:30 +0000 Subject: [PATCH] Network Manager Support 2005-12-22 Shreyas Srinivasan * Network Manager Support * camel-session.[h,c]: Add a gboolean network_state which the shell uses to set the current network state. Add new api's camel_session_get_network_state and camel_session_set_network_state. * camel-offline-folder.c: If network down then dont sync folders while going offline and send clean as FALSE to camel_service_disconnect. * camel-disco-folder.c: If network down then dont sync folders while going offline and send clean as FALSE to camel_service_disconnect. --- camel/ChangeLog | 17 +++++++++++++++ camel/camel-disco-store.c | 50 +++++++++++++++++++++++++------------------- camel/camel-offline-store.c | 51 ++++++++++++++++++++++++++------------------- camel/camel-session.c | 17 +++++++++++++++ camel/camel-session.h | 4 +++- 5 files changed, 94 insertions(+), 45 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index 26495c0..f64653f 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,20 @@ +2005-12-22 Shreyas Srinivasan + + * Network Manager Support + + * camel-session.[h,c]: Add a gboolean network_state + which the shell uses to set the current network state. + Add new api's camel_session_get_network_state and + camel_session_set_network_state. + + * camel-offline-folder.c: If network down then dont + sync folders while going offline and send clean as FALSE + to camel_service_disconnect. + + * camel-disco-folder.c: If network down then dont + sync folders while going offline and send clean as FALSE + to camel_service_disconnect. + 2005-12-13 Tor Lillqvist * camel-filter-driver.c: Use gstdio wrappers. Use diff --git a/camel/camel-disco-store.c b/camel/camel-disco-store.c index 57babf4..2828179 100644 --- a/camel/camel-disco-store.c +++ b/camel/camel-disco-store.c @@ -296,6 +296,8 @@ static void set_status(CamelDiscoStore *disco_store, CamelDiscoStoreStatus status, CamelException *ex) { CamelException x; + CamelService *service = CAMEL_SERVICE (disco_store); + gboolean network_state = camel_session_get_network_state (service->session); if (disco_store->status == status) return; @@ -303,32 +305,36 @@ set_status(CamelDiscoStore *disco_store, CamelDiscoStoreStatus status, CamelExce camel_exception_init(&x); /* Sync the folder fully if we've been told to sync online for this store or this folder and we're going offline */ - if (disco_store->status == CAMEL_DISCO_STORE_ONLINE - && status == CAMEL_DISCO_STORE_OFFLINE) { - if (((CamelStore *)disco_store)->folders) { - GPtrArray *folders; - CamelFolder *folder; - int i, sync; - - sync = camel_url_get_param(((CamelService *)disco_store)->url, "offline_sync") != NULL; - - folders = camel_object_bag_list(((CamelStore *)disco_store)->folders); - for (i=0;ilen;i++) { - folder = folders->pdata[i]; - if (CAMEL_CHECK_TYPE(folder, CAMEL_DISCO_FOLDER_TYPE) - && (sync || ((CamelDiscoFolder *)folder)->offline_sync)) { - camel_disco_folder_prepare_for_offline((CamelDiscoFolder *)folder, "(match-all)", &x); - camel_exception_clear(&x); + + if (network_state) { + if (disco_store->status == CAMEL_DISCO_STORE_ONLINE + && status == CAMEL_DISCO_STORE_OFFLINE) { + if (((CamelStore *)disco_store)->folders) { + GPtrArray *folders; + CamelFolder *folder; + int i, sync; + + sync = camel_url_get_param(((CamelService *)disco_store)->url, "offline_sync") != NULL; + + folders = camel_object_bag_list(((CamelStore *)disco_store)->folders); + for (i=0;ilen;i++) { + folder = folders->pdata[i]; + if (CAMEL_CHECK_TYPE(folder, CAMEL_DISCO_FOLDER_TYPE) + && (sync || ((CamelDiscoFolder *)folder)->offline_sync)) { + camel_disco_folder_prepare_for_offline((CamelDiscoFolder *)folder, "(match-all)", &x); + camel_exception_clear(&x); + } + camel_object_unref(folder); } - camel_object_unref(folder); + g_ptr_array_free(folders, TRUE); } - g_ptr_array_free(folders, TRUE); } + + camel_store_sync(CAMEL_STORE (disco_store), FALSE, &x); + camel_exception_clear(&x); } - - camel_store_sync(CAMEL_STORE (disco_store), FALSE, &x); - camel_exception_clear(&x); - if (!camel_service_disconnect (CAMEL_SERVICE (disco_store), TRUE, ex)) + + if (!camel_service_disconnect (CAMEL_SERVICE (disco_store), network_state, ex)) return; disco_store->status = status; diff --git a/camel/camel-offline-store.c b/camel/camel-offline-store.c index 3459311..a5865bd 100644 --- a/camel/camel-offline-store.c +++ b/camel/camel-offline-store.c @@ -114,46 +114,53 @@ void camel_offline_store_set_network_state (CamelOfflineStore *store, int state, CamelException *ex) { CamelException lex; - + CamelService *service = CAMEL_SERVICE (store); + gboolean network_state = camel_session_get_network_state (service->session); + if (store->state == state) return; camel_exception_init (&lex); if (store->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL) { /* network available -> network unavailable */ - if (((CamelStore *) store)->folders) { - GPtrArray *folders; - CamelFolder *folder; - int i, sync; - - sync = camel_url_get_param (((CamelService *) store)->url, "sync_offline") != NULL; - - folders = camel_object_bag_list (((CamelStore *) store)->folders); - for (i = 0; i < folders->len; i++) { - folder = folders->pdata[i]; + if (network_state) { + if (((CamelStore *) store)->folders) { + GPtrArray *folders; + CamelFolder *folder; + int i, sync; + + sync = camel_url_get_param (((CamelService *) store)->url, "sync_offline") != NULL; - if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE) - && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) { - camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex); - camel_exception_clear (&lex); + folders = camel_object_bag_list (((CamelStore *) store)->folders); + for (i = 0; i < folders->len; i++) { + folder = folders->pdata[i]; + + if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE) + && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) { + camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex); + camel_exception_clear (&lex); + } + + camel_object_unref (folder); } - camel_object_unref (folder); + g_ptr_array_free (folders, TRUE); } - g_ptr_array_free (folders, TRUE); + camel_store_sync (CAMEL_STORE (store), FALSE, &lex); + camel_exception_clear (&lex); } - - camel_store_sync (CAMEL_STORE (store), FALSE, &lex); - camel_exception_clear (&lex); - - if (!camel_service_disconnect (CAMEL_SERVICE (store), TRUE, ex)) + + if (!camel_service_disconnect (CAMEL_SERVICE (store), network_state, ex)) return; } else { /* network unavailable -> network available */ if (!camel_service_connect (CAMEL_SERVICE (store), ex)) return; + fprintf (stderr, "i hit this boo wtf\n"); } + if (store->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL) + fprintf (stderr,"I do my job well\n"); store->state = state; } diff --git a/camel/camel-session.c b/camel/camel-session.c index 63c8202..69400ff 100644 --- a/camel/camel-session.c +++ b/camel/camel-session.c @@ -68,6 +68,7 @@ static void camel_session_init (CamelSession *session) { session->online = TRUE; + session->network_state = TRUE; session->priv = g_malloc0(sizeof(*session->priv)); session->priv->lock = g_mutex_new(); @@ -679,3 +680,19 @@ camel_session_set_check_junk (CamelSession *session, gboolean check_junk) session->check_junk = check_junk; } + +gboolean +camel_session_get_network_state (CamelSession *session) +{ + g_return_if_fail (CAMEL_IS_SESSION(session)); + + return session->network_state; +} + +void +camel_session_set_network_state (CamelSession *session, gboolean network_state) +{ + g_return_if_fail (CAMEL_IS_SESSION(session)); + + session->network_state = network_state; +} diff --git a/camel/camel-session.h b/camel/camel-session.h index b5e0b6f..0d559a6 100644 --- a/camel/camel-session.h +++ b/camel/camel-session.h @@ -68,6 +68,7 @@ struct _CamelSession gboolean online:1; gboolean check_junk:1; + gboolean network_state:1; }; typedef struct _CamelSessionThreadOps CamelSessionThreadOps; @@ -193,7 +194,8 @@ void *camel_session_thread_msg_new(CamelSession *session, CamelSessionThreadOps void camel_session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg); int camel_session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, int flags); void camel_session_thread_wait(CamelSession *session, int id); - +gboolean camel_session_get_network_state (CamelSession *session); +void camel_session_set_network_state (CamelSession *session, gboolean network_state); #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.7.4