linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #06707
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3231: transfer list fixes
------------------------------------------------------------
revno: 3231
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2013-03-22 15:59:39 +0100
message:
transfer list fixes
modified:
dwt/include/dwt/widgets/TableTree.h
dwt/src/widgets/TableTree.cpp
win32/SearchFrame.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-16 13:25:11 +0000
+++ dwt/include/dwt/widgets/TableTree.h 2013-03-22 14:59:39 +0000
@@ -62,6 +62,8 @@
virtual bool handleMessage(const MSG& msg, LRESULT& retVal);
+ /** Insert a child item.
+ @note The list should be resorted and redrawn for this to take effect. */
void insertChild(LPARAM parent, LPARAM child);
void collapse(LPARAM parent);
void expand(LPARAM parent);
=== modified file 'dwt/src/widgets/TableTree.cpp'
--- dwt/src/widgets/TableTree.cpp 2013-03-21 23:03:56 +0000
+++ dwt/src/widgets/TableTree.cpp 2013-03-22 14:59:39 +0000
@@ -100,13 +100,24 @@
void TableTree::insertChild(LPARAM parent, LPARAM child) {
items[parent].children.push_back(child);
children[child] = parent;
+
+ if(items[parent].expanded) {
+ LVITEM item = { LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_INDENT, findData(parent) + 1 };
+ item.pszText = LPSTR_TEXTCALLBACK;
+ item.iImage = I_IMAGECALLBACK;
+ item.lParam = child;
+ item.iIndent = 2;
+ sendMsg(LVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&item));
+ }
}
void TableTree::collapse(LPARAM parent) {
util::HoldRedraw hold { this };
- auto pos = findData(parent) + 1;
- for(size_t i = 0, n = items[parent].children.size(); i < n; ++i) {
- sendMsg(LVM_DELETEITEM, pos, 0);
+ for(auto child: items[parent].children) {
+ auto pos = findData(child);
+ if(pos != -1) {
+ sendMsg(LVM_DELETEITEM, pos, 0);
+ }
}
items[parent].switchExp(*this);
}
@@ -122,6 +133,7 @@
item.lParam = child;
sendMsg(LVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&item));
}
+ resort();
items[parent].switchExp(*this);
}
@@ -309,7 +321,7 @@
if((lv.mask & LVIF_INDENT) != LVIF_INDENT) {
lv.mask |= LVIF_INDENT;
}
- ++lv.iIndent;
+ lv.iIndent = 1;
}
int TableTree::handleSort(LPARAM& lhs, LPARAM& rhs) {
=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp 2013-03-21 23:03:56 +0000
+++ win32/SearchFrame.cpp 2013-03-22 14:59:39 +0000
@@ -654,6 +654,7 @@
}
}
}
+ results->resort();
updateStatusCount();
}
=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp 2013-03-21 23:03:56 +0000
+++ win32/TransferView.cpp 2013-03-22 14:59:39 +0000
@@ -142,14 +142,12 @@
switch(col) {
case COLUMN_STATUS:
{
- if(!a->transferred && !b->transferred)
- return compare(a->size, b->size);
- if(!b->transferred)
- return -1;
- if(!a->transferred)
- return 1;
- return compare(static_cast<double>(a->size) / static_cast<double>(a->transferred),
- static_cast<double>(b->size) / static_cast<double>(b->transferred));
+ // avoid returning 0
+ auto ret = !a->transferred && !b->transferred ? compare(a->size, b->size) :
+ !b->transferred ? -1 :
+ !a->transferred ? 1 :
+ compare(a->size / a->transferred, b->size / b->transferred);
+ return ret ? ret : compare(a->getText(COLUMN_PATH), b->getText(COLUMN_PATH));
}
case COLUMN_TIMELEFT: return compare(a->timeleft(), b->timeleft());
case COLUMN_SPEED: return compare(a->speed, b->speed);
@@ -207,16 +205,20 @@
actual = ui.actual;
transferred = ui.transferred;
size = ui.size;
- columns[COLUMN_TRANSFERRED] = str(TF_("%1% (%2$0.2f)")
- % Text::toT(Util::formatBytes(transferred))
- % (static_cast<double>(actual) / static_cast<double>(transferred)));
+ if(transferred) {
+ columns[COLUMN_TRANSFERRED] = str(TF_("%1% (%2$0.2f)")
+ % Text::toT(Util::formatBytes(transferred))
+ % (static_cast<double>(actual) / static_cast<double>(transferred)));
+ } else {
+ columns[COLUMN_TRANSFERRED].clear();
+ }
columns[COLUMN_SIZE] = Text::toT(Util::formatBytes(size));
}
if((ui.updateMask & UpdateInfo::MASK_STATUS) || (ui.updateMask & UpdateInfo::MASK_SPEED)) {
- speed = ui.speed;
+ speed = std::max(ui.speed, 0LL); // sometimes the speed is negative; avoid problems.
if(status == STATUS_RUNNING) {
- columns[COLUMN_SPEED] = str(TF_("%1%/s") % Text::toT(Util::formatBytes(static_cast<int64_t>(speed))));
+ columns[COLUMN_SPEED] = str(TF_("%1%/s") % Text::toT(Util::formatBytes(speed)));
} else {
columns[COLUMN_SPEED].clear();
}
@@ -224,7 +226,7 @@
if((ui.updateMask & UpdateInfo::MASK_STATUS) || (ui.updateMask & UpdateInfo::MASK_TRANSFERRED) || (ui.updateMask & UpdateInfo::MASK_SPEED)) {
if(status == STATUS_RUNNING) {
- columns[COLUMN_TIMELEFT] = Text::toT(Util::formatSeconds(static_cast<int64_t>(timeleft())));
+ columns[COLUMN_TIMELEFT] = Text::toT(Util::formatSeconds(timeleft()));
} else {
columns[COLUMN_TIMELEFT].clear();
}
@@ -278,8 +280,10 @@
speed = 0; transferred = startPos;
set<string> hubs;
for(auto& conn: conns) {
- speed += conn.speed;
- transferred += conn.transferred;
+ if(conn.status == ConnectionInfo::STATUS_RUNNING) {
+ speed += conn.speed;
+ transferred += conn.transferred;
+ }
hubs.insert(conn.getUser().hint);
}
@@ -291,6 +295,7 @@
}
if(conns.empty()) {
+ // this should never happen, but let's play safe.
columns[COLUMN_STATUS] = T_("Idle");
columns[COLUMN_USER].clear();
columns[COLUMN_HUB].clear();
@@ -302,10 +307,18 @@
columns[COLUMN_STATUS] = download ?
str(TFN_("Downloading from %1% user", "Downloading from %1% users", users) % users) :
str(TFN_("Uploading to %1% user", "Uploading to %1% users", users) % users);
- columns[COLUMN_USER] = str(TFN_("%1% user", "%1% users", users) % users);
- columns[COLUMN_HUB] = str(TFN_("%1% hub", "%1% hubs", hubs.size()) % hubs.size());
- columns[COLUMN_TIMELEFT] = Text::toT(Util::formatSeconds(static_cast<int64_t>(timeleft())));
- columns[COLUMN_SPEED] = str(TF_("%1%/s") % Text::toT(Util::formatBytes(static_cast<int64_t>(speed))));
+ if(users == 1) {
+ columns[COLUMN_USER] = conns.front().getText(COLUMN_USER);
+ } else {
+ columns[COLUMN_USER] = str(TF_("%1% users") % users);
+ }
+ if(hubs.size() == 1) {
+ columns[COLUMN_HUB] = conns.front().getText(COLUMN_HUB);
+ } else {
+ columns[COLUMN_HUB] = str(TF_("%1% hubs") % hubs.size());
+ }
+ columns[COLUMN_TIMELEFT] = Text::toT(Util::formatSeconds(timeleft()));
+ columns[COLUMN_SPEED] = str(TF_("%1%/s") % Text::toT(Util::formatBytes(speed)));
}
columns[COLUMN_TRANSFERRED] = Text::toT(Util::formatBytes(transferred));
@@ -637,17 +650,16 @@
TransferInfo* transfer = nullptr;
auto conn = findConn(ui.user, ui.download);
if(ui.updateMask & UpdateInfo::MASK_FILE) {
- transfer = conn ? &conn->parent : findTransfer(ui.path, ui.download);
- if(transfer) {
- transfer->tth = ui.tth;
- transfer->download = ui.download;
- transfer->path = ui.path;
- transfer->updatePath();
- } else {
+ transfer = findTransfer(ui.path, ui.download);
+ if(!transfer) {
transferItems.emplace_back(ui.tth, ui.download, ui.path);
transfer = &transferItems.back();
transfers->insert(transfer);
}
+ if(conn && &conn->parent != transfer) {
+ removeTransfer(conn->parent);
+ conn = nullptr;
+ }
if(ui.download) {
QueueManager::getInstance()->getSizeInfo(transfer->size, transfer->startPos, ui.path);
} else {
=== modified file 'win32/TransferView.h'
--- win32/TransferView.h 2013-03-21 23:03:56 +0000
+++ win32/TransferView.h 2013-03-22 14:59:39 +0000
@@ -102,7 +102,7 @@
int64_t timeleft() const;
- double speed;
+ int64_t speed;
int64_t actual;
int64_t transferred;
int64_t size;
@@ -188,8 +188,8 @@
int64_t actual;
int64_t transferred;
int64_t size;
- void setSpeed(double aSpeed) { speed = aSpeed; updateMask |= MASK_SPEED; }
- double speed;
+ void setSpeed(int64_t aSpeed) { speed = aSpeed; updateMask |= MASK_SPEED; }
+ int64_t speed;
void setStatusString(const tstring& aStatusString) { statusString = aStatusString; updateMask |= MASK_STATUS_STRING; }
tstring statusString;