* Fixes NB#57580
[modest] / src / modest-tny-simple-folder-store.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30
31 #include <config.h>
32 #include <glib.h>
33 #include <glib/gi18n-lib.h>
34
35 #include <modest-tny-simple-folder-store.h>
36
37 static void
38 tny_folder_store_init (TnyFolderStoreIface *klass);
39
40 G_DEFINE_TYPE_EXTENDED (ModestTnySimpleFolderStore, 
41         modest_tny_simple_folder_store, 
42         G_TYPE_OBJECT,
43         0,
44         G_IMPLEMENT_INTERFACE (TNY_TYPE_FOLDER_STORE, tny_folder_store_init));
45
46 #define TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE(o) \
47   (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_TNY_SIMPLE_FOLDER_STORE, ModestTnySimpleFolderStorePrivate))
48
49 typedef struct _ModestTnySimpleFolderStorePrivate ModestTnySimpleFolderStorePrivate;
50
51 struct _ModestTnySimpleFolderStorePrivate
52 {
53         GSList *list_folders;
54 };
55
56 static void
57 modest_tny_simple_folder_store_dispose (GObject *object)
58 {
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);
61 }
62
63 static void
64 modest_tny_simple_folder_store_finalize (GObject *object)
65 {
66   G_OBJECT_CLASS (modest_tny_simple_folder_store_parent_class)->finalize (object);
67   
68   ModestTnySimpleFolderStorePrivate *priv = 
69                 TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE (object);
70                 
71   GSList *iter = priv->list_folders;
72   while (iter)
73   {
74         TnyFolder *folder = (TnyFolder*)iter->data;
75         if (folder) {
76                 g_object_unref (folder);
77                 iter->data = NULL;
78         }
79                 
80         iter = g_slist_next (iter);
81   }
82
83   g_slist_free (priv->list_folders);
84   priv->list_folders = NULL;
85 }
86
87 static void
88 modest_tny_simple_folder_store_class_init (ModestTnySimpleFolderStoreClass *klass)
89 {
90   GObjectClass *object_class = G_OBJECT_CLASS (klass);
91
92   g_type_class_add_private (klass, sizeof (ModestTnySimpleFolderStorePrivate));
93
94   object_class->dispose = modest_tny_simple_folder_store_dispose;
95   object_class->finalize = modest_tny_simple_folder_store_finalize;
96 }
97
98 static void
99 modest_tny_simple_folder_store_init (ModestTnySimpleFolderStore *self)
100 {
101 }
102
103 ModestTnySimpleFolderStore*
104 modest_tny_simple_folder_store_new (void)
105 {
106   return g_object_new (MODEST_TYPE_TNY_SIMPLE_FOLDER_STORE, NULL);
107 }
108
109
110 static void
111 modest_tny_simple_folder_store_remove_folder (TnyFolderStore *self, TnyFolder *folder, GError **err)
112 {
113 }
114
115 static TnyFolder*
116 modest_tny_simple_folder_store_create_folder (TnyFolderStore *self, const gchar *name, GError **err)
117 {
118         return NULL;
119 }
120
121 static void
122 modest_tny_simple_folder_store_get_folders (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GError **err)
123 {
124   ModestTnySimpleFolderStorePrivate *priv = 
125                 TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE (self);
126                 
127   if (!list)
128     return;
129     
130   GSList *iter = priv->list_folders;
131   while (iter)
132   {
133         TnyFolder *folder = (TnyFolder*)iter->data;
134         if (folder) {
135                 tny_list_append (list, G_OBJECT (folder));
136         }
137                 
138         iter = g_slist_next (iter);
139   }
140   
141 }
142
143 static void
144 modest_tny_simple_folder_store_get_folders_async (TnyFolderStore *self, TnyList *list, TnyGetFoldersCallback callback, TnyFolderStoreQuery *query, TnyStatusCallback status_callback, gpointer user_data)
145 {
146 }
147
148 static void
149 modest_tny_simple_folder_store_add_observer (TnyFolderStore *self, TnyFolderStoreObserver *observer)
150 {
151 }
152
153 static void
154 modest_tny_simple_folder_store_remove_observer (TnyFolderStore *self, TnyFolderStoreObserver *observer)
155 {
156 }
157
158 static void
159 tny_folder_store_init (TnyFolderStoreIface *klass)
160 {
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;
167 }
168
169
170 void
171 modest_tny_simple_folder_store_add_folder (ModestTnySimpleFolderStore *store, 
172         TnyFolder *folder)
173 {
174         ModestTnySimpleFolderStorePrivate *priv = 
175                 TNY_SIMPLE_FOLDER_STORE_GET_PRIVATE (store);
176                 
177         /* Check that it isn't already in the list: */
178         GSList *exists = g_slist_find (priv->list_folders, folder);
179         if (exists)
180                 return;
181                 
182         /* Add it: */
183         /* The reference is released in finalize: */
184         priv->list_folders = g_slist_append (priv->list_folders, folder);
185         g_object_ref (folder);
186 }
187