Tizen 2.1 base
[framework/uifw/ise-engine-anthy.git] / src / scim_anthy_factory.cpp
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  *  Copyright (C) Hiroyuki Ikezoe <poincare@ikezoe.net>
4  *  Copyright (C) 2004 Takuro Ashie <ashie@homa.ne.jp>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * The original code is scim_uim_imengine.cpp in scim-uim-0.1.3. 
23  * Copyright (C) 2004 James Su <suzhe@tsinghua.org.cn>
24  */
25
26 #define Uses_SCIM_UTILITY
27 #define Uses_SCIM_IMENGINE
28 #define Uses_SCIM_CONFIG_BASE
29
30 #ifdef HAVE_CONFIG_H
31   #include <config.h>
32 #endif
33
34 #include <stdio.h>
35 #include <unistd.h>
36 #include <sys/types.h>
37 #include <sys/wait.h>
38
39 #include <scim.h>
40 #include "scim_anthy_factory.h"
41 #include "scim_anthy_imengine.h"
42 #include "scim_anthy_prefs.h"
43 #include "scim_anthy_intl.h"
44
45 #define scim_module_init ise_engine_anthy_LTX_scim_module_init
46 #define scim_module_exit ise_engine_anthy_LTX_scim_module_exit
47 #define scim_imengine_module_init ise_engine_anthy_LTX_scim_imengine_module_init
48 #define scim_imengine_module_create_factory ise_engine_anthy_LTX_scim_imengine_module_create_factory
49
50 #define SCIM_CONFIG_IMENGINE_ANTHY_UUID     "/IMEngine/Anthy/UUID-"
51
52 #ifndef SCIM_ANTHY_ICON_FILE
53     #define SCIM_ANTHY_ICON_FILE           (SCIM_ICONDIR"/scim-anthy.png")
54 #endif
55
56 static ConfigPointer _scim_config (0);
57
58 extern "C" {
59     void scim_module_init (void)
60     {
61         bindtextdomain (GETTEXT_PACKAGE, SCIM_ANTHY_LOCALEDIR);
62         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
63     }
64
65     void scim_module_exit (void)
66     {
67         anthy_quit ();
68         _scim_config.reset ();
69     }
70
71     uint32 scim_imengine_module_init (const ConfigPointer &config)
72     {
73         SCIM_DEBUG_IMENGINE(1) << "Initialize Anthy Engine.\n";
74
75         _scim_config = config;
76
77         if (anthy_init ()) {
78             SCIM_DEBUG_IMENGINE(1) << "Failed to initialize Anthy Library!\n";
79             return 0;
80         }
81
82         return 1;
83     }
84
85     IMEngineFactoryPointer scim_imengine_module_create_factory (uint32 engine)
86     {
87         AnthyFactory *factory = 0;
88
89         try {
90             factory = new AnthyFactory (
91                 String ("ja_JP"),
92                 String ("065d7b20-dda2-47fb-8f94-3306d9a25e56"),
93                 _scim_config);
94         } catch (...) {
95             delete factory;
96             factory = 0;
97         }
98
99         return factory;
100     }
101 }
102
103 AnthyFactory::AnthyFactory (const String &lang,
104                             const String &uuid,
105                             const ConfigPointer &config)
106     : m_uuid                        (uuid),
107       m_config                      (config),
108       m_input_mode                  (SCIM_ANTHY_CONFIG_INPUT_MODE_DEFAULT),
109       m_typing_method               (SCIM_ANTHY_CONFIG_TYPING_METHOD_DEFAULT),
110       m_conversion_mode             (SCIM_ANTHY_CONFIG_CONVERSION_MODE_DEFAULT),
111       m_period_style                (SCIM_ANTHY_CONFIG_PERIOD_STYLE_DEFAULT),
112       m_symbol_style                (SCIM_ANTHY_CONFIG_SYMBOL_STYLE_DEFAULT),
113       m_space_type                  (SCIM_ANTHY_CONFIG_SPACE_TYPE_DEFAULT),
114       m_ten_key_type                (SCIM_ANTHY_CONFIG_TEN_KEY_TYPE_DEFAULT),
115       m_behavior_on_period          (SCIM_ANTHY_CONFIG_BEHAVIOR_ON_PERIOD_DEFAULT),
116       m_behavior_on_focus_out       (SCIM_ANTHY_CONFIG_BEHAVIOR_ON_FOCUS_OUT_DEFAULT),
117      m_show_candidates_label       (SCIM_ANTHY_CONFIG_SHOW_CANDIDATES_LABEL_DEFAULT),
118       m_close_cand_win_on_select    (SCIM_ANTHY_CONFIG_CLOSE_CAND_WIN_ON_SELECT_DEFAULT),
119       m_cand_win_page_size          (SCIM_ANTHY_CONFIG_CAND_WIN_PAGE_SIZE_DEFAULT),
120       m_n_triggers_to_show_cand_win (SCIM_ANTHY_CONFIG_N_TRIGGERS_TO_SHOW_CAND_WIN_DEFAULT),
121       m_learn_on_manual_commit      (SCIM_ANTHY_CONFIG_LEARN_ON_MANUAL_COMMIT_DEFAULT),
122       m_learn_on_auto_commit        (SCIM_ANTHY_CONFIG_LEARN_ON_AUTO_COMMIT_DEFAULT),
123       m_romaji_half_symbol          (SCIM_ANTHY_CONFIG_ROMAJI_HALF_SYMBOL_DEFAULT),
124       m_romaji_half_number          (SCIM_ANTHY_CONFIG_ROMAJI_HALF_NUMBER_DEFAULT),
125       m_romaji_allow_split          (SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT_DEFAULT),
126       m_romaji_pseudo_ascii_mode    (SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE_DEFAULT),
127       m_romaji_pseudo_ascii_blank_behavior (SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_BLANK_BEHAVIOR),
128       m_nicola_time                 (SCIM_ANTHY_CONFIG_NICOLA_TIME_DEFAULT),
129       m_dict_encoding               (SCIM_ANTHY_CONFIG_DICT_ENCODING),
130       m_dict_admin_command          (SCIM_ANTHY_CONFIG_DICT_ADMIN_COMMAND_DEFAULT),
131       m_add_word_command            (SCIM_ANTHY_CONFIG_ADD_WORD_COMMAND_DEFAULT),
132       m_predict_on_input            (SCIM_ANTHY_CONFIG_PREDICT_ON_INPUT_DEFAULT),
133       m_use_direct_key_on_predict   (SCIM_ANTHY_CONFIG_USE_DIRECT_KEY_ON_PREDICT_DEFAULT),
134       m_show_input_mode_label       (SCIM_ANTHY_CONFIG_SHOW_INPUT_MODE_LABEL_DEFAULT),
135       m_show_conv_mode_label        (SCIM_ANTHY_CONFIG_SHOW_INPUT_MODE_LABEL_DEFAULT),
136       m_show_typing_method_label    (SCIM_ANTHY_CONFIG_SHOW_TYPING_METHOD_LABEL_DEFAULT),
137       m_show_period_style_label     (SCIM_ANTHY_CONFIG_SHOW_PERIOD_STYLE_LABEL_DEFAULT),
138       m_show_symbol_style_label     (SCIM_ANTHY_CONFIG_SHOW_SYMBOL_STYLE_LABEL_DEFAULT),
139       m_show_dict_label             (SCIM_ANTHY_CONFIG_SHOW_DICT_LABEL_DEFAULT),
140       m_show_dict_admin_label       (SCIM_ANTHY_CONFIG_SHOW_DICT_ADMIN_LABEL_DEFAULT),
141       m_show_add_word_label         (SCIM_ANTHY_CONFIG_SHOW_ADD_WORD_LABEL_DEFAULT),
142       m_preedit_style               (SCIM_ANTHY_CONFIG_PREEDIT_STYLE_DEFAULT),
143       m_conversion_style            (SCIM_ANTHY_CONFIG_CONVERSION_STYLE_DEFAULT),
144       m_selected_segment_style      (SCIM_ANTHY_CONFIG_SELECTED_SEGMENT_STYLE_DEFAULT),
145       m_custom_romaji_table         (NULL),
146       m_custom_kana_table           (NULL),
147       m_custom_nicola_table         (NULL),
148       m_kana_layout_ro_key          (SCIM_ANTHY_CONFIG_KANA_LAYOUT_RO_KEY)
149 {
150     SCIM_DEBUG_IMENGINE(1) << "Create Anthy Factory :\n";
151     SCIM_DEBUG_IMENGINE(1) << "  Lang : " << lang << "\n";
152     SCIM_DEBUG_IMENGINE(1) << "  UUID : " << uuid << "\n";
153
154     if (lang.length () >= 2)
155         set_languages (lang);
156
157     /* config */
158     reload_config (m_config);
159     m_reload_signal_connection = m_config->signal_connect_reload (slot (this, &AnthyFactory::reload_config));
160 }
161
162 AnthyFactory::~AnthyFactory ()
163 {
164     m_reload_signal_connection.disconnect ();
165
166     if (m_custom_romaji_table) {
167         delete m_custom_romaji_table;
168         m_custom_romaji_table = NULL;
169     }
170
171     if (m_custom_kana_table) {
172         delete m_custom_kana_table;
173         m_custom_kana_table = NULL;
174     }
175
176     if (m_custom_nicola_table) {
177         delete m_custom_nicola_table;
178         m_custom_nicola_table = NULL;
179     }
180 }
181
182 WideString
183 AnthyFactory::get_name () const
184 {
185     return utf8_mbstowcs (String ("Anthy"));
186 }
187
188 WideString
189 AnthyFactory::get_authors () const
190 {
191     const char *package = 
192         PACKAGE "-" PACKAGE_VERSION "\n"
193         "\n";
194     const char *authors =
195         _("Authors of scim-anthy:\n"
196           "  Copyright (C) 2004,2005 Takuro Ashie <ashie@homa.ne.jp>\n"
197           "  Copyright (C) 2004,2005 Hiroyuki Ikezoe <poincare@ikezoe.net>\n"
198           "  \n"
199           "Authors of Anthy:\n"
200           "  Copyright (C) 2000-2005 Yusuke TABATA <yusuke@w5.dion.ne.jp>\n"
201           "  Copyright (C) 2004-2005 Yuichi YOSHIDA <oxy@kmc.gr.jp>\n"
202           "  You can find out all credits of Anthy from AUTHORS file in Anthy package.\n");
203
204     return utf8_mbstowcs (package) + utf8_mbstowcs (authors);
205 }
206
207 WideString
208 AnthyFactory::get_credits () const
209 {
210     return utf8_mbstowcs (
211         _("Art work:\n"
212           "  SHIMODA Hiroshi <piro@p.club.ne.jp>\n"
213           "\n"
214           "Translation:\n"
215           "  Gerrit Sangel <z0idberg@gmx.de>"
216           "\n"
217           "Special thanks:\n"
218           "  UTUMI Hirosi <utuhiro78@yahoo.co.jp>\n"
219           "  Yukiko Bando <ybando@k6.dion.ne.jp>\n"
220           "  Mike Fabian <mfabian@suse.de>\n"
221           "  David Oftedal <david@start.no>\n"
222           "  Ryo Dairiki <ryo-dairiki@users.sourceforge.net>\n"
223           "  Seiichi SATO\n"
224           "  AWASHIRO Ikuya <ikuya@oooug.jp>\n"
225           "  Hatuka*nezumi <nezumi@jca.apc.org>\n"
226           "  Teppei Tamra <tam-t@par.odn.ne.jp>\n"
227           "  Akira TAGOH <at@gclab.org>\n"
228           "  Tatsuki Sugiura <sugi@nemui.org>\n"
229           "  Takashi Nakamoto <bluedwarf@bpost.plala.or.jp>"));
230 }
231
232 WideString
233 AnthyFactory::get_help () const
234 {
235     const char *title = 
236         _("Basic operation:\n"
237           "  \n");
238
239     const char *text1 = 
240         _("1. Switch input mode:\n"
241           "  You can switch on/off Japanese input mode by pressing Zenkaku_Hankaku key\n"
242           "  or Control+J. Or you can rotate all input modes by pressing Control+,\n"
243           "  (comma).\n"
244           "  \n");
245
246     const char *text2 = 
247         _("2. Input Japanese hiragana and katakana:\n"
248           "  You can input Japanese hiragana and katakana by inputting romaji.\n"
249           "  The Romaji table can be found out from the \"Anthy\" section of the setup\n"
250           "  window in SCIM or SKIM.\n"
251           "  If you want to hiragana and katakana directly by using Japanese keyboard,\n"
252           "  please press Alt + Romaji key or Conrol+\\ key to switch typing method.\n"
253           "  \n");
254
255     const char *text3 = 
256         _("3. Convert hiragana or katakana to Japanese kanji\n"
257           "  After inputting hiragana or katakana, you can convert it to Japanese\n"
258           "  kanji by pressing Space key. Then it will show some candidates. You can\n"
259           "  select the next candidate by pressing Space key, and can commit it by\n"
260           "  pressing Enter key.\n"
261           "  If you input a sentense, Anthy will split it to some segments. You can\n"
262           "  select the next or previous segment by pressing left or right cursor key,\n"
263           "  and can extend or shrink the selected segment by pressing Shift + left or\n"
264           "  right cursor key.\n"
265           "  \n");
266
267     const char *text4 = 
268         _("4. Other key bindings:\n"
269           "  You can find out all key bindings definition of scim-anthy from \"Anthy\"\n"
270           "  section on setup window of SCIM or SKIM.\n");
271
272     return utf8_mbstowcs (title)
273         + utf8_mbstowcs (text1)
274         + utf8_mbstowcs (text2)
275         + utf8_mbstowcs (text3)
276         + utf8_mbstowcs (text4);
277 }
278
279 String
280 AnthyFactory::get_uuid () const
281 {
282     return m_uuid;
283 }
284
285 String
286 AnthyFactory::get_icon_file () const
287 {
288     return String (SCIM_ANTHY_ICON_FILE);
289 }
290
291 IMEngineInstancePointer
292 AnthyFactory::create_instance (const String &encoding, int id)
293 {
294     return new AnthyInstance (this, encoding, id);
295 }
296
297 void
298 AnthyFactory::append_config_listener (AnthyInstance *listener)
299 {
300     bool found = false;
301     std::vector<AnthyInstance*>::iterator it;
302     for (it = m_config_listeners.begin();
303          it != m_config_listeners.end();
304          it++)
305     {
306         if (*it == listener) {
307             found = true;
308             break;
309         }
310     }
311
312     if (!found)
313         m_config_listeners.push_back (listener);
314 }
315
316 void
317 AnthyFactory::remove_config_listener (AnthyInstance *listener)
318 {
319     std::vector<AnthyInstance*>::iterator it;
320     for (it = m_config_listeners.begin();
321          it != m_config_listeners.end();
322          it++)
323     {
324         if (*it == listener) {
325             m_config_listeners.erase (it);
326             break;
327         }
328     }
329 }
330
331
332 #if 0
333 #define APPEND_ACTION(key, func)                                               \
334 {                                                                              \
335     String name = "func", str;                                                 \
336     str = config->read (String (SCIM_ANTHY_CONFIG_##key##_KEY),                \
337                         String (SCIM_ANTHY_CONFIG_##key##_KEY_DEFAULT));       \
338     m_actions.push_back (Action (name, str, &AnthyInstance::func));            \
339 }
340 #else
341 #define APPEND_ACTION(key, func)                                               \
342 {                                                                              \
343     String name = #key, str;                                                   \
344     if (loaded) {                                                              \
345         String str2, str3;                                                     \
346         str2 = String (SCIM_ANTHY_CONFIG_##key##_KEY);                         \
347         str3 = String ("/IMEngine/Anthy/");                                    \
348         if (str2.length () > str3.length ()) {                                 \
349                 str2 = str2.substr (str3.length (),                            \
350                                     str2.length () - str3.length ());          \
351             style.get_string (str, section_key, str2);                         \
352         }                                                                      \
353     } else if (config) {                                                       \
354         str = config->read (String (SCIM_ANTHY_CONFIG_##key##_KEY),            \
355                             String (SCIM_ANTHY_CONFIG_##key##_KEY_DEFAULT));   \
356     }                                                                          \
357     m_actions.push_back (Action (name, str, func));                            \
358 }
359 #endif
360
361 // FIXME
362 #define ANTHY_DEFINE_ACTION(func) \
363 static bool                       \
364 func (AnthyInstance *anthy)       \
365 {                                 \
366     return anthy->func ();        \
367 }
368
369 ANTHY_DEFINE_ACTION (action_do_nothing);
370 ANTHY_DEFINE_ACTION (action_commit_follow_preference);
371 ANTHY_DEFINE_ACTION (action_commit_reverse_preference);
372 ANTHY_DEFINE_ACTION (action_convert);
373 ANTHY_DEFINE_ACTION (action_predict);
374 ANTHY_DEFINE_ACTION (action_revert);
375 ANTHY_DEFINE_ACTION (action_cancel_all);
376 ANTHY_DEFINE_ACTION (action_back);
377 ANTHY_DEFINE_ACTION (action_delete);
378 ANTHY_DEFINE_ACTION (action_insert_space);
379 ANTHY_DEFINE_ACTION (action_insert_alternative_space);
380 ANTHY_DEFINE_ACTION (action_insert_half_space);
381 ANTHY_DEFINE_ACTION (action_insert_wide_space);
382 ANTHY_DEFINE_ACTION (action_move_caret_first);
383 ANTHY_DEFINE_ACTION (action_move_caret_last);
384 ANTHY_DEFINE_ACTION (action_move_caret_forward);
385 ANTHY_DEFINE_ACTION (action_move_caret_backward);
386 ANTHY_DEFINE_ACTION (action_select_first_segment);
387 ANTHY_DEFINE_ACTION (action_select_last_segment);
388 ANTHY_DEFINE_ACTION (action_select_next_segment);
389 ANTHY_DEFINE_ACTION (action_select_prev_segment);
390 ANTHY_DEFINE_ACTION (action_shrink_segment);
391 ANTHY_DEFINE_ACTION (action_expand_segment);
392 ANTHY_DEFINE_ACTION (action_commit_first_segment);
393 ANTHY_DEFINE_ACTION (action_commit_selected_segment);
394 ANTHY_DEFINE_ACTION (action_commit_first_segment_reverse_preference);
395 ANTHY_DEFINE_ACTION (action_commit_selected_segment_reverse_preference);
396 ANTHY_DEFINE_ACTION (action_select_first_candidate);
397 ANTHY_DEFINE_ACTION (action_select_last_candidate);
398 ANTHY_DEFINE_ACTION (action_select_next_candidate);
399 ANTHY_DEFINE_ACTION (action_select_prev_candidate);
400 ANTHY_DEFINE_ACTION (action_candidates_page_up);
401 ANTHY_DEFINE_ACTION (action_candidates_page_down);
402 ANTHY_DEFINE_ACTION (action_select_candidate_1);
403 ANTHY_DEFINE_ACTION (action_select_candidate_2);
404 ANTHY_DEFINE_ACTION (action_select_candidate_3);
405 ANTHY_DEFINE_ACTION (action_select_candidate_4);
406 ANTHY_DEFINE_ACTION (action_select_candidate_5);
407 ANTHY_DEFINE_ACTION (action_select_candidate_6);
408 ANTHY_DEFINE_ACTION (action_select_candidate_7);
409 ANTHY_DEFINE_ACTION (action_select_candidate_8);
410 ANTHY_DEFINE_ACTION (action_select_candidate_9);
411 ANTHY_DEFINE_ACTION (action_select_candidate_10);
412 ANTHY_DEFINE_ACTION (action_convert_char_type_forward);
413 ANTHY_DEFINE_ACTION (action_convert_char_type_backward);
414 ANTHY_DEFINE_ACTION (action_convert_to_hiragana);
415 ANTHY_DEFINE_ACTION (action_convert_to_katakana);
416 ANTHY_DEFINE_ACTION (action_convert_to_half);
417 ANTHY_DEFINE_ACTION (action_convert_to_half_katakana);
418 ANTHY_DEFINE_ACTION (action_convert_to_latin);
419 ANTHY_DEFINE_ACTION (action_convert_to_wide_latin);
420 ANTHY_DEFINE_ACTION (action_reconvert);
421 ANTHY_DEFINE_ACTION (action_on_off);
422 ANTHY_DEFINE_ACTION (action_circle_input_mode);
423 ANTHY_DEFINE_ACTION (action_circle_kana_mode);
424 ANTHY_DEFINE_ACTION (action_circle_typing_method);
425 ANTHY_DEFINE_ACTION (action_latin_mode);
426 ANTHY_DEFINE_ACTION (action_wide_latin_mode);
427 ANTHY_DEFINE_ACTION (action_hiragana_mode);
428 ANTHY_DEFINE_ACTION (action_katakana_mode);
429 ANTHY_DEFINE_ACTION (action_half_katakana_mode);
430 ANTHY_DEFINE_ACTION (action_cancel_pseudo_ascii_mode);
431 ANTHY_DEFINE_ACTION (action_launch_dict_admin_tool);
432 ANTHY_DEFINE_ACTION (action_add_word);
433
434 void
435 AnthyFactory::reload_config (const ConfigPointer &config)
436 {
437     if (config) {
438         String str;
439
440         m_input_mode
441             = config->read (String (SCIM_ANTHY_CONFIG_INPUT_MODE),
442                             String (SCIM_ANTHY_CONFIG_INPUT_MODE_DEFAULT));
443
444         m_typing_method
445             = config->read (String (SCIM_ANTHY_CONFIG_TYPING_METHOD),
446                             String (SCIM_ANTHY_CONFIG_TYPING_METHOD_DEFAULT));
447
448         m_conversion_mode
449             = config->read (String (SCIM_ANTHY_CONFIG_CONVERSION_MODE),
450                             String (SCIM_ANTHY_CONFIG_CONVERSION_MODE_DEFAULT));
451
452         m_period_style
453             = config->read (String (SCIM_ANTHY_CONFIG_PERIOD_STYLE),
454                             String (SCIM_ANTHY_CONFIG_PERIOD_STYLE_DEFAULT));
455
456         m_symbol_style
457             = config->read (String (SCIM_ANTHY_CONFIG_SYMBOL_STYLE),
458                             String (SCIM_ANTHY_CONFIG_SYMBOL_STYLE_DEFAULT));
459
460         m_space_type
461             = config->read (String (SCIM_ANTHY_CONFIG_SPACE_TYPE),
462                             String (SCIM_ANTHY_CONFIG_SPACE_TYPE_DEFAULT));
463
464         m_ten_key_type
465             = config->read (String (SCIM_ANTHY_CONFIG_TEN_KEY_TYPE),
466                             String (SCIM_ANTHY_CONFIG_TEN_KEY_TYPE_DEFAULT));
467
468         m_behavior_on_period
469             = config->read (String (SCIM_ANTHY_CONFIG_BEHAVIOR_ON_PERIOD),
470                             String (SCIM_ANTHY_CONFIG_BEHAVIOR_ON_PERIOD_DEFAULT));
471
472         m_behavior_on_focus_out
473             = config->read (String (SCIM_ANTHY_CONFIG_BEHAVIOR_ON_FOCUS_OUT),
474                             String (SCIM_ANTHY_CONFIG_BEHAVIOR_ON_FOCUS_OUT_DEFAULT));
475
476         m_cand_win_page_size
477             = config->read (String (SCIM_ANTHY_CONFIG_CAND_WIN_PAGE_SIZE),
478                             SCIM_ANTHY_CONFIG_CAND_WIN_PAGE_SIZE_DEFAULT);
479
480         m_show_candidates_label
481             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_CANDIDATES_LABEL),
482                             SCIM_ANTHY_CONFIG_SHOW_CANDIDATES_LABEL_DEFAULT);
483
484         m_close_cand_win_on_select
485             = config->read (String (SCIM_ANTHY_CONFIG_CLOSE_CAND_WIN_ON_SELECT),
486                             SCIM_ANTHY_CONFIG_CLOSE_CAND_WIN_ON_SELECT_DEFAULT);
487
488         m_n_triggers_to_show_cand_win
489             = config->read (String (SCIM_ANTHY_CONFIG_N_TRIGGERS_TO_SHOW_CAND_WIN),
490                             SCIM_ANTHY_CONFIG_N_TRIGGERS_TO_SHOW_CAND_WIN_DEFAULT);
491
492         m_learn_on_manual_commit
493             = config->read (String (SCIM_ANTHY_CONFIG_LEARN_ON_MANUAL_COMMIT),
494                             SCIM_ANTHY_CONFIG_LEARN_ON_MANUAL_COMMIT_DEFAULT);
495
496         m_learn_on_auto_commit
497             = config->read (String (SCIM_ANTHY_CONFIG_LEARN_ON_AUTO_COMMIT),
498                             SCIM_ANTHY_CONFIG_LEARN_ON_AUTO_COMMIT_DEFAULT);
499
500         m_romaji_half_symbol
501             = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_HALF_SYMBOL),
502                             SCIM_ANTHY_CONFIG_ROMAJI_HALF_SYMBOL_DEFAULT);
503
504         m_romaji_half_number
505             = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_HALF_NUMBER),
506                             SCIM_ANTHY_CONFIG_ROMAJI_HALF_NUMBER_DEFAULT);
507
508         m_romaji_allow_split
509             = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT),
510                             SCIM_ANTHY_CONFIG_ROMAJI_ALLOW_SPLIT_DEFAULT);
511
512         m_romaji_pseudo_ascii_mode
513             = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE),
514                             SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_MODE_DEFAULT);
515
516         m_romaji_pseudo_ascii_blank_behavior
517             = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_BLANK_BEHAVIOR),
518                             SCIM_ANTHY_CONFIG_ROMAJI_PSEUDO_ASCII_BLANK_BEHAVIOR_DEFAULT);
519
520         m_nicola_time
521             = config->read (String (SCIM_ANTHY_CONFIG_NICOLA_TIME),
522                             SCIM_ANTHY_CONFIG_NICOLA_TIME_DEFAULT);
523
524         str = config->read (String (SCIM_ANTHY_CONFIG_LEFT_THUMB_SHIFT_KEY),
525                             String (SCIM_ANTHY_CONFIG_LEFT_THUMB_SHIFT_KEY_DEFAULT));
526         scim_string_to_key_list (m_left_thumb_keys, str);
527
528         str = config->read (String (SCIM_ANTHY_CONFIG_RIGHT_THUMB_SHIFT_KEY),
529                             String (SCIM_ANTHY_CONFIG_RIGHT_THUMB_SHIFT_KEY_DEFAULT));
530         scim_string_to_key_list (m_right_thumb_keys, str);
531
532
533         m_dict_encoding
534             = config->read (String (SCIM_ANTHY_CONFIG_DICT_ENCODING),
535                             String (SCIM_ANTHY_CONFIG_DICT_ENCODING_DEFAULT));
536
537         m_dict_admin_command
538             = config->read (String (SCIM_ANTHY_CONFIG_DICT_ADMIN_COMMAND),
539                             String (SCIM_ANTHY_CONFIG_DICT_ADMIN_COMMAND_DEFAULT));
540
541         m_add_word_command
542             = config->read (String (SCIM_ANTHY_CONFIG_ADD_WORD_COMMAND),
543                             String (SCIM_ANTHY_CONFIG_ADD_WORD_COMMAND_DEFAULT));
544
545         m_predict_on_input
546             = config->read (String (SCIM_ANTHY_CONFIG_PREDICT_ON_INPUT),
547                             SCIM_ANTHY_CONFIG_PREDICT_ON_INPUT_DEFAULT);
548
549         m_use_direct_key_on_predict
550             = config->read (String (SCIM_ANTHY_CONFIG_USE_DIRECT_KEY_ON_PREDICT),
551                             SCIM_ANTHY_CONFIG_USE_DIRECT_KEY_ON_PREDICT_DEFAULT);
552
553         m_show_input_mode_label
554             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_INPUT_MODE_LABEL),
555                             SCIM_ANTHY_CONFIG_SHOW_INPUT_MODE_LABEL_DEFAULT);
556
557         m_show_conv_mode_label
558             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_CONVERSION_MODE_LABEL),
559                             SCIM_ANTHY_CONFIG_SHOW_CONVERSION_MODE_LABEL_DEFAULT);
560
561         m_show_typing_method_label
562             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_TYPING_METHOD_LABEL),
563                             SCIM_ANTHY_CONFIG_SHOW_TYPING_METHOD_LABEL_DEFAULT);
564
565         m_show_period_style_label
566             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_PERIOD_STYLE_LABEL),
567                             SCIM_ANTHY_CONFIG_SHOW_PERIOD_STYLE_LABEL_DEFAULT);
568
569         m_show_symbol_style_label
570             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_SYMBOL_STYLE_LABEL),
571                             SCIM_ANTHY_CONFIG_SHOW_SYMBOL_STYLE_LABEL_DEFAULT);
572
573         m_show_dict_label
574             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_DICT_LABEL),
575                             SCIM_ANTHY_CONFIG_SHOW_DICT_LABEL_DEFAULT);
576
577         m_show_dict_admin_label
578             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_DICT_ADMIN_LABEL),
579                             SCIM_ANTHY_CONFIG_SHOW_DICT_ADMIN_LABEL_DEFAULT);
580
581         m_show_add_word_label
582             = config->read (String (SCIM_ANTHY_CONFIG_SHOW_ADD_WORD_LABEL),
583                             SCIM_ANTHY_CONFIG_SHOW_ADD_WORD_LABEL_DEFAULT);
584
585         // color settings
586         int red, green, blue;
587
588         // preedit string color
589         m_preedit_style
590             = config->read (String (SCIM_ANTHY_CONFIG_PREEDIT_STYLE),
591                             String (SCIM_ANTHY_CONFIG_PREEDIT_STYLE_DEFAULT));
592         str = config->read (String (SCIM_ANTHY_CONFIG_PREEDIT_FG_COLOR),
593                             String (SCIM_ANTHY_CONFIG_PREEDIT_FG_COLOR_DEFAULT));
594         sscanf (str.c_str (), "#%02X%02X%02X", &red, &green, &blue);
595         m_preedit_fg_color = SCIM_RGB_COLOR (red, green, blue);
596
597         str = config->read (String (SCIM_ANTHY_CONFIG_PREEDIT_BG_COLOR),
598                             String (SCIM_ANTHY_CONFIG_PREEDIT_BG_COLOR_DEFAULT));
599         sscanf (str.c_str (), "#%02X%02X%02X", &red, &green, &blue);
600         m_preedit_bg_color = SCIM_RGB_COLOR (red, green, blue);
601
602         // conversion string color
603         m_conversion_style
604             = config->read (String (SCIM_ANTHY_CONFIG_CONVERSION_STYLE),
605                             String (SCIM_ANTHY_CONFIG_CONVERSION_STYLE_DEFAULT));
606         str = config->read (String (SCIM_ANTHY_CONFIG_CONVERSION_FG_COLOR),
607                             String (SCIM_ANTHY_CONFIG_CONVERSION_FG_COLOR_DEFAULT));
608         sscanf (str.c_str (), "#%02X%02X%02X", &red, &green, &blue);
609         m_conversion_fg_color = SCIM_RGB_COLOR (red, green, blue);
610
611         str = config->read (String (SCIM_ANTHY_CONFIG_CONVERSION_BG_COLOR),
612                             String (SCIM_ANTHY_CONFIG_CONVERSION_BG_COLOR_DEFAULT));
613         sscanf (str.c_str (), "#%02X%02X%02X", &red, &green, &blue);
614         m_conversion_bg_color = SCIM_RGB_COLOR (red, green, blue);
615
616         // selected segment color
617         m_selected_segment_style
618             = config->read (String (SCIM_ANTHY_CONFIG_SELECTED_SEGMENT_STYLE),
619                             String (SCIM_ANTHY_CONFIG_SELECTED_SEGMENT_STYLE_DEFAULT));
620         str = config->read (String (SCIM_ANTHY_CONFIG_SELECTED_SEGMENT_FG_COLOR),
621                             String (SCIM_ANTHY_CONFIG_SELECTED_SEGMENT_FG_COLOR_DEFAULT));
622         sscanf (str.c_str (), "#%02X%02X%02X", &red, &green, &blue);
623         m_selected_segment_fg_color = SCIM_RGB_COLOR (red, green, blue);
624
625         str = config->read (String (SCIM_ANTHY_CONFIG_SELECTED_SEGMENT_BG_COLOR),
626                             String (SCIM_ANTHY_CONFIG_SELECTED_SEGMENT_BG_COLOR_DEFAULT));
627         sscanf (str.c_str (), "#%02X%02X%02X", &red, &green, &blue);
628         m_selected_segment_bg_color = SCIM_RGB_COLOR (red, green, blue);
629     }
630
631     StyleFile style;
632     String file;
633     bool loaded = false;
634
635     // load key bindings
636     const char *section_key = "KeyBindings";
637     file = config->read (String (SCIM_ANTHY_CONFIG_KEY_THEME_FILE),
638                          String (SCIM_ANTHY_CONFIG_KEY_THEME_FILE_DEFAULT));
639     loaded = style.load (file.c_str ());
640
641     // clear old actions
642     m_actions.clear ();
643
644     // convert key
645     APPEND_ACTION (CONVERT,                 action_convert);
646     APPEND_ACTION (PREDICT,                 action_predict);
647
648     // candidates keys
649     APPEND_ACTION (CANDIDATES_PAGE_UP,      action_candidates_page_up);
650     APPEND_ACTION (CANDIDATES_PAGE_DOWN,    action_candidates_page_down);
651     APPEND_ACTION (SELECT_CANDIDATE_1,      action_select_candidate_1);
652     APPEND_ACTION (SELECT_CANDIDATE_2,      action_select_candidate_2);
653     APPEND_ACTION (SELECT_CANDIDATE_3,      action_select_candidate_3);
654     APPEND_ACTION (SELECT_CANDIDATE_4,      action_select_candidate_4);
655     APPEND_ACTION (SELECT_CANDIDATE_5,      action_select_candidate_5);
656     APPEND_ACTION (SELECT_CANDIDATE_6,      action_select_candidate_6);
657     APPEND_ACTION (SELECT_CANDIDATE_7,      action_select_candidate_7);
658     APPEND_ACTION (SELECT_CANDIDATE_8,      action_select_candidate_8);
659     APPEND_ACTION (SELECT_CANDIDATE_9,      action_select_candidate_9);
660     APPEND_ACTION (SELECT_CANDIDATE_10,     action_select_candidate_10);
661     APPEND_ACTION (SELECT_FIRST_CANDIDATE,  action_select_first_candidate);
662     APPEND_ACTION (SELECT_LAST_CANDIDATE,   action_select_last_candidate);
663     APPEND_ACTION (SELECT_NEXT_CANDIDATE,   action_select_next_candidate);
664     APPEND_ACTION (SELECT_PREV_CANDIDATE,   action_select_prev_candidate);
665
666     // segment keys
667     APPEND_ACTION (SELECT_FIRST_SEGMENT,    action_select_first_segment);
668     APPEND_ACTION (SELECT_LAST_SEGMENT,     action_select_last_segment);
669     APPEND_ACTION (SELECT_NEXT_SEGMENT,     action_select_next_segment);
670     APPEND_ACTION (SELECT_PREV_SEGMENT,     action_select_prev_segment);
671     APPEND_ACTION (SHRINK_SEGMENT,          action_shrink_segment);
672     APPEND_ACTION (EXPAND_SEGMENT,          action_expand_segment);
673     APPEND_ACTION (COMMIT_FIRST_SEGMENT,    action_commit_first_segment);
674     APPEND_ACTION (COMMIT_SELECTED_SEGMENT, action_commit_selected_segment);
675     APPEND_ACTION (COMMIT_FIRST_SEGMENT_REVERSE_LEARN,
676                    action_commit_first_segment_reverse_preference);
677     APPEND_ACTION (COMMIT_SELECTED_SEGMENT_REVERSE_LEARN,
678                    action_commit_selected_segment_reverse_preference);
679
680     // direct convert keys
681     APPEND_ACTION (CONV_CHAR_TYPE_FORWARD,  action_convert_char_type_forward);
682     APPEND_ACTION (CONV_CHAR_TYPE_BACKWARD, action_convert_char_type_backward);
683     APPEND_ACTION (CONV_TO_HIRAGANA,        action_convert_to_hiragana);
684     APPEND_ACTION (CONV_TO_KATAKANA,        action_convert_to_katakana);
685     APPEND_ACTION (CONV_TO_HALF,            action_convert_to_half);
686     APPEND_ACTION (CONV_TO_HALF_KATAKANA,   action_convert_to_half_katakana);
687     APPEND_ACTION (CONV_TO_LATIN,           action_convert_to_latin);
688     APPEND_ACTION (CONV_TO_WIDE_LATIN,      action_convert_to_wide_latin);
689
690     // pseudo ascii mode
691     APPEND_ACTION (CANCEL_PSEUDO_ASCII_MODE,action_cancel_pseudo_ascii_mode);
692
693     // caret keys
694     APPEND_ACTION (MOVE_CARET_FIRST,        action_move_caret_first);
695     APPEND_ACTION (MOVE_CARET_LAST,         action_move_caret_last);
696     APPEND_ACTION (MOVE_CARET_FORWARD,      action_move_caret_forward);
697     APPEND_ACTION (MOVE_CARET_BACKWARD,     action_move_caret_backward);
698
699     // edit keys
700     APPEND_ACTION (BACKSPACE,               action_back);
701     APPEND_ACTION (DELETE,                  action_delete);
702     APPEND_ACTION (COMMIT,                  action_commit_follow_preference);
703     APPEND_ACTION (COMMIT_REVERSE_LEARN,    action_commit_reverse_preference);
704     APPEND_ACTION (CANCEL,                  action_revert);
705     APPEND_ACTION (CANCEL_ALL,              action_cancel_all);
706     APPEND_ACTION (INSERT_SPACE,            action_insert_space);
707     APPEND_ACTION (INSERT_ALT_SPACE,        action_insert_alternative_space);
708     APPEND_ACTION (INSERT_HALF_SPACE,       action_insert_half_space);
709     APPEND_ACTION (INSERT_WIDE_SPACE,       action_insert_wide_space);
710
711     // mode keys
712     APPEND_ACTION (ON_OFF,                  action_on_off);
713     APPEND_ACTION (CIRCLE_INPUT_MODE,       action_circle_input_mode);
714     APPEND_ACTION (CIRCLE_KANA_MODE,        action_circle_kana_mode);
715     APPEND_ACTION (CIRCLE_TYPING_METHOD,    action_circle_typing_method);
716     APPEND_ACTION (LATIN_MODE,              action_latin_mode);
717     APPEND_ACTION (WIDE_LATIN_MODE,         action_wide_latin_mode);
718     APPEND_ACTION (HIRAGANA_MODE,           action_hiragana_mode);
719     APPEND_ACTION (KATAKANA_MODE,           action_katakana_mode);
720     APPEND_ACTION (HALF_KATAKANA_MODE,      action_half_katakana_mode);
721
722     // dict keys
723     APPEND_ACTION (DICT_ADMIN,              action_launch_dict_admin_tool);
724     APPEND_ACTION (ADD_WORD,                action_add_word);
725
726     // reconvert
727     APPEND_ACTION (RECONVERT,               action_reconvert);
728
729     // disabled key
730     APPEND_ACTION (DO_NOTHING,              action_do_nothing);
731
732     // load custom romaji table
733     const char *section_romaji = "RomajiTable/FundamentalTable";
734     file = config->read (String (SCIM_ANTHY_CONFIG_ROMAJI_THEME_FILE),
735                          String (SCIM_ANTHY_CONFIG_ROMAJI_THEME_FILE_DEFAULT));
736     if (m_custom_romaji_table) {
737         delete m_custom_romaji_table;
738         m_custom_romaji_table = NULL;
739     }
740     if (!file.empty() && style.load (file.c_str ())) {
741         m_custom_romaji_table = style.get_key2kana_table (section_romaji);
742     }
743
744     // load custom kana table
745     const char *section_kana = "KanaTable/FundamentalTable";
746     file = config->read (String (SCIM_ANTHY_CONFIG_KANA_LAYOUT_FILE),
747                          String (SCIM_ANTHY_CONFIG_KANA_LAYOUT_FILE_DEFAULT));
748     if (m_custom_kana_table) {
749         delete m_custom_kana_table;
750         m_custom_kana_table = NULL;
751     }
752     if (!file.empty () && style.load (file.c_str ())) {
753         m_custom_kana_table = style.get_key2kana_table (section_kana);
754     }
755
756     // load custom NICOLA table
757     const char *section_nicola = "NICOLATable/FundamentalTable";
758     file = config->read (String (SCIM_ANTHY_CONFIG_NICOLA_LAYOUT_FILE),
759                          String (SCIM_ANTHY_CONFIG_NICOLA_LAYOUT_FILE_DEFAULT));
760     if (m_custom_nicola_table) {
761         delete m_custom_nicola_table;
762         m_custom_nicola_table = NULL;
763     }
764     if (!file.empty () && style.load (file.c_str ())) {
765         m_custom_nicola_table = style.get_key2kana_table (section_nicola);
766     }
767
768     // special kana keys
769     m_kana_layout_ro_key
770         = config->read (String (SCIM_ANTHY_CONFIG_KANA_LAYOUT_RO_KEY),
771                         String (SCIM_ANTHY_CONFIG_KANA_LAYOUT_RO_KEY_DEFAULT));
772
773
774     // reload config for all instance
775     std::vector<AnthyInstance*>::iterator it;
776     for (it = m_config_listeners.begin();
777          it != m_config_listeners.end();
778          it++)
779     {
780         (*it)->reload_config (config);
781     }
782 }