void QuizFrame::editCurrentTerm() { if( controller->isQuizInProgress() ) { Folder* vocabTree = controller->getVocabTree(); Term* term = controller->getCurrentTerm(); if( !term ) { QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) ); return; } Vocabulary* vocab = vocabTree->getVocabulary( term->getVocabId() ); if( vocab == NULL || !vocab->isTermExists( term->getId() ) ) { QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) ); return; } TermDialog dialog( *vocab, controller, this, *term ); int result = dialog.exec(); if( result ) { QString firstLang( controller->getQuizFirstLanguage() ); QString testLang( controller->getQuizTestLanguage() ); Term newTerm = dialog.getTerm(); Translation firstLangTrans = newTerm.getTranslation( firstLang ); Translation testLangTrans = newTerm.getTranslation( testLang ); term->addTranslation( firstLangTrans ); term->addTranslation( testLangTrans ); BilingualKey commentKey( firstLang, testLang ); term->addComment( commentKey, newTerm.getComment( commentKey ) ); term->setImagePath( newTerm.getImagePath() ); vocab->setModificationDate( QDateTime::currentDateTime() ); vocab->setDirty( true ); setTerm( newTerm ); } } }
void SearchDialog::editResultTerm() { ResultListItem* currItem = (ResultListItem*)resultsListView->currentItem(); if( currItem ) { Term* term = currItem->getTerm(); if( term ) { Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() ); TermDialog dialog( *vocab, controller, this, *term ); #if defined(Q_WS_HILDON) dialog.showFullScreen(); #endif int result = dialog.exec(); if( result ) { Term newTerm = dialog.getTerm(); term->addTranslation( newTerm.getTranslation( controller->getPreferences().getFirstLanguage() ) ); term->addTranslation( newTerm.getTranslation( controller->getPreferences().getTestLanguage() ) ); BilingualKey commentKey( controller->getPreferences().getFirstLanguage(), controller->getPreferences().getTestLanguage() ); term->addComment( commentKey, newTerm.getComment( commentKey ) ); term->setImagePath( newTerm.getImagePath() ); currItem->updateUi(); vocab->setModificationDate( QDateTime::currentDateTime() ); vocab->setDirty( true ); } } } }
void QuizFrame::setTerm( const Term& term ) { Translation firstLangTranslation = term.getTranslation( controller->getQuizFirstLanguage() ); Translation testLangTranslation = term.getTranslation( controller->getQuizTestLanguage() ); const QString firstLangWord = firstLangTranslation.getWord(); const QString testLangAlt = testLangTranslation.getAlt(); const QString testLangWord = testLangTranslation.getWord(); QString comment; BilingualKey commentKey( controller->getQuizFirstLanguage(), controller->getQuizTestLanguage() ); if( term.isCommentExists( commentKey ) ) comment = term.getComment( commentKey ); firstLangTermLineEdit->setText( firstLangWord ); firstLangTermLineEdit->setCursorPosition( 0 ); testLangTermAltLineEdit->setText( testLangAlt ); testLangTermAltLineEdit->setCursorPosition( 0 ); testLangTermLineEdit->setText( testLangWord ); testLangTermLineEdit->setCursorPosition( 0 ); commentMultiLineEdit->setText( comment ); Folder* vocabTree = controller->getVocabTree(); Vocabulary* vocab = vocabTree->getVocabulary( term.getVocabId() ); if( vocab ) { QString absPath = controller->getResolvedImagePath( term.getImagePath(), *vocab ); setImage( absPath ); } }
void SearchDialog::doRemoveTerms( bool allowSelectTrans /* = true */, bool confirmBeforeRemove /* = true */ ) { int selectedItemCount = 0; // Find all the translation languages of the selected terms. QStringList translationLanguages; for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) { ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i ); if( termItem->isSelected() ) { selectedItemCount++; Term* term = termItem->getTerm(); for( Term::TranslationMap::ConstIterator it = term->translationsBegin(); it != term->translationsEnd(); it++ ) { const Translation& trans = *it; if( !translationLanguages.contains( trans.getLanguage() ) ) translationLanguages.append( trans.getLanguage() ); } } } if( selectedItemCount == 0 ) return; if( translationLanguages.count() <= 2 ) { int response; if( confirmBeforeRemove ) { QMessageBox msgBox( QObject::tr( "Warning" ), tr( "ConfirmRemoveSelectedTerms" ), QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this ); msgBox.setButtonText( QMessageBox::Yes, tr( "Yes" ) ); msgBox.setButtonText( QMessageBox::No, tr( "No" ) ); response = msgBox.exec(); } else response = QMessageBox::Yes; if( response == QMessageBox::Yes ) { for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) { ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i ); if( termItem->isSelected() ) { Term* term = termItem->getTerm(); Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() ); if( !term->getImagePath().isNull() ) { QDir imagePath( term->getImagePath() ); if( imagePath.isRelative() ) { const QString& imagePath = controller->getApplicationDirName() + "/" + vocab->getParent()->getPath() + "/v-" + QString::number( vocab->getId() ) + "/" + term->getImagePath(); QFile imageFile( imagePath ); if( imageFile.exists() ) { if( !imageFile.remove() ) cerr << "Could not remove image " << qPrintable( imagePath ) << endl; } } } vocab->removeTerm( term->getId() ); delete( termItem ); vocab->setModificationDate( QDateTime::currentDateTime() ); vocab->setDirty( true ); } } resultsListView->clearSelection(); updateUi(); emit termsRemoved(); } } else { int response; QStringList selectedLanguages; if( allowSelectTrans ) { TranslationSelectionDialog msgBox( tr( "MultipleTranslationsDetectedForRemoveTermsCaption" ), tr( "MultipleTranslationsDetectedForRemoveTerms" ), translationLanguages, TranslationSelectionDialog::selectionModeTargetLanguage, controller, this ); msgBox.setMaximumHeight( size().height() - 40 ); msgBox.setMaximumWidth( size().width() - 40 ); response = msgBox.exec(); if( response ) selectedLanguages = msgBox.getSelectedLanguages(); } else { selectedLanguages = QStringList(); selectedLanguages.append( controller->getPreferences().getFirstLanguage() ); selectedLanguages.append( controller->getPreferences().getTestLanguage() ); } if( selectedLanguages.count() == 0 ) return; for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) { ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i ); if( termItem->isSelected() ) { Term* term = termItem->getTerm(); Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() ); for( QStringList::ConstIterator it = selectedLanguages.begin(); it != selectedLanguages.end(); it++ ) { QString lang = *it; term->removeTranslation( lang ); } if( term->getTranslationCount() == 0 ) { if( !term->getImagePath().isNull() ) { QDir imagePath( term->getImagePath() ); if( imagePath.isRelative() ) { const QString& imagePath = controller->getApplicationDirName() + "/" + vocab->getParent()->getPath() + "/v-" + QString::number( vocab->getId() ) + "/" + term->getImagePath(); QFile imageFile( imagePath ); if( imageFile.exists() ) { if( !imageFile.remove() ) cerr << "Could not remove image " << qPrintable( imagePath ) << endl; } } } vocab->removeTerm( term->getId() ); delete( termItem ); vocab->setModificationDate( QDateTime::currentDateTime() ); vocab->setDirty( true ); } } } resultsListView->clearSelection(); updateUi(); } }