From: Ragner Magalhaes Date: Tue, 2 Dec 2008 21:05:07 +0000 (+0000) Subject: Updated connection_cbs.pxd. X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=commitdiff_plain;h=3d9932a4f305fc45e781e6d1620a864f569f3556 Updated connection_cbs.pxd. FIXES: - Replace try/except with has_key. - Added comments for each callback. - Cosmetics. Signed-off-by: Bruno Abinader git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1401 596f6dd7-e928-0410-a184-9e12fd12cf7e --- diff --git a/connection_cbs.pxd b/connection_cbs.pxd index bd36f09..b30016e 100644 --- a/connection_cbs.pxd +++ b/connection_cbs.pxd @@ -19,65 +19,98 @@ cimport purple +cdef extern from *: + ctypedef char const_char "const char" + 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): +cdef void connect_progress(connection.PurpleConnection *gc, const_char *text, \ + size_t step, size_t step_count): + """ + When an account is connecting, this operation is called to notify the UI + of what is happening, as well as which a step out of step_count has been + reached (which might be displayed as a progress bar). + """ debug.c_purple_debug_info("connection", "%s", "connect-progress\n") - try: - (connection_cbs["connect-progress"])(text, step, step_count) - except KeyError: - pass + if connection_cbs.has_key("connect-progress"): + ( connection_cbs["connect-progress"])( text, step, step_count) -cdef void connected (connection.PurpleConnection *gc): +cdef void connected(connection.PurpleConnection *gc): + """ + Called when a connection is established (just before the signed-on signal). + """ debug.c_purple_debug_info("connection", "%s", "connected\n") - try: - (connection_cbs["connected"])("connected: TODO") - except KeyError: - pass + if connection_cbs.has_key("connected"): + ( connection_cbs["connected"])("connected: TODO") -cdef void disconnected (connection.PurpleConnection *gc): +cdef void disconnected(connection.PurpleConnection *gc): + """ + Called when a connection is ended (between the signing-off and signed-off + signal). + """ debug.c_purple_debug_info("connection", "%s", "disconnected\n") - try: - (connection_cbs["disconnected"])("disconnected: TODO") - except KeyError: - pass + if connection_cbs.has_key("disconnected"): + ( connection_cbs["disconnected"])("disconnected: TODO") -cdef void notice (connection.PurpleConnection *gc, const_char *text): +cdef void notice(connection.PurpleConnection *gc, const_char *text): + """ + Used to display connection-specific notices. (Pidgin's Gtk user interface + implements this as a no-op; purple_connection_notice(), which uses this + operation, is not used by any of the protocols shipped with libpurple.) + """ debug.c_purple_debug_info("connection", "%s", "notice\n") - try: - (connection_cbs["notice"])("notice: TODO") - except KeyError: - pass + if connection_cbs.has_key("notice"): + ( connection_cbs["notice"])("notice: TODO") -cdef void report_disconnect (connection.PurpleConnection *gc, - const_char *text): +cdef void report_disconnect(connection.PurpleConnection *gc, const_char *text): + """ + Called when an error causes a connection to be disconnected. + Called before disconnected. + @param text a localized error message. + @see purple_connection_error + @deprecated in favour of + PurpleConnectionUiOps.report_disconnect_reason. + """ debug.c_purple_debug_info("connection", "%s", "report-disconnect\n") - try: - (connection_cbs["report-disconnect"])(text) - except KeyError: - pass + if connection_cbs.has_key("report-disconnect"): + ( connection_cbs["report-disconnect"])( text) -cdef void network_connected (): +cdef void network_connected(): + """ + Called when libpurple discovers that the computer's network connection + is active. On Linux, this uses Network Manager if available; on Windows, + it uses Win32's network change notification infrastructure. + """ debug.c_purple_debug_info("connection", "%s", "network-connected\n") - try: - (connection_cbs["network-connected"])("network-connected: TODO") - except KeyError: - pass + if connection_cbs.has_key("network-connected"): + ( connection_cbs["network-connected"])() -cdef void network_disconnected (): +cdef void network_disconnected(): + """ + Called when libpurple discovers that the computer's network connection + has gone away. + """ debug.c_purple_debug_info("connection", "%s", "network-disconnected\n") - try: - (connection_cbs["network-disconnected"])("network-disconnected: TODO") - except KeyError: - pass + if connection_cbs.has_key("network-disconnected"): + ( connection_cbs["network-disconnected"])() -cdef void report_disconnect_reason (connection.PurpleConnection *gc, - connection.PurpleConnectionError reason, - const_char *text): +cdef void report_disconnect_reason(connection.PurpleConnection *gc, \ + connection.PurpleConnectionError reason, const_char *text): + """ + Called when an error causes a connection to be disconnected. Called + before disconnected. This op is intended to replace report_disconnect. + If both are implemented, this will be called first; however, there's no + real reason to implement both. + @param reason why the connection ended, if known, or + PURPLE_CONNECTION_ERROR_OTHER_ERROR, if not. + @param text a localized message describing the disconnection + in more detail to the user. + @see purple_connection_error_reason + @since 2.3.0 + """ debug.c_purple_debug_info("connection", "%s", "report-disconnect-reason\n") reason_string = { @@ -99,7 +132,5 @@ cdef void report_disconnect_reason (connection.PurpleConnection *gc, 15: 'Certificate error (other)', 16: 'Other error' }[reason] - try: - (connection_cbs["report-disconnect-reason"])(reason_string, text) - except KeyError: - pass + if connection_cbs.has_key("report-disconnect-reason"): + ( connection_cbs["report-disconnect-reason"])(reason_string, text)