diff options
author | Joshua Wambua <joshua@megvel.me.ke> | 2014-02-28 12:04:00 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-28 07:51:41 -0800 |
commit | 9cd3d61c112f81156c22d44c1ab632fcfabc8a14 (patch) | |
tree | 293dc1feda18e53786cef070e1cd2b245d5a5521 /qt-ui/mainwindow.cpp | |
parent | 76e6420f6b3503b76bd3eec00ab0e53d6ea17a20 (diff) | |
download | subsurface-9cd3d61c112f81156c22d44c1ab632fcfabc8a14.tar.gz |
Remove failed parses from recent files menu
This patch will remove all files that fail to parse from the recent
files menu.
Signed-off-by: Joshua Wambua <joshua@megvel.me.ke>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r-- | qt-ui/mainwindow.cpp | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 19b97fd45..02ac2337b 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -757,9 +757,8 @@ void MainWindow::addRecentFile(const QStringList &newFiles) QStringList files; QSettings s; - if (newFiles.isEmpty()) { + if (newFiles.isEmpty()) return; - } s.beginGroup("Recent_Files"); @@ -792,11 +791,11 @@ void MainWindow::addRecentFile(const QStringList &newFiles) files.removeLast(); } - for (int c = 0; c < 4; c++) { - QString key = QString("File_%1").arg(c + 1); + for (int c = 1; c <= 4; c++) { + QString key = QString("File_%1").arg(c); - if (files.count() > c) { - s.setValue(key, files.at(c)); + if (files.count() >= c) { + s.setValue(key, files.at(c - 1)); } else { if (s.contains(key)) { s.remove(key); @@ -809,6 +808,47 @@ void MainWindow::addRecentFile(const QStringList &newFiles) loadRecentFiles(&s); } +void MainWindow::removeRecentFile(QStringList failedFiles) +{ + QStringList files; + QSettings s; + + if (failedFiles.isEmpty()) + return; + + s.beginGroup("Recent_Files"); + + for (int c = 1; c <= 4; c++) { + QString key = QString("File_%1").arg(c); + + if (s.contains(key)) { + QString file = s.value(key).toString(); + files.append(file); + } else { + break; + } + } + + foreach (QString file, failedFiles) + files.removeAll(file); + + for (int c = 1; c <= 4; c++) { + QString key = QString("File_%1").arg(c); + + if (files.count() >= c) { + s.setValue(key, files.at(c - 1)); + } else { + if (s.contains(key)) + s.remove(key); + } + } + + s.endGroup(); + s.sync(); + + loadRecentFiles(&s); +} + void MainWindow::recentFileTriggered(bool checked) { Q_UNUSED(checked); @@ -925,6 +965,7 @@ void MainWindow::loadFiles(const QStringList fileNames) char *error = NULL; QByteArray fileNamePtr; + QStringList failedParses; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); @@ -933,6 +974,7 @@ void MainWindow::loadFiles(const QStringList fileNames) setTitle(MWTF_FILENAME); if (error != NULL) { + failedParses.append(fileNames.at(i)); showError(error); free(error); } @@ -940,6 +982,7 @@ void MainWindow::loadFiles(const QStringList fileNames) process_dives(false, false); addRecentFile(fileNames); + removeRecentFile(failedParses); refreshDisplay(); ui.actionAutoGroup->setChecked(autogroup); |