1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <glib/gi18n-lib.h>
35 #include <modest-tny-simple-folder-store.h>
38 tny_folder_store_init (TnyFolderStoreIface *klass);
40 G_DEFINE_TYPE_EXTENDED (ModestTnySimpleFolderStore,
41 modest_tny_simple_folder_store,
44 G_IMPLEMENT_INTERFACE (TNY_TYPE_FOLDER_STORE, tny_folder_store_init));
46 #define TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE(o) \
47 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_TNY_SIMPLE_FOLDER_STORE, ModestTnySimpleFolderStorePrivate))
49 typedef struct _ModestTnySimpleFolderStorePrivate ModestTnySimpleFolderStorePrivate;
51 struct _ModestTnySimpleFolderStorePrivate
57 modest_tny_simple_folder_store_dispose (GObject *object)
59 if (G_OBJECT_CLASS (modest_tny_simple_folder_store_parent_class)->dispose)
60 G_OBJECT_CLASS (modest_tny_simple_folder_store_parent_class)->dispose (object);
64 modest_tny_simple_folder_store_finalize (GObject *object)
66 G_OBJECT_CLASS (modest_tny_simple_folder_store_parent_class)->finalize (object);
68 ModestTnySimpleFolderStorePrivate *priv =
69 TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE (object);
71 GSList *iter = priv->list_folders;
74 TnyFolder *folder = (TnyFolder*)iter->data;
76 g_object_unref (folder);
80 iter = g_slist_next (iter);
83 g_slist_free (priv->list_folders);
84 priv->list_folders = NULL;
88 modest_tny_simple_folder_store_class_init (ModestTnySimpleFolderStoreClass *klass)
90 GObjectClass *object_class = G_OBJECT_CLASS (klass);
92 g_type_class_add_private (klass, sizeof (ModestTnySimpleFolderStorePrivate));
94 object_class->dispose = modest_tny_simple_folder_store_dispose;
95 object_class->finalize = modest_tny_simple_folder_store_finalize;
99 modest_tny_simple_folder_store_init (ModestTnySimpleFolderStore *self)
103 ModestTnySimpleFolderStore*
104 modest_tny_simple_folder_store_new (void)
106 return g_object_new (MODEST_TYPE_TNY_SIMPLE_FOLDER_STORE, NULL);
111 modest_tny_simple_folder_store_remove_folder (TnyFolderStore *self, TnyFolder *folder, GError **err)
116 modest_tny_simple_folder_store_create_folder (TnyFolderStore *self, const gchar *name, GError **err)
122 modest_tny_simple_folder_store_get_folders (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GError **err)
124 ModestTnySimpleFolderStorePrivate *priv =
125 TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE (self);
130 GSList *iter = priv->list_folders;
133 TnyFolder *folder = (TnyFolder*)iter->data;
135 tny_list_append (list, G_OBJECT (folder));
138 iter = g_slist_next (iter);
144 modest_tny_simple_folder_store_get_folders_async (TnyFolderStore *self, TnyList *list, TnyGetFoldersCallback callback, TnyFolderStoreQuery *query, TnyStatusCallback status_callback, gpointer user_data)
149 modest_tny_simple_folder_store_add_observer (TnyFolderStore *self, TnyFolderStoreObserver *observer)
154 modest_tny_simple_folder_store_remove_observer (TnyFolderStore *self, TnyFolderStoreObserver *observer)
159 tny_folder_store_init (TnyFolderStoreIface *klass)
161 klass->remove_folder_func = modest_tny_simple_folder_store_remove_folder;
162 klass->create_folder_func = modest_tny_simple_folder_store_create_folder;
163 klass->get_folders_func = modest_tny_simple_folder_store_get_folders;
164 klass->get_folders_async_func = modest_tny_simple_folder_store_get_folders_async;
165 klass->add_observer_func = modest_tny_simple_folder_store_add_observer;
166 klass->remove_observer_func = modest_tny_simple_folder_store_remove_observer;
171 modest_tny_simple_folder_store_add_folder (ModestTnySimpleFolderStore *store,
174 ModestTnySimpleFolderStorePrivate *priv =
175 TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE (store);
177 /* Check that it isn't already in the list: */
178 GSList *exists = g_slist_find (priv->list_folders, folder);
183 /* The reference is released in finalize: */
184 priv->list_folders = g_slist_append (priv->list_folders, folder);
185 g_object_ref (folder);