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 | |||
@@ -19,4 +19,5 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_LANGLIST | ||
21 | #include "inputmethods.h" | 22 | #include "inputmethods.h" |
22 | 23 | ||
@@ -25,4 +26,5 @@ | |||
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> |
@@ -64,7 +66,7 @@ static const char * tri_xpm[]={ | |||
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 ) : |
@@ -95,5 +97,5 @@ InputMethods::InputMethods( QWidget *parent ) : | |||
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(); |
@@ -105,7 +107,7 @@ InputMethods::~InputMethods() | |||
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 |
@@ -128,11 +130,11 @@ void InputMethods::showInputMethod(const QString& name) | |||
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 | ||
@@ -140,5 +142,5 @@ void InputMethods::resetStates() | |||
140 | { | 142 | { |
141 | if ( method ) | 143 | if ( method ) |
142 | method->interface->resetState(); | 144 | method->interface->resetState(); |
143 | } | 145 | } |
144 | 146 | ||
@@ -146,7 +148,7 @@ 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 | ||
@@ -159,7 +161,7 @@ void InputMethods::loadInputMethods() | |||
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(); |
@@ -170,25 +172,28 @@ void InputMethods::loadInputMethods() | |||
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 |
@@ -208,15 +213,29 @@ void InputMethods::loadInputMethods() | |||
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 | ||
@@ -228,7 +247,7 @@ void InputMethods::chooseKbd() | |||
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 | ||
@@ -239,5 +258,5 @@ void InputMethods::chooseKbd() | |||
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); |
@@ -247,13 +266,16 @@ 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 | ||
@@ -262,16 +284,16 @@ 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 | ||
@@ -287,5 +309,5 @@ 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 | ||