|
23 | 23 |
|
24 | 24 | #include <ibus.h> |
25 | 25 | #include <locale.h> |
26 | | -#include <stdlib.h> |
27 | 26 | #include <stdio.h> |
28 | | -#include "keymanutil.h" |
| 27 | +#include <stdlib.h> |
29 | 28 | #include "engine.h" |
30 | 29 | #include "keyman-service.h" |
| 30 | +#include "keymanutil.h" |
31 | 31 |
|
32 | | -static IBusBus *bus = NULL; |
| 32 | +static IBusBus *bus = NULL; |
33 | 33 | static IBusFactory *factory = NULL; |
34 | 34 |
|
35 | 35 | /* options */ |
36 | | -static gboolean xml = FALSE; |
| 36 | +static gboolean xml = FALSE; |
37 | 37 | static gboolean ibus = FALSE; |
38 | | -gboolean testing = FALSE; |
39 | | - |
40 | | -static const GOptionEntry entries[] = |
41 | | -{ |
42 | | - { "xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL }, |
43 | | - { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL }, |
44 | | - { "testing", 0, 0, G_OPTION_ARG_NONE, &testing, "component is executed by integration testing", NULL}, |
45 | | - { NULL }, |
| 38 | +gboolean testing = FALSE; |
| 39 | + |
| 40 | +static const GOptionEntry entries[] = { |
| 41 | + {"xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL}, |
| 42 | + {"ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL}, |
| 43 | + {"testing", 0, 0, G_OPTION_ARG_NONE, &testing, "component is executed by integration testing", NULL}, |
| 44 | + {NULL}, |
46 | 45 | }; |
47 | 46 |
|
48 | 47 | // Add an environment variable to see debug messages: export G_MESSAGES_DEBUG=all |
49 | 48 |
|
50 | 49 | static void |
51 | | -ibus_disconnected_cb (IBusBus *unused_bus, |
52 | | - gpointer unused_data) |
53 | | -{ |
54 | | - g_debug ("bus disconnected"); |
55 | | - KeymanService *service = km_service_get_default(NULL); |
56 | | - g_clear_object(&service); |
| 50 | +ibus_disconnected_cb(IBusBus *unused_bus, gpointer unused_data) { |
| 51 | + g_debug("bus disconnected"); |
| 52 | + KeymanService *service = km_service_get_default(NULL); |
| 53 | + g_clear_object(&service); |
57 | 54 |
|
58 | | - g_object_unref(factory); |
59 | | - g_object_unref(bus); |
| 55 | + g_object_unref(factory); |
| 56 | + g_object_unref(bus); |
60 | 57 |
|
61 | | - ibus_quit (); |
| 58 | + ibus_quit(); |
62 | 59 | } |
63 | 60 |
|
64 | | - |
65 | 61 | static void |
66 | | -start_component (void) |
67 | | -{ |
68 | | - GList *engines, *p; |
69 | | - IBusComponent *component; |
| 62 | +start_component(void) { |
| 63 | + GList *engines, *p; |
| 64 | + IBusComponent *component; |
70 | 65 |
|
71 | | - ibus_init (); |
| 66 | + ibus_init(); |
72 | 67 |
|
73 | | - bus = ibus_bus_new (); |
74 | | - g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL); |
| 68 | + bus = ibus_bus_new(); |
| 69 | + g_signal_connect(bus, "disconnected", G_CALLBACK(ibus_disconnected_cb), NULL); |
75 | 70 |
|
76 | | - component = ibus_keyman_get_component (); |
| 71 | + component = ibus_keyman_get_component(); |
77 | 72 |
|
78 | | - factory = ibus_factory_new (ibus_bus_get_connection (bus)); |
| 73 | + factory = ibus_factory_new(ibus_bus_get_connection(bus)); |
79 | 74 |
|
80 | | - engines = ibus_component_get_engines (component); |
81 | | - for (p = engines; p != NULL; p = p->next) { |
82 | | - IBusEngineDesc *engine = (IBusEngineDesc *)p->data; |
83 | | -#if IBUS_CHECK_VERSION(1,3,99) |
84 | | - const gchar *engine_name = ibus_engine_desc_get_name (engine); |
| 75 | + engines = ibus_component_get_engines(component); |
| 76 | + for (p = engines; p != NULL; p = p->next) { |
| 77 | + IBusEngineDesc *engine = (IBusEngineDesc *)p->data; |
| 78 | +#if IBUS_CHECK_VERSION(1, 3, 99) |
| 79 | + const gchar *engine_name = ibus_engine_desc_get_name(engine); |
85 | 80 | #else |
86 | | - const gchar *engine_name = engine->name; |
87 | | -#endif /* !IBUS_CHECK_VERSION(1,3,99) */ |
88 | | - ibus_factory_add_engine (factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE); |
89 | | - } |
90 | | - |
91 | | - if (ibus) { |
92 | | - ibus_bus_request_name (bus, "org.freedesktop.IBus.Keyman", 0); |
93 | | - } |
94 | | - else { |
95 | | - ibus_bus_register_component (bus, component); |
96 | | - } |
97 | | - |
98 | | - g_object_unref (component); |
99 | | - km_service_get_default(NULL); // initialise dbus service |
100 | | - |
101 | | - ibus_main (); |
| 81 | + const gchar *engine_name = engine->name; |
| 82 | +#endif /* !IBUS_CHECK_VERSION(1,3,99) */ |
| 83 | + ibus_factory_add_engine(factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE); |
| 84 | + } |
| 85 | + |
| 86 | + if (ibus) { |
| 87 | + ibus_bus_request_name(bus, "org.freedesktop.IBus.Keyman", 0); |
| 88 | + } else { |
| 89 | + ibus_bus_register_component(bus, component); |
| 90 | + } |
| 91 | + |
| 92 | + g_object_unref(component); |
| 93 | + km_service_get_default(NULL); // initialise dbus service |
| 94 | + |
| 95 | + ibus_main(); |
102 | 96 | } |
103 | 97 |
|
104 | 98 | static void |
105 | | -print_engines_xml (void) |
106 | | -{ |
107 | | - IBusComponent *component; |
108 | | - GString *output; |
| 99 | +print_engines_xml(void) { |
| 100 | + IBusComponent *component; |
| 101 | + GString *output; |
109 | 102 |
|
110 | | - ibus_init (); |
| 103 | + ibus_init(); |
111 | 104 |
|
112 | | - component = ibus_keyman_get_component (); |
113 | | - output = g_string_new (""); |
| 105 | + component = ibus_keyman_get_component(); |
| 106 | + output = g_string_new(""); |
114 | 107 |
|
115 | | - ibus_component_output_engines (component, output, 0); |
| 108 | + ibus_component_output_engines(component, output, 0); |
116 | 109 |
|
117 | | - fprintf (stdout, "%s", output->str); |
| 110 | + fprintf(stdout, "%s", output->str); |
118 | 111 |
|
119 | | - g_string_free (output, TRUE); |
120 | | - g_object_unref(component); |
| 112 | + g_string_free(output, TRUE); |
| 113 | + g_object_unref(component); |
121 | 114 | } |
122 | 115 |
|
123 | 116 | int |
124 | | -main (gint argc, gchar **argv) |
125 | | -{ |
126 | | - GError *error = NULL; |
127 | | - GOptionContext *context; |
| 117 | +main(gint argc, gchar **argv) { |
| 118 | + GError *error = NULL; |
| 119 | + GOptionContext *context; |
128 | 120 |
|
129 | | - setlocale (LC_ALL, ""); |
| 121 | + setlocale(LC_ALL, ""); |
130 | 122 |
|
131 | | - context = g_option_context_new ("- ibus Keyman engine component"); |
| 123 | + context = g_option_context_new("- ibus Keyman engine component"); |
132 | 124 |
|
133 | | - g_option_context_add_main_entries (context, entries, "ibus-keyman"); |
| 125 | + g_option_context_add_main_entries(context, entries, "ibus-keyman"); |
134 | 126 |
|
135 | | - if (!g_option_context_parse (context, &argc, &argv, &error)) { |
136 | | - g_print ("Option parsing failed: %s\n", error->message); |
137 | | - exit (-1); |
138 | | - } |
| 127 | + if (!g_option_context_parse(context, &argc, &argv, &error)) { |
| 128 | + g_print("Option parsing failed: %s\n", error->message); |
| 129 | + exit(-1); |
| 130 | + } |
139 | 131 |
|
140 | | - if (xml) { |
141 | | - print_engines_xml (); |
142 | | - exit (0); |
143 | | - } |
| 132 | + if (xml) { |
| 133 | + print_engines_xml(); |
| 134 | + exit(0); |
| 135 | + } |
144 | 136 |
|
145 | | - start_component (); |
146 | | - return 0; |
| 137 | + start_component(); |
| 138 | + return 0; |
147 | 139 | } |
0 commit comments