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