1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
2 /*
3  * nimf-m17n-ug.c
4  * This file is part of Nimf.
5  *
6  * Copyright (C) 2019 Hodong Kim <cogniti@gmail.com>
7  *
8  * Nimf is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Nimf is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program;  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "nimf-m17n.h"
23 
24 #define NIMF_TYPE_M17N_UG              (nimf_m17n_ug_get_type ())
25 #define NIMF_M17N_UG(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), NIMF_TYPE_M17N_UG, NimfM17nUg))
26 #define NIMF_M17N_UG_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), NIMF_TYPE_M17N_UG, NimfM17nUgClass))
27 #define NIMF_IS_M17N_UG(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), NIMF_TYPE_M17N_UG))
28 #define NIMF_IS_M17N_UG_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), NIMF_TYPE_M17N_UG))
29 #define NIMF_M17N_UG_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), NIMF_TYPE_M17N_UG, NimfM17nUgClass))
30 
31 typedef struct _NimfM17nUg      NimfM17nUg;
32 typedef struct _NimfM17nUgClass NimfM17nUgClass;
33 
34 struct _NimfM17nUg
35 {
36   NimfM17n parent_instance;
37 };
38 
39 struct _NimfM17nUgClass
40 {
41   /*< private >*/
42   NimfM17nClass parent_class;
43 };
44 
45 G_DEFINE_DYNAMIC_TYPE (NimfM17nUg, nimf_m17n_ug, NIMF_TYPE_M17N);
46 
47 static void
nimf_m17n_ug_init(NimfM17nUg * ug)48 nimf_m17n_ug_init (NimfM17nUg *ug)
49 {
50   g_debug (G_STRLOC ": %s", G_STRFUNC);
51 
52   NimfM17n *m17n = NIMF_M17N (ug);
53 
54   m17n->id       = g_strdup ("nimf-m17n-ug");
55   m17n->settings = g_settings_new ("org.nimf.engines.nimf-m17n-ug");
56   m17n->method   = g_settings_get_string (m17n->settings, "get-method-infos");
57   m17n->preedit_attrs = g_malloc_n (2, sizeof (NimfPreeditAttr *));
58 
59   nimf_m17n_open_im (m17n);
60 
61   g_signal_connect (m17n->settings, "changed::get-method-infos",
62                     G_CALLBACK (on_changed_method), m17n);
63 }
64 
65 static void
nimf_m17n_ug_class_init(NimfM17nUgClass * class)66 nimf_m17n_ug_class_init (NimfM17nUgClass *class)
67 {
68   g_debug (G_STRLOC ": %s", G_STRFUNC);
69 }
70 
71 static void
nimf_m17n_ug_class_finalize(NimfM17nUgClass * class)72 nimf_m17n_ug_class_finalize (NimfM17nUgClass *class)
73 {
74   g_debug (G_STRLOC ": %s", G_STRFUNC);
75 }
76 
77 NimfMethodInfo **
nimf_m17n_ug_get_method_infos()78 nimf_m17n_ug_get_method_infos ()
79 {
80   g_debug (G_STRLOC ": %s", G_STRFUNC);
81 
82   NimfMethodInfo *info;
83   GPtrArray      *array;
84   gchar          *methods[] = {"kbd", NULL};
85   gint            i;
86 
87   array = g_ptr_array_new ();
88 
89   for (i = 0; methods[i]; i++)
90   {
91     info = nimf_method_info_new ();
92     info->method_id = g_strdup_printf ("ug:%s", methods[i]);
93     info->label     = g_strdup (methods[i]);
94     g_ptr_array_add (array, info);
95   }
96 
97   g_ptr_array_add (array, NULL);
98 
99   return (NimfMethodInfo **) g_ptr_array_free (array, FALSE);
100 }
101 
module_register_type(GTypeModule * type_module)102 void module_register_type (GTypeModule *type_module)
103 {
104   g_debug (G_STRLOC ": %s", G_STRFUNC);
105 
106   nimf_m17n_ug_register_type (type_module);
107 }
108 
module_get_type()109 GType module_get_type ()
110 {
111   g_debug (G_STRLOC ": %s", G_STRFUNC);
112 
113   return nimf_m17n_ug_get_type ();
114 }
115