src/file.cpp

changeset 292
4779ca562d5e
parent 290
be0c367e7420
child 293
a0ed563e14b2
--- a/src/file.cpp	Sat Jun 15 04:36:52 2013 +0300
+++ b/src/file.cpp	Sat Jun 15 19:14:42 2013 +0300
@@ -20,7 +20,7 @@
 #include <QFileDialog>
 #include <qprogressbar.h>
 #include <QDir>
-#include <qthread.h>
+#include <QThread>
 
 #include <stdlib.h>
 #include "common.h"
@@ -38,9 +38,7 @@
 cfg (str, io_recentfiles, "");
 
 static bool g_loadingMainFile = false;
-PrimitiveLister* g_activePrimLister = null;
 bool g_primListerMutex = false;
-vector<PrimitiveInfo> g_Primitives;
 
 // =============================================================================
 namespace LDPaths {
@@ -929,108 +927,4 @@
 	
 	g_loadedFiles.clear ();
 	g_loadedFiles << filesUsed;
-}
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-void recursiveGetFilenames (QDir dir, vector<str>& fnames) {
-	QFileInfoList flist = dir.entryInfoList ();
-	for (const QFileInfo& info : flist) {
-		if (info.fileName () == "." || info.fileName () == "..")
-			continue; // skip . and ..
-		
-		if (info.isDir ())
-			recursiveGetFilenames (QDir (info.absoluteFilePath ()), fnames);
-		else
-			fnames << info.absoluteFilePath ();
-	}
-}
-
-void PrimitiveLister::work () {
-	g_activePrimLister = this;
-	m_prims.clear ();
-	
-	QDir dir (LDPaths::prims ());
-	assert (dir.exists ());
-	
-	ulong baselen = dir.absolutePath ().length ();
-	
-	vector<str> fnames;
-	recursiveGetFilenames (dir, fnames);
-	emit starting (fnames.size ());
-	
-	ulong i = 0;
-	for (str fname : fnames) {
-		File f (fname, File::Read);
-		
-		PrimitiveInfo info;
-		info.name = fname.mid (baselen + 1); // make full path relative
-		info.name.replace ('/', '\\'); // use DOS backslashes, they're expected
-		
-		if (!f.readLine (info.title))
-			info.title = "";
-		
-		info.title = info.title.simplified ();
-		
-		if (info.title[0] == '0') {
-			info.title.remove (0, 1); // remove 0
-			info.title = info.title.simplified ();
-		}
-		
-		m_prims << info;
-		emit update (++i);
-	}
-	
-	// Save to a config file
-	File conf (config::dirpath () + "prims.cfg", File::Write);
-	for (PrimitiveInfo& info : m_prims)
-		fprint (conf, "%1 %2\n", info.name, info.title);
-	
-	conf.close ();
-	
-	g_primListerMutex = true;
-	g_Primitives = m_prims;
-	g_primListerMutex = false;
-	
-	g_activePrimLister = null;
-	emit workDone ();
-}
-
-void PrimitiveLister::start () {
-	if (g_activePrimLister)
-		return;
-	
-	PrimitiveLister* lister = new PrimitiveLister;
-	QThread* listerThread = new QThread;
-	lister->moveToThread (listerThread);
-	connect (lister, SIGNAL (starting (ulong)), g_win, SLOT (primitiveLoaderStart (ulong)));
-	connect (lister, SIGNAL (update (ulong)), g_win, SLOT (primitiveLoaderUpdate (ulong)));
-	connect (lister, SIGNAL (workDone ()), g_win, SLOT (primitiveLoaderEnd ()));
-	connect (listerThread, SIGNAL (started ()), lister, SLOT (work ()));
-	connect (listerThread, SIGNAL (finished ()), lister, SLOT (deleteLater ()));
-	listerThread->start ();
-}
-
-void loadPrimitiveInfo () {
-	g_Primitives.clear ();
-	
-	// Try to load prims.cfg
-	File conf (config::dirpath () + "prims.cfg", File::Read);
-	if (!conf) {
-		// No prims.cfg, build it
-		PrimitiveLister::start ();
-		return;
-	}
-	
-	for (str line : conf) {
-		int space = line.indexOf (" ");
-		if (space == -1)
-			continue;
-		
-		PrimitiveInfo info;
-		info.name = line.left (space);
-		info.title = line.mid (space + 1);
-		g_Primitives << info;
-	}
 }
\ No newline at end of file

mercurial