From dc1f5dfb2613864772791678184fa7b12aa20706 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Thu, 18 Aug 2005 04:36:34 +0000 Subject: ** See #312668. 2005-08-16 Not Zed ** See #312668. * mail-component.c (impl_setLineStatus): new offline interface. (setline_check, setline_done): and implementation. * mail-offline-handler.[ch]: destroyed, burnt, dissolved in acid. svn path=/trunk/; revision=30155 --- mail/ChangeLog | 9 ++ mail/Makefile.am | 2 - mail/mail-component.c | 75 +++++++++++- mail/mail-offline-handler.c | 273 -------------------------------------------- mail/mail-offline-handler.h | 65 ----------- 5 files changed, 79 insertions(+), 345 deletions(-) delete mode 100644 mail/mail-offline-handler.c delete mode 100644 mail/mail-offline-handler.h diff --git a/mail/ChangeLog b/mail/ChangeLog index 88c11c9999..3e54b80d59 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,12 @@ +2005-08-16 Not Zed + + ** See #312668. + + * mail-component.c (impl_setLineStatus): new offline interface. + (setline_check, setline_done): and implementation. + + * mail-offline-handler.[ch]: destroyed, burnt, dissolved in acid. + 2005-08-17 Srinivasa Ragavan * em-format-html-display.c diff --git a/mail/Makefile.am b/mail/Makefile.am index ec6347c416..a086afd211 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -189,8 +189,6 @@ libevolution_mail_la_SOURCES = \ mail-folder-cache.c \ mail-folder-cache.h \ mail-mt.c \ - mail-offline-handler.c \ - mail-offline-handler.h \ mail-ops.c \ mail-send-recv.c \ mail-send-recv.h \ diff --git a/mail/mail-component.c b/mail/mail-component.c index e6a1c4fe69..15ddb760e2 100644 --- a/mail/mail-component.c +++ b/mail/mail-component.c @@ -59,7 +59,6 @@ #include "mail-tools.h" #include "mail-send-recv.h" #include "mail-session.h" -#include "mail-offline-handler.h" #include "message-list.h" #include "e-activity-handler.h" @@ -79,6 +78,8 @@ #include #include +#include +#include #include #include @@ -923,6 +924,73 @@ impl_upgradeFromVersion (PortableServer_Servant servant, const short major, cons camel_exception_clear (&ex); } +struct _setline_data { + GNOME_Evolution_Listener listener; + CORBA_boolean status; + int pending; +}; + +static void +setline_done(CamelStore *store, void *data) +{ + struct _setline_data *sd = data; + + g_assert(sd->pending > 0); + + sd->pending--; + if (sd->pending == 0) { + CORBA_Environment ev = { 0 }; + + GNOME_Evolution_Listener_complete(sd->listener, &ev); + CORBA_exception_free(&ev); + CORBA_Object_release(sd->listener, &ev); + CORBA_exception_free(&ev); + g_free(sd); + } +} + +static void +setline_check(void *key, void *value, void *data) +{ + CamelService *service = key; + struct _setline_data *sd = data; + + if (CAMEL_IS_DISCO_STORE(service) + || CAMEL_IS_OFFLINE_STORE(service)) { + sd->pending++; + mail_store_set_offline((CamelStore *)service, !sd->status, setline_done, sd); + } +} + +static void +impl_setLineStatus(PortableServer_Servant servant, CORBA_boolean status, GNOME_Evolution_Listener listener, CORBA_Environment *ev) +{ + struct _setline_data *sd; + + /* This will dis/enable further auto-mail-check action. */ + /* FIXME: If send/receive active, wait for it to finish? */ + camel_session_set_online(session, status); + + sd = g_malloc0(sizeof(*sd)); + sd->status = status; + sd->listener = CORBA_Object_duplicate(listener, ev); + if (ev->_major == CORBA_NO_EXCEPTION) + mail_component_stores_foreach(mail_component_peek(), setline_check, sd); + else + CORBA_exception_free(ev); + + if (sd->pending == 0) { + if (sd->listener) { + CORBA_Object_release(sd->listener, ev); + CORBA_exception_free(ev); + } + + g_free(sd); + + GNOME_Evolution_Listener_complete(listener, ev); + } +} + static void impl_mail_test(PortableServer_Servant servant, CORBA_Environment *ev) { @@ -951,6 +1019,7 @@ mail_component_class_init (MailComponentClass *class) epv->handleURI = impl_handleURI; epv->sendAndReceive = impl_sendAndReceive; epv->upgradeFromVersion = impl_upgradeFromVersion; + epv->setLineStatus = impl_setLineStatus; mepv->test = impl_mail_test; } @@ -959,7 +1028,6 @@ static void mail_component_init (MailComponent *component) { MailComponentPrivate *priv; - MailOfflineHandler *offline; priv = g_new0 (MailComponentPrivate, 1); component->priv = priv; @@ -980,9 +1048,6 @@ mail_component_init (MailComponent *component) priv->store_hash = g_hash_table_new (NULL, NULL); mail_autoreceive_init(); - - offline = mail_offline_handler_new(); - bonobo_object_add_interface((BonoboObject *)component, (BonoboObject *)offline); } /* Public API. */ diff --git a/mail/mail-offline-handler.c b/mail/mail-offline-handler.c deleted file mode 100644 index 3095124ad1..0000000000 --- a/mail/mail-offline-handler.c +++ /dev/null @@ -1,273 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* mail-offline-handler.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Authors: - * Ettore Perazzoli - * Dan Winship - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "mail-offline-handler.h" -#include "mail-component.h" -#include "mail-ops.h" -#include "mail-folder-cache.h" -#include "em-folder-tree.h" - -#include -#include -#include "mail-session.h" - -#include - -#include - - -#define PARENT_TYPE bonobo_object_get_type () -static BonoboObjectClass *parent_class = NULL; - -struct _MailOfflineHandlerPrivate { - GHashTable *sync_table; -}; - -static gboolean -service_is_relevant (CamelService *service, gboolean going_offline) -{ - if (!(service->provider->flags & CAMEL_PROVIDER_IS_REMOTE)) - return FALSE; - - if (CAMEL_IS_DISCO_STORE (service) && - camel_disco_store_status (CAMEL_DISCO_STORE (service)) == CAMEL_DISCO_STORE_OFFLINE) - return !going_offline; - else if ( CAMEL_IS_OFFLINE_STORE (service) && - CAMEL_OFFLINE_STORE ( service )->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL ) - return !going_offline; - return service->status != CAMEL_SERVICE_DISCONNECTED; -} - -static void -add_connection (gpointer key, gpointer value, gpointer user_data) -{ - CamelService *service = key; - GNOME_Evolution_ConnectionList *list = user_data; - - if (!service_is_relevant (service, TRUE)) - return; - - list->_buffer[list->_length].hostName = CORBA_string_dup (service->url->host); - list->_buffer[list->_length].type = CORBA_string_dup (service->provider->name); - list->_length++; -} - -static GNOME_Evolution_ConnectionList * -create_connection_list (void) -{ - GNOME_Evolution_ConnectionList *list; - - list = GNOME_Evolution_ConnectionList__alloc (); - list->_length = 0; - list->_maximum = mail_component_get_store_count (mail_component_peek ()); - list->_buffer = CORBA_sequence_GNOME_Evolution_Connection_allocbuf (list->_maximum); - - mail_component_stores_foreach (mail_component_peek (), add_connection, list); - - return list; -} - -/* GNOME::Evolution::Offline methods. */ - -static CORBA_boolean -impl__get_isOffline (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - return !camel_session_is_online (session); -} - -static void -impl_prepareForOffline (PortableServer_Servant servant, - GNOME_Evolution_ConnectionList **active_connection_list, - CORBA_Environment *ev) -{ - MailOfflineHandler *offline_handler; - MailOfflineHandlerPrivate *priv; - - offline_handler = MAIL_OFFLINE_HANDLER (bonobo_object_from_servant (servant)); - priv = offline_handler->priv; - - *active_connection_list = create_connection_list (); -} - -/* keep track of each sync in progress */ -struct _sync_info { - char *uri; /* uri of folder being synced */ - CamelOperation *cancel; /* progress report/cancellation object */ - int pc; /* percent complete (0-100) */ - int lastpc; /* last percent reported, so we dont overreport */ - int id; /* timeout id */ - GHashTable *table; /* the hashtable that we're registered in */ -}; - -static void -went_offline (CamelStore *store, void *data) -{ - CORBA_Environment ev; - GNOME_Evolution_ConnectionList *connection_list; - GNOME_Evolution_OfflineProgressListener listener = data; - - connection_list = create_connection_list (); - - CORBA_exception_init (&ev); - GNOME_Evolution_OfflineProgressListener_updateProgress(listener, connection_list, &ev); - if (ev._major != CORBA_NO_EXCEPTION) - g_warning ("Error updating offline progress"); - CORBA_Object_release(listener, &ev); - - CORBA_exception_free (&ev); - CORBA_free (connection_list); -} - -static void -store_go_offline (gpointer key, gpointer value, gpointer data) -{ - CamelStore *store = key; - GNOME_Evolution_OfflineProgressListener listener = data; - CORBA_Environment ev; - - CORBA_exception_init(&ev); - if (service_is_relevant (CAMEL_SERVICE (store), TRUE)) { - mail_store_set_offline (store, TRUE, went_offline, CORBA_Object_duplicate(listener, &ev)); - } - CORBA_exception_free(&ev); -} - -static void -impl_goOffline (PortableServer_Servant servant, - const GNOME_Evolution_OfflineProgressListener progress_listener, - CORBA_Environment *ev) -{ - MailOfflineHandler *offline_handler; - - offline_handler = MAIL_OFFLINE_HANDLER (bonobo_object_from_servant (servant)); - - /* This will disable further auto-mail-check action. */ - camel_session_set_online (session, FALSE); - - /* FIXME: If send/receive active, wait for it to finish */ - - mail_component_stores_foreach (mail_component_peek (), store_go_offline, progress_listener); -} - -static void -store_went_online(CamelStore *store, void *data) -{ - char *name = data; - - em_folder_tree_model_add_store(mail_component_peek_tree_model(mail_component_peek()), store, name); - mail_note_store (store, NULL, NULL, NULL); - g_free(name); -} - -static void -store_go_online (gpointer key, gpointer value, gpointer data) -{ - CamelStore *store = key; - char *name = value; - - if (service_is_relevant (CAMEL_SERVICE (store), FALSE)) { - mail_store_set_offline (store, FALSE, store_went_online, g_strdup(name)); - } -} - -static void -impl_goOnline (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - MailOfflineHandler *offline_handler; - MailOfflineHandlerPrivate *priv; - - offline_handler = MAIL_OFFLINE_HANDLER (bonobo_object_from_servant (servant)); - priv = offline_handler->priv; - - /* Enable auto-mail-checking */ - camel_session_set_online (session, TRUE); - - mail_component_stores_foreach (mail_component_peek (), store_go_online, NULL); -} - -/* GObject methods. */ - -static void -impl_finalise (GObject *object) -{ - MailOfflineHandler *offline_handler; - MailOfflineHandlerPrivate *priv; - - offline_handler = MAIL_OFFLINE_HANDLER (object); - priv = offline_handler->priv; - g_hash_table_destroy(priv->sync_table); - g_free (priv); - - if (G_OBJECT_CLASS (parent_class)->finalize != NULL) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -/* GTK+ type initialization. */ - -static void -mail_offline_handler_class_init (MailOfflineHandlerClass *klass) -{ - GObjectClass *object_class; - POA_GNOME_Evolution_Offline__epv *epv; - - object_class = G_OBJECT_CLASS (klass); - object_class->finalize = impl_finalise; - - epv = & klass->epv; - epv->_get_isOffline = impl__get_isOffline; - epv->prepareForOffline = impl_prepareForOffline; - epv->goOffline = impl_goOffline; - epv->goOnline = impl_goOnline; - - parent_class = g_type_class_ref(PARENT_TYPE); -} - -static void -mail_offline_handler_init (MailOfflineHandler *offline_handler) -{ - MailOfflineHandlerPrivate *priv; - - priv = g_new (MailOfflineHandlerPrivate, 1); - priv->sync_table = g_hash_table_new(g_str_hash, g_str_equal); - - offline_handler->priv = priv; -} - -MailOfflineHandler * -mail_offline_handler_new (void) -{ - MailOfflineHandler *new; - - new = g_object_new(mail_offline_handler_get_type (), NULL); - - return new; -} - -BONOBO_TYPE_FUNC_FULL (MailOfflineHandler, GNOME_Evolution_Offline, PARENT_TYPE, mail_offline_handler); diff --git a/mail/mail-offline-handler.h b/mail/mail-offline-handler.h deleted file mode 100644 index 4e6a811d98..0000000000 --- a/mail/mail-offline-handler.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* mail-offline-handler.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifndef _MAIL_OFFLINE_HANDLER_H_ -#define _MAIL_OFFLINE_HANDLER_H_ - -#include -#include "Evolution.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define MAIL_TYPE_OFFLINE_HANDLER (mail_offline_handler_get_type ()) -#define MAIL_OFFLINE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAIL_TYPE_OFFLINE_HANDLER, MailOfflineHandler)) -#define MAIL_OFFLINE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAIL_TYPE_OFFLINE_HANDLER, MailOfflineHandlerClass)) -#define MAIL_IS_OFFLINE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAIL_TYPE_OFFLINE_HANDLER)) -#define MAIL_IS_OFFLINE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MAIL_TYPE_OFFLINE_HANDLER)) - - -typedef struct _MailOfflineHandler MailOfflineHandler; -typedef struct _MailOfflineHandlerPrivate MailOfflineHandlerPrivate; -typedef struct _MailOfflineHandlerClass MailOfflineHandlerClass; - -struct _MailOfflineHandler { - BonoboObject parent; - - MailOfflineHandlerPrivate *priv; -}; - -struct _MailOfflineHandlerClass { - BonoboObjectClass parent_class; - - POA_GNOME_Evolution_Offline__epv epv; -}; - - -GType mail_offline_handler_get_type (void); -MailOfflineHandler *mail_offline_handler_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _MAIL_OFFLINE_HANDLER_H_ */ -- cgit v1.2.3