summaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-11-14 13:42:26 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-15 09:13:58 +0900
commitb28237309a5fd3af527d71fe0d4dfada7a11107c (patch)
treedcd55814792d99e5c5abeea2a2da2e02cf594fcd /qt-ui/mainwindow.cpp
parente2a4da767d13a6ab4c4f2e10400823e5708c40bf (diff)
downloadsubsurface-b28237309a5fd3af527d71fe0d4dfada7a11107c.tar.gz
Good deal of code Cleanup.
Rewrite of the way we handle the last used directory for the loading / saving of files. we didn't reuse anything for the code, and that's error prone and also dumb =p. Reworked that so we have a nice method to help us out on that. lastUsedDir and updateLastUsedDir Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp51
1 files changed, 21 insertions, 30 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index b2180d1ce..5e7560030 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -99,27 +99,11 @@ void MainWindow::on_actionNew_triggered()
void MainWindow::on_actionOpen_triggered()
{
- QSettings settings;
- QString lastDir = QDir::homePath();
-
- settings.beginGroup("FileDialog");
- if (settings.contains("LastDir")) {
- if(QDir::setCurrent(settings.value("LastDir").toString())) {
- lastDir = settings.value("LastDir").toString();
- }
- }
- settings.endGroup();
-
+ QString lastDir = lastUsedDir();
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), lastDir, filter());
if (filename.isEmpty())
return;
-
- // Keep last open dir
- QFileInfo fileInfo(filename);
- settings.beginGroup("FileDialog");
- settings.setValue("LastDir",fileInfo.dir().path());
- settings.endGroup();
-
+ updateLastUsedDir(filename);
on_actionClose_triggered();
loadFiles( QStringList() << filename );
}
@@ -166,6 +150,18 @@ void MainWindow::on_actionClose_triggered()
void MainWindow::on_actionImport_triggered()
{
+ QString lastDir = lastUsedDir();
+
+ QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Import Files"), lastDir, filter());
+ if (!fileNames.size())
+ return; // no selection
+
+ updateLastUsedDir(QFileInfo(fileNames.at(0)).dir().path());
+ importFiles(fileNames);
+}
+
+QString MainWindow::lastUsedDir()
+{
QSettings settings;
QString lastDir = QDir::homePath();
@@ -173,19 +169,14 @@ void MainWindow::on_actionImport_triggered()
if (settings.contains("LastDir"))
if (QDir::setCurrent(settings.value("LastDir").toString()))
lastDir = settings.value("LastDir").toString();
- settings.endGroup();
-
- QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Import Files"), lastDir, filter());
- if (!fileNames.size())
- return; // no selection
-
- // Keep last open dir
- QFileInfo fileInfo(fileNames.at(0));
- settings.beginGroup("FileDialog");
- settings.setValue("LastDir", fileInfo.dir().path());
- settings.endGroup();
+ return lastDir;
+}
- importFiles(fileNames);
+void MainWindow::updateLastUsedDir(const QString& dir)
+{
+ QSettings s;
+ s.beginGroup("FileDialog");
+ s.setValue("LastDir", dir);
}
void MainWindow::on_actionExportUDDF_triggered()