Network Manager Support
authorShreyas Srinivasan <sshreyas@novell.com>
Thu, 22 Dec 2005 01:48:30 +0000 (01:48 +0000)
committerShreyas Srinivasan <shres@src.gnome.org>
Thu, 22 Dec 2005 01:48:30 +0000 (01:48 +0000)
2005-12-22  Shreyas Srinivasan  <sshreyas@novell.com>

* 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
camel/camel-disco-store.c
camel/camel-offline-store.c
camel/camel-session.c
camel/camel-session.h

index 26495c0..f64653f 100644 (file)
@@ -1,3 +1,20 @@
+2005-12-22  Shreyas Srinivasan  <sshreyas@novell.com>
+
+       * 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  <tml@novell.com>
 
        * camel-filter-driver.c: Use gstdio wrappers. Use
index 57babf4..2828179 100644 (file)
@@ -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;i<folders->len;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;i<folders->len;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;
index 3459311..a5865bd 100644 (file)
@@ -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;
 }
index 63c8202..69400ff 100644 (file)
@@ -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;
+}
index b5e0b6f..0d559a6 100644 (file)
@@ -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 */