← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2894: file list loading: plug a mem leak, allow cancellation while matching with ADLS, add a message to...

 

------------------------------------------------------------
revno: 2894
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2012-04-07 20:05:24 +0200
message:
  file list loading: plug a mem leak, allow cancellation while matching with ADLS, add a message to the title bar
modified:
  changelog.txt
  dcpp/ADLSearch.cpp
  dcpp/ADLSearch.h
  dcpp/DirectoryListing.cpp
  win32/DirectoryListingFrame.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2012-03-22 19:20:44 +0000
+++ changelog.txt	2012-04-07 18:05:24 +0000
@@ -26,6 +26,7 @@
 * Update boost to version 1.49
 * [L#947895] Move the "follow redirect" command to inline chat links (poy)
 * Format chat links (poy)
+* Improve threaded file list loading (poy)
 
 -- 0.791 2012-01-14 --
 * Update translations

=== modified file 'dcpp/ADLSearch.cpp'
--- dcpp/ADLSearch.cpp	2012-03-03 19:33:45 +0000
+++ dcpp/ADLSearch.cpp	2012-04-07 18:05:24 +0000
@@ -436,20 +436,24 @@
 	setBreakOnFirst(BOOLSETTING(ADLS_BREAK_ON_FIRST));
 
 	string path(root->getName());
-	matchRecurse(destDirs, root, path);
+	matchRecurse(destDirs, aDirList, root, path);
 
 	finalizeDestinationDirectories(destDirs, root);
 }
 
-void ADLSearchManager::matchRecurse(DestDirList &aDestList, DirectoryListing::Directory* aDir, string &aPath) {
+void ADLSearchManager::matchRecurse(DestDirList& aDestList, DirectoryListing& filelist, DirectoryListing::Directory* aDir, string& aPath) {
 	for(auto& dirIt: aDir->directories) {
+		if(filelist.getAbort()) { throw Exception(); }
 		string tmpPath = aPath + "\\" + dirIt->getName();
 		matchesDirectory(aDestList, dirIt, tmpPath);
-		matchRecurse(aDestList, dirIt, tmpPath);
+		matchRecurse(aDestList, filelist, dirIt, tmpPath);
 	}
+
 	for(auto& fileIt: aDir->files) {
+		if(filelist.getAbort()) { throw Exception(); }
 		matchesFile(aDestList, fileIt, aPath);
 	}
+
 	stepUpDirectory(aDestList);
 }
 

=== modified file 'dcpp/ADLSearch.h'
--- dcpp/ADLSearch.h	2012-01-13 20:55:20 +0000
+++ dcpp/ADLSearch.h	2012-04-07 18:05:24 +0000
@@ -129,12 +129,12 @@
 	GETSET(bool, breakOnFirst, BreakOnFirst)
 	GETSET(HintedUser, user, User)
 
-	// @remarks Used to add ADLSearch directories to an existing DirectoryListing
+	/// @remarks Used to add ADLSearch directories to an existing DirectoryListing
 	void matchListing(DirectoryListing& aDirList) noexcept;
 
 private:
-	// @internal
-	void matchRecurse(DestDirList& /*aDestList*/, DirectoryListing::Directory* /*aDir*/, string& /*aPath*/);
+	// Recurse through the directories and files of a directory.
+	void matchRecurse(DestDirList& aDestList, DirectoryListing& filelist, DirectoryListing::Directory* aDir, string& aPath);
 	// Search for file match
 	void matchesFile(DestDirList& destDirVector, DirectoryListing::File *currentFile, string& fullPath);
 	// Search for directory match

=== modified file 'dcpp/DirectoryListing.cpp'
--- dcpp/DirectoryListing.cpp	2012-03-03 19:33:45 +0000
+++ dcpp/DirectoryListing.cpp	2012-04-07 18:05:24 +0000
@@ -156,9 +156,7 @@
 static const string sTTH = "TTH";
 
 void ListLoader::startTag(const string& name, StringPairList& attribs, bool simple) {
-	if(list->getAbort()) {
-		throw Exception();
-	}
+	if(list->getAbort()) { throw Exception(); }
 
 	if(inListing) {
 		if(name == sFile) {

=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp	2012-03-18 15:43:00 +0000
+++ win32/DirectoryListingFrame.cpp	2012-04-07 18:05:24 +0000
@@ -449,6 +449,9 @@
 		layout();
 	}
 
+	// add a "loading" message to the title bar.
+	updateTitle();
+
 	auto finishLoad = [this] {
 		delete loader;
 		loader = 0;
@@ -456,8 +459,8 @@
 		loading->close(true);
 		loading = 0;
 		layout();
+		updateTitle();
 		if(!error.empty()) {
-			updateTitle();
 			status->setText(STATUS_STATUS, error);
 		}
 		setDirty(SettingsManager::BOLD_FL);
@@ -475,13 +478,6 @@
 		finishLoad();
 	}); });
 
-	onDestroy([this] {
-		if(loader) {
-			dl->setAbort(true);
-			loader->join();
-		}
-	});
-
 	try {
 		loader->start();
 
@@ -575,6 +571,12 @@
 	ClientManager::getInstance()->removeListener(this);
 
 	lists.erase(dl->getUser());
+
+	if(loader) {
+		dl->setAbort(true);
+		loader->join();
+	}
+
 	return true;
 }
 
@@ -680,7 +682,11 @@
 	}
 
 	// bypass the recent item updater if the file list hasn't been loaded yet.
-	if(loaded) setText(text); else BaseType::setText(text);
+	if(loaded) {
+		setText(text);
+	} else {
+		BaseType::setText(loading ? str(TF_("Loading file list: %1%") % text) : text);
+	}
 
 	dirs->getData(treeRoot)->setText(text);
 	dirs->redraw();