summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-11-17 11:03:44 (UTC)
committer mickeyl <mickeyl>2003-11-17 11:03:44 (UTC)
commit725e2723291fe1d71ca68cb59cec83428d40b8af (patch) (unidiff)
tree2c9cb7b26af0c1adea965be4ea458e52ad386a7c
parenta13d188a20f66546d4d96c0c1c06b1f05b69418b (diff)
downloadopie-725e2723291fe1d71ca68cb59cec83428d40b8af.zip
opie-725e2723291fe1d71ca68cb59cec83428d40b8af.tar.gz
opie-725e2723291fe1d71ca68cb59cec83428d40b8af.tar.bz2
hide inputmethod also when not floating
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/inputmethods.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp
index 62e316c..5d8faf7 100644
--- a/core/launcher/inputmethods.cpp
+++ b/core/launcher/inputmethods.cpp
@@ -1,630 +1,630 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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#define QTOPIA_INTERNAL_LANGLIST
22#include "inputmethods.h" 22#include "inputmethods.h"
23 23
24#include <qtopia/config.h> 24#include <qtopia/config.h>
25#include <qtopia/qpeapplication.h> 25#include <qtopia/qpeapplication.h>
26#include <qtopia/inputmethodinterface.h> 26#include <qtopia/inputmethodinterface.h>
27#include <qtopia/global.h> 27#include <qtopia/global.h>
28 28
29#include <qpopupmenu.h> 29#include <qpopupmenu.h>
30#include <qpushbutton.h> 30#include <qpushbutton.h>
31#include <qtoolbutton.h> 31#include <qtoolbutton.h>
32#include <qwidgetstack.h> 32#include <qwidgetstack.h>
33#include <qwidget.h> 33#include <qwidget.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qdir.h> 36#include <qdir.h>
37#include <stdlib.h> 37#include <stdlib.h>
38#include <qtranslator.h> 38#include <qtranslator.h>
39#include <qtl.h> 39#include <qtl.h>
40 40
41#ifdef Q_WS_QWS 41#ifdef Q_WS_QWS
42#include <qwindowsystem_qws.h> 42#include <qwindowsystem_qws.h>
43#include <qwsevent_qws.h> 43#include <qwsevent_qws.h>
44#include <qcopchannel_qws.h> 44#include <qcopchannel_qws.h>
45#endif 45#endif
46 46
47/* ### SingleFloppy if someone is interested? */ 47/* ### SingleFloppy if someone is interested? */
48#if 0 48#if 0
49#ifdef QT_NO_COMPONENT 49#ifdef QT_NO_COMPONENT
50#include "../plugins/inputmethods/handwriting/handwritingimpl.h" 50#include "../plugins/inputmethods/handwriting/handwritingimpl.h"
51#include "../plugins/inputmethods/keyboard/keyboardimpl.h" 51#include "../plugins/inputmethods/keyboard/keyboardimpl.h"
52#include "../3rdparty/plugins/inputmethods/pickboard/pickboardimpl.h" 52#include "../3rdparty/plugins/inputmethods/pickboard/pickboardimpl.h"
53#endif 53#endif
54#endif 54#endif
55 55
56/* XPM */ 56/* XPM */
57static const char * tri_xpm[]={ 57static const char * tri_xpm[]={
58"9 9 2 1", 58"9 9 2 1",
59"a c #000000", 59"a c #000000",
60". c None", 60". c None",
61".........", 61".........",
62".........", 62".........",
63".........", 63".........",
64"....a....", 64"....a....",
65"...aaa...", 65"...aaa...",
66"..aaaaa..", 66"..aaaaa..",
67".aaaaaaa.", 67".aaaaaaa.",
68".........", 68".........",
69"........."}; 69"........."};
70 70
71int InputMethod::operator <(const InputMethod& o) const 71int InputMethod::operator <(const InputMethod& o) const
72{ 72{
73 return name() < o.name(); 73 return name() < o.name();
74} 74}
75int InputMethod::operator >(const InputMethod& o) const 75int InputMethod::operator >(const InputMethod& o) const
76{ 76{
77 return name() > o.name(); 77 return name() > o.name();
78} 78}
79int InputMethod::operator <=(const InputMethod& o) const 79int InputMethod::operator <=(const InputMethod& o) const
80{ 80{
81 return name() <= o.name(); 81 return name() <= o.name();
82} 82}
83 83
84 84
85/* 85/*
86 Slightly hacky: We use WStyle_Tool as a flag to say "this widget 86 Slightly hacky: We use WStyle_Tool as a flag to say "this widget
87 belongs to the IM system, so clicking it should not cause a reset". 87 belongs to the IM system, so clicking it should not cause a reset".
88 */ 88 */
89class IMToolButton : public QToolButton 89class IMToolButton : public QToolButton
90{ 90{
91public: 91public:
92 IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) 92 IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent )
93 { setWFlags( WStyle_Tool ); } 93 { setWFlags( WStyle_Tool ); }
94}; 94};
95 95
96 96
97InputMethods::InputMethods( QWidget *parent ) : 97InputMethods::InputMethods( QWidget *parent ) :
98 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), 98 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ),
99 mkeyboard(0), imethod(0) 99 mkeyboard(0), imethod(0)
100{ 100{
101 Config cfg( "Launcher" ); 101 Config cfg( "Launcher" );
102 cfg.setGroup( "InputMethods" ); 102 cfg.setGroup( "InputMethods" );
103 inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool; 103 inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool;
104 inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0; 104 inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0;
105 inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); 105 inputWidgetWidth = cfg.readNumEntry( "Width", 100 );
106 106
107 setBackgroundMode( PaletteBackground ); 107 setBackgroundMode( PaletteBackground );
108 QHBoxLayout *hbox = new QHBoxLayout( this ); 108 QHBoxLayout *hbox = new QHBoxLayout( this );
109 109
110 kbdButton = new IMToolButton( this); 110 kbdButton = new IMToolButton( this);
111 kbdButton->setFocusPolicy(NoFocus); 111 kbdButton->setFocusPolicy(NoFocus);
112 kbdButton->setToggleButton( TRUE ); 112 kbdButton->setToggleButton( TRUE );
113 if (parent->sizeHint().height() > 0) 113 if (parent->sizeHint().height() > 0)
114 kbdButton->setFixedHeight( parent->sizeHint().height() ); 114 kbdButton->setFixedHeight( parent->sizeHint().height() );
115 kbdButton->setFixedWidth( 32 ); 115 kbdButton->setFixedWidth( 32 );
116 kbdButton->setAutoRaise( TRUE ); 116 kbdButton->setAutoRaise( TRUE );
117 kbdButton->setUsesBigPixmap( TRUE ); 117 kbdButton->setUsesBigPixmap( TRUE );
118 hbox->addWidget( kbdButton ); 118 hbox->addWidget( kbdButton );
119 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); 119 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) );
120 120
121 kbdChoice = new IMToolButton( this ); 121 kbdChoice = new IMToolButton( this );
122 kbdChoice->setFocusPolicy(NoFocus); 122 kbdChoice->setFocusPolicy(NoFocus);
123 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 123 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
124 if (parent->sizeHint().height() > 0) 124 if (parent->sizeHint().height() > 0)
125 kbdChoice->setFixedHeight( parent->sizeHint().height() ); 125 kbdChoice->setFixedHeight( parent->sizeHint().height() );
126 kbdChoice->setFixedWidth( 13 ); 126 kbdChoice->setFixedWidth( 13 );
127 kbdChoice->setAutoRaise( TRUE ); 127 kbdChoice->setAutoRaise( TRUE );
128 hbox->addWidget( kbdChoice ); 128 hbox->addWidget( kbdChoice );
129 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); 129 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) );
130 130
131 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), 131 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()),
132 this, SLOT(resetStates()) ); 132 this, SLOT(resetStates()) );
133 133
134 134
135 imButton = new QWidgetStack( this ); // later a widget stack 135 imButton = new QWidgetStack( this ); // later a widget stack
136 imButton->setFocusPolicy(NoFocus); 136 imButton->setFocusPolicy(NoFocus);
137 if (parent->sizeHint().height() > 0) 137 if (parent->sizeHint().height() > 0)
138 imButton->setFixedHeight( parent->sizeHint().height() ); 138 imButton->setFixedHeight( parent->sizeHint().height() );
139 hbox->addWidget(imButton); 139 hbox->addWidget(imButton);
140 140
141 imChoice = new QToolButton( this ); 141 imChoice = new QToolButton( this );
142 imChoice->setFocusPolicy(NoFocus); 142 imChoice->setFocusPolicy(NoFocus);
143 imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 143 imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
144 if (parent->sizeHint().height() > 0) 144 if (parent->sizeHint().height() > 0)
145 imChoice->setFixedHeight( parent->sizeHint().height() ); 145 imChoice->setFixedHeight( parent->sizeHint().height() );
146 imChoice->setFixedWidth( 13 ); 146 imChoice->setFixedWidth( 13 );
147 imChoice->setAutoRaise( TRUE ); 147 imChoice->setAutoRaise( TRUE );
148 hbox->addWidget( imChoice ); 148 hbox->addWidget( imChoice );
149 connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) ); 149 connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) );
150 150
151 loadInputMethods(); 151 loadInputMethods();
152 152
153 QCopChannel *channel = new QCopChannel( "QPE/IME", this ); 153 QCopChannel *channel = new QCopChannel( "QPE/IME", this );
154 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 154 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
155 this, SLOT(qcopReceive(const QCString&, const QByteArray&)) ); 155 this, SLOT(qcopReceive(const QCString&, const QByteArray&)) );
156} 156}
157 157
158InputMethods::~InputMethods() 158InputMethods::~InputMethods()
159{ 159{
160 Config cfg("qpe"); 160 Config cfg("qpe");
161 cfg.setGroup("InputMethod"); 161 cfg.setGroup("InputMethod");
162 if (imethod) 162 if (imethod)
163 cfg.writeEntry("im", imethod->name() ); 163 cfg.writeEntry("im", imethod->name() );
164 if (mkeyboard) 164 if (mkeyboard)
165 cfg.writeEntry("current", mkeyboard->name() ); 165 cfg.writeEntry("current", mkeyboard->name() );
166 166
167 unloadInputMethods(); 167 unloadInputMethods();
168} 168}
169 169
170void InputMethods::hideInputMethod() 170void InputMethods::hideInputMethod()
171{ 171{
172 kbdButton->setOn( FALSE ); 172 kbdButton->setOn( FALSE );
173} 173}
174 174
175void InputMethods::showInputMethod() 175void InputMethods::showInputMethod()
176{ 176{
177 kbdButton->setOn( TRUE ); 177 kbdButton->setOn( TRUE );
178} 178}
179 179
180void InputMethods::showInputMethod(const QString& name) 180void InputMethods::showInputMethod(const QString& name)
181{ 181{
182 int i = 0; 182 int i = 0;
183 QValueList<InputMethod>::Iterator it; 183 QValueList<InputMethod>::Iterator it;
184 InputMethod *im = 0; 184 InputMethod *im = 0;
185 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 185 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
186 QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1); 186 QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1);
187 if ( (*it).name() == name || lname == name ) { 187 if ( (*it).name() == name || lname == name ) {
188 im = &(*it); 188 im = &(*it);
189 break; 189 break;
190 } 190 }
191 } 191 }
192 if ( im ) 192 if ( im )
193 chooseKeyboard(im); 193 chooseKeyboard(im);
194} 194}
195 195
196void InputMethods::resetStates() 196void InputMethods::resetStates()
197{ 197{
198 if ( mkeyboard && !mkeyboard->newIM ) 198 if ( mkeyboard && !mkeyboard->newIM )
199 mkeyboard->interface->resetState(); 199 mkeyboard->interface->resetState();
200} 200}
201 201
202QRect InputMethods::inputRect() const 202QRect InputMethods::inputRect() const
203{ 203{
204 if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() ) 204 if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() )
205 return QRect(); 205 return QRect();
206 else 206 else
207 return mkeyboard->widget->geometry(); 207 return mkeyboard->widget->geometry();
208} 208}
209 209
210void InputMethods::unloadInputMethods() 210void InputMethods::unloadInputMethods()
211{ 211{
212 unloadMethod( inputMethodList ); 212 unloadMethod( inputMethodList );
213 unloadMethod( inputModifierList ); 213 unloadMethod( inputModifierList );
214 inputMethodList.clear(); 214 inputMethodList.clear();
215 inputModifierList.clear(); 215 inputModifierList.clear();
216 216
217} 217}
218 218
219void InputMethods::unloadMethod( QValueList<InputMethod>& list ) { 219void InputMethods::unloadMethod( QValueList<InputMethod>& list ) {
220 QValueList<InputMethod>::Iterator it; 220 QValueList<InputMethod>::Iterator it;
221 221
222 for (it = list.begin(); it != list.end(); ++it ) 222 for (it = list.begin(); it != list.end(); ++it )
223 (*it).releaseInterface(); 223 (*it).releaseInterface();
224 224
225} 225}
226 226
227 227
228QStringList InputMethods::plugins()const { 228QStringList InputMethods::plugins()const {
229 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 229 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
230#ifdef Q_OS_MACX 230#ifdef Q_OS_MACX
231 QDir dir( path, "lib*.dylib" ); 231 QDir dir( path, "lib*.dylib" );
232#else 232#else
233 QDir dir( path, "lib*.so" ); 233 QDir dir( path, "lib*.so" );
234#endif /* Q_OS_MACX */ 234#endif /* Q_OS_MACX */
235 return dir.entryList(); 235 return dir.entryList();
236} 236}
237 237
238void InputMethods::installTranslator( const QString& type ) { 238void InputMethods::installTranslator( const QString& type ) {
239 QStringList langs = Global::languageList(); 239 QStringList langs = Global::languageList();
240 QStringList::ConstIterator lit; 240 QStringList::ConstIterator lit;
241 for ( lit= langs.begin(); lit!=langs.end(); ++lit) { 241 for ( lit= langs.begin(); lit!=langs.end(); ++lit) {
242 QString lang = *lit; 242 QString lang = *lit;
243 QTranslator * trans = new QTranslator(qApp); 243 QTranslator * trans = new QTranslator(qApp);
244 244
245 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 245 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
246 246
247 if ( trans->load( tfn )) 247 if ( trans->load( tfn ))
248 qApp->installTranslator( trans ); 248 qApp->installTranslator( trans );
249 else 249 else
250 delete trans; 250 delete trans;
251 } 251 }
252} 252}
253 253
254void InputMethods::setPreferedHandlers() { 254void InputMethods::setPreferedHandlers() {
255 Config cfg("qpe"); 255 Config cfg("qpe");
256 cfg.setGroup("InputMethod"); 256 cfg.setGroup("InputMethod");
257 QString current = cfg.readEntry("current"); 257 QString current = cfg.readEntry("current");
258 QString im = cfg.readEntry("im"); 258 QString im = cfg.readEntry("im");
259 259
260 QValueList<InputMethod>::Iterator it; 260 QValueList<InputMethod>::Iterator it;
261 if (!inputModifierList.isEmpty() && !im.isEmpty() ) { 261 if (!inputModifierList.isEmpty() && !im.isEmpty() ) {
262 for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it ) 262 for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it )
263 if ( (*it).name() == im ) { 263 if ( (*it).name() == im ) {
264 imethod = &(*it); break; 264 imethod = &(*it); break;
265 } 265 }
266 266
267 } 267 }
268 if (!inputMethodList.isEmpty() && !current.isEmpty() ) { 268 if (!inputMethodList.isEmpty() && !current.isEmpty() ) {
269 for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) 269 for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it )
270 if ( (*it).name() == current ) { 270 if ( (*it).name() == current ) {
271 qWarning("preferred keyboard is %s", current.latin1() ); 271 qWarning("preferred keyboard is %s", current.latin1() );
272 mkeyboard = &(*it); 272 mkeyboard = &(*it);
273 kbdButton->setPixmap( *mkeyboard->icon() ); 273 kbdButton->setPixmap( *mkeyboard->icon() );
274 break; 274 break;
275 } 275 }
276 } 276 }
277 277
278} 278}
279 279
280void InputMethods::loadInputMethods() 280void InputMethods::loadInputMethods()
281{ 281{
282#ifndef QT_NO_COMPONENT 282#ifndef QT_NO_COMPONENT
283 hideInputMethod(); 283 hideInputMethod();
284 mkeyboard = 0; 284 mkeyboard = 0;
285 285
286 unloadInputMethods(); 286 unloadInputMethods();
287 287
288 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 288 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
289 QStringList list = plugins(); 289 QStringList list = plugins();
290 QStringList::Iterator it; 290 QStringList::Iterator it;
291 for ( it = list.begin(); it != list.end(); ++it ) { 291 for ( it = list.begin(); it != list.end(); ++it ) {
292 InputMethodInterface *iface = 0; 292 InputMethodInterface *iface = 0;
293 ExtInputMethodInterface *eface = 0; 293 ExtInputMethodInterface *eface = 0;
294 QLibrary *lib = new QLibrary( path + "/" + *it ); 294 QLibrary *lib = new QLibrary( path + "/" + *it );
295 295
296 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) { 296 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) {
297 InputMethod input; 297 InputMethod input;
298 input.newIM = FALSE; 298 input.newIM = FALSE;
299 input.library = lib; 299 input.library = lib;
300 input.libName = *it; 300 input.libName = *it;
301 input.interface = iface; 301 input.interface = iface;
302 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 302 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
303 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 303 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
304 inputMethodList.append( input ); 304 inputMethodList.append( input );
305 } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) { 305 } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) {
306 InputMethod input; 306 InputMethod input;
307 input.newIM = TRUE; 307 input.newIM = TRUE;
308 input.library = lib; 308 input.library = lib;
309 input.libName = *it; 309 input.libName = *it;
310 input.extInterface = eface; 310 input.extInterface = eface;
311 input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle ); 311 input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle );
312 // may be either a simple, or advanced. 312 // may be either a simple, or advanced.
313 if (input.widget) { 313 if (input.widget) {
314 //qDebug("its a keyboard"); 314 //qDebug("its a keyboard");
315 inputMethodList.append( input ); 315 inputMethodList.append( input );
316 } else { 316 } else {
317 //qDebug("its a real im"); 317 //qDebug("its a real im");
318 input.widget = input.extInterface->statusWidget( 0, 0 ); 318 input.widget = input.extInterface->statusWidget( 0, 0 );
319 if (input.widget) { 319 if (input.widget) {
320 //qDebug("blah"); 320 //qDebug("blah");
321 inputModifierList.append( input ); 321 inputModifierList.append( input );
322 imButton->addWidget(input.widget, inputModifierList.count()); 322 imButton->addWidget(input.widget, inputModifierList.count());
323 } 323 }
324 } 324 }
325 }else{ 325 }else{
326 delete lib; 326 delete lib;
327 lib = 0l; 327 lib = 0l;
328 } 328 }
329 installTranslator( (*it).left( (*it).find(".") ) ); 329 installTranslator( (*it).left( (*it).find(".") ) );
330 } 330 }
331 qHeapSort( inputMethodList ); 331 qHeapSort( inputMethodList );
332#endif /* killed BUILT in cause they would not compile */ 332#endif /* killed BUILT in cause they would not compile */
333 333
334 QWSServer::setCurrentInputMethod( 0 ); 334 QWSServer::setCurrentInputMethod( 0 );
335 335
336 /* set the prefered IM + handler */ 336 /* set the prefered IM + handler */
337 setPreferedHandlers(); 337 setPreferedHandlers();
338 if ( !inputModifierList.isEmpty() ) { 338 if ( !inputModifierList.isEmpty() ) {
339 if (!imethod) 339 if (!imethod)
340 imethod = &inputModifierList[0]; 340 imethod = &inputModifierList[0];
341 imButton->raiseWidget(imethod->widget); 341 imButton->raiseWidget(imethod->widget);
342 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); 342 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
343 } else { 343 } else {
344 imethod = 0; 344 imethod = 0;
345 } 345 }
346 346
347 // we need to update keyboards afterwards, as some of them may not be compatible with 347 // we need to update keyboards afterwards, as some of them may not be compatible with
348 // the current input method 348 // the current input method
349 updateKeyboards(imethod); 349 updateKeyboards(imethod);
350 350
351 if ( !inputModifierList.isEmpty() ) 351 if ( !inputModifierList.isEmpty() )
352 imButton->show(); 352 imButton->show();
353 else 353 else
354 imButton->hide(); 354 imButton->hide();
355 355
356 if ( inputModifierList.count() > 1 ) 356 if ( inputModifierList.count() > 1 )
357 imChoice->show(); 357 imChoice->show();
358 else 358 else
359 imChoice->hide(); 359 imChoice->hide();
360} 360}
361 361
362void InputMethods::chooseKbd() 362void InputMethods::chooseKbd()
363{ 363{
364 QPopupMenu pop( this ); 364 QPopupMenu pop( this );
365 pop.setFocusPolicy( NoFocus ); //don't reset IM 365 pop.setFocusPolicy( NoFocus ); //don't reset IM
366 366
367 QString imname; 367 QString imname;
368 if (imethod) 368 if (imethod)
369 imname = imethod->libName.mid(imethod->libName.findRev('/') + 1); 369 imname = imethod->libName.mid(imethod->libName.findRev('/') + 1);
370 370
371 int i = 0; 371 int i = 0;
372 int firstDepKbd = 0; 372 int firstDepKbd = 0;
373 373
374 QValueList<InputMethod>::Iterator it; 374 QValueList<InputMethod>::Iterator it;
375 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 375 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
376 // add empty new items, all old items. 376 // add empty new items, all old items.
377 if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) { 377 if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) {
378 pop.insertItem( (*it).name(), i, firstDepKbd); 378 pop.insertItem( (*it).name(), i, firstDepKbd);
379 if ( mkeyboard == &(*it) ) 379 if ( mkeyboard == &(*it) )
380 pop.setItemChecked( i, TRUE ); 380 pop.setItemChecked( i, TRUE );
381 381
382 firstDepKbd++; 382 firstDepKbd++;
383 } else if ( (*it).extInterface->compatible().contains(imname)) { 383 } else if ( (*it).extInterface->compatible().contains(imname)) {
384 // check if we need to insert a sep. 384 // check if we need to insert a sep.
385 if (firstDepKbd == i) 385 if (firstDepKbd == i)
386 pop.insertSeparator(); 386 pop.insertSeparator();
387 pop.insertItem( (*it).name(), i, -1); 387 pop.insertItem( (*it).name(), i, -1);
388 if ( mkeyboard == &(*it) ) 388 if ( mkeyboard == &(*it) )
389 pop.setItemChecked( i, TRUE ); 389 pop.setItemChecked( i, TRUE );
390 } 390 }
391 } 391 }
392 392
393 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight()); 393 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight());
394 QSize s = pop.sizeHint(); 394 QSize s = pop.sizeHint();
395 pt.ry() -= s.height(); 395 pt.ry() -= s.height();
396 pt.rx() -= s.width(); 396 pt.rx() -= s.width();
397 i = pop.exec( pt ); 397 i = pop.exec( pt );
398 if ( i == -1 ) 398 if ( i == -1 )
399 return; 399 return;
400 InputMethod *im = &inputMethodList[i]; 400 InputMethod *im = &inputMethodList[i];
401 chooseKeyboard(im); 401 chooseKeyboard(im);
402} 402}
403 403
404void InputMethods::chooseIm() 404void InputMethods::chooseIm()
405{ 405{
406 QPopupMenu pop( this ); 406 QPopupMenu pop( this );
407 407
408 int i = 0; 408 int i = 0;
409 QValueList<InputMethod>::Iterator it; 409 QValueList<InputMethod>::Iterator it;
410 for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) { 410 for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) {
411 pop.insertItem( (*it).name(), i ); 411 pop.insertItem( (*it).name(), i );
412 if ( imethod == &(*it) ) 412 if ( imethod == &(*it) )
413 pop.setItemChecked( i, TRUE ); 413 pop.setItemChecked( i, TRUE );
414 } 414 }
415 415
416 QPoint pt = mapToGlobal(imChoice->geometry().topRight()); 416 QPoint pt = mapToGlobal(imChoice->geometry().topRight());
417 QSize s = pop.sizeHint(); 417 QSize s = pop.sizeHint();
418 pt.ry() -= s.height(); 418 pt.ry() -= s.height();
419 pt.rx() -= s.width(); 419 pt.rx() -= s.width();
420 i = pop.exec( pt ); 420 i = pop.exec( pt );
421 if ( i == -1 ) 421 if ( i == -1 )
422 return; 422 return;
423 InputMethod *im = &inputModifierList[i]; 423 InputMethod *im = &inputModifierList[i];
424 424
425 chooseMethod(im); 425 chooseMethod(im);
426} 426}
427 427
428void InputMethods::chooseKeyboard(InputMethod* im) 428void InputMethods::chooseKeyboard(InputMethod* im)
429{ 429{
430 if ( im != mkeyboard ) { 430 if ( im != mkeyboard ) {
431 if ( mkeyboard && mkeyboard->widget->isVisible() ) 431 if ( mkeyboard && mkeyboard->widget->isVisible() )
432 mkeyboard->widget->hide(); 432 mkeyboard->widget->hide();
433 mkeyboard = im; 433 mkeyboard = im;
434 kbdButton->setPixmap( *mkeyboard->icon() ); 434 kbdButton->setPixmap( *mkeyboard->icon() );
435 } 435 }
436 if ( !kbdButton->isOn() ) 436 if ( !kbdButton->isOn() )
437 kbdButton->setOn( TRUE ); 437 kbdButton->setOn( TRUE );
438 else 438 else
439 showKbd( TRUE ); 439 showKbd( TRUE );
440} 440}
441 441
442static bool keyboardCompatible(InputMethod *keyb, const QString &imname ) 442static bool keyboardCompatible(InputMethod *keyb, const QString &imname )
443{ 443{
444 if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() ) 444 if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() )
445 return TRUE; 445 return TRUE;
446 446
447 if ( keyb->extInterface->compatible().contains(imname) ) 447 if ( keyb->extInterface->compatible().contains(imname) )
448 return TRUE; 448 return TRUE;
449 449
450 return FALSE; 450 return FALSE;
451} 451}
452 452
453// Updates the display of the soft keyboards available to the current input method 453// Updates the display of the soft keyboards available to the current input method
454void InputMethods::updateKeyboards(InputMethod *im ) 454void InputMethods::updateKeyboards(InputMethod *im )
455{ 455{
456 uint count; 456 uint count;
457 457
458 if ( im ) { 458 if ( im ) {
459 QString imname = im->libName.mid(im->libName.findRev('/') + 1); 459 QString imname = im->libName.mid(im->libName.findRev('/') + 1);
460 460
461 if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) { 461 if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) {
462 kbdButton->setOn( FALSE ); 462 kbdButton->setOn( FALSE );
463 showKbd( FALSE ); 463 showKbd( FALSE );
464 mkeyboard = 0; 464 mkeyboard = 0;
465 } 465 }
466 466
467 count = 0; 467 count = 0;
468 468
469 QValueList<InputMethod>::Iterator it; 469 QValueList<InputMethod>::Iterator it;
470 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) { 470 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) {
471 if ( keyboardCompatible( &(*it), imname ) ) { 471 if ( keyboardCompatible( &(*it), imname ) ) {
472 if ( !mkeyboard ) { 472 if ( !mkeyboard ) {
473 mkeyboard = &(*it); 473 mkeyboard = &(*it);
474 kbdButton->setPixmap( *mkeyboard->icon() ); 474 kbdButton->setPixmap( *mkeyboard->icon() );
475 } 475 }
476 476
477 count++; 477 count++;
478 } 478 }
479 } 479 }
480 } else { 480 } else {
481 count = inputMethodList.count(); 481 count = inputMethodList.count();
482 if ( count && !mkeyboard ) { 482 if ( count && !mkeyboard ) {
483 mkeyboard = &inputMethodList[0]; 483 mkeyboard = &inputMethodList[0];
484 kbdButton->setPixmap( *mkeyboard->icon() ); 484 kbdButton->setPixmap( *mkeyboard->icon() );
485 } else if (!count){ 485 } else if (!count){
486 mkeyboard = 0; //might be redundant 486 mkeyboard = 0; //might be redundant
487 } 487 }
488 } 488 }
489 489
490 if ( count > 1 ) 490 if ( count > 1 )
491 kbdChoice->show(); 491 kbdChoice->show();
492 else 492 else
493 kbdChoice->hide(); 493 kbdChoice->hide();
494 494
495 if ( count ) 495 if ( count )
496 kbdButton->show(); 496 kbdButton->show();
497 else 497 else
498 kbdButton->hide(); 498 kbdButton->hide();
499} 499}
500 500
501void InputMethods::chooseMethod(InputMethod* im) 501void InputMethods::chooseMethod(InputMethod* im)
502{ 502{
503 if ( im != imethod ) { 503 if ( im != imethod ) {
504 updateKeyboards( im ); 504 updateKeyboards( im );
505 505
506 Config cfg("qpe"); 506 Config cfg("qpe");
507 cfg.setGroup("InputMethod"); 507 cfg.setGroup("InputMethod");
508 if (im ) 508 if (im )
509 cfg.writeEntry("im", im->name() ); 509 cfg.writeEntry("im", im->name() );
510 if (mkeyboard) 510 if (mkeyboard)
511 cfg.writeEntry("current", mkeyboard->name() ); 511 cfg.writeEntry("current", mkeyboard->name() );
512 512
513 QWSServer::setCurrentInputMethod( 0 ); 513 QWSServer::setCurrentInputMethod( 0 );
514 imethod = im; 514 imethod = im;
515 if ( imethod && imethod->newIM ) 515 if ( imethod && imethod->newIM )
516 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); 516 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
517 else 517 else
518 QWSServer::setCurrentInputMethod( 0 ); 518 QWSServer::setCurrentInputMethod( 0 );
519 519
520 if ( im ) 520 if ( im )
521 imButton->raiseWidget(im->widget); 521 imButton->raiseWidget(im->widget);
522 else 522 else
523 imButton->hide(); //### good UI? make sure it is shown again! 523 imButton->hide(); //### good UI? make sure it is shown again!
524 } 524 }
525} 525}
526 526
527void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data ) 527void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data )
528{ 528{
529 if ( imethod && imethod->newIM ) 529 if ( imethod && imethod->newIM )
530 imethod->extInterface->qcopReceive( msg, data ); 530 imethod->extInterface->qcopReceive( msg, data );
531} 531}
532 532
533 533
534void InputMethods::showKbd( bool on ) 534void InputMethods::showKbd( bool on )
535{ 535{
536 if ( !mkeyboard ) 536 if ( !mkeyboard )
537 return; 537 return;
538 538
539 if ( on ) 539 if ( on )
540 { 540 {
541 mkeyboard->resetState(); 541 mkeyboard->resetState();
542 542
543 int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 ); 543 int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 );
544 int width = qApp->desktop()->width() * (inputWidgetWidth*0.01); 544 int width = qApp->desktop()->width() * (inputWidgetWidth*0.01);
545 int left = 0; 545 int left = 0;
546 int top = mapToGlobal( QPoint() ).y() - height; 546 int top = mapToGlobal( QPoint() ).y() - height;
547 547
548 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) 548 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
549 { 549 {
550 qDebug( "InputMethods: reading geometry." ); 550 qDebug( "InputMethods: reading geometry." );
551 Config cfg( "Launcher" ); 551 Config cfg( "Launcher" );
552 cfg.setGroup( "InputMethods" ); 552 cfg.setGroup( "InputMethods" );
553 int l = cfg.readNumEntry( "absX", -1 ); 553 int l = cfg.readNumEntry( "absX", -1 );
554 int t = cfg.readNumEntry( "absY", -1 ); 554 int t = cfg.readNumEntry( "absY", -1 );
555 int w = cfg.readNumEntry( "absWidth", -1 ); 555 int w = cfg.readNumEntry( "absWidth", -1 );
556 int h = cfg.readNumEntry( "absHeight", -1 ); 556 int h = cfg.readNumEntry( "absHeight", -1 );
557 557
558 if ( l > -1 && t > -1 && w > -1 && h > -1 ) 558 if ( l > -1 && t > -1 && w > -1 && h > -1 )
559 { 559 {
560 qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h ); 560 qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h );
561 left = l; 561 left = l;
562 top = t; 562 top = t;
563 width = w; 563 width = w;
564 height = h; 564 height = h;
565 } 565 }
566 else 566 else
567 { 567 {
568 qDebug( "InputMethods: config values are new or not ok." ); 568 qDebug( "InputMethods: config values are new or not ok." );
569 } 569 }
570 } 570 }
571 else 571 else
572 { 572 {
573 qDebug( "InputMethods: no floating selected." ); 573 qDebug( "InputMethods: no floating selected." );
574 } 574 }
575 mkeyboard->widget->resize( width, height ); 575 mkeyboard->widget->resize( width, height );
576 mkeyboard->widget->move( left, top ); 576 mkeyboard->widget->move( left, top );
577 mkeyboard->widget->show(); 577 mkeyboard->widget->show();
578 mkeyboard->widget->installEventFilter( this ); 578 mkeyboard->widget->installEventFilter( this );
579 } 579 }
580 else 580 else
581 { 581 {
582 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) 582 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
583 { 583 {
584 QPoint pos = mkeyboard->widget->pos(); 584 QPoint pos = mkeyboard->widget->pos();
585 QSize siz = mkeyboard->widget->size(); 585 QSize siz = mkeyboard->widget->size();
586 qDebug( "InputMethods: saving geometry." ); 586 qDebug( "InputMethods: saving geometry." );
587 Config cfg( "Launcher" ); 587 Config cfg( "Launcher" );
588 cfg.setGroup( "InputMethods" ); 588 cfg.setGroup( "InputMethods" );
589 cfg.writeEntry( "absX", pos.x() ); 589 cfg.writeEntry( "absX", pos.x() );
590 cfg.writeEntry( "absY", pos.y() ); 590 cfg.writeEntry( "absY", pos.y() );
591 cfg.writeEntry( "absWidth", siz.width() ); 591 cfg.writeEntry( "absWidth", siz.width() );
592 cfg.writeEntry( "absHeight", siz.height() ); 592 cfg.writeEntry( "absHeight", siz.height() );
593 cfg.write(); 593 cfg.write();
594 mkeyboard->widget->hide();
595 mkeyboard->widget->removeEventFilter( this ); 594 mkeyboard->widget->removeEventFilter( this );
596 } 595 }
596 mkeyboard->widget->hide();
597 } 597 }
598 598
599 emit inputToggled( on ); 599 emit inputToggled( on );
600} 600}
601 601
602bool InputMethods::shown() const 602bool InputMethods::shown() const
603{ 603{
604 return mkeyboard && mkeyboard->widget->isVisible(); 604 return mkeyboard && mkeyboard->widget->isVisible();
605} 605}
606 606
607QString InputMethods::currentShown() const 607QString InputMethods::currentShown() const
608{ 608{
609 return mkeyboard && mkeyboard->widget->isVisible() 609 return mkeyboard && mkeyboard->widget->isVisible()
610 ? mkeyboard->name() : QString::null; 610 ? mkeyboard->name() : QString::null;
611} 611}
612 612
613void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) 613void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )
614{ 614{
615#if defined(Q_WS_QWS) 615#if defined(Q_WS_QWS)
616 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); 616 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat );
617#endif 617#endif
618} 618}
619 619
620bool InputMethods::eventFilter( QObject* o, QEvent* e ) 620bool InputMethods::eventFilter( QObject* o, QEvent* e )
621{ 621{
622 if ( e->type() == QEvent::Close ) 622 if ( e->type() == QEvent::Close )
623 { 623 {
624 ( (QCloseEvent*) e )->ignore(); 624 ( (QCloseEvent*) e )->ignore();
625 showKbd( false ); 625 showKbd( false );
626 kbdButton->setOn( false ); 626 kbdButton->setOn( false );
627 return true; 627 return true;
628 } 628 }
629 return false; 629 return false;
630} 630}