X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=blobdiff_plain;f=purple.pyx;h=d4d53836becf1a1192e4548ffbd6143c2308e2d1;hp=4738762dc889a6020c0aec7d5731e2bbba5e79e9;hb=54c3652ebe4f40182214f4f37403ac13fcfeb7ff;hpb=07bfe51b3e6afa82ca011f8a4c29fb4d669ed848;ds=sidebyside diff --git a/purple.pyx b/purple.pyx index 4738762..d4d5383 100644 --- a/purple.pyx +++ b/purple.pyx @@ -28,19 +28,32 @@ __DEFAULT_PATH__ = "/tmp" __APP_NAME__ = "carman-purple-python" __APP_VERSION__ = "0.1" -cdef core.PurpleCoreUiOps c_core_ui_ops cdef account.PurpleAccountUiOps c_account_ui_ops +cdef blist.PurpleBlistUiOps c_blist_ui_ops cdef connection.PurpleConnectionUiOps c_conn_ui_ops cdef conversation.PurpleConversationUiOps c_conv_ui_ops +cdef core.PurpleCoreUiOps c_core_ui_ops cdef eventloop.PurpleEventLoopUiOps c_eventloop_ui_ops +#cdef ft.PurpleXferUiOps c_ft_ui_ops +cdef notify.PurpleNotifyUiOps c_notify_ui_ops +#cdef privacy.PurplePrivacyUiOps c_privacy_ui_ops +cdef request.PurpleRequestUiOps c_request_ui_ops +#cdef roomlist.PurpleRoomlistUiOps c_rlist_ui_ops cdef glib.GHashTable *c_ui_info c_ui_info = NULL include "account_cbs.pxd" +include "blist_cbs.pxd" include "connection_cbs.pxd" include "conversation_cbs.pxd" +#include "xfer_cbs.pxd" +include "notify_cbs.pxd" +#include "privacy_cbs.pxd" +include "request_cbs.pxd" +#include "roomlist_cbs.pxd" +include "signal_cbs.pxd" cdef class Purple: """ Purple class. @@ -50,7 +63,10 @@ cdef class Purple: @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 @@ -62,9 +78,9 @@ cdef class Purple: plugin.c_purple_plugins_add_search_path(default_path) # adds glib iteration inside ecore main loop - ecore.idler_add(self.__glib_iteration_when_idle) + ecore.timer_add(0.001, self.__glib_iteration_when_idle) - def __del__(self): + def destroy(self): core.c_purple_core_quit() cdef void __core_ui_ops_ui_prefs_init(self): @@ -79,15 +95,13 @@ cdef class Purple: cdef void __core_ui_ops_ui_init(self): debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "ui_init\n") - global c_account_ui_ops - global c_conv_ui_ops - account.c_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) + 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) - #request.c_purple_request_set_ui_ops(&c_request_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) @@ -101,9 +115,10 @@ cdef class Purple: 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) + #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) @@ -125,20 +140,18 @@ cdef class Purple: def purple_init(self, callbacks_dict=None): """ Initializes libpurple """ - global c_account_ui_ops - global c_conn_ui_ops - global c_conv_ui_ops - global c_core_ui_ops - global c_eventloop_ui_ops - if callbacks_dict is not None: - global account_cbs + global blist_cbs global connection_cbs global conversation_cbs + global notify_cbs + global request_cbs - account_cbs = callbacks_dict["account"] + blist_cbs = callbacks_dict["blist"] connection_cbs = callbacks_dict["connection"] conversation_cbs = callbacks_dict["conversation"] + notify_cbs = callbacks_dict["notify"] + request_cbs = callbacks_dict["request"] c_account_ui_ops.notify_added = notify_added c_account_ui_ops.status_changed = status_changed @@ -146,6 +159,17 @@ cdef class Purple: c_account_ui_ops.request_authorize = request_authorize c_account_ui_ops.close_account_request = close_account_request + c_blist_ui_ops.new_list = new_list + c_blist_ui_ops.new_node = new_node + c_blist_ui_ops.show = show + c_blist_ui_ops.update = update + c_blist_ui_ops.remove = remove + c_blist_ui_ops.destroy = destroy + c_blist_ui_ops.set_visible = set_visible + c_blist_ui_ops.request_add_buddy = request_add_buddy + c_blist_ui_ops.request_add_chat = request_add_chat + c_blist_ui_ops.request_add_group = request_add_group + c_conn_ui_ops.connect_progress = connect_progress c_conn_ui_ops.connected = connected c_conn_ui_ops.disconnected = disconnected @@ -171,6 +195,24 @@ cdef class Purple: c_conv_ui_ops.custom_smiley_close = custom_smiley_close c_conv_ui_ops.send_confirm = send_confirm + c_notify_ui_ops.notify_message = notify_message + c_notify_ui_ops.notify_email = notify_email + c_notify_ui_ops.notify_emails = notify_emails + c_notify_ui_ops.notify_formatted = notify_formatted + c_notify_ui_ops.notify_searchresults = notify_searchresults + c_notify_ui_ops.notify_searchresults_new_rows = notify_searchresults_new_rows + c_notify_ui_ops.notify_userinfo = notify_userinfo + c_notify_ui_ops.notify_uri = notify_uri + c_notify_ui_ops.close_notify = close_notify + + c_request_ui_ops.request_input = request_input + c_request_ui_ops.request_choice = request_choice + c_request_ui_ops.request_action = request_action + c_request_ui_ops.request_fields = request_fields + c_request_ui_ops.request_file = request_file + c_request_ui_ops.close_request = close_request + c_request_ui_ops.request_folder = request_folder + c_core_ui_ops.ui_prefs_init = self.__core_ui_ops_ui_prefs_init c_core_ui_ops.debug_ui_init = self.__core_ui_ops_debug_init c_core_ui_ops.ui_init = self.__core_ui_ops_ui_init @@ -182,7 +224,7 @@ cdef class Purple: c_eventloop_ui_ops.input_add = glib_input_add c_eventloop_ui_ops.input_remove = glib.g_source_remove c_eventloop_ui_ops.input_get_error = NULL - c_eventloop_ui_ops.timeout_add_seconds = glib.g_timeout_add_seconds + c_eventloop_ui_ops.timeout_add_seconds = NULL core.c_purple_core_set_ui_ops(&c_core_ui_ops) eventloop.c_purple_eventloop_set_ui_ops(&c_eventloop_ui_ops) @@ -208,22 +250,82 @@ cdef class Purple: return ret - def get_protocols(self): - cdef glib.GList *iter - cdef plugin.PurplePlugin *__plugin - protocols = [] - iter = plugin.c_purple_plugins_get_protocols() - while iter: - __plugin = iter.data - if __plugin.info and __plugin.info.name: - protocols += [(__plugin.info.id, __plugin.info.name)] - iter = iter.next - return protocols + def add_account_cb(self, name, func): + global account_cbs + account_cbs[name] = func def connect(self): conn = Connection() conn.connect() + def signal_connect(self, name=None, cb=None): + cdef int handle + cdef plugin.PurplePlugin *jabber + + if name is None: + return + + jabber = prpl.c_purple_find_prpl("prpl-jabber") + if jabber == NULL: + return + + global signal_cbs + signal_cbs[name] = cb + + if name == "buddy-signed-off": + signals.c_purple_signal_connect( + blist.c_purple_blist_get_handle(), + "buddy-signed-off", &handle, + signal_buddy_signed_off_cb, NULL) + elif name == "receiving-im-msg": + signals.c_purple_signal_connect( + conversation.c_purple_conversations_get_handle(), + "receiving-im-msg", &handle, + signal_receiving_im_msg_cb, NULL) + elif name == "jabber-receiving-xmlnode": + signals.c_purple_signal_connect( + jabber, "jabber-receiving-xmlnode", &handle, + jabber_receiving_xmlnode_cb, NULL) + + def new_account(self, username, protocol_id): + acc = Account(username, protocol_id) + return acc + + def accounts_init(self): + cdef glib.GList *iter + cdef account.PurpleAccount *acc + iter = account.c_purple_accounts_get_all() + while iter: + acc = iter.data + if acc: + self.account_add(acc.username.split("/")[0], acc.protocol_id, "172.18.216.211", 8080) + iter = iter.next + + def account_add(self, username, protocol_id, host, port): + if not self.account_verify(username): + acc = purple.Account(username, protocol_id) + self.accounts_add_dict(username, acc) + if not account.c_purple_accounts_find(username, protocol_id): + acc.proxy.set_type(purple.ProxyInfoType().HTTP) + acc.proxy.set_host(host) + acc.proxy.set_port(port) + acc.save_into_xml() + else: + print "Exists account" + + def account_verify(self, acc_username): + if self.accounts: + for username in self.accounts.keys(): + if acc_username == username: + return self.accounts[username] + return None + + def accounts_add_dict(self, username, acc): + self.accounts[username] = acc + + def accounts_get_dict(self): + return self.accounts + include "proxy.pyx" include "account.pyx" include "buddy.pyx"