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
34 cdef object __protocol
37 self.__proxy = purple.ProxyInfo()
38 self.__protocol = purple.Plugin()
41 def __init__(self, char *username, char *protocol_id):
42 cdef proxy.PurpleProxyInfo *c_proxyinfo
43 cdef account.PurpleAccount *acc = NULL
45 acc = account.c_purple_accounts_find(username, protocol_id)
48 c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
50 self.c_account = account.c_purple_account_new(username, protocol_id)
51 c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
52 if c_proxyinfo == NULL:
53 c_proxyinfo = proxy.c_purple_proxy_info_new()
54 proxy.c_purple_proxy_info_set_type(c_proxyinfo, proxy.PURPLE_PROXY_NONE)
55 account.c_purple_account_set_proxy_info(self.c_account, c_proxyinfo)
56 self.__proxy = ProxyInfo()
57 self.__proxy.c_proxyinfo = c_proxyinfo
60 self.c_plugin = plugin.c_purple_plugins_find_with_id(protocol_id)
61 self.c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(self.c_plugin)
64 def __get_username(self):
66 return account.c_purple_account_get_username(self.c_account)
69 def __set_username(self, username):
71 account.c_purple_account_set_username(self.c_account, username)
72 username = property(__get_password, __set_username)
74 def __get_password(self):
76 return account.c_purple_account_get_password(self.c_account)
79 def __set_password(self, password):
81 account.c_purple_account_set_password(self.c_account, password)
82 password = property(__get_password, __set_password)
84 def __get_alias(self):
86 return account.c_purple_account_get_alias(self.c_account)
89 def __set_alias(self, alias):
91 account.c_purple_account_set_alias(self.c_account, alias)
92 alias = property(__get_alias, __set_alias)
94 def __get_user_info(self):
96 return account.c_purple_account_get_user_info(self.c_account)
99 def __set_user_info(self, user_info):
101 account.c_purple_account_set_user_info(self.c_account, user_info)
102 user_info = property(__get_user_info, __set_user_info)
104 def __get_protocol_id(self):
106 return account.c_purple_account_get_protocol_id(self.c_account)
109 def __set_protocol_id(self, protocol_id):
111 account.c_purple_account_set_protocol_id(self.c_account, protocol_id)
112 protocol_id = property(__get_protocol_id, __set_protocol_id)
114 def __get_remember_password(self):
116 return account.c_purple_account_get_remember_password(self.c_account)
119 def __set_remember_password(self, value):
121 account.c_purple_account_set_remember_password(self.c_account, value)
122 remember_password = property(__get_remember_password, __set_remember_password)
124 def _get_protocol_options(self):
125 cdef glib.GList *iter
126 cdef accountopt.PurpleAccountOption *option
127 cdef prefs.PurplePrefType type
128 cdef const_char *label_name
129 cdef const_char *str_value
130 cdef const_char *setting
132 cdef glib.gboolean bool_value
134 if self.c_account == NULL:
139 iter = self.c_prpl_info.protocol_options
143 option = <accountopt.PurpleAccountOption *> iter.data
144 type = accountopt.c_purple_account_option_get_type(option)
145 label_name = accountopt.c_purple_account_option_get_text(option)
146 setting = accountopt.c_purple_account_option_get_setting(option)
148 sett = str(<char *> setting)
150 if type == prefs.PURPLE_PREF_STRING:
152 str_value = accountopt.c_purple_account_option_get_default_string(option)
154 # Google Talk default domain hackery!
155 if str_value == NULL and str(<char *> label_name) == "Connect server":
156 str_value = "talk.google.com"
157 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
159 val = str(<char *> str_value)
161 elif type == prefs.PURPLE_PREF_INT:
163 int_value = accountopt.c_purple_account_option_get_default_int(option)
164 int_value = account.c_purple_account_get_int(self.c_account, setting, int_value)
168 elif type == prefs.PURPLE_PREF_BOOLEAN:
170 bool_value = accountopt.c_purple_account_option_get_default_bool(option)
171 bool_value = account.c_purple_account_get_bool(self.c_account, setting, bool_value)
173 val = bool(bool_value)
175 elif type == prefs.PURPLE_PREF_STRING_LIST:
177 str_value = accountopt.c_purple_account_option_get_default_list_value(option)
178 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
180 val = str(<char *> str_value)
188 def _set_protocol_options(self, po):
189 cdef glib.GList *iter
190 cdef accountopt.PurpleAccountOption *option
191 cdef prefs.PurplePrefType type
192 cdef const_char *str_value
193 cdef const_char *setting
195 cdef glib.gboolean bool_value
197 if self.c_account == NULL:
202 iter = self.c_prpl_info.protocol_options
206 option = <accountopt.PurpleAccountOption *> iter.data
207 type = accountopt.c_purple_account_option_get_type(option)
208 setting = accountopt.c_purple_account_option_get_setting(option)
210 sett = str(<char *> setting)
212 if type == prefs.PURPLE_PREF_STRING:
214 str_value = <char *> po[sett]
215 account.c_purple_account_set_string(self.c_account, setting, str_value)
217 elif type == prefs.PURPLE_PREF_INT:
219 int_value = int(po[sett])
220 account.c_purple_account_set_int(self.c_account, setting, int_value)
222 elif type == prefs.PURPLE_PREF_BOOLEAN:
224 bool_value = bool(po[sett])
225 account.c_purple_account_set_bool(self.c_account, setting, bool_value)
227 elif type == prefs.PURPLE_PREF_STRING_LIST:
229 str_value = <char *> po[sett]
230 account.c_purple_account_set_string(self.c_account, setting, str_value)
234 protocol_options = property(_get_protocol_options, _set_protocol_options)
236 def _get_protocol_labels(self):
237 cdef glib.GList *iter
238 cdef accountopt.PurpleAccountOption *option
239 cdef const_char *label_name
240 cdef const_char *setting
242 if self.c_account == NULL:
247 iter = self.c_prpl_info.protocol_options
251 option = <accountopt.PurpleAccountOption *> iter.data
252 label_name = accountopt.c_purple_account_option_get_text(option)
253 setting = accountopt.c_purple_account_option_get_setting(option)
255 sett = str(<char *> setting)
256 label = str(<char *> label_name)
262 protocol_labels = property(_get_protocol_labels)
264 def __get_proxy(self):
266 proxy = property(__get_proxy)
268 def __get_protocol(self):
269 return self.__protocol
270 protocol = property(__get_protocol)
272 def get_protocol_name(self):
274 return account.c_purple_account_get_protocol_name(self.c_account)
278 def set_status(self):
279 self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
280 savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
282 def get_buddies_online(self, acc):
283 cdef account.PurpleAccount *c_account
284 cdef glib.GSList *iter
285 cdef blist.PurpleBuddy *buddy
286 cdef char *c_name = NULL
287 cdef char *c_alias = NULL
289 c_account = account.c_purple_accounts_find(acc[0], acc[1])
291 iter = blist.c_purple_find_buddies(c_account, NULL)
299 buddy = <blist.PurpleBuddy *> iter.data
300 if <blist.PurpleBuddy *>buddy and \
301 account.c_purple_account_is_connected(blist.c_purple_buddy_get_account(buddy)) and \
302 status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(buddy)):
303 c_name = <char *> blist.c_purple_buddy_get_name(buddy)
308 c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
313 buddies.append((name, alias))
317 def new(self, username, protocol_id):
318 cdef account.PurpleAccount *c_account
319 c_account = account.c_purple_account_new(username, protocol_id)
321 if c_account == NULL:
324 account.c_purple_accounts_add(c_account)
326 return (username, protocol_id)
329 cdef glib.GList *iter
330 cdef account.PurpleAccount *acc
334 iter = account.c_purple_accounts_get_all()
336 acc = <account.PurpleAccount *> iter.data
337 if <account.PurpleAccount *>acc:
338 username = account.c_purple_account_get_username(acc)
339 protocol_id = account.c_purple_account_get_protocol_id(acc)
341 accounts.append((username, protocol_id))
346 def get_password(self, acc):
347 ''' @param acc Tuple (username, protocol id) '''
348 cdef account.PurpleAccount *c_account
352 c_account = account.c_purple_accounts_find(acc[0], acc[1])
354 value = <char *> account.c_purple_account_get_password(c_account)
362 def set_password(self, acc, password):
363 ''' @param acc Tuple (username, protocol id) '''
364 ''' @param password The account's password '''
365 cdef account.PurpleAccount *c_account
370 c_account = account.c_purple_accounts_find(acc[0], acc[1])
372 account.c_purple_account_set_password(c_account, password)
374 def get_alias(self, acc):
375 ''' @param acc Tuple (username, protocol id) '''
376 cdef account.PurpleAccount *c_account
380 c_account = account.c_purple_accounts_find(acc[0], acc[1])
382 value = <char *> account.c_purple_account_get_alias(c_account)
389 def set_alias(self, acc, alias):
390 ''' @param acc Tuple (username, protocol id) '''
391 ''' @param alias The account's alias '''
392 cdef account.PurpleAccount *c_account
397 c_account = account.c_purple_accounts_find(acc[0], acc[1])
399 account.c_purple_account_set_alias(c_account, alias)
401 def set_protocol_id(self, acc, protocol_id):
402 ''' @param acc Tuple (username, protocol id) '''
403 ''' @param protocol_id The new account's protocol id '''
404 cdef account.PurpleAccount *c_account
409 c_account = account.c_purple_accounts_find(acc[0], acc[1])
411 account.c_purple_account_set_protocol_id(c_account, protocol_id)
413 def get_protocol_id(self, acc):
414 ''' @param acc Tuple (username, protocol id) '''
415 ''' @return account's protocol id '''
416 cdef account.PurpleAccount *c_account
420 c_account = account.c_purple_accounts_find(acc[0], acc[1])
422 value = <char *> account.c_purple_account_get_protocol_id(c_account)
430 def set_enabled(self, acc, ui, value):
431 ''' @param acc Tuple (username, protocol id) '''
432 ''' @param ui The UI '''
433 ''' @param value True to enabled or False to disabled '''
434 cdef account.PurpleAccount *c_account
436 c_account = account.c_purple_accounts_find(acc[0], acc[1])
438 account.c_purple_account_set_enabled(c_account, <char *> ui, bool(value))
440 def get_enabled(self, acc, ui):
441 ''' @param acc Tuple (username, protocol id) '''
442 ''' @param ui The UI '''
443 cdef account.PurpleAccount *c_account
445 c_account = account.c_purple_accounts_find(acc[0], acc[1])
447 return account.c_purple_account_get_enabled(c_account, ui)
451 def is_connected(self, acc):
452 ''' @param acc Tuple (username, protocol id) '''
453 ''' @param ui The UI '''
454 cdef account.PurpleAccount *c_account
456 c_account = account.c_purple_accounts_find(acc[0], acc[1])
458 return account.c_purple_account_is_connected(c_account)
462 def connect(self, acc):
463 ''' @param acc Tuple (username, protocol id) '''
464 ''' @param ui The UI '''
465 cdef account.PurpleAccount *c_account
467 c_account = account.c_purple_accounts_find(acc[0], acc[1])
469 account.c_purple_account_connect(c_account)
471 def disconnect(self, acc):
472 ''' @param acc Tuple (username, protocol id) '''
473 ''' @param ui The UI '''
474 cdef account.PurpleAccount *c_account
476 c_account = account.c_purple_accounts_find(acc[0], acc[1])
478 account.c_purple_account_disconnect(c_account)
480 def set_remember_password(self, acc, value):
481 cdef account.PurpleAccount *c_account
482 c_account = account.c_purple_accounts_find(acc[0], acc[1])
484 account.c_purple_account_set_remember_password(c_account, value)
486 def get_remember_password(self, acc):
487 cdef account.PurpleAccount *c_account
488 c_account = account.c_purple_accounts_find(acc[0], acc[1])
490 return account.c_purple_account_get_remember_password(c_account)
494 def remove(self, acc):
495 cdef account.PurpleAccount *c_account
497 c_account = account.c_purple_accounts_find(acc[0], acc[1])
499 account.c_purple_accounts_delete(c_account)