Newer
Older
scim-wnn / honoka / src / honoka_imengine_setup.cpp
@tamra tamra on 14 Jul 2005 10 KB 新しい設定画面実装。
/* -*- 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 HonokaSetupGtk("setup","","");
    HonokaSetupGtkPage *page;
    vector<String> l;
    HonokaSetupGtk * keys = new HonokaSetupGtk(_("key setting"),"","");
    page = new HonokaSetupGtkPage(_("general setting"),"","");
    page->append(new HonokaSetupGtkIntItem(
        _("_Auto candidates popup: "),
        HONOKA_CONFIG_ALP,
        _("set the count of conversion until displaying the list of lookup result automatically."),
        HONOKA_DEFAULT_ALP,
        -1,10
    ));
    setup->append(page);
    
    page = new HonokaSetupGtkPage(_("Common keys"),"","");
    page->append(new HonokaSetupGtkKeyItem(
        _("Commit keys:"),
        HONOKA_CONFIG_KEY_COMMIT,
        _("The key events to commit the preedit string. "),
        HONOKA_DEFAULT_KEY_COMMIT
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("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 HonokaSetupGtkKeyItem(
        _("Cancel keys:"),
        HONOKA_CONFIG_KEY_CANCEL,
        _("The key events to cancel preediting or converting. "),
        HONOKA_DEFAULT_KEY_CANCEL
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("Backspace keys:"),
        HONOKA_CONFIG_KEY_BACKSPACE,
        _("The key events to delete a character before caret. "),
        HONOKA_DEFAULT_KEY_BACKSPACE
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("Delete keys:"),
        HONOKA_CONFIG_KEY_DELETE,
        _("The key events to delete a character after caret. "),
        HONOKA_DEFAULT_KEY_DELETE
    ));
    keys->append(page);

    page = new HonokaSetupGtkPage(_("Preedit keys"),"","");
    page->append(new HonokaSetupGtkKeyItem(
        _("Move forward keys:"),
        HONOKA_CONFIG_KEY_FORWARD,
        _("The key events to move the caret to forward. "),
        HONOKA_DEFAULT_KEY_FORWARD
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("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 HonokaSetupGtkPage(_("Candidates keys"),"","");
    page->append(new HonokaSetupGtkKeyItem(
        _("Next segment keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_FORWARD,
        _("The key events to select next segment. "),
        HONOKA_DEFAULT_KEY_CONVERSION_FORWARD
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("Previous segment keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_BACKWARD,
        _("The key events to select previous segment. "),
        HONOKA_DEFAULT_KEY_CONVERSION_BACKWARD
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("Shrink segment keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_SHRINK,
        _("The key events to shrink the selected segment. "),
        HONOKA_DEFAULT_KEY_CONVERSION_SHRINK
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("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 HonokaSetupGtkPage(_("Candidates keys"),"","");
    page->append(new HonokaSetupGtkKeyItem(
        _("Next keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_NEXT,
        _("The key events to select next candidate. "),
        HONOKA_DEFAULT_KEY_CONVERSION_NEXT
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("Previous keys:"),
        HONOKA_CONFIG_KEY_CONVERSION_PREV,
        _("The key events to select previous candidate. "),
        HONOKA_DEFAULT_KEY_CONVERSION_PREV
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("candidates list keys:"),
        HONOKA_CONFIG_KEY_LOOKUPPOPUP,
        _("The key events to popup candidates list. "),
        HONOKA_DEFAULT_KEY_LOOKUPPOPUP
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("Page up keys:"),
        HONOKA_CONFIG_KEY_LOOKUPPAGEUP,
        _("The key events to select page up candidates. "),
        HONOKA_DEFAULT_KEY_LOOKUPPAGEUP
    ));
    page->append(new HonokaSetupGtkKeyItem(
        _("Page down keys:"),
        HONOKA_CONFIG_KEY_LOOKUPPAGEDOWN,
        _("The key events to select page down candidates. "),
        HONOKA_DEFAULT_KEY_LOOKUPPAGEDOWN
    ));
    keys->append(page);
    
    setup->append(keys);
    
    page = new HonokaSetupGtkPage(_("Wnn-plugin"),"","");
    
    page->append(new HonokaSetupGtkBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-wnn"),
        _("if you use this plugin, check this."),
        true
    ));
    
    page->append(new HonokaSetupGtkEntryItem(
        _("_Server: "),
        HONOKA_CONFIG_JSERVER,
        _("input the server name to connect."),
        HONOKA_DEFAULT_JSERVER
    ));
    // file
    page->append(new HonokaSetupGtkFileItem(
        _("_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 HonokaSetupGtkSelectItem(
        _("Server_type: "),
        HONOKA_CONFIG_JSERVERTYPE,
        _("select the server type from Wnn4 / Wnn6 / Wnn7."),
        HONOKA_DEFAULT_JSERVERTYPE,
        l
    ));
    setup->append(page);
    
    
    page = new HonokaSetupGtkPage(_("Anthy-plugin"),"","");
    
    page->append(new HonokaSetupGtkBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-anthy"),
        _("if you use this plugin, check this."),
        true
    ));
    setup->append(page);

    page = new HonokaSetupGtkPage(_("Canna-plugin"),"","");
    
    page->append(new HonokaSetupGtkBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/canna-anthy"),
        _("if you use this plugin, check this."),
        true
    ));
    // file
    page->append(new HonokaSetupGtkFileItem(
        _("_DicHomeDir: "),
        HONOKA_CONFIG_CANNA_DICHOMEDIRPATH,
        _("set your DicHomeDir in this entry."),
        HONOKA_DEFAULT_CANNA_DICHOMEDIRPATH
    ));
    setup->append(page);


    page = new HonokaSetupGtkPage(_("SKKDic-plugin"),"","");
    
    page->append(new HonokaSetupGtkBoolItem(
        _("_Use this plugin: "),
        String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/skkdic-anthy"),
        _("if you use this plugin, check this."),
        true
    ));
    // file
    page->append(new HonokaSetupGtkFileItem(
        _("_SKKDic file: "),
        HONOKA_CONFIG_SKKDIC_DICFILE,
        _("set SKKDic file in this entry."),
        HONOKA_DEFAULT_SKKDIC_DICFILE
    ));
    setup->append(page);


    return setup->getValueWidget();
};

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

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

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