Moved purple_core_init to cython, added purple debug methods, added checks for core...
[python-purple] / purple.pyx
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 include "glib.pxd"
21
22 cdef extern from *:
23     ctypedef char* const_char_ptr "const char *"
24
25 cdef extern from "time.h":
26     ctypedef long int time_t
27
28 cdef extern from "libpurple/core.h":
29     gboolean c_purple_core_init "purple_core_init" (const_char_ptr ui_name)
30     void c_purple_core_quit "purple_core_quit" ()
31     gboolean c_purple_core_ensure_single_instance "purple_core_ensure_single_instance" ()
32
33 cdef extern from "libpurple/debug.h":
34     ctypedef enum PurpleDebugLevel:
35         PURPLE_DEBUG_ALL
36         PURPLE_DEBUG_MISC
37         PURPLE_DEBUG_INFO
38         PURPLE_DEBUG_WARNING
39         PURPLE_DEBUG_ERROR
40         PURPLE_DEBUG_FATAL
41
42     void c_purple_debug "purple_debug" (PurpleDebugLevel level, const_char_ptr category, const_char_ptr format)
43     void c_purple_debug_set_enabled "purple_debug_set_enabled" (gboolean debug_enabled)
44
45 cdef extern from "libpurple/plugin.h":
46     void c_purple_plugins_add_search_path "purple_plugins_add_search_path" (const_char_ptr path)
47
48 cdef extern from "libpurple/util.h":
49     void c_purple_util_set_user_dir "purple_util_set_user_dir" (char *dir)
50
51 cdef extern from "c_purple.h":
52      void set_uiops()
53
54 class Purple(object):
55     def __init__(self):
56         self.DEFAULT_PATH = "/home/user/MyDocs/Carman"
57         self.APP_NAME = "carman-purple-python"
58
59         self.debug_set_enabled(True)
60         self.util_set_user_dir(self.DEFAULT_PATH)
61         self.plugin_add_search_path(self.DEFAULT_PATH)
62
63         set_uiops()
64
65         ret = self.core_init(self.APP_NAME)
66         if ret is False:
67             self.debug_info("main", "Exiting because libpurple initialization failed.")
68             return
69
70         # check if there is another instance of libpurple running
71         if self.core_ensure_single_instance() == False:
72             self.debug_info("main", "Exiting because another instance of libpurple is already running.")
73             self.core_quit()
74             return
75     # __init__
76
77     def __del__(self):
78         self.core_quit()
79     # __del__
80
81     def core_ensure_single_instance(self):
82         return c_purple_core_ensure_single_instance()
83     # core_ensure_single_instance
84
85     def core_init(self, ui_name):
86         return c_purple_core_init(ui_name)
87     # core_init
88
89     def core_quit(self):
90         c_purple_core_quit()
91     # core_quit
92
93     def debug_misc(self, category, format):
94         if category == None:
95             c_purple_debug(PURPLE_DEBUG_MISC, NULL, format)
96         else:
97             c_purple_debug(PURPLE_DEBUG_MISC, category, format)
98     # debug_misc
99
100     def debug_info(self, category, format):
101         if category == None:
102             c_purple_debug(PURPLE_DEBUG_INFO, NULL, format)
103         else:
104             c_purple_debug(PURPLE_DEBUG_INFO, category, format)
105     # debug_info
106
107     def debug_warning(self, category, format):
108         if category == None:
109             c_purple_debug(PURPLE_DEBUG_WARNING, NULL, format)
110         else:
111             c_purple_debug(PURPLE_DEBUG_WARNING, category, format)
112     # debug_warning
113
114     def debug_error(self, category, format):
115         if category == None:
116             c_purple_debug(PURPLE_DEBUG_ERROR, NULL, format)
117         else:
118             c_purple_debug(PURPLE_DEBUG_ERROR, category, format)
119     # debug_error
120
121     def debug_fatal(self, category, format):
122         if category == None:
123             c_purple_debug(PURPLE_DEBUG_FATAL, NULL, format)
124         else:
125             c_purple_debug(PURPLE_DEBUG_FATAL, category, format)
126     # debug_fatal
127
128     def debug_set_enabled(self, debug_enabled):
129         c_purple_debug_set_enabled(debug_enabled)
130     # debug_set_enabled
131
132     def plugin_add_search_path(self, path):
133         c_purple_plugins_add_search_path(path)
134     # plugin_add_search_path
135
136     def util_set_user_dir(self, dir):
137         c_purple_util_set_user_dir(dir)
138     # util_set_user_dir
139
140 #include "core/account.pxd"
141 #include "core/blist.pxd"
142 #include "core/connection.pxd"
143 #include "core/core.pxd"
144 #include "core/eventloop.pxd"
145 #include "core/idle.pxd"
146 #include "core/pounce.pxd"
147 #include "core/prefs.pxd"