Added initial support for user-specified conversation callbacks.
[python-purple] / account.pyx
1 #
2 #  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
3 #
4 #  This file is part of python-purple.
5 #
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.
10 #
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.
15 #
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/>.
18 #
19
20 cimport purple
21 cimport proxy
22
23 cdef class Account:
24     """ Account class """
25     cdef account.PurpleAccount *__account
26     cdef savedstatuses.PurpleSavedStatus *__sstatus
27
28     def __init__(self, char *username, char *protocol_id):
29         self.__account = account.c_purple_account_new(username, protocol_id)
30
31     def set_password(self, password):
32         account.c_purple_account_set_password(self.__account, password)
33
34     def set_enabled(self, ui, value):
35         account.c_purple_account_set_enabled(self.__account, ui, value)
36
37     def get_acc_username(self):
38         if self.__account:
39             return account.c_purple_account_get_username(self.__account)
40
41     def get_password(self):
42         if self.__account:
43             return account.c_purple_account_get_password(self.__account)
44
45     def set_status(self):
46         self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
47         savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
48
49     def get_buddies_online(self):
50         cdef glib.GSList *iter
51         cdef blist.PurpleBuddy *buddy
52         buddies = []
53         iter = blist.c_purple_find_buddies(self.__account, NULL)
54         while iter:
55             buddy = <blist.PurpleBuddy *> iter.data
56             if <blist.PurpleBuddy *>buddy and \
57                 account.c_purple_account_is_connected(blist.c_purple_buddy_get_account(buddy)) and \
58                 status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(buddy)):
59                 buddies += [buddy.name]
60             iter = iter.next
61         return buddies
62
63     def get_proxyinfo(self):
64         cdef proxy.PurpleProxyInfo *c_proxyinfo
65         c_proxyinfo = account.c_purple_account_get_proxy_info(self.__account)
66         if c_proxyinfo == NULL:
67             return None
68         cdef ProxyInfo proxyinfo
69         proxyinfo = proxy.ProxyInfo()
70         proxyinfo.c_proxyinfo = c_proxyinfo
71         return proxyinfo
72
73     def set_proxyinfo(self, ProxyInfo proxyinf):
74         account.c_purple_account_set_proxy_info(self.__account, proxyinf.c_proxyinfo)