示例#1
0
void
TableCallbacks::KnobChanged(QListViewItem *item)
{
    QString value;
    QCheckListItem *foo;
    int i;

    value = item->text(0);

    foo = (QCheckListItem *) item;

    for (i = 0; i < my_num_knobs; i++) {

        if (strncmp(value.ascii(), (my_rc_knobs+i)->name, 255) == 0) {

            break;

        }

    }


    if (foo->isOn() && (my_rc_knobs+i)->knob_val == KNOB_IS_NO) {

#ifdef VERBOSE_CONSOLE
        printf("Now %s is activated\n", value.ascii());
#endif

        (my_rc_knobs+i)->knob_val = KNOB_IS_YES;

        if ((my_rc_knobs+i)->knob_orig == KNOB_IS_YES) {

            if ((my_rc_knobs+i)->user_added == USER_ADDED_NO) {

                (my_rc_knobs+i)->modified = MODIFIED_NO;

                if (dirty > 0) dirty--;

            }

        } else {

            (my_rc_knobs+i)->modified = MODIFIED_YES;
            dirty++;

        }

    } else if (foo->isOn()==FALSE && (my_rc_knobs+i)->knob_val == KNOB_IS_YES) {

#ifdef VERBOSE_CONSOLE
        printf("Now %s is deactivated\n", value.ascii());
#endif

        (my_rc_knobs+i)->knob_val = KNOB_IS_NO;

        if ((my_rc_knobs+i)->knob_orig == KNOB_IS_NO) {

            if ((my_rc_knobs+i)->user_added == USER_ADDED_NO) {

                (my_rc_knobs+i)->modified = MODIFIED_NO;

                if (dirty > 0) dirty--;

            }

        } else {

            (my_rc_knobs+i)->modified = MODIFIED_YES;
            dirty++;

        }

    }


    my_status_bar->message((my_rc_knobs+i)->comment);

    if (dirty == 0) {

        SaveButton->setEnabled(FALSE);

    } else {

        SaveButton->setEnabled(TRUE);

    }

}
//=====================================
// XKeyboard apply keyboard
//-------------------------------------
bool XKeyboard::apply ( void ) {
	// log(L_INFO,"XKeyboard::apply() called\n");
	// ...
	// apply the keyboard to the X-Server for immediate
	// usage. This call will use the XKB extension
    // ---
	XWrapPointer< QDict<char> > mText (mTextPtr);

	QString* XkbModel   = NULL;
	QString* XkbLayout  = NULL;
	QString* XkbVariant = NULL;
	QString* XkbOptions = NULL;
	// 1) primary XKB model
	QDictIterator<char> itModel (mModelHash);
	for (; itModel.current(); ++itModel) {
	if (QString::fromLocal8Bit (itModel.current()) == mType->currentText()) {
		XkbModel = new QString (itModel.currentKey());
	}
	}
	// 2) primary XKB layout
	QDictIterator<char> itLayout (mLayoutHash);
	for (; itLayout.current(); ++itLayout) {
	if (QString::fromLocal8Bit(itLayout.current()) == mLayout->currentText()) {
		XkbLayout = new QString (itLayout.currentKey());
	}
	}
	// 3) variant for primary XKB layout
	XkbVariant = new QString();
	if (mVariant->currentText()) {
		*XkbVariant = mVariant->currentText();
	}
	// 4) additional layout and variant
	QListViewItemIterator itAdd (mAddView);
	for ( ; itAdd.current(); ++itAdd ) {
	QCheckListItem* item = (QCheckListItem*)itAdd.current();
	if (item->isOn()) {
		QString layout  = itAdd.current()->text(2);
		QString variant = "";
		XkbLayout->sprintf("%s,%s",
			XkbLayout->ascii(),layout.ascii()
		);
		if (itAdd.current()->text(3)) {
			variant = itAdd.current()->text(3);
		}
		XkbVariant->sprintf("%s,%s",
			XkbVariant->ascii(),variant.ascii()
		);
	}
	}
	// 5) options
	if (mKeyboardOptions["XkbOptions"]) {
	if (! QString(mKeyboardOptions["XkbOptions"]).isEmpty()) {
		XkbOptions = new QString (mKeyboardOptions["XkbOptions"]);
	}
	}
	QString optm ("-model");
    QString optl ("-layout");
    QString opto ("-option");
    QString optv ("-variant");
	if ((XkbVariant) && (XkbOptions)) {
		#if 0
		printf("%s %s %s %s %s %s %s %s\n",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii(),
			opto.ascii(),XkbOptions->ascii(),optv.ascii(),XkbVariant->ascii()
		);
		#endif
		#if 1
		qx ( SETXKBMAP,STDNONE,8,"%s %s %s %s %s %s %s %s",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii(),
			opto.ascii(),XkbOptions->ascii(),optv.ascii(),XkbVariant->ascii()
		);
		#endif
	} else if (XkbVariant) {
		#if 0
		printf("%s %s %s %s %s %s\n",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii(),
			optv.ascii(),XkbVariant->ascii()
		);
		#endif
		#if 1
		qx ( SETXKBMAP,STDNONE,8,"%s %s %s %s %s %s",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii(),
			optv.ascii(),XkbVariant->ascii()
		);
		#endif
	} else if (XkbOptions) {
		#if 0
		printf("%s %s %s %s %s %s\n",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii(),
			opto.ascii(),XkbOptions->ascii()
		);
		#endif
		#if 1
		qx ( SETXKBMAP,STDNONE,8,"%s %s %s %s %s %s",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii(),
			opto.ascii(),XkbOptions->ascii()
		);
		#endif
	} else {
		#if 0
		printf("%s %s %s %s\n",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii()
		);
		#endif
		#if 1
		qx ( SETXKBMAP,STDNONE,8,"%s %s %s %s",
			optm.ascii(),XkbModel->ascii(),optl.ascii(),XkbLayout->ascii()
		);
		#endif
	}
	return (true);
}
示例#3
0
void MainWindow::slotApply()
{
    QStringList removeList;
    QStringList installList;
    QStringList upgradeList;

    for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild());
          item != 0 ;
          item = static_cast<QCheckListItem *>(item->nextSibling()) )
    {
        if ( item->isOn() )
        {
            OPackage *package = m_packman.findPackage( item->text() );
            if ( package )
            {
                if ( !package->versionInstalled().isNull() )
                {
                    if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 )
                    {
                        // Remove/upgrade package
                        int answer =  PromptDlg::ask( tr( "Remove or upgrade" ),
                                      tr( QString( "Do you wish to remove or upgrade\n%1?" ).arg( item->text() ) ),
                                      tr( "Remove" ), tr( "Upgrade" ), this );
                        if ( answer == 1 )  // Remove
                        {
                            removeList.append( item->text() );
                        }
                        else if ( answer == 2 )  // Upgrade
                        {
                            upgradeList.append( item->text() );
                        }
                    }
                    else
                    {
                        // Remove/reinstall package
                        int answer =  PromptDlg::ask( tr( "Remove or reinstall" ),
                                      tr( QString( "Do you wish to remove or reinstall\n%1?" ).arg( item->text() ) ),
                                      tr( "Remove" ), tr( "Reinstall" ), this );
                        if ( answer == 1 )  // Remove
                        {
                            removeList.append( item->text() );
                        }
                        else if ( answer == 2 )  // Reinstall
                        {
                            installList.append( item->text() );
                        }
                    }
                }
                else
                {
                    // Install package
                    installList.append( item->text() );
                }
            }
        }
    }

    // If nothing is selected, display message and exit
    if ( removeList.isEmpty() && installList.isEmpty() && upgradeList.isEmpty() )
    {
        QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) );
        return;
    }

    // Send command only if there are packages to process
    OPackage::Command removeCmd = !removeList.isEmpty() ? OPackage::Remove
                                                        : OPackage::NotDefined;
    OPackage::Command installCmd = !installList.isEmpty() ? OPackage::Install
                                                          : OPackage::NotDefined;
    OPackage::Command upgradeCmd = !upgradeList.isEmpty() ? OPackage::Upgrade
                                                          : OPackage::NotDefined;

    // Create package manager output widget
    InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Apply changes" ),
                                      removeCmd, removeList,
                                      installCmd, installList,
                                      upgradeCmd, upgradeList );
    connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) );

    // Display widget
    m_widgetStack.addWidget( dlg, 3 );
    m_widgetStack.raiseWidget( dlg );
}
//=====================================
// XKeyboard reset and switch to Intro
//-------------------------------------
void XKeyboard::resetPage (int reload) {
	// ...
	// this function is called if the keyboard dialog is finished or canceled
	// The changes are serialized and re-imported if the user want
	// to conclude the dialog. Otherwhise the original file is imported
	// and the changes will be lost.
	// ---
	QString update = "sys_KEYBOARD";

	//=======================================
	// save primary and secondary keyboard(s)
	//---------------------------------------
	if (reload == PAGE_RELOAD) {
		QString* XkbLayout  = NULL;
		QString* XkbModel   = NULL;
		QString* XkbVariant = NULL;
		XWrapFile < QDict<XFile> > mFiles (mFilePtr);
		XWrapPointer<XData> workingKeyboard (
			mFiles["sys_KEYBOARD"]->getDevice (0)
		);
		// 1) primary XKB model
		QDictIterator<char> itModel (mModelHash);
		for (; itModel.current(); ++itModel) {
		if (QString::fromLocal8Bit(itModel.current()) == mType->currentText()) {
			XkbModel = new QString (itModel.currentKey());
		}
		}
		// 2) primary XKB layout
		QDictIterator<char> itLayout (mLayoutHash);
		for (; itLayout.current(); ++itLayout) {
		if (
			QString::fromLocal8Bit(itLayout.current()) == mLayout->currentText()
		) {
			XkbLayout = new QString (itLayout.currentKey());
		}
		}
		// 3) variant for primary XKB layout
		XkbVariant = new QString();
		if ((mVariant->currentText()) && (mVariant->currentText() != "basic")) {
			*XkbVariant = mVariant->currentText();
		}
		// 4) additional layout and variant
		QListViewItemIterator itAdd (mAddView);
		for ( ; itAdd.current(); ++itAdd ) {
			QCheckListItem* item = (QCheckListItem*)itAdd.current();
			if (item->isOn()) {
				QString layout  = itAdd.current()->text(2);
				QString variant = "!";
				XkbLayout->sprintf("%s,%s",
					XkbLayout->ascii(),layout.ascii()
				);
				if (itAdd.current()->text(3)) {
					variant = itAdd.current()->text(3);
				}
				XkbVariant->sprintf("%s,%s",
					XkbVariant->ascii(),variant.ascii()
				);
			}
		}
		if (XkbLayout) {
		workingKeyboard.setPair ("XkbLayout",
			XkbLayout->ascii()
		);
		}
		if (XkbModel) {
		workingKeyboard.setPair ("XkbModel",
			XkbModel->ascii()
		);
		}
		if ((XkbVariant) && (! XkbVariant->isEmpty())) {
		workingKeyboard.setPair ("XkbVariant",
			XkbVariant->ascii()
		);
		} else {
		workingKeyboard.setPair ("XkbVariant", "");
		}
		// 5) XkbOptions LeftAlt RightAlt ScrollLock RightCtl
		if (mKeyboardOptions["XkbOptions"]) {
		workingKeyboard.setPair (
			"XkbOptions", mKeyboardOptions["XkbOptions"]
		);
		}
		if (mKeyboardOptions["LeftAlt"]) {
		workingKeyboard.setPair (
			"LeftAlt", mKeyboardOptions["LeftAlt"]
		);
		}
		if (mKeyboardOptions["RightAlt"]) {
		workingKeyboard.setPair (
			"RightAlt", mKeyboardOptions["RightAlt"]
		);
		}
		if (mKeyboardOptions["ScrollLock"]) {
		workingKeyboard.setPair (
			"ScrollLock", mKeyboardOptions["ScrollLock"]
		);
		}
		if (mKeyboardOptions["RightCtl"]) {
		workingKeyboard.setPair (
			"RightCtl", mKeyboardOptions["RightCtl"]
		);
		}
	}

	mStatus -> clear();
	if (reload == PAGE_RELOAD) {
		mFilePtr = mIntro->getFiles();
		XWrapFile < QDict<XFile> > mFiles (mFilePtr);
        if (mFiles [update] -> sysSerialize()) {
			mFiles [update] -> isModified ( mFrame );
		}
    }
	mIntro -> importFile (update);
	slotIntro (mIndex);
	XTemplate::resetPage ();
	mStack -> raiseWidget (Intro);
}
void PreferencesDialog::accept() {
    cancelSetAccelKey();

    if( !isRevealingSequenceSelectionValid() ) {
        tab->showPage( quizPage ); 
        QMessageBox::warning( this, QObject::tr( "Warning" ), tr( "RevealingOrderMandatory" ) );
        return;
    }

    if( !isStudyLanguageSelectionValid() ) {
        tab->showPage( languagePage ); 
        QMessageBox::warning( this, QObject::tr( "Warning" ), tr( "StudyLanguagesMandatory" ) );
        return;
    }

    if( quizAlgoOriginalRadioButton->isChecked() )
        prefs->setQuizAlgorithm( Preferences::ORIGINAL );
    else if( quizAlgoSuperMemo2RadioButton->isChecked() )
        prefs->setQuizAlgorithm( Preferences::SUPERMEMO2 );

    prefs->setQuizCharacterImageLocation( quizCharacterImageLocationField->text() );
    prefs->setQuizCharacterImagesAnimated( quizCharacterImageTypeCheckbox->isOn() );
    prefs->setQuizLength( quizLengthSlider->value() );

    prefs->clearRevealingSequences();
    for( SequenceListItem* item = (SequenceListItem*)sequencesView->firstChild(); item; item = (SequenceListItem*)item->nextSibling() )
        prefs->addRevealingSequence( item->getSequence() );

    prefs->setLabelsFontFamily( labelsFontFamilyComboBox->text( labelsFontFamilyComboBox->currentItem() ) );
    int fontSizeNameListLength = sizeof( fontSizeNameList ) / sizeof( QString );
    int labelsFontSizeModifier =  labelsFontSizeComboBox->currentItem() - ( fontSizeNameListLength - 1 ) / 2;
    prefs->setLabelsFontSizeModifier( labelsFontSizeModifier );

    prefs->setFontFamily( fontFamilyComboBox->text( fontFamilyComboBox->currentItem() ) );
    int fontSizeModifier =  fontSizeComboBox->currentItem() - ( fontSizeNameListLength - 1 ) / 2;
    prefs->setFontSizeModifier( fontSizeModifier );

    prefs->clearFontOverrideFamilies();
    prefs->clearFontOverrideSizes();
    int fontOverrideCount = fontOverrideLabels.count();
    for( int i = 0; i < fontOverrideCount; i++ ) {
        const QString& language = Util::getLanguageCode( fontOverrideLabels.at( i )->text() );
        if( fontOverrideFamilyComboBoxes.at( i )->currentItem() > 0 )
            prefs->setFontOverrideFamily( language, fontOverrideFamilyComboBoxes.at( i )->currentText() );
        if( fontOverrideSizeComboBoxes.at( i )->currentItem() > 0 ) {
            int fontSizeModifier =  ( fontOverrideSizeComboBoxes.at( i )->currentItem() - 1 ) - ( fontSizeNameListLength - 1 ) / 2;
            prefs->setFontOverrideSize( language, fontSizeModifier );
        }
    }

    bool firstLanguageExists = false;
    bool testLanguageExists = false;
    prefs->clearStudyLanguages();
    for( QCheckListItem* item = (QCheckListItem*)studyLanguagesListView->firstChild(); item; item = (QCheckListItem*)item->nextSibling() ) {
        if( item->isOn() ) {
            QString langCode( Util::getLanguageCode( item->text() ) );
            prefs->addStudyLanguage( langCode );
            if( !firstLanguageExists )
                firstLanguageExists = ( prefs->getFirstLanguage() == langCode );
            if( !testLanguageExists )
                testLanguageExists = (prefs->getTestLanguage() == langCode );
        }
    }
    if( !firstLanguageExists )
        prefs->setFirstLanguage( QString::null );
    if( !testLanguageExists )
        prefs->setTestLanguage( QString::null );

    prefs->setDigraphEnabled( digraphCheckBox->isOn() );
    prefs->setQuizButtonsHidden( hideQuizButtonCheckBox->isOn() );
    prefs->setAltInTermListShown( showAltTextInTermListCheckBox->isOn() );

    if( keyboardAccelModified ) {
        for( KeyActionListViewItem* item = (KeyActionListViewItem*)keyboardAccelListView->firstChild(); item ; 
            item = (KeyActionListViewItem*)item->nextSibling() ) {
            QAction *action = item->getAction();
            action->setAccel( item->getKey() );
            prefs->setAccelerator( item->getActionIndex(), item->getKey() );
        }
    }

    QDialog::accept();
}