예제 #1
0
static void
save_config (const ConfigPointer &config)
{
    if (!config.null ()) {
    //    config->write (String (SCIM_CONFIG_IMENGINE_ANTHY_USE_KANA),
    //                    __config_use_kana);
        config->write (String (SCIM_CONFIG_WNN_SERVER),
                       __config_server);
        config->write (String (SCIM_CONFIG_WNN_RC),
                       __config_wnn_rc);
        config->write (String (SCIM_CONFIG_WNN_SERVERTYPE),
                       __config_servertype);
        config->write (String (SCIM_CONFIG_WNN_DEFAULT_PREEDITOR),
                       __config_preeditor);
        config->write (String (SCIM_CONFIG_WNN_ALP),
                       __config_alp);
        config->write (String (SCIM_CONFIG_WNN_NUMKEY_SELECT),
                       __config_numkeyselect);
        config->write (String (SCIM_CONFIG_WNN_AUTO_CONVERSION),
                       __config_autoconversion);
        config->write (String (SCIM_CONFIG_WNN_YOSOKU),
                       __config_yosoku);
        config->write (String (SCIM_CONFIG_WNN_ROMKAN_TABLE_FILE),
                       __config_romkan_table);

        for (unsigned j = 0; j < __key_conf_pages_num; j++) {
            for (unsigned int i = 0; __key_conf_pages[j].data[i].key; ++ i) {
                config->write (String (__key_conf_pages[j].data[i].key),
                               __key_conf_pages[j].data[i].data);
            }
        }

        __have_changed = false;
    }
}
void save_config(const ConfigPointer& config)
{
    //Don't save to a null config file.
    if (config.null())
        return;

    //Flash our file: burmese_numerals
    int id = 0;
    for (int i=0; i<__burmese_numerals_config_opts; i++) {
        if (__config_burmese_numerals == __burmese_numerals_config_vals[i])
	    id = i;
    }
    config->write(String(SCIM_CONFIG_IMENGINE_WAITZAR_BURMESE_NUMERALS), String(__burmese_numerals_config_string[id]));

    //Flash our file: default_encoding
    id = 0;
    for (int i=0; i<__default_encoding_config_opts; i++) {
        if (__config_default_encoding == __default_encoding_config_vals[i])
	    id = i;
    }
    config->write(String(SCIM_CONFIG_IMENGINE_WAITZAR_DEFAULT_ENCODING), String(__default_encoding_config_string[id]));

    //The update is complete
    __has_changed = false;
}
예제 #3
0
void
romaji_page_save_config (const ConfigPointer &config)
{
    __config_romaji_theme_file
        = config->write (String (SCIM_ANTHY_CONFIG_ROMAJI_THEME_FILE),
                         String (__config_romaji_theme_file));
}
예제 #4
0
void
IMEngineHotkeyMatcher::save_hotkeys (const ConfigPointer &config) const
{
    if (config.null () || !config->valid () || !m_impl->m_uuids.size ()) return;

    KeyEventList keys;
    String keystr;
    std::vector <String> uuids;

    for (size_t i = 0; i < m_impl->m_uuids.size (); ++i) {
        if (m_impl->m_matcher.find_hotkeys ((int) i, keys) > 0 && scim_key_list_to_string (keystr, keys)) {
            config->write (String (SCIM_CONFIG_HOTKEYS_IMENGINE "/") + m_impl->m_uuids [i], keystr);
            uuids.push_back (m_impl->m_uuids [i]);
        }
    }

    config->write (String (SCIM_CONFIG_HOTKEYS_IMENGINE_LIST), scim_combine_string_list (uuids));
}
예제 #5
0
void
FrontEndHotkeyMatcher::save_hotkeys (const ConfigPointer &config) const
{
    if (config.null () || !config->valid ()) return;

    KeyEventList keys;
    String keystr;

    for (int i = SCIM_FRONTEND_HOTKEY_TRIGGER; i <= SCIM_FRONTEND_HOTKEY_SHOW_FACTORY_MENU; ++i) {
        if (m_impl->m_matcher.find_hotkeys (i, keys) > 0 && scim_key_list_to_string (keystr, keys))
            config->write (String (__scim_frontend_hotkey_config_paths [i]), keystr);
    }
}
    void
save_config (const ConfigPointer &config)
{
    if (!config.null ()) {
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_TOOLBAR_AUTO_SNAP),
                __config_toolbar_auto_snap);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_TOOLBAR_HIDE_TIMEOUT),
                __config_toolbar_hide_timeout);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_TOOLBAR_SHOW_FACTORY_ICON),
                __config_toolbar_show_factory_icon);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_TOOLBAR_SHOW_FACTORY_NAME),
                __config_toolbar_show_factory_name);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_TOOLBAR_SHOW_MENU_ICON),
                __config_toolbar_show_menu_icon);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_TOOLBAR_SHOW_HELP_ICON),
                __config_toolbar_show_help_icon);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_TOOLBAR_SHOW_PROPERTY_LABEL),
                __config_toolbar_show_property_label);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_FONT),
                __config_font);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_VKB_PROGRAM),
                __config_vkb_program);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_VKB_PARAMETERS),
                __config_vkb_parameters);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_VKB_WIDTH),
                __config_vkb_window_width);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_VKB_HEIGHT),
                __config_vkb_window_height);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_DOCK_PANEL),
                __config_vkb_dockpanel);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_PANEL_EXTEND),
                __config_vkb_panel_extend);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_ENABLE_VKB),
                __config_vkb_enable);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_PANEL_NORMAL_TEXT_COLOR),
                __config_vkb_panel_normal_text_color);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_PANEL_NORMAL_BG_COLOR),
                __config_vkb_panel_normal_bg_color);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_PANEL_ACTIVE_TEXT_COLOR),
                __config_vkb_panel_active_text_color);
        config->write (String (SCIM_CONFIG_PANEL_VKB_GTK_PANEL_ACTIVE_BG_COLOR),
                __config_vkb_panel_active_bg_color);

        __have_changed = false;
    }
}
예제 #7
0
void ScimBridgeAgentImpl::save_config ()
{
    scim_bridge_pdebugln (6, "save_config ()");

    scim_config->write (String (SCIM_CONFIG_FRONTEND_IM_OPENED_BY_DEFAULT), ScimBridgeAgentIMContext::is_enabled_by_default ());
}
예제 #8
0
void
save_config (const ConfigPointer &config)
{
    if (!config.null ()) {
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_HIDDEN),
                       __config_toolbar_always_hidden);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_SHOW),
                       __config_toolbar_always_show);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_AUTO_SNAP),
                       __config_toolbar_auto_snap);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_HIDE_TIMEOUT),
                       __config_toolbar_hide_timeout);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_ICON),
                       __config_toolbar_show_factory_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_NAME),
                       __config_toolbar_show_factory_name);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_STICK_ICON),
                       __config_toolbar_show_stick_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_MENU_ICON),
                       __config_toolbar_show_menu_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_HELP_ICON),
                       __config_toolbar_show_help_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_PROPERTY_LABEL),
                       __config_toolbar_show_property_label);
        config->write (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_EMBEDDED),
                        __config_lookup_table_embedded);
        config->write (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_VERTICAL),
                       __config_lookup_table_vertical);
        config->write (String (SCIM_CONFIG_PANEL_GTK_SHOW_TRAY_ICON),
                       __config_show_tray_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_DEFAULT_STICKED),
                       __config_default_sticked);
        config->write (String (SCIM_CONFIG_PANEL_GTK_FONT),
                       __config_font);

        __have_changed = false;
    }
}
예제 #9
0
int main (int argc, char *argv [])
{
    static ConfigModule  config_module;

    ConfigPointer        config;
    std::vector<String>  config_list;
    String               def_config;
    String               key;
    String               value;
    String               display;

    DataType             type = DATA_TYPE_STRING;
    Command              cmd = DO_NOTHING;
    bool                 reload = false;
    bool                 global = false;

    int                  i;

    char *p =  getenv ("DISPLAY");
    if (p) display = String (p);

    //get modules list
    scim_get_config_module_list (config_list);

    //Use simple Config module as default if available.
    if (config_list.size ()) {
        def_config = scim_global_config_read (SCIM_GLOBAL_CONFIG_DEFAULT_CONFIG_MODULE, String ("simple"));
        if (std::find (config_list.begin (),
                       config_list.end (),
                       def_config) == config_list.end ())
            def_config = config_list [0];
    } else {
        cerr << "No config module found.\n";
        return -1;
    }

    // parse command options
    i = 0;
    while (i<argc) {
        if (++i >= argc) break;

        if (String ("-h") == argv [i] ||
                String ("--help") == argv [i]) {
            cout << "Usage: " << argv [0] << " <option>...\n\n"
                 << "The options are:\n"
                 << "  -g, --get key        Get the value of this key.\n"
                 << "  -s, --set key=value  Set the value of this key.\n"
                 << "  -d, --del key        Delete the key and its data\n"
                 << "                       from user config file.\n"
                 << "  -t, --type type      The key value type, valid types are:\n"
                 << "                       string, int, double, bool, string-list,\n"
                 << "                       int-list. The default type is string.\n"
                 << "  -c, --config name    Use specified Config module,\n"
                 << "                       use simple module by default.\n"
                 << "                       Use \"global\" instead of a real config module name,\n"
                 << "                       if you want to access the global configuration file.\n"
                 << "                       (Normally they are /etc/scim/global and ~/.scim/global).\n"
                 << "  --reload             Force the running scim to reload configuration.\n"
                 << "  --display display    The display which scim Panel is running on,\n"
                 << "                       it's only useful when --reload is used.\n"
                 << "  -h, --help           Show this help.\n";
            return 0;
        }

        if (String ("-g") == argv [i] ||
                String ("--get") == argv [i]) {
            if (++i >= argc) {
                cerr << "No argument for option " << argv [i-1] << endl;
                return -1;
            }
            if (cmd != DO_NOTHING) {
                cerr << "You can only do one thing at the same time!\n";
                return -1;
            }
            key = String (argv [i]);
            cmd = GET_DATA;
            continue;
        }

        if (String ("-s") == argv [i] ||
                String ("--set") == argv [i]) {
            if (++i >= argc) {
                cerr << "No argument for option " << argv [i-1] << endl;
                return -1;
            }
            if (cmd != DO_NOTHING) {
                cerr << "You can only do one thing at the same time!\n";
                return -1;
            }

            String str (argv [i]);
            str = trim_blank (str);

            key = get_param_portion (str);
            value = get_value_portion (str);

            if (!key.length ()) {
                cerr << "Bad argument for option " << argv [i-1] << endl;
                return -1;
            }

            cmd = SET_DATA;
            continue;
        }

        if (String ("-d") == argv [i] ||
                String ("--del") == argv [i]) {
            if (++i >= argc) {
                cerr << "No argument for option " << argv [i-1] << endl;
                return -1;
            }
            if (cmd != DO_NOTHING) {
                cerr << "You can only do one thing at the same time!\n";
                return -1;
            }

            key = String (argv [i]);
            cmd = DEL_KEY;
            continue;
        }

        if (String ("-t") == argv [i] ||
                String ("--type") == argv [i]) {
            if (++i >= argc) {
                cerr << "No argument for option " << argv [i-1] << endl;
                return -1;
            }
            if (String (argv [i]) == "string")
                type = DATA_TYPE_STRING;
            else if (String (argv [i]) == "int")
                type = DATA_TYPE_INT;
            else if (String (argv [i]) == "double")
                type = DATA_TYPE_DOUBLE;
            else if (String (argv [i]) == "bool")
                type = DATA_TYPE_BOOL;
            else if (String (argv [i]) == "string-list")
                type = DATA_TYPE_STRING_LIST;
            else if (String (argv [i]) == "int-list")
                type = DATA_TYPE_STRING_LIST;
            else {
                cerr << "Bad argument for option " << argv [i-1] << endl;
                return -1;
            }
            continue;
        }

        if (String ("-c") == argv [i] ||
                String ("--config") == argv [i]) {
            if (++i >= argc) {
                cerr << "No argument for option " << argv [i-1] << endl;
                return -1;
            }
            def_config = String (argv [i]);
            continue;
        }

        if (String ("--display") == argv [i]) {
            if (++i >= argc) {
                cerr << "No argument for option " << argv [i-1] << endl;
                return -1;
            }
            display = String (argv [i]);
            continue;
        }

        if (String ("--reload") == argv [i]) {
            reload = true;
            continue;
        }

        cerr << "Unknown option " << argv [i] << endl;
        return -1;
    }

    if ((cmd == DO_NOTHING || !key.length ()) && reload == false) {
        cerr << "What do you want to do?\n";
        return -1;
    }

    if (cmd != DO_NOTHING) {
        if (def_config == "global") {
            global = true;
        } else {
            if (!config_module.load (def_config)) {
                cerr << "Failed to load config module " << def_config << endl;
                return -1;
            }

            config = config_module.create_config ();

            if (config.null ()) {
                cerr << "Failed to create config object.\n";
                return -1;
            }
        }
    }

    // Get data
    if (cmd == GET_DATA) {
        bool ok = false;
        if (type == DATA_TYPE_STRING) {
            if (global) {
                value = scim_global_config_read (key, String (""));
                ok = (scim_global_config_read (key, String ("Invalid")) == value);
            } else {
                ok = config->read (key, &value);
            }
            if (ok) cout << value << endl;
        } else if (type == DATA_TYPE_INT) {
            int intval;
            if (global) {
                intval = scim_global_config_read (key, (int) 0);
                ok = (scim_global_config_read (key, (int) 0) == intval);
            } else {
                ok = config->read (key, &intval);
            }
            if (ok) cout << intval << endl;
        } else if (type == DATA_TYPE_DOUBLE) {
            double doubleval;
            if (global) {
                doubleval = scim_global_config_read (key, (double) 0);
                ok = (scim_global_config_read (key, (double) 1) == doubleval);
            } else {
                ok = config->read (key, &doubleval);
            }
            if (ok) cout << doubleval << endl;
        } else if (type == DATA_TYPE_BOOL) {
            bool boolval;
            if (global) {
                boolval = scim_global_config_read (key, (bool) false);
                ok = (scim_global_config_read (key, (bool) true) == boolval);
            } else {
                ok = config->read (key, &boolval);
            }
            if (ok) cout << (boolval ? "true" : "false") << endl;
        } else if (type == DATA_TYPE_STRING_LIST) {
            std::vector <String> strlistval;
            if (global) {
                strlistval = scim_global_config_read (key, strlistval);
                ok = (strlistval.size () > 0);
            } else {
                ok = config->read (key, &strlistval);
            }
            if (ok) cout << scim_combine_string_list (strlistval, ',') << endl;
        } else if (type == DATA_TYPE_INT_LIST) {
            std::vector <int> intlistval;
            if (global) {
                intlistval = scim_global_config_read (key, intlistval);
                ok = (intlistval.size () > 0);
            } else {
                ok = config->read (key, &intlistval);
            }

            if (ok) {
                for (size_t i = 0; i<intlistval.size (); ++i) {
                    cout << intlistval [i];
                    if (i < intlistval.size () - 1)
                        cout << ",";
                }
                cout << endl;
            }
        }

        if (!ok) {
            cerr << "Failed to get key value.\n";
            return -1;
        }
    }

    // Set data
    else if (cmd == SET_DATA) {
        bool ok = true;
        if (type != DATA_TYPE_STRING && !value.length ()) {
            ok = false;
        } else if (type == DATA_TYPE_STRING) {
            if (global) {
                scim_global_config_write (key, value);
            } else {
                ok = config->write (key, value);
            }
        } else if (type == DATA_TYPE_INT) {
            int intval = strtol (value.c_str (), 0, 10);
            if (global) {
                scim_global_config_write (key, intval);
            } else {
                ok = config->write (key, intval);
            }
        } else if (type == DATA_TYPE_DOUBLE) {
            double doubleval = strtod (value.c_str (), 0);
            if (global) {
                scim_global_config_write (key, doubleval);
            } else {
                ok = config->write (key, doubleval);
            }
        } else if (type == DATA_TYPE_BOOL) {
            bool boolval = false;
            if (value == "true" || value == "True" || value == "TRUE" || value == "1")
                boolval = true;

            if (global) {
                scim_global_config_write (key, boolval);
            } else {
                ok = config->write (key, boolval);
            }
        } else if (type == DATA_TYPE_STRING_LIST) {
            std::vector <String> strlistval;
            scim_split_string_list (strlistval, value, ',');

            if (global) {
                scim_global_config_write (key, strlistval);
            } else {
                ok = config->write (key, strlistval);
            }
        } else if (type == DATA_TYPE_INT_LIST) {
            std::vector <int> intlistval;
            std::vector <String> strlist;
            scim_split_string_list (strlist, value, ',');
            for (size_t i = 0; i<strlist.size (); ++i)
                intlistval.push_back (strtol (strlist[i].c_str (), 0, 10));

            if (global) {
                scim_global_config_write (key, intlistval);
            } else {
                ok = config->write (key, intlistval);
            }
        }

        if (global)
            ok = scim_global_config_flush ();

        if (!ok) {
            cerr << "Failed to set key value.\n";
            return -1;
        } else {
            cout << "Set data success.\n";
            if (!global) config->flush ();
        }
    }

    // Delete key
    else if (cmd == DEL_KEY) {
        bool ok = false;

        if (global) {
            scim_global_config_reset (key);
            ok = scim_global_config_flush ();
        } else {
            ok = config->erase (key);
        }

        if (ok) {
            cout << "Delete key success.\n";
            if (!global) config->flush ();
        } else {
            cerr << "Failed to delete the key.\n";
            return -1;
        }
    }

    if (reload) {
        HelperInfo   helper_info ("41b79480-c5d2-4929-9456-11d519c26b87", "scim-config-agent", "", "", SCIM_HELPER_STAND_ALONE);
        HelperAgent  helper_agent;

        int          id;

        id = helper_agent.open_connection (helper_info, display);

        if (id < 0) {
            cerr << "Unable to open the connection to scim Panel.\n";
            return -1;
        }

        helper_agent.reload_config ();

        cout << "Configuration reload request has been sent to the running scim.\n";

        helper_agent.close_connection ();
    }

    return 0;
}
void save_config( const ConfigPointer &config )
{
	if ( ! config.null() ) {
		config->write( String( SCIM_CONFIG_IMENGINE_CHEWING_ADD_PHRASE_FORWARD ),
				__config_add_phrase_forward );

		config->write( String( SCIM_CONFIG_IMENGINE_CHEWING_PHRASE_CHOICE_REARWARD ),
				__config_phrase_choice_rearward );

		config->write( String( SCIM_CONFIG_IMENGINE_CHEWING_AUTO_SHIFT_CURSOR ),
				__config_auto_shift_cursor );

		config->write( String( SCIM_CONFIG_IMENGINE_CHEWING_ESC_CLEAN_ALL_BUFFER ),
				__config_esc_clean_all_buffer );

		config->write( String( SCIM_CONFIG_IMENGINE_CHEWING_SPACE_AS_SELECTION ),
				__config_space_as_selection );

		// SCIM_CONFIG_IMENGINE_CHEWING_USER_KB_TYPE
		int index_keymap = 
			(sizeof(builtin_keymaps) / sizeof(_builtin_keymap)) - 1;
		for ( ; index_keymap >= 0;  index_keymap--) {
			if (__config_kb_type_data_translated == 
				builtin_keymaps[index_keymap].translated_name ) {
				break;
			}
		}
		if (index_keymap < 0)
			index_keymap = 0;
		__config_kb_type_data = builtin_keymaps[index_keymap].entry;

		config->write (String (SCIM_CONFIG_IMENGINE_CHEWING_USER_KB_TYPE),
			__config_kb_type_data);

		// SCIM_CONFIG_IMENGINE_CHEWING_USER_SELECTION_KEYS
		int index_selectkeys =
			sizeof(builtin_selectkeys) / sizeof(builtin_selectkeys[0]) - 1;
		for ( ; index_selectkeys >= 0; index_selectkeys--) {
			if (__config_selKey_type_data ==
			    builtin_selectkeys[index_selectkeys]) {
				break;
			}
		}
		if (index_selectkeys < 0)
			index_selectkeys = 0;
		__config_selKey_type_data =
			builtin_selectkeys[index_selectkeys];

		config->write (String (SCIM_CONFIG_IMENGINE_CHEWING_USER_SELECTION_KEYS),
				__config_selKey_type_data);

		// SCIM_CHEWING_SELECTION_KEYS_NUM
		int index_selectkeys_num =
			sizeof(builtin_selectkeys_num) / sizeof(builtin_selectkeys_num[0]) - 1;
		for ( ; index_selectkeys_num >= 0; index_selectkeys_num--) {
			if (__config_selKey_num_data ==
			    builtin_selectkeys_num[index_selectkeys_num]) {
				break;
			}
		}
		if (index_selectkeys_num < 0)
			index_selectkeys_num = 0;
		__config_selKey_num_data =
			builtin_selectkeys_num[index_selectkeys_num];

		config->write (String (SCIM_CHEWING_SELECTION_KEYS_NUM),
		               __config_selKey_num_data);

		// SCIM_CONFIG_IMENGINE_CHEWING_CHI_ENG_MODE
		int index_chieng_mode =
			sizeof(builtin_chieng_mode) / sizeof(builtin_chieng_mode[0]) - 1;
		for ( ; index_chieng_mode >= 0; index_chieng_mode--) {
			if (__config_chieng_mode_data ==
			    builtin_chieng_mode[index_chieng_mode]) {
				break;
			}
		}
		if (index_chieng_mode < 0)
			index_chieng_mode = 0;
		__config_chieng_mode_data =
			builtin_chieng_mode[index_chieng_mode];

		config->write (String (SCIM_CONFIG_IMENGINE_CHEWING_CHI_ENG_MODE)		               , __config_chieng_mode_data);

		for (int i = 0; __config_keyboards [i].key; ++ i) {
			config->write (String (__config_keyboards [i].key),
					__config_keyboards [i].data);
		}

		for (unsigned int i = 0;
		     i < (sizeof(config_color_common) / sizeof((config_color_common)[0])); i++) {
			ColorConfigData &entry = config_color_common[i];
			if (entry.changed) {
				entry.bg_value = config->write (String (entry.bg_key),
						entry.bg_value);
			}
			entry.changed = false;
		}


		__have_changed = false;
	}
}