On 02/17/2014 06:33 PM, Lubomir I. Ivanov wrote:
hello and thank you for the patch,

it has some coding style issues that should be resolved.
please refer to the file CodingStyle in the project root:
Hello,

see the updated patch.
>From 8cb1bae6b4c8bcdb6255c931e74362797838d8b8 Mon Sep 17 00:00:00 2001
From: Joshua Wambua <[email protected]>
Date: Fri, 21 Feb 2014 08:50:31 +0300
Subject: [PATCH] [PATCH] Hide failed parses from recent files list

When a file fails to parse, this hides it from the recent files list.

Signed-off-by: Joshua Wambua <[email protected]>
---
 qt-ui/mainwindow.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++---
 qt-ui/mainwindow.h   |  1 +
 2 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 7609bff..9ae1958 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -812,7 +812,58 @@ void MainWindow::addRecentFile(const QStringList &newFiles)
 	s.endGroup();
 	s.sync();
 
-	loadRecentFiles(&s);
+    loadRecentFiles(&s);
+}
+
+void MainWindow::removeRecentFile(const 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(const QString & file, failedFiles) {
+        int index = files.indexOf(file);
+
+        if (index >= 0) {
+            files.removeAt(index);
+        }
+    }
+
+    while (files.count() > 4) {
+        files.removeLast();
+    }
+
+    for (int c = 0; c < 4; c++) {
+        QString key = QString("File_%1").arg(c + 1);
+
+        if (files.count() > c) {
+            s.setValue(key, files.at(c));
+        } else {
+            if (s.contains(key)) {
+                s.remove(key);
+            }
+        }
+    }
+    s.endGroup();
+    s.sync();
+
+    loadRecentFiles(&s);
 }
 
 void MainWindow::recentFileTriggered(bool checked)
@@ -931,6 +982,8 @@ void MainWindow::loadFiles(const QStringList fileNames)
 
 	char *error = NULL;
 	QByteArray fileNamePtr;
+    QStringList parsedFiles;
+    QStringList failedFiles;
 
 	for (int i = 0; i < fileNames.size(); ++i) {
 		fileNamePtr = QFile::encodeName(fileNames.at(i));
@@ -941,11 +994,15 @@ void MainWindow::loadFiles(const QStringList fileNames)
 		if (error != NULL) {
 			showError(error);
 			free(error);
-		}
+            failedFiles.append(fileNames.at(i));
+        } else {
+            parsedFiles.append(fileNames.at(i));
+        }
 	}
 
 	process_dives(false, false);
-	addRecentFile(fileNames);
+    addRecentFile(parsedFiles);
+    removeRecentFile(failedFiles);
 
 	refreshDisplay();
 	ui.actionAutoGroup->setChecked(autogroup);
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 24d3d70..c3f6d7d 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -47,6 +47,7 @@ public:
 	MainTab *information();
 	void loadRecentFiles(QSettings *s);
 	void addRecentFile(const QStringList &newFiles);
+    void removeRecentFile(const QStringList &failedFiles);
 	DiveListView *dive_list();
 	GlobeGPS *globe();
 	void showError(QString message);
-- 
1.9.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to