2 # Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
4 # This file is part of python-purple.
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.
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.
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/>.
22 cdef extern from "c_purple.h":
23 glib.guint glib_input_add(glib.gint fd, eventloop.PurpleInputCondition condition, eventloop.PurpleInputFunction function, glib.gpointer data)
27 __DEFAULT_PATH__ = "/tmp"
28 __APP_NAME__ = "carman-purple-python"
29 __APP_VERSION__ = "0.1"
31 cdef core.PurpleCoreUiOps c_core_ui_ops
32 cdef account.PurpleAccountUiOps c_account_ui_ops
33 cdef connection.PurpleConnectionUiOps c_conn_ui_ops
34 cdef conversation.PurpleConversationUiOps c_conv_ui_ops
35 cdef eventloop.PurpleEventLoopUiOps c_eventloop_ui_ops
37 cdef glib.GHashTable *c_ui_info
41 include "account_cbs.pxd"
42 include "connection_cbs.pxd"
43 include "conversation_cbs.pxd"
48 @parm debug_enabled: Toggle debug messages.
49 @parm app_name: Set application name.
50 @parm default_path: Full path for libpurple user files.
53 def __init__(self, debug_enabled=True, app_name=__APP_NAME__, default_path=__DEFAULT_PATH__):
54 if app_name is not __APP_NAME__:
55 __APP_NAME__ = app_name
57 if default_path is not __DEFAULT_PATH__:
58 __DEFAULT_PATH__ = default_path
60 debug.c_purple_debug_set_enabled(debug_enabled)
61 util.c_purple_util_set_user_dir(default_path)
62 plugin.c_purple_plugins_add_search_path(default_path)
64 # adds glib iteration inside ecore main loop
65 ecore.idler_add(self.__glib_iteration_when_idle)
68 core.c_purple_core_quit()
70 cdef void __core_ui_ops_ui_prefs_init(self):
71 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "ui_prefs_init\n")
72 prefs.c_purple_prefs_load()
74 prefs.c_purple_prefs_add_none("/carman")
76 cdef void __core_ui_ops_debug_init(self):
77 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "debug_ui_init\n")
79 cdef void __core_ui_ops_ui_init(self):
80 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "ui_init\n")
82 global c_account_ui_ops
85 account.c_purple_accounts_set_ui_ops(&c_account_ui_ops)
86 connection.c_purple_connections_set_ui_ops(&c_conn_ui_ops)
87 #blist.c_purple_blist_set_ui_ops(&c_blist_ui_ops)
88 conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops)
89 #notify.c_purple_notify_set_ui_ops(&c_notify_ui_ops)
90 #request.c_purple_request_set_ui_ops(&c_request_ui_ops)
91 #ft.c_purple_xfers_set_ui_ops(&c_ft_ui_ops)
92 #roomlist.c_purple_roomlist_set_ui_ops(&c_rlist_ui_ops)
94 cdef void __core_ui_ops_quit(self):
95 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "quit\n")
99 account.c_purple_accounts_set_ui_ops(NULL)
100 connection.c_purple_connections_set_ui_ops(NULL)
101 blist.c_purple_blist_set_ui_ops(NULL)
102 conversation.c_purple_conversations_set_ui_ops(NULL)
103 notify.c_purple_notify_set_ui_ops(NULL)
104 request.c_purple_request_set_ui_ops(NULL)
105 ft.c_purple_xfers_set_ui_ops(NULL)
106 roomlist.c_purple_roomlist_set_ui_ops(NULL)
109 glib.g_hash_table_destroy(c_ui_info)
111 cdef glib.GHashTable *__core_ui_ops_get_ui_info(self):
114 if c_ui_info == NULL:
115 c_ui_info = glib.g_hash_table_new(glib.g_str_hash, glib.g_str_equal)
117 glib.g_hash_table_insert(c_ui_info, "name", <glib.gpointer> __APP_NAME__)
118 glib.g_hash_table_insert(c_ui_info, "version", <glib.gpointer> __APP_VERSION__)
121 def __glib_iteration_when_idle(self):
122 glib.g_main_context_iteration(NULL, False)
125 def purple_init(self, callbacks_dict=None):
126 """ Initializes libpurple """
128 global c_account_ui_ops
132 global c_eventloop_ui_ops
134 if callbacks_dict is not None:
136 global connection_cbs
137 global conversation_cbs
139 account_cbs = callbacks_dict["account"]
140 connection_cbs = callbacks_dict["connection"]
141 conversation_cbs = callbacks_dict["conversation"]
143 c_account_ui_ops.notify_added = notify_added
144 c_account_ui_ops.status_changed = status_changed
145 c_account_ui_ops.request_add = request_add
146 c_account_ui_ops.request_authorize = request_authorize
147 c_account_ui_ops.close_account_request = close_account_request
149 c_conn_ui_ops.connect_progress = connect_progress
150 c_conn_ui_ops.connected = connected
151 c_conn_ui_ops.disconnected = disconnected
152 c_conn_ui_ops.notice = notice
153 c_conn_ui_ops.report_disconnect = report_disconnect
154 c_conn_ui_ops.network_connected = network_connected
155 c_conn_ui_ops.network_disconnected = network_disconnected
156 c_conn_ui_ops.report_disconnect_reason = report_disconnect_reason
158 c_conv_ui_ops.create_conversation = create_conversation
159 c_conv_ui_ops.destroy_conversation = destroy_conversation
160 c_conv_ui_ops.write_chat = write_chat
161 c_conv_ui_ops.write_im = write_im
162 c_conv_ui_ops.write_conv = write_conv
163 c_conv_ui_ops.chat_add_users = chat_add_users
164 c_conv_ui_ops.chat_rename_user = chat_rename_user
165 c_conv_ui_ops.chat_remove_users = chat_remove_users
166 c_conv_ui_ops.chat_update_user = chat_update_user
167 c_conv_ui_ops.present = present
168 c_conv_ui_ops.has_focus = has_focus
169 c_conv_ui_ops.custom_smiley_add = custom_smiley_add
170 c_conv_ui_ops.custom_smiley_write = custom_smiley_write
171 c_conv_ui_ops.custom_smiley_close = custom_smiley_close
172 c_conv_ui_ops.send_confirm = send_confirm
174 c_core_ui_ops.ui_prefs_init = <void (*)()> self.__core_ui_ops_ui_prefs_init
175 c_core_ui_ops.debug_ui_init = <void (*)()> self.__core_ui_ops_debug_init
176 c_core_ui_ops.ui_init = <void (*)()> self.__core_ui_ops_ui_init
177 c_core_ui_ops.quit = <void (*)()> self.__core_ui_ops_quit
178 c_core_ui_ops.get_ui_info = <glib.GHashTable* (*)()> self.__core_ui_ops_get_ui_info
180 c_eventloop_ui_ops.timeout_add = glib.g_timeout_add
181 c_eventloop_ui_ops.timeout_remove = glib.g_source_remove
182 c_eventloop_ui_ops.input_add = glib_input_add
183 c_eventloop_ui_ops.input_remove = glib.g_source_remove
184 c_eventloop_ui_ops.input_get_error = NULL
185 c_eventloop_ui_ops.timeout_add_seconds = glib.g_timeout_add_seconds
187 core.c_purple_core_set_ui_ops(&c_core_ui_ops)
188 eventloop.c_purple_eventloop_set_ui_ops(&c_eventloop_ui_ops)
190 # initialize purple core
191 ret = core.c_purple_core_init(__APP_NAME__)
193 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "main", "Exiting because libpurple initialization failed.\n")
196 # check if there is another instance of libpurple running
197 if core.c_purple_core_ensure_single_instance() == False:
198 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "main", "Exiting because another instance of libpurple is already running.\n")
199 core.c_purple_core_quit()
202 # create and load the buddy list
203 blist.c_purple_set_blist(blist.c_purple_blist_new())
204 blist.c_purple_blist_load()
207 pounce.c_purple_pounces_load()
211 def get_protocols(self):
212 cdef glib.GList *iter
213 cdef plugin.PurplePlugin *__plugin
215 iter = plugin.c_purple_plugins_get_protocols()
217 __plugin = <plugin.PurplePlugin*> iter.data
218 if __plugin.info and __plugin.info.name:
219 protocols += [(__plugin.info.id, __plugin.info.name)]
228 include "account.pyx"
230 include "connection.pyx"
231 include "conversation.pyx"