~ubuntu-branches/ubuntu/saucy/ibus-pinyin/saucy-proposed

« back to all changes in this revision

Viewing changes to src/PYMain.cc

  • Committer: Bazaar Package Importer
  • Author(s): LI Daobing, Asias He
  • Date: 2010-09-08 21:38:54 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100908213854-q4wlx8zlcyqxvelz
Tags: 1.3.11-1
[ Asias He ]
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim:set et ts=4 sts=4:
 
2
 *
 
3
 * ibus-pinyin - The Chinese PinYin engine for IBus
 
4
 *
 
5
 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#  include "config.h"
 
24
#endif
 
25
#include <ibus.h>
 
26
#include <stdlib.h>
 
27
#include <locale.h>
 
28
#include "PYEngine.h"
 
29
#include "PYPointer.h"
 
30
#include "PYBus.h"
 
31
#include "PYConfig.h"
 
32
#include "PYDatabase.h"
 
33
 
 
34
using namespace PY;
 
35
 
 
36
#define N_(text) text
 
37
 
 
38
static Pointer<IBusFactory> factory;
 
39
 
 
40
/* options */
 
41
static gboolean ibus = FALSE;
 
42
static gboolean verbose = FALSE;
 
43
 
 
44
static void
 
45
show_version_and_quit (void)
 
46
{
 
47
    g_print ("%s - Version %s\n", g_get_application_name (), VERSION);
 
48
    exit (EXIT_SUCCESS);
 
49
}
 
50
 
 
51
static const GOptionEntry entries[] =
 
52
{
 
53
    { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
 
54
        (gpointer) show_version_and_quit, "Show the application's version.", NULL },
 
55
    { "ibus",    'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
 
56
    { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
 
57
    { NULL },
 
58
};
 
59
 
 
60
 
 
61
static void
 
62
ibus_disconnected_cb (IBusBus  *bus,
 
63
                      gpointer  user_data)
 
64
{
 
65
    g_debug ("bus disconnected");
 
66
    ibus_quit ();
 
67
}
 
68
 
 
69
 
 
70
static void
 
71
start_component (void)
 
72
{
 
73
    Pointer<IBusComponent> component;
 
74
 
 
75
    ibus_init ();
 
76
    Bus bus;
 
77
 
 
78
    if (!bus.isConnected ()) {
 
79
        g_warning ("Can not connect to ibus");
 
80
        exit (0);
 
81
    }
 
82
 
 
83
    Database::init ();
 
84
    PinyinConfig::init (bus);
 
85
    BopomofoConfig::init (bus);
 
86
 
 
87
    g_signal_connect ((IBusBus *)bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
 
88
 
 
89
    component = ibus_component_new ("org.freedesktop.IBus.Pinyin",
 
90
                                    N_("Pinyin input method"),
 
91
                                    VERSION,
 
92
                                    "GPL",
 
93
                                    "Peng Huang <shawn.p.huang@gmail.com>",
 
94
                                    "http://code.google.com/p/ibus/",
 
95
                                    "",
 
96
                                    "ibus-pinyin");
 
97
    ibus_component_add_engine (component,
 
98
                               ibus_engine_desc_new ("pinyin-debug",
 
99
                                                     N_("Pinyin (debug)"),
 
100
                                                     N_("Pinyin input method (debug)"),
 
101
                                                     "zh_CN",
 
102
                                                     "GPL",
 
103
                                                     "Peng Huang <shawn.p.huang@gmail.com>\n"
 
104
                                                     "BYVoid <byvoid1@gmail.com>",
 
105
                                                     PKGDATADIR "/icons/ibus-pinyin.svg",
 
106
                                                     "us"));
 
107
    ibus_component_add_engine (component,
 
108
                               ibus_engine_desc_new ("bopomofo-debug",
 
109
                                                     N_("Bopomofo (debug)"),
 
110
                                                     N_("Bopomofo input method (debug)"),
 
111
                                                     "zh_CN",
 
112
                                                     "GPL",
 
113
                                                     "BYVoid <byvoid1@gmail.com>\n"
 
114
                                                     "Peng Huang <shawn.p.huang@gmail.com>",
 
115
                                                     PKGDATADIR "/icons/ibus-bopomofo.svg",
 
116
                                                     "us"));
 
117
 
 
118
    factory = ibus_factory_new (ibus_bus_get_connection (bus));
 
119
 
 
120
    if (ibus) {
 
121
        ibus_factory_add_engine (factory, "pinyin", IBUS_TYPE_PINYIN_ENGINE);
 
122
        ibus_factory_add_engine (factory, "bopomofo", IBUS_TYPE_PINYIN_ENGINE);
 
123
        ibus_bus_request_name (bus, "org.freedesktop.IBus.Pinyin", 0);
 
124
    }
 
125
    else {
 
126
        ibus_factory_add_engine (factory, "pinyin-debug", IBUS_TYPE_PINYIN_ENGINE);
 
127
        ibus_factory_add_engine (factory, "bopomofo-debug", IBUS_TYPE_PINYIN_ENGINE);
 
128
        ibus_bus_register_component (bus, component);
 
129
    }
 
130
 
 
131
    ibus_main ();
 
132
}
 
133
 
 
134
int
 
135
main (gint argc, gchar **argv)
 
136
{
 
137
    GError *error = NULL;
 
138
    GOptionContext *context;
 
139
 
 
140
    setlocale (LC_ALL, "");
 
141
 
 
142
    context = g_option_context_new ("- ibus pinyin engine component");
 
143
 
 
144
    g_option_context_add_main_entries (context, entries, "ibus-pinyin");
 
145
 
 
146
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
 
147
        g_print ("Option parsing failed: %s\n", error->message);
 
148
        exit (-1);
 
149
    }
 
150
 
 
151
    start_component ();
 
152
    return 0;
 
153
}