/* * Copyright © 2013 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the eetific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include "wkb-ibus-config-eet.h" /* * Base struct for all config types */ struct _config_section { const char *id; void (*free)(struct _config_section *); void (*set_defaults)(struct _config_section *); Eina_Bool (*set_value)(struct _config_section *, const char *, const char *, Eldbus_Message_Iter *); void *(*get_value)(struct _config_section *, const char *, const char *); void *(*get_values)(struct _config_section *, const char *); }; static void _config_section_free(struct _config_section *base) { eina_stringshare_del(base->id); base->free(base); } static void _config_section_set_defaults(struct _config_section *base) { base->set_defaults(base); } static Eina_Bool _config_section_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { return base->set_value(base, section, name, value); } static void * _config_section_get_value(struct _config_section *base, const char *section, const char *name) { return base->get_value(base, section, name); } static void * _config_section_get_values(struct _config_section *base, const char *section) { return base->get_values(base, section); } /* * Helpers for manipulating list of strings */ static void _config_string_list_free(Eina_List *list) { const char *str; EINA_LIST_FREE(list, str) eina_stringshare_del(str); eina_list_free(list); } static Eina_List * _config_string_list_new(const char **strs) { Eina_List *list = NULL; const char *str; for (str = *strs; str != NULL; str = *++strs) list = eina_list_append(list, eina_stringshare_add(str)); return list; } /* * * * [ 'Control+space', 'Zenkaku_Hankaku', 'Alt+Kanji', 'Alt+grave', 'Hangul', 'Alt+Release+Alt_R' ] * Trigger shortcut keys * The shortcut keys for turning input method on or off * * * [ '<Super>space' ] * Trigger shortcut keys for gtk_accelerator_parse * The shortcut keys for turning input method on or off * * * [] * Enable shortcut keys * The shortcut keys for turning input method on * * * [] * Disable shortcut keys * The shortcut keys for turning input method off * * * [ 'Alt+Shift_L' ] * Next engine shortcut keys * The shortcut keys for switching to the next input method in the list * * * [ 'Alt+Shift_L' ] * Next engine shortcut keys * The shortcut keys for switching to the next input method in the list * * * [] * Prev engine shortcut keys * The shortcut keys for switching to the previous input method * * * [] * Prev engine shortcut keys * The shortcut keys for switching to the previous input method * * */ struct _config_hotkey { struct _config_section base; Eina_List *trigger; Eina_List *triggers; Eina_List *enable_unconditional; Eina_List *disable_unconditional; Eina_List *next_engine; Eina_List *next_engine_in_menu; Eina_List *prev_engine; Eina_List *previous_engine; }; static Eet_Data_Descriptor * _config_hotkey_edd_new(void) { Eet_Data_Descriptor *edd; Eet_Data_Descriptor_Class eddc; EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, struct _config_hotkey); edd = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "trigger", trigger); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "triggers", triggers); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "enable-unconditional", enable_unconditional); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "disable-unconditional", disable_unconditional); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "next-engine", next_engine); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "next-engine-in-menu", next_engine_in_menu); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "prev-engine", prev_engine); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hotkey, "previous-engine", previous_engine); return edd; } static void _config_hotkey_set_defaults(struct _config_section *base) { struct _config_hotkey *hotkey = (struct _config_hotkey *) base; const char *trigger[] = { "Control+space", "Zenkaku_Hankaku", "Alt+Kanji", "Alt+grave", "Hangul", "Alt+Release+Alt_R", NULL }; const char *triggers[] = { "space", NULL }; const char *enable_unconditional[] = { NULL }; const char *disable_unconditional[] = { NULL }; const char *next_engine[] = { NULL }; const char *next_engine_in_menu[] = { NULL }; const char *prev_engine[] = { NULL }; const char *previous_engine[] = { NULL }; hotkey->trigger = _config_string_list_new(trigger); hotkey->triggers = _config_string_list_new(triggers); hotkey->enable_unconditional = _config_string_list_new(enable_unconditional); hotkey->disable_unconditional = _config_string_list_new(disable_unconditional); hotkey->next_engine = _config_string_list_new(next_engine); hotkey->next_engine_in_menu = _config_string_list_new(next_engine_in_menu); hotkey->prev_engine = _config_string_list_new(prev_engine); hotkey->previous_engine = _config_string_list_new(previous_engine); } static void _config_hotkey_free(struct _config_section *base) { struct _config_hotkey *hotkey = (struct _config_hotkey *) base; _config_string_list_free(hotkey->trigger); _config_string_list_free(hotkey->triggers); _config_string_list_free(hotkey->enable_unconditional); _config_string_list_free(hotkey->disable_unconditional); _config_string_list_free(hotkey->next_engine); _config_string_list_free(hotkey->next_engine_in_menu); _config_string_list_free(hotkey->prev_engine); _config_string_list_free(hotkey->previous_engine); free(hotkey); } static Eina_Bool _config_hotkey_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { return EINA_FALSE; } static void * _config_hotkey_get_value(struct _config_section *base, const char *section, const char *name) { return NULL; } static void * _config_hotkey_get_values(struct _config_section *base, const char *section) { return NULL; } static void _config_hotkey_section_init(struct _config_section *base) { base->id = eina_stringshare_add("hotkey"); base->free = _config_hotkey_free; base->set_defaults = _config_hotkey_set_defaults; base->set_value = _config_hotkey_set_value; base->get_value = _config_hotkey_get_value; base->get_values = _config_hotkey_get_values; } static struct _config_section * _config_hotkey_new(void) { struct _config_hotkey *conf = calloc(1, sizeof(*conf)); _config_hotkey_section_init((struct _config_section *) conf); return (struct _config_section *) conf; } /* * * * [] * Preload engines * Preload engines during ibus starts up * * * [] * Engines order * Saved engines order in input method list * * * 400 * Popup delay milliseconds for IME switcher window * Set popup delay milliseconds to show IME switcher window. The default is 400. 0 = Show the window immediately. 0 < Delay milliseconds. 0 > Do not show the * * * '' * Saved version number * The saved version number will be used to check the difference between the version of the previous installed ibus and one of the current ibus. * * * false * Use system keyboard layout * Use system keyboard (XKB) layout * * * true * Embed Preedit Text * Embed Preedit Text in Application Window * * * false * Use global input method * Share the same input method among all applications * * * false * Enable input method by default * Enable input method by default when the application gets input focus * * * [ '/desktop/ibus/engine/pinyin', '/desktop/ibus/engine/bopomofo', '/desktop/ibus/engine/hangul' ] * DConf preserve name prefixes * Prefixes of DConf keys to stop name conversion * * * */ struct _config_general { struct _config_section base; struct _config_section *hotkey; Eina_List *preload_engines; Eina_List *engines_order; Eina_List *dconf_preserve_name_prefixes; const char *version; int switcher_delay_time; Eina_Bool use_system_keyboard_layout; Eina_Bool embed_preedit_text; Eina_Bool use_global_engine; Eina_Bool enable_by_default; }; static Eet_Data_Descriptor * _config_general_edd_new(Eet_Data_Descriptor *hotkey_edd) { Eet_Data_Descriptor *edd; Eet_Data_Descriptor_Class eddc; EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, struct _config_general); edd = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_general, "preload-engines", preload_engines); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_general, "engines-order", engines_order); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_general, "switcher-delay-time", switcher_delay_time, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_general, "version", version, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_general, "use-system-keyboard-layout", use_system_keyboard_layout, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_general, "embed-preedit-text", embed_preedit_text, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_general, "use-global-engine", use_global_engine, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_general, "enable-by-default", enable_by_default, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_general, "dconf-preserve-name-prefixes", dconf_preserve_name_prefixes); EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct _config_general, "hotkey", hotkey, hotkey_edd); return edd; } static void _config_general_set_defaults(struct _config_section *base) { struct _config_general *general = (struct _config_general *) base; const char *preload_engines[] = { NULL }; const char *engines_order[] = { NULL }; const char *dconf_preserve_name_prefixes[] = { "/desktop/ibus/engine/pinyin", "/desktop/ibus/engine/bopomofo", "/desktop/ibus/engine/hangul", NULL }; _config_section_set_defaults(general->hotkey); general->preload_engines = _config_string_list_new(preload_engines); general->engines_order = _config_string_list_new(engines_order); general->switcher_delay_time = 400; general->version = eina_stringshare_add(""); general->use_system_keyboard_layout = EINA_FALSE; general->embed_preedit_text = EINA_TRUE; general->use_global_engine = EINA_FALSE; general->enable_by_default = EINA_FALSE; general->dconf_preserve_name_prefixes = _config_string_list_new(dconf_preserve_name_prefixes); } static void _config_general_free(struct _config_section *base) { struct _config_general *general = (struct _config_general *) base; _config_section_free(general->hotkey); _config_string_list_free(general->preload_engines); _config_string_list_free(general->engines_order); _config_string_list_free(general->dconf_preserve_name_prefixes); eina_stringshare_del(general->version); free(general); } static Eina_Bool _config_general_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { return EINA_FALSE; } static void * _config_general_get_value(struct _config_section *base, const char *section, const char *name) { return NULL; } static void * _config_general_get_values(struct _config_section *base, const char *section) { return NULL; } static void _config_general_section_init(struct _config_section *base) { struct _config_general *general = (struct _config_general *) base; base->id = eina_stringshare_add("general"); base->free = _config_general_free; base->set_defaults = _config_general_set_defaults; base->set_value = _config_general_set_value; base->get_value = _config_general_get_value; base->get_values = _config_general_get_values; if (general->hotkey) _config_hotkey_section_init(general->hotkey); } static struct _config_section * _config_general_new(void) { struct _config_general *conf = calloc(1, sizeof(*conf)); _config_general_section_init((struct _config_section *) conf); conf->hotkey = _config_hotkey_new(); return (struct _config_section *) conf; } /* * * * 0 * Auto hide * The behavior of language panel. 0 = Embedded in menu, 1 = Auto hide, 2 = Always show * * * -1 * Language panel position * * * -1 * Language panel position * * * 1 * Orientation of lookup table * Orientation of lookup table. 0 = Horizontal, 1 = Vertical * * * true * Show icon on system tray * Show icon on system tray * * * false * Show input method name * Show input method name on language bar * * * false * Use custom font * Use custom font name for language panel * * * 'Sans 10' * Custom font * Custom font name for language panel * * */ struct _config_panel { struct _config_section base; const char *custom_font; int show; int x; int y; int lookup_table_orientation; Eina_Bool show_icon_in_systray; Eina_Bool show_im_name; Eina_Bool use_custom_font; }; static Eet_Data_Descriptor * _config_panel_edd_new(void) { Eet_Data_Descriptor *edd; Eet_Data_Descriptor_Class eddc; EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, struct _config_panel); edd = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "show", show, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "x", x, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "y", y, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "lookup-table-orientation", lookup_table_orientation, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "show-icon-in-systray", show_icon_in_systray, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "show-im-name", show_im_name, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "use-custom-font", use_custom_font, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_panel, "custom-font", custom_font, EET_T_STRING); return edd; } static void _config_panel_set_defaults(struct _config_section *base) { struct _config_panel *panel = (struct _config_panel *) base; panel->show = 0; panel->x = -1; panel->y = -1; panel->lookup_table_orientation = 1; panel->show_icon_in_systray = EINA_TRUE; panel->show_im_name = EINA_FALSE; panel->use_custom_font = EINA_FALSE; panel->custom_font = eina_stringshare_add("Sans 10"); } static void _config_panel_free(struct _config_section *base) { struct _config_panel *panel = (struct _config_panel *) base; eina_stringshare_del(panel->custom_font); free(panel); } static Eina_Bool _config_panel_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { return EINA_FALSE; } static void * _config_panel_get_value(struct _config_section *base, const char *section, const char *name) { return NULL; } static void * _config_panel_get_values(struct _config_section *base, const char *section) { return NULL; } static void _config_panel_section_init(struct _config_section *base) { base->id = eina_stringshare_add("panel"); base->free = _config_panel_free; base->set_defaults = _config_panel_set_defaults; base->set_value = _config_panel_set_value; base->get_value = _config_panel_get_value; base->get_values = _config_panel_get_values; } static struct _config_section * _config_panel_new(void) { struct _config_panel *conf = calloc(1, sizeof(*conf)); _config_panel_section_init((struct _config_section *) conf); return (struct _config_section *) conf; } /* * NO SCHEMA AVAILABLE. BASED ON THE SOURCE CODE */ struct _config_hangul { struct _config_section base; const char *hangul_keyboard; Eina_List *hanja_keys; Eina_Bool word_commit; Eina_Bool auto_reorder; }; static Eet_Data_Descriptor * _config_hangul_edd_new(void) { Eet_Data_Descriptor *edd; Eet_Data_Descriptor_Class eddc; EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, struct _config_hangul); edd = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_hangul, "HangulKeyboard", hangul_keyboard, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct _config_hangul, "HanjaKeys", hanja_keys); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_hangul, "WordCommit", word_commit, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct _config_hangul, "AutoReorder", auto_reorder, EET_T_UCHAR); return edd; } static void _config_hangul_set_defaults(struct _config_section *base) { struct _config_hangul *hangul = (struct _config_hangul *) base; const char *hanja_keys[] = { "Hangul_Hanja", "F9", NULL }; hangul->hangul_keyboard = eina_stringshare_add("2"); hangul->hanja_keys = _config_string_list_new(hanja_keys); hangul->word_commit = EINA_FALSE; hangul->auto_reorder = EINA_TRUE; } static void _config_hangul_free(struct _config_section *base) { struct _config_hangul *hangul = (struct _config_hangul *) base; eina_stringshare_del(hangul->hangul_keyboard); _config_string_list_free(hangul->hanja_keys); free(hangul); } static Eina_Bool _config_hangul_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { return EINA_FALSE; } static void * _config_hangul_get_value(struct _config_section *base, const char *section, const char *name) { return NULL; } static void * _config_hangul_get_values(struct _config_section *base, const char *section) { return NULL; } static void _config_hangul_section_init(struct _config_section *base) { base->id = eina_stringshare_add("hangul"); base->free = _config_hangul_free; base->set_defaults = _config_hangul_set_defaults; base->set_value = _config_hangul_set_value; base->get_value = _config_hangul_get_value; base->get_values = _config_hangul_get_values; } static struct _config_section * _config_hangul_new(void) { struct _config_hangul *conf = calloc(1, sizeof(*conf)); _config_hangul_section_init((struct _config_section *) conf); return (struct _config_section *) conf; } /* * NO SCHEMA AVAILABLE. BASED ON THE SOURCE CODE */ struct _config_engine { struct _config_section base; struct _config_section *hangul; }; static Eet_Data_Descriptor * _config_engine_edd_new(Eet_Data_Descriptor *hangul_edd) { Eet_Data_Descriptor *edd; Eet_Data_Descriptor_Class eddc; EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, struct _config_engine); edd = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct _config_engine, "Hangul", hangul, hangul_edd); return edd; } static void _config_engine_set_defaults(struct _config_section *base) { struct _config_engine *engine = (struct _config_engine *) base; _config_section_set_defaults(engine->hangul); } static void _config_engine_free(struct _config_section *base) { struct _config_engine *engine = (struct _config_engine *) base; _config_section_free(engine->hangul); free(engine); } static Eina_Bool _config_engine_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { return EINA_FALSE; } static void * _config_engine_get_value(struct _config_section *base, const char *section, const char *name) { return NULL; } static void * _config_engine_get_values(struct _config_section *base, const char *section) { return NULL; } static void _config_engine_section_init(struct _config_section *base) { struct _config_engine *engine = (struct _config_engine *) base; base->id = eina_stringshare_add("engine"); base->free = _config_engine_free; base->set_defaults = _config_engine_set_defaults; base->set_value = _config_engine_set_value; base->get_value = _config_engine_get_value; base->get_values = _config_engine_get_values; if (engine->hangul) _config_hangul_section_init(engine->hangul); } static struct _config_section * _config_engine_new(void) { struct _config_engine *conf = calloc(1, sizeof(*conf)); _config_engine_section_init((struct _config_section *) conf); conf->hangul = _config_hangul_new(); return (struct _config_section *) conf; } /* * * * * */ struct _config_ibus { struct _config_section base; struct _config_section *general; struct _config_section *panel; struct _config_section *engine; }; static Eet_Data_Descriptor * _config_ibus_edd_new(Eet_Data_Descriptor *general_edd, Eet_Data_Descriptor *panel_edd, Eet_Data_Descriptor *engine_edd) { Eet_Data_Descriptor *edd; Eet_Data_Descriptor_Class eddc; EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, struct _config_ibus); edd = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct _config_ibus, "general", general, general_edd); EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct _config_ibus, "panel", panel, panel_edd); EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct _config_ibus, "engine", engine, engine_edd); return edd; } static void _config_ibus_set_defaults(struct _config_section *base) { struct _config_ibus *ibus = (struct _config_ibus *) base; _config_section_set_defaults(ibus->general); _config_section_set_defaults(ibus->panel); _config_section_set_defaults(ibus->engine); } static void _config_ibus_free(struct _config_section *base) { struct _config_ibus *ibus = (struct _config_ibus *) base; _config_section_free(ibus->general); _config_section_free(ibus->panel); _config_section_free(ibus->engine); free(ibus); } static Eina_Bool _config_ibus_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { return EINA_FALSE; } static void * _config_ibus_get_value(struct _config_section *base, const char *section, const char *name) { return NULL; } static void * _config_ibus_get_values(struct _config_section *base, const char *section) { return NULL; } static void _config_ibus_section_init(struct _config_section *base) { struct _config_ibus *ibus = (struct _config_ibus *) base; base->id = eina_stringshare_add("ibus"); base->free = _config_ibus_free; base->set_defaults = _config_ibus_set_defaults; base->set_value = _config_ibus_set_value; base->get_value = _config_ibus_get_value; base->get_values = _config_ibus_get_values; if (ibus->general) _config_general_section_init(ibus->general); if (ibus->panel) _config_panel_section_init(ibus->panel); if (ibus->engine) _config_engine_section_init(ibus->engine); } static struct _config_section * _config_ibus_new(void) { struct _config_ibus *conf = calloc(1, sizeof(*conf)); _config_ibus_section_init((struct _config_section *) conf); conf->general = _config_general_new(); conf->panel = _config_panel_new(); conf->engine = _config_engine_new(); return (struct _config_section *) conf; } /* * MAIN */ struct wkb_ibus_config_eet { const char *path; struct _config_section *ibus_config; Eet_Data_Descriptor *hotkey_edd; Eet_Data_Descriptor *general_edd; Eet_Data_Descriptor *panel_edd; Eet_Data_Descriptor *hangul_edd; Eet_Data_Descriptor *engine_edd; Eet_Data_Descriptor *ibus_edd; }; Eina_Bool wkb_ibus_config_eet_set_value(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name, Eldbus_Message_Iter *value) { return _config_section_set_value(config_eet->ibus_config, section, name, value); } void * wkb_ibus_config_eet_get_value(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name) { return _config_section_get_value(config_eet->ibus_config, section, name); } void * wkb_ibus_config_eet_get_values(struct wkb_ibus_config_eet *config_eet, const char *section) { return _config_section_get_values(config_eet->ibus_config, section); } void wkb_ibus_config_eet_set_defaults(struct wkb_ibus_config_eet *config_eet) { if (config_eet->ibus_config) _config_section_free(config_eet->ibus_config); config_eet->ibus_config = _config_ibus_new(); _config_ibus_set_defaults(config_eet->ibus_config); } static struct wkb_ibus_config_eet * _config_eet_section_init(const char *path) { struct wkb_ibus_config_eet *eet = calloc(1, sizeof(*eet)); eet->path = eina_stringshare_add(path); eet->hotkey_edd = _config_hotkey_edd_new(); eet->general_edd = _config_general_edd_new(eet->hotkey_edd); eet->panel_edd = _config_panel_edd_new(); eet->hangul_edd = _config_hangul_edd_new(); eet->engine_edd = _config_engine_edd_new(eet->hangul_edd); eet->ibus_edd = _config_ibus_edd_new(eet->general_edd, eet->panel_edd, eet->engine_edd); return eet; } static Eina_Bool _config_eet_exists(const char *path) { struct stat buf; return stat(path, &buf) == 0; } struct wkb_ibus_config_eet * wkb_ibus_config_eet_new(const char *path) { struct wkb_ibus_config_eet *eet = _config_eet_section_init(path); Eet_File *ef = NULL; Eet_File_Mode mode = EET_FILE_MODE_READ_WRITE; if (_config_eet_exists(path)) mode = EET_FILE_MODE_READ; if (!(ef = eet_open(path, mode))) { fprintf(stderr,"Error opening eet file '%s' for %s\n", path, mode == EET_FILE_MODE_READ ? "read" : "write"); wkb_ibus_config_eet_free(eet); return NULL; } if (mode == EET_FILE_MODE_READ) { eet->ibus_config = eet_data_read(ef, eet->ibus_edd, "ibus"); _config_ibus_section_init(eet->ibus_config); goto end; } wkb_ibus_config_eet_set_defaults(eet); if (!eet_data_write(ef, eet->ibus_edd, "ibus", eet->ibus_config, EINA_TRUE)) { fprintf(stderr,"Error creating eet file '%s'\n", path); wkb_ibus_config_eet_free(eet); eet = NULL; } end: eet_close(ef); return eet; } void wkb_ibus_config_eet_free(struct wkb_ibus_config_eet *config_eet) { _config_ibus_free(config_eet->ibus_config); eina_stringshare_del(config_eet->path); eet_data_descriptor_free(config_eet->hotkey_edd); eet_data_descriptor_free(config_eet->general_edd); eet_data_descriptor_free(config_eet->panel_edd); eet_data_descriptor_free(config_eet->hangul_edd); eet_data_descriptor_free(config_eet->engine_edd); eet_data_descriptor_free(config_eet->ibus_edd); free(config_eet); }