X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=blobdiff_plain;f=account.pyx;h=407dc4ec8c3c1abd9ae3b6b7f39b3dfb61df4724;hp=0e985488f3149eb6f3c8780fd806095ab8af4dbe;hb=5f1088fe97ce236fcb720c47d4a1122cb9bca8ec;hpb=e7e4e8ff4937aed9c1b732719bc310c3e8a88f5e
diff --git a/account.pyx b/account.pyx
index 0e98548..407dc4e 100644
--- a/account.pyx
+++ b/account.pyx
@@ -17,49 +17,502 @@
# along with this program. If not, see .
#
-cimport glib
-
-cimport account
-cimport blist
-cimport savedstatuses
-cimport status
+cimport purple
cdef class Account:
- """ Account class """
- cdef account.PurpleAccount *__account
- cdef savedstatuses.PurpleSavedStatus *__sstatus
+ """
+ Account class
+ @param username
+ @param protocol Protocol class instance
+ @param core Purple class instance
+ """
- def __cinit__(self, char *username, char *protocol_id):
- self.__account = account.c_purple_account_new(username, protocol_id)
+ cdef object __username
+ cdef object __protocol
+ cdef object __core
+ cdef object __exists
- def set_password(self, password):
- account.c_purple_account_set_password(self.__account, password)
+ def __init__(self, username, protocol, core):
+ self.__username = username
+ self.__protocol = protocol
+ self.__core = core
+
+ if protocol.exists and self._get_structure() != NULL:
+ self.__exists = True
+ else:
+ self.__exists = False
+
+ cdef account.PurpleAccount *_get_structure(self):
+ return account.purple_accounts_find(self.__username, \
+ self.__protocol.id)
+
+ def __is_connected(self):
+ if self.__exists:
+ return account.purple_account_is_connected(self._get_structure())
+ else:
+ return None
+ is_connected = property(__is_connected)
+
+ def __is_connecting(self):
+ if self.__exists:
+ return account.purple_account_is_connecting(self._get_structure())
+ else:
+ return None
+ is_connecting = property(__is_connecting)
+
+ def __is_disconnected(self):
+ if self.__exists:
+ return account.purple_account_is_disconnected( \
+ self._get_structure())
+ else:
+ return None
+ is_disconnected = property(__is_disconnected)
+
+ def __get_core(self):
+ return self.__core
+ core = property(__get_core)
+
+ def __get_exists(self):
+ return self.__exists
+ exists = property(__get_exists)
+
+ def __get_username(self):
+ cdef char *username = NULL
+ if self.__exists:
+ username = account.purple_account_get_username( \
+ self._get_structure())
+ if username:
+ return username
+ else:
+ return None
+ else:
+ return self.__username
+ username = property(__get_username)
+
+ def __get_protocol(self):
+ return self.__protocol
+ protocol = property(__get_protocol)
+
+ def _get_protocol_options(self):
+ """
+ @return Dictionary {'setting': value, ...}
+ """
+ cdef glib.GList *iter
+ cdef account.PurpleAccount *c_account
+ cdef plugin.PurplePlugin *c_plugin
+ cdef prpl.PurplePluginProtocolInfo *prpl_info
+ cdef accountopt.PurpleAccountOption *option
+ cdef prefs.PurplePrefType type
+ cdef char *label_name
+ cdef char *str_value
+ cdef char *setting
+ cdef int int_value
+ cdef glib.gboolean bool_value
- def set_enabled(self, ui, value):
- account.c_purple_account_set_enabled(self.__account, ui, value)
+ c_account = self._get_structure()
- def get_acc_username(self):
- if self.__account:
- return account.c_purple_account_get_username(self.__account)
+ if c_account == NULL:
+ return None
- def get_password(self):
- if self.__account:
- return account.c_purple_account_get_password(self.__account)
+ po = {}
- def set_status(self):
- self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
- savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
+ c_plugin = plugin.purple_plugins_find_with_id(self.__protocol.id)
+ prpl_info = plugin.PURPLE_PLUGIN_PROTOCOL_INFO(c_plugin)
+ iter = prpl_info.protocol_options
- def get_buddies_online(self, acc):
- cdef glib.GSList *iter
- cdef blist.PurpleBuddy *buddy
- buddies = []
- iter = blist.c_purple_find_buddies(self.__account, NULL)
while iter:
- buddy = iter.data
- if