accountlist.h 6.18 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
 *  Author: Pierre-Luc Beaudoin <pierre-luc@savoirfairelinux.com>
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Julien Bonjean's avatar
Julien Bonjean committed
5
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
6
7
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
9
 *  (at your option) any later version.
Julien Bonjean's avatar
Julien Bonjean committed
10
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
11
12
13
14
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
Julien Bonjean's avatar
Julien Bonjean committed
15
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
16
17
18
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
21
22
23
24
25
26
27
28
29
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
30
 */
Julien Bonjean's avatar
Julien Bonjean committed
31

Tristan Matthews's avatar
Tristan Matthews committed
32
33
#ifndef ACCOUNTLIST_H_
#define ACCOUNTLIST_H_
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
34
35

#include <gtk/gtk.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
36
37
38
/** @file accountlist.h
  * @brief A list to hold accounts.
  */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
39

Julien Bonjean's avatar
Julien Bonjean committed
40
/** @enum account_state_t
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
41
42
  * This enum have all the states an account can take.
  */
Julien Bonjean's avatar
Julien Bonjean committed
43
44
45
46
47
typedef enum {
    /** The account is not registered */
    ACCOUNT_STATE_UNREGISTERED,
    /** The account is trying to register */
    ACCOUNT_STATE_TRYING,
48
49
    /** The account is registered  */
    ACCOUNT_STATE_REGISTERED,
Julien Bonjean's avatar
Julien Bonjean committed
50
51
52
53
54
55
56
57
58
59
    /** Error state. The account is not registered */
    ACCOUNT_STATE_ERROR,
    /** An authentification error occured. Wrong password or wrong username. The account is not registered */
    ACCOUNT_STATE_ERROR_AUTH,
    /** The network is unreachable. The account is not registered */
    ACCOUNT_STATE_ERROR_NETWORK,
    /** Host is unreachable. The account is not registered */
    ACCOUNT_STATE_ERROR_HOST,
    /** Stun server is not existing. The account is not registered */
    ACCOUNT_STATE_ERROR_EXIST_STUN,
60
    /** Stun server configuration error. The account is not registered */
61
    ACCOUNT_STATE_ERROR_NOT_ACCEPTABLE,
62
63
    /** IP2IP Account is always ready */
    ACCOUNT_STATE_IP2IP_READY,
64
65
    /** Invalid state */
    ACCOUNT_STATE_INVALID
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
66
67
} account_state_t;

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
68
69
/** @struct account_t
  * @brief Account information.
Julien Bonjean's avatar
Julien Bonjean committed
70
71
  * This struct holds information about an account.  All values are stored in the
  * properties GHashTable except the accountID and state.  This match how the
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
72
  * server internally works and the dbus API to save and retrieve the accounts details.
Julien Bonjean's avatar
Julien Bonjean committed
73
74
  *
  * To retrieve the Alias for example, use g_hash_table_lookup(a->properties, ACCOUNT_ALIAS).
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
75
  */
76

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
77
typedef struct  {
Julien Bonjean's avatar
Julien Bonjean committed
78
79
80
81
82
83
84
85
86
87
    gchar * accountID;
    account_state_t state;
    gchar * protocol_state_description;
    guint protocol_state_code;
    GHashTable * properties;
    GPtrArray * credential_information;

    /* The codec list */
    GQueue *codecs;
    guint _messages_number;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
88
89
} account_t;

90

Julien Bonjean's avatar
Julien Bonjean committed
91
92
/**
 * This function initialize the account list.
93
 */
Tristan Matthews's avatar
Tristan Matthews committed
94
void account_list_init();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
95

Julien Bonjean's avatar
Julien Bonjean committed
96
97
98
/**
 * This function append an account to list.
 * @param a The account you want to add
99
 */
Tristan Matthews's avatar
Tristan Matthews committed
100
void account_list_add(account_t * a);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
101

Julien Bonjean's avatar
Julien Bonjean committed
102
103
/**
 * Return the first account that corresponds to the state
Emmanuel Milou's avatar
Emmanuel Milou committed
104
 * @param state The state
Julien Bonjean's avatar
Julien Bonjean committed
105
 * @return account_t* An account or NULL
106
 */
Tristan Matthews's avatar
Tristan Matthews committed
107
account_t * account_list_get_by_state(account_state_t state);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
108

109
110
111
/**
 * @return guint The number of registered accounts in the list
 */
Julien Bonjean's avatar
Julien Bonjean committed
112
guint account_list_get_registered_accounts();
113

Julien Bonjean's avatar
Julien Bonjean committed
114
/**
115
 * Return the number of accounts in the list
Julien Bonjean's avatar
Julien Bonjean committed
116
 * @return guint The number of accounts in the list
117
 */
Tristan Matthews's avatar
Tristan Matthews committed
118
guint account_list_get_size();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
119

Julien Bonjean's avatar
Julien Bonjean committed
120
/**
121
122
 * Return the account at the nth position in the list
 * @param n The position of the account you want
Julien Bonjean's avatar
Julien Bonjean committed
123
 * @return An account or NULL
124
 */
Tristan Matthews's avatar
Tristan Matthews committed
125
account_t * account_list_get_nth(guint n);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
126

Julien Bonjean's avatar
Julien Bonjean committed
127
/**
128
 * Return the current account struct
129
 *  @return The current account struct
130
 */
Julien Bonjean's avatar
Julien Bonjean committed
131
account_t * account_list_get_current();
132

Julien Bonjean's avatar
Julien Bonjean committed
133
/**
134
 * This function sets an account as the current one
135
 * @param current the account you want to set as current
136
 */
Tristan Matthews's avatar
Tristan Matthews committed
137
void account_list_set_current(account_t *current);
138

Julien Bonjean's avatar
Julien Bonjean committed
139
/**
140
141
 * This function maps account_state_t enums to a description.
 * @param s The state
Julien Bonjean's avatar
Julien Bonjean committed
142
 * @return The full text description of the state
143
 */
Tristan Matthews's avatar
Tristan Matthews committed
144
const gchar * account_state_name(account_state_t s);
145

Julien Bonjean's avatar
Julien Bonjean committed
146
/**
Rafaël Carré's avatar
Cleanup    
Rafaël Carré committed
147
 * This function frees the list
148
 */
Tristan Matthews's avatar
Tristan Matthews committed
149
void account_list_free();
150

Julien Bonjean's avatar
Julien Bonjean committed
151
/**
152
 * Return the account associated with an ID
153
 * @param accountID The ID of the account
Julien Bonjean's avatar
Julien Bonjean committed
154
 * @return An account or NULL
155
 */
Tristan Matthews's avatar
Tristan Matthews committed
156
account_t * account_list_get_by_id(const gchar * const accountID);
157

Julien Bonjean's avatar
Julien Bonjean committed
158
/**
159
160
161
 * Move the account from an unit up in the account_list
 * @param index The current index in the list
 */
Tristan Matthews's avatar
Tristan Matthews committed
162
void account_list_move_up(guint index);
163

Julien Bonjean's avatar
Julien Bonjean committed
164
/**
165
166
167
 * Move the account from an unit down in the account_list
 * @param index The current index in the list
 */
Tristan Matthews's avatar
Tristan Matthews committed
168
void account_list_move_down(guint index);
169

170
171
172
173
/**
 * Return the ID of the current default account
 * @return gchar* The id
 */
Tristan Matthews's avatar
Tristan Matthews committed
174
const gchar* account_list_get_current_id(void);
175

Tristan Matthews's avatar
Tristan Matthews committed
176
gchar * account_list_get_ordered_list(void);
Emmanuel Milou's avatar
Emmanuel Milou committed
177

Tristan Matthews's avatar
Tristan Matthews committed
178
gboolean current_account_has_mailbox(void);
179

Tristan Matthews's avatar
Tristan Matthews committed
180
guint current_account_get_message_number(void);
181

Tristan Matthews's avatar
Tristan Matthews committed
182
void current_account_set_message_number(guint nb);
183

Tristan Matthews's avatar
Tristan Matthews committed
184
gboolean current_account_has_new_message(void);
185

186
187
188
gboolean account_is_IP2IP(const account_t *account);
gboolean account_is_SIP(const account_t *account);
gboolean account_is_IAX(const account_t *account);
189
190

account_t *create_default_account();
191
account_t *create_account_with_ID(const gchar *ID);
192

193
194
void initialize_credential_information(account_t *account);

195
void account_replace(account_t *account, const gchar *key, const gchar *value);
196
void account_insert(account_t *account, const gchar *key, const gchar *value);
197
gpointer account_lookup(const account_t *account, gconstpointer key);
198
void account_list_remove(const gchar *accountID);
199

Tristan Matthews's avatar
Tristan Matthews committed
200
#endif  // ACCOUNTLIST_H_