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)
90 cdef PurpleCoreUiOps c_core_ui_ops
91 c_core_ui_ops.ui_prefs_init = NULL
92 c_core_ui_ops.debug_ui_init = NULL
93 c_core_ui_ops.ui_init = ui_init
94 c_core_ui_ops.quit = NULL
95 c_core_ui_ops.get_ui_info = NULL
97 cdef PurpleEventLoopUiOps c_eventloop_ui_ops
98 c_eventloop_ui_ops.timeout_add = g_timeout_add
99 c_eventloop_ui_ops.timeout_remove = g_source_remove
100 c_eventloop_ui_ops.input_add = glib_input_add
101 c_eventloop_ui_ops.input_remove = g_source_remove
102 c_eventloop_ui_ops.input_get_error = NULL
103 c_eventloop_ui_ops.timeout_add_seconds = NULL
105 self.DEFAULT_PATH = "/home/user/MyDocs/Carman"
106 self.APP_NAME = "carman-purple-python"
108 self.debug_set_enabled(True)
109 self.util_set_user_dir(self.DEFAULT_PATH)
110 self.plugin_add_search_path(self.DEFAULT_PATH)
112 c_purple_core_set_ui_ops(&c_core_ui_ops)
113 c_purple_eventloop_set_ui_ops(&c_eventloop_ui_ops)
115 ret = self.core_init(self.APP_NAME)
117 self.debug_info("main", "Exiting because libpurple initialization failed.")
120 # check if there is another instance of libpurple running
121 if self.core_ensure_single_instance() == False:
122 self.debug_info("main", "Exiting because another instance of libpurple is already running.")
131 def core_ensure_single_instance(self):
132 return c_purple_core_ensure_single_instance()
133 # core_ensure_single_instance
135 def core_init(self, ui_name):
136 return c_purple_core_init(ui_name)
143 def debug_misc(self, category, format):
145 c_purple_debug(PURPLE_DEBUG_MISC, NULL, format)
147 c_purple_debug(PURPLE_DEBUG_MISC, category, format)
150 def debug_info(self, category, format):
152 c_purple_debug(PURPLE_DEBUG_INFO, NULL, format)
154 c_purple_debug(PURPLE_DEBUG_INFO, category, format)
157 def debug_warning(self, category, format):
159 c_purple_debug(PURPLE_DEBUG_WARNING, NULL, format)
161 c_purple_debug(PURPLE_DEBUG_WARNING, category, format)
164 def debug_error(self, category, format):
166 c_purple_debug(PURPLE_DEBUG_ERROR, NULL, format)
168 c_purple_debug(PURPLE_DEBUG_ERROR, category, format)
171 def debug_fatal(self, category, format):
173 c_purple_debug(PURPLE_DEBUG_FATAL, NULL, format)
175 c_purple_debug(PURPLE_DEBUG_FATAL, category, format)
178 def debug_set_enabled(self, debug_enabled):
179 c_purple_debug_set_enabled(debug_enabled)
182 def plugin_add_search_path(self, path):
183 c_purple_plugins_add_search_path(path)
184 # plugin_add_search_path
186 def prefs_rename(self, old_name, new_name):
187 c_purple_prefs_rename(old_name, new_name)
190 def prefs_get_string(self, name):
191 return c_purple_prefs_get_string(name)
194 def prefs_load(self):
195 return c_purple_prefs_load()
198 def util_set_user_dir(self, dir):
199 c_purple_util_set_user_dir(dir)
202 #include "core/account.pxd"
203 #include "core/blist.pxd"
204 #include "core/connection.pxd"
205 #include "core/core.pxd"
206 #include "core/idle.pxd"
207 #include "core/pounce.pxd"