+include "util.pxd"
+
+cdef class Purple:
+ """ Purple class.
+
+ @parm debug_enabled: Toggle debug messages.
+ @parm app_name: Set application name.
+ @parm default_path: Full path for libpurple user files.
+ """
+
+ cdef object __accounts
+
+ def __init__(self, debug_enabled=True, app_name=__APP_NAME__, default_path=__DEFAULT_PATH__):
+ self.__accounts = {}
+ if app_name is not __APP_NAME__:
+ __APP_NAME__ = app_name
+
+ if default_path is not __DEFAULT_PATH__:
+ __DEFAULT_PATH__ = default_path
+
+ debug.purple_debug_set_enabled(debug_enabled)
+ util.purple_util_set_user_dir(default_path)
+ plugin.c_purple_plugins_add_search_path(default_path)
+
+ # adds glib iteration inside ecore main loop
+ ecore.timer_add(0.001, self.__glib_iteration_when_idle)
+
+ def __get_ui_name(self):
+ return __APP_NAME__
+ ui_name = property(__get_ui_name)
+
+ def destroy(self):
+ core.c_purple_core_quit()
+
+ cdef void __core_ui_ops_ui_prefs_init(self):
+ debug.purple_debug_info("core_ui_ops", "%s", "ui_prefs_init\n")
+ prefs.c_purple_prefs_load()
+
+ prefs.c_purple_prefs_add_none("/carman")
+
+ cdef void __core_ui_ops_debug_init(self):
+ debug.purple_debug_info("core_ui_ops", "%s", "debug_ui_init\n")
+ pass
+
+ cdef void __core_ui_ops_ui_init(self):
+ debug.purple_debug_info("core_ui_ops", "%s", "ui_init\n")
+
+ account.purple_accounts_set_ui_ops(&c_account_ui_ops)
+ connection.c_purple_connections_set_ui_ops(&c_conn_ui_ops)
+ blist.c_purple_blist_set_ui_ops(&c_blist_ui_ops)
+ conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops)
+ notify.c_purple_notify_set_ui_ops(&c_notify_ui_ops)
+ #privacy.c_purple_privacy_set_ui_ops(&c_privacy_ui_ops)
+ request.c_purple_request_set_ui_ops(&c_request_ui_ops)
+ #ft.c_purple_xfers_set_ui_ops(&c_ft_ui_ops)
+ #roomlist.c_purple_roomlist_set_ui_ops(&c_rlist_ui_ops)
+
+ cdef void __core_ui_ops_quit(self):
+ debug.purple_debug_info("core_ui_ops", "%s", "quit\n")
+
+ global c_ui_info
+
+ account.purple_accounts_set_ui_ops(NULL)
+ connection.c_purple_connections_set_ui_ops(NULL)
+ blist.c_purple_blist_set_ui_ops(NULL)
+ conversation.c_purple_conversations_set_ui_ops(NULL)
+ notify.c_purple_notify_set_ui_ops(NULL)
+ #privacy.c_purple_privacy_set_ui_ops(NULL)
+ request.c_purple_request_set_ui_ops(NULL)
+ #ft.c_purple_xfers_set_ui_ops(NULL)
+ #roomlist.c_purple_roomlist_set_ui_ops(NULL)
+
+ if c_ui_info:
+ glib.g_hash_table_destroy(c_ui_info)
+
+ cdef glib.GHashTable *__core_ui_ops_get_ui_info(self):
+ global c_ui_info
+
+ if c_ui_info == NULL:
+ c_ui_info = glib.g_hash_table_new(glib.g_str_hash, glib.g_str_equal)
+
+ glib.g_hash_table_insert(c_ui_info, "name", <glib.gpointer> __APP_NAME__)
+ glib.g_hash_table_insert(c_ui_info, "version", <glib.gpointer> __APP_VERSION__)
+ return c_ui_info
+
+ def __glib_iteration_when_idle(self):
+ glib.g_main_context_iteration(NULL, False)
+ return True
+
+ def purple_init(self):
+ """ Initializes libpurple """
+
+ c_account_ui_ops.notify_added = notify_added
+ c_account_ui_ops.status_changed = status_changed
+ c_account_ui_ops.request_add = request_add
+ c_account_ui_ops.request_authorize = request_authorize
+ c_account_ui_ops.close_account_request = close_account_request