3
Copyright (c) 2004-2005 Kazuki Ohta <mover@hct.zaq.ne.jp>
4
Copyright (c) 2005-2008 uim Project http://code.google.com/p/uim/
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions
12
1. Redistributions of source code must retain the above copyright
13
notice, this list of conditions and the following disclaimer.
14
2. Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in the
16
documentation and/or other materials provided with the distribution.
17
3. Neither the name of authors nor the names of its contributors
18
may be used to endorse or promote products derived from this software
19
without specific prior written permission.
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
22
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
25
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37
#include <qapplication.h>
38
#include <qinputcontextplugin.h>
39
#include <qinputcontext.h>
40
#include <qstringlist.h>
46
#include "uim/uim-x-util.h"
49
#include "quiminfomanager.h"
50
#include "quiminputcontext_with_slave.h"
52
#define UIM_QT_LIST_SUBIM_AS_QTIM 0
54
QUimInfoManager *UimInputContextPlugin::infoManager = NULL;
57
UimInputContextPlugin::UimInputContextPlugin()
63
UimInputContextPlugin::~UimInputContextPlugin()
68
QStringList UimInputContextPlugin::keys() const
70
return createImList();
73
QInputContext *UimInputContextPlugin::create( const QString & key )
75
QString imname = QString::null;
77
#if UIM_QT_LIST_SUBIM_AS_QTIM
78
if ( key.startsWith( "uim-" ) )
79
imname = key.mid( 4 );
83
imname = uim_get_default_im_name( setlocale( LC_ALL, NULL ) );
85
QStringList langs = createLanguageList( key );
86
QUimInputContext *uic = new QUimInputContext( imname.toUtf8(),
87
langs[ 0 ].toUtf8() );
92
QStringList UimInputContextPlugin::languages( const QString & key )
94
return createLanguageList( key );
97
QString UimInputContextPlugin::displayName( const QString & key )
99
return QString( key ) + " (" + languages( key ) [ 0 ] + ")";
102
QString UimInputContextPlugin::description( const QString & key )
104
return displayName( key ) + ": an input method provided via the uim input method framework";
108
UimInputContextPlugin::getQUimInfoManager()
113
void UimInputContextPlugin::uimInit()
117
infoManager = new QUimInfoManager();
118
#if UIM_QT_USE_JAPANESE_KANA_KEYBOARD_HACK
119
uim_x_kana_input_hack_init( QX11Info::display() );
125
void UimInputContextPlugin::uimQuit()
137
QStringList UimInputContextPlugin::createImList() const
143
qDebug( "name = uim" );
145
#if UIM_QT_LIST_SUBIM_AS_QTIM
146
uim_context tmp_uc = uim_create_context( NULL, "UTF-8",
147
NULL, NULL, uim_iconv, NULL );
148
int nr = uim_get_nr_im( tmp_uc );
151
for ( int i = 0; i < nr; i++ )
153
const char *name = uim_get_im_name( tmp_uc, i );
158
qDebug( "name = %s", ( const char* ) qs.toUtf8() );
161
uim_release_context( tmp_uc );
167
QStringList UimInputContextPlugin::createLanguageList( const QString &key ) const
170
return QStringList() << "ja" << "ko" << "zh" << "*";
172
#if UIM_QT_LIST_SUBIM_AS_QTIM
173
uim_context tmp_uc = uim_create_context( NULL, "UTF-8",
174
NULL, NULL, uim_iconv, NULL );
175
int nr = uim_get_nr_im( tmp_uc );
178
for ( int i = 0; i < nr; i++ )
180
const char *name = uim_get_im_name( tmp_uc, i );
181
const char *lang = uim_get_im_language( tmp_uc, i );
183
if ( key == QString( "uim-" ) + name )
185
// ":" separated languages for future extension
186
QStringList langs = QString( lang ).split( ":" );
191
uim_release_context( tmp_uc );
194
return QStringList( "" );
197
Q_EXPORT_PLUGIN2( uiminputcontextplugin, UimInputContextPlugin )