2014-02-28 12:36:28 +00:00
|
|
|
/* This file is (c) 2014 Abs62
|
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "dictheadwords.hh"
|
|
|
|
#include "gddebug.hh"
|
2023-05-27 09:50:41 +00:00
|
|
|
#include "headwordsmodel.hh"
|
2014-02-28 12:36:28 +00:00
|
|
|
|
|
|
|
#include <QRegExp>
|
2022-02-27 05:17:37 +00:00
|
|
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
|
|
|
#include <QtCore5Compat>
|
|
|
|
#endif
|
2014-02-28 12:36:28 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QProgressDialog>
|
|
|
|
|
2019-03-25 15:08:52 +00:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include "wildcard.hh"
|
2023-04-22 00:43:50 +00:00
|
|
|
#include "help.hh"
|
2022-12-31 06:01:48 +00:00
|
|
|
#include <QMessageBox>
|
2023-04-22 04:03:53 +00:00
|
|
|
#include <QMutexLocker>
|
2023-05-27 09:50:41 +00:00
|
|
|
#include <memory>
|
2019-03-25 15:08:52 +00:00
|
|
|
|
2014-02-28 12:36:28 +00:00
|
|
|
#define AUTO_APPLY_LIMIT 150000
|
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
DictHeadwords::DictHeadwords( QWidget * parent, Config::Class & cfg_, Dictionary::Class * dict_ ):
|
|
|
|
QDialog( parent ),
|
|
|
|
cfg( cfg_ ),
|
|
|
|
dict( dict_ ),
|
|
|
|
helpAction( this )
|
2014-02-28 12:36:28 +00:00
|
|
|
{
|
|
|
|
ui.setupUi( this );
|
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
const bool fromMainWindow = parent->objectName() == "MainWindow";
|
2015-03-23 15:58:49 +00:00
|
|
|
|
|
|
|
if ( fromMainWindow )
|
|
|
|
setAttribute( Qt::WA_DeleteOnClose, false );
|
|
|
|
|
2014-03-03 13:46:41 +00:00
|
|
|
setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2019-03-19 14:36:07 +00:00
|
|
|
if ( cfg.headwordsDialog.headwordsDialogGeometry.size() > 0 )
|
|
|
|
restoreGeometry( cfg.headwordsDialog.headwordsDialogGeometry );
|
|
|
|
|
2014-02-28 12:36:28 +00:00
|
|
|
ui.searchModeCombo->addItem( tr( "Text" ), QRegExp::FixedString );
|
2014-03-14 12:38:59 +00:00
|
|
|
ui.searchModeCombo->addItem( tr( "Wildcards" ), QRegExp::WildcardUnix );
|
2014-02-28 12:36:28 +00:00
|
|
|
ui.searchModeCombo->addItem( tr( "RegExp" ), QRegExp::RegExp );
|
|
|
|
ui.searchModeCombo->setCurrentIndex( cfg.headwordsDialog.searchMode );
|
|
|
|
|
|
|
|
ui.exportButton->setAutoDefault( false );
|
|
|
|
ui.OKButton->setAutoDefault( false );
|
|
|
|
ui.applyButton->setAutoDefault( true );
|
|
|
|
ui.applyButton->setDefault( true );
|
|
|
|
|
|
|
|
ui.matchCase->setChecked( cfg.headwordsDialog.matchCase );
|
|
|
|
|
2023-05-27 09:50:41 +00:00
|
|
|
model = std::make_shared< HeadwordListModel >();
|
2014-02-28 12:36:28 +00:00
|
|
|
proxy = new QSortFilterProxyModel( this );
|
|
|
|
|
2023-05-27 09:50:41 +00:00
|
|
|
proxy->setSourceModel( model.get() );
|
2014-03-01 13:41:05 +00:00
|
|
|
|
|
|
|
proxy->setSortCaseSensitivity( Qt::CaseInsensitive );
|
|
|
|
proxy->setSortLocaleAware( true );
|
2014-03-18 13:44:41 +00:00
|
|
|
proxy->setDynamicSortFilter( false );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
|
|
|
ui.headersListView->setModel( proxy );
|
2014-03-01 13:11:14 +00:00
|
|
|
ui.headersListView->setEditTriggers( QAbstractItemView::NoEditTriggers );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
|
|
|
// very important call, for performance reasons:
|
|
|
|
ui.headersListView->setUniformItemSizes( true );
|
|
|
|
|
|
|
|
delegate = new WordListItemDelegate( ui.headersListView->itemDelegate() );
|
|
|
|
if ( delegate )
|
|
|
|
ui.headersListView->setItemDelegate( delegate );
|
|
|
|
|
2014-03-14 12:38:59 +00:00
|
|
|
ui.autoApply->setChecked( cfg.headwordsDialog.autoApply );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( this, &QDialog::finished, this, &DictHeadwords::savePos );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2015-03-23 15:58:49 +00:00
|
|
|
if ( !fromMainWindow ) {
|
|
|
|
ui.helpButton->hide();
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( this, &DictHeadwords::closeDialog, this, &QDialog::accept );
|
2015-03-23 15:58:49 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
helpAction.setShortcut( QKeySequence( "F1" ) );
|
|
|
|
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
|
2023-04-17 02:23:39 +00:00
|
|
|
connect( ui.helpButton, &QAbstractButton::clicked, &helpAction, &QAction::trigger );
|
|
|
|
connect( &helpAction, &QAction::triggered, []() {
|
2023-04-22 00:43:50 +00:00
|
|
|
Help::openHelpWebpage( Help::section::ui_headwords );
|
2023-04-17 02:23:39 +00:00
|
|
|
} );
|
2015-03-23 15:58:49 +00:00
|
|
|
|
|
|
|
addAction( &helpAction );
|
|
|
|
}
|
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( ui.OKButton, &QAbstractButton::clicked, this, &DictHeadwords::okButtonClicked );
|
|
|
|
connect( ui.exportButton, &QAbstractButton::clicked, this, &DictHeadwords::exportButtonClicked );
|
|
|
|
connect( ui.applyButton, &QAbstractButton::clicked, this, &DictHeadwords::filterChanged );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( ui.autoApply, &QCheckBox::stateChanged, this, &DictHeadwords::autoApplyStateChanged );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( ui.filterLine, &QLineEdit::textChanged, this, &DictHeadwords::filterChangedInternal );
|
|
|
|
connect( ui.searchModeCombo, &QComboBox::currentIndexChanged, this, &DictHeadwords::filterChangedInternal );
|
|
|
|
connect( ui.matchCase, &QCheckBox::stateChanged, this, &DictHeadwords::filterChangedInternal );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( ui.headersListView, &QAbstractItemView::clicked, this, &DictHeadwords::itemClicked );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( proxy, &QAbstractItemModel::dataChanged, this, &DictHeadwords::showHeadwordsNumber );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2014-03-04 17:38:47 +00:00
|
|
|
ui.headersListView->installEventFilter( this );
|
|
|
|
|
2014-03-03 13:46:41 +00:00
|
|
|
setup( dict_ );
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DictHeadwords::~DictHeadwords()
|
|
|
|
{
|
|
|
|
if ( delegate )
|
2019-03-20 14:49:39 +00:00
|
|
|
delegate->deleteLater();
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 13:46:41 +00:00
|
|
|
void DictHeadwords::setup( Dictionary::Class * dict_ )
|
|
|
|
{
|
|
|
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
|
|
|
|
|
|
|
dict = dict_;
|
|
|
|
|
|
|
|
setWindowTitle( QString::fromUtf8( dict->getName().c_str() ) );
|
|
|
|
|
2023-05-27 09:50:41 +00:00
|
|
|
const auto size = dict->getWordCount();
|
|
|
|
std::shared_ptr< HeadwordListModel > other = std::make_shared< HeadwordListModel >();
|
|
|
|
model.swap( other );
|
|
|
|
model->setDict( dict );
|
|
|
|
proxy->setSourceModel( model.get() );
|
2014-03-03 13:46:41 +00:00
|
|
|
proxy->sort( 0 );
|
|
|
|
filterChanged();
|
|
|
|
|
2023-05-27 09:50:41 +00:00
|
|
|
if ( size > AUTO_APPLY_LIMIT ) {
|
2014-03-14 12:38:59 +00:00
|
|
|
cfg.headwordsDialog.autoApply = ui.autoApply->isChecked();
|
|
|
|
ui.autoApply->setChecked( false );
|
|
|
|
ui.autoApply->setEnabled( false );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui.autoApply->setEnabled( true );
|
|
|
|
ui.autoApply->setChecked( cfg.headwordsDialog.autoApply );
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.applyButton->setEnabled( !ui.autoApply->isChecked() );
|
|
|
|
|
2014-11-14 16:45:06 +00:00
|
|
|
setWindowIcon( dict->getIcon() );
|
|
|
|
|
2014-11-17 14:37:19 +00:00
|
|
|
dictId = QString( dict->getId().c_str() );
|
|
|
|
|
2014-03-03 13:46:41 +00:00
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::savePos()
|
2014-02-28 12:36:28 +00:00
|
|
|
{
|
|
|
|
cfg.headwordsDialog.searchMode = ui.searchModeCombo->currentIndex();
|
|
|
|
cfg.headwordsDialog.matchCase = ui.matchCase->isChecked();
|
|
|
|
|
2022-09-19 14:19:22 +00:00
|
|
|
if ( model->totalCount() <= AUTO_APPLY_LIMIT )
|
2014-02-28 12:36:28 +00:00
|
|
|
cfg.headwordsDialog.autoApply = ui.autoApply->isChecked();
|
|
|
|
|
|
|
|
cfg.headwordsDialog.headwordsDialogGeometry = saveGeometry();
|
|
|
|
}
|
|
|
|
|
2014-03-04 17:38:47 +00:00
|
|
|
bool DictHeadwords::eventFilter( QObject * obj, QEvent * ev )
|
|
|
|
{
|
|
|
|
if ( obj == ui.headersListView && ev->type() == QEvent::KeyPress ) {
|
|
|
|
QKeyEvent * kev = static_cast< QKeyEvent * >( ev );
|
|
|
|
if ( kev->key() == Qt::Key_Return || kev->key() == Qt::Key_Enter ) {
|
|
|
|
itemClicked( ui.headersListView->currentIndex() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QDialog::eventFilter( obj, ev );
|
|
|
|
}
|
|
|
|
|
2014-02-28 12:36:28 +00:00
|
|
|
void DictHeadwords::okButtonClicked()
|
|
|
|
{
|
2014-03-03 13:46:41 +00:00
|
|
|
savePos();
|
2023-04-22 04:03:53 +00:00
|
|
|
emit closeDialog();
|
2014-03-03 13:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::reject()
|
|
|
|
{
|
|
|
|
savePos();
|
2023-04-22 04:03:53 +00:00
|
|
|
emit closeDialog();
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::exportButtonClicked()
|
|
|
|
{
|
|
|
|
saveHeadersToFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::filterChangedInternal()
|
|
|
|
{
|
|
|
|
// emit signal in async manner, to avoid UI slowdown
|
|
|
|
if ( ui.autoApply->isChecked() )
|
2022-12-26 02:08:17 +00:00
|
|
|
QTimer::singleShot( 100, this, &DictHeadwords::filterChanged );
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
2023-04-22 05:32:10 +00:00
|
|
|
QRegularExpression DictHeadwords::getFilterRegex() const
|
2014-02-28 12:36:28 +00:00
|
|
|
{
|
2023-04-22 04:03:53 +00:00
|
|
|
const QRegExp::PatternSyntax syntax =
|
|
|
|
static_cast< QRegExp::PatternSyntax >( ui.searchModeCombo->itemData( ui.searchModeCombo->currentIndex() ).toInt() );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2019-03-25 15:08:52 +00:00
|
|
|
QRegularExpression::PatternOptions options = QRegularExpression::UseUnicodePropertiesOption;
|
|
|
|
if ( !ui.matchCase->isChecked() )
|
|
|
|
options |= QRegularExpression::CaseInsensitiveOption;
|
|
|
|
|
|
|
|
QString pattern;
|
|
|
|
switch ( syntax ) {
|
2023-04-22 04:03:53 +00:00
|
|
|
case QRegExp::FixedString:
|
|
|
|
pattern = QRegularExpression::escape( ui.filterLine->text() );
|
|
|
|
break;
|
|
|
|
case QRegExp::WildcardUnix:
|
|
|
|
pattern = wildcardsToRegexp( ui.filterLine->text() );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pattern = ui.filterLine->text();
|
|
|
|
break;
|
2019-03-25 15:08:52 +00:00
|
|
|
}
|
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
QRegularExpression regExp = QRegularExpression( pattern, options );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2019-03-25 15:08:52 +00:00
|
|
|
if ( !regExp.isValid() ) {
|
|
|
|
gdWarning( "Invalid regexp pattern: %s\n", pattern.toUtf8().data() );
|
|
|
|
}
|
2023-04-22 04:03:53 +00:00
|
|
|
return regExp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::filterChanged()
|
|
|
|
{
|
2023-04-22 09:04:03 +00:00
|
|
|
const QRegularExpression regExp = getFilterRegex();
|
2019-03-25 15:08:52 +00:00
|
|
|
|
|
|
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
if ( sortedWords.isEmpty() && regExp.isValid() && !regExp.pattern().isEmpty() ) {
|
|
|
|
const int headwordsNumber = model->totalCount();
|
|
|
|
|
|
|
|
QProgressDialog progress( tr( "Loading headwords..." ), tr( "Cancel" ), 0, headwordsNumber, this );
|
|
|
|
progress.setWindowModality( Qt::WindowModal );
|
|
|
|
loadAllSortedWords( progress );
|
|
|
|
progress.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto filtered = sortedWords.filter( regExp );
|
2023-04-22 09:04:03 +00:00
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
model->addMatches( filtered );
|
2022-05-05 12:59:50 +00:00
|
|
|
|
2022-09-19 14:19:22 +00:00
|
|
|
proxy->setFilterRegularExpression( regExp );
|
2014-03-18 13:44:41 +00:00
|
|
|
proxy->sort( 0 );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2014-03-01 18:43:31 +00:00
|
|
|
QApplication::restoreOverrideCursor();
|
2014-02-28 12:36:28 +00:00
|
|
|
|
|
|
|
showHeadwordsNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::itemClicked( const QModelIndex & index )
|
|
|
|
{
|
|
|
|
QVariant value = proxy->data( index, Qt::DisplayRole );
|
|
|
|
if ( value.canConvert< QString >() ) {
|
2014-03-17 17:23:36 +00:00
|
|
|
QString headword = value.toString();
|
2014-11-17 14:37:19 +00:00
|
|
|
emit headwordSelected( headword, dictId );
|
2014-03-17 17:23:36 +00:00
|
|
|
}
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::autoApplyStateChanged( int state )
|
|
|
|
{
|
|
|
|
ui.applyButton->setEnabled( state == Qt::Unchecked );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictHeadwords::showHeadwordsNumber()
|
|
|
|
{
|
|
|
|
ui.headersNumber->setText( tr( "Unique headwords total: %1, filtered: %2" )
|
2022-09-19 14:19:22 +00:00
|
|
|
.arg( QString::number( model->totalCount() ), QString::number( proxy->rowCount() ) ) );
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
// TODO , the ui and the code mixed together , this is not the right way to do this. need future refactor
|
|
|
|
void DictHeadwords::loadAllSortedWords( QProgressDialog & progress )
|
|
|
|
{
|
|
|
|
const int headwordsNumber = model->totalCount();
|
|
|
|
|
|
|
|
QMutexLocker _( &mutex );
|
|
|
|
if ( sortedWords.isEmpty() ) {
|
|
|
|
QSet< QString > allHeadwords;
|
|
|
|
|
|
|
|
int totalCount = 0;
|
|
|
|
for ( int i = 0; i < headwordsNumber && i < model->wordCount(); ++i ) {
|
|
|
|
if ( progress.wasCanceled() )
|
|
|
|
break;
|
|
|
|
progress.setValue( totalCount++ );
|
|
|
|
|
|
|
|
QVariant value = model->getRow( i );
|
|
|
|
if ( !value.canConvert< QString >() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
allHeadwords.insert( value.toString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// continue to write the remaining headword
|
|
|
|
int nodeIndex = model->getCurrentIndex();
|
|
|
|
auto headwords = model->getRemainRows( nodeIndex );
|
|
|
|
while ( !headwords.isEmpty() ) {
|
|
|
|
if ( progress.wasCanceled() )
|
|
|
|
break;
|
|
|
|
allHeadwords.unite( headwords );
|
|
|
|
|
|
|
|
totalCount += headwords.size();
|
|
|
|
progress.setValue( totalCount );
|
|
|
|
|
|
|
|
headwords = model->getRemainRows( nodeIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
sortedWords = allHeadwords.values();
|
|
|
|
sortedWords.sort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 12:36:28 +00:00
|
|
|
void DictHeadwords::saveHeadersToFile()
|
|
|
|
{
|
|
|
|
QString exportPath;
|
|
|
|
if ( cfg.headwordsDialog.headwordsExportPath.isEmpty() )
|
|
|
|
exportPath = QDir::homePath();
|
|
|
|
else {
|
|
|
|
exportPath = QDir::fromNativeSeparators( cfg.headwordsDialog.headwordsExportPath );
|
|
|
|
if ( !QDir( exportPath ).exists() )
|
|
|
|
exportPath = QDir::homePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName( this,
|
|
|
|
tr( "Save headwords to file" ),
|
|
|
|
exportPath,
|
|
|
|
tr( "Text files (*.txt);;All files (*.*)" ) );
|
|
|
|
if ( fileName.size() == 0 )
|
|
|
|
return;
|
|
|
|
|
2022-12-31 06:01:48 +00:00
|
|
|
QFile file( fileName );
|
|
|
|
|
|
|
|
if ( !file.open( QFile::WriteOnly | QIODevice::Text ) ) {
|
|
|
|
QMessageBox::critical( this, "GoldenDict", tr( "Can not open exported file" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-28 12:36:28 +00:00
|
|
|
cfg.headwordsDialog.headwordsExportPath =
|
|
|
|
QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() );
|
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
const int headwordsNumber = model->totalCount();
|
2022-12-31 06:01:48 +00:00
|
|
|
|
|
|
|
QProgressDialog progress( tr( "Export headwords..." ), tr( "Cancel" ), 0, headwordsNumber * 2, this );
|
|
|
|
progress.setWindowModality( Qt::WindowModal );
|
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
loadAllSortedWords( progress );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2022-12-31 06:01:48 +00:00
|
|
|
// Write UTF-8 BOM
|
2023-04-22 04:42:10 +00:00
|
|
|
QTextStream out( &file );
|
|
|
|
out.setGenerateByteOrderMark( true );
|
|
|
|
//qt 6 will use utf-8 default.
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
|
|
|
out.setCodec( "UTF-8" );
|
|
|
|
#endif
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
QStringList filtered;
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2023-04-22 05:32:10 +00:00
|
|
|
if ( const QRegularExpression regExp = getFilterRegex(); regExp.isValid() && !regExp.pattern().isEmpty() ) {
|
2023-04-22 04:03:53 +00:00
|
|
|
filtered = sortedWords.filter( regExp );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
filtered = sortedWords;
|
|
|
|
}
|
|
|
|
auto currentValue = progress.value();
|
2022-12-31 06:01:48 +00:00
|
|
|
// Write headwords
|
2023-04-22 04:03:53 +00:00
|
|
|
for ( auto const & word : filtered ) {
|
2022-12-31 06:01:48 +00:00
|
|
|
if ( progress.wasCanceled() )
|
|
|
|
break;
|
2023-04-22 04:03:53 +00:00
|
|
|
progress.setValue( currentValue++ );
|
2023-04-22 04:42:10 +00:00
|
|
|
QByteArray line = word.toUtf8();
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2023-04-22 04:42:10 +00:00
|
|
|
//usually the headword should not contain \r \n;
|
2022-12-31 06:01:48 +00:00
|
|
|
line.replace( '\n', ' ' );
|
|
|
|
line.replace( '\r', ' ' );
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2023-04-22 04:42:10 +00:00
|
|
|
//write one line
|
|
|
|
out << line << Qt::endl;
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
2022-12-31 06:01:48 +00:00
|
|
|
|
2023-04-22 04:03:53 +00:00
|
|
|
progress.setValue( progress.maximum() );
|
2022-12-31 06:01:48 +00:00
|
|
|
if ( progress.wasCanceled() ) {
|
|
|
|
QMessageBox::warning( this, "GoldenDict", tr( "Export process is interrupted" ) );
|
|
|
|
gdWarning( "Headers export error: %s", file.errorString().toUtf8().data() );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//completed.
|
|
|
|
progress.setValue( headwordsNumber * 2 );
|
2023-04-22 04:03:53 +00:00
|
|
|
progress.close();
|
2022-12-31 06:01:48 +00:00
|
|
|
QMessageBox::information( this, "GoldenDict", tr( "Export finished" ) );
|
|
|
|
}
|
2014-02-28 12:36:28 +00:00
|
|
|
}
|