Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(651)

Side by Side Diff: src/main.c

Issue 4428051: ibus-zinnia - Japanese handwriting recognition engine (Closed) Base URL: git@github.com:yusukes/ibus-zinnia.git@master
Patch Set: version change: 0.0.0 to 0.0.1 Created 14 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/engine.c ('k') | src/xkb-layouts.xml.in.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <ibus.h> 1 #include <ibus.h>
2 #include <locale.h> 2 #include <locale.h>
3 #include <stdio.h> 3 #include <stdio.h>
4 #include <stdlib.h> 4 #include <stdlib.h>
5 #include "engine.h" 5 #include "engine.h"
6 #include "xkbutil.h" 6 #include "zinnia_component.h"
7 7
8 static IBusBus *bus = NULL; 8 static IBusBus *bus = NULL;
9 static IBusFactory *factory = NULL; 9 static IBusFactory *factory = NULL;
10 10
11 /* options */ 11 /* options */
12 static gboolean xml = FALSE;
13 static gboolean ibus = FALSE; 12 static gboolean ibus = FALSE;
14 static gboolean verbose = FALSE; 13 static gboolean verbose = FALSE;
15 14
16 static const GOptionEntry entries[] = 15 static const GOptionEntry entries[] =
17 { 16 {
18 { "xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL } ,
19 { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL }, 17 { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
20 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL }, 18 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
21 { NULL }, 19 { NULL },
22 }; 20 };
23 21
24 static void 22 static void
25 ibus_disconnected_cb (IBusBus *bus, 23 ibus_disconnected_cb (IBusBus *bus,
26 gpointer user_data) 24 gpointer user_data)
27 { 25 {
28 g_debug ("bus disconnected"); 26 g_debug ("bus disconnected");
29 ibus_quit (); 27 ibus_quit ();
30 } 28 }
31 29
32 30
33 static void 31 static void
34 start_component (void) 32 start_component (void)
35 { 33 {
36 GList *engines, *p; 34 GList *engines, *p;
37 IBusComponent *component; 35 IBusComponent *component;
38 36
39 ibus_init (); 37 ibus_init ();
40 38
41 bus = ibus_bus_new (); 39 bus = ibus_bus_new ();
42 g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NU LL); 40 g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NU LL);
43 41
44 component = ibus_xkb_get_component (); 42 component = ibus_zinnia_get_component ();
45 43
46 factory = ibus_factory_new (ibus_bus_get_connection (bus)); 44 factory = ibus_factory_new (ibus_bus_get_connection (bus));
47 45
48 engines = ibus_component_get_engines (component); 46 engines = ibus_component_get_engines (component);
49 for (p = engines; p != NULL; p = p->next) { 47 for (p = engines; p != NULL; p = p->next) {
50 IBusEngineDesc *engine = (IBusEngineDesc *)p->data; 48 IBusEngineDesc *engine = (IBusEngineDesc *)p->data;
51 ibus_factory_add_engine (factory, engine->name, IBUS_TYPE_XKB_LAYOUT_ENG INE); 49 ibus_factory_add_engine (factory,
50 » » » » ibus_engine_desc_get_name(engine),
51 » » » » IBUS_TYPE_ZINNIA_ENGINE);
52 } 52 }
53 53
54 if (ibus) { 54 if (ibus) {
55 ibus_bus_request_name (bus, "org.freedesktop.IBus.XKBLayouts", 0); 55 ibus_bus_request_name (bus, "com.google.IBus.Zinnia", 0);
56 } 56 }
57 else { 57 else {
58 ibus_bus_register_component (bus, component); 58 ibus_bus_register_component (bus, component);
59 } 59 }
60 60
61 g_object_unref (component); 61 g_object_unref (component);
62 62
63 ibus_main (); 63 ibus_main ();
64 } 64 }
65 65
66 static void
67 print_engines_xml (void)
68 {
69 IBusComponent *component;
70 GString *output;
71
72 ibus_init ();
73
74 component = ibus_xkb_get_component ();
75 output = g_string_new ("");
76
77 ibus_component_output_engines (component, output, 0);
78
79 fprintf (stdout, "%s", output->str);
80
81 g_string_free (output, TRUE);
82
83 }
84
85 int 66 int
86 main (gint argc, gchar **argv) 67 main (gint argc, gchar **argv)
87 { 68 {
88 GError *error = NULL; 69 GError *error = NULL;
89 GOptionContext *context; 70 GOptionContext *context;
90 71
91 setlocale (LC_ALL, ""); 72 setlocale (LC_ALL, "");
92 73
93 context = g_option_context_new ("- ibus XKB Layouts engine component"); 74 context = g_option_context_new ("- ibus zinnia engine component");
94 75
95 g_option_context_add_main_entries (context, entries, "ibus-xkb-layouts"); 76 g_option_context_add_main_entries (context, entries, "ibus-zinnia");
96 77
97 if (!g_option_context_parse (context, &argc, &argv, &error)) { 78 if (!g_option_context_parse (context, &argc, &argv, &error)) {
98 g_print ("Option parsing failed: %s\n", error->message); 79 g_print ("Option parsing failed: %s\n", error->message);
99 exit (-1); 80 exit (-1);
100 } 81 }
101 82
102 if (xml) {
103 print_engines_xml ();
104 exit (0);
105 }
106
107 start_component (); 83 start_component ();
108 return 0; 84 return 0;
109 } 85 }
OLDNEW
« no previous file with comments | « src/engine.c ('k') | src/xkb-layouts.xml.in.in » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b