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 cdef plugin.PurplePlugin *c_plugin
24 cdef prpl.PurplePluginProtocolInfo *c_prpl_info
25 cdef plugin.PurplePluginInfo *c_plugin_info
31 def __init__(self, id):
32 self.c_plugin = plugin.c_purple_plugins_find_with_id(id)
33 self.c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(self.c_plugin)
37 return self.c_plugin.info.name
40 return self.c_plugin.info.id
43 ''' @return A string list of protocols' (id, name) '''
44 ''' [('prpl-jabber', 'XMPP'), ('foo', 'MSN'), ...] '''
46 cdef plugin.PurplePlugin *pp
50 iter = plugin.c_purple_plugins_get_protocols()
52 pp = <plugin.PurplePlugin*> iter.data
53 if pp.info and pp.info.name:
54 protocols.append((pp.info.id, pp.info.name))
59 def get_options(self, id, username=None):
60 ''' @param id The protocol's id '''
61 ''' @param username The account's username '''
62 ''' @return {'setting type': ('UI label', str|int|bool value)} '''
64 cdef plugin.PurplePlugin *c_plugin
65 cdef prpl.PurplePluginProtocolInfo *c_prpl_info
66 cdef account.PurpleAccount *c_account
68 cdef accountopt.PurpleAccountOption *option
69 cdef prefs.PurplePrefType type
70 cdef const_char *label_name
71 cdef const_char *str_value
72 cdef const_char *setting
74 cdef glib.gboolean bool_value
79 c_account = account.c_purple_accounts_find(username, id)
81 c_plugin = plugin.c_purple_plugins_find_with_id(id)
82 c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(c_plugin)
86 iter = c_prpl_info.protocol_options
90 option = <accountopt.PurpleAccountOption *> iter.data
91 type = accountopt.c_purple_account_option_get_type(option)
92 label_name = accountopt.c_purple_account_option_get_text(option)
93 setting = accountopt.c_purple_account_option_get_setting(option)
95 sett = str(<char *> setting)
96 label = str(<char *> label_name)
98 if type == prefs.PURPLE_PREF_STRING:
99 str_value = accountopt.c_purple_account_option_get_default_string(option)
100 # Google Talk default domain hackery!
101 if str_value == NULL and label == "Connect server":
102 str_value = "talk.google.com"
103 if c_account != NULL:
104 str_value = account.c_purple_account_get_string(c_account, setting, str_value)
106 val = str(<char *> str_value)
108 elif type == prefs.PURPLE_PREF_INT:
109 int_value = accountopt.c_purple_account_option_get_default_int(option)
112 if c_account != NULL:
113 int_value = account.c_purple_account_get_int(c_account, setting, int_value)
117 elif type == prefs.PURPLE_PREF_BOOLEAN:
118 bool_value = accountopt.c_purple_account_option_get_default_bool(option)
119 if c_account != NULL:
120 bool_value = account.c_purple_account_get_bool(c_account, setting, bool_value)
122 val = bool(bool_value)
124 elif type == prefs.PURPLE_PREF_STRING_LIST:
125 str_value = accountopt.c_purple_account_option_get_default_list_value(option)
126 if c_account != NULL:
127 str_value = account.c_purple_account_get_string(c_account, setting, str_value)
129 val = str(<char *> str_value)
133 po[sett] = (label, val)
137 def set_options(self, acc, po):
139 ''' @param id The protocol's id '''
140 ''' @param username The account's username '''
141 ''' @param po Dictionary {'setting type': str|int|bool value, ...} '''
142 ''' @return True to success or False to failure '''
144 cdef plugin.PurplePlugin *c_plugin
145 cdef prpl.PurplePluginProtocolInfo *c_prpl_info
146 cdef account.PurpleAccount *c_account
147 cdef glib.GList *iter
148 cdef accountopt.PurpleAccountOption *option
149 cdef prefs.PurplePrefType type
150 cdef const_char *str_value
151 cdef const_char *setting
153 cdef glib.gboolean bool_value
157 c_account = account.c_purple_accounts_find(acc[0], acc[1])
158 if c_account == NULL:
159 # FIXME: Message error or call a error handler
162 c_plugin = plugin.c_purple_plugins_find_with_id(acc[1])
163 c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(c_plugin)
165 iter = c_prpl_info.protocol_options
169 option = <accountopt.PurpleAccountOption *> iter.data
170 type = accountopt.c_purple_account_option_get_type(option)
171 setting = accountopt.c_purple_account_option_get_setting(option)
173 sett = str(<char *> setting)
177 if not po.has_key(sett) or not po[sett]:
180 if type == prefs.PURPLE_PREF_STRING:
182 str_value = <char *> po[sett]
183 account.c_purple_account_set_string(c_account, setting, str_value)
185 elif type == prefs.PURPLE_PREF_INT:
187 int_value = int(po[sett])
188 account.c_purple_account_set_int(c_account, setting, int_value)
190 elif type == prefs.PURPLE_PREF_BOOLEAN:
192 bool_value = bool(po[sett])
193 account.c_purple_account_set_bool(c_account, setting, bool_value)
195 elif type == prefs.PURPLE_PREF_STRING_LIST:
197 str_value = <char *> po[sett]
198 account.c_purple_account_set_string(c_account, setting, str_value)
208 self.protocols = None
210 def get_protocols(self):
212 return self.protocols
213 cdef glib.GList *iter
214 cdef plugin.PurplePlugin *pp
216 iter = plugin.c_purple_plugins_get_protocols()
218 pp = <plugin.PurplePlugin*> iter.data
219 if pp.info and pp.info.name:
220 p = Plugin(pp.info.id)
224 glib.g_list_free(iter)
225 self.protocols = protocols