~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to qt4/immodule/plugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2008-06-25 19:56:33 UTC
  • mfrom: (3.1.18 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080625195633-8jljph4rfq00l8o7
Tags: 1:1.5.1-2
* uim-tcode: provide tutcode-custom.scm, tutcode-bushudic.scm
  and tutcode-rule.scm (Closes: #482659)
* Fix FTBFS: segv during compile (Closes: #483078).
  I personally think this bug is not specific for uim but is a optimization
  problem on gcc-4.3.1. (https://bugs.freedesktop.org/show_bug.cgi?id=16477)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
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/
 
5
 
 
6
  All rights reserved.
 
7
 
 
8
  Redistribution and use in source and binary forms, with or without
 
9
  modification, are permitted provided that the following conditions
 
10
  are met:
 
11
 
 
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.
 
20
 
 
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
 
31
  SUCH DAMAGE.
 
32
 
 
33
*/
 
34
 
 
35
#include "plugin.h"
 
36
 
 
37
#include <qapplication.h>
 
38
#include <qinputcontextplugin.h>
 
39
#include <qinputcontext.h>
 
40
#include <qstringlist.h>
 
41
#ifdef Q_WS_X11
 
42
#include <QX11Info>
 
43
#endif
 
44
 
 
45
#include "uim/uim.h"
 
46
#include "uim/uim-x-util.h"
 
47
 
 
48
#include "debug.h"
 
49
#include "quiminfomanager.h"
 
50
#include "quiminputcontext_with_slave.h"
 
51
 
 
52
#define UIM_QT_LIST_SUBIM_AS_QTIM 0
 
53
 
 
54
QUimInfoManager *UimInputContextPlugin::infoManager = NULL;
 
55
 
 
56
 
 
57
UimInputContextPlugin::UimInputContextPlugin()
 
58
{
 
59
    uimReady = false;
 
60
    uimInit();
 
61
}
 
62
 
 
63
UimInputContextPlugin::~UimInputContextPlugin()
 
64
{
 
65
    uimQuit();
 
66
}
 
67
 
 
68
QStringList UimInputContextPlugin::keys() const
 
69
{
 
70
    return createImList();
 
71
}
 
72
 
 
73
QInputContext *UimInputContextPlugin::create( const QString & key )
 
74
{
 
75
    QString imname = QString::null;
 
76
 
 
77
#if UIM_QT_LIST_SUBIM_AS_QTIM
 
78
    if ( key.startsWith( "uim-" ) )
 
79
        imname = key.mid( 4 );
 
80
    else
 
81
#endif
 
82
    if ( key == "uim" )
 
83
        imname = uim_get_default_im_name( setlocale( LC_ALL, NULL ) );
 
84
 
 
85
    QStringList langs = createLanguageList( key );
 
86
    QUimInputContext *uic = new QUimInputContext( imname.toUtf8(),
 
87
                                                  langs[ 0 ].toUtf8() );
 
88
 
 
89
    return uic;
 
90
}
 
91
 
 
92
QStringList UimInputContextPlugin::languages( const QString & key )
 
93
{
 
94
    return createLanguageList( key );
 
95
}
 
96
 
 
97
QString UimInputContextPlugin::displayName( const QString & key )
 
98
{
 
99
    return QString( key ) + " (" + languages( key ) [ 0 ] + ")";
 
100
}
 
101
 
 
102
QString UimInputContextPlugin::description( const QString & key )
 
103
{
 
104
    return displayName( key ) + ": an input method provided via the uim input method framework";
 
105
}
 
106
 
 
107
QUimInfoManager *
 
108
UimInputContextPlugin::getQUimInfoManager()
 
109
{
 
110
    return infoManager;
 
111
}
 
112
 
 
113
void UimInputContextPlugin::uimInit()
 
114
{
 
115
    if ( !uim_init() ) {
 
116
        if (!infoManager)
 
117
            infoManager = new QUimInfoManager();
 
118
#if UIM_QT_USE_JAPANESE_KANA_KEYBOARD_HACK
 
119
        uim_x_kana_input_hack_init( QX11Info::display() );
 
120
#endif
 
121
        uimReady = true;
 
122
    }
 
123
}
 
124
 
 
125
void UimInputContextPlugin::uimQuit()
 
126
{
 
127
    if ( uimReady )
 
128
    {
 
129
        uim_quit();
 
130
        delete infoManager;
 
131
        uimReady = false;
 
132
    }
 
133
}
 
134
 
 
135
 
 
136
 
 
137
QStringList UimInputContextPlugin::createImList() const
 
138
{
 
139
    QStringList lst;
 
140
 
 
141
    // default
 
142
    lst.append( "uim" );
 
143
    qDebug( "name = uim" );
 
144
 
 
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 );
 
149
    if ( uimReady )
 
150
    {
 
151
        for ( int i = 0; i < nr; i++ )
 
152
        {
 
153
            const char *name = uim_get_im_name( tmp_uc, i );
 
154
            QString qs( name );
 
155
            qs = "uim-" + qs;
 
156
            lst << qs;
 
157
 
 
158
            qDebug( "name = %s", ( const char* ) qs.toUtf8() );
 
159
        }
 
160
    }
 
161
    uim_release_context( tmp_uc );
 
162
#endif
 
163
 
 
164
    return lst;
 
165
}
 
166
 
 
167
QStringList UimInputContextPlugin::createLanguageList( const QString &key ) const
 
168
{
 
169
    if ( key == "uim" )
 
170
        return QStringList() << "ja" << "ko" << "zh" << "*";
 
171
 
 
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 );
 
176
    if ( uimReady )
 
177
    {
 
178
        for ( int i = 0; i < nr; i++ )
 
179
        {
 
180
            const char *name = uim_get_im_name( tmp_uc, i );
 
181
            const char *lang = uim_get_im_language( tmp_uc, i );
 
182
 
 
183
            if ( key == QString( "uim-" ) + name )
 
184
            {
 
185
                // ":" separated languages for future extension
 
186
                QStringList langs = QString( lang ).split( ":" );
 
187
                return langs;
 
188
            }
 
189
        }
 
190
    }
 
191
    uim_release_context( tmp_uc );
 
192
#endif
 
193
 
 
194
    return QStringList( "" );
 
195
}
 
196
 
 
197
Q_EXPORT_PLUGIN2( uiminputcontextplugin, UimInputContextPlugin )