2 # Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
4 # This file is part of python-purple.
6 # python-purple is free software: you can redistribute it and/or modify
7 # 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
9 # (at your option) any later version.
11 # python-purple is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 @param protocol Protocol class instance
27 @param core Purple class instance
30 cdef object __username
31 cdef object __protocol
35 def __init__(self, username, protocol, core):
36 self.__username = username
37 self.__protocol = protocol
40 if protocol.exists and self._get_structure() != NULL:
45 cdef account.PurpleAccount *_get_structure(self):
46 return account.purple_accounts_find(self.__username, \
49 def __is_connected(self):
51 return account.purple_account_is_connected(self._get_structure())
54 is_connected = property(__is_connected)
56 def __is_connecting(self):
58 return account.purple_account_is_connecting(self._get_structure())
61 is_connecting = property(__is_connecting)
63 def __is_disconnected(self):
65 return account.purple_account_is_disconnected( \
66 self._get_structure())
69 is_disconnected = property(__is_disconnected)
73 core = property(__get_core)
75 def __get_exists(self):
77 exists = property(__get_exists)
79 def __get_username(self):
80 cdef char *username = NULL
82 username = <char *> account.purple_account_get_username( \
83 self._get_structure())
89 return self.__username
90 username = property(__get_username)
92 def __get_protocol(self):
93 return self.__protocol
94 protocol = property(__get_protocol)
96 def __get_password(self):
97 cdef char *password = NULL
99 password = <char *> account.purple_account_get_password( \
100 self._get_structure())
107 password = property(__get_password)
109 def __get_alias(self):
110 cdef char *alias = NULL
112 alias = <char *> account.purple_account_get_alias(self._get_structure())
119 alias = property(__get_alias)
121 def __get_user_info(self):
122 cdef char *user_info = NULL
124 user_info = <char *> account.purple_account_get_user_info(self._get_structure())
131 user_info = property(__get_user_info)
133 def __get_remember_password(self):
135 return account.purple_account_get_remember_password( \
136 self._get_structure())
139 remember_password = property(__get_remember_password)
141 def __get_enabled(self):
143 return account.purple_account_get_enabled(self._get_structure(), \
147 enabled = property(__get_enabled)
149 def set_username(self, username):
151 Sets the account's username.
153 @param username The username
154 @return True if successful, False if account doesn't exists
157 account.purple_account_set_username(self._get_structure(), \
163 def set_protocol(self, protocol):
165 Sets the account's protocol.
167 @param protocol A Protocol class instance
168 @return True if successful, False if account doesn't exists
170 if protocol.exists and self.__exists:
171 account.purple_account_set_protocol_id(self._get_structure(), \
173 self.__protocol = protocol
178 def set_password(self, password):
180 Sets the account's password.
182 @param password The password
183 @return True if successful, False if account doesn't exists
186 account.purple_account_set_password(self._get_structure(), \
192 def set_alias(self, alias):
194 Sets the account's alias
196 @param alias The alias
197 @return True if successful, False if account doesn't exists
200 account.purple_account_set_alias(self._get_structure(), \
206 def set_user_info(self, user_info):
208 Sets the account's user information
210 @param user_info The user information
211 @return True if successful, False if account doesn't exists
214 account.purple_account_set_user_info(self._get_structure(), \
220 def set_remember_password(self, remember_password):
222 Sets whether or not this account should save its password.
224 @param remember_password True if should remember the password,
226 @return True if successful, False if account doesn't exists
229 account.purple_account_set_remember_password( \
230 self._get_structure(), remember_password)
235 def set_enabled(self, value):
237 Sets wheter or not this account is enabled.
239 @param value True if it is enabled, or False otherwise
240 @return True if successful, False if account doesn't exists
243 account.purple_account_set_enabled(self._get_structure(), \
244 self.__core.ui_name, bool(value))
251 Creates a new account.
253 @return True if successful, False if account already exists
258 account.purple_account_new(self.__username, self.__protocol.id)
264 Connects to an account.
266 @return True if successful, False if account doesn't exists
269 account.purple_account_connect(self._get_structure())
274 def disconnect(self):
276 Disconnects from an account.
278 @return True if successful, False if account doesn't exists
281 account.purple_account_disconnect(self._get_structure())