Fixing cython error to purple_account_set_status bind
[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
22 from protocol import Protocol
23
24 cdef class Account:
25     """
26     Account class
27     @param username
28     @param protocol_id
29     """
30
31     def __init__(self, username, protocol_id):
32         self.__username = username
33         self.__protocol = Protocol(self, protocol_id)
34
35         if self._get_structure() == NULL:
36             self.__exists = False
37         else:
38             self.__exists = True
39
40     cdef account.PurpleAccount *_get_structure(self):
41         return account.purple_accounts_find(self.username, \
42                 self.protocol_id)
43
44     def __get_exists(self):
45         return self.__exists
46     exists = property(__get_exists)
47
48     def __get_username(self):
49         cdef char *username = NULL
50         if self.__exists:
51             username = <char *> account.purple_account_get_username( \
52                     self._get_structure())
53             if username:
54                 return username
55             else:
56                 return None
57         else:
58             return self.__username
59     username = property(__get_username)
60
61     def __get_protocol_id(self):
62         cdef char *protocol_id = NULL
63         if self.__exists:
64             protocol_id = <char *> account.purple_account_get_protocol_id( \
65                     self._get_structure())
66             if protocol_id:
67                 return protocol_id
68             else:
69                 return None
70         else:
71             return self.protocol_id
72     protocol_id = property(__get_protocol_id)
73
74     def __get_password(self):
75         cdef char *password = NULL
76         if self.__exists:
77             password = <char *> account.purple_account_get_password( \
78                     self._get_structure())
79             if password:
80                 return password
81             else:
82                 return None
83         else:
84             return None
85     def __set_password(self, password):
86         if self.__exists:
87             account.purple_account_set_password(self._get_structure(), \
88                     password)
89             return True
90         else:
91             return False
92     password = property(__get_password, __set_password)
93
94     def __get_alias(self):
95         cdef char *alias = NULL
96         if self.__exists:
97             alias = <char *> account.purple_account_get_alias(self._get_structure())
98             if alias:
99                 return alias
100             else:
101                 return None
102         else:
103             return None
104     def __set_alias(self, alias):
105         if self.__exists:
106             account.purple_account_set_alias(self._get_structure(), \
107                     alias)
108             return True
109         else:
110             return False
111     alias = property(__get_alias, __set_alias)
112
113     def __get_user_info(self):
114         cdef char *user_info = NULL
115         if self.__exists:
116             user_info = <char *> account.purple_account_get_user_info(self._get_structure())
117             if user_info:
118                 return user_info
119             else:
120                 return None
121         else:
122             return None
123     def __set_user_info(self, user_info):
124         if self.__exists:
125             account.purple_account_set_user_info(self._get_structure(), \
126                     user_info)
127             return True
128         else:
129             return False
130     user_info = property(__get_user_info, __set_user_info)
131
132     def __get_remember_password(self):
133         if self.__exists:
134             return account.purple_account_get_remember_password( \
135                     self._get_structure())
136         else:
137             return None
138     def __set_remember_password(self, remember_password):
139         if self.__exists:
140             account.purple_account_set_remember_password( \
141                 self._get_structure(), remember_password)
142             return True
143         else:
144             return False
145     remember_password = property(__get_remember_password, \
146             __set_remember_password)
147
148     def set_username(self, username):
149         if self.__exists:
150             account.purple_account_set_username(self._get_structure(), \
151                     username)
152             return True
153         else:
154             return False
155
156     def set_protocol_id(self, protocol_id):
157         if self.__exists:
158             self.__protocol._set_protocol_id(protocol_id)
159             return True
160         else:
161             return False
162
163     def new(self):
164         if self.__exists:
165             return False
166         else:
167             account.purple_account_new(self.username, self.protocol_id)
168             self.__exists = True
169             return True