diff --git a/config.cc b/config.cc index 2d45a9e3..6482a929 100644 --- a/config.cc +++ b/config.cc @@ -780,6 +780,9 @@ Class load() throw( exError ) if ( !root.namedItem( "resourceSavePath" ).isNull() ) c.resourceSavePath = root.namedItem( "resourceSavePath" ).toElement().text(); + if ( !root.namedItem( "articleSavePath" ).isNull() ) + c.articleSavePath = root.namedItem( "articleSavePath" ).toElement().text(); + if ( !root.namedItem( "editDictionaryCommandLine" ).isNull() ) c.editDictionaryCommandLine = root.namedItem( "editDictionaryCommandLine" ).toElement().text(); @@ -1480,6 +1483,13 @@ void save( Class const & c ) throw( exError ) root.appendChild( opt ); } + if( !c.articleSavePath.isEmpty() ) + { + opt = dd.createElement( "articleSavePath" ); + opt.appendChild( dd.createTextNode( c.articleSavePath ) ); + root.appendChild( opt ); + } + opt = dd.createElement( "editDictionaryCommandLine" ); opt.appendChild( dd.createTextNode( c.editDictionaryCommandLine ) ); root.appendChild( opt ); diff --git a/config.hh b/config.hh index 02e2b59b..1b6c555c 100644 --- a/config.hh +++ b/config.hh @@ -404,7 +404,8 @@ struct Class QByteArray dictInfoGeometry; // Geometry of "Dictionary info" window QString historyExportPath; // Path for export/import history - QString resourceSavePath; // Path to save images/audio + QString resourceSavePath; // Path to save images/audio + QString articleSavePath; // Path to save articles bool pinPopupWindow; // Last pin status diff --git a/mainwindow.cc b/mainwindow.cc index 130fa445..8a96cb87 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -2876,25 +2876,38 @@ void MainWindow::on_saveArticle_triggered() { ArticleView *view = getCurrentArticleView(); - QFileDialog fileDialog( this, tr( "Save Article As" ), QString(), tr( "Html files (*.html *.htm)" ) ); + QString fileName = view->getTitle() + ".html"; + QString savePath; - fileDialog.setAcceptMode( QFileDialog::AcceptSave ); - - fileDialog.setDefaultSuffix( "html" ); - - fileDialog.selectFile( view->getTitle() + ".html" ); - - if ( fileDialog.exec() && fileDialog.selectedFiles().size() == 1 ) + if ( cfg.articleSavePath.isEmpty() ) + savePath = QDir::homePath(); + else + { + savePath = QDir::fromNativeSeparators( cfg.articleSavePath ); + if ( !QDir( savePath ).exists() ) + savePath = QDir::homePath(); + } + + fileName = savePath + "/" + fileName; + fileName = QFileDialog::getSaveFileName( this, tr( "Save Article As" ), + fileName, + tr( "Html files (*.html *.htm)" ) ); + + if ( !fileName.isEmpty() ) { - QString fileName = fileDialog.selectedFiles().front(); QFile file( fileName ); if ( !file.open( QIODevice::WriteOnly ) ) + { QMessageBox::critical( this, tr( "Error" ), tr( "Can't save article: %1" ).arg( file.errorString() ) ); + } else + { file.write( view->toHtml().toUtf8() ); + cfg.articleSavePath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() ); + } } }