Newer
Older
scim-wnn / honoka / src / honoka_imengine_setup.cpp
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 *  Copyright (C) 2004 TAM (Teppei Tamra)
 *  Copyright (C) 2004 Hiroyuki Ikezoe
 *  Copyright (C) 2004 Takuro Ashie
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*
 * Based on scim-hangul.
 * Copyright (c) 2004 James Su <suzhe@turbolinux.com.cn>
 */

#define Uses_SCIM_CONFIG_BASE

#include <gtk/gtk.h>

#ifdef HAVE_CONFIG_H
  #include <config.h>
#endif

#include <scim.h>
#include <gtk/scimkeyselection.h>
#include "honoka_def.h"
#include "../plugins/honoka_plugin_def.h"

#ifdef HAVE_GETTEXT
  #include <libintl.h>
  #define _(String) dgettext(GETTEXT_PACKAGE,String)
  #define N_(String) (String)
#else
  #define _(String) (String)
  #define N_(String) (String)
  #define bindtextdomain(Package,Directory)
  #define textdomain(domain)
  #define bind_textdomain_codeset(domain,codeset)
#endif

using namespace scim;

#define scim_module_init honoka_imengine_setup_LTX_scim_module_init
#define scim_module_exit honoka_imengine_setup_LTX_scim_module_exit

#define scim_setup_module_create_ui       honoka_imengine_setup_LTX_scim_setup_module_create_ui
#define scim_setup_module_get_category    honoka_imengine_setup_LTX_scim_setup_module_get_category
#define scim_setup_module_get_name        honoka_imengine_setup_LTX_scim_setup_module_get_name
#define scim_setup_module_get_description honoka_imengine_setup_LTX_scim_setup_module_get_description
#define scim_setup_module_load_config     honoka_imengine_setup_LTX_scim_setup_module_load_config
#define scim_setup_module_save_config     honoka_imengine_setup_LTX_scim_setup_module_save_config
#define scim_setup_module_query_changed   honoka_imengine_setup_LTX_scim_setup_module_query_changed


#include <honokasetupgtk.h>

static GtkWidget * create_setup_window ();
static void        load_config (const ConfigPointer &config);
static void        save_config (const ConfigPointer &config);
static bool        query_changed ();

static HonokaSetupGtk * setup;

// Module Interface.

extern "C" {
    void scim_module_init (void)
    {
        bindtextdomain (GETTEXT_PACKAGE, HONOKA_LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    }

    void scim_module_exit (void)
    {
    }

    GtkWidget * scim_setup_module_create_ui (void)
    {
        return create_setup_window ();
    }

    String scim_setup_module_get_category (void)
    {
        return String ("IMEngine");
    }

    String scim_setup_module_get_name (void)
    {
        return String (_("Honoka"));
    }

    String scim_setup_module_get_description (void)
    {
        return String (_("A Honoka IMEngine Module."));
    }

    void scim_setup_module_load_config (const ConfigPointer &config)
    {
        load_config (config);
    }

    void scim_setup_module_save_config (const ConfigPointer &config)
    {
        save_config (config);
    }

    bool scim_setup_module_query_changed ()
    {
        return query_changed ();
    }
} // extern "C"


static GtkWidget * create_setup_window ()
{
    setup = new HonokaSetup("setup","","");
    HonokaSetupPage *page;
    vector<String> l;

    //
    // general setting 
    //
    
    page = new HonokaSetupPage(_("general setting"),"","");
    page->append(new HonokaSetupIntItem(
        _("_Auto candidates popup: "),
        HONOKA_CONFIG_ALP,
        _("set the count of conversion until displaying the list of lookup result automatically."),
        HONOKA_DEFAULT_ALP,
        -1,10
    ));
    page->append(new HonokaSetupBoolItem(
        _("Auto _conversion: "),
        HONOKA_CONFIG_AUTO_CONVERSION,
        _("If you set default to the auto conversion mode use, check this."),
        HONOKA_DEFAULT_AUTO_CONVERSION
    ));
    page->append(new HonokaSetupBoolItem(
        _("_NumKey selection: "),
        HONOKA_CONFIG_NUMKEY_SELECT,
        _("If you use the candidate selection by numkey, check this."),
        HONOKA_DEFAULT_NUMKEY_SELECT
    ));
    page->append(new HonokaSetupBoolItem(
        _("use _Prediction: "),
        HONOKA_CONFIG_PREDICTION,
        _("If you use the prediction, check this."),
        HONOKA_DEFAULT_PREDICTION
    ));
    page->append(new HonokaSetupEntryItem(
        _("Default _PreEditor: "),
        HONOKA_CONFIG_DEFAULT_PREEDITOR,
        _("select the default preeditor."),
        HONOKA_DEFAULT_DEFAULT_PREEDITOR
    ));
    page->append(new HonokaSetupEntryItem(
        _("Default _Convertor: "),
        HONOKA_CONFIG_DEFAULT_CONVERTOR,
        _("select the default Convertor."),
        HONOKA_DEFAULT_DEFAULT_CONVERTOR
    ));
    page->append(new HonokaSetupEntryItem(
        _("Default _Predictor: "),
        HONOKA_CONFIG_DEFAULT_PREDICTOR,
        _("select the default predictor."),
        HONOKA_DEFAULT_DEFAULT_PREDICTOR
    ));
    
    setup->append(page);
    
    
    //
    // key setting
    //
    
    HonokaSetup * keys = new HonokaSetup(_("key setting"),"","");

    page = new HonokaSetupPage(_("Common keys"),"","");
    page->append(new HonokaSetupKeyItem(
        _("Commit keys:"),
        HONOKA_CONFIG_KEY_COMMIT,
        _("The key events to commit the preedit string. "),
        HONOKA_DEFAULT_KEY_COMMIT
    ));
    page->append(new HonokaSetupKeyItem(
        _("Convert keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_START,
        _("The key events to convert the preedit string to kanji. "),
        HONOKA_DEFAULT_KEY_CONVERSION_START
    ));
    page->append(new HonokaSetupKeyItem(
        _("Cancel keys:"),
        HONOKA_CONFIG_KEY_CANCEL,
        _("The key events to cancel preediting or converting. "),
        HONOKA_DEFAULT_KEY_CANCEL
    ));
    page->append(new HonokaSetupKeyItem(
        _("Backspace keys:"),
        HONOKA_CONFIG_KEY_BACKSPACE,
        _("The key events to delete a character before caret. "),
        HONOKA_DEFAULT_KEY_BACKSPACE
    ));
    page->append(new HonokaSetupKeyItem(
        _("Delete keys:"),
        HONOKA_CONFIG_KEY_DELETE,
        _("The key events to delete a character after caret. "),
        HONOKA_DEFAULT_KEY_DELETE
    ));
    keys->append(page);

    page = new HonokaSetupPage(_("Preedit keys"),"","");
    page->append(new HonokaSetupKeyItem(
        _("Move forward keys:"),
        HONOKA_CONFIG_KEY_FORWARD,
        _("The key events to move the caret to forward. "),
        HONOKA_DEFAULT_KEY_FORWARD
    ));
    page->append(new HonokaSetupKeyItem(
        _("Move backward keys:"),
        HONOKA_CONFIG_KEY_BACKWARD,
        _("The key events to move the caret to backward. "),
        HONOKA_DEFAULT_KEY_BACKWARD
    ));
    keys->append(page);

    page = new HonokaSetupPage(_("Segment keys"),"","");
    page->append(new HonokaSetupKeyItem(
        _("Next segment keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_FORWARD,
        _("The key events to select next segment. "),
        HONOKA_DEFAULT_KEY_CONVERSION_FORWARD
    ));
    page->append(new HonokaSetupKeyItem(
        _("Previous segment keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_BACKWARD,
        _("The key events to select previous segment. "),
        HONOKA_DEFAULT_KEY_CONVERSION_BACKWARD
    ));
    page->append(new HonokaSetupKeyItem(
        _("Shrink segment keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_SHRINK,
        _("The key events to shrink the selected segment. "),
        HONOKA_DEFAULT_KEY_CONVERSION_SHRINK
    ));
    page->append(new HonokaSetupKeyItem(
        _("Expand segment keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_EXPAND,
        _("The key events to expand the selected segment. "),
        HONOKA_DEFAULT_KEY_CONVERSION_EXPAND
    ));
    keys->append(page);

    page = new HonokaSetupPage(_("Candidates keys"),"","");
    page->append(new HonokaSetupKeyItem(
        _("Next keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_NEXT,
        _("The key events to select next candidate. "),
        HONOKA_DEFAULT_KEY_CONVERSION_NEXT
    ));
    page->append(new HonokaSetupKeyItem(
        _("Previous keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_PREV,
        _("The key events to select previous candidate. "),
        HONOKA_DEFAULT_KEY_CONVERSION_PREV
    ));
    page->append(new HonokaSetupKeyItem(
        _("candidates list keys:"),
        HONOKA_CONFIG_KEY_LOOKUPPOPUP,
        _("The key events to popup candidates list. "),
        HONOKA_DEFAULT_KEY_LOOKUPPOPUP
    ));
    page->append(new HonokaSetupKeyItem(
        _("Page up keys:"),
        HONOKA_CONFIG_KEY_LOOKUPPAGEUP,
        _("The key events to select page up candidates. "),
        HONOKA_DEFAULT_KEY_LOOKUPPAGEUP
    ));
    page->append(new HonokaSetupKeyItem(
        _("Page down keys:"),
        HONOKA_CONFIG_KEY_LOOKUPPAGEDOWN,
        _("The key events to select page down candidates. "),
        HONOKA_DEFAULT_KEY_LOOKUPPAGEDOWN
    ));
    keys->append(page);

    page = new HonokaSetupPage(_("Other function keys"),"","");
    page->append(new HonokaSetupKeyItem(
        _("auto conversion mode keys:"),
        HONOKA_CONFIG_KEY_AUTO_CONVERSION,
        _("The key events to change auto conversion mode. "),
        HONOKA_DEFAULT_KEY_AUTO_CONVERSION
    ));
    page->append(new HonokaSetupKeyItem(
        _("Prediction keys:"),
        HONOKA_CONFIG_KEY_SELECT_PREDICTION,
        _("The key events to select from prediction list. "),
        HONOKA_DEFAULT_KEY_SELECT_PREDICTION
    ));
    page->append(new HonokaSetupKeyItem(
        _("Convert to HIRAGANA keys:"),
        HONOKA_CONFIG_KEY_CONVERT_HIRAGANA,
        _("The key events to convert the selected candidate or the preedit string to HIRAGANA. "),
        HONOKA_DEFAULT_KEY_CONVERT_HIRAGANA
    ));
    page->append(new HonokaSetupKeyItem(
        _("Convert to KATAKANA keys:"),
        HONOKA_CONFIG_KEY_CONVERT_KATAKANA,
        _("The key events to convert the selected candidate or the preedit string to KATAKANA. "),
        HONOKA_DEFAULT_KEY_CONVERT_KATAKANA
    ));
    page->append(new HonokaSetupKeyItem(
        _("Convert to WIDE keys:"),
        HONOKA_CONFIG_KEY_CONVERT_WIDE,
        _("The key events to convert the selected candidate or the preedit string to WIDE-charactors. "),
        HONOKA_DEFAULT_KEY_CONVERT_WIDE
    ));
    page->append(new HonokaSetupKeyItem(
        _("Convert to HALF keys:"),
        HONOKA_CONFIG_KEY_CONVERT_HALF,
        _("The key events to convert the selected candidate or the preedit string to HALF-charactors. "),
        HONOKA_DEFAULT_KEY_CONVERT_HALF
    ));
    page->append(new HonokaSetupKeyItem(
        _("Convert to ikeiji keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_IKEIJI,
        _("The key events to convert the selected candidate to ikei-kanji. "),
        HONOKA_DEFAULT_KEY_CONVERSION_IKEIJI
    ));
    page->append(new HonokaSetupKeyItem(
        _("Convert to rensou keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_RENSOU,
        _("The key events to convert the selected candidate to the associated acceptation string.  "),
        HONOKA_DEFAULT_KEY_CONVERSION_RENSOU
    ));
    keys->append(page);
    
    page = new HonokaSetupPage(_("shortcut keys"),"","");
    page->append(new HonokaSetupKeyItem(
        _("Wnn Conversion:"),
        String(HONOKA_CONFIG_KEY_CONVERTOR_PREFIX) + String("/Wnn"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Anthy Conversion:"),
        String(HONOKA_CONFIG_KEY_CONVERTOR_PREFIX) + String("/Anthy"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Canna Conversion:"),
        String(HONOKA_CONFIG_KEY_CONVERTOR_PREFIX) + String("/Canna"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("SKKDic:"),
        String(HONOKA_CONFIG_KEY_CONVERTOR_PREFIX) + String("/SKKDic"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Romkan input:"),
        String(HONOKA_CONFIG_KEY_PREEDITOR_PREFIX) + String("/Romkan"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Kana input:"),
        String(HONOKA_CONFIG_KEY_PREEDITOR_PREFIX) + String("/KanaInput"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Nicola input:"),
        String(HONOKA_CONFIG_KEY_PREEDITOR_PREFIX) + String("/Nicola"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Wnn Prediction:"),
        String(HONOKA_CONFIG_KEY_PREDICTOR_PREFIX) + String("/WnnPrediction"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Anthy Prediction:"),
        String(HONOKA_CONFIG_KEY_PREDICTOR_PREFIX) + String("/AnthyPrediction"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Simple Prediction:"),
        String(HONOKA_CONFIG_KEY_PREDICTOR_PREFIX) + String("/SimplePrediction"),
        "",
        ""
    ));
    page->append(new HonokaSetupKeyItem(
        _("Prime Prediction:"),
        String(HONOKA_CONFIG_KEY_PREDICTOR_PREFIX) + String("/PrimePrediction"),
        "",
        ""
    ));
    
    keys->append(page);

    setup->append(keys);
    
    //
    // plugins setting
    //
    
    HonokaSetup * plugins = new HonokaSetup(_("plugins setting"),"","");
    
    //
    // romkan setting
    //
    
    page = new HonokaSetupPage(_("Romkan-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-romkan"),
        _("if you use this plugin, check this."),
        true
    ));
    page->append(new HonokaSetupFileItem(
        _("_Roma-Kana table: "),
        HONOKA_CONFIG_ROMKAN_TABLE_FILE,
        _("input the path of Roma-Kana convert table file."),
        HONOKA_DEFAULT_ROMKAN_TABLE_FILE
    ));
    
    plugins->append(page);

    //
    // kana-input setting
    //
    
    page = new HonokaSetupPage(_("KanaInput-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-kanainput"),
        _("if you use this plugin, check this."),
        true
    ));
    page->append(new HonokaSetupBoolItem(
        _("use _fake kana-input: "),
        HONOKA_CONFIG_KANAINPUT_FAKEKANA,
        _("if you use the table of ASCII-KANA key mapping,check this."),
        HONOKA_DEFAULT_KANAINPUT_FAKEKANA
    ));
    
    plugins->append(page);

    //
    // nicola-input setting
    //
    
    page = new HonokaSetupPage(_("Nicola-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-nicola"),
        _("if you use this plugin, check this."),
        true
    ));
    page->append(new HonokaSetupKeyItem(
        _("Left KANA-Shift keys:"),
        HONOKA_CONFIG_NICOLAINPUT_LSHIFT,
        "",
        HONOKA_DEFAULT_NICOLAINPUT_LSHIFT
    ));
    page->append(new HonokaSetupKeyItem(
        _("Right KANA-Shift keys:"),
        HONOKA_CONFIG_NICOLAINPUT_RSHIFT,
        "",
        HONOKA_DEFAULT_NICOLAINPUT_RSHIFT
    ));

    plugins->append(page);

    //
    // Wnn setting
    //
    page = new HonokaSetupPage(_("Wnn-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-wnn"),
        _("if you use this plugin, check this."),
        true
    ));
    
    page->append(new HonokaSetupEntryItem(
        _("_Server: "),
        HONOKA_CONFIG_JSERVER,
        _("input the server name to connect."),
        HONOKA_DEFAULT_JSERVER
    ));
    page->append(new HonokaSetupFileItem(
        _("_wnnenvrc: "),
        HONOKA_CONFIG_WNNENVRC,
        _("input the path of wnnenvrc."),
        HONOKA_DEFAULT_WNNENVRC
    ));
    l.clear();
    l.push_back(String("Wnn4"));
    l.push_back(String("Wnn6"));
    l.push_back(String("Wnn7"));
    l.push_back(String("Wnn8"));
    page->append(new HonokaSetupSelectItem(
        _("Server_type: "),
        HONOKA_CONFIG_JSERVERTYPE,
        _("select the server type from Wnn4 / Wnn6 / Wnn7."),
        HONOKA_DEFAULT_JSERVERTYPE,
        l
    ));
    plugins->append(page);
    page->append(new HonokaSetupBoolItem(
        _("use Wnn7-_YOSOKU: "),
        HONOKA_CONFIG_WNNYOSOKU,
        _("if you use the prediction of Wnn7, check this."),
        HONOKA_DEFAULT_WNNYOSOKU
    ));
    
    //
    // Anthy setting
    //
    
    page = new HonokaSetupPage(_("Anthy-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-anthy"),
        _("if you use this plugin, check this."),
        true
    ));
    plugins->append(page);

    //
    // Canna setting
    //
    
    page = new HonokaSetupPage(_("Canna-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-canna"),
        _("if you use this plugin, check this."),
        true
    ));
    page->append(new HonokaSetupEntryItem(
        _("_Server: "),
        HONOKA_CONFIG_CANNA_SERVER,
        _("input the server name to connect."),
        HONOKA_DEFAULT_CANNA_SERVER
    ));
    page->append(new HonokaSetupFileItem(
        _("_DicHomeDir: "),
        HONOKA_CONFIG_CANNA_DICHOMEDIRPATH,
        _("set your DicHomeDir in this entry."),
        HONOKA_DEFAULT_CANNA_DICHOMEDIRPATH
    ));
    plugins->append(page);


    //
    // SKKDic setting
    //
    
    page = new HonokaSetupPage(_("SKKDic-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-skkdic"),
        _("if you use this plugin, check this."),
        true
    ));
    page->append(new HonokaSetupFileItem(
        _("_SKKDic file: "),
        HONOKA_CONFIG_SKKDIC_DICFILE,
        _("set SKKDic file in this entry."),
        HONOKA_DEFAULT_SKKDIC_DICFILE
    ));
    plugins->append(page);
    
    //
    // SimplePrediction setting
    //
    
    page = new HonokaSetupPage(_("SimplePrediction-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-simpleprediction"),
        _("if you use this plugin, check this."),
        true
    ));
    page->append(new HonokaSetupIntItem(
        _("_max history count: "),
        HONOKA_CONFIG_SIMPLEPREDICTION_SIZE,
        _("set maximum size of history count."),
        HONOKA_DEFAULT_SIMPLEPREDICTION_SIZE,
        1,500
    ));
    plugins->append(page);
    
    //
    // PrimePrediction setting
    //
    
    page = new HonokaSetupPage(_("PrimePrediction-plugin"),"","");
    
    page->append(new HonokaSetupBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-prime"),
        _("if you use this plugin, check this."),
        true
    ));
    l.clear();
    l.push_back(String("lookup"));
    l.push_back(String("lookup_all"));
    l.push_back(String("lookup_compact"));
    l.push_back(String("lookup_compact_all"));
    l.push_back(String("lookup_direct"));
    l.push_back(String("lookup_direct_all"));
    l.push_back(String("lookup_exact"));
    l.push_back(String("lookup_expansion"));
    l.push_back(String("lookup_hybrid"));
    l.push_back(String("lookup_hybrid_all"));
    l.push_back(String("lookup_mixed"));
    page->append(new HonokaSetupSelectItem(
        _("_Lookup method: "),
        HONOKA_CONFIG_PRIME_PREDICTION_LM,
        _("select the lookup method."),
        HONOKA_DEFAULT_PRIME_PREDICTION_LM,
        l
    ));
    plugins->append(page);
    
    setup->append(plugins);


    return setup->getValueWidget();
};

static void
load_config (const ConfigPointer &config)
{
    if (!config.null()) {
        setup->readConfig(config);
        HonokaSetup::changed = false;
    }
}

static void
save_config (const ConfigPointer &config)
{
    if (!config.null()) {
        setup->saveConfig(config);
        HonokaSetup::changed = false;
    }
}

static bool
query_changed ()
{
    return HonokaSetup::changed;
}