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/>.
23 ctypedef char const_char "const char"
27 cdef account.PurpleAccount *c_account
28 cdef plugin.PurplePlugin *c_plugin
29 cdef prpl.PurplePluginProtocolInfo *c_prpl_info
30 cdef plugin.PurplePluginInfo *c_plugin_info
31 cdef savedstatuses.PurpleSavedStatus *__sstatus
32 cdef ProxyInfo __proxy
34 def __init__(self, char *username, char *protocol_id):
35 cdef proxy.PurpleProxyInfo *c_proxyinfo
36 cdef account.PurpleAccount *acc = NULL
38 acc = account.c_purple_accounts_find(username, protocol_id)
41 c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
43 self.c_account = account.c_purple_account_new(username, protocol_id)
44 c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
45 if c_proxyinfo == NULL:
46 c_proxyinfo = proxy.c_purple_proxy_info_new()
47 proxy.c_purple_proxy_info_set_type(c_proxyinfo, proxy.PURPLE_PROXY_NONE)
48 account.c_purple_account_set_proxy_info(self.c_account, c_proxyinfo)
49 self.__proxy = ProxyInfo()
50 self.__proxy.c_proxyinfo = c_proxyinfo
53 self.c_plugin = plugin.c_purple_plugins_find_with_id(protocol_id)
54 self.c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(self.c_plugin)
56 def __get_username(self):
58 return account.c_purple_account_get_username(self.c_account)
61 def __set_username(self, username):
63 account.c_purple_account_set_username(self.c_account, username)
64 username = property(__get_password, __set_username)
66 def __get_password(self):
68 return account.c_purple_account_get_password(self.c_account)
71 def __set_password(self, password):
73 account.c_purple_account_set_password(self.c_account, password)
74 password = property(__get_password, __set_password)
76 def __get_alias(self):
78 return account.c_purple_account_get_alias(self.c_account)
81 def __set_alias(self, alias):
83 account.c_purple_account_set_alias(self.c_account, alias)
84 alias = property(__get_alias, __set_alias)
86 def __get_user_info(self):
88 return account.c_purple_account_get_user_info(self.c_account)
91 def __set_user_info(self, user_info):
93 account.c_purple_account_set_user_info(self.c_account, user_info)
94 user_info = property(__get_user_info, __set_user_info)
96 def __get_protocol_id(self):
98 return account.c_purple_account_get_protocol_id(self.c_account)
101 def __set_protocol_id(self, protocol_id):
103 account.c_purple_account_set_protocol_id(self.c_account, protocol_id)
104 protocol_id = property(__get_protocol_id, __set_protocol_id)
106 def __get_remember_password(self):
108 return account.c_purple_account_get_remember_password(self.c_account)
111 def __set_remember_password(self, value):
113 account.c_purple_account_set_remember_password(self.c_account, value)
114 remember_password = property(__get_remember_password, __set_remember_password)
116 def _get_protocol_options(self):
117 cdef glib.GList *iter
118 cdef accountopt.PurpleAccountOption *option
119 cdef prefs.PurplePrefType type
120 cdef const_char *label_name
121 cdef const_char *str_value
122 cdef const_char *setting
124 cdef glib.gboolean bool_value
126 if self.c_account == NULL:
131 iter = self.c_prpl_info.protocol_options
135 option = <accountopt.PurpleAccountOption *> iter.data
136 type = accountopt.c_purple_account_option_get_type(option)
137 label_name = accountopt.c_purple_account_option_get_text(option)
138 setting = accountopt.c_purple_account_option_get_setting(option)
140 sett = str(<char *> setting)
142 if type == prefs.PURPLE_PREF_STRING:
144 str_value = accountopt.c_purple_account_option_get_default_string(option)
146 # Google Talk default domain hackery!
147 if str_value == NULL and str(<char *> label_name) == "Connect server":
148 str_value = "talk.google.com"
149 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
151 val = str(<char *> str_value)
153 elif type == prefs.PURPLE_PREF_INT:
155 int_value = accountopt.c_purple_account_option_get_default_int(option)
156 int_value = account.c_purple_account_get_int(self.c_account, setting, int_value)
160 elif type == prefs.PURPLE_PREF_BOOLEAN:
162 bool_value = accountopt.c_purple_account_option_get_default_bool(option)
163 bool_value = account.c_purple_account_get_bool(self.c_account, setting, bool_value)
165 val = bool(bool_value)
167 elif type == prefs.PURPLE_PREF_STRING_LIST:
169 str_value = accountopt.c_purple_account_option_get_default_list_value(option)
170 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
172 val = str(<char *> str_value)
180 protocol_options = property(_get_protocol_options)
182 def _get_protocol_labels(self):
183 cdef glib.GList *iter
184 cdef accountopt.PurpleAccountOption *option
185 cdef const_char *label_name
186 cdef const_char *setting
188 if self.c_account == NULL:
193 iter = self.c_prpl_info.protocol_options
197 option = <accountopt.PurpleAccountOption *> iter.data
198 label_name = accountopt.c_purple_account_option_get_text(option)
199 setting = accountopt.c_purple_account_option_get_setting(option)
201 sett = str(<char *> setting)
202 label = str(<char *> label_name)
208 protocol_labels = property(_get_protocol_labels)
210 def get_protocol_name(self):
212 return account.c_purple_account_get_protocol_name(self.c_account)
216 def get_enabled(self, ui):
218 return account.c_purple_account_get_enabled(self.c_account, ui)
222 def set_enabled(self, ui, value):
224 account.c_purple_account_set_enabled(self.c_account, ui, value)
226 def set_status(self):
227 self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
228 savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
230 def __get_proxy(self):
232 proxy = property(__get_proxy)
234 def get_buddies_online(self):
235 cdef glib.GSList *iter
236 cdef blist.PurpleBuddy *buddy
237 cdef char *c_name = NULL
238 cdef char *c_alias = NULL
240 iter = blist.c_purple_find_buddies(self.c_account, NULL)
244 buddy = <blist.PurpleBuddy *> iter.data
245 if <blist.PurpleBuddy *>buddy and \
246 account.c_purple_account_is_connected(blist.c_purple_buddy_get_account(buddy)) and \
247 status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(buddy)):
248 c_name = <char *> blist.c_purple_buddy_get_name(buddy)
253 c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
258 buddies.append((name, alias))
262 def get_protocol_options(self):
263 ''' FIXME: It is just a hack, to set the XMPP's options. '''
264 cdef glib.GList *iter
265 cdef accountopt.PurpleAccountOption *option
266 cdef prefs.PurplePrefType type
267 cdef const_char *label_name
268 cdef const_char *str_value
269 cdef const_char *setting
271 cdef glib.gboolean bool_value
272 iter = self.c_prpl_info.protocol_options
274 option = <accountopt.PurpleAccountOption *> iter.data
275 type = accountopt.c_purple_account_option_get_type(option)
276 label_name = accountopt.c_purple_account_option_get_text(option)
277 setting = accountopt.c_purple_account_option_get_setting(option)
278 if type == prefs.PURPLE_PREF_STRING:
279 str_value = accountopt.c_purple_account_option_get_default_string(option)
281 # Google Talk default domain hackery!
282 if str_value == NULL and str(<char *> label_name) == "Connect server":
283 str_value = "talk.google.com"
285 if self.c_account != NULL:
286 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
287 account.c_purple_account_set_string(self.c_account, setting, str_value)
289 elif type == prefs.PURPLE_PREF_INT:
290 int_value = accountopt.c_purple_account_option_get_default_int(option)
291 if self.c_account != NULL:
292 int_value = account.c_purple_account_get_int(self.c_account, setting, int_value)
293 if str(<char *> setting) == "port":
294 account.c_purple_account_set_int(self.c_account, setting, 443)
296 elif type == prefs.PURPLE_PREF_BOOLEAN:
297 bool_value = accountopt.c_purple_account_option_get_default_bool(option)
298 if self.c_account != NULL:
299 bool_value = account.c_purple_account_get_bool(self.c_account, setting, bool_value)
300 if str(<char *> setting) == "old_ssl":
301 account.c_purple_account_set_bool(self.c_account, setting, True)
303 elif type == prefs.PURPLE_PREF_STRING_LIST:
304 str_value = accountopt.c_purple_account_option_get_default_list_value(option)
305 if self.c_account != NULL:
306 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
310 def save_into_xml(self):
311 account.c_purple_accounts_add(self.c_account)