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 conversation.PurpleConversationUiOps c_conv_ui_ops
34 cdef eventloop.PurpleEventLoopUiOps c_eventloop_ui_ops
35 cdef glib.GHashTable *c_ui_info
39 include "account_cbs.pxd"
40 include "conversation_cbs.pxd"
45 @parm debug_enabled: Toggle debug messages.
46 @parm app_name: Set application name.
47 @parm default_path: Full path for libpurple user files.
50 def __init__(self, debug_enabled=True, app_name=__APP_NAME__, default_path=__DEFAULT_PATH__):
51 if app_name is not __APP_NAME__:
52 __APP_NAME__ = app_name
54 if default_path is not __DEFAULT_PATH__:
55 __DEFAULT_PATH__ = default_path
57 debug.c_purple_debug_set_enabled(debug_enabled)
58 util.c_purple_util_set_user_dir(default_path)
59 plugin.c_purple_plugins_add_search_path(default_path)
61 # adds glib iteration inside ecore main loop
62 ecore.idler_add(self.__glib_iteration_when_idle)
65 core.c_purple_core_quit()
67 cdef void __core_ui_ops_ui_prefs_init(self):
68 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "ui_prefs_init\n")
69 prefs.c_purple_prefs_load()
71 prefs.c_purple_prefs_add_none("/carman")
73 cdef void __core_ui_ops_debug_init(self):
74 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "debug_ui_init\n")
76 cdef void __core_ui_ops_ui_init(self):
77 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "ui_init\n")
79 global c_account_ui_ops
82 account.c_purple_accounts_set_ui_ops(&c_account_ui_ops)
83 conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops)
84 # FIXME: Add core ui initialization here
86 cdef void __core_ui_ops_quit(self):
87 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "core_ui_ops", "quit\n")
91 account.c_purple_accounts_set_ui_ops(NULL)
92 connection.c_purple_connections_set_ui_ops(NULL)
93 blist.c_purple_blist_set_ui_ops(NULL)
94 conversation.c_purple_conversations_set_ui_ops(NULL)
95 notify.c_purple_notify_set_ui_ops(NULL)
96 request.c_purple_request_set_ui_ops(NULL)
97 ft.c_purple_xfers_set_ui_ops(NULL)
98 roomlist.c_purple_roomlist_set_ui_ops(NULL)
101 glib.g_hash_table_destroy(c_ui_info)
103 cdef glib.GHashTable *__core_ui_ops_get_ui_info(self):
106 if c_ui_info == NULL:
107 c_ui_info = glib.g_hash_table_new(glib.g_str_hash, glib.g_str_equal)
109 glib.g_hash_table_insert(c_ui_info, "name", <glib.gpointer> __APP_NAME__)
110 glib.g_hash_table_insert(c_ui_info, "version", <glib.gpointer> __APP_VERSION__)
113 def __glib_iteration_when_idle(self):
114 glib.g_main_context_iteration(NULL, False)
117 def purple_init(self, callbacks_dict=None):
118 """ Initializes libpurple """
120 global c_account_ui_ops
123 global c_eventloop_ui_ops
125 if callbacks_dict is not None:
127 global conversation_cbs
129 account_cbs = callbacks_dict["account"]
130 conversation_cbs = callbacks_dict["conversation"]
132 c_account_ui_ops.notify_added = notify_added
133 c_account_ui_ops.status_changed = status_changed
134 c_account_ui_ops.request_add = request_add
135 c_account_ui_ops.request_authorize = request_authorize
136 c_account_ui_ops.close_account_request = close_account_request
138 c_conv_ui_ops.create_conversation = create_conversation
139 c_conv_ui_ops.destroy_conversation = destroy_conversation
140 c_conv_ui_ops.write_chat = write_chat
141 c_conv_ui_ops.write_im = write_im
142 c_conv_ui_ops.write_conv = write_conv
143 c_conv_ui_ops.chat_add_users = chat_add_users
144 c_conv_ui_ops.chat_rename_user = chat_rename_user
145 c_conv_ui_ops.chat_remove_users = chat_remove_users
146 c_conv_ui_ops.chat_update_user = chat_update_user
147 c_conv_ui_ops.present = present
148 c_conv_ui_ops.has_focus = has_focus
149 c_conv_ui_ops.custom_smiley_add = custom_smiley_add
150 c_conv_ui_ops.custom_smiley_write = custom_smiley_write
151 c_conv_ui_ops.custom_smiley_close = custom_smiley_close
152 c_conv_ui_ops.send_confirm = send_confirm
154 c_core_ui_ops.ui_prefs_init = <void (*)()> self.__core_ui_ops_ui_prefs_init
155 c_core_ui_ops.debug_ui_init = <void (*)()> self.__core_ui_ops_debug_init
156 c_core_ui_ops.ui_init = <void (*)()> self.__core_ui_ops_ui_init
157 c_core_ui_ops.quit = <void (*)()> self.__core_ui_ops_quit
158 c_core_ui_ops.get_ui_info = <glib.GHashTable* (*)()> self.__core_ui_ops_get_ui_info
160 c_eventloop_ui_ops.timeout_add = glib.g_timeout_add
161 c_eventloop_ui_ops.timeout_remove = glib.g_source_remove
162 c_eventloop_ui_ops.input_add = glib_input_add
163 c_eventloop_ui_ops.input_remove = glib.g_source_remove
164 c_eventloop_ui_ops.input_get_error = NULL
165 c_eventloop_ui_ops.timeout_add_seconds = glib.g_timeout_add_seconds
167 core.c_purple_core_set_ui_ops(&c_core_ui_ops)
168 eventloop.c_purple_eventloop_set_ui_ops(&c_eventloop_ui_ops)
170 # initialize purple core
171 ret = core.c_purple_core_init(__APP_NAME__)
173 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "main", "Exiting because libpurple initialization failed.\n")
176 # check if there is another instance of libpurple running
177 if core.c_purple_core_ensure_single_instance() == False:
178 debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "main", "Exiting because another instance of libpurple is already running.\n")
179 core.c_purple_core_quit()
182 # create and load the buddy list
183 blist.c_purple_set_blist(blist.c_purple_blist_new())
184 blist.c_purple_blist_load()
187 pounce.c_purple_pounces_load()
191 def get_protocols(self):
192 cdef glib.GList *iter
193 cdef plugin.PurplePlugin *__plugin
195 iter = plugin.c_purple_plugins_get_protocols()
197 __plugin = <plugin.PurplePlugin*> iter.data
198 if __plugin.info and __plugin.info.name:
199 protocols += [(__plugin.info.id, __plugin.info.name)]
208 include "account.pyx"
210 include "connection.pyx"
211 include "conversation.pyx"