← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2461: turn predefined window params into flags

 

------------------------------------------------------------
revno: 2461
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-03-18 16:40:31 +0100
message:
  turn predefined window params into flags
modified:
  dcpp/FavoriteManager.cpp
  dcpp/WindowInfo.cpp
  dcpp/WindowInfo.h
  dcpp/WindowManager.cpp
  win32/DirectoryListingFrame.cpp
  win32/HubFrame.cpp
  win32/MainWindow.cpp
  win32/PrivateFrame.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 'dcpp/FavoriteManager.cpp'
--- dcpp/FavoriteManager.cpp	2011-03-16 18:23:54 +0000
+++ dcpp/FavoriteManager.cpp	2011-03-18 15:40:31 +0000
@@ -510,7 +510,7 @@
 			FavoriteHubEntryList hubs = getFavoriteHubs(i->first);
 			for(FavoriteHubEntryList::const_iterator hub = hubs.begin(), hub_end = hubs.end(); hub != hub_end; ++hub) {
 				WindowParams params;
-				params[WindowInfo::address] = WindowParam((*hub)->getServer(), true);
+				params[WindowInfo::address] = WindowParam((*hub)->getServer(), WindowParam::FLAG_IDENTIFIES);
 				WindowManager::getInstance()->add(WindowManager::hub(), params);
 			}
 		}

=== modified file 'dcpp/WindowInfo.cpp'
--- dcpp/WindowInfo.cpp	2011-03-16 18:23:54 +0000
+++ dcpp/WindowInfo.cpp	2011-03-18 15:40:31 +0000
@@ -24,8 +24,6 @@
 namespace dcpp {
 
 const string WindowInfo::address = "Address";
-const string WindowInfo::cid = "CID";
-const string WindowInfo::fileList = "FileList";
 
 WindowInfo::WindowInfo(const string& id_, const WindowParams& params_) :
 id(id_),
@@ -40,10 +38,10 @@
 	// compare every identifying params.
 	int rParams = 0;
 	for(auto i = rhs.params.cbegin(), iend = rhs.params.cend(); i != iend; ++i)
-		if(i->second.identifies)
+		if(i->second.isSet(WindowParam::FLAG_IDENTIFIES))
 			++rParams;
 	for(auto i = params.cbegin(), iend = params.cend(); i != iend; ++i) {
-		if(i->second.identifies) {
+		if(i->second.isSet(WindowParam::FLAG_IDENTIFIES)) {
 			auto ri = rhs.params.find(i->first);
 			if(ri == rhs.params.end())
 				return false;

=== modified file 'dcpp/WindowInfo.h'
--- dcpp/WindowInfo.h	2011-03-16 18:23:54 +0000
+++ dcpp/WindowInfo.h	2011-03-18 15:40:31 +0000
@@ -20,16 +20,23 @@
 #define DCPLUSPLUS_DCPP_WINDOW_INFO_H
 
 #include "forward.h"
+#include "Flags.h"
 #include "Util.h"
 
 namespace dcpp {
 
-struct WindowParam {
-	WindowParam() : identifies(false) { }
-	WindowParam(const string& content, bool identifies) : content(content), identifies(identifies) { }
+struct WindowParam : Flags {
+	WindowParam() : Flags() { }
+	WindowParam(const string& content, Flags::MaskType flags = 0) : Flags(flags), content(content) { }
+
+	enum {
+		FLAG_IDENTIFIES = 1 << 1, /// this WindowParam determines the uniqueness of the WindowInfo holding it.
+
+		FLAG_CID = 1 << 2, /// this WindowParam indicates a CID for an user whose information shall be saved on exit.
+		FLAG_FILELIST = 1 << 3 /// this WindowParam specifies the path to a file list that must not be deleted on exit.
+	};
 
 	string content;
-	bool identifies; /// whether this param determines the uniqueness of the WindowInfo holding it.
 
 	operator const string&() const { return content; }
 	template<typename T> bool operator==(const T& str) const { return content == str; }
@@ -49,12 +56,6 @@
 
 	/// special param for hub addresses.
 	static const string address;
-
-	/// special param that indicates a CID for an user whose information shall be saved on exit.
-	static const string cid;
-
-	/// special param for paths to file lists that must not be deleted on exit.
-	static const string fileList;
 };
 
 } // namespace dcpp

=== modified file 'dcpp/WindowManager.cpp'
--- dcpp/WindowManager.cpp	2011-03-18 15:07:59 +0000
+++ dcpp/WindowManager.cpp	2011-03-18 15:40:31 +0000
@@ -147,13 +147,17 @@
 
 void WindowManager::prepareSave(const WindowInfoList& infoList) const {
 	for(auto wi = infoList.cbegin(), wiend = infoList.cend(); wi != wiend; ++wi) {
-		auto i = wi->getParams().find(WindowInfo::cid);
-		if(i != wi->getParams().end())
-			ClientManager::getInstance()->saveUser(CID(i->second));
-
-		i = wi->getParams().find(WindowInfo::fileList);
-		if(i != wi->getParams().end() && !i->second.empty())
-			QueueManager::getInstance()->noDeleteFileList(i->second);
+		for(auto i = wi->getParams().cbegin(), iend = wi->getParams().cend(); i != iend; ++i) {
+			auto& param = i->second;
+			if(param.empty())
+				continue;
+
+			if(param.isSet(WindowParam::FLAG_CID))
+				ClientManager::getInstance()->saveUser(CID(param));
+
+			if(param.isSet(WindowParam::FLAG_FILELIST))
+				QueueManager::getInstance()->noDeleteFileList(param);
+		}
 	}
 }
 
@@ -167,13 +171,24 @@
 
 		WindowParams params;
 		xml.stepIn();
+
 		while(xml.findChild("Param")) {
 			const string& id_ = xml.getChildAttrib("Id");
 			if(id_.empty())
 				continue;
-			params[id_] = WindowParam(xml.getChildData(), !xml.getBoolChildAttrib("Opt")
-				&& id_ != "Title"); /// @todo for back compat - remove later
+
+			WindowParam param(xml.getChildData());
+
+			if(!xml.getBoolChildAttrib("Opt") && id_ != "Title") /// @todo "Title" check for back compat - remove later
+				param.setFlag(WindowParam::FLAG_IDENTIFIES);
+			if(xml.getBoolChildAttrib("CID"))
+				param.setFlag(WindowParam::FLAG_CID);
+			if(xml.getBoolChildAttrib("FileList"))
+				param.setFlag(WindowParam::FLAG_FILELIST);
+
+			params[id_] = param;
 		}
+
 		xml.stepOut();
 
 		(this->*handler)(id, params);
@@ -188,12 +203,19 @@
 
 	if(!info.getParams().empty()) {
 		xml.stepIn();
+
 		for(auto i = info.getParams().cbegin(), iend = info.getParams().cend(); i != iend; ++i) {
 			xml.addTag("Param", i->second);
 			xml.addChildAttrib("Id", i->first);
-			if(!i->second.identifies)
+
+			if(!i->second.isSet(WindowParam::FLAG_IDENTIFIES))
 				xml.addChildAttrib("Opt", true);
+			if(i->second.isSet(WindowParam::FLAG_CID))
+				xml.addChildAttrib("CID", true);
+			if(i->second.isSet(WindowParam::FLAG_FILELIST))
+				xml.addChildAttrib("FileList", true);
 		}
+
 		xml.stepOut();
 	}
 }

=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp	2011-03-18 15:07:59 +0000
+++ win32/DirectoryListingFrame.cpp	2011-03-18 15:40:31 +0000
@@ -131,18 +131,19 @@
 WindowParams DirectoryListingFrame::getWindowParams() const {
 	WindowParams ret;
 	addRecentParams(ret);
-	ret[WindowInfo::cid] = WindowParam(dl->getUser().user->getCID().toBase32(), false);
-	ret[WindowInfo::fileList] = WindowParam((dl->getUser() == ClientManager::getInstance()->getMe()) ? "" : path, true);
+	ret["CID"] = WindowParam(dl->getUser().user->getCID().toBase32(), WindowParam::FLAG_CID);
+	ret["FileList"] = WindowParam((dl->getUser() == ClientManager::getInstance()->getMe()) ? "" : path,
+		WindowParam::FLAG_IDENTIFIES | WindowParam::FLAG_FILELIST);
 	ItemInfo* ii = dirs->getSelectedData();
 	if(ii && ii->type == ItemInfo::DIRECTORY)
-		ret["Directory"] = WindowParam(dl->getPath(ii->dir), false);
-	ret["Hub"] = WindowParam(dl->getUser().hint, false);
-	ret["Speed"] = WindowParam(Util::toString(speed), false);
+		ret["Directory"] = WindowParam(dl->getPath(ii->dir));
+	ret["Hub"] = WindowParam(dl->getUser().hint);
+	ret["Speed"] = WindowParam(Util::toString(speed));
 	return ret;
 }
 
 void DirectoryListingFrame::parseWindowParams(TabViewPtr parent, const WindowParams& params) {
-	auto path = params.find(WindowInfo::fileList);
+	auto path = params.find("FileList");
 	auto dir = params.find("Directory");
 	auto hub = params.find("Hub");
 	auto speed = params.find("Speed");
@@ -163,7 +164,7 @@
 }
 
 bool DirectoryListingFrame::isFavorite(const WindowParams& params) {
-	auto path = params.find(WindowInfo::fileList);
+	auto path = params.find("FileList");
 	if(path != params.end() && !(path->second == "OwnList") && File::getSize(path->second) != -1) {
 		UserPtr u = DirectoryListing::getUserFromFilename(path->second);
 		if(u)

=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2011-03-16 18:23:54 +0000
+++ win32/HubFrame.cpp	2011-03-18 15:40:31 +0000
@@ -100,7 +100,7 @@
 WindowParams HubFrame::getWindowParams() const {
 	WindowParams ret;
 	addRecentParams(ret);
-	ret[WindowInfo::address] = WindowParam(url, true);
+	ret[WindowInfo::address] = WindowParam(url, WindowParam::FLAG_IDENTIFIES);
 	return ret;
 }
 

=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp	2011-03-18 15:07:59 +0000
+++ win32/MainWindow.cpp	2011-03-18 15:40:31 +0000
@@ -607,7 +607,7 @@
 }
 
 void addActiveParam(WindowParams& params) {
-	params["Active"] = WindowParam("1", false);
+	params["Active"] = WindowParam("1");
 }
 
 template<typename T, typename configureF>

=== modified file 'win32/PrivateFrame.cpp'
--- win32/PrivateFrame.cpp	2011-03-16 18:23:54 +0000
+++ win32/PrivateFrame.cpp	2011-03-18 15:40:31 +0000
@@ -88,14 +88,14 @@
 WindowParams PrivateFrame::getWindowParams() const {
 	WindowParams ret;
 	addRecentParams(ret);
-	ret[WindowInfo::cid] = WindowParam(replyTo.getUser().user->getCID().toBase32(), true);
-	ret["Hub"] = WindowParam(replyTo.getUser().hint, false);
-	ret["LogPath"] = WindowParam(getLogPath(), false);
+	ret["CID"] = WindowParam(replyTo.getUser().user->getCID().toBase32(), WindowParam::FLAG_IDENTIFIES | WindowParam::FLAG_CID);
+	ret["Hub"] = WindowParam(replyTo.getUser().hint);
+	ret["LogPath"] = WindowParam(getLogPath());
 	return ret;
 }
 
 void PrivateFrame::parseWindowParams(TabViewPtr parent, const WindowParams& params) {
-	auto cid = params.find(WindowInfo::cid);
+	auto cid = params.find("CID");
 	auto hub = params.find("Hub");
 	if(cid != params.end() && hub != params.end()) {
 		auto logPath = params.find("LogPath");
@@ -105,7 +105,7 @@
 }
 
 bool PrivateFrame::isFavorite(const WindowParams& params) {
-	auto cid = params.find(WindowInfo::cid);
+	auto cid = params.find("CID");
 	if(cid != params.end()) {
 		UserPtr u = ClientManager::getInstance()->getUser(CID(cid->second));
 		if(u)