Use the native OS dialog to save articles, store the save location in a config

This commit is contained in:
Tvangeste 2013-04-12 08:57:41 +02:00
parent a16e77af43
commit ce4a212155
3 changed files with 34 additions and 10 deletions

View file

@ -780,6 +780,9 @@ Class load() throw( exError )
if ( !root.namedItem( "resourceSavePath" ).isNull() ) if ( !root.namedItem( "resourceSavePath" ).isNull() )
c.resourceSavePath = root.namedItem( "resourceSavePath" ).toElement().text(); c.resourceSavePath = root.namedItem( "resourceSavePath" ).toElement().text();
if ( !root.namedItem( "articleSavePath" ).isNull() )
c.articleSavePath = root.namedItem( "articleSavePath" ).toElement().text();
if ( !root.namedItem( "editDictionaryCommandLine" ).isNull() ) if ( !root.namedItem( "editDictionaryCommandLine" ).isNull() )
c.editDictionaryCommandLine = root.namedItem( "editDictionaryCommandLine" ).toElement().text(); c.editDictionaryCommandLine = root.namedItem( "editDictionaryCommandLine" ).toElement().text();
@ -1480,6 +1483,13 @@ void save( Class const & c ) throw( exError )
root.appendChild( opt ); 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 = dd.createElement( "editDictionaryCommandLine" );
opt.appendChild( dd.createTextNode( c.editDictionaryCommandLine ) ); opt.appendChild( dd.createTextNode( c.editDictionaryCommandLine ) );
root.appendChild( opt ); root.appendChild( opt );

View file

@ -404,7 +404,8 @@ struct Class
QByteArray dictInfoGeometry; // Geometry of "Dictionary info" window QByteArray dictInfoGeometry; // Geometry of "Dictionary info" window
QString historyExportPath; // Path for export/import history 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 bool pinPopupWindow; // Last pin status

View file

@ -2876,25 +2876,38 @@ void MainWindow::on_saveArticle_triggered()
{ {
ArticleView *view = getCurrentArticleView(); 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 ); if ( cfg.articleSavePath.isEmpty() )
savePath = QDir::homePath();
fileDialog.setDefaultSuffix( "html" ); else
{
fileDialog.selectFile( view->getTitle() + ".html" ); savePath = QDir::fromNativeSeparators( cfg.articleSavePath );
if ( !QDir( savePath ).exists() )
if ( fileDialog.exec() && fileDialog.selectedFiles().size() == 1 ) 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 ); QFile file( fileName );
if ( !file.open( QIODevice::WriteOnly ) ) if ( !file.open( QIODevice::WriteOnly ) )
{
QMessageBox::critical( this, tr( "Error" ), QMessageBox::critical( this, tr( "Error" ),
tr( "Can't save article: %1" ).arg( file.errorString() ) ); tr( "Can't save article: %1" ).arg( file.errorString() ) );
}
else else
{
file.write( view->toHtml().toUtf8() ); file.write( view->toHtml().toUtf8() );
cfg.articleSavePath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() );
}
} }
} }