- configuration is now always situated and read from the application working directory

Fri, 10 Jan 2014 03:35:50 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 10 Jan 2014 03:35:50 +0200
changeset 611
6679e47b019f
parent 610
f8244301110d
child 612
ad1ba9509ba3

- configuration is now always situated and read from the application working directory
- primitive scanner now works for sure
- some minor cleanup

changelog.txt file | annotate | diff | comparison | revisions
ldforge.pro file | annotate | diff | comparison | revisions
src/config.cc file | annotate | diff | comparison | revisions
src/gui.cc file | annotate | diff | comparison | revisions
src/gui.h file | annotate | diff | comparison | revisions
src/gui_actions.cc file | annotate | diff | comparison | revisions
src/main.cc file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
src/primitives.cc file | annotate | diff | comparison | revisions
src/primitives.h file | annotate | diff | comparison | revisions
--- a/changelog.txt	Wed Jan 08 23:52:25 2014 +0200
+++ b/changelog.txt	Fri Jan 10 03:35:50 2014 +0200
@@ -18,6 +18,7 @@
 	Subfile matrix values are rounded to 4 decimals, everything else to 3 decimals.
 - Implicitely-opened documents are now closed automatically when rendered unused, hopefully reducing memory
 	usage somewhat.
+- Configuration is now always situated and read from the application working directory
 - LDraw code parser no longer complains about scientific notation.
 - Changing to draw mode while in free camera now causes the camera to be changed to top.
 - When drawing polygons, line lengths are now displayed. Added a configuration option to toggle this behavior.
--- a/ldforge.pro	Wed Jan 08 23:52:25 2014 +0200
+++ b/ldforge.pro	Fri Jan 10 03:35:50 2014 +0200
@@ -4,16 +4,10 @@
 
 TEMPLATE        = app
 TARGET          = ldforge
-SUBDIRS        += ./src
-
-TARGET          = ldforge
-DEPENDPATH     += .
-INCLUDEPATH    += . ./build_shared/
 RC_FILE         = ldforge.rc
 RESOURCES       = ldforge.qrc
 RCC_DIR         = ./build_shared/
 MOC_DIR         = ./build_shared/
-RCC_DIR         = ./build_shared/
 UI_DIR          = ./build_shared/
 SOURCES         = src/*.cc
 HEADERS         = src/*.h src/misc/*.h
@@ -23,11 +17,9 @@
 CONFIG         += debug_and_release
 
 CONFIG (debug, debug|release) {
-	TARGET   = ldforge_debug
 	DEFINES += DEBUG
 	OBJECTS_DIR = ./build_debug/
 } else {
-	TARGET = ldforge
 	DEFINES += RELEASE
 	OBJECTS_DIR = ./build_release/
 }
--- a/src/config.cc	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/config.cc	Fri Jan 10 03:35:50 2014 +0200
@@ -48,7 +48,13 @@
 // -----------------------------------------------------------------------------
 static QSettings* getSettingsObject()
 {
-	return new QSettings (UNIXNAME EXTENSION, QSettings::IniFormat);
+	QString path = getApplicationDirectory() + DIRSLASH UNIXNAME EXTENSION;
+
+#if DIRSLASH_CHAR != '/'
+	path.replace (DIRSLASH, "/");
+#endif
+
+	return new QSettings (path, QSettings::IniFormat);
 }
 
 Config::Config (QString name) :
@@ -161,8 +167,9 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 #undef IMPLEMENT_CONFIG
+
 #define IMPLEMENT_CONFIG(NAME)								\
-	NAME##Config* NAME##Config::getByName (QString name)		\
+	NAME##Config* NAME##Config::getByName (QString name)	\
 	{														\
 		return getConfigByName<NAME##Config> (name, NAME);	\
 	}
--- a/src/gui.cc	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/gui.cc	Fri Jan 10 03:35:50 2014 +0200
@@ -90,15 +90,6 @@
 	slot_selectionChanged();
 	setStatusBar (new QStatusBar);
 
-	// Init primitive loader task stuff
-	m_primLoaderBar = new QProgressBar;
-	m_primLoaderWidget = new QWidget;
-	QHBoxLayout* primLoaderLayout = new QHBoxLayout (m_primLoaderWidget);
-	primLoaderLayout->addWidget (new QLabel ("Loading primitives:"));
-	primLoaderLayout->addWidget (m_primLoaderBar);
-	statusBar()->addPermanentWidget (m_primLoaderWidget);
-	m_primLoaderWidget->hide();
-
 	// Make certain actions checkable
 	ui->actionAxes->setChecked (gl_axes);
 	ui->actionWireframe->setChecked (gl_wireframe);
@@ -508,7 +499,7 @@
 	QToolButton* button = static_cast<QToolButton*> (sender());
 	LDColor* col = null;
 
-	for (const LDQuickColor & entry : m_quickColors)
+	for (const LDQuickColor& entry : m_quickColors)
 	{
 		if (entry.getToolButton() == button)
 		{
@@ -745,37 +736,6 @@
 	AddObjectDialog::staticDialog (obj->getType(), obj);
 }
 
-#if 0
-// =============================================================================
-// -----------------------------------------------------------------------------
-void ForgeWindow::primitiveLoaderStart (int max)
-{
-	m_primLoaderWidget->show();
-	m_primLoaderBar->setRange (0, max);
-	m_primLoaderBar->setValue (0);
-	m_primLoaderBar->setFormat ("%p%");
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void ForgeWindow::primitiveLoaderUpdate (int prog)
-{
-	m_primLoaderBar->setValue (prog);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void ForgeWindow::primitiveLoaderEnd()
-{
-	QTimer* hidetimer = new QTimer;
-	connect (hidetimer, SIGNAL (timeout()), m_primLoaderWidget, SLOT (hide()));
-	hidetimer->setSingleShot (true);
-	hidetimer->start (1500);
-	m_primLoaderBar->setFormat (tr ("Done"));
-	log (tr ("Primitives scanned: %1 primitives listed"), m_primLoaderBar->value());
-}
-#endif
-
 // =============================================================================
 // -----------------------------------------------------------------------------
 bool ForgeWindow::save (LDDocument* f, bool saveAs)
--- a/src/gui.h	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/gui.h	Fri Jan 10 03:35:50 2014 +0200
@@ -134,11 +134,6 @@
 		void endAction();
 
 	public slots:
-#if 0
-		void primitiveLoaderStart (int max);
-		void primitiveLoaderUpdate (int prog);
-		void primitiveLoaderEnd();
-#endif // 0
 		void changeCurrentFile();
 		void slot_action();
 		void slot_actionNew();
@@ -241,8 +236,6 @@
 
 	private:
 		GLRenderer* m_renderer;
-		QProgressBar* m_primLoaderBar;
-		QWidget* m_primLoaderWidget;
 		QList<LDObject*> m_sel;
 		QList<LDQuickColor> m_quickColors;
 		QList<QToolButton*> m_colorButtons;
--- a/src/gui_actions.cc	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/gui_actions.cc	Fri Jan 10 03:35:50 2014 +0200
@@ -669,7 +669,7 @@
 // -----------------------------------------------------------------------------
 DEFINE_ACTION (ScanPrimitives, 0)
 {
-	PrimitiveLister::start();
+	PrimitiveScanner::start();
 }
 
 // =============================================================================
--- a/src/main.cc	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/main.cc	Fri Jan 10 03:35:50 2014 +0200
@@ -21,6 +21,7 @@
 #include <QAbstractButton>
 #include <QFile>
 #include <QTextStream>
+#include <QDir>
 #include "gui.h"
 #include "document.h"
 #include "misc.h"
@@ -35,7 +36,6 @@
 
 QList<LDDocument*> g_loadedFiles;
 ForgeWindow* g_win = null;
-const QApplication* g_app = null;
 static QString g_versionString, g_fullVersionString;
 
 const Vertex g_origin (0.0f, 0.0f, 0.0f);
@@ -43,6 +43,18 @@
 
 cfg (Bool, firststart, true);
 
+static QString g_argv0;
+
+QString getApplicationDirectory()
+{
+	assert (g_argv0.isEmpty() == false);
+
+	if (g_argv0.indexOf (DIRSLASH) != -1)
+		return dirname (g_argv0);
+
+	return ".";
+}
+
 // =============================================================================
 // -----------------------------------------------------------------------------
 int main (int argc, char* argv[])
@@ -50,8 +62,7 @@
 	QApplication app (argc, argv);
 	app.setOrganizationName (APPNAME);
 	app.setApplicationName (APPNAME);
-	g_app = &app;
-
+	g_argv0 = argv[0];
 	initCrashCatcher();
 	LDDocument::setCurrent (null);
 
--- a/src/main.h	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/main.h	Fri Jan 10 03:35:50 2014 +0200
@@ -23,23 +23,6 @@
 #ifndef LDFORGE_MAIN_H
 #define LDFORGE_MAIN_H
 
-// Hack to make KDevelop parse QString properly. Q_REQUIRED_RESULT expands into
-// an __attribute__((warn_unused_result)) KDevelop's lexer doesn't seem to
-// understand, yielding an error and leaving some methods unlexed.
-//
-// The following first includes <QChar> to get Q_REQUIRED_RESULT defined first,
-// then re-defining it as nothing. This causes Q_REQUIRED_RESULT to essentially
-// "vanish" from QString's methods when KDevelop lexes them.
-//
-// Similar reasoning for Q_DECL_HIDDEN, except with Q_OBJECT this time.
-#ifdef IN_IDE_PARSER
-# include <QChar>
-# undef Q_REQUIRED_RESULT
-# undef Q_DECL_HIDDEN
-# define Q_REQUIRED_RESULT
-# define Q_DECL_HIDDEN
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -84,10 +67,6 @@
 # define DIRSLASH_CHAR '/'
 #endif // WIN32
 
-#ifdef null
-#undef null
-#endif // null
-
 #ifdef __GNUC__
 #define FUNCNAME __PRETTY_FUNCTION__
 #else
@@ -108,9 +87,7 @@
 // On Windows I just can't get the actual error messages otherwise.
 void assertionFailure (const char* file, int line, const char* funcname, const char* expr);
 
-#ifdef assert
-# undef assert
-#endif // assert
+#undef assert
 
 #ifdef DEBUG
 # define assert(N) { ((N) ? (void) 0 : assertionFailure (__FILE__, __LINE__, FUNCNAME, #N)); }
@@ -122,6 +99,8 @@
 QString versionString();
 QString fullVersionString();
 
+QString getApplicationDirectory();
+
 #define properties private
 #define typedefs public
 #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis> ({X, Y, Z}))
--- a/src/primitives.cc	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/primitives.cc	Fri Jan 10 03:35:50 2014 +0200
@@ -29,7 +29,7 @@
 
 QList<PrimitiveCategory*> g_PrimitiveCategories;
 QList<Primitive> g_primitives;
-static PrimitiveLister* g_activePrimLister = null;
+static PrimitiveScanner* g_activeScanner = null;
 PrimitiveCategory* g_unmatched = null;
 
 extern_cfg (String, ld_defaultname);
@@ -46,16 +46,15 @@
 	"con"
 };
 
-PrimitiveLister* getPrimitiveLister()
+PrimitiveScanner* getActivePrimitiveScanner()
 {
-	return g_activePrimLister;
+	return g_activeScanner;
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
 void loadPrimitives()
 {
-	log ("Loading primitives...\n");
 	PrimitiveCategory::loadCategories();
 
 	// Try to load prims.cfg
@@ -64,11 +63,10 @@
 	if (!conf.open (QIODevice::ReadOnly))
 	{
 		// No prims.cfg, build it
-		PrimitiveLister::start();
+		PrimitiveScanner::start();
 	}
 	else
 	{
-		// Read primitives from prims.cfg
 		while (conf.atEnd() == false)
 		{
 			QString line = conf.readLine();
@@ -83,7 +81,7 @@
 			g_primitives << info;
 		}
 
-		PrimitiveCategory::populateCategories();
+		log ("%1 primitives loaded.\n", g_primitives.size());
 	}
 }
 
@@ -91,13 +89,10 @@
 // -----------------------------------------------------------------------------
 static void recursiveGetFilenames (QDir dir, QList<QString>& fnames)
 {
-	QFileInfoList flist = dir.entryInfoList();
+	QFileInfoList flist = dir.entryInfoList (QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
 
-	for (const QFileInfo & info : flist)
+	for (const QFileInfo& info : flist)
 	{
-		if (info.fileName() == "." || info.fileName() == "..")
-			continue; // skip . and ..
-
 		if (info.isDir())
 			recursiveGetFilenames (QDir (info.absoluteFilePath()), fnames);
 		else
@@ -107,28 +102,29 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-PrimitiveLister::PrimitiveLister (QObject* parent) :
+PrimitiveScanner::PrimitiveScanner (QObject* parent) :
 	QObject (parent),
 	m_i (0)
 {
-	g_activePrimLister = this;
+	g_activeScanner = this;
 	QDir dir (LDPaths::prims());
 	assert (dir.exists());
 	m_baselen = dir.absolutePath().length();
 	recursiveGetFilenames (dir, m_files);
 	emit starting (m_files.size());
+	log ("Scanning primitives...");
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-PrimitiveLister::~PrimitiveLister()
+PrimitiveScanner::~PrimitiveScanner()
 {
-	g_activePrimLister = null;
+	g_activeScanner = null;
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void PrimitiveLister::work()
+void PrimitiveScanner::work()
 {
 	int j = min (m_i + 100, m_files.size());
 
@@ -167,19 +163,20 @@
 		QFile conf (path);
 
 		if (!conf.open (QIODevice::WriteOnly | QIODevice::Text))
-			critical (fmt ("Couldn't write %1: %2", path, conf.errorString()));
+			critical (fmt ("Couldn't write primitive list %1: %2",
+				path, conf.errorString()));
 		else
 		{
 			for (Primitive& info : m_prims)
-				fprint (conf, "%1 %2\n", info.name, info.title);
+				fprint (conf, "%1 %2\r\n", info.name, info.title);
 
 			conf.close();
 		}
 
 		g_primitives = m_prims;
 		PrimitiveCategory::populateCategories();
-		log ("%1 primitives listed", g_primitives.size());
-		g_activePrimLister = null;
+		log ("%1 primitives scanned", g_primitives.size());
+		g_activeScanner = null;
 		emit workDone();
 		deleteLater();
 	}
@@ -193,18 +190,13 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void PrimitiveLister::start()
+void PrimitiveScanner::start()
 {
-	if (g_activePrimLister)
+	if (g_activeScanner)
 		return;
 
-	PrimitiveLister* lister = new PrimitiveLister;
-	/*
-	connect (lister, SIGNAL (starting (int)), g_win, SLOT (primitiveLoaderStart (int)));
-	connect (lister, SIGNAL (update (int)), g_win, SLOT (primitiveLoaderUpdate (int)));
-	connect (lister, SIGNAL (workDone()), g_win, SLOT (primitiveLoaderEnd()));
-	*/
-	lister->work();
+	PrimitiveScanner* scanner = new PrimitiveScanner;
+	scanner->work();
 }
 
 // =============================================================================
@@ -361,7 +353,7 @@
 // -----------------------------------------------------------------------------
 bool isPrimitiveLoaderBusy()
 {
-	return g_activePrimLister != null;
+	return g_activeScanner != null;
 }
 
 // =============================================================================
--- a/src/primitives.h	Wed Jan 08 23:52:25 2014 +0200
+++ b/src/primitives.h	Fri Jan 10 03:35:50 2014 +0200
@@ -64,18 +64,18 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-// PrimitiveLister
+// PrimitiveScanner
 //
 // Worker object that scans the primitives folder for primitives and
 // builds an index of them.
 // =============================================================================
-class PrimitiveLister : public QObject
+class PrimitiveScanner : public QObject
 {
 	Q_OBJECT
 
 	public:
-		explicit			PrimitiveLister (QObject* parent = 0);
-		virtual				~PrimitiveLister();
+		explicit			PrimitiveScanner (QObject* parent = 0);
+		virtual				~PrimitiveScanner();
 		static void			start();
 
 	public slots:
@@ -96,7 +96,7 @@
 extern QList<PrimitiveCategory*> g_PrimitiveCategories;
 
 void loadPrimitives();
-PrimitiveLister* getPrimitiveLister();
+PrimitiveScanner* getActivePrimitiveScanner();
 
 enum PrimitiveType
 {

mercurial