From ab00ec05f653b2f10b7907f1655b707c937bfaea Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 29 Jan 2007 17:44:12 +0000 Subject: [PATCH] * modest-tny-account.[ch]: - new modest decorator for TnyAccount pmo-trunk-r757 --- src/modest-tny-account.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++ src/modest-tny-account.h | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 src/modest-tny-account.c create mode 100644 src/modest-tny-account.h diff --git a/src/modest-tny-account.c b/src/modest-tny-account.c new file mode 100644 index 0000000..15b79c9 --- /dev/null +++ b/src/modest-tny-account.c @@ -0,0 +1,82 @@ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + + +/* for now, ignore the account ===> the special folders are the same, + * local folders for all accounts + * this might change, ie, IMAP might have server-side sent-items + */ +TnyFolder * +modest_tny_account_get_special_folder (TnyAccount *account, + TnyFolderType special_type) +{ + TnyList *folders; + TnyIterator *iter; + TnyFolder *special_folder = NULL; + TnyAccount *local_account; + + g_return_val_if_fail (account, NULL); + g_return_val_if_fail (0 <= special_type && special_type < TNY_FOLDER_TYPE_NUM, + NULL); + + local_account = modest_tny_account_store_get_local_folders_account + (modest_runtime_get_account_store()); + if (!local_account) { + g_printerr ("modest: cannot get local account\n"); + return NULL; + } + + folders = TNY_LIST (tny_simple_list_new ()); + + /* no need to do this _async, as these are local folders */ + tny_folder_store_get_folders (TNY_FOLDER_STORE (account), + folders, NULL, NULL); + iter = tny_list_create_iterator (folders); + + while (!tny_iterator_is_done (iter)) { + TnyFolder *folder = + TNY_FOLDER (tny_iterator_get_current (iter)); + if (modest_tny_folder_get_local_folder_type (folder) == special_type) { + special_folder = folder; + break; + } + tny_iterator_next (iter); + } + g_object_unref (G_OBJECT (folders)); + g_object_unref (G_OBJECT (iter)); + + return special_folder; +} diff --git a/src/modest-tny-account.h b/src/modest-tny-account.h new file mode 100644 index 0000000..c60936f --- /dev/null +++ b/src/modest-tny-account.h @@ -0,0 +1,61 @@ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TnyAccount Decorator + */ + +#ifndef __MODEST_TNY_ACCOUNT_H__ +#define __MODEST_TNY_ACCOUNT_H__ + +#include +#include +#include + +G_BEGIN_DECLS + +/** + * modest_tny_account_get_special_folder + * @self: a TnyAccount + * @special_type: the special folder to get + * + * get the special (Inbox,Outbox,Sent,Draft etc.) folder for this account + * Note: currently, the implementation will always return a local folder for this. + * This can be changed later to return really account-specific special folders, + * such as (for example) server-side Sent/Junk mail for IMAP accounts + * + * Returns: the tny folder corresponding to this special folder, or NULL in case + * of error, or if the special folder does not exist for this account + */ +TnyFolder* modest_tny_account_get_special_folder (TnyAccount *self, + TnyFolderType special_type); + +G_END_DECLS + +#endif /* __MODEST_TNY_ACCOUNT_H__*/ -- 1.7.9.5