Ejemplo n.º 1
0
static void *on_create (ui_gadget_h ug, enum ug_mode mode, service_h s, void *priv)
{
    Evas_Object *parent = NULL;
    Evas_Object *content = NULL;

    if ( ug == NULL || priv == NULL)
        return NULL;

    bindtextdomain (WIZARD_PACKAGE, WIZARD_LOCALEDIR);

    struct ug_data *ugd = (struct ug_data *)priv;
    ugd->ug = ug;
    ugd->data = s;
    parent = (Evas_Object *) ug_get_parent_layout (ug);
    if (parent == NULL)
        return NULL;
    //-------------------------- ise infomation ----------------------------

    const char *ctx_id = ecore_imf_context_default_id_get ();
    if (ctx_id != NULL) {
        imf_context = ecore_imf_context_add (ctx_id);
    }

    _config = isf_imf_context_get_config ();
    if (_config.null ()) {
        std::cerr << "Create dummy config!!!\n";
        _config = new DummyConfig ();
    }

    if (_config.null ()) {
        std::cerr << "Can not create Config Object!\n";
    }

    //only helper ISEs will be needed in isfsetting according to phone requirement.
    isf_load_ise_information (HELPER_ONLY, _config);
    // Request ISF to update ISE list, below codes are very important, dont remove
    char **iselist = NULL;
    int count = isf_control_get_ise_list (&iselist);
    for (unsigned int i = 0; i < (unsigned int)count; i++) {
        SCIM_DEBUG_MAIN (3) << " [" << i << " : " << iselist[i] << "] \n";
        if (iselist[i] != NULL)
            delete []  (iselist[i]);
    }

    if (iselist!=NULL)
        free(iselist);
    //-------------------------- ise infomation ----------------------------

    //construct the UI part of the isfsetting module
    if (mode == UG_MODE_FULLVIEW)
        ugd->layout_main = create_fullview (parent, ugd);
    else
        ugd->layout_main = create_frameview (parent, ugd);

    if (ugd->layout_main != NULL) {
        content = isf_setting_main_view_tizen(ugd);
        elm_object_part_content_set (ugd->layout_main, "elm.swallow.content", content);
    }
    return (void *)ugd->layout_main;
}
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;
}
Ejemplo n.º 3
0
void
HangulFactory::reload_config(const ConfigPointer &config)
{
    if (config.null())
	return;

    m_show_candidate_comment = config->read(String(SCIM_CONFIG_SHOW_CANDIDATE_COMMENT),
					    m_show_candidate_comment);

    m_keyboard_layout = config->read(String(SCIM_CONFIG_LAYOUT), String("2"));

    m_use_ascii_mode = config->read(String(SCIM_CONFIG_USE_ASCII_MODE),
				    false);
    m_commit_by_word = config->read(String(SCIM_CONFIG_COMMIT_BY_WORD),
				    false);
    m_hanja_mode = config->read(String(SCIM_CONFIG_HANJA_MODE),
				    false);

    String str;
    str = config->read(String(SCIM_CONFIG_HANGUL_KEY),
		       String("Hangul,Shift+space"));
    scim_string_to_key_list(m_hangul_keys, str);

    str = config->read(String (SCIM_CONFIG_HANJA_KEY),
		       String ("Hangul_Hanja,F9"));
    scim_string_to_key_list(m_hanja_keys, str);

    str = config->read(String (SCIM_CONFIG_HANJA_MODE_KEY),
		       String (""));
    scim_string_to_key_list(m_hanja_mode_keys, str);

    m_lookup_table_vertical = config->read(String(SCIM_CONFIG_PANEL_LOOKUP_TABLE_VERTICAL),
					   false);
}
Ejemplo n.º 4
0
static void on_destroy (ui_gadget_h ug, service_h s, void *priv)
{
    if ( ug == NULL|| priv == NULL)
        return;

    if (imf_context != NULL) {
        ecore_imf_context_del(imf_context);
        imf_context = NULL;
    }

    struct ug_data *ugd = (struct ug_data *) priv;

    if (ugd->naviframe != NULL) {
        evas_object_del (ugd->naviframe);
        ugd->naviframe = NULL;
    }

    if (ugd->layout_main != NULL) {
        evas_object_del (ugd->layout_main);
        ugd->layout_main = NULL;
    }

    if (!_config.null ()) {
        _config->flush ();
        _config.reset ();
    }
}
Ejemplo n.º 5
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 load_config( const ConfigPointer &config )
{
	if (!config.null ()) {
		__config_add_phrase_forward =
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_ADD_PHRASE_FORWARD ),
				__config_add_phrase_forward );

		__config_phrase_choice_rearward =
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_PHRASE_CHOICE_REARWARD ),
				__config_phrase_choice_rearward );

		__config_auto_shift_cursor =
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_AUTO_SHIFT_CURSOR ),
				__config_auto_shift_cursor );

		__config_esc_clean_all_buffer =
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_ESC_CLEAN_ALL_BUFFER ),
				__config_esc_clean_all_buffer );

		__config_space_as_selection =
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_SPACE_AS_SELECTION ),
				__config_space_as_selection );

		__config_kb_type_data = 
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_USER_KB_TYPE ),
				__config_kb_type_data);

		__config_selKey_type_data =
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_USER_SELECTION_KEYS ),
					__config_selKey_type_data);

		__config_selKey_num_data =
			config->read( String( SCIM_CHEWING_SELECTION_KEYS_NUM ),
					__config_selKey_num_data);

		__config_chieng_mode_data =
			config->read( String( SCIM_CONFIG_IMENGINE_CHEWING_CHI_ENG_MODE ),
					__config_chieng_mode_data);


		for (int i = 0; __config_keyboards[ i ].key; ++ i) {
			__config_keyboards[ i ].data =
				config->read( 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];
			entry.bg_value = config->read (String (entry.bg_key), entry.bg_value);
		}

		setup_widget_value ();

		__have_changed = false;
	}
}
Ejemplo n.º 7
0
void
load_config (const ConfigPointer &config)
{
    if (!config.null ()) {
        __config_toolbar_always_hidden =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_HIDDEN),
                          __config_toolbar_always_hidden);
        __config_toolbar_always_show =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_SHOW),
                          __config_toolbar_always_show);
        __config_toolbar_auto_snap =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_AUTO_SNAP),
                          __config_toolbar_auto_snap);
        __config_toolbar_hide_timeout =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_HIDE_TIMEOUT),
                          __config_toolbar_hide_timeout);
        __config_toolbar_show_factory_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_ICON),
                          __config_toolbar_show_factory_icon);
        __config_toolbar_show_factory_name =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_NAME),
                          __config_toolbar_show_factory_name);
        __config_toolbar_show_stick_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_STICK_ICON),
                          __config_toolbar_show_stick_icon);
        __config_toolbar_show_menu_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_MENU_ICON),
                          __config_toolbar_show_menu_icon);
        __config_toolbar_show_help_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_HELP_ICON),
                          __config_toolbar_show_help_icon);
        __config_toolbar_show_property_label =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_PROPERTY_LABEL),
                          __config_toolbar_show_property_label);
        __config_lookup_table_embedded =
            config->read (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_EMBEDDED),
                          __config_lookup_table_embedded);
        __config_lookup_table_vertical =
            config->read (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_VERTICAL),
                          __config_lookup_table_vertical);
        __config_default_sticked =
            config->read (String (SCIM_CONFIG_PANEL_GTK_DEFAULT_STICKED),
                          __config_default_sticked);
        __config_show_tray_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_SHOW_TRAY_ICON),
                          __config_show_tray_icon);
        __config_font =
            config->read (String (SCIM_CONFIG_PANEL_GTK_FONT),
                          __config_font);

        setup_widget_value ();

        __have_changed = false;
    }
}
Ejemplo n.º 8
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);
    }
}
Ejemplo n.º 9
0
void
FrontEndHotkeyMatcher::load_hotkeys (const ConfigPointer &config)
{
    clear ();

    if (config.null () || !config->valid ()) return;

    KeyEventList keys;

    // Load the least important hotkeys first.
    for (int i = SCIM_FRONTEND_HOTKEY_SHOW_FACTORY_MENU; i >= SCIM_FRONTEND_HOTKEY_TRIGGER; --i) {
        if (scim_string_to_key_list (keys, config->read (String (__scim_frontend_hotkey_config_paths [i]), String (__scim_frontend_hotkey_defaults [i]))))
            m_impl->m_matcher.add_hotkeys (keys, i);
    }
}
    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;
    }
}
Ejemplo n.º 11
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));
}
Ejemplo n.º 12
0
void
ArrayFactory::reload_config(const ConfigPointer &config)
{
    if (config.null())
        return;

    String str;
    str = config->read(String(SCIM_CONFIG_IMENGINE_ARRAY_ENCHKEY),
                    String(""));
    scim_string_to_key_list(m_ench_key, str);

    str = config->read(String(SCIM_CONFIG_IMENGINE_ARRAY_HFKEY),
                    String("Shift+space"));
    scim_string_to_key_list(m_full_half_key, str);

    m_show_special = config->read(String(SCIM_CONFIG_IMENGINE_ARRAY_SHOW_SPECIAL),
                    false);

    m_special_code_only = config->read(String(SCIM_CONFIG_IMENGINE_ARRAY_SPECIAL_CODE_ONLY),
                    false);
}
Ejemplo n.º 13
0
void
IMEngineHotkeyMatcher::load_hotkeys (const ConfigPointer &config)
{
    clear ();

    if (config.null () || !config->valid ()) return;

    std::vector <String> uuids;

    scim_split_string_list (uuids, config->read (String (SCIM_CONFIG_HOTKEYS_IMENGINE_LIST), String ("")));

    std::sort (uuids.begin (), uuids.end ());
    uuids.erase (std::unique (uuids.begin (), uuids.end ()), uuids.end ());

    if (uuids.size ()) {
        KeyEventList keys;
        for (std::vector <String>::iterator uit = uuids.begin (); uit != uuids.end (); ++uit) {
            if (scim_string_to_key_list (keys, config->read (String (SCIM_CONFIG_HOTKEYS_IMENGINE "/") + *uit, String ("")))) {
                m_impl->m_matcher.add_hotkeys (keys, (int) m_impl->m_uuids.size ());
                m_impl->m_uuids.push_back (*uit);
            }
        }
    }
}
Ejemplo n.º 14
0
int main(int argc, char* argv[])
{
    String config_name("simple");
    String display_name;
    bool daemon = false;
    bool should_resident = true;

    //parse command options
    int i = 1;
    while (i < argc) {
        if (String("-l") == argv[i] || String("--list") == argv[i]) {
            std::cout << "\n";
            std::cout << "Available Config module:\n";
            // get config module list
            std::vector<String> config_list;
            scim_get_config_module_list(config_list);
            config_list.push_back("dummy");
            std::vector<String>::iterator it = config_list.begin();
            for (; it != config_list.end(); ++it) {
                std::cout << "    " << *it << "\n";
            }
            return 0;
        }
        else if (String("-c") == argv[i] || String("--config") == argv[i]) {
            if (++i >= argc) {
                std::cerr << "no argument for option " << argv[i-1] << "\n";
                return -1;
            }
            config_name = argv[i];
        }
        else if (String("-h") == argv[i] || String("--help") == argv[i]) {
            std::cout << "Usage: " << argv [0] << " [option]...\n\n"
                      << "The options are: \n"
                      << "  --display DISPLAY    Run on display DISPLAY.\n"
                      << "  -l, --list           List all of available config modules.\n"
                      << "  -c, --config NAME    Uses specified Config module.\n"
                      << "  -d, --daemon         Run " << argv [0] << " as a daemon.\n"
                      << "  -ns, --no-stay       Quit if no connected client.\n"
                      << "  -h, --help           Show this help message.\n";
            return 0;
        }
        else if (String("-d") == argv[i] || String("--daemon") == argv[i]) {
            daemon = true;
        }
        else if (String("-ns") == argv[i] || String("--no-stay") == argv[i]) {
            should_resident = false;
        }
        else if (String("--display") == argv[i]) {
            if (++i >= argc) {
                std::cerr << "No argument for option " << argv[i-1] << "\n";
                return -1;
            }
            display_name = argv[i];
        }
        else {
            std::cerr << "Invalid command line option: " << argv[i] << "\n";
            return -1;
        }
        ++i;
    }

    // Make up DISPLAY env.
    if (display_name.length()) {
        setenv("DISPLAY", display_name.c_str(), 1);
    }

    if (config_name == "dummy") {
        _config = new DummyConfig();
    }
    else {
        _config_module = new ConfigModule(config_name);
        if (!_config_module || !_config_module->valid()) {
            std::cerr << "Can not load " << config_name << " Config module.\n";
            return -1;
        }
        _config = _config_module->create_config();
    }

    if (_config.null()) {
        std::cerr << "Failed to create instance from " << config_name << " Config module.\n";
        return -1;
    }


    signal(SIGTERM, niam);
    signal(SIGINT, niam);

    if (!initialize_panel_agent(config_name, display_name, should_resident)) {
        std::cerr << "Failed to initialize PanelAgent.\n";
        return -1;
    }

    if (daemon)
        scim_daemon();

    if (!run_panel_agent()) {
        std::cerr << "Failed to run Socket Server!\n";
        return -1;
    }

    start_auto_start_helpers();

    DBus::default_dispatcher = &dispatcher;

    DBus::Connection conn = DBus::Connection::SessionBus();
    conn.request_name("org.kde.impanel.inputmethod");

    panel = new Panel(conn);

    /// add initial helper as helper property
    PropertyList props;
    std::vector<HelperInfo>::const_iterator it = _helper_list.begin();
    std::vector<HelperInfo>::const_iterator end = _helper_list.end();
    while (it != end) {
        if ((it->option & SCIM_HELPER_STAND_ALONE)
                && !(it->option & SCIM_HELPER_AUTO_START)) {
            props.push_back(Property(String(helper_prop_prefix) + it->uuid,
                                     it->name,
                                     it->icon,
                                     it->description));
        }
        ++it;
    }
    if (props.size()) {
        helper_props_map[0] = props;
    }

    dispatcher.enter();

    delete panel;

    return 0;
}
Ejemplo n.º 15
0
 virtual void ReloadConfig() {
     panel_agent->reload_config();
     if (!_config.null())
         _config->reload();
 }
Ejemplo n.º 16
0
int main (int argc, char *argv [])
{
    BackEndPointer      backend;

    std::vector<String> engine_list;

    String config_name   ("simple");
    String frontend_name ("socket");

    int   new_argc = 0;
    char *new_argv [40];

    int i = 0;
    bool daemon = false;

    new_argv [new_argc ++] = argv [0];

    while (i<argc) {
        if (++i >= argc) break;

        if (String ("-f") == argv [i] ||
                String ("--frontend") == argv [i]) {
            if (++i >= argc) {
                std::cerr << "No argument for option " << argv [i-1] << "\n";
                return -1;
            }
            frontend_name = argv [i];
            continue;
        }

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

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

        if (String ("-e") == argv [i] ||
                String ("--engines") == argv [i]) {
            if (++i >= argc) {
                std::cerr << "No argument for option " << argv [i-1] << "\n";
                return -1;
            }
            if (String (argv [i]) == "all") {
                scim_get_imengine_module_list (engine_list);
                for (size_t j = 0; j < engine_list.size (); ++j) {
                    if (engine_list [j] == "socket") {
                        engine_list.erase (engine_list.begin () + j);
                        break;
                    }
                }
            } else if (String (argv [i]) != "none") {
                scim_split_string_list (engine_list, String (argv [i]), ',');
            }
            continue;
        }

        if (String ("-v") == argv [i] ||
                String ("--verbose") == argv [i]) {
            if (++i >= argc) {
                std::cerr << "No argument for option " << argv [i-1] << "\n";
                return -1;
            }
            DebugOutput::set_verbose_level (atoi (argv [i]));
            continue;
        }

        if (String ("-m") == argv [i] ||
                String ("--mask") == argv [i]) {
            if (++i >= argc) {
                std::cerr << "No argument for option " << argv [i-1] << "\n";
                return -1;
            }
            if (String (argv [i]) != "none") {
                std::vector<String> debug_mask_list;
                scim_split_string_list (debug_mask_list, argv [i], ',');
                DebugOutput::disable_debug (SCIM_DEBUG_AllMask);
                for (size_t j=0; j<debug_mask_list.size (); j++)
                    DebugOutput::enable_debug_by_name (debug_mask_list [j]);
            }
            continue;
        }

        if (String ("-o") == argv [i] ||
                String ("--output") == argv [i]) {
            if (++i >= argc) {
                std::cerr << "No argument for option " << argv [i-1] << "\n";
                return -1;
            }
            DebugOutput::set_output (String (argv [i]));
            continue;
        }

        if (String ("--") == argv [i])
            break;

        new_argv [new_argc ++] = argv [i];
    } //End of command line parsing.

    // Construct new argv array for FrontEnd.
    new_argv [new_argc ++] = const_cast <char *> ("-c");
    new_argv [new_argc ++] = const_cast <char *> (config_name.c_str ());

    // Store the rest argvs into new_argv.
    for (++i; i < argc && new_argc < 40; ++i) {
        new_argv [new_argc ++] = argv [i];
    }

    new_argv [new_argc] = 0;

    try {
        // Try to load config module
        std::cerr << "Loading " << config_name << " Config module ...\n";
        if (config_name != "dummy") {
            //load config module
            config_module = new ConfigModule (config_name);

            if (!config_module->valid ()) {
                std::cerr << "Can not load " << config_name << " Config module. Using dummy module instead.\n";
                delete config_module;
                config_module = 0;
            }

        }

        if (config_module) {
            config = config_module->create_config ();
        } else {
            config = new DummyConfig ();
        }

        if (config.null ()) {
            std::cerr << "Can not create Config Object!\n";
            return 1;
        }

        // create backend
        std::cerr << "Creating backend ...\n";
        backend = new CommonBackEnd (config, engine_list);

        //load FrontEnd module
        std::cerr << "Loading " << frontend_name << " FrontEnd module ...\n";
        frontend_module = new FrontEndModule (frontend_name, backend, config, new_argc, new_argv);

        if (!frontend_module || !frontend_module->valid ()) {
            std::cerr << "Failed to load " << frontend_name << " FrontEnd module.\n";
            return 1;
        }

        //reset backend pointer, in order to destroy backend automatically.
        backend.reset ();

        signal(SIGQUIT, signalhandler);
        signal(SIGTERM, signalhandler);
        signal(SIGINT,  signalhandler);
        signal(SIGHUP,  signalhandler);

        if (daemon) {
            std::cerr << "Starting SCIM as daemon ...\n";
            scim_daemon ();
        } else {
            std::cerr << "Starting SCIM ...\n";
        }

        frontend_module->run ();
    } catch (const std::exception & err) {
        std::cerr << err.what () << "\n";
        return 1;
    }

    return 0;
}
Ejemplo n.º 17
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;
	}
}