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 self.c_account = account.c_purple_account_new(username, protocol_id)
37 self.c_plugin = plugin.c_purple_plugins_find_with_id(protocol_id)
38 self.c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(self.c_plugin)
40 c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
41 if c_proxyinfo == NULL:
42 c_proxyinfo = proxy.c_purple_proxy_info_new()
43 proxy.c_purple_proxy_info_set_type(c_proxyinfo, proxy.PURPLE_PROXY_NONE)
44 account.c_purple_account_set_proxy_info(self.c_account, c_proxyinfo)
45 self.__proxy = ProxyInfo()
46 self.__proxy.c_proxyinfo = c_proxyinfo
48 def set_password(self, password):
49 account.c_purple_account_set_password(self.c_account, password)
51 def set_enabled(self, ui, value):
52 account.c_purple_account_set_enabled(self.c_account, ui, value)
54 def get_acc_username(self):
56 return account.c_purple_account_get_username(self.c_account)
58 def get_password(self):
60 return account.c_purple_account_get_password(self.c_account)
63 self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
64 savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
69 proxy = property(get_proxy)
71 def get_buddies_online(self):
72 cdef glib.GSList *iter
73 cdef blist.PurpleBuddy *buddy
75 iter = blist.c_purple_find_buddies(self.c_account, NULL)
77 buddy = <blist.PurpleBuddy *> iter.data
78 if <blist.PurpleBuddy *>buddy and \
79 account.c_purple_account_is_connected(blist.c_purple_buddy_get_account(buddy)) and \
80 status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(buddy)):
81 buddies += [buddy.name]
85 def get_protocol_options(self):
86 ''' FIXME: It is just a hack, to set the XMPP's options. '''
88 cdef accountopt.PurpleAccountOption *option
89 cdef prefs.PurplePrefType type
90 cdef const_char *label_name
91 cdef const_char *str_value
92 cdef const_char *setting
94 cdef glib.gboolean bool_value
95 iter = self.c_prpl_info.protocol_options
97 option = <accountopt.PurpleAccountOption *> iter.data
98 type = accountopt.c_purple_account_option_get_type(option)
99 label_name = accountopt.c_purple_account_option_get_text(option)
100 setting = accountopt.c_purple_account_option_get_setting(option)
101 if type == prefs.PURPLE_PREF_STRING:
102 str_value = accountopt.c_purple_account_option_get_default_string(option)
104 # Google Talk default domain hackery!
105 if str_value == NULL and str(<char *> label_name) == "Connect server":
106 str_value = "talk.google.com"
108 if self.c_account != NULL:
109 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
110 account.c_purple_account_set_string(self.c_account, setting, str_value );
112 elif type == prefs.PURPLE_PREF_INT:
113 int_value = accountopt.c_purple_account_option_get_default_int(option)
114 if self.c_account != NULL:
115 int_value = account.c_purple_account_get_int(self.c_account, setting, int_value)
116 if str(<char *> setting) == "port":
117 account.c_purple_account_set_int(self.c_account, setting, 443);
119 elif type == prefs.PURPLE_PREF_BOOLEAN:
120 bool_value = accountopt.c_purple_account_option_get_default_bool(option)
121 if self.c_account != NULL:
122 bool_value = account.c_purple_account_get_bool(self.c_account, setting, bool_value)
123 if str(<char *> setting) == "old_ssl":
124 account.c_purple_account_set_bool(self.c_account, setting, True);
126 elif type == prefs.PURPLE_PREF_STRING_LIST:
127 str_value = accountopt.c_purple_account_option_get_default_list_value(option)
128 if self.c_account != NULL:
129 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)