diff options
author | Dan Winship <danw@src.gnome.org> | 2001-05-04 04:52:59 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2001-05-04 04:52:59 +0800 |
commit | 7c553e6e5bb47c7b4b26f9bed147e7b7df234f96 (patch) | |
tree | 75b27df033aa84aa60eeea841fd8341ff6c415e4 /camel/camel-disco-folder.c | |
parent | 57546880c8e3470834bb7012aee9d892e3ac6708 (diff) | |
download | gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.gz gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.bz2 gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.lz gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.xz gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.tar.zst gsoc2013-evolution-7c553e6e5bb47c7b4b26f9bed147e7b7df234f96.zip |
new abstract class for disconnectable remote stores
* camel-disco-store.c: new abstract class for disconnectable
remote stores
* camel-disco-folder.c: new abstract class for folders on
disconnectable stores.
* Makefile.am: Add camel-disco-folder.[ch] and
camel-disco-store.[ch].
* providers/imap/camel-imap-store.c: Make this a subclass of
CamelDiscoStore, and fix up the offline interfaces for the changes
since they were first written (particularly the fact that some
IMAP stores don't just use subscribed folders).
* providers/imap/camel-imap-folder.c: Make this a subclass of
CamelDiscoFolder, although most ops still fail in disconnected
mode.
* camel-store.c (camel_store_get_folder_info): Change gboolean,
gboolean, gboolean to guint32 in the prototype for this function.
* providers/local/camel-local-store.c (get_folder_info): Update
for prototype change.
svn path=/trunk/; revision=9659
Diffstat (limited to 'camel/camel-disco-folder.c')
-rw-r--r-- | camel/camel-disco-folder.c | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/camel/camel-disco-folder.c b/camel/camel-disco-folder.c new file mode 100644 index 0000000000..bce6eaef06 --- /dev/null +++ b/camel/camel-disco-folder.c @@ -0,0 +1,243 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* camel-disco-folder.c: abstract class for a disconnectable folder */ + +/* + * Authors: Dan Winship <danw@ximian.com> + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "camel-disco-diary.h" +#include "camel-disco-folder.h" +#include "camel-disco-store.h" +#include "camel-exception.h" + +#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (o))) +#define CDF_CLASS(o) (CAMEL_DISCO_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS (o))) + +static CamelFolderClass *parent_class = NULL; + +static void disco_refresh_info (CamelFolder *folder, CamelException *ex); +static void disco_sync (CamelFolder *folder, gboolean expunge, CamelException *ex); +static void disco_expunge (CamelFolder *folder, CamelException *ex); + +static void disco_append_message (CamelFolder *folder, CamelMimeMessage *message, + const CamelMessageInfo *info, CamelException *ex); +static void disco_copy_messages_to (CamelFolder *source, GPtrArray *uids, + CamelFolder *destination, CamelException *ex); +static void disco_move_messages_to (CamelFolder *source, GPtrArray *uids, + CamelFolder *destination, CamelException *ex); + + +static void +camel_disco_folder_class_init (CamelDiscoFolderClass *camel_disco_folder_class) +{ + CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_disco_folder_class); + + parent_class = CAMEL_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_folder_get_type ())); + + /* virtual method overload */ + camel_folder_class->refresh_info = disco_refresh_info; + camel_folder_class->sync = disco_sync; + camel_folder_class->expunge = disco_expunge; + + camel_folder_class->append_message = disco_append_message; + camel_folder_class->copy_messages_to = disco_copy_messages_to; + camel_folder_class->move_messages_to = disco_move_messages_to; +} + +CamelType +camel_disco_folder_get_type (void) +{ + static CamelType camel_disco_folder_type = CAMEL_INVALID_TYPE; + + if (camel_disco_folder_type == CAMEL_INVALID_TYPE) { + camel_disco_folder_type = camel_type_register ( + CAMEL_FOLDER_TYPE, "CamelDiscoFolder", + sizeof (CamelDiscoFolder), + sizeof (CamelDiscoFolderClass), + (CamelObjectClassInitFunc) camel_disco_folder_class_init, + NULL, NULL, NULL); + } + + return camel_disco_folder_type; +} + + +static void +disco_refresh_info (CamelFolder *folder, CamelException *ex) +{ + if (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store)) != CAMEL_DISCO_STORE_ONLINE) + return; + CDF_CLASS (folder)->refresh_info_online (folder, ex); +} + +static void +disco_sync (CamelFolder *folder, gboolean expunge, CamelException *ex) +{ + if (expunge) { + disco_expunge (folder, ex); + if (camel_exception_is_set (ex)) + return; + } + + switch (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store))) { + case CAMEL_DISCO_STORE_ONLINE: + CDF_CLASS (folder)->sync_online (folder, ex); + break; + + case CAMEL_DISCO_STORE_OFFLINE: + CDF_CLASS (folder)->sync_offline (folder, ex); + break; + } +} + +static void +disco_expunge_uids (CamelFolder *folder, GPtrArray *uids, CamelException *ex) +{ + CamelDiscoStore *disco = CAMEL_DISCO_STORE (folder->parent_store); + + if (uids->len == 0) + return; + + switch (camel_disco_store_status (disco)) { + case CAMEL_DISCO_STORE_ONLINE: + CDF_CLASS (folder)->expunge_uids_online (folder, uids, ex); + break; + + case CAMEL_DISCO_STORE_OFFLINE: + CDF_CLASS (folder)->expunge_uids_offline (folder, uids, ex); +#ifdef NOTYET + if (!camel_exception_is_set (ex)) + camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_EXPUNGE, folder, uids); +#endif + break; + } +} + +static void +disco_expunge (CamelFolder *folder, CamelException *ex) +{ + GPtrArray *uids; + int i, count; + CamelMessageInfo *info; + + uids = g_ptr_array_new (); + count = camel_folder_summary_count (folder->summary); + for (i = 0; i < count; i++) { + info = camel_folder_summary_index (folder->summary, i); + if (info->flags & CAMEL_MESSAGE_DELETED) + g_ptr_array_add (uids, g_strdup (camel_message_info_uid (info))); + camel_folder_summary_info_free (folder->summary, info); + } + + disco_expunge_uids (folder, uids, ex); + + for (i = 0; i < uids->len; i++) + g_free (uids->pdata[i]); + g_ptr_array_free (uids, TRUE); +} + +static void +disco_append_message (CamelFolder *folder, CamelMimeMessage *message, + const CamelMessageInfo *info, CamelException *ex) +{ + CamelDiscoStore *disco = CAMEL_DISCO_STORE (folder->parent_store); + char *uid; + + switch (camel_disco_store_status (disco)) { + case CAMEL_DISCO_STORE_ONLINE: + uid = CDF_CLASS (folder)->append_online (folder, message, info, ex); + break; + + case CAMEL_DISCO_STORE_OFFLINE: + uid = CDF_CLASS (folder)->append_offline (folder, message, info, ex); +#ifdef NOTYET + if (uid) + camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_APPEND, folder, uid); +#endif + break; + } + g_free (uid); +} + +static void +disco_copy_messages_to (CamelFolder *source, GPtrArray *uids, + CamelFolder *destination, CamelException *ex) +{ + CamelDiscoStore *disco = CAMEL_DISCO_STORE (source->parent_store); + + switch (camel_disco_store_status (disco)) { + case CAMEL_DISCO_STORE_ONLINE: + CDF_CLASS (source)->copy_online (source, uids, destination, ex); + break; + + case CAMEL_DISCO_STORE_OFFLINE: + CDF_CLASS (source)->copy_offline (source, uids, destination, ex); +#ifdef NOTYET + if (!camel_exception_is_set (ex)) + camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_COPY, source, destination, uids); +#endif + break; + } +} + +static void +disco_move_messages_to (CamelFolder *source, GPtrArray *uids, + CamelFolder *destination, CamelException *ex) +{ + CamelDiscoStore *disco = CAMEL_DISCO_STORE (source->parent_store); + + switch (camel_disco_store_status (disco)) { + case CAMEL_DISCO_STORE_ONLINE: + CDF_CLASS (source)->move_online (source, uids, destination, ex); + break; + + case CAMEL_DISCO_STORE_OFFLINE: + CDF_CLASS (source)->move_offline (source, uids, destination, ex); +#ifdef NOTYET + if (!camel_exception_is_set (ex)) + camel_disco_diary_log (disco->diary, CAMEL_DISCO_DIARY_FOLDER_MOVE, source, destination, uids); +#endif + break; + } +} + + +/** + * camel_disco_folder_expunge_uids: + * @folder: a (disconnectable) folder + * @uids: array of UIDs to expunge + * @ex: a CamelException + * + * This expunges the messages in @uids from @folder. It should take + * whatever steps are needed to avoid expunging any other messages, + * although in some cases it may not be possible to avoid expunging + * messages that are marked deleted by another client at the same time + * as the expunge_uids call is running. + **/ +void +camel_disco_folder_expunge_uids (CamelFolder *folder, GPtrArray *uids, + CamelException *ex) +{ + disco_expunge_uids (folder, uids, ex); +} |