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 __get_username(self):
50 return account.c_purple_account_get_username(self.c_account)
53 def __set_username(self, username):
55 account.c_purple_account_set_username(self.c_account, username)
56 username = property(__get_password, __set_username)
58 def __get_password(self):
60 return account.c_purple_account_get_password(self.c_account)
63 def __set_password(self, password):
65 account.c_purple_account_set_password(self.c_account, password)
66 password = property(__get_password, __set_password)
68 def __get_alias(self):
70 return account.c_purple_account_get_alias(self.c_account)
73 def __set_alias(self, alias):
75 account.c_purple_account_set_alias(self.c_account, alias)
76 alias = property(__get_alias, __set_alias)
78 def __get_user_info(self):
80 return account.c_purple_account_get_user_info(self.c_account)
83 def __set_user_info(self, user_info):
85 account.c_purple_account_set_user_info(self.c_account, user_info)
86 user_info = property(__get_user_info, __set_user_info)
88 def __get_protocol_id(self):
90 return account.c_purple_account_get_protocol_id(self.c_account)
93 def __set_protocol_id(self, protocol_id):
95 account.c_purple_account_set_protocol_id(self.c_account, protocol_id)
96 protocol_id = property(__get_protocol_id, __set_protocol_id)
98 def __get_remember_password(self):
100 return account.c_purple_account_get_remember_password(self.c_account)
103 def __set_remember_password(self, value):
105 account.c_purple_account_set_remember_password(self.c_account, value)
106 remember_password = property(__get_remember_password, __set_remember_password)
108 def get_protocol_name(self):
110 return account.c_purple_account_get_protocol_name(self.c_account)
114 def get_enabled(self, ui):
116 return account.c_purple_account_get_enabled(self.c_account, ui)
120 def set_enabled(self, ui, value):
122 account.c_purple_account_set_enabled(self.c_account, ui, value)
124 def set_status(self):
125 self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
126 savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
128 def __get_proxy(self):
130 proxy = property(__get_proxy)
132 def get_buddies_online(self):
133 cdef glib.GSList *iter
134 cdef blist.PurpleBuddy *buddy
136 iter = blist.c_purple_find_buddies(self.c_account, NULL)
138 buddy = <blist.PurpleBuddy *> iter.data
139 if <blist.PurpleBuddy *>buddy and \
140 account.c_purple_account_is_connected(blist.c_purple_buddy_get_account(buddy)) and \
141 status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(buddy)):
142 buddies += [buddy.name]
146 def get_protocol_options(self):
147 ''' FIXME: It is just a hack, to set the XMPP's options. '''
148 cdef glib.GList *iter
149 cdef accountopt.PurpleAccountOption *option
150 cdef prefs.PurplePrefType type
151 cdef const_char *label_name
152 cdef const_char *str_value
153 cdef const_char *setting
155 cdef glib.gboolean bool_value
156 iter = self.c_prpl_info.protocol_options
158 option = <accountopt.PurpleAccountOption *> iter.data
159 type = accountopt.c_purple_account_option_get_type(option)
160 label_name = accountopt.c_purple_account_option_get_text(option)
161 setting = accountopt.c_purple_account_option_get_setting(option)
162 if type == prefs.PURPLE_PREF_STRING:
163 str_value = accountopt.c_purple_account_option_get_default_string(option)
165 # Google Talk default domain hackery!
166 if str_value == NULL and str(<char *> label_name) == "Connect server":
167 str_value = "talk.google.com"
169 if self.c_account != NULL:
170 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
171 account.c_purple_account_set_string(self.c_account, setting, str_value)
173 elif type == prefs.PURPLE_PREF_INT:
174 int_value = accountopt.c_purple_account_option_get_default_int(option)
175 if self.c_account != NULL:
176 int_value = account.c_purple_account_get_int(self.c_account, setting, int_value)
177 if str(<char *> setting) == "port":
178 account.c_purple_account_set_int(self.c_account, setting, 443)
180 elif type == prefs.PURPLE_PREF_BOOLEAN:
181 bool_value = accountopt.c_purple_account_option_get_default_bool(option)
182 if self.c_account != NULL:
183 bool_value = account.c_purple_account_get_bool(self.c_account, setting, bool_value)
184 if str(<char *> setting) == "old_ssl":
185 account.c_purple_account_set_bool(self.c_account, setting, True)
187 elif type == prefs.PURPLE_PREF_STRING_LIST:
188 str_value = accountopt.c_purple_account_option_get_default_list_value(option)
189 if self.c_account != NULL:
190 str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)