From d33c1fb34a7d736bfacc17d4b4602478c77514e1 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 10 Sep 2012 22:00:29 +0400 Subject: [PATCH] Store path for history export/import --- config.cc | 10 ++++++++++ config.hh | 1 + mainwindow.cc | 26 ++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/config.cc b/config.cc index dd1c8b89..328ffba5 100644 --- a/config.cc +++ b/config.cc @@ -648,6 +648,9 @@ Class load() throw( exError ) if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() ) c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt() ; + + if ( !preferences.namedItem( "historyExportPath" ).isNull() ) + c.preferences.historyExportPath = preferences.namedItem( "historyExportPath" ).toElement().text(); } c.lastMainGroupId = root.namedItem( "lastMainGroupId" ).toElement().text().toUInt(); @@ -1206,6 +1209,13 @@ void save( Class const & c ) throw( exError ) opt = dd.createElement( "maxStringsInHistory" ); opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) ); preferences.appendChild( opt ); + + if( !c.preferences.historyExportPath.isEmpty() ) + { + opt = dd.createElement( "historyExportPath" ); + opt.appendChild( dd.createTextNode( c.preferences.historyExportPath ) ); + preferences.appendChild( opt ); + } } { diff --git a/config.hh b/config.hh index de967dda..296dc378 100644 --- a/config.hh +++ b/config.hh @@ -181,6 +181,7 @@ struct Preferences int wordsZoomLevel; unsigned maxStringsInHistory; + QString historyExportPath; Preferences(); }; diff --git a/mainwindow.cc b/mainwindow.cc index 4ba229ba..f6dc7f45 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -2683,12 +2683,23 @@ static bool needHideSearchPane; void MainWindow::on_exportHistory_activated() { + QString exportPath; + if( cfg.preferences.historyExportPath.isEmpty() ) + exportPath = QDir::homePath(); + else + { + exportPath = QDir::fromNativeSeparators( cfg.preferences.historyExportPath ); + if( !QDir( exportPath ).exists() ) + exportPath = QDir::homePath(); + } + QString fileName = QFileDialog::getSaveFileName( this, tr( "Export history to file" ), - QDir::homePath(), + exportPath, tr( "Text files (*.txt);;All files (*.*)" ) ); if( fileName.size() == 0) return; + cfg.preferences.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() ); QFile file( fileName ); for(;;) @@ -2733,12 +2744,23 @@ void MainWindow::on_exportHistory_activated() void MainWindow::on_importHistory_activated() { + QString importPath; + if( cfg.preferences.historyExportPath.isEmpty() ) + importPath = QDir::homePath(); + else + { + importPath = QDir::fromNativeSeparators( cfg.preferences.historyExportPath ); + if( !QDir( importPath ).exists() ) + importPath = QDir::homePath(); + } + QString fileName = QFileDialog::getOpenFileName( this, tr( "Import history from file" ), - QDir::homePath(), + importPath, tr( "Text files (*.txt);;All files (*.*)" ) ); if( fileName.size() == 0) return; + cfg.preferences.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() ); QString errStr; QFile file( fileName );