61cef7d26a620fb2215e3d304952d012df73fb8e
[modest] / src / modest-account-mgr-helpers.h
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 #ifndef __MODEST_ACCOUNT_MGR_HELPERS_H__
32 #define __MODEST_ACCOUNT_MGR_HELPERS_H__
33
34 #include <modest-account-mgr.h>
35 #include <modest-tny-account-store.h>
36
37 #include <tny-account.h>
38 #include <tny-store-account.h>
39 #include <tny-transport-account.h>
40
41 G_BEGIN_DECLS
42
43 typedef struct {
44         TnyAccount    *tny_account;
45         gchar         *account_name;
46         gchar         *hostname;
47         gchar         *username;
48         ModestProtocol proto;
49         gchar         *password;
50         GSList        *options;
51 } ModestServerAccountData;
52
53 typedef struct {
54         gchar                  *account_name;
55         gchar                  *display_name;
56         gchar                  *fullname;
57         gchar                  *email;
58         gboolean                enabled;
59         ModestServerAccountData *transport_account;
60         ModestServerAccountData *store_account;
61 } ModestAccountData;
62
63
64
65 /**
66  * modest_account_mgr_get_account_data:
67  * @self: a ModestAccountMgr instance
68  * @name: the name of the account
69  * 
70  * get information about an account
71  *
72  * Returns: a ModestAccountData structure with information about the account.
73  * the data should not be changed, and be freed with modest_account_mgr_free_account_data
74  * The function does a sanity check, an if it's not returning NULL,
75  * it is a valid account
76  */
77 ModestAccountData *modest_account_mgr_get_account_data     (ModestAccountMgr *self,
78                                                             const gchar* name);
79
80 /**
81  * modest_account_mgr_get_default_account:
82  * @self: a ModestAccountMgr instance
83  * 
84  * get the default account name, or NULL if none is found
85  *
86  * Returns: the default account name (as newly allocated string, which
87  * must be g_free'd), or NULL
88  */
89 gchar* modest_account_mgr_get_default_account  (ModestAccountMgr *self);
90
91 /**
92  * modest_account_mgr_get_default_account:
93  * @self: a ModestAccountMgr instance
94  * @account: the name of an existing account
95  * 
96  * set the default account name (which must be valid account)
97  *
98  * Returns: TRUE if succeeded, FALSE otherwise
99  */
100 gboolean modest_account_mgr_set_default_account  (ModestAccountMgr *self,
101                                                   const gchar* account);
102
103 /**
104  * modest_account_mgr_free_account_data:
105  * @self: a ModestAccountMgr instance
106  * @data: a ModestAccountData instance
107  * 
108  * free the account data structure
109  */
110 void       modest_account_mgr_free_account_data     (ModestAccountMgr *self,
111                                                      ModestAccountData *data);
112
113
114
115 /**
116  * modest_account_mgr_set_enabled
117  * @self: a ModestAccountMgr instance
118  * @name: the account name 
119  * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
120  * 
121  * enable/disabled an account
122  *
123  * Returns: TRUE if it worked, FALSE otherwise
124  */
125 gboolean modest_account_mgr_set_enabled (ModestAccountMgr *self, const gchar* name,
126                                          gboolean enabled);
127
128 /**
129  * modest_account_mgr_get_enabled:
130  * @self: a ModestAccountMgr instance
131  * @name: the account name to check
132  *
133  * check whether a certain account is enabled
134  *
135  * Returns: TRUE if it is enabled, FALSE otherwise
136  */
137 gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
138
139
140
141 /**
142  * modest_account_mgr_get_tny_account:
143  * @self: a #ModestAccountMgr instance
144  * @name: the account name
145  * @type: the #TnyAccountType to check; either TNY_ACCOUNT_TYPE_TRANSPORT or TNY_ACCOUNT_TYPE_STORE
146  *
147  * get the TnyAccount corresponding to the store/transport (server) accounts for some account.
148  * ie., every account has two server accounts, and for every server account there is a corresponding
149  * TnyAccount 
150  *
151  * Returns: the requested TnyAccount, or NULL in case of error
152  */
153 TnyAccount*  modest_account_mgr_get_tny_account (ModestAccountMgr *self, const gchar* name,
154                                                  TnyAccountType type);
155
156 /**
157  * modest_account_mgr_get_from_string
158  * @self: a #ModestAccountMgr instance
159  * @name: the account name
160  *
161  * get the From: string for some account; ie. "Foo Bar" <foo.bar@cuux.yy>"
162  *
163  * Returns: the newly allocated from-string, or NULL in case of error
164  */
165 gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name);
166
167
168 G_END_DECLS
169
170 #endif /* __MODEST_ACCOUNT_MGR_H__ */