update PYLibPinyin.*
[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     /* use static initializer in C++. */
54     static LibPinyinBackEnd & instance (void) { return *m_instance; }
55
56     static void init (void);
57     static void finalize (void);
58
59
60 private:
61     gboolean saveUserDB (void);
62     static gboolean timeoutCallback (gpointer data);
63
64 private:
65     /* libpinyin context */
66     pinyin_context_t *m_pinyin_context;
67     pinyin_context_t *m_chewing_context;
68
69     guint m_timeout_id;
70     GTimer *m_timer;
71
72 private:
73     static std::unique_ptr<LibPinyinBackEnd> m_instance;
74 };
75
76 };
77
78 #endif