summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/inputmethods.cpp152
1 files changed, 87 insertions, 65 deletions
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp
index 003dc77..da98e07 100644
--- a/core/launcher/inputmethods.cpp
+++ b/core/launcher/inputmethods.cpp
@@ -1,297 +1,319 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_LANGLIST
21#include "inputmethods.h" 22#include "inputmethods.h"
22 23
23#include <qpe/config.h> 24#include <qpe/config.h>
24#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
25#include <qpe/inputmethodinterface.h> 26#include <qpe/inputmethodinterface.h>
26#include <qpe/qlibrary.h> 27#include <qpe/qlibrary.h>
28#include <qpe/global.h>
27 29
28#include <qpopupmenu.h> 30#include <qpopupmenu.h>
29#include <qpushbutton.h> 31#include <qpushbutton.h>
30#include <qtoolbutton.h> 32#include <qtoolbutton.h>
31#include <qwidget.h> 33#include <qwidget.h>
32#include <qlayout.h> 34#include <qlayout.h>
33#include <qtimer.h> 35#include <qtimer.h>
34#include <qdir.h> 36#include <qdir.h>
35#include <stdlib.h> 37#include <stdlib.h>
36#include <qtranslator.h> 38#include <qtranslator.h>
37 39
38#ifdef Q_WS_QWS 40#ifdef Q_WS_QWS
39#include <qwindowsystem_qws.h> 41#include <qwindowsystem_qws.h>
40#include <qwsevent_qws.h> 42#include <qwsevent_qws.h>
41#endif 43#endif
42 44
43#ifdef SINGLE_APP 45#ifdef SINGLE_APP
44#include "handwritingimpl.h" 46#include "handwritingimpl.h"
45#include "keyboardimpl.h" 47#include "keyboardimpl.h"
46#include "pickboardimpl.h" 48#include "pickboardimpl.h"
47#endif 49#endif
48 50
49 51
50/* XPM */ 52/* XPM */
51static const char * tri_xpm[]={ 53static const char * tri_xpm[]={
52"9 9 2 1", 54"9 9 2 1",
53"a c #000000", 55"a c #000000",
54". c None", 56". c None",
55".........", 57".........",
56".........", 58".........",
57".........", 59".........",
58"....a....", 60"....a....",
59"...aaa...", 61"...aaa...",
60"..aaaaa..", 62"..aaaaa..",
61".aaaaaaa.", 63".aaaaaaa.",
62".........", 64".........",
63"........."}; 65"........."};
64 66
65static const int inputWidgetStyle = QWidget::WStyle_Customize | 67static const int inputWidgetStyle = QWidget::WStyle_Customize |
66 QWidget::WStyle_Tool | 68 QWidget::WStyle_Tool |
67 QWidget::WStyle_StaysOnTop | 69 QWidget::WStyle_StaysOnTop |
68 QWidget::WGroupLeader; 70 QWidget::WGroupLeader;
69 71
70InputMethods::InputMethods( QWidget *parent ) : 72InputMethods::InputMethods( QWidget *parent ) :
71 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ) 73 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize )
72{ 74{
73 method = NULL; 75 method = NULL;
74 76
75 QHBoxLayout *hbox = new QHBoxLayout( this ); 77 QHBoxLayout *hbox = new QHBoxLayout( this );
76 78
77 kbdButton = new QToolButton( this ); 79 kbdButton = new QToolButton( this );
78 kbdButton->setFocusPolicy(NoFocus); 80 kbdButton->setFocusPolicy(NoFocus);
79 kbdButton->setToggleButton( TRUE ); 81 kbdButton->setToggleButton( TRUE );
80 kbdButton->setFixedHeight( 17 ); 82 kbdButton->setFixedHeight( 17 );
81 kbdButton->setFixedWidth( 32 ); 83 kbdButton->setFixedWidth( 32 );
82 kbdButton->setAutoRaise( TRUE ); 84 kbdButton->setAutoRaise( TRUE );
83 kbdButton->setUsesBigPixmap( TRUE ); 85 kbdButton->setUsesBigPixmap( TRUE );
84 hbox->addWidget( kbdButton ); 86 hbox->addWidget( kbdButton );
85 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); 87 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) );
86 88
87 kbdChoice = new QToolButton( this ); 89 kbdChoice = new QToolButton( this );
88 kbdChoice->setFocusPolicy(NoFocus); 90 kbdChoice->setFocusPolicy(NoFocus);
89 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 91 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
90 kbdChoice->setFixedHeight( 17 ); 92 kbdChoice->setFixedHeight( 17 );
91 kbdChoice->setFixedWidth( 12 ); 93 kbdChoice->setFixedWidth( 12 );
92 kbdChoice->setAutoRaise( TRUE ); 94 kbdChoice->setAutoRaise( TRUE );
93 hbox->addWidget( kbdChoice ); 95 hbox->addWidget( kbdChoice );
94 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); 96 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) );
95 97
96 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), 98 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()),
97 this, SLOT(resetStates()) ); 99 this, SLOT(resetStates()) );
98 100
99 loadInputMethods(); 101 loadInputMethods();
100} 102}
101 103
102InputMethods::~InputMethods() 104InputMethods::~InputMethods()
103{ 105{
104#ifndef SINGLE_APP 106#ifndef SINGLE_APP
105 QValueList<InputMethod>::Iterator mit; 107 QValueList<InputMethod>::Iterator mit;
106 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) { 108 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) {
107 int i = (*mit).interface->release(); 109 int i = (*mit).interface->release();
108 (*mit).library->unload(); 110 (*mit).library->unload();
109 delete (*mit).library; 111 delete (*mit).library;
110 } 112 }
111#endif 113#endif
112} 114}
113 115
114void InputMethods::hideInputMethod() 116void InputMethods::hideInputMethod()
115{ 117{
116 kbdButton->setOn( FALSE ); 118 kbdButton->setOn( FALSE );
117} 119}
118 120
119void InputMethods::showInputMethod() 121void InputMethods::showInputMethod()
120{ 122{
121 kbdButton->setOn( TRUE ); 123 kbdButton->setOn( TRUE );
122} 124}
123 125
124void InputMethods::showInputMethod(const QString& name) 126void InputMethods::showInputMethod(const QString& name)
125{ 127{
126 int i = 0; 128 int i = 0;
127 QValueList<InputMethod>::Iterator it; 129 QValueList<InputMethod>::Iterator it;
128 InputMethod *im = 0; 130 InputMethod *im = 0;
129 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 131 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
130 if ( (*it).interface->name() == name ) { 132 if ( (*it).interface->name() == name ) {
131 im = &(*it); 133 im = &(*it);
132 break; 134 break;
133 } 135 }
134 } 136 }
135 if ( im ) 137 if ( im )
136 chooseMethod(im); 138 chooseMethod(im);
137} 139}
138 140
139void InputMethods::resetStates() 141void InputMethods::resetStates()
140{ 142{
141 if ( method ) 143 if ( method )
142 method->interface->resetState(); 144 method->interface->resetState();
143} 145}
144 146
145QRect InputMethods::inputRect() const 147QRect InputMethods::inputRect() const
146{ 148{
147 if ( !method || !method->widget->isVisible() ) 149 if ( !method || !method->widget->isVisible() )
148 return QRect(); 150 return QRect();
149 else 151 else
150 return method->widget->geometry(); 152 return method->widget->geometry();
151} 153}
152 154
153void InputMethods::loadInputMethods() 155void InputMethods::loadInputMethods()
154{ 156{
155#ifndef SINGLE_APP 157#ifndef SINGLE_APP
156 hideInputMethod(); 158 hideInputMethod();
157 method = 0; 159 method = 0;
158 160
159 QValueList<InputMethod>::Iterator mit; 161 QValueList<InputMethod>::Iterator mit;
160 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) { 162 for ( mit = inputMethodList.begin(); mit != inputMethodList.end(); ++mit ) {
161 (*mit).interface->release(); 163 (*mit).interface->release();
162 (*mit).library->unload(); 164 (*mit).library->unload();
163 delete (*mit).library; 165 delete (*mit).library;
164 } 166 }
165 inputMethodList.clear(); 167 inputMethodList.clear();
166 168
167 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 169 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
168 QDir dir( path, "lib*.so" ); 170 QDir dir( path, "lib*.so" );
169 QStringList list = dir.entryList(); 171 QStringList list = dir.entryList();
170 QStringList::Iterator it; 172 QStringList::Iterator it;
171 for ( it = list.begin(); it != list.end(); ++it ) { 173 for ( it = list.begin(); it != list.end(); ++it ) {
172 InputMethodInterface *iface = 0; 174 InputMethodInterface *iface = 0;
173 QLibrary *lib = new QLibrary( path + "/" + *it ); 175 QLibrary *lib = new QLibrary( path + "/" + *it );
174 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) { 176 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) {
175 InputMethod input; 177 InputMethod input;
176 input.library = lib; 178 input.library = lib;
177 input.interface = iface; 179 input.interface = iface;
178 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 180 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
179 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 181 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
180 inputMethodList.append( input ); 182 inputMethodList.append( input );
181 QString lang = getenv( "LANG" ); 183
182 QTranslator * trans = new QTranslator(qApp); 184 QString type = (*it).left( (*it).find(".") );
183 QString type = (*it).left( (*it).find(".") ); 185 QStringList langs = Global::languageList();
184 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 186 for (QStringList::ConstIterator lit = langs.begin(); lit!=langs.end(); ++lit) {
185 qDebug("tr for inputmethod: %s", tfn.latin1() ); 187 QString lang = *lit;
186 if ( trans->load( tfn )) 188 QTranslator * trans = new QTranslator(qApp);
187 qApp->installTranslator( trans ); 189 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
188 else 190 if ( trans->load( tfn ))
189 delete trans; 191 qApp->installTranslator( trans );
190 } else { 192 else
191 delete lib; 193 delete trans;
192 } 194 }
195 } else {
196 delete lib;
197 }
193 } 198 }
194#else 199#else
195 InputMethod input; 200 InputMethod input;
196 input.interface = new HandwritingImpl(); 201 input.interface = new HandwritingImpl();
197 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 202 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
198 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 203 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
199 inputMethodList.append( input ); 204 inputMethodList.append( input );
200 input.interface = new KeyboardImpl(); 205 input.interface = new KeyboardImpl();
201 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 206 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
202 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 207 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
203 inputMethodList.append( input ); 208 inputMethodList.append( input );
204 input.interface = new PickboardImpl(); 209 input.interface = new PickboardImpl();
205 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 210 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
206 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 211 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
207 inputMethodList.append( input ); 212 inputMethodList.append( input );
208#endif 213#endif
209 if ( !inputMethodList.isEmpty() ) { 214 if ( !inputMethodList.isEmpty() ) {
210 method = &inputMethodList[0]; 215 Config cfg("qpe");
211 kbdButton->setPixmap( *method->interface->icon() ); 216 cfg.setGroup("InputMethod");
217 QString curMethod = cfg.readEntry("current","");
218 if(curMethod.isEmpty()) {
219 method = &inputMethodList[0];
220 } else {
221 int i = 0;
222 QValueList<InputMethod>::Iterator it;
223 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
224 if((*it).interface->name() == curMethod) {
225 method = &inputMethodList[i];
226// qDebug(curMethod);
227 }
228 }
229 }
230 kbdButton->setPixmap( *method->interface->icon() );
212 } 231 }
213 if ( !inputMethodList.isEmpty() ) 232 if ( !inputMethodList.isEmpty() )
214 kbdButton->show(); 233 kbdButton->show();
215 else 234 else
216 kbdButton->hide(); 235 kbdButton->hide();
217 if ( inputMethodList.count() > 1 ) 236 if ( inputMethodList.count() > 1 )
218 kbdChoice->show(); 237 kbdChoice->show();
219 else 238 else
220 kbdChoice->hide(); 239 kbdChoice->hide();
221} 240}
222 241
223void InputMethods::chooseKbd() 242void InputMethods::chooseKbd()
224{ 243{
225 QPopupMenu pop( this ); 244 QPopupMenu pop( this );
226 245
227 int i = 0; 246 int i = 0;
228 QValueList<InputMethod>::Iterator it; 247 QValueList<InputMethod>::Iterator it;
229 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 248 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
230 pop.insertItem( (*it).interface->name(), i ); 249 pop.insertItem( (*it).interface->name(), i );
231 if ( method == &(*it) ) 250 if ( method == &(*it) )
232 pop.setItemChecked( i, TRUE ); 251 pop.setItemChecked( i, TRUE );
233 } 252 }
234 253
235 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight()); 254 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight());
236 QSize s = pop.sizeHint(); 255 QSize s = pop.sizeHint();
237 pt.ry() -= s.height(); 256 pt.ry() -= s.height();
238 pt.rx() -= s.width(); 257 pt.rx() -= s.width();
239 i = pop.exec( pt ); 258 i = pop.exec( pt );
240 if ( i == -1 ) 259 if ( i == -1 )
241 return; 260 return;
242 InputMethod *im = &inputMethodList[i]; 261 InputMethod *im = &inputMethodList[i];
243 chooseMethod(im); 262 chooseMethod(im);
244} 263}
245 264
246void InputMethods::chooseMethod(InputMethod* im) 265void InputMethods::chooseMethod(InputMethod* im)
247{ 266{
248 if ( im != method ) { 267 if ( im != method ) {
249 if ( method && method->widget->isVisible() ) 268 if ( method && method->widget->isVisible() )
250 method->widget->hide(); 269 method->widget->hide();
251 method = im; 270 method = im;
252 kbdButton->setPixmap( *method->interface->icon() ); 271 Config cfg("qpe");
272 cfg.setGroup("InputMethod");
273 cfg.writeEntry("current", method->interface->name());
274 kbdButton->setPixmap( *method->interface->icon() );
253 } 275 }
254 if ( !kbdButton->isOn() ) 276 if ( !kbdButton->isOn() )
255 kbdButton->setOn( TRUE ); 277 kbdButton->setOn( TRUE );
256 else 278 else
257 showKbd( TRUE ); 279 showKbd( TRUE );
258} 280}
259 281
260 282
261void InputMethods::showKbd( bool on ) 283void InputMethods::showKbd( bool on )
262{ 284{
263 if ( !method ) 285 if ( !method )
264 return; 286 return;
265 287
266 if ( on ) { 288 if ( on ) {
267 method->interface->resetState(); 289 method->interface->resetState();
268 // HACK... Make the texteditor fit with all input methods 290 // HACK... Make the texteditor fit with all input methods
269 // Input methods should also never use more than about 40% of the screen 291 // Input methods should also never use more than about 40% of the screen
270 int height = QMIN( method->widget->sizeHint().height(), 134 ); 292 int height = QMIN( method->widget->sizeHint().height(), 134 );
271 method->widget->resize( qApp->desktop()->width(), height ); 293 method->widget->resize( qApp->desktop()->width(), height );
272 method->widget->move( 0, mapToGlobal( QPoint() ).y() - height ); 294 method->widget->move( 0, mapToGlobal( QPoint() ).y() - height );
273 method->widget->show(); 295 method->widget->show();
274 } else { 296 } else {
275 method->widget->hide(); 297 method->widget->hide();
276 } 298 }
277 299
278 emit inputToggled( on ); 300 emit inputToggled( on );
279} 301}
280 302
281bool InputMethods::shown() const 303bool InputMethods::shown() const
282{ 304{
283 return method && method->widget->isVisible(); 305 return method && method->widget->isVisible();
284} 306}
285 307
286QString InputMethods::currentShown() const 308QString InputMethods::currentShown() const
287{ 309{
288 return method && method->widget->isVisible() 310 return method && method->widget->isVisible()
289 ? method->interface->name() : QString::null; 311 ? method->interface->name() : QString::null;
290} 312}
291 313
292void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) 314void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )
293{ 315{
294#if defined(Q_WS_QWS) 316#if defined(Q_WS_QWS)
295 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); 317 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat );
296#endif 318#endif
297} 319}