Newer
Older
scim-wnn / honoka-plugins / wnn / src / wnnplugin.cpp
@tamra tamra on 22 May 2006 4 KB プラグイン分離。
/***************************************************************************
 *   Copyright (C) 2005 by TAM(Teppei Tamra)                               *
 *   tam-t@par.odn.ne.jp                                                   *
 *                                                                         *
 *   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 of the License, 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.             *
 ***************************************************************************/

#include "wnnplugin.h"

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


#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


HonokaPluginRegister(WnnPlugin);
HonokaPluginSetup(WnnPlugin);

HonokaSetupCorePage *WnnPlugin::setup()
{
    bindtextdomain (GETTEXT_PACKAGE, HONOKA_LOCALEDIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");

    HonokaSetupPage *page = new HonokaSetupPage(_("Wnn-plugin"),"","");
    vector<String> l;
    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
    ));
    page->append(new HonokaSetupBoolItem(
        _("use Wnn7-_YOSOKU: "),
        HONOKA_CONFIG_WNNYOSOKU,
        _("if you use the prediction of Wnn7, check this."),
        HONOKA_DEFAULT_WNNYOSOKU
    ));
    HonokaSetupPage *sc = new HonokaSetupPage(_("shortcut keys: "),"","");
    sc->append(new HonokaSetupKeyItem(
        _("Wnn Conversion: "),
        String(HONOKA_CONFIG_KEY_CONVERTOR_PREFIX) + String("/Wnn"),
        "",
        ""
    ));
    sc->append(new HonokaSetupKeyItem(
        _("Wnn Prediction: "),
        String(HONOKA_CONFIG_KEY_PREDICTOR_PREFIX) + String("/WnnPrediction"),
        "",
        ""
    ));
    page->append(sc);

    return page;
};

WnnPlugin::WnnPlugin(ConfigPointer cfg) : HonokaMultiplePluginBase(cfg)
{
    bindtextdomain (GETTEXT_PACKAGE, HONOKA_LOCALEDIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");

    predictor = 0;
    convertor = new WnnConversion(cfg);
    
    bool yosoku = cfg->read(String(HONOKA_CONFIG_WNNYOSOKU),HONOKA_DEFAULT_WNNYOSOKU);
    String sType = cfg->read(String(HONOKA_CONFIG_JSERVERTYPE),String(HONOKA_DEFAULT_JSERVERTYPE));
    if (yosoku && (sType == String("Wnn7"))) {
        predictor = new WnnPrediction(cfg,convertor);
    }
}


WnnPlugin::~WnnPlugin()
{
    if (predictor) delete predictor;
    delete convertor;
}

/*!
    \fn WnnPlugin::getPluginInstanceAt(int p)
 */
HonokaPluginBase * WnnPlugin::getPluginInstanceAt(int p)
{
    if (p == 0) return convertor;
    if ((p == 1) && predictor) return predictor;
    return 0;
}


/*!
    \fn WnnPlugin::getPluginCount()
 */
int WnnPlugin::getPluginCount()
{
    if (predictor) return 2;
    return 1;
}

/*!
    \fn WnnPlugin::getName()
 */
String WnnPlugin::getName()
{
    return String("WnnPlugin");
}