Use QMutex for the thread locking, remove filename from the progress dialog since it's not known anyway

Fri, 24 May 2013 03:34:09 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 24 May 2013 03:34:09 +0300
changeset 249
6b2cc2d82ba6
parent 248
4431371f3ffe
child 250
6e80f038e8df

Use QMutex for the thread locking, remove filename from the progress dialog since it's not known anyway

src/common.h file | annotate | diff | comparison | revisions
src/dialogs.cpp file | annotate | diff | comparison | revisions
src/dialogs.h file | annotate | diff | comparison | revisions
src/file.cpp file | annotate | diff | comparison | revisions
src/file.h file | annotate | diff | comparison | revisions
--- a/src/common.h	Fri May 24 03:22:11 2013 +0300
+++ b/src/common.h	Fri May 24 03:34:09 2013 +0300
@@ -29,6 +29,9 @@
 #include <vector>
 #include <stdint.h>
 #include <stdarg.h>
+#include <QString>
+#include <QMutex>
+
 #include "string.h"
 #include "config.h"
 #include "types.h"
@@ -106,22 +109,15 @@
 #define THREAD_PROPERTY(T, GET, SET) \
 private: \
 	T m_##GET; \
-	bool m_threadLock_##GET; \
+	QMutex m_threadLock_##GET; \
 public: \
-	const T& GET () const { \
-		while (m_threadLock_##GET) \
-			; \
-		return m_##GET; \
-	} \
+	const T& GET () const { return m_##GET; } \
 	void callback_##SET (); \
 	void SET (T val) { \
-		while (m_threadLock_##GET) \
-			; \
-		 \
-		m_threadLock_##GET = true; \
+		m_threadLock_##GET.lock (); \
 		m_##GET = val; \
 		callback_##SET (); \
-		m_threadLock_##GET = false; \
+		m_threadLock_##GET.unlock (); \
 	}
 
 #ifdef null
--- a/src/dialogs.cpp	Fri May 24 03:22:11 2013 +0300
+++ b/src/dialogs.cpp	Fri May 24 03:34:09 2013 +0300
@@ -480,7 +480,7 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-OpenFileDialog::OpenFileDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
+OpenProgressDialog::OpenProgressDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
 	progressBar = new QProgressBar;
 	progressText = new QLabel;
 	setNumLines (0);
@@ -496,17 +496,17 @@
 	layout->addWidget (dbb_buttons);
 }
 
-void OpenFileDialog::callback_setNumLines () {
+void OpenProgressDialog::callback_setNumLines () {
 	progressBar->setRange (0, numLines ());
 	updateValues ();
 }
 
-void OpenFileDialog::updateValues () {
+void OpenProgressDialog::updateValues () {
 	progressBar->setValue (progress ());
-	progressText->setText (fmt ("%s: %lu/%lu lines parsed", fileName ().c (), progress (), numLines ()));
+	progressText->setText (fmt ("%lu/%lu lines parsed", progress (), numLines ()));
 }
 
-void OpenFileDialog::updateProgress (int progress) {
+void OpenProgressDialog::updateProgress (int progress) {
 	m_progress = progress;
 	updateValues ();
 }
\ No newline at end of file
--- a/src/dialogs.h	Fri May 24 03:22:11 2013 +0300
+++ b/src/dialogs.h	Fri May 24 03:34:09 2013 +0300
@@ -156,14 +156,13 @@
 };
 
 // =============================================================================
-class OpenFileDialog : public QDialog {
+class OpenProgressDialog : public QDialog {
 	Q_OBJECT
 	READ_PROPERTY (ulong, progress)
 	CALLBACK_PROPERTY (ulong, numLines, setNumLines)
-	PROPERTY (str, fileName, setFileName)
 	
 public:
-	explicit OpenFileDialog (QWidget* parent = null, Qt::WindowFlags f = 0);
+	explicit OpenProgressDialog (QWidget* parent = null, Qt::WindowFlags f = 0);
 	
 public slots:
 	void updateProgress (int progress);
--- a/src/file.cpp	Fri May 24 03:22:11 2013 +0300
+++ b/src/file.cpp	Fri May 24 03:34:09 2013 +0300
@@ -270,8 +270,7 @@
 		loaderThread->start ();
 		
 		// Now create a progress dialog for the operation
-		OpenFileDialog* dlg = new OpenFileDialog (g_win);
-		dlg->setFileName ("???");
+		OpenProgressDialog* dlg = new OpenProgressDialog (g_win);
 		dlg->setNumLines (numLines);
 		
 		// Connect the loader in so we can actually show updates
--- a/src/file.h	Fri May 24 03:22:11 2013 +0300
+++ b/src/file.h	Fri May 24 03:34:09 2013 +0300
@@ -23,7 +23,7 @@
 #include "ldtypes.h"
 #include <QObject>
 
-class OpenFileDialog;
+class OpenProgressDialog;
 namespace LDPaths {
 	void initPaths ();
 	bool tryConfigure (str path);

mercurial