fixes compile
[platform/upstream/ibus-libpinyin.git] / src / PYLibPinyin.h
1 /* vim:set et ts=4 sts=4:
2  *
3  * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
4  *
5  * Copyright (c) 2011 Peng Wu <alexepico@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21
22 #ifndef __PY_LIB_PINYIN_H_
23 #define __PY_LIB_PINYIN_H_
24
25 #include <memory>
26 #include <glib.h>
27
28 typedef struct _pinyin_context_t pinyin_context_t;
29 typedef struct _pinyin_instance_t pinyin_instance_t;
30
31 namespace PY {
32
33 class Config;
34
35 class LibPinyinBackEnd{
36
37 public:
38     LibPinyinBackEnd();
39     ~LibPinyinBackEnd();
40
41     gboolean setPinyinOptions (Config *config);
42     gboolean setChewingOptions (Config *config);
43
44     pinyin_context_t * initPinyinContext (Config *config);
45     pinyin_context_t * initChewingContext (Config *config);
46
47     pinyin_instance_t *allocPinyinInstance ();
48     void freePinyinInstance (pinyin_instance_t *instance);
49     pinyin_instance_t *allocChewingInstance ();
50     void freeChewingInstance (pinyin_instance_t *instance);
51     void modified (void);
52
53     gboolean importPinyinDictionary(const char * filename);
54     gboolean clearPinyinUserData(const char * target);
55
56     /* use static initializer in C++. */
57     static LibPinyinBackEnd & instance (void) { return *m_instance; }
58
59     static void init (void);
60     static void finalize (void);
61
62
63 private:
64     gboolean saveUserDB (void);
65     static gboolean timeoutCallback (gpointer data);
66
67 private:
68     /* libpinyin context */
69     pinyin_context_t *m_pinyin_context;
70     pinyin_context_t *m_chewing_context;
71
72     guint m_timeout_id;
73     GTimer *m_timer;
74
75 private:
76     static std::unique_ptr<LibPinyinBackEnd> m_instance;
77 };
78
79 };
80
81 #endif