1
/* libtinymail - The Tiny Mail base library
2
* Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with self library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
26
#include <tny-folder-store.h>
27
#include <tny-folder-store-observer.h>
32
* tny_folder_store_add_observer:
33
* @self: a #TnyFolder instance
34
* @observer: a #TnyFolderStoreObserver instance
36
* Add @observer to the list of interested observers for events that could happen
37
* caused by for example folder creates and deletions and other spontaneous
40
* After this, @observer will start receiving notification of changes about @self.
42
* You must use tny_folder_store_remove_observer, in for example the finalization
43
* of your type if you used this method. Adding an observer to @self, changes
44
* reference counting of the objects involved. Removing the observer will undo
45
* those reference counting changes. Therefore if you don't, you will introduce
50
tny_folder_store_add_observer (TnyFolderStore *self, TnyFolderStoreObserver *observer)
52
#ifdef DBC /* require */
53
g_assert (TNY_IS_FOLDER_STORE (self));
55
g_assert (TNY_IS_FOLDER_STORE_OBSERVER (observer));
56
g_assert (TNY_FOLDER_STORE_GET_IFACE (self)->add_observer_func != NULL);
59
TNY_FOLDER_STORE_GET_IFACE (self)->add_observer_func (self, observer);
61
#ifdef DBC /* ensure */
62
/* TNY TODO: Check whether it's really added */
70
* tny_folder_store_remove_observer:
71
* @self: a #TnyFolderStore instance
72
* @observer: a #TnyFolderStoreObserver instance
74
* Remove @observer from the list of interested observers for events that could
75
* happen caused by for example folder creates and deletions and other
76
* spontaneous changes.
78
* After this, @observer will no longer receive notification of changes about @self.
80
* You must use this method, in for example the finalization of your type
81
* if you used tny_folder_store_add_observer. Adding an observer to @self, changes
82
* reference counting of the objects involved. Removing the observer will undo
83
* those reference counting changes. Therefore if you don't, you will introduce
88
tny_folder_store_remove_observer (TnyFolderStore *self, TnyFolderStoreObserver *observer)
90
#ifdef DBC /* require */
91
g_assert (TNY_IS_FOLDER_STORE (self));
93
g_assert (TNY_IS_FOLDER_STORE_OBSERVER (observer));
94
g_assert (TNY_FOLDER_STORE_GET_IFACE (self)->remove_observer_func != NULL);
97
TNY_FOLDER_STORE_GET_IFACE (self)->remove_observer_func (self, observer);
99
#ifdef DBC /* ensure */
100
/* TNY TODO: Check whether it's really removed */
108
* tny_folder_store_remove_folder:
109
* @self: a #TnyFolderStore object
110
* @folder: The folder to remove
111
* @err: a #GError object or NULL
113
* Removes a folder represented by @folder from the folder store @self. You are
114
* responsible for unreferencing the @folder instance yourself. This method will
115
* not do this for you, leaving the @folder instance in an unusable state.
117
* All the #TnyFolderObservers and #TnyFolderStoreObservers of @folder, but of
118
* course not of @self, will automatically be unsubscribed.
120
* This method will always recursively delete all child folders of @self. While
121
* deleting folders, the folders will also always get unsubscribed (for example
122
* in case of IMAP, which means that the folder wont be in LSUB either anymore).
124
* Observers of @self and of any the child folders of @self will receive delete
125
* observer events in deletion order (childs first, parents after that). Types
126
* like the #TnyGtkFolderStoreListModel know about this and act on folder
127
* deletions by automatically updating themselves.
130
* <informalexample><programlisting>
132
* my_remove_a_folder (TnyFolderStore *store, TnyFolder *remfol, GError **err)
134
* tny_folder_store_remove_folder (store, remfol, err);
135
* g_object_unref (G_OBJECT (remfol));
137
* </programlisting></informalexample>
141
tny_folder_store_remove_folder (TnyFolderStore *self, TnyFolder *folder, GError **err)
143
#ifdef DBC /* require */
144
g_assert (TNY_IS_FOLDER_STORE (self));
146
g_assert (TNY_IS_FOLDER (folder));
147
g_assert (TNY_FOLDER_STORE_GET_IFACE (self)->remove_folder_func != NULL);
150
TNY_FOLDER_STORE_GET_IFACE (self)->remove_folder_func (self, folder, err);
152
#ifdef DBC /* ensure */
153
/* Checking this is something for a unit test */
160
* tny_folder_store_create_folder:
161
* @self: a #TnyFolderStore object
162
* @name: The folder name to create
163
* @err: a #GError object or NULL
165
* Creates a new folder in @self. If not NULL, the value returned is the newly
166
* created folder instance and must be unreferenced after use.
169
* <informalexample><programlisting>
170
* TnyFolderStore *store = ...
171
* TnyFolder *createfol;
172
* createfol = tny_folder_store_create_folder (store, "Test", NULL);
173
* if (createfol) g_object_unref (G_OBJECT (createfol));
174
* </programlisting></informalexample>
176
* Return value: A new folder instance representing the folder that was created
177
* or NULL in case of failure
181
tny_folder_store_create_folder (TnyFolderStore *self, const gchar *name, GError **err)
185
#ifdef DBC /* require */
186
g_assert (TNY_IS_FOLDER_STORE (self));
188
g_assert (strlen (name) > 0);
189
g_assert (TNY_FOLDER_STORE_GET_IFACE (self)->create_folder_func != NULL);
192
retval = TNY_FOLDER_STORE_GET_IFACE (self)->create_folder_func (self, name, err);
194
#ifdef DBC /* ensure */
196
g_assert (TNY_IS_FOLDER (retval));
203
* tny_folder_store_get_folders:
204
* @self: a #TnyFolderStore object
205
* @list: A #TnyList to fillup
206
* @query: A #TnyFolderStoreQuery object or NULL
207
* @err: a #GError object or NULL
209
* Get a list of child folders from @self. You can use @query to limit the list
210
* of folders with only folders that match a query or NULL if you don't want
211
* to limit the list at all.
214
* <informalexample><programlisting>
215
* TnyFolderStore *store = ...
216
* TnyIterator *iter; TnyFolderStoreQuery *query = ...
217
* TnyList *folders = tny_simple_list_new ();
218
* tny_folder_store_get_folders (store, folders, query, NULL);
219
* iter = tny_list_create_iterator (folders);
220
* while (!tny_iterator_is_done (iter))
222
* TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (iter));
223
* g_print ("%s\n", tny_folder_get_name (folder));
224
* g_object_unref (G_OBJECT (folder));
225
* tny_iterator_next (iter);
227
* g_object_unref (G_OBJECT (iter));
228
* g_object_unref (G_OBJECT (folders));
229
* </programlisting></informalexample>
232
tny_folder_store_get_folders (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GError **err)
234
#ifdef DBC /* require */
235
g_assert (TNY_IS_FOLDER_STORE (self));
237
g_assert (TNY_IS_LIST (list));
239
g_assert (TNY_IS_FOLDER_STORE_QUERY (query));
240
g_assert (TNY_FOLDER_STORE_GET_IFACE (self)->get_folders_func != NULL);
243
TNY_FOLDER_STORE_GET_IFACE (self)->get_folders_func (self, list, query, err);
245
#ifdef DBC /* ensure */
252
* tny_folder_store_get_folders_async:
253
* @self: a #TnyFolderStore object
254
* @list: A #TnyList to fillup
255
* @callback: The callback handler
256
* @query: A #TnyFolderStoreQuery object
257
* @user_data: user data for the callback
259
* Get a list of child folders from the folder store @self and call back when
260
* finished. You can use @query to limit the list of folders with only folders
261
* that match a query or NULL if you don't want to limit the list at all.
264
* <informalexample><programlisting>
266
* callback (TnyFolderStore *self, TnyList *list, GError **err, gpointer user_data)
268
* TnyIterator *iter = tny_list_create_iterator (list);
269
* while (!tny_iterator_is_done (iter))
271
* TnyFolderStore *folder = tny_iterator_get_current (iter);
272
* TnyList *folders = tny_simple_list_new ();
273
* g_print ("%s\n", tny_folder_get_name (TNY_FOLDER (folder)));
274
* tny_folder_store_get_folders_async (folder,
275
* folders, callback, NULL, NULL);
276
* g_object_unref (G_OBJECT (folder));
277
* tny_iterator_next (iter);
279
* g_object_unref (G_OBJECT (iter));
280
* g_object_unref (G_OBJECT (list));
283
* get_all_folders (TnyStoreAccount *account)
286
* folders = tny_simple_list_new ();
287
* tny_folder_store_get_folders_async (TNY_FOLDER_STORE (account),
288
* folders, callback, NULL, NULL);
290
* </programlisting></informalexample>
292
* If you want to use this functionality, you are advised to let your application
293
* use a #GMainLoop. All Gtk+ applications have this once gtk_main () is called.
295
* When using a #GMainLoop, this method will callback using g_idle_add_full.
296
* Without a #GMainLoop, which the libtinymail-camel implementations detect
297
* using (g_main_depth > 0), the callbacks will happen in a worker thread at an
298
* unknown moment in time (check your locking).
300
* When using Gtk+ the callback doesn't need gdk_threads_enter and
301
* gdk_threads_leave in Gtk+.
305
tny_folder_store_get_folders_async (TnyFolderStore *self, TnyList *list, TnyGetFoldersCallback callback, TnyFolderStoreQuery *query, TnyStatusCallback status_callback, gpointer user_data)
307
#ifdef DBC /* require */
308
g_assert (TNY_IS_FOLDER_STORE (self));
311
g_assert (TNY_IS_LIST (list));
313
g_assert (TNY_IS_FOLDER_STORE_QUERY (query));
314
g_assert (TNY_FOLDER_STORE_GET_IFACE (self)->get_folders_async_func != NULL);
317
TNY_FOLDER_STORE_GET_IFACE (self)->get_folders_async_func (self, list, callback, query, status_callback, user_data);
319
#ifdef DBC /* ensure */
328
tny_folder_store_base_init (gpointer g_class)
330
static gboolean initialized = FALSE;
333
/* create interface signals here. */
339
tny_folder_store_get_type (void)
341
static GType type = 0;
343
if (G_UNLIKELY(type == 0))
345
static const GTypeInfo info =
347
sizeof (TnyFolderStoreIface),
348
tny_folder_store_base_init, /* base_init */
349
NULL, /* base_finalize */
350
NULL, /* class_init */
351
NULL, /* class_finalize */
352
NULL, /* class_data */
355
NULL, /* instance_init */
358
type = g_type_register_static (G_TYPE_INTERFACE,
359
"TnyFolderStore", &info, 0);