author | llornkcor <llornkcor> | 2002-03-16 22:22:53 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-16 22:22:53 (UTC) |
commit | 152ca79d3a2d0277934eb0c844c15f0170de2044 (patch) (unidiff) | |
tree | 5cf8fd5c17e14a6266912103d125153a3b860bf6 | |
parent | 8111d4bf6281420b7f44ae70c26d2531cfe34401 (diff) | |
download | opie-152ca79d3a2d0277934eb0c844c15f0170de2044.zip opie-152ca79d3a2d0277934eb0c844c15f0170de2044.tar.gz opie-152ca79d3a2d0277934eb0c844c15f0170de2044.tar.bz2 |
added ability to remember the preferred (last used) input method on qpe restart
-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 | |||
@@ -20,2 +20,3 @@ | |||
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_LANGLIST | ||
21 | #include "inputmethods.h" | 22 | #include "inputmethods.h" |
@@ -26,2 +27,3 @@ | |||
26 | #include <qpe/qlibrary.h> | 27 | #include <qpe/qlibrary.h> |
28 | #include <qpe/global.h> | ||
27 | 29 | ||
@@ -65,5 +67,5 @@ static const char * tri_xpm[]={ | |||
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 | ||
@@ -96,3 +98,3 @@ InputMethods::InputMethods( QWidget *parent ) : | |||
96 | connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), | 98 | connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), |
97 | this, SLOT(resetStates()) ); | 99 | this, SLOT(resetStates()) ); |
98 | 100 | ||
@@ -106,5 +108,5 @@ InputMethods::~InputMethods() | |||
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 | } |
@@ -129,9 +131,9 @@ void InputMethods::showInputMethod(const QString& name) | |||
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 | } |
@@ -141,3 +143,3 @@ void InputMethods::resetStates() | |||
141 | if ( method ) | 143 | if ( method ) |
142 | method->interface->resetState(); | 144 | method->interface->resetState(); |
143 | } | 145 | } |
@@ -147,5 +149,5 @@ QRect InputMethods::inputRect() const | |||
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 | } |
@@ -160,5 +162,5 @@ void InputMethods::loadInputMethods() | |||
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 | } |
@@ -171,23 +173,26 @@ void InputMethods::loadInputMethods() | |||
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 | } |
@@ -209,13 +214,27 @@ void InputMethods::loadInputMethods() | |||
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 | } |
@@ -229,5 +248,5 @@ void InputMethods::chooseKbd() | |||
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 | } |
@@ -240,3 +259,3 @@ void InputMethods::chooseKbd() | |||
240 | if ( i == -1 ) | 259 | if ( i == -1 ) |
241 | return; | 260 | return; |
242 | InputMethod *im = &inputMethodList[i]; | 261 | InputMethod *im = &inputMethodList[i]; |
@@ -248,11 +267,14 @@ void InputMethods::chooseMethod(InputMethod* im) | |||
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 | } |
@@ -263,14 +285,14 @@ void InputMethods::showKbd( bool on ) | |||
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 | } |
@@ -288,3 +310,3 @@ QString InputMethods::currentShown() const | |||
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 | } |