summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-16 22:22:53 (UTC)
committer llornkcor <llornkcor>2002-03-16 22:22:53 (UTC)
commit152ca79d3a2d0277934eb0c844c15f0170de2044 (patch) (unidiff)
tree5cf8fd5c17e14a6266912103d125153a3b860bf6
parent8111d4bf6281420b7f44ae70c26d2531cfe34401 (diff)
downloadopie-152ca79d3a2d0277934eb0c844c15f0170de2044.zip
opie-152ca79d3a2d0277934eb0c844c15f0170de2044.tar.gz
opie-152ca79d3a2d0277934eb0c844c15f0170de2044.tar.bz2
added ability to remember the preferred (last used) input method on qpe restart
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/inputmethods.cpp152
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
@@ -18,12 +18,14 @@
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>
@@ -63,9 +65,9 @@ static const char * tri_xpm[]={
63"........."}; 65"........."};
64 66
65static const int inputWidgetStyle = QWidget::WStyle_Customize | 67static 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
70InputMethods::InputMethods( QWidget *parent ) : 72InputMethods::InputMethods( QWidget *parent ) :
71 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ) 73 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize )
@@ -94,7 +96,7 @@ InputMethods::InputMethods( QWidget *parent ) :
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}
@@ -104,9 +106,9 @@ InputMethods::~InputMethods()
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}
@@ -127,27 +129,27 @@ void InputMethods::showInputMethod(const QString& name)
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
139void InputMethods::resetStates() 141void InputMethods::resetStates()
140{ 142{
141 if ( method ) 143 if ( method )
142 method->interface->resetState(); 144 method->interface->resetState();
143} 145}
144 146
145QRect InputMethods::inputRect() const 147QRect 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
153void InputMethods::loadInputMethods() 155void InputMethods::loadInputMethods()
@@ -158,9 +160,9 @@ void InputMethods::loadInputMethods()
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
@@ -169,27 +171,30 @@ void InputMethods::loadInputMethods()
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;
@@ -207,17 +212,31 @@ void InputMethods::loadInputMethods()
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
223void InputMethods::chooseKbd() 242void InputMethods::chooseKbd()
@@ -227,9 +246,9 @@ void InputMethods::chooseKbd()
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());
@@ -238,7 +257,7 @@ void InputMethods::chooseKbd()
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}
@@ -246,33 +265,36 @@ void InputMethods::chooseKbd()
246void InputMethods::chooseMethod(InputMethod* im) 265void 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
261void InputMethods::showKbd( bool on ) 283void 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 );
@@ -286,7 +308,7 @@ bool InputMethods::shown() const
286QString InputMethods::currentShown() const 308QString 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
292void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) 314void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )