Re: Offline mode



It still doesn't work. But this is a "after looking at
evolution/mail/*.c" improved version.

On Tue, 2006-06-13 at 16:41 +0200, Philip Van Hoof wrote:
> Is the disco an instance that is created once (and reused)? Or, when
> will this method happen?
> 
> 
> static void
> disco_construct (CamelService *service, CamelSession *session,
>                  CamelProvider *provider, CamelURL *url,
>                  CamelException *ex)
> {
>         CamelDiscoStore *disco = CAMEL_DISCO_STORE (service);
> 
>         CAMEL_SERVICE_CLASS (parent_class)->construct (service, session,
> 		 provider, url, ex);
>         if (camel_exception_is_set (ex))
>                 return;
>         disco->status = camel_session_is_online (session) ?
>                 CAMEL_DISCO_STORE_ONLINE : CAMEL_DISCO_STORE_OFFLINE;
> }
> 
> 
> I create my folder the first time when the session is offline. I
> recreate the same folder when the session becomes online. However, if
> the disco is reused .. this constructor will not happen and therefore
> will the disco stay offline (disco->status iif).
> 
> Correct?
> 
> On Tue, 2006-06-13 at 16:20 +0200, Philip Van Hoof wrote:
> > (gdb) break imap_get_message
> > Breakpoint 5 at 0xb57332db: file camel-imap-folder.c, line 2038.
> > (gdb) cont
> > Continuing.
> > [New Thread -1259193424 (LWP 13222)]
> > [Thread -1259193424 (zombie) exited]
> > 
> > Breakpoint 5, imap_get_message (folder=0x8350e68, uid=0x8396588 "2790",
> > ex=0x83333b8) at camel-imap-folder.c:2038
> > 2038            CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER
> > (folder);
> > (gdb) next
> > 2039            CamelImapStore *store = CAMEL_IMAP_STORE
> > (folder->parent_store);
> > (gdb)
> > 2045            mi = (CamelImapMessageInfo *)camel_folder_summary_uid
> > (folder->summary, uid);
> > (gdb) print store
> > $1 = (CamelImapStore *) 0x8334150
> > (gdb) next
> > 2046            if (mi == NULL) {
> > (gdb) print *store
> > $2 = {parent_object = {parent_object = {parent_object = {parent_object =
> > {klass = 0x8333ce8, magic = 2007188717, hooks = 0x83354b0,
> >           ref_count = 6, flags = 0, next = 0x0, prev = 0x0}, priv =
> > 0x83346b8, session = 0x831cef0, provider = 0xb57429a0,
> >         status = CAMEL_SERVICE_CONNECTED, connect_op = 0x0, url =
> > 0x83347e0}, priv = 0x8336200, folders = 0x8335270, flags = 11,
> >       mode = 3}, status = CAMEL_DISCO_STORE_OFFLINE, diary = 0x8334970},
> > istream = 0x0, ostream = 0x0, summary = 0x8334ef0,
> >   connected = 1, preauthed = 0, braindamaged = 0, renaming = 0,
> > nocustomappend = 0, tag_prefix = 66 'B', command = 0,
> >   current_folder = 0x0, server_level = IMAP_LEVEL_IMAP4REV1,
> > capabilities = 350, parameters = 0, namespace = 0x8336738 "INBOX",
> >   dir_sep = 46 '.', base_url = 0x8334838
> > "imap://spampvanhoofbe mail pvanhoof be",
> >   storage_path = 0x8336810
> > "/home/pvanhoof/.tinymail/mail/imap/spampvanhoofbe mail pvanhoof be",
> > authtypes = 0x0, refresh_stamp = 0}
> > (gdb) print *session
> > No symbol "session" in current context.
> > (gdb) print *store->session
> > There is no member named session.
> > (gdb) print store->session
> > There is no member named session.
> > (gdb) print store.session
> > There is no member named session.
> > (gdb) print *0x831cef0
> > $3 = 137481768
> > (gdb) print *(CamelSession*)0x831cef0
> > $4 = {parent_object = {klass = 0x831ce28, magic = 2007188717, hooks =
> > 0x0, ref_count = 3, flags = 0, next = 0x0, prev = 0x0},
> >   priv = 0x831d120, storage_path = 0x8332ae8
> > "/home/pvanhoof/.tinymail/mail", junk_plugin = 0x0, online = 1,
> > check_junk = 0,
> >   network_state = 1}
> > (gdb) print *store
> > $5 = {parent_object = {parent_object = {parent_object = {parent_object =
> > {klass = 0x8333ce8, magic = 2007188717, hooks = 0x83354b0,
> >           ref_count = 6, flags = 0, next = 0x0, prev = 0x0}, priv =
> > 0x83346b8, session = 0x831cef0, provider = 0xb57429a0,
> >         status = CAMEL_SERVICE_CONNECTED, connect_op = 0x0, url =
> > 0x83347e0}, priv = 0x8336200, folders = 0x8335270, flags = 11,
> >       mode = 3}, status = CAMEL_DISCO_STORE_OFFLINE, diary = 0x8334970},
> > istream = 0x0, ostream = 0x0, summary = 0x8334ef0,
> >   connected = 1, preauthed = 0, braindamaged = 0, renaming = 0,
> > nocustomappend = 0, tag_prefix = 66 'B', command = 0,
> >   current_folder = 0x0, server_level = IMAP_LEVEL_IMAP4REV1,
> > capabilities = 350, parameters = 0, namespace = 0x8336738 "INBOX",
> >   dir_sep = 46 '.', base_url = 0x8334838
> > "imap://spampvanhoofbe mail pvanhoof be",
> >   storage_path = 0x8336810
> > "/home/pvanhoof/.tinymail/mail/imap/spampvanhoofbe mail pvanhoof be",
> > authtypes = 0x0, refresh_stamp = 0}
> > (gdb) print *(CamelSession*)0x831cef0
> > $6 = {parent_object = {klass = 0x831ce28, magic = 2007188717, hooks =
> > 0x0, ref_count = 3, flags = 0, next = 0x0, prev = 0x0},
> >   priv = 0x831d120, storage_path = 0x8332ae8
> > "/home/pvanhoof/.tinymail/mail", junk_plugin = 0x0, online = 1,
> > check_junk = 0,
> >   network_state = 1}
> > (gdb) bt
> > #0  imap_get_message (folder=0x8350e68, uid=0x8396588 "2790",
> > ex=0x83333b8) at camel-imap-folder.c:2046
> > #1  0xb6e0fa93 in camel_folder_get_message (folder=0x8350e68,
> > uid=0x8396588 "2790", ex=0x8367b9c) at camel-folder.c:1070
> > #2  0xb71bbd6b in tny_msg_folder_get_message (self=0x8083640,
> > header=0x83bd460) at tny-msg-folder.c:661
> > #3  0xb71d3da2 in tny_msg_folder_iface_get_message (self=0x8083640,
> > header=0x8191a30) at tny-msg-folder-iface.c:196
> > #4  0x0804c29e in on_header_view_tree_selection_changed
> > (selection=0x8367b9c, user_data=0x8367b9c) at tny-summary-window.c:337
> > #5  0xb730d423 in IA__g_cclosure_marshal_VOID__VOID (closure=0x82655f0,
> > return_value=0x0, n_param_values=1, param_values=0xbf92f60c,
> >     invocation_hint=0xbf92f4fc, marshal_data=0x804c219) at gmarshal.c:77
> > #6  0xb730179f in IA__g_closure_invoke (closure=0x82655f0,
> > return_value=0x8367b9c, n_param_values=137788316,
> > param_values=0x8367b9c,
> >     invocation_hint=0x8367b9c) at gclosure.c:490
> > #7  0xb73102ea in signal_emit_unlocked_R (node=0x8267058, detail=0,
> > instance=0x80d4060, emission_return=0x0,
> >     instance_and_params=0xbf92f60c) at gsignal.c:2438
> > #8  0xb7311b19 in IA__g_signal_emit_valist (instance=0x80d4060,
> > signal_id=203, detail=0, var_args=<value optimized out>)
> >     at gsignal.c:2197
> > #9  0xb7311e89 in IA__g_signal_emit (instance=0x8367b9c,
> > signal_id=137788316, detail=137788316) at gsignal.c:2241
> > #10 0xb7860c57 in _gtk_tree_selection_internal_select_node ()
> > from /usr/lib/libgtk-x11-2.0.so.0
> > #11 0xb787307e in gtk_tree_view_scroll_to_cell ()
> > from /usr/lib/libgtk-x11-2.0.so.0
> > #12 0xb787b9ca in gtk_tree_view_set_model ()
> > from /usr/lib/libgtk-x11-2.0.so.0
> > #13 0xb77aa850 in _gtk_marshal_BOOLEAN__BOXED ()
> > from /usr/lib/libgtk-x11-2.0.so.0
> > #14 0xb730116f in g_type_class_meta_marshal (closure=0x80a93e0,
> > return_value=0x8367b9c, n_param_values=137788316,
> >     param_values=0xbf92fc2c, invocation_hint=0x8367b9c,
> > marshal_data=0x8367b9c) at gclosure.c:567
> > #15 0xb730179f in IA__g_closure_invoke (closure=0x80a93e0,
> > return_value=0x8367b9c, n_param_values=137788316,
> > param_values=0x8367b9c,
> >     invocation_hint=0x8367b9c) at gclosure.c:490
> > #16 0xb73109ce in signal_emit_unlocked_R (node=0x80a9818, detail=0,
> > instance=0x80c7b40, emission_return=0xbf92fdec,
> >     instance_and_params=0xbf92fc2c) at gsignal.c:2476
> > #17 0xb7311886 in IA__g_signal_emit_valist (instance=0x80c7b40,
> > signal_id=30, detail=0,
> >     var_args=0xbf92fe70 "\210�\222�(\0334\b {\f\b!�\210�@{\f\b�j\n\b")
> > at gsignal.c:2207
> > #18 0xb7311e89 in IA__g_signal_emit (instance=0x8367b9c,
> > signal_id=137788316, detail=137788316) at gsignal.c:2241
> > #19 0xb788cc4f in gtk_widget_activate ()
> > from /usr/lib/libgtk-x11-2.0.so.0
> > #20 0xb77a8fcd in gtk_propagate_event ()
> > from /usr/lib/libgtk-x11-2.0.so.0
> > #21 0xb77a93db in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
> > #22 0xb764cddc in _gdk_events_queue () from /usr/lib/libgdk-x11-2.0.so.0
> > #23 0xb71fa8c6 in IA__g_main_context_dispatch (context=0x80862c8) at
> > gmain.c:1916
> > #24 0xb71fd986 in g_main_context_iterate (context=0x80862c8, block=1,
> > dispatch=1, self=0x804e008) at gmain.c:2547
> > #25 0xb71fdca8 in IA__g_main_loop_run (loop=0x80e1448) at gmain.c:2751
> > #26 0xb77a86d5 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
> > #27 0x0804ad42 in main (argc=1, argv=0xbf930144) at tny-main.c:92
> > (gdb)
> -- 
> Philip Van Hoof, software developer at x-tend 
> home: me at pvanhoof dot be 
> gnome: pvanhoof at gnome dot org 
> work: vanhoof at x-tend dot be 
> http://www.pvanhoof.be - http://www.x-tend.be
-- 
Philip Van Hoof, software developer at x-tend 
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
work: vanhoof at x-tend dot be 
http://www.pvanhoof.be - http://www.x-tend.be
Index: tinymail/tny-summary-window.c
===================================================================
--- tinymail/tny-summary-window.c	(revision 503)
+++ tinymail/tny-summary-window.c	(working copy)
@@ -52,6 +52,10 @@
 #include <tny-summary-window-iface.h>
 #include <tny-account-store-view-iface.h>
 
+
+#define GO_ONLINE_TXT _("Go online")
+#define GO_OFFLINE_TXT _("Go offline")
+
 static GObjectClass *parent_class = NULL;
 
 
@@ -63,12 +67,12 @@
 	GtkTreeView *mailbox_view, *header_view;
 	TnyMsgViewIface *msg_view;
 	guint accounts_reloaded_signal;
-	GtkWidget *status, *progress;
+	GtkWidget *status, *progress, *online_button;
 	guint status_id;
 	gulong mailbox_select_sid;
 	GtkTreeSelection *mailbox_select;
 	GtkTreeIter last_mailbox_correct_select;
-	guint connchanged_signal;
+	guint connchanged_signal, online_button_signal;
 	TnyMsgFolderIface *last_folder;
 };
 
@@ -95,11 +99,11 @@
 	return;
 }
 
+static GtkTreeModel *empty_model;
+
 static void 
 reload_accounts (TnySummaryWindowPriv *priv)
 {
-	static GtkTreeModel *empty_model;
-
 	TnyAccountStoreIface *account_store = priv->account_store;
 	GtkTreeModel *sortable, *mailbox_model = GTK_TREE_MODEL (tny_account_tree_model_new ());
 	const GList* accounts;
@@ -107,7 +111,6 @@
 	if (G_UNLIKELY (!empty_model))
 		empty_model = GTK_TREE_MODEL (gtk_list_store_new 
 			(1, G_TYPE_STRING));
-
 	/* Clear the header_view by giving it an empty model */
 	set_header_view_model (GTK_TREE_VIEW (priv->header_view), empty_model);
 
@@ -140,21 +143,52 @@
 accounts_reloaded (TnyAccountStoreIface *store, gpointer user_data)
 {
 	TnySummaryWindowPriv *priv = user_data;
-
+	
 	reload_accounts (priv);
 	
 	return;
 }
 
+static void 
+online_button_toggled (GtkToggleButton *togglebutton, gpointer user_data)
+{
+	TnySummaryWindowIface *self = user_data;
+	TnySummaryWindowPriv *priv = TNY_SUMMARY_WINDOW_GET_PRIVATE (self);
+
+	if (priv->account_store)
+	{
+		const TnyDeviceIface *device = tny_account_store_iface_get_device (priv->account_store);
+
+		if (gtk_toggle_button_get_active (togglebutton))
+			tny_device_iface_force_online (device);
+		else
+			tny_device_iface_force_offline (device);
+	}
+}
+
 static void
 connection_changed (TnyDeviceIface *device, gboolean online, gpointer user_data)
 {
 	TnySummaryWindowIface *self = user_data;
+	TnySummaryWindowPriv *priv = TNY_SUMMARY_WINDOW_GET_PRIVATE (self);
 
 	if (online)
+	{
+		gtk_button_set_label  (GTK_BUTTON (priv->online_button), GO_OFFLINE_TXT);
+		g_signal_handler_block (G_OBJECT (priv->online_button), priv->online_button_signal);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->online_button), TRUE);
+		g_signal_handler_unblock (G_OBJECT (priv->online_button), priv->online_button_signal);
+
 		gtk_window_set_title (GTK_WINDOW (self), _("Tinymail - online"));
-	else
+	} else {
+
+		gtk_button_set_label  (GTK_BUTTON (priv->online_button), GO_ONLINE_TXT);
+		g_signal_handler_block (G_OBJECT (priv->online_button), priv->online_button_signal);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->online_button), FALSE);
+		g_signal_handler_unblock (G_OBJECT (priv->online_button), priv->online_button_signal);
+
 		gtk_window_set_title (GTK_WINDOW (self), _("Tinymail - offline"));
+	}
 
 	return;
 }
@@ -296,10 +330,8 @@
 					tny_msg_view_iface_set_msg (priv->msg_view, TNY_MSG_IFACE (msg));
 				else 
 				{
-					GtkTreeModel *rmodel = model;
-					if (GTK_IS_TREE_MODEL_SORT (model))
-						rmodel = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model));
-					tny_list_iface_remove (TNY_LIST_IFACE (rmodel), header);
+					/* Loading the message failed (service unavailable 
+					   or message deleted by an external device) */
 				}
 
 			}
@@ -527,8 +559,12 @@
 	GtkWidget *vpaned1;
 	GtkWidget *vbox;
 	
+	/* TODO: Persist application UI status (of the panes) */
 
-	/* TODO: Persist application UI status (of the panes) */
+	priv->online_button = gtk_toggle_button_new ();
+
+	priv->online_button_signal = g_signal_connect (G_OBJECT (priv->online_button), "toggled", 
+		G_CALLBACK (online_button_toggled), self);
 	priv->last_folder = NULL;
 	platfact = TNY_PLATFORM_FACTORY_IFACE 
 			(tny_platform_factory_get_instance ());
@@ -541,6 +577,9 @@
 	priv->status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->status), "default");
 
 	gtk_box_pack_start (GTK_BOX (priv->status), priv->progress, FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (priv->status), priv->online_button, FALSE, FALSE, 0);
+
+	gtk_widget_show (priv->online_button);
 	gtk_widget_show (priv->status);
 	gtk_widget_show (vbox);
 
Index: libtinymail-gnome-desktop/tny-account-store.c
===================================================================
--- libtinymail-gnome-desktop/tny-account-store.c	(revision 503)
+++ libtinymail-gnome-desktop/tny-account-store.c	(working copy)
@@ -747,6 +747,7 @@
 		tny_platform_factory_get_instance ());
 
 	priv->device = tny_platform_factory_iface_new_device (platfact);
+	//tny_device_iface_force_online (priv->device);
 	priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE_IFACE (self));
 
 	return self;
Index: libtinymail-gnome-desktop/tny-device.c
===================================================================
--- libtinymail-gnome-desktop/tny-device.c	(revision 503)
+++ libtinymail-gnome-desktop/tny-device.c	(working copy)
@@ -28,7 +28,63 @@
 
 #include "tny-device-priv.h"
 
+static void tny_device_on_online (TnyDeviceIface *self);
+static void tny_device_on_offline (TnyDeviceIface *self);
+static gboolean tny_device_is_online (TnyDeviceIface *self);
+
+
+static void 
+nm_callback (libnm_glib_ctx *nm_ctx, gpointer user_data)
+{
+	TnyDeviceIface *self = (TnyDeviceIface *)user_data;
+
+	if (tny_device_is_online (self))
+		tny_device_on_online (self);
+	else
+		tny_device_on_offline (self);
+
+	return;
+}
+
+static void 
+tny_device_reset (TnyDeviceIface *self)
+{
+	TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self);
+
+	priv->fset = FALSE;
+	priv->forced = FALSE;
+
+	nm_callback (priv->nm_ctx, self);
+}
+
+static void 
+tny_device_force_online (TnyDeviceIface *self)
+{
+	TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self);
+
+	priv->fset = TRUE;
+	priv->forced = TRUE;
+
+	nm_callback (priv->nm_ctx, self);
+
+	return;
+}
+
+
 static void
+tny_device_force_offline (TnyDeviceIface *self)
+{
+	TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self);
+
+	priv->fset = TRUE;
+	priv->forced = FALSE;
+
+	nm_callback (priv->nm_ctx, self);
+
+	return;
+}
+
+static void
 tny_device_on_online (TnyDeviceIface *self)
 {
 	g_signal_emit (self, tny_device_iface_signals [TNY_DEVICE_IFACE_CONNECTION_CHANGED], 0, TRUE);
@@ -48,48 +104,41 @@
 tny_device_is_online (TnyDeviceIface *self)
 {
 	TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self);
+	gboolean retval = priv->forced;
 
-	libnm_glib_state state = libnm_glib_get_network_state (priv->nm_ctx);
-	gboolean retval;
-
-	switch (state)
+	if (!priv->fset)
 	{
-		case LIBNM_NO_NETWORK_CONNECTION:
-		retval = FALSE;
-		break;
+		libnm_glib_state state = libnm_glib_get_network_state (priv->nm_ctx);
+		
+		switch (state)
+		{
+			case LIBNM_NO_NETWORK_CONNECTION:
+			retval = FALSE;
+			break;
 
-		case LIBNM_NO_DBUS:
-		case LIBNM_NO_NETWORKMANAGER:
-		case LIBNM_INVALID_CONTEXT:
-		g_print (_("Invalid network manager installation. Going to assume Online status\n"));
-		case LIBNM_ACTIVE_NETWORK_CONNECTION:
-		default:
-		retval = TRUE;
-		break;
+			case LIBNM_NO_DBUS:
+			case LIBNM_NO_NETWORKMANAGER:
+			case LIBNM_INVALID_CONTEXT:
+			g_print (_("Invalid network manager installation. Going to assume Online status\n"));
+			case LIBNM_ACTIVE_NETWORK_CONNECTION:
+			default:
+			retval = TRUE;
+			break;
+		}
 	}
 
 	return retval;
 }
 
-static void 
-nm_callback (libnm_glib_ctx *nm_ctx, gpointer user_data)
-{
-	TnyDeviceIface *self = (TnyDeviceIface *)user_data;
 
-	if (tny_device_is_online (self))
-		tny_device_on_online (self);
-	else
-		tny_device_on_offline (self);
-
-	return;
-}
-
 static void
 tny_device_instance_init (GTypeInstance *instance, gpointer g_class)
 {
 	TnyDevice *self = (TnyDevice *)instance;
 	TnyDevicePriv *priv = TNY_DEVICE_GET_PRIVATE (self);
 
+	priv->fset = FALSE;
+	priv->forced = FALSE;
 	priv->nm_ctx = libnm_glib_init ();
 	priv->callback_id = libnm_glib_register_callback 
 		(priv->nm_ctx, nm_callback, self, NULL);
@@ -135,6 +184,9 @@
 	TnyDeviceIfaceClass *klass = (TnyDeviceIfaceClass *)g_iface;
 
 	klass->is_online_func = tny_device_is_online;
+	klass->reset_func = tny_device_reset;
+	klass->force_offline_func = tny_device_force_offline;
+	klass->force_online_func = tny_device_force_online;
 
 	return;
 }
Index: libtinymail-gnome-desktop/tny-device-priv.h
===================================================================
--- libtinymail-gnome-desktop/tny-device-priv.h	(revision 503)
+++ libtinymail-gnome-desktop/tny-device-priv.h	(working copy)
@@ -26,6 +26,7 @@
 {
 	libnm_glib_ctx *nm_ctx;
 	guint callback_id;
+	gboolean forced, fset;
 };
 
 
Index: libtinymail-camel/tny-account-priv.h
===================================================================
--- libtinymail-camel/tny-account-priv.h	(revision 503)
+++ libtinymail-camel/tny-account-priv.h	(working copy)
@@ -42,11 +42,12 @@
 	gchar *name; GList *options;
 };
 
-const CamelService*  _tny_account_get_service    (TnyAccount *self);
-const gchar*         _tny_account_get_url_string (TnyAccount *self);
+const CamelService* _tny_account_get_service (TnyAccount *self);
+const gchar* _tny_account_get_url_string (TnyAccount *self);
+void _tny_account_set_online_status (TnyAccount *self, gboolean offline);
 
-void _tny_account_start_camel_operation          (TnyAccountIface *self, CamelOperationStatusFunc func, gpointer user_data, const gchar *what);
-void _tny_account_stop_camel_operation           (TnyAccountIface *self);
+void _tny_account_start_camel_operation (TnyAccountIface *self, CamelOperationStatusFunc func, gpointer user_data, const gchar *what);
+void _tny_account_stop_camel_operation (TnyAccountIface *self);
 
 #define TNY_ACCOUNT_GET_PRIVATE(o)	\
 	(G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_ACCOUNT, TnyAccountPriv))
Index: libtinymail-camel/tny-store-account.c
===================================================================
--- libtinymail-camel/tny-store-account.c	(revision 503)
+++ libtinymail-camel/tny-store-account.c	(working copy)
@@ -66,11 +66,47 @@
 	}
 }
 
+
+static void
+walk_folders_uncache_em (TnyStoreAccountIface *self, TnyListIface *folders)
+{
+  if (folders && tny_list_iface_length (folders) > 0)
+  {
+	TnyIteratorIface *iterator = tny_list_iface_create_iterator (folders);
+	gboolean next = TRUE;
+
+	while (next)
+	{
+		TnyMsgFolderIface *folder = tny_iterator_iface_current (iterator);
+		TnyListIface *more_folders = (TnyListIface*)tny_msg_folder_iface_get_folders (folder);
+
+		tny_msg_folder_iface_uncache (folder);
+
+		if (tny_list_iface_length (more_folders) > 0)
+			walk_folders_uncache_em (self, more_folders);
+
+		next = tny_iterator_iface_has_next (iterator);
+
+		if (next)
+			tny_iterator_iface_next (iterator);
+	}
+
+	g_object_unref (G_OBJECT (iterator));
+  }
+}
+
 static void 
 tny_store_account_reconnect (TnyAccount *self)
 {
 	TnyAccountPriv *priv = TNY_ACCOUNT_GET_PRIVATE (self);
+	TnyStoreAccountPriv *spriv = TNY_STORE_ACCOUNT_GET_PRIVATE (self);
 
+	if (spriv->folders)
+		walk_folders_uncache_em (TNY_STORE_ACCOUNT_IFACE (self), spriv->folders);
+
+	if (spriv->ufolders)
+		walk_folders_uncache_em (TNY_STORE_ACCOUNT_IFACE (self), spriv->ufolders);
+
 	if (G_LIKELY (priv->session) && G_UNLIKELY (priv->proto) && 
 		G_UNLIKELY (priv->user) && G_UNLIKELY (priv->host))
 	{
@@ -124,8 +160,8 @@
 		}
 		if (G_UNLIKELY (priv->service))
 			camel_object_unref (CAMEL_OBJECT (priv->service));
-	
-		priv->service = camel_session_get_service 
+
+		priv->service = camel_session_get_service
 			(CAMEL_SESSION (priv->session), priv->url_string, 
 			priv->type, priv->ex);
 
@@ -135,9 +171,11 @@
 	if (G_LIKELY (priv->session) && (priv->url_string))
 	{
 		/* un officially supported provider */
-		priv->service = camel_session_get_service 
+
+		priv->service = camel_session_get_service
 			(CAMEL_SESSION (priv->session), priv->url_string, 
 			priv->type, priv->ex);
+
 		if (priv->service == NULL)
 			report_error (priv);
 	}
@@ -150,20 +188,17 @@
 		&& G_UNLIKELY (priv->host))
 	{
 		priv->connected = FALSE;
-		camel_service_connect (priv->service, priv->ex);
 
-		if (camel_exception_is_set (priv->ex))
+		if (!camel_service_connect (priv->service, priv->ex))
 		{
 			g_warning (_("Not connected with %s: %s\n"), priv->url_string,
 				   camel_exception_get_description (priv->ex));
 			camel_exception_clear (priv->ex);
-			camel_service_cancel_connect (priv->service);
-			camel_service_disconnect (priv->service, FALSE, priv->ex);
+			/* camel_service_cancel_connect (priv->service);
+			camel_service_disconnect (priv->service, FALSE, priv->ex); */
 		} else {
 			priv->connected = TRUE;
 		}
-		
-		camel_session_set_online (CAMEL_SESSION (priv->session), priv->connected);
 	}
 
 	return;
Index: libtinymail-camel/tny-account.c
===================================================================
--- libtinymail-camel/tny-account.c	(revision 503)
+++ libtinymail-camel/tny-account.c	(working copy)
@@ -35,6 +35,10 @@
 #include <camel/camel.h>
 #include <camel/camel-session.h>
 #include <camel/camel-store.h>
+#include <camel/camel-offline-folder.h>
+#include <camel/camel-offline-store.h>
+#include <camel/camel-disco-folder.h>
+#include <camel/camel-disco-store.h>
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -471,7 +475,52 @@
 	g_object_unref (G_OBJECT (data));
 }
 
+void 
+_tny_account_set_online_status (TnyAccount *self, gboolean offline)
+{
+	TnyAccountPriv *priv = TNY_ACCOUNT_GET_PRIVATE (self);
 
+	if (!priv->service)
+		return;
+
+
+	if (offline)
+		camel_service_cancel_connect (priv->service);
+
+        if (CAMEL_IS_DISCO_STORE (priv->service)) {
+                if (!offline) {
+                        camel_disco_store_set_status (CAMEL_DISCO_STORE (priv->service),
+                                                      CAMEL_DISCO_STORE_ONLINE, priv->ex);
+                        return;
+                } else if (camel_disco_store_can_work_offline (CAMEL_DISCO_STORE (priv->service))) {
+
+                        camel_disco_store_set_status (CAMEL_DISCO_STORE (priv->service),
+                                                      CAMEL_DISCO_STORE_OFFLINE,
+                                                      priv->ex);
+                        return;
+                }
+        } else if (CAMEL_IS_OFFLINE_STORE (priv->service)) {
+
+                if (!offline) {
+
+                        camel_offline_store_set_network_state (CAMEL_OFFLINE_STORE (priv->service),
+                                                               CAMEL_OFFLINE_STORE_NETWORK_AVAIL,
+                                                               priv->ex);
+                        return;
+                } else {
+                        camel_offline_store_set_network_state (CAMEL_OFFLINE_STORE (priv->service),
+                                                               CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL,
+                                                               priv->ex);
+                        return;
+                }
+        }
+
+        if (offline)
+                camel_service_disconnect (CAMEL_SERVICE (priv->service),
+                                          TRUE, priv->ex);
+}
+
+
 static void
 tny_account_finalize (GObject *object)
 {
Index: libtinymail-camel/tny-session-camel.c
===================================================================
--- libtinymail-camel/tny-session-camel.c	(revision 503)
+++ libtinymail-camel/tny-session-camel.c	(working copy)
@@ -437,6 +437,8 @@
 static void
 tny_session_camel_init (TnySessionCamel *instance)
 {
+	/* Avoid the first question in connection_changed */
+	instance->prev_constat = TRUE;
 	instance->device = NULL;
 }
 
@@ -444,9 +446,27 @@
 connection_changed (TnyDeviceIface *device, gboolean online, gpointer user_data)
 {
 	TnySessionCamel *self = user_data;
+	
+	if (self->account_store)
+	{
+		GList *copy;
 
+		copy = (GList*) tny_account_store_iface_get_store_accounts (self->account_store);;
+	
+		while (G_LIKELY (copy))
+		{
+			TnyStoreAccountIface *account = copy->data;
+
+			_tny_account_set_online_status (account, !online);
+
+			copy = g_list_next (copy);
+		}
+	}
+
 	camel_session_set_online ((CamelSession *) self, online); 
 
+	self->prev_constat = online;
+
 	return;
 }
 
Index: libtinymail-camel/tny-session-camel.h
===================================================================
--- libtinymail-camel/tny-session-camel.h	(revision 503)
+++ libtinymail-camel/tny-session-camel.h	(working copy)
@@ -38,7 +38,7 @@
 
 	gpointer device;
 	gpointer account_store;
-        gboolean interactive;
+        gboolean interactive, prev_constat;
 	guint connchanged_signal;
 };
 
Index: libtinymail/tny-device-iface.c
===================================================================
--- libtinymail/tny-device-iface.c	(revision 503)
+++ libtinymail/tny-device-iface.c	(working copy)
@@ -33,6 +33,45 @@
 
 
 /**
+ * tny_device_iface_reset:
+ * @self: a #TnyDeviceIface object
+ * 
+ * Reset status
+ **/
+void 
+tny_device_iface_reset (TnyDeviceIface *self)
+{
+	TNY_DEVICE_IFACE_GET_CLASS (self)->reset_func (self);
+	return;
+}
+
+/**
+ * tny_device_iface_force_offline:
+ * @self: a #TnyDeviceIface object
+ * 
+ * Force offline status
+ **/
+void 
+tny_device_iface_force_online (TnyDeviceIface *self)
+{
+	TNY_DEVICE_IFACE_GET_CLASS (self)->force_online_func (self);
+	return;
+}
+
+/**
+ * tny_device_iface_force_online:
+ * @self: a #TnyDeviceIface object
+ * 
+ * Force online status
+ **/
+void
+tny_device_iface_force_offline (TnyDeviceIface *self)
+{
+	TNY_DEVICE_IFACE_GET_CLASS (self)->force_offline_func (self);
+	return;
+}
+
+/**
  * tny_device_iface_is_online:
  * @self: a #TnyDeviceIface object
  * 
Index: libtinymail/tny-device-iface.h
===================================================================
--- libtinymail/tny-device-iface.h	(revision 503)
+++ libtinymail/tny-device-iface.h	(working copy)
@@ -47,16 +47,22 @@
 {
 	GTypeInterface parent;
 
-	gboolean (*is_online_func)  (TnyDeviceIface *self);
+	gboolean (*is_online_func) (TnyDeviceIface *self);
 
+	void (*force_online_func) (TnyDeviceIface *self);
+	void (*force_offline_func) (TnyDeviceIface *self);
+	void (*reset_func) (TnyDeviceIface *self);
+
 	/* Signals */
-	void (*connection_changed)  (TnyDeviceIface *self, gboolean online);
+	void (*connection_changed) (TnyDeviceIface *self, gboolean online);
 
 };
 
 GType tny_device_iface_get_type (void);
 
 gboolean tny_device_iface_is_online (TnyDeviceIface *self);
+void tny_device_iface_force_online (TnyDeviceIface *self);
+void tny_device_iface_force_offline (TnyDeviceIface *self);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]