summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-11-17 11:03:44 (UTC)
committer mickeyl <mickeyl>2003-11-17 11:03:44 (UTC)
commit725e2723291fe1d71ca68cb59cec83428d40b8af (patch) (side-by-side diff)
tree2c9cb7b26af0c1adea965be4ea458e52ad386a7c
parenta13d188a20f66546d4d96c0c1c06b1f05b69418b (diff)
downloadopie-725e2723291fe1d71ca68cb59cec83428d40b8af.zip
opie-725e2723291fe1d71ca68cb59cec83428d40b8af.tar.gz
opie-725e2723291fe1d71ca68cb59cec83428d40b8af.tar.bz2
hide inputmethod also when not floating
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/inputmethods.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp
index 62e316c..5d8faf7 100644
--- a/core/launcher/inputmethods.cpp
+++ b/core/launcher/inputmethods.cpp
@@ -210,421 +210,421 @@ QRect InputMethods::inputRect() const
void InputMethods::unloadInputMethods()
{
unloadMethod( inputMethodList );
unloadMethod( inputModifierList );
inputMethodList.clear();
inputModifierList.clear();
}
void InputMethods::unloadMethod( QValueList<InputMethod>& list ) {
QValueList<InputMethod>::Iterator it;
for (it = list.begin(); it != list.end(); ++it )
(*it).releaseInterface();
}
QStringList InputMethods::plugins()const {
QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
#ifdef Q_OS_MACX
QDir dir( path, "lib*.dylib" );
#else
QDir dir( path, "lib*.so" );
#endif /* Q_OS_MACX */
return dir.entryList();
}
void InputMethods::installTranslator( const QString& type ) {
QStringList langs = Global::languageList();
QStringList::ConstIterator lit;
for ( lit= langs.begin(); lit!=langs.end(); ++lit) {
QString lang = *lit;
QTranslator * trans = new QTranslator(qApp);
QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
if ( trans->load( tfn ))
qApp->installTranslator( trans );
else
delete trans;
}
}
void InputMethods::setPreferedHandlers() {
Config cfg("qpe");
cfg.setGroup("InputMethod");
QString current = cfg.readEntry("current");
QString im = cfg.readEntry("im");
QValueList<InputMethod>::Iterator it;
if (!inputModifierList.isEmpty() && !im.isEmpty() ) {
for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it )
if ( (*it).name() == im ) {
imethod = &(*it); break;
}
}
if (!inputMethodList.isEmpty() && !current.isEmpty() ) {
for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it )
if ( (*it).name() == current ) {
qWarning("preferred keyboard is %s", current.latin1() );
mkeyboard = &(*it);
kbdButton->setPixmap( *mkeyboard->icon() );
break;
}
}
}
void InputMethods::loadInputMethods()
{
#ifndef QT_NO_COMPONENT
hideInputMethod();
mkeyboard = 0;
unloadInputMethods();
QString path = QPEApplication::qpeDir() + "/plugins/inputmethods";
QStringList list = plugins();
QStringList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
InputMethodInterface *iface = 0;
ExtInputMethodInterface *eface = 0;
QLibrary *lib = new QLibrary( path + "/" + *it );
if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) {
InputMethod input;
input.newIM = FALSE;
input.library = lib;
input.libName = *it;
input.interface = iface;
input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
inputMethodList.append( input );
} else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) {
InputMethod input;
input.newIM = TRUE;
input.library = lib;
input.libName = *it;
input.extInterface = eface;
input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle );
// may be either a simple, or advanced.
if (input.widget) {
//qDebug("its a keyboard");
inputMethodList.append( input );
} else {
//qDebug("its a real im");
input.widget = input.extInterface->statusWidget( 0, 0 );
if (input.widget) {
//qDebug("blah");
inputModifierList.append( input );
imButton->addWidget(input.widget, inputModifierList.count());
}
}
}else{
delete lib;
lib = 0l;
}
installTranslator( (*it).left( (*it).find(".") ) );
}
qHeapSort( inputMethodList );
#endif /* killed BUILT in cause they would not compile */
QWSServer::setCurrentInputMethod( 0 );
/* set the prefered IM + handler */
setPreferedHandlers();
if ( !inputModifierList.isEmpty() ) {
if (!imethod)
imethod = &inputModifierList[0];
imButton->raiseWidget(imethod->widget);
QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
} else {
imethod = 0;
}
// we need to update keyboards afterwards, as some of them may not be compatible with
// the current input method
updateKeyboards(imethod);
if ( !inputModifierList.isEmpty() )
imButton->show();
else
imButton->hide();
if ( inputModifierList.count() > 1 )
imChoice->show();
else
imChoice->hide();
}
void InputMethods::chooseKbd()
{
QPopupMenu pop( this );
pop.setFocusPolicy( NoFocus ); //don't reset IM
QString imname;
if (imethod)
imname = imethod->libName.mid(imethod->libName.findRev('/') + 1);
int i = 0;
int firstDepKbd = 0;
QValueList<InputMethod>::Iterator it;
for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
// add empty new items, all old items.
if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) {
pop.insertItem( (*it).name(), i, firstDepKbd);
if ( mkeyboard == &(*it) )
pop.setItemChecked( i, TRUE );
firstDepKbd++;
} else if ( (*it).extInterface->compatible().contains(imname)) {
// check if we need to insert a sep.
if (firstDepKbd == i)
pop.insertSeparator();
pop.insertItem( (*it).name(), i, -1);
if ( mkeyboard == &(*it) )
pop.setItemChecked( i, TRUE );
}
}
QPoint pt = mapToGlobal(kbdChoice->geometry().topRight());
QSize s = pop.sizeHint();
pt.ry() -= s.height();
pt.rx() -= s.width();
i = pop.exec( pt );
if ( i == -1 )
return;
InputMethod *im = &inputMethodList[i];
chooseKeyboard(im);
}
void InputMethods::chooseIm()
{
QPopupMenu pop( this );
int i = 0;
QValueList<InputMethod>::Iterator it;
for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) {
pop.insertItem( (*it).name(), i );
if ( imethod == &(*it) )
pop.setItemChecked( i, TRUE );
}
QPoint pt = mapToGlobal(imChoice->geometry().topRight());
QSize s = pop.sizeHint();
pt.ry() -= s.height();
pt.rx() -= s.width();
i = pop.exec( pt );
if ( i == -1 )
return;
InputMethod *im = &inputModifierList[i];
chooseMethod(im);
}
void InputMethods::chooseKeyboard(InputMethod* im)
{
if ( im != mkeyboard ) {
if ( mkeyboard && mkeyboard->widget->isVisible() )
mkeyboard->widget->hide();
mkeyboard = im;
kbdButton->setPixmap( *mkeyboard->icon() );
}
if ( !kbdButton->isOn() )
kbdButton->setOn( TRUE );
else
showKbd( TRUE );
}
static bool keyboardCompatible(InputMethod *keyb, const QString &imname )
{
if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() )
return TRUE;
if ( keyb->extInterface->compatible().contains(imname) )
return TRUE;
return FALSE;
}
// Updates the display of the soft keyboards available to the current input method
void InputMethods::updateKeyboards(InputMethod *im )
{
uint count;
if ( im ) {
QString imname = im->libName.mid(im->libName.findRev('/') + 1);
if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) {
kbdButton->setOn( FALSE );
showKbd( FALSE );
mkeyboard = 0;
}
count = 0;
QValueList<InputMethod>::Iterator it;
for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) {
if ( keyboardCompatible( &(*it), imname ) ) {
if ( !mkeyboard ) {
mkeyboard = &(*it);
kbdButton->setPixmap( *mkeyboard->icon() );
}
count++;
}
}
} else {
count = inputMethodList.count();
if ( count && !mkeyboard ) {
mkeyboard = &inputMethodList[0];
kbdButton->setPixmap( *mkeyboard->icon() );
} else if (!count){
mkeyboard = 0; //might be redundant
}
}
if ( count > 1 )
kbdChoice->show();
else
kbdChoice->hide();
if ( count )
kbdButton->show();
else
kbdButton->hide();
}
void InputMethods::chooseMethod(InputMethod* im)
{
if ( im != imethod ) {
updateKeyboards( im );
Config cfg("qpe");
cfg.setGroup("InputMethod");
if (im )
cfg.writeEntry("im", im->name() );
if (mkeyboard)
cfg.writeEntry("current", mkeyboard->name() );
QWSServer::setCurrentInputMethod( 0 );
imethod = im;
if ( imethod && imethod->newIM )
QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
else
QWSServer::setCurrentInputMethod( 0 );
if ( im )
imButton->raiseWidget(im->widget);
else
imButton->hide(); //### good UI? make sure it is shown again!
}
}
void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data )
{
if ( imethod && imethod->newIM )
imethod->extInterface->qcopReceive( msg, data );
}
void InputMethods::showKbd( bool on )
{
if ( !mkeyboard )
return;
if ( on )
{
mkeyboard->resetState();
int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 );
int width = qApp->desktop()->width() * (inputWidgetWidth*0.01);
int left = 0;
int top = mapToGlobal( QPoint() ).y() - height;
if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
{
qDebug( "InputMethods: reading geometry." );
Config cfg( "Launcher" );
cfg.setGroup( "InputMethods" );
int l = cfg.readNumEntry( "absX", -1 );
int t = cfg.readNumEntry( "absY", -1 );
int w = cfg.readNumEntry( "absWidth", -1 );
int h = cfg.readNumEntry( "absHeight", -1 );
if ( l > -1 && t > -1 && w > -1 && h > -1 )
{
qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h );
left = l;
top = t;
width = w;
height = h;
}
else
{
qDebug( "InputMethods: config values are new or not ok." );
}
}
else
{
qDebug( "InputMethods: no floating selected." );
}
mkeyboard->widget->resize( width, height );
mkeyboard->widget->move( left, top );
mkeyboard->widget->show();
mkeyboard->widget->installEventFilter( this );
}
else
{
if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
{
QPoint pos = mkeyboard->widget->pos();
QSize siz = mkeyboard->widget->size();
qDebug( "InputMethods: saving geometry." );
Config cfg( "Launcher" );
cfg.setGroup( "InputMethods" );
cfg.writeEntry( "absX", pos.x() );
cfg.writeEntry( "absY", pos.y() );
cfg.writeEntry( "absWidth", siz.width() );
cfg.writeEntry( "absHeight", siz.height() );
cfg.write();
- mkeyboard->widget->hide();
mkeyboard->widget->removeEventFilter( this );
}
+ mkeyboard->widget->hide();
}
emit inputToggled( on );
}
bool InputMethods::shown() const
{
return mkeyboard && mkeyboard->widget->isVisible();
}
QString InputMethods::currentShown() const
{
return mkeyboard && mkeyboard->widget->isVisible()
? mkeyboard->name() : QString::null;
}
void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )
{
#if defined(Q_WS_QWS)
QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat );
#endif
}
bool InputMethods::eventFilter( QObject* o, QEvent* e )
{
if ( e->type() == QEvent::Close )
{
( (QCloseEvent*) e )->ignore();
showKbd( false );
kbdButton->setOn( false );
return true;
}
return false;
}