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/>.
23 ctypedef char* const_char_ptr "const char *"
25 cdef extern from "time.h":
26 ctypedef long int time_t
28 cdef extern from "libpurple/core.h":
29 ctypedef struct PurpleCoreUiOps:
30 void (*ui_prefs_init) ()
31 void (*debug_ui_init) ()
34 GHashTable (*get_ui_info) ()
36 gboolean c_purple_core_init "purple_core_init" (const_char_ptr ui_name)
37 void c_purple_core_quit "purple_core_quit" ()
38 void c_purple_core_set_ui_ops "purple_core_set_ui_ops" (PurpleCoreUiOps *ops)
39 gboolean c_purple_core_ensure_single_instance "purple_core_ensure_single_instance" ()
41 cdef extern from "libpurple/debug.h":
42 ctypedef enum PurpleDebugLevel:
50 void c_purple_debug "purple_debug" (PurpleDebugLevel level, const_char_ptr category, const_char_ptr format)
51 void c_purple_debug_set_enabled "purple_debug_set_enabled" (gboolean debug_enabled)
53 cdef extern from "libpurple/eventloop.h":
54 ctypedef enum PurpleInputCondition:
58 ctypedef void (*PurpleInputFunction) (gpointer , gint, PurpleInputCondition)
60 ctypedef struct PurpleEventLoopUiOps:
61 guint (*timeout_add) (guint interval, GSourceFunc function, gpointer data)
62 gboolean (*timeout_remove) (guint handle)
63 guint (*input_add) (int fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer user_data)
64 gboolean (*input_remove) (guint handle)
65 int (*input_get_error) (int fd, int *error)
66 guint (*timeout_add_seconds)(guint interval, GSourceFunc function, gpointer data)
68 void c_purple_eventloop_set_ui_ops "purple_eventloop_set_ui_ops" (PurpleEventLoopUiOps *ops)
70 cdef extern from "libpurple/plugin.h":
71 void c_purple_plugins_add_search_path "purple_plugins_add_search_path" (const_char_ptr path)
73 cdef extern from "libpurple/prefs.h":
74 void c_purple_prefs_rename "purple_prefs_rename" (const_char_ptr oldname, const_char_ptr newname)
75 const_char_ptr c_purple_prefs_get_string "purple_prefs_get_string" (const_char_ptr name)
76 gboolean c_purple_prefs_load "purple_prefs_load" ()
78 cdef extern from "libpurple/util.h":
79 void c_purple_util_set_user_dir "purple_util_set_user_dir" (char *dir)
81 cdef extern from "c_purple.h":
83 guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data)
85 __DEFAULT_PATH__ = "/home/user/MyDocs/Carman"
86 __APP_NAME__ = "carman-purple-python"
87 __APP_VERSION__ = "0.1"
89 global __DEFAULT_PATH__
92 def debug_misc(category, format):
94 c_purple_debug(PURPLE_DEBUG_MISC, NULL, format)
96 c_purple_debug(PURPLE_DEBUG_MISC, category, format)
99 def debug_info(category, format):
101 c_purple_debug(PURPLE_DEBUG_INFO, NULL, format)
103 c_purple_debug(PURPLE_DEBUG_INFO, category, format)
106 def debug_warning(category, format):
108 c_purple_debug(PURPLE_DEBUG_WARNING, NULL, format)
110 c_purple_debug(PURPLE_DEBUG_WARNING, category, format)
113 def debug_error(category, format):
115 c_purple_debug(PURPLE_DEBUG_ERROR, NULL, format)
117 c_purple_debug(PURPLE_DEBUG_ERROR, category, format)
120 def debug_fatal(category, format):
122 c_purple_debug(PURPLE_DEBUG_FATAL, NULL, format)
124 c_purple_debug(PURPLE_DEBUG_FATAL, category, format)
127 cdef void core_ui_ops_ui_prefs_init():
128 debug_info("core_ui_ops", "ui_prefs_init")
129 # core_ui_ops_ui_prefs_init
131 cdef void core_ui_ops_debug_ui_init():
132 debug_info("core_ui_ops", "debug_ui_init")
133 # core_ui_ops_debug_ui_init
135 cdef void core_ui_ops_ui_init():
136 debug_info("core_ui_ops", "ui_init")
137 # core_ui_ops_ui_init
139 cdef void core_ui_ops_quit():
140 debug_info("core_ui_ops", "quit")
145 cdef PurpleCoreUiOps c_core_ui_ops
146 c_core_ui_ops.ui_prefs_init = core_ui_ops_ui_prefs_init
147 c_core_ui_ops.debug_ui_init = core_ui_ops_debug_ui_init
148 c_core_ui_ops.ui_init = core_ui_ops_ui_init
149 c_core_ui_ops.quit = core_ui_ops_quit
150 c_core_ui_ops.get_ui_info = NULL # FIXME
152 cdef PurpleEventLoopUiOps c_eventloop_ui_ops
153 c_eventloop_ui_ops.timeout_add = g_timeout_add
154 c_eventloop_ui_ops.timeout_remove = g_source_remove
155 c_eventloop_ui_ops.input_add = glib_input_add
156 c_eventloop_ui_ops.input_remove = g_source_remove
157 c_eventloop_ui_ops.input_get_error = NULL
158 c_eventloop_ui_ops.timeout_add_seconds = g_timeout_add_seconds
160 self.debug_set_enabled(True)
161 self.util_set_user_dir(__DEFAULT_PATH__)
162 self.plugin_add_search_path(__DEFAULT_PATH__)
164 c_purple_core_set_ui_ops(&c_core_ui_ops)
165 c_purple_eventloop_set_ui_ops(&c_eventloop_ui_ops)
167 ret = self.core_init(__APP_NAME__)
169 debug_info("main", "Exiting because libpurple initialization failed.")
172 # check if there is another instance of libpurple running
173 if self.core_ensure_single_instance() == False:
174 debug_info("main", "Exiting because another instance of libpurple is already running.")
183 def core_ensure_single_instance(self):
184 return c_purple_core_ensure_single_instance()
185 # core_ensure_single_instance
187 def core_init(self, ui_name):
188 return c_purple_core_init(ui_name)
195 def debug_set_enabled(self, debug_enabled):
196 c_purple_debug_set_enabled(debug_enabled)
199 def plugin_add_search_path(self, path):
200 c_purple_plugins_add_search_path(path)
201 # plugin_add_search_path
203 def prefs_rename(self, old_name, new_name):
204 c_purple_prefs_rename(old_name, new_name)
207 def prefs_get_string(self, name):
208 return c_purple_prefs_get_string(name)
211 def prefs_load(self):
212 return c_purple_prefs_load()
215 def util_set_user_dir(self, dir):
216 c_purple_util_set_user_dir(dir)
219 include "core/account.pxd"
220 include "core/buddy.pxd"
221 #include "core/blist.pxd"
222 #include "core/connection.pxd"
223 #include "core/core.pxd"
224 #include "core/idle.pxd"
225 #include "core/pounce.pxd"