Create simple engine
[platform/upstream/ibus.git] / engine / main.vala
1 /* vim:set et sts=4 sw=4:
2  *
3  * ibus - The Input Bus
4  *
5  * Copyright(c) 2011 Peng Huang <shawn.p.huang@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or(at your option) any later version.
11  *
12  * This library 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 Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA  02111-1307  USA
21  */
22
23 using IBus;
24
25 class DummyEngine : IBus.EngineSimple {
26 }
27
28 public int main(string[] args) {
29     IBus.init();
30
31     IBus.Bus bus = new IBus.Bus();
32     if (!bus.is_connected()) {
33         warning("ibus-daemon does not exist.");
34         return 1;
35     }
36
37     uint flags = 
38         IBus.BusNameFlag.REPLACE_EXISTING |
39         IBus.BusNameFlag.ALLOW_REPLACEMENT;
40     uint retval = bus.request_name("org.freedesktop.IBus.Simple", flags);
41
42     if (retval == 0) {
43         warning("Registry bus name org.freedesktop.IBus.Simple failed!");
44         return 1;
45     }
46
47     bus.disconnected.connect((bus) => {
48         debug("bus disconnected");
49         IBus.quit();
50     });
51
52     IBus.Factory factory = new IBus.Factory(bus.get_connection());
53     
54     int id = 0;
55
56     factory.create_engine.connect((factory, name) => {
57         const string path = "/org/freedesktop/IBus/engine/simple/%d";
58         IBus.Engine engine = new IBus.Engine.type(
59             typeof(IBus.EngineSimple), name,
60             path.printf(++id), bus.get_connection());
61         return engine;
62     });
63
64     IBus.main();
65
66     return 0;
67 }