501f39ee5ed8bbee7aeba203a58ff88905e1bd01
[python-purple] / connection_cbs.pxd
1 #
2 #  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
3 #
4 #  This file is part of python-purple.
5 #
6 #  python-purple is free software: you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation, either version 3 of the License, or
9 #  (at your option) any later version.
10 #
11 #  python-purple is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 cimport purple
21
22 cdef extern from *:
23     ctypedef char const_char "const char"
24
25 connection_cbs = {}
26
27 cdef extern from *:
28     ctypedef int size_t
29
30 cdef void connect_progress(connection.PurpleConnection *gc, const_char *text, \
31         size_t step, size_t step_count):
32     """
33     When an account is connecting, this operation is called to notify the UI
34     of what is happening, as well as which a step out of step_count has been
35     reached (which might be displayed as a progress bar).
36     """
37     debug.purple_debug_info("connection", "%s", "connect-progress\n")
38     if "connect-progress" in connection_cbs:
39         (<object> connection_cbs["connect-progress"]) \
40             (<char *> text, step, step_count)
41
42 cdef void connected(connection.PurpleConnection *gc):
43     """
44     Called when a connection is established (just before the signed-on signal).
45     """
46     debug.purple_debug_info("connection", "%s", "connected\n")
47     if "connected" in connection_cbs:
48         (<object> connection_cbs["connected"])("connected: TODO")
49
50 cdef void disconnected(connection.PurpleConnection *gc):
51     """
52     Called when a connection is ended (between the signing-off and signed-off
53     signal).
54     """
55     debug.purple_debug_info("connection", "%s", "disconnected\n")
56     if "disconnected" in connection_cbs:
57         (<object> connection_cbs["disconnected"])("disconnected: TODO")
58
59 cdef void notice(connection.PurpleConnection *gc, const_char *text):
60     """
61     Used to display connection-specific notices. (Pidgin's Gtk user interface
62     implements this as a no-op; purple_connection_notice(), which uses this
63     operation, is not used by any of the protocols shipped with libpurple.)
64     """
65     debug.purple_debug_info("connection", "%s", "notice\n")
66     if "notice" in connection_cbs:
67         (<object> connection_cbs["notice"])("notice: TODO")
68
69 cdef void report_disconnect(connection.PurpleConnection *gc, const_char *text):
70     """
71     Called when an error causes a connection to be disconnected.
72     Called before disconnected.
73     @param text  a localized error message.
74     @see purple_connection_error
75     @deprecated in favour of
76                 PurpleConnectionUiOps.report_disconnect_reason.
77     """
78     debug.purple_debug_info("connection", "%s", "report-disconnect\n")
79     if "report-disconnect" in connection_cbs:
80         (<object> connection_cbs["report-disconnect"])(<char *> text)
81
82 cdef void network_connected():
83     """
84     Called when libpurple discovers that the computer's network connection
85     is active. On Linux, this uses Network Manager if available; on Windows,
86     it uses Win32's network change notification infrastructure.
87     """
88     debug.purple_debug_info("connection", "%s", "network-connected\n")
89     if "network-connected" in connection_cbs:
90         (<object> connection_cbs["network-connected"])()
91
92 cdef void network_disconnected():
93     """
94     Called when libpurple discovers that the computer's network connection
95     has gone away.
96     """
97     debug.purple_debug_info("connection", "%s", "network-disconnected\n")
98     if "network-disconnected" in connection_cbs:
99         (<object> connection_cbs["network-disconnected"])()
100
101 cdef void report_disconnect_reason(connection.PurpleConnection *gc, \
102         connection.PurpleConnectionError reason, const_char *c_text):
103     """
104     Called when an error causes a connection to be disconnected. Called
105     before disconnected. This op is intended to replace report_disconnect.
106     If both are implemented, this will be called first; however, there's no
107     real reason to implement both.
108     @param reason  why the connection ended, if known, or
109                    PURPLE_CONNECTION_ERROR_OTHER_ERROR, if not.
110     @param text  a localized message describing the disconnection
111                  in more detail to the user.
112     @see purple_connection_error_reason
113     @since 2.3.0
114     """
115     debug.purple_debug_info("connection", "%s", "report-disconnect-reason\n")
116
117     reason_string = {
118         0: 'Network error',
119         1: 'Invalid username',
120         2: 'Authentication failed',
121         3: 'Authentication impossible',
122         4: 'No SSL support',
123         5: 'Encryption error',
124         6: 'Name in use',
125         7: 'Invalid settings',
126         8: 'Certificate not provided',
127         9: 'Certificate untrusted',
128         10: 'Certificate expired',
129         11: 'Certificate not activated',
130         12: 'Certificate hostname mismatch',
131         13: 'Certificate fingerprint mismatch',
132         14: 'Certificate self signed',
133         15: 'Certificate error (other)',
134         16: 'Other error' }[reason]
135
136     if c_text:
137         text = <char *> c_text
138     else:
139         text = None
140
141     if "report-disconnect-reason" in connection_cbs:
142         (<object> connection_cbs["report-disconnect-reason"]) \
143             (reason_string, <char *> text)