mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Use the native OS dialog to save articles, store the save location in a config
This commit is contained in:
parent
a16e77af43
commit
ce4a212155
10
config.cc
10
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 );
|
||||
|
|
|
@ -405,6 +405,7 @@ struct Class
|
|||
|
||||
QString historyExportPath; // Path for export/import history
|
||||
QString resourceSavePath; // Path to save images/audio
|
||||
QString articleSavePath; // Path to save articles
|
||||
|
||||
bool pinPopupWindow; // Last pin status
|
||||
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue