Added PurpleConnectionUiOps callbacks.
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:26:42 +0000 (20:26 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:10 +0000 (17:11 -0400)
FIXES:
 - Added missing structures on connection.pxd.
 - Added connection callbacks forwarding on purple.pyx.
 - Added connection callbacks example on nullclient.py.
 - Added c-based callbacks on connection_cbs.pxd.

Signed-off-by: Bruno Abinader <bruno.abinader@indt.org.br>

git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1304 596f6dd7-e928-0410-a184-9e12fd12cf7e

connection_cbs.pxd [new file with mode: 0644]
libpurple/connection.pxd
nullclient.py
purple.pyx

diff --git a/connection_cbs.pxd b/connection_cbs.pxd
new file mode 100644 (file)
index 0000000..ca39432
--- /dev/null
@@ -0,0 +1,101 @@
+#
+#  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
+#
+#  This file is part of python-purple.
+#
+#  python-purple is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  python-purple is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+cimport purple
+
+connection_cbs = {}
+
+cdef extern from *:
+    ctypedef int size_t
+
+cdef void connect_progress (connection.PurpleConnection *gc, const_char *text,
+                            size_t step, size_t step_count):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "connect_progress\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["connect_progress"])("connect_progress")
+    except KeyError:
+        pass
+
+cdef void connected (connection.PurpleConnection *gc):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "connected\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["connected"])("connected")
+    except KeyError:
+        pass
+
+cdef void disconnected (connection.PurpleConnection *gc):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "disconnected\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["disconnected"])("disconnected")
+    except KeyError:
+        pass
+
+cdef void notice (connection.PurpleConnection *gc, const_char *text):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "notice\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["notice"])("notice")
+    except KeyError:
+        pass
+
+cdef void report_disconnect (connection.PurpleConnection *gc,
+                             const_char *text):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "report_disconnect\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["report_disconnect"])("report_disconnect")
+    except KeyError:
+        pass
+
+cdef void network_connected ():
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "network_connected\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["network_connected"])("network_connected")
+    except KeyError:
+        pass
+
+cdef void network_disconnected ():
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "network_disconnected\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["network_disconnected"])("network_disconnected")
+    except KeyError:
+        pass
+
+cdef void report_disconnect_reason (connection.PurpleConnection *gc,
+                                    connection.PurpleConnectionError reason,
+                                    const_char *text):
+    debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
+                         "report_disconnect_reason\n")
+    global connection_cbs
+    try:
+        (<object>connection_cbs["report_disconnect_reason"])("report_disconnect_reason")
+    except KeyError:
+        pass
index 510307c..1dc6c62 100644 (file)
 
 cimport account
 
+cdef extern from *:
+    ctypedef int size_t
+    ctypedef char const_char "const char"
+
 cdef extern from "libpurple/connection.h":
-    ctypedef struct PurpleConnection:
-        pass
+    ctypedef struct PurpleConnection
+
+    ctypedef enum PurpleConnectionFlags:
+        PURPLE_CONNECTION_HTML = 0x0001
+        PURPLE_CONNECTION_NO_BGCOLOR = 0x0002
+        PURPLE_CONNECTION_AUTO_RESP = 0x0004
+        PURPLE_CONNECTION_FORMATTING_WBFO = 0x0008
+        PURPLE_CONNECTION_NO_NEWLINES = 0x0010
+        PURPLE_CONNECTION_NO_FONTSIZE = 0x0020
+        PURPLE_CONNECTION_NO_URLDESC = 0x0040
+        PURPLE_CONNECTION_NO_IMAGES = 0x0080
+        PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY = 0x0100
+
+    ctypedef enum PurpleConnectionState:
+        PURPLE_DISCONNECTED = 0
+        PURPLE_CONNECTED
+        PURPLE_CONNECTING
+
+    ctypedef enum PurpleConnectionError:
+        PURPLE_CONNECTION_ERROR_NETWORK_ERROR = 0
+        PURPLE_CONNECTION_ERROR_INVALID_USERNAME = 1
+        PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED = 2
+        PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3
+        PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT = 4
+        PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR = 5
+        PURPLE_CONNECTION_ERROR_NAME_IN_USE = 6
+        PURPLE_CONNECTION_ERROR_INVALID_SETTINGS = 7
+        PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED = 8
+        PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED = 9
+        PURPLE_CONNECTION_ERROR_CERT_EXPIRED = 10
+        PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11
+        PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12
+        PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13
+        PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED = 14
+        PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR = 15
+        PURPLE_CONNECTION_ERROR_OTHER_ERROR = 16
+
+    ctypedef struct PurpleConnectionErrorInfo:
+        PurpleConnectionError type
+        char *description
 
     ctypedef struct PurpleConnectionUiOps:
+        void (*connect_progress) (PurpleConnection *gc, const_char *text, size_t step, size_t step_count)
+        void (*connected) (PurpleConnection *gc)
+        void (*disconnected) (PurpleConnection *gc)
+        void (*notice) (PurpleConnection *gc, const_char *text)
+        void (*report_disconnect) (PurpleConnection *gc, const_char *text)
+        void (*network_connected) ()
+        void (*network_disconnected) ()
+        void (*report_disconnect_reason) (PurpleConnection *gc, PurpleConnectionError reason, const_char *text)
+
+    ctypedef struct PurpleConnection:
         pass
 
     account.PurpleAccount *c_purple_connection_get_account "purple_connection_get_account" (PurpleConnection *gc)
index eafc95d..0e3a73c 100644 (file)
@@ -5,6 +5,7 @@ import sys
 
 cbs = {}
 acc_cbs = {}
+conn_cbs = {}
 conv_cbs = {}
 
 def account_callback(name):
@@ -18,6 +19,20 @@ acc_cbs["close_account_request"] = account_callback
 
 cbs["account"] = acc_cbs
 
+def conn_callback(name):
+    print "---- connection callback example: %s" % name
+
+conn_cbs["connect_progress"] = conn_callback
+conn_cbs["connected"] = conn_callback
+conn_cbs["disconnected"] = conn_callback
+conn_cbs["notice"] = conn_callback
+conn_cbs["report_disconnect"] = conn_callback
+conn_cbs["network_connected"] = conn_callback
+conn_cbs["network_disconnected"] = conn_callback
+conn_cbs["report_disconnect_reason"] = conn_callback
+
+cbs["connection"] = conn_cbs
+
 def conv_callback(name):
     print "---- conversation callback example: %s" % name
 
index 8136de8..4738762 100644 (file)
@@ -30,13 +30,16 @@ __APP_VERSION__ = "0.1"
 
 cdef core.PurpleCoreUiOps c_core_ui_ops
 cdef account.PurpleAccountUiOps c_account_ui_ops
+cdef connection.PurpleConnectionUiOps c_conn_ui_ops
 cdef conversation.PurpleConversationUiOps c_conv_ui_ops
 cdef eventloop.PurpleEventLoopUiOps c_eventloop_ui_ops
+
 cdef glib.GHashTable *c_ui_info
 
 c_ui_info = NULL
 
 include "account_cbs.pxd"
+include "connection_cbs.pxd"
 include "conversation_cbs.pxd"
 
 cdef class Purple:
@@ -80,8 +83,13 @@ cdef class Purple:
         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)
         conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops)
-        # FIXME: Add core ui initialization here
+        #notify.c_purple_notify_set_ui_ops(&c_notify_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.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "quit\n")
@@ -118,15 +126,18 @@ cdef class Purple:
         """ 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 connection_cbs
             global conversation_cbs
 
             account_cbs = callbacks_dict["account"]
+            connection_cbs = callbacks_dict["connection"]
             conversation_cbs = callbacks_dict["conversation"]
 
         c_account_ui_ops.notify_added = notify_added
@@ -135,6 +146,15 @@ cdef class Purple:
         c_account_ui_ops.request_authorize = request_authorize
         c_account_ui_ops.close_account_request = close_account_request
 
+        c_conn_ui_ops.connect_progress = connect_progress
+        c_conn_ui_ops.connected = connected
+        c_conn_ui_ops.disconnected = disconnected
+        c_conn_ui_ops.notice = notice
+        c_conn_ui_ops.report_disconnect = report_disconnect
+        c_conn_ui_ops.network_connected = network_connected
+        c_conn_ui_ops.network_disconnected = network_disconnected
+        c_conn_ui_ops.report_disconnect_reason = report_disconnect_reason
+
         c_conv_ui_ops.create_conversation = create_conversation
         c_conv_ui_ops.destroy_conversation = destroy_conversation
         c_conv_ui_ops.write_chat = write_chat