~ubuntu-branches/ubuntu/utopic/ibus-m17n/utopic

« back to all changes in this revision

Viewing changes to src/main.c

Tags: upstream-1.1.0.20090211
ImportĀ upstreamĀ versionĀ 1.1.0.20090211

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim:set et sts=4: */
 
2
 
 
3
#include <ibus.h>
 
4
#include <locale.h>
 
5
#include <m17n.h>
 
6
#include "engine.h"
 
7
#include "m17nutil.h"
 
8
 
 
9
static IBusBus *bus = NULL;
 
10
static IBusFactory *factory = NULL;
 
11
 
 
12
/* options */
 
13
static gboolean xml = FALSE;
 
14
static gboolean ibus = FALSE;
 
15
static gboolean verbose = FALSE;
 
16
 
 
17
static const GOptionEntry entries[] =
 
18
{
 
19
    { "xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL },
 
20
    { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
 
21
    { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
 
22
    { NULL },
 
23
};
 
24
 
 
25
 
 
26
static void
 
27
ibus_disconnected_cb (IBusBus  *bus,
 
28
                      gpointer  user_data)
 
29
{
 
30
    g_debug ("bus disconnected");
 
31
    ibus_quit ();
 
32
}
 
33
 
 
34
 
 
35
static void
 
36
start_component (void)
 
37
{
 
38
    GList *engines, *p;
 
39
    IBusComponent *component;
 
40
 
 
41
    ibus_init ();
 
42
    ibus_m17n_init ();
 
43
 
 
44
    bus = ibus_bus_new ();
 
45
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
 
46
 
 
47
    component = ibus_m17n_get_component ();
 
48
 
 
49
    factory = ibus_factory_new (ibus_bus_get_connection (bus));
 
50
 
 
51
    engines = ibus_component_get_engines (component);
 
52
    for (p = engines; p != NULL; p = p->next) {
 
53
        IBusEngineDesc *engine = (IBusEngineDesc *)p->data;
 
54
        ibus_factory_add_engine (factory, engine->name, IBUS_TYPE_M17N_ENGINE);
 
55
    }
 
56
 
 
57
    if (ibus) {
 
58
        ibus_bus_request_name (bus, "org.freedesktop.IBus.M17N", 0);
 
59
    }
 
60
    else {
 
61
        ibus_bus_register_component (bus, component);
 
62
    }
 
63
 
 
64
    g_object_unref (component);
 
65
 
 
66
    ibus_main ();
 
67
}
 
68
 
 
69
static void
 
70
print_engines_xml (void)
 
71
{
 
72
    IBusComponent *component;
 
73
    GString *output;
 
74
 
 
75
    ibus_init ();
 
76
    ibus_m17n_init ();
 
77
 
 
78
    component = ibus_m17n_get_component ();
 
79
    output = g_string_new ("");
 
80
 
 
81
    ibus_component_output_engines (component, output, 0);
 
82
 
 
83
    fprintf (stdout, "%s", output->str);
 
84
 
 
85
    g_string_free (output, TRUE);
 
86
 
 
87
}
 
88
 
 
89
int
 
90
main (gint argc, gchar **argv)
 
91
{
 
92
    GError *error = NULL;
 
93
    GOptionContext *context;
 
94
 
 
95
    setlocale (LC_ALL, "");
 
96
 
 
97
    context = g_option_context_new ("- ibus M17N engine component");
 
98
 
 
99
    g_option_context_add_main_entries (context, entries, "ibus-m17n");
 
100
 
 
101
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
 
102
        g_print ("Option parsing failed: %s\n", error->message);
 
103
        exit (-1);
 
104
    }
 
105
 
 
106
    if (xml) {
 
107
        print_engines_xml ();
 
108
        exit (0);
 
109
    }
 
110
 
 
111
    start_component ();
 
112
    return 0;
 
113
}