← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2804: keep the selected dir when downloading a full list

 

------------------------------------------------------------
revno: 2804
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-01-08 15:35:15 +0100
message:
  keep the selected dir when downloading a full list
modified:
  win32/DirectoryListingFrame.cpp
  win32/DirectoryListingFrame.h


--
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 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp	2012-01-08 14:08:54 +0000
+++ win32/DirectoryListingFrame.cpp	2012-01-08 14:35:15 +0000
@@ -484,11 +484,7 @@
 
 void DirectoryListingFrame::loadXML(const string& txt) {
 	try {
-		string prevDir;
-		auto sel = dirs->getSelectedData();
-		if(sel && sel->type == ItemInfo::DIRECTORY) {
-			prevDir = dl->getPath(sel->dir);
-		}
+		auto sel = getSelectedDir();
 
 		path = QueueManager::getInstance()->getListPath(dl->getUser()) + ".xml";
 
@@ -528,8 +524,8 @@
 		});
 		refreshTree(Text::toT(Util::toNmdcFile(base)));
 
-		if(!prevDir.empty()) {
-			selectItem(Text::toT(prevDir));
+		if(!sel.empty()) {
+			selectItem(Text::toT(sel));
 		}
 
 	} catch(const Exception& e) {
@@ -590,6 +586,16 @@
 	status->setText(STATUS_STATUS, str(TFN_("Matched %1% file", "Matched %1% files", matched) % matched));
 }
 
+void DirectoryListingFrame::UserHolder::getList() {
+	// imitate UserInfoBase::getList but keep the current dir and dl a full list.
+	auto w = lists[user];
+	try {
+		QueueManager::getInstance()->addList(user, QueueItem::FLAG_CLIENT_VIEW, w->getSelectedDir());
+	} catch(const Exception& e) {
+		w->status->setText(STATUS_STATUS, Text::toT(e.getError()));
+	}
+}
+
 void DirectoryListingFrame::UserHolder::matchQueue() {
 	lists[user]->handleMatchQueue();
 }
@@ -1005,12 +1011,20 @@
 
 void DirectoryListingFrame::selectItem(const tstring& name) {
 	auto ht = findItem(treeRoot, name);
-	if(ht != NULL) {
+	if(ht) {
 		dirs->setSelected(ht);
 		dirs->ensureVisible(ht);
 	}
 }
 
+string DirectoryListingFrame::getSelectedDir() const {
+	auto sel = dirs->getSelectedData();
+	if(sel && sel->type == ItemInfo::DIRECTORY) {
+		return dl->getPath(sel->dir);
+	}
+	return Util::emptyString;
+}
+
 void DirectoryListingFrame::addDir(DirectoryListing::Directory* d, HTREEITEM parent) {
 	auto item = dirs->insert(parent, new ItemInfo(d));
 	if(d->getAdls())

=== modified file 'win32/DirectoryListingFrame.h'
--- win32/DirectoryListingFrame.h	2012-01-07 16:20:01 +0000
+++ win32/DirectoryListingFrame.h	2012-01-08 14:35:15 +0000
@@ -178,9 +178,13 @@
 	std::unique_ptr<DirectoryListing> dl;
 	string path;
 
-	// override the default match-queue method not to download the file list again.
 	struct UserHolder : UserInfoBase {
 		UserHolder(const HintedUser& u) : UserInfoBase(u) { }
+
+		// override the get-list method to keep the current directory and dl a full list.
+		void getList();
+
+		// override the default match-queue method not to download the file list again.
 		void matchQueue();
 	} user;
 
@@ -260,6 +264,7 @@
 	void updateDir(DirectoryListing::Directory* d, HTREEITEM parent);
 	HTREEITEM findItem(HTREEITEM ht, const tstring& name);
 	void selectItem(const tstring& name);
+	string getSelectedDir() const;
 	void updateTitle();
 
 	void loadFile(const tstring& dir);