| 1 |
/* tinymail - Tiny Mail |
| 2 |
* Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org> |
| 3 |
* |
| 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. |
| 8 |
* |
| 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. |
| 13 |
* |
| 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., 51 Franklin Street, Fifth Floor, |
| 17 |
* Boston, MA 02110-1301, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <gtk/gtk.h> |
| 22 |
#include <tny-shared.h> |
| 23 |
#include <tny-list.h> |
| 24 |
#include <tny-iterator.h> |
| 25 |
#include <tny-simple-list.h> |
| 26 |
#include <tny-account-store.h> |
| 27 |
#include <tny-store-account.h> |
| 28 |
#include <tny-folder.h> |
| 29 |
#include <tny-folder-store.h> |
| 30 |
#include <tny-folder-store-query.h> |
| 31 |
|
| 32 |
#include <account-store.h> |
| 33 |
|
| 34 |
static gchar *cachedir=NULL; |
| 35 |
static gboolean online=FALSE, mainloop=FALSE; |
| 36 |
|
| 37 |
static const GOptionEntry options[] = |
| 38 |
{ |
| 39 |
{ "cachedir", 'c', 0, G_OPTION_ARG_STRING, &cachedir, |
| 40 |
"Cache directory", NULL }, |
| 41 |
{ "online", 'o', 0, G_OPTION_ARG_NONE, &online, |
| 42 |
"Online or offline", NULL }, |
| 43 |
{ "mainloop", 'm', 0, G_OPTION_ARG_NONE, &mainloop, |
| 44 |
"Use the Gtk+ mainloop", NULL }, |
| 45 |
|
| 46 |
{ NULL } |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
static void |
| 51 |
callback (TnyFolderStore *self, gboolean cancelled, TnyList *list, GError *err, gpointer user_data) |
| 52 |
{ |
| 53 |
TnyIterator *iter = tny_list_create_iterator (list); |
| 54 |
|
| 55 |
while (!tny_iterator_is_done (iter)) |
| 56 |
{ |
| 57 |
TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter); |
| 58 |
TnyList *folders = tny_simple_list_new (); |
| 59 |
g_print ("%s\n", tny_folder_get_name (TNY_FOLDER (folder))); |
| 60 |
tny_folder_store_get_folders_async (folder, |
| 61 |
folders, NULL, TRUE, callback, NULL, NULL); |
| 62 |
g_object_unref (G_OBJECT (folder)); |
| 63 |
tny_iterator_next (iter); |
| 64 |
} |
| 65 |
|
| 66 |
g_object_unref (iter); |
| 67 |
g_object_unref (list); |
| 68 |
} |
| 69 |
|
| 70 |
static gboolean |
| 71 |
time_s_up (gpointer data) |
| 72 |
{ |
| 73 |
gtk_main_quit (); |
| 74 |
return FALSE; |
| 75 |
} |
| 76 |
|
| 77 |
static gboolean |
| 78 |
dance (gpointer data) |
| 79 |
{ |
| 80 |
TnyList *folders; |
| 81 |
TnyStoreAccount *account = data; |
| 82 |
|
| 83 |
folders = tny_simple_list_new (); |
| 84 |
tny_folder_store_get_folders_async (TNY_FOLDER_STORE (account), |
| 85 |
folders, NULL, TRUE, callback, NULL, NULL); |
| 86 |
|
| 87 |
return FALSE; |
| 88 |
} |
| 89 |
|
| 90 |
int |
| 91 |
main (int argc, char **argv) |
| 92 |
{ |
| 93 |
GOptionContext *context; |
| 94 |
TnyAccountStore *account_store; |
| 95 |
TnyList *accounts; |
| 96 |
TnyStoreAccount *account; |
| 97 |
TnyIterator *iter; |
| 98 |
|
| 99 |
free (malloc (10)); |
| 100 |
g_type_init (); |
| 101 |
|
| 102 |
|
| 103 |
context = g_option_context_new ("- The tinymail functional tester"); |
| 104 |
g_option_context_add_main_entries (context, options, "tinymail"); |
| 105 |
|
| 106 |
g_option_context_parse (context, &argc, &argv, NULL); |
| 107 |
|
| 108 |
if (mainloop) |
| 109 |
gtk_init (&argc, &argv); |
| 110 |
|
| 111 |
account_store = tny_test_account_store_new (online, cachedir); |
| 112 |
|
| 113 |
if (cachedir) |
| 114 |
g_print ("Using %s as cache directory\n", cachedir); |
| 115 |
|
| 116 |
g_option_context_free (context); |
| 117 |
|
| 118 |
accounts = tny_simple_list_new (); |
| 119 |
|
| 120 |
tny_account_store_get_accounts (account_store, accounts, |
| 121 |
TNY_ACCOUNT_STORE_STORE_ACCOUNTS); |
| 122 |
g_object_unref (G_OBJECT (account_store)); |
| 123 |
|
| 124 |
iter = tny_list_create_iterator (accounts); |
| 125 |
account = (TnyStoreAccount*) tny_iterator_get_current (iter); |
| 126 |
|
| 127 |
|
| 128 |
if (mainloop) |
| 129 |
{ |
| 130 |
g_print ("Using the Gtk+ mainloop (will wait 4 seconds in the loop)\n"); |
| 131 |
|
| 132 |
g_timeout_add (1, dance, account); |
| 133 |
g_timeout_add (1000 * 4, time_s_up, NULL); |
| 134 |
|
| 135 |
gtk_main (); |
| 136 |
|
| 137 |
} else { |
| 138 |
g_print ("Not using a mainloop (will sleep 4 seconds)\n"); |
| 139 |
|
| 140 |
dance (account); |
| 141 |
sleep (4); |
| 142 |
} |
| 143 |
|
| 144 |
g_object_unref (account); |
| 145 |
g_object_unref (iter); |
| 146 |
g_object_unref (accounts); |
| 147 |
|
| 148 |
return 0; |
| 149 |
} |