void KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current, const QModelIndex& previous ) { Q_UNUSED( previous ); if ( !current.isValid() ) return; updateVariants( QPersistentModelIndex( current ) ); }
//===================================== // XKeyboard select basic layout... //------------------------------------- void XKeyboard::slotLayout ( int ) { // log(L_INFO,"XKeyboard::slotLayout() called\n"); // ... // every time the primary language layout gets changed // this function is called // --- updateVariants(); validateLayout(); apply(); }
//===================================== // XKeyboard::slotAddLayout //------------------------------------- void XKeyboard::slotAddLayout ( QListViewItem* ) { // log(L_INFO,"XKeyboard::slotAddLayout() called\n"); // ... // every time the user changed the selection in the addOn // layout list this function is called to update the // available list of Variants according to the selected // layout // --- updateVariants(); apply(); }
void KeyboardPage::init() { //### Detect current keyboard layout and variant QString currentLayout; QString currentVariant; QProcess process; process.start( "setxkbmap", QStringList() << "-print" ); if ( process.waitForFinished() ) { const QStringList list = QString( process.readAll() ) .split( "\n", QString::SkipEmptyParts ); for ( QString line : list ) { line = line.trimmed(); if ( !line.startsWith( "xkb_symbols" ) ) continue; line = line.remove( "}" ) .remove( "{" ) .remove( ";" ); line = line.mid( line.indexOf( "\"" ) + 1 ); QStringList split = line.split( "+", QString::SkipEmptyParts ); if ( split.size() >= 2 ) { currentLayout = split.at( 1 ); if ( currentLayout.contains( "(" ) ) { int parenthesisIndex = currentLayout.indexOf( "(" ); currentVariant = currentLayout.mid( parenthesisIndex + 1 ) .trimmed(); currentVariant.chop( 1 ); currentLayout = currentLayout .mid( 0, parenthesisIndex ) .trimmed(); } break; } } } //### Models m_models = KeyboardGlobal::getKeyboardModels(); QMapIterator< QString, QString > mi( m_models ); ui->comboBoxModel->blockSignals( true ); while ( mi.hasNext() ) { mi.next(); if ( mi.value() == "pc105" ) m_defaultIndex = ui->comboBoxModel->count(); ui->comboBoxModel->addItem( mi.key() ); } ui->comboBoxModel->blockSignals( false ); // Set to default value pc105 ui->comboBoxModel->setCurrentIndex( m_defaultIndex ); //### Layouts and Variants KeyboardLayoutModel* klm = new KeyboardLayoutModel( this ); ui->listLayout->setModel( klm ); connect( ui->listLayout->selectionModel(), &QItemSelectionModel::currentChanged, this, &KeyboardPage::onListLayoutCurrentItemChanged ); // Block signals ui->listLayout->blockSignals( true ); QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout ); if ( !currentLayoutItem.isValid() && ( ( currentLayout == "latin" ) || ( currentLayout == "pc" ) ) ) { currentLayout = "us"; currentLayoutItem = findLayout( klm, currentLayout ); } // Set current layout and variant if ( currentLayoutItem.isValid() ) { ui->listLayout->setCurrentIndex( currentLayoutItem ); updateVariants( currentLayoutItem, currentVariant ); } // Unblock signals ui->listLayout->blockSignals( false ); // Default to the first available layout if none was set // Do this after unblocking signals so we get the default variant handling. if ( !currentLayoutItem.isValid() && klm->rowCount() > 0 ) ui->listLayout->setCurrentIndex( klm->index( 0 ) ); }
//===================================== // XKeyboard virtual slots... //------------------------------------- bool XKeyboard::slotRun (int index) { if (XTemplate::slotRun (index)) { // log(L_INFO,"XKeyboard::slotRun() called: %d\n",index); // ... // this function is called if the keyboard page is activated. // use this function to init the dialog with the current // setup of the keyboard // --- XWrapPointer< QDict<char> > mText (mTextPtr); mStatus -> message (mText["RunXKeyboard"]); mFrame -> nextButton() -> setText (mText["finish"]); // ... // get the mFiles pointer wrapper from the Intro // object which has read all the data files. Than // lookup the keyboard XData object // --- QDict<XFile>* mFilePtr = mIntro->getFiles(); XWrapFile < QDict<XFile> > mFiles (mFilePtr); XData* sysData = mFiles["sys_KEYBOARD"] -> getDevice(0); if (! sysData) { return (FALSE); } QDict<char> keyboardInfo = sysData -> getData(); QString XKBLayouts = keyboardInfo["XkbLayout"]; QString XKBVariants = keyboardInfo["XkbVariant"]; QString XKBModel = keyboardInfo["XkbModel"]; //===================================== // clean QListView data fields //------------------------------------- mAddView -> clearSelection(); QListViewItemIterator itAdd (mAddView); for ( ; itAdd.current(); ++itAdd ) { QCheckListItem* item = (QCheckListItem*)itAdd.current(); item -> setOn ( false ); item -> setText ( 3 , "" ); } //===================================== // select base keyboard model //------------------------------------- QDictIterator<char> itModel (mModelHash); for (; itModel.current(); ++itModel) { if (itModel.currentKey() == XKBModel) { mType -> setCurrentText (QString::fromLocal8Bit (itModel.current())); } } //===================================== // get layout/variant lists //------------------------------------- XStringList completeLayout (XKBLayouts); completeLayout.setSeperator (","); QList<char> layoutList = completeLayout.getList(); QString baseLayout = layoutList.getFirst(); layoutList.removeFirst(); QStringList completeVariant = QStringList::split (",", XKBVariants,True); QList<char> variantList; QStringList::Iterator in; for (in = completeVariant.begin(); in != completeVariant.end(); ++in) { if (QString (*in).isEmpty()) { variantList.append ("!"); } else { variantList.append (*in); } } QString baseVariant = variantList.getFirst(); variantList.removeFirst(); int varCount = 0; //===================================== // select base/secondary layout(s) //------------------------------------- // 1) QDictIterator<char> itLayout (mLayoutHash); for (; itLayout.current(); ++itLayout) { if (itLayout.currentKey() == baseLayout) { mLayout -> setCurrentText (QString::fromLocal8Bit (itLayout.current())); } } // 2) QListIterator<char> it (layoutList); for (; it.current(); ++it) { QListViewItemIterator itAdd (mAddView); for ( ; itAdd.current(); ++itAdd ) { QCheckListItem* item = (QCheckListItem*)itAdd.current(); QString layout = itAdd.current()->text(2); if (layout == it.current()) { item -> setOn (true); if (QString(variantList.at(varCount)) != "!") { item -> setText ( 3 , variantList.at(varCount) ); } mAddView -> setSelected (itAdd.current(), true); mAddView -> ensureItemVisible (item); varCount++; } } } updateVariants(); //===================================== // select base/secondary variant(s) //------------------------------------- for (int n=0;n<mVariant->count();n++) { QString item = mVariant->text (n); if (item == baseVariant) { mVariant -> setCurrentText (baseVariant); } } } return (TRUE); }