-rw-r--r-- | core/launcher/inputmethods.cpp | 152 |
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 | |||
@@ -13,22 +13,24 @@ | |||
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> |
@@ -58,19 +60,19 @@ static const char * tri_xpm[]={ | |||
58 | "....a....", | 60 | "....a....", |
59 | "...aaa...", | 61 | "...aaa...", |
60 | "..aaaaa..", | 62 | "..aaaaa..", |
61 | ".aaaaaaa.", | 63 | ".aaaaaaa.", |
62 | ".........", | 64 | ".........", |
63 | "........."}; | 65 | "........."}; |
64 | 66 | ||
65 | static const int inputWidgetStyle = QWidget::WStyle_Customize | | 67 | static 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 | ||
70 | InputMethods::InputMethods( QWidget *parent ) : | 72 | InputMethods::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 | ||
@@ -89,29 +91,29 @@ InputMethods::InputMethods( QWidget *parent ) : | |||
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 | ||
102 | InputMethods::~InputMethods() | 104 | InputMethods::~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 | ||
114 | void InputMethods::hideInputMethod() | 116 | void InputMethods::hideInputMethod() |
115 | { | 117 | { |
116 | kbdButton->setOn( FALSE ); | 118 | kbdButton->setOn( FALSE ); |
117 | } | 119 | } |
@@ -122,79 +124,82 @@ void InputMethods::showInputMethod() | |||
122 | } | 124 | } |
123 | 125 | ||
124 | void InputMethods::showInputMethod(const QString& name) | 126 | void 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 | ||
139 | void InputMethods::resetStates() | 141 | void InputMethods::resetStates() |
140 | { | 142 | { |
141 | if ( method ) | 143 | if ( method ) |
142 | method->interface->resetState(); | 144 | method->interface->resetState(); |
143 | } | 145 | } |
144 | 146 | ||
145 | QRect InputMethods::inputRect() const | 147 | QRect 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 | ||
153 | void InputMethods::loadInputMethods() | 155 | void 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(); |
@@ -202,96 +207,113 @@ void InputMethods::loadInputMethods() | |||
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 | ||
223 | void InputMethods::chooseKbd() | 242 | void 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 | ||
246 | void InputMethods::chooseMethod(InputMethod* im) | 265 | void 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 | ||
261 | void InputMethods::showKbd( bool on ) | 283 | void 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 | ||
281 | bool InputMethods::shown() const | 303 | bool InputMethods::shown() const |
282 | { | 304 | { |
283 | return method && method->widget->isVisible(); | 305 | return method && method->widget->isVisible(); |
284 | } | 306 | } |
285 | 307 | ||
286 | QString InputMethods::currentShown() const | 308 | QString 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 | ||
292 | void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) | 314 | void 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 | } |