From 9cd3d61c112f81156c22d44c1ab632fcfabc8a14 Mon Sep 17 00:00:00 2001 From: Joshua Wambua Date: Fri, 28 Feb 2014 12:04:00 +0300 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'qt-ui/mainwindow.cpp') 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); -- cgit v1.2.3-70-g09d2