← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2134: magnet link additions

 

------------------------------------------------------------
revno: 2134
committer: poy <poy@xxxxxxxxxx>
branch nick: repo
timestamp: Sat 2010-05-08 18:17:17 +0200
message:
  magnet link additions
modified:
  changelog.txt
  help/dialog_user_command.html
  win32/AboutDlg.cpp
  win32/DirectoryListingFrame.cpp
  win32/QueueFrame.cpp
  win32/SearchFrame.cpp
  win32/SearchFrame.h
  win32/TransferView.cpp
  win32/WinUtil.cpp
  win32/WinUtil.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 'changelog.txt'
--- changelog.txt	2010-05-04 17:44:05 +0000
+++ changelog.txt	2010-05-08 16:17:17 +0000
@@ -11,6 +11,8 @@
 * Fix 'Share hidden files' checkbox value saved to a wrong setting (emtee)
 * [L#562099] Fix encoding problems (poy)
 * [L#556011] Respect the font style in chat windows
+* [L#551319] Add %[fileMN] to user command params (thanks darkklor)
+* Magnet links are now produced with a size (xl) param
 
 -- 0.761 2010-03-14 --
 * [L#533840] Fix crashes with themed menus (poy)

=== modified file 'help/dialog_user_command.html'
--- help/dialog_user_command.html	2010-02-07 20:28:31 +0000
+++ help/dialog_user_command.html	2010-05-08 16:17:17 +0000
@@ -60,13 +60,15 @@
 available:
 </p>
 <ul style="margin-left: 40px;">
-  <li>%[fileFN]: Filename (search, file list, and transfer view contexts only)</li>
-  <li>%[fileSIsize]: File size (search, file list contexts only)</li>
-  <li>%[fileSIshort]: File size, short version including units
-(search, file list contexts only)</li>
-  <li>%[fileTR]: TTH for the file, or "NONE" (search, file list contexts only)</li>
-  <li>%[type]: "File" or "Directory" (directory context only)</li>
-  <li>%[line:<i>reason</i>]: Opens up a window asking for "<i>reason</i>"</li>
+	<li>%[fileFN]: Filename (search, file list, and transfer view contexts only)</li>
+	<li>%[fileSIsize]: File size (search, file list contexts only)</li>
+	<li>%[fileSIshort]: File size, short version including units (search, file list contexts only)</li>
+	<li>%[fileTR]: TTH for the file, or "NONE" (search, file list contexts only)</li>
+	<li>%[fileMN]:
+	<a href="http://en.wikipedia.org/wiki/Magnet_link"; target="_blank" class="external">magnet link</a>
+	to the file (search, file list contexts only)</li>
+	<li>%[type]: "File" or "Directory" (directory context only)</li>
+	<li>%[line:<i>reason</i>]: Opens up a window asking for "<i>reason</i>"</li>
 </ul>
 <p>
 In addition to these variables, all of the ADC INF flags are available, with the following prefixes: <b>my</b>, <b>user</b>, and <b>hub</b>. Some may <u>not</u> be available on NMDC hubs. Many useful ones are enumerated below:

=== modified file 'win32/AboutDlg.cpp'
--- win32/AboutDlg.cpp	2010-04-18 04:32:43 +0000
+++ win32/AboutDlg.cpp	2010-05-08 16:17:17 +0000
@@ -44,7 +44,7 @@
 "krzysztof tyszecki, poison, mikejj, pur, bigmuscle, martin, jove, bart vullings, "
 "steven sheehy, tobias nygren, poy, dorian, stephan hohe, mafa_45, mikael eman, james ross, "
 "stanislav maslovski, david grundberg, pavel andreev, yakov suraev, kulmegil, smir, emtee, individ, "
-"pseudonym, crise, ben, ximin luo, radox, razzloss, Andrew Browne. "
+"pseudonym, crise, ben, ximin luo, radox, razzloss, andrew browne, darkklor. "
 "Keep it coming!";
 
 AboutDlg::AboutDlg(dwt::Widget* parent) :

=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp	2010-03-20 14:12:35 +0000
+++ win32/DirectoryListingFrame.cpp	2010-05-08 16:17:17 +0000
@@ -381,7 +381,7 @@
 
 		menu->appendSeparator();
 
-		WinUtil::addHashItems(menu, ii->file->getTTH(), Text::toT(ii->file->getName()));
+		WinUtil::addHashItems(menu, ii->file->getTTH(), Text::toT(ii->file->getName()), ii->file->getSize());
 	}
 
 	if((ii->type == ItemInfo::FILE && ii->file->getAdls()) ||
@@ -974,6 +974,7 @@
 			ucParams["fileSI"] = Util::toString(ii->file->getSize());
 			ucParams["fileSIshort"] = Util::formatBytes(ii->file->getSize());
 			ucParams["fileTR"] = ii->file->getTTH().toBase32();
+			ucParams["fileMN"] = WinUtil::makeMagnet(ii->file->getTTH(), ii->file->getName(), ii->file->getSize());
 		} else {
 			ucParams["type"] = "Directory";
 			ucParams["fileFN"] = dl->getPath(ii->dir) + ii->dir->getName();

=== modified file 'win32/QueueFrame.cpp'
--- win32/QueueFrame.cpp	2010-02-14 16:06:46 +0000
+++ win32/QueueFrame.cpp	2010-05-08 16:17:17 +0000
@@ -853,7 +853,7 @@
 MenuPtr QueueFrame::makeSingleMenu(QueueItemInfo* qii) {
 	MenuPtr menu = addChild(WinUtil::Seeds::menu);
 
-	WinUtil::addHashItems(menu, qii->getTTH(), Text::toT(Util::getFileName(qii->getTarget())));
+	WinUtil::addHashItems(menu, qii->getTTH(), Text::toT(Util::getFileName(qii->getTarget())), qii->getSize());
 	menu->appendItem(T_("&Move/Rename"), std::tr1::bind(&QueueFrame::handleMove, this));
 	menu->appendItem(T_("Re&check integrity"), std::tr1::bind(&QueueFrame::handleRecheck, this));
 	addPriorityMenu(menu);

=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp	2010-02-14 16:06:46 +0000
+++ win32/SearchFrame.cpp	2010-05-08 16:17:17 +0000
@@ -376,21 +376,25 @@
 }
 
 void SearchFrame::SearchInfo::CheckTTH::operator()(SearchInfo* si) {
+	const SearchResultPtr& sr = si->srs[0];
+
 	if(firstTTH) {
-		tth = si->columns[COLUMN_TTH];
 		hasTTH = true;
 		firstTTH = false;
+		tth = sr->getTTH();
+		name = si->getText(COLUMN_FILENAME);
+		size = sr->getSize();
 	} else if(hasTTH) {
-		if(tth != si->columns[COLUMN_TTH]) {
+		if(tth != sr->getTTH()) {
 			hasTTH = false;
 		}
 	}
 
 	if(firstHubs && hubs.empty()) {
-		hubs = ClientManager::getInstance()->getHubs(si->srs[0]->getUser()->getCID(), si->srs[0]->getHubURL());
+		hubs = ClientManager::getInstance()->getHubs(sr->getUser()->getCID(), sr->getHubURL());
 		firstHubs = false;
 	} else if(!hubs.empty()) {
-		Util::intersect(hubs, ClientManager::getInstance()->getHubs(si->srs[0]->getUser()->getCID(), si->srs[0]->getHubURL()));
+		Util::intersect(hubs, ClientManager::getInstance()->getHubs(sr->getUser()->getCID(), sr->getHubURL()));
 	}
 }
 
@@ -682,7 +686,7 @@
 
 	if(checkTTH.hasTTH) {
 		menu->appendSeparator();
-		WinUtil::addHashItems(menu, TTHValue(Text::fromT(checkTTH.tth)), results->getSelectedData()->getText(COLUMN_FILENAME));
+		WinUtil::addHashItems(menu, checkTTH.tth, checkTTH.name, checkTTH.size);
 	}
 
 	menu->appendSeparator();
@@ -718,7 +722,7 @@
 	if(checkTTH.hasTTH) {
 		targets.clear();
 
-		QueueManager::getInstance()->getTargets(TTHValue(Text::fromT(checkTTH.tth)), targets);
+		QueueManager::getInstance()->getTargets(checkTTH.tth, targets);
 		if(targets.size() > 0) {
 			menu->appendSeparator();
 			for(StringIter i = targets.begin(); i != targets.end(); ++i)
@@ -1013,6 +1017,7 @@
 			if(sr->getType() == SearchResult::TYPE_FILE) {
 				ucParams["fileTR"] = sr->getTTH().toBase32();
 			}
+			ucParams["fileMN"] = WinUtil::makeMagnet(sr->getTTH(), sr->getFile(), sr->getSize());
 
 			// compatibility with 0.674 and earlier
 			ucParams["file"] = ucParams["fileFN"];

=== modified file 'win32/SearchFrame.h'
--- win32/SearchFrame.h	2010-02-11 21:44:13 +0000
+++ win32/SearchFrame.h	2010-05-08 16:17:17 +0000
@@ -111,7 +111,9 @@
 			bool op;
 			bool hasTTH;
 			bool firstTTH;
-			tstring tth;
+			TTHValue tth;
+			tstring name;
+			int64_t size;
 		};
 
 		const tstring& getText(int col) const { return columns[col]; }

=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp	2010-03-01 14:21:27 +0000
+++ win32/TransferView.cpp	2010-05-08 16:17:17 +0000
@@ -219,7 +219,7 @@
 
 		MenuPtr menu = addChild(WinUtil::Seeds::menu);
 		DownloadInfo* di = downloads->getSelectedData();
-		WinUtil::addHashItems(menu, di->tth, di->columns[DOWNLOAD_COLUMN_FILE]);
+		WinUtil::addHashItems(menu, di->tth, di->columns[DOWNLOAD_COLUMN_FILE], di->size);
 		menu->open(pt);
 
 		return true;

=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp	2010-03-26 21:55:05 +0000
+++ win32/WinUtil.cpp	2010-05-08 16:17:17 +0000
@@ -571,10 +571,10 @@
 	}
 }
 
-void WinUtil::addHashItems(const dwt::Menu::ObjectType& menu, const TTHValue& tth, const tstring& filename) {
+void WinUtil::addHashItems(const dwt::Menu::ObjectType& menu, const TTHValue& tth, const tstring& filename, int64_t size) {
 	menu->appendItem(T_("Search for alternates"), std::tr1::bind(&WinUtil::searchHash, tth));
 	menu->appendItem(T_("Lookup TTH at Bitzi.com"), std::tr1::bind(WinUtil::bitziLink, tth));
-	menu->appendItem(T_("Copy magnet link to clipboard"), std::tr1::bind(&WinUtil::copyMagnet, tth, filename));
+	menu->appendItem(T_("Copy magnet link to clipboard"), std::tr1::bind(&WinUtil::copyMagnet, tth, filename, size));
 }
 
 void WinUtil::bitziLink(const TTHValue& aHash) {
@@ -585,13 +585,19 @@
 	openLink(_T("http://bitzi.com/lookup/tree:tiger:";) + Text::toT(aHash.toBase32()));
 }
 
-void WinUtil::copyMagnet(const TTHValue& aHash, const tstring& aFile) {
+void WinUtil::copyMagnet(const TTHValue& aHash, const tstring& aFile, int64_t size) {
 	if(!aFile.empty()) {
-		setClipboard(_T("magnet:?xt=urn:tree:tiger:") + Text::toT(aHash.toBase32()) + _T("&dn=") + Text::toT(
-			Util::encodeURI(Text::fromT(aFile))));
+		setClipboard(Text::toT(makeMagnet(aHash, Text::fromT(aFile), size)));
 	}
 }
 
+string WinUtil::makeMagnet(const TTHValue& aHash, const string& aFile, int64_t size) {
+	string ret = "magnet:?xt=urn:tree:tiger:" + aHash.toBase32() + "&dn=" + Util::encodeURI(aFile);
+	if(size > 0)
+		ret += "&xl=" + Util::toString(size);
+	return ret;
+}
+
 void WinUtil::searchHash(const TTHValue& aHash) {
 	SearchFrame::openWindow(mainWindow->getTabView(), Text::toT(aHash.toBase32()), SearchManager::TYPE_TTH);
 }

=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h	2010-03-26 17:15:26 +0000
+++ win32/WinUtil.h	2010-05-08 16:17:17 +0000
@@ -173,10 +173,11 @@
 	static void reducePaths(string& message);
 
 	// Hash related
-	static void addHashItems(const dwt::Menu::ObjectType& menu, const TTHValue& tth, const tstring& filename);
-	static void bitziLink(const TTHValue& /*aHash*/);
-	static void copyMagnet(const TTHValue& /*aHash*/, const tstring& /*aFile*/);
-	static void searchHash(const TTHValue& /*aHash*/);
+	static void addHashItems(const dwt::Menu::ObjectType& menu, const TTHValue& tth, const tstring& filename, int64_t size);
+	static void bitziLink(const TTHValue& aHash);
+	static void copyMagnet(const TTHValue& aHash, const tstring& aFile, int64_t size);
+	static void searchHash(const TTHValue& aHash);
+	static string makeMagnet(const TTHValue& aHash, const string& aFile, int64_t size);
 
 	static void addLastDir(const tstring& dir);