mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-03 20:04:20 -04:00
-when a file is downloaded through different peers, all peers are put together
under a single root line. line is click-able, when collapsed it displays all download peers -sources column shows number of peers as online (offline) -name column for root/peer shows filename/peername git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1261 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4694ff22d5
commit
3d37a0c242
2 changed files with 236 additions and 175 deletions
|
@ -80,6 +80,8 @@ TransfersDialog::TransfersDialog(QWidget *parent)
|
|||
|
||||
ui.downloadList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
ui.downloadList->setRootIsDecorated(true);
|
||||
|
||||
|
||||
/* Set header resize modes and initial section sizes Downloads TreeView*/
|
||||
QHeaderView * _header = ui.downloadList->header () ;
|
||||
|
@ -115,8 +117,11 @@ TransfersDialog::TransfersDialog(QWidget *parent)
|
|||
ui.uploadsList->setItemDelegate(ULDelegate);
|
||||
|
||||
ui.uploadsList->setAutoScroll(false) ;
|
||||
|
||||
ui.uploadsList->setRootIsDecorated(false);
|
||||
|
||||
|
||||
|
||||
//Selection Setup
|
||||
//selection = ui.uploadsList->selectionModel();
|
||||
|
||||
|
@ -279,16 +284,51 @@ int TransfersDialog::addItem(QString symbol, QString name, QString coreID, qlong
|
|||
//DLListModel->setData(DLListModel->index(row, NAME), QVariant((QIcon)icon), Qt::DecorationRole);
|
||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant((QString)name), Qt::DisplayRole);
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)fileSize));
|
||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)progress));
|
||||
DLListModel->setData(DLListModel->index(row, COMPLETED), QVariant((qlonglong)completed));
|
||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)dlspeed));
|
||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)progress));
|
||||
DLListModel->setData(DLListModel->index(row, SOURCES), QVariant((QString)sources));
|
||||
DLListModel->setData(DLListModel->index(row, STATUS), QVariant((QString)status));
|
||||
DLListModel->setData(DLListModel->index(row, COMPLETED), QVariant((qlonglong)completed));
|
||||
DLListModel->setData(DLListModel->index(row, REMAINING), QVariant((qlonglong)remaining));
|
||||
DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
bool TransfersDialog::addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining)
|
||||
{
|
||||
QStandardItem *dlItem = DLListModel->item(row);
|
||||
if (!dlItem) return false;
|
||||
|
||||
//set this false if you want to expand on double click
|
||||
dlItem->setEditable(false);
|
||||
|
||||
QList<QStandardItem *> items;
|
||||
QStandardItem *i1 = new QStandardItem(); i1->setData(QVariant((QString)name), Qt::DisplayRole);
|
||||
QStandardItem *i2 = new QStandardItem(); i2->setData(QVariant((qlonglong)fileSize), Qt::DisplayRole);
|
||||
QStandardItem *i3 = new QStandardItem(); i3->setData(QVariant((qlonglong)completed), Qt::DisplayRole);
|
||||
QStandardItem *i4 = new QStandardItem(); i4->setData(QVariant((double)dlspeed), Qt::DisplayRole);
|
||||
QStandardItem *i5 = new QStandardItem(); i5->setData(QVariant((double)progress), Qt::DisplayRole);
|
||||
QStandardItem *i6 = new QStandardItem(); i6->setData(QVariant((QString)sources), Qt::DisplayRole);
|
||||
QStandardItem *i7 = new QStandardItem(); i7->setData(QVariant((QString)status), Qt::DisplayRole);
|
||||
QStandardItem *i8 = new QStandardItem(); i8->setData(QVariant((qlonglong)remaining), Qt::DisplayRole);
|
||||
QStandardItem *i9 = new QStandardItem(); i9->setData(QVariant((QString)coreID), Qt::DisplayRole);
|
||||
|
||||
items.append(i1);
|
||||
items.append(i2);
|
||||
items.append(i3);
|
||||
items.append(i4);
|
||||
items.append(i5);
|
||||
items.append(i6);
|
||||
items.append(i7);
|
||||
items.append(i8);
|
||||
items.append(i9);
|
||||
|
||||
dlItem->appendRow(items);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int TransfersDialog::addUploadItem(QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining)
|
||||
{
|
||||
|
@ -310,6 +350,7 @@ int TransfersDialog::addUploadItem(QString symbol, QString name, QString coreID,
|
|||
return row;
|
||||
}
|
||||
|
||||
|
||||
void TransfersDialog::delItem(int row)
|
||||
{
|
||||
DLListModel->removeRow(row, QModelIndex());
|
||||
|
@ -370,11 +411,36 @@ void TransfersDialog::insertTransfers()
|
|||
/* get current selection */
|
||||
std::list<std::string> selectedIds;
|
||||
|
||||
for(int i = 0; i <= DLListModel->rowCount(); i++) {
|
||||
for (int i = 0; i < DLListModel->rowCount(); i++) {
|
||||
if (selection->isRowSelected(i, QModelIndex())) {
|
||||
std::string id = getID(i, DLListModel).toStdString();
|
||||
selectedIds.push_back(id);
|
||||
}
|
||||
|
||||
QStandardItem *parent = DLListModel->item(i);
|
||||
//if (!parent) continue;
|
||||
int childs = parent->rowCount();
|
||||
for (int j = 0; j < childs; j++) {
|
||||
QModelIndex parentIndex = DLListModel->indexFromItem(parent);
|
||||
if (selection->isRowSelected(j, parentIndex)) {
|
||||
QStandardItem *child = parent->child(j, ID);
|
||||
std::string id = child->data(Qt::DisplayRole).toString().toStdString();
|
||||
selectedIds.push_back(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* get expanded donwload items */
|
||||
std::list<std::string> expandedIds;
|
||||
|
||||
for (int i = 0; i < DLListModel->rowCount(); i++) {
|
||||
QStandardItem *item = DLListModel->item(i);
|
||||
QModelIndex index = DLListModel->indexFromItem(item);
|
||||
if (ui.downloadList->isExpanded(index)) {
|
||||
std::string id = getID(i, DLListModel).toStdString();
|
||||
expandedIds.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
//remove all Items
|
||||
|
@ -400,121 +466,115 @@ void TransfersDialog::insertTransfers()
|
|||
uint32_t ulCount = 0;
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = downHashes.begin(); it != downHashes.end(); it++)
|
||||
{
|
||||
for (it = downHashes.begin(); it != downHashes.end(); it++) {
|
||||
FileInfo info;
|
||||
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
||||
//if file transfer is a cache file index file, don't show it
|
||||
if (info.flags & CB_CODE_CACHE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (info.flags & CB_CODE_CACHE) continue;
|
||||
|
||||
std::list<TransferInfo>::iterator pit;
|
||||
for(pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
||||
{
|
||||
symbol = "";
|
||||
coreId = QString::fromStdString(info.hash);
|
||||
name = QString::fromStdString(info.fname);
|
||||
sources = QString::fromStdString(rsPeers->getPeerName(pit->peerId));
|
||||
|
||||
switch(pit->status)
|
||||
{
|
||||
case FT_STATE_FAILED:
|
||||
status = tr("Failed");
|
||||
break;
|
||||
case FT_STATE_OKAY:
|
||||
status = tr("Okay");
|
||||
break;
|
||||
case FT_STATE_WAITING:
|
||||
status = tr("Waiting");
|
||||
break;
|
||||
case FT_STATE_DOWNLOADING:
|
||||
status = tr("Downloading");
|
||||
break;
|
||||
case FT_STATE_COMPLETE:
|
||||
default:
|
||||
status = tr("Complete");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (info.downloadStatus == FT_STATE_COMPLETE)
|
||||
{
|
||||
status = tr("Complete");
|
||||
}
|
||||
|
||||
dlspeed = pit->tfRate * 1024.0;
|
||||
coreId = QString::fromStdString(info.hash);
|
||||
fileSize = info.size;
|
||||
completed = info.transfered;
|
||||
progress = info.transfered * 100.0 / info.size;
|
||||
remaining = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
||||
|
||||
addItem(symbol, name, coreId, fileSize, progress,
|
||||
dlspeed, sources, status, completed, remaining);
|
||||
|
||||
/* if found in selectedIds -> select again */
|
||||
if (selectedIds.end() != std::find(selectedIds.begin(), selectedIds.end(), info.hash))
|
||||
{
|
||||
selection->select(DLListModel->index(dlCount, 0),
|
||||
QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
|
||||
|
||||
}
|
||||
dlCount++;
|
||||
}
|
||||
/* alternative ... if no peers there stick it in anyway */
|
||||
if (info.peers.size() == 0)
|
||||
{
|
||||
symbol = "";
|
||||
coreId = QString::fromStdString(info.hash);
|
||||
name = QString::fromStdString(info.fname);
|
||||
sources = tr("Unknown");
|
||||
|
||||
switch(info.downloadStatus)
|
||||
{
|
||||
case FT_STATE_FAILED:
|
||||
status = tr("Failed");
|
||||
break;
|
||||
case FT_STATE_OKAY:
|
||||
status = tr("Okay");
|
||||
break;
|
||||
case FT_STATE_WAITING:
|
||||
status = tr("Waiting");
|
||||
break;
|
||||
case FT_STATE_DOWNLOADING:
|
||||
status = tr("Downloading");
|
||||
break;
|
||||
case FT_STATE_COMPLETE:
|
||||
default:
|
||||
status = tr("Complete");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
progress = (info.transfered * 100.0) / info.size;
|
||||
dlspeed = info.tfRate * 1024.0;
|
||||
fileSize = info.size;
|
||||
|
||||
/* get number of online peers */
|
||||
int online = 0;
|
||||
std::list<TransferInfo>::iterator pit;
|
||||
for (pit = info.peers.begin(); pit != info.peers.end(); pit++) {
|
||||
if (rsPeers->isOnline(pit->peerId)) {
|
||||
online++;
|
||||
}
|
||||
}
|
||||
|
||||
sources = QString("%1 (%2)").arg(online).arg(info.peers.size() - online);
|
||||
|
||||
switch (info.downloadStatus) {
|
||||
case FT_STATE_FAILED:
|
||||
status = tr("Failed"); break;
|
||||
case FT_STATE_OKAY:
|
||||
status = tr("Okay"); break;
|
||||
case FT_STATE_WAITING:
|
||||
status = tr("Waiting"); break;
|
||||
case FT_STATE_DOWNLOADING:
|
||||
status = tr("Downloading"); break;
|
||||
case FT_STATE_COMPLETE:
|
||||
status = tr("Complete"); break;
|
||||
default:
|
||||
status = tr("Unknown"); break;
|
||||
}
|
||||
|
||||
completed = info.transfered;
|
||||
progress = info.transfered * 100.0 / info.size;
|
||||
remaining = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
||||
|
||||
addItem(symbol, name, coreId, fileSize, progress,
|
||||
dlspeed, sources, status, completed, remaining);
|
||||
int addedRow = addItem(symbol, name, coreId, fileSize, progress, dlspeed, sources, status, completed, remaining);
|
||||
|
||||
/* if found in selectedIds -> select again */
|
||||
if (selectedIds.end() != std::find(selectedIds.begin(), selectedIds.end(), info.hash))
|
||||
{
|
||||
if (selectedIds.end() != std::find(selectedIds.begin(), selectedIds.end(), info.hash)) {
|
||||
selection->select(DLListModel->index(dlCount, 0),
|
||||
QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
|
||||
}
|
||||
|
||||
/* expand last expanded items */
|
||||
if (expandedIds.end() != std::find(expandedIds.begin(), expandedIds.end(), info.hash)) {
|
||||
QStandardItem *item = DLListModel->item(dlCount);
|
||||
QModelIndex index = DLListModel->indexFromItem(item);
|
||||
ui.downloadList->setExpanded(index, true);
|
||||
}
|
||||
|
||||
dlCount++;
|
||||
|
||||
/* continue to next download item if no peers to add */
|
||||
if (!info.peers.size()) continue;
|
||||
|
||||
int dlPeers = 0;
|
||||
for (pit = info.peers.begin(); pit != info.peers.end(); pit++) {
|
||||
symbol = "";
|
||||
name = QString::fromStdString(rsPeers->getPeerName(pit->peerId));
|
||||
//unique combination: fileName + peerName, variant: hash + peerName (too long)
|
||||
coreId = QString::fromStdString(info.fname + rsPeers->getPeerName(pit->peerId));
|
||||
fileSize = info.size;
|
||||
progress = (info.transfered * 100.0) / info.size;
|
||||
dlspeed = pit->tfRate * 1024.0;
|
||||
//sources = QString("rShare v %1").arg(tr("0.4.13a"));//TODO: take it from somewhere
|
||||
sources = "";
|
||||
|
||||
if (info.downloadStatus == FT_STATE_COMPLETE) {
|
||||
status = tr("Complete");
|
||||
} else {
|
||||
status = tr("Unknown");
|
||||
switch (pit->status) {
|
||||
case FT_STATE_FAILED:
|
||||
status = tr("Failed"); break;
|
||||
case FT_STATE_OKAY:
|
||||
status = tr("Okay"); break;
|
||||
case FT_STATE_WAITING:
|
||||
status = tr("Waiting"); break;
|
||||
case FT_STATE_DOWNLOADING:
|
||||
status = tr("Downloading"); break;
|
||||
case FT_STATE_COMPLETE:
|
||||
status = tr("Complete"); break;
|
||||
}
|
||||
}
|
||||
|
||||
completed = info.transfered;
|
||||
remaining = (info.size - info.transfered) / (pit->tfRate * 1024.0);
|
||||
|
||||
if (!addPeerToItem(addedRow, symbol, name, coreId, fileSize, progress, dlspeed, sources, status, completed, remaining))
|
||||
continue;
|
||||
|
||||
/* if peers found in selectedIds, select again */
|
||||
if (selectedIds.end() != std::find(selectedIds.begin(), selectedIds.end(), info.fname + rsPeers->getPeerName(pit->peerId))) {
|
||||
QStandardItem *dlItem = DLListModel->item(addedRow);
|
||||
QModelIndex childIndex = DLListModel->indexFromItem(dlItem).child(dlPeers, 0);
|
||||
selection->select(childIndex, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
|
||||
}
|
||||
dlPeers++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(it = upHashes.begin(); it != upHashes.end(); it++)
|
||||
{
|
||||
FileInfo info;
|
||||
|
|
|
@ -105,6 +105,7 @@ class TransfersDialog : public MainPage
|
|||
|
||||
public slots:
|
||||
int addItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
|
||||
bool addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
|
||||
void delItem(int row);
|
||||
|
||||
int addUploadItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue