← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3248: transfers

 

------------------------------------------------------------
revno: 3248
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2013-03-31 18:22:41 +0200
message:
  transfers
modified:
  dwt/include/dwt/widgets/TableTree.h
  dwt/src/widgets/TableTree.cpp
  win32/TransferView.cpp
  win32/TransferView.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 'dwt/include/dwt/widgets/TableTree.h'
--- dwt/include/dwt/widgets/TableTree.h	2013-03-22 14:59:39 +0000
+++ dwt/include/dwt/widgets/TableTree.h	2013-03-31 16:22:41 +0000
@@ -65,6 +65,7 @@
 	/** Insert a child item.
 	@note The list should be resorted and redrawn for this to take effect. */
 	void insertChild(LPARAM parent, LPARAM child);
+	void eraseChild(LPARAM child);
 	void collapse(LPARAM parent);
 	void expand(LPARAM parent);
 
@@ -100,6 +101,12 @@
 	void handleInsert(LVITEM& lv);
 	int handleSort(LPARAM& lhs, LPARAM& rhs);
 
+#ifndef _MSC_VER /// @todo workaround for VS' sucky decltype
+	void eraseChild(decltype(children)::iterator& child);
+#else
+	void eraseChild(std::unordered_map<LPARAM, LPARAM>::iterator& child);
+#endif
+
 	LRESULT sendMsg(UINT msg, WPARAM wParam, LPARAM lParam);
 };
 

=== modified file 'dwt/src/widgets/TableTree.cpp'
--- dwt/src/widgets/TableTree.cpp	2013-03-23 16:45:15 +0000
+++ dwt/src/widgets/TableTree.cpp	2013-03-31 16:22:41 +0000
@@ -111,6 +111,13 @@
 	}
 }
 
+void TableTree::eraseChild(LPARAM child) {
+	auto i = children.find(child);
+	if(i != children.end()) {
+		eraseChild(i);
+	}
+}
+
 void TableTree::collapse(LPARAM parent) {
 	util::HoldRedraw hold { this };
 
@@ -307,14 +314,7 @@
 
 	auto child = children.find(param);
 	if(child != children.end()) {
-		auto& item = items[child->second];
-		auto& cont = item.children;
-		cont.erase(std::remove(cont.begin(), cont.end(), param), cont.end());
-		if(cont.empty()) {
-			item.glyphRect = Rectangle();
-			item.switchExp(*this);
-		}
-		children.erase(child);
+		eraseChild(child);
 	}
 }
 
@@ -359,6 +359,24 @@
 	return 0;
 }
 
+#ifndef _MSC_VER /// @todo workaround for VS' sucky decltype
+void TableTree::eraseChild(decltype(children)::iterator& child) {
+#else
+void TableTree::eraseChild(std::unordered_map<LPARAM, LPARAM>::iterator& child) {
+#endif
+	auto& item = items[child->second];
+	auto& cont = item.children;
+	if(item.expanded) {
+		sendMsg(LVM_DELETEITEM, findData(child->first), 0);
+	}
+	cont.erase(std::remove(cont.begin(), cont.end(), child->first), cont.end());
+	if(cont.empty()) {
+		item.glyphRect = Rectangle();
+		item.switchExp(*this);
+	}
+	children.erase(child);
+}
+
 LRESULT TableTree::sendMsg(UINT msg, WPARAM wParam, LPARAM lParam) {
 	// send with a direct dispatcher call to avoid loops (since we catch messages in handleMessage).
 	MSG directMsg { handle(), msg, wParam, lParam };

=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp	2013-03-30 16:33:09 +0000
+++ win32/TransferView.cpp	2013-03-31 16:22:41 +0000
@@ -191,9 +191,14 @@
 	}
 
 	if(ui.updateMask & UpdateInfo::MASK_TRANSFERRED) {
+		if(parent.download && ui.transferred > transferred) {
+			parent.transferred += ui.transferred - transferred;
+		}
+
 		actual = ui.actual;
 		transferred = ui.transferred;
 		size = ui.size;
+
 		if(transferred > 0) {
 			columns[COLUMN_TRANSFERRED] = str(TF_("%1% (%2$0.2f)")
 				% Text::toT(Util::formatBytes(transferred))
@@ -201,6 +206,7 @@
 		} else {
 			columns[COLUMN_TRANSFERRED].clear();
 		}
+
 		if(size > 0) {
 			columns[COLUMN_SIZE] = Text::toT(Util::formatBytes(size));
 		} else {
@@ -265,8 +271,7 @@
 	tth(tth),
 	download(download),
 	path(path),
-	tempPath(tempPath),
-	startPos(0)
+	tempPath(tempPath)
 {
 }
 
@@ -281,7 +286,7 @@
 void TransferView::TransferInfo::update() {
 	timeleft = 0;
 	speed = 0;
-	transferred = startPos;
+	if(!download) { transferred = 0; }
 
 	if(conns.empty()) {
 		// this should never happen, but let's play safe.
@@ -291,13 +296,17 @@
 		return;
 	}
 
+	size_t running = 0;
 	set<string> hubs;
 	for(auto& conn: conns) {
-		if(!download) { timeleft += conn.timeleft; }
+		if(!download) {
+			timeleft += conn.timeleft;
+			transferred += conn.transferred;
+		}
 		if(conn.status == ConnectionInfo::STATUS_RUNNING) {
+			++running;
 			speed += conn.speed;
 		}
-		transferred += conn.transferred;
 		hubs.insert(conn.getUser().hint);
 	}
 
@@ -310,7 +319,9 @@
 		timeleft = static_cast<double>(size - transferred) / speed;
 	}
 
-	if(conns.size() == 1) {
+	auto users = conns.size();
+
+	if(users == 1) {
 		auto& conn = conns.front();
 		columns[COLUMN_STATUS] = conn.getText(COLUMN_STATUS);
 		columns[COLUMN_USER] = conn.getText(COLUMN_USER);
@@ -320,10 +331,14 @@
 		columns[COLUMN_COUNTRY] = conn.getText(COLUMN_COUNTRY);
 
 	} else {
-		auto users = conns.size();
-		columns[COLUMN_STATUS] = download ?
-			str(TF_("Downloading from %1% users") % users) :
-			str(TF_("Uploading to %1% users") % users);
+		if(running > 0) {
+			tstring userStr = Text::toT(Util::toString(running) + "/" + Util::toString(users));
+			columns[COLUMN_STATUS] = download ?
+				str(TF_("Downloading from %1% users") % userStr) :
+				str(TF_("Uploading to %1% users") % userStr);
+		} else {
+			columns[COLUMN_STATUS] = T_("Idle");
+		}
 		columns[COLUMN_USER] = str(TF_("%1% users") % users);
 		if(hubs.size() == 1) {
 			columns[COLUMN_HUB] = conns.front().getText(COLUMN_HUB);
@@ -658,11 +673,11 @@
 			transferItems.emplace_back(ui.tth, ui.download, ui.path, ui.tempPath);
 			transfer = &transferItems.back();
 			transfers->insert(transfer);
-		}
-		if(ui.download) {
-			QueueManager::getInstance()->getSizeInfo(transfer->size, transfer->startPos, ui.path);
-		} else {
-			transfer->size = File::getSize(ui.path);
+			if(ui.download) {
+				QueueManager::getInstance()->getSizeInfo(transfer->size, transfer->transferred, ui.path);
+			} else {
+				transfer->size = File::getSize(ui.path);
+			}
 		}
 
 	} else {
@@ -742,7 +757,7 @@
 }
 
 void TransferView::removeConn(ConnectionInfo& conn) {
-	transfers->erase(&conn);
+	transfers->eraseChild(reinterpret_cast<LPARAM>(&conn));
 
 	auto& transfer = conn.parent;
 

=== modified file 'win32/TransferView.h'
--- win32/TransferView.h	2013-03-30 14:28:28 +0000
+++ win32/TransferView.h	2013-03-31 16:22:41 +0000
@@ -148,7 +148,6 @@
 		bool download;
 		string path;
 		string tempPath;
-		int64_t startPos;
 
 		list<ConnectionInfo> conns;
 	};