diff --git a/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp b/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp index 9da53d50c..f07d2eb55 100644 --- a/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp +++ b/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp @@ -229,6 +229,8 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, temp); break; case COLUMN_LASTDL: + if (index.data().value().isEmpty()) + break; qi64Value = index.data().value(); if (qi64Value < std::numeric_limits::max()){ QDateTime qdtLastDL = QDateTime::fromTime_t(qi64Value); diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index fb11b3bd2..c7f85d1f8 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -212,7 +212,6 @@ TransfersDialog::TransfersDialog(QWidget *parent) DLLFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); ui.downloadList->setModel(DLLFilterModel); - //ui.downloadList->hideColumn(ID); DLDelegate = new DLListDelegate(); ui.downloadList->setItemDelegate(DLDelegate); @@ -229,7 +228,7 @@ TransfersDialog::TransfersDialog(QWidget *parent) mShortcut = new QShortcut(QKeySequence (Qt::Key_Delete), ui.downloadList, 0, 0, Qt::WidgetShortcut); connect(mShortcut, SIGNAL(activated()), this, SLOT( cancel ())); - //Selection Setup + //Selection Setup selection = ui.downloadList->selectionModel(); ui.downloadList->setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -238,34 +237,34 @@ TransfersDialog::TransfersDialog(QWidget *parent) /* Set header resize modes and initial section sizes Downloads TreeView*/ - QHeaderView * _header = ui.downloadList->header () ; - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_NAME, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_SIZE, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_COMPLETED, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_DLSPEED, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_PROGRESS, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_SOURCES, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_STATUS, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_PRIORITY, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_REMAINING, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_DOWNLOADTIME, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_ID, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_LASTDL, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(_header, COLUMN_PATH, QHeaderView::Interactive); + QHeaderView * dlheader = ui.downloadList->header () ; + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_NAME, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_SIZE, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_COMPLETED, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_DLSPEED, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_PROGRESS, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_SOURCES, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_STATUS, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_PRIORITY, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_REMAINING, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_DOWNLOADTIME, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_ID, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_LASTDL, QHeaderView::Interactive); + QHeaderView_setSectionResizeModeColumn(dlheader, COLUMN_PATH, QHeaderView::Interactive); - _header->resizeSection ( COLUMN_NAME, 170 ); - _header->resizeSection ( COLUMN_SIZE, 70 ); - _header->resizeSection ( COLUMN_COMPLETED, 75 ); - _header->resizeSection ( COLUMN_DLSPEED, 75 ); - _header->resizeSection ( COLUMN_PROGRESS, 170 ); - _header->resizeSection ( COLUMN_SOURCES, 90 ); - _header->resizeSection ( COLUMN_STATUS, 100 ); - _header->resizeSection ( COLUMN_PRIORITY, 100 ); - _header->resizeSection ( COLUMN_REMAINING, 100 ); - _header->resizeSection ( COLUMN_DOWNLOADTIME, 100 ); - _header->resizeSection ( COLUMN_ID, 100 ); - _header->resizeSection ( COLUMN_LASTDL, 100 ); - _header->resizeSection ( COLUMN_PATH, 100 ); + dlheader->resizeSection ( COLUMN_NAME, 170 ); + dlheader->resizeSection ( COLUMN_SIZE, 70 ); + dlheader->resizeSection ( COLUMN_COMPLETED, 75 ); + dlheader->resizeSection ( COLUMN_DLSPEED, 75 ); + dlheader->resizeSection ( COLUMN_PROGRESS, 170 ); + dlheader->resizeSection ( COLUMN_SOURCES, 90 ); + dlheader->resizeSection ( COLUMN_STATUS, 100 ); + dlheader->resizeSection ( COLUMN_PRIORITY, 100 ); + dlheader->resizeSection ( COLUMN_REMAINING, 100 ); + dlheader->resizeSection ( COLUMN_DOWNLOADTIME, 100 ); + dlheader->resizeSection ( COLUMN_ID, 100 ); + dlheader->resizeSection ( COLUMN_LASTDL, 100 ); + dlheader->resizeSection ( COLUMN_PATH, 100 ); // set default column and sort order for download ui.downloadList->sortByColumn(COLUMN_NAME, Qt::AscendingOrder); @@ -283,16 +282,13 @@ TransfersDialog::TransfersDialog(QWidget *parent) ULListModel = new QStandardItemModel(0,COLUMN_UCOUNT); ULListModel->setHeaderData(COLUMN_UNAME, Qt::Horizontal, tr("Name", "i.e: file name")); ULListModel->setHeaderData(COLUMN_USIZE, Qt::Horizontal, tr("Size", "i.e: file size")); - ULListModel->setHeaderData(COLUMN_USERNAME, Qt::Horizontal, tr("Peer", "i.e: user name")); - ULListModel->setHeaderData(COLUMN_UPROGRESS, Qt::Horizontal, tr("Progress", "i.e: % uploaded")); - ULListModel->setHeaderData(COLUMN_ULSPEED, Qt::Horizontal, tr("Speed", "i.e: upload speed")); - ULListModel->setHeaderData(COLUMN_USTATUS, Qt::Horizontal, tr("Status")); ULListModel->setHeaderData(COLUMN_UTRANSFERRED, Qt::Horizontal, tr("Transferred", "")); + ULListModel->setHeaderData(COLUMN_ULSPEED, Qt::Horizontal, tr("Speed", "i.e: upload speed")); + ULListModel->setHeaderData(COLUMN_UPROGRESS, Qt::Horizontal, tr("Progress", "i.e: % uploaded")); ULListModel->setHeaderData(COLUMN_UHASH, Qt::Horizontal, tr("Hash", "")); - ULListModel->setHeaderData(COLUMN_UUSERID, Qt::Horizontal, tr("UserID", "")); + ui.uploadsList->setModel(ULListModel); - //ULListModel->insertColumn(COLUMN_UUSERID); - //ui.uploadsList->hideColumn(COLUMN_UUSERID); + ULDelegate = new ULListDelegate(); ui.uploadsList->setItemDelegate(ULDelegate); @@ -300,13 +296,13 @@ TransfersDialog::TransfersDialog(QWidget *parent) // With disabled autoscroll, the treeview doesn't scroll with cursor move // ui.uploadsList->setAutoScroll(false) ; - ui.uploadsList->setRootIsDecorated(false); - - - //Selection Setup + //Selection Setup selectionUp = ui.uploadsList->selectionModel(); + ui.uploadsList->setSelectionMode(QAbstractItemView::ExtendedSelection); + ui.uploadsList->setRootIsDecorated(true); + /* Set header resize modes and initial section sizes Uploads TreeView*/ QHeaderView * upheader = ui.uploadsList->header () ; QHeaderView_setSectionResizeModeColumn(upheader, COLUMN_UNAME, QHeaderView::Interactive); @@ -314,28 +310,15 @@ TransfersDialog::TransfersDialog(QWidget *parent) QHeaderView_setSectionResizeModeColumn(upheader, COLUMN_UTRANSFERRED, QHeaderView::Interactive); QHeaderView_setSectionResizeModeColumn(upheader, COLUMN_ULSPEED, QHeaderView::Interactive); QHeaderView_setSectionResizeModeColumn(upheader, COLUMN_UPROGRESS, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(upheader, COLUMN_USTATUS, QHeaderView::Interactive); - QHeaderView_setSectionResizeModeColumn(upheader, COLUMN_USERNAME, QHeaderView::Interactive); upheader->resizeSection ( COLUMN_UNAME, 260 ); upheader->resizeSection ( COLUMN_USIZE, 70 ); upheader->resizeSection ( COLUMN_UTRANSFERRED, 75 ); upheader->resizeSection ( COLUMN_ULSPEED, 75 ); upheader->resizeSection ( COLUMN_UPROGRESS, 170 ); - upheader->resizeSection ( COLUMN_USTATUS, 100 ); - upheader->resizeSection ( COLUMN_USERNAME, 120 ); // set default column and sort order for upload ui.uploadsList->sortByColumn(COLUMN_UNAME, Qt::AscendingOrder); - - // FileTransferInfoWidget *ftiw = new FileTransferInfoWidget(); - // ui.fileTransferInfoWidget->setWidget(ftiw); - // ui.fileTransferInfoWidget->setWidgetResizable(true); - // ui.fileTransferInfoWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - // ui.fileTransferInfoWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - // ui.fileTransferInfoWidget->viewport()->setBackgroundRole(QPalette::NoRole); - // ui.fileTransferInfoWidget->setFrameStyle(QFrame::NoFrame); - // ui.fileTransferInfoWidget->setFocusPolicy(Qt::NoFocus); QObject::connect(ui.downloadList->selectionModel(),SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),this,SLOT(showFileDetails())) ; @@ -384,13 +367,13 @@ TransfersDialog::TransfersDialog(QWidget *parent) connect( cancelAct , SIGNAL( triggered() ), this, SLOT( cancel() ) ); openFolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this); - connect(openFolderAct, SIGNAL(triggered()), this, SLOT(openFolderTransfer())); + connect(openFolderAct, SIGNAL(triggered()), this, SLOT(dlOpenFolder())); openFileAct = new QAction(QIcon(IMAGE_OPENFILE), tr("Open File"), this); - connect(openFileAct, SIGNAL(triggered()), this, SLOT(openTransfer())); + connect(openFileAct, SIGNAL(triggered()), this, SLOT(dlOpenFile())); previewFileAct = new QAction(QIcon(IMAGE_PREVIEW), tr("Preview File"), this); - connect(previewFileAct, SIGNAL(triggered()), this, SLOT(previewTransfer())); + connect(previewFileAct, SIGNAL(triggered()), this, SLOT(dlPreviewFile())); detailsFileAct = new QAction(QIcon(IMAGE_INFO), tr("Details..."), this); connect(detailsFileAct, SIGNAL(triggered()), this, SLOT(showDetailsDialog())); @@ -400,7 +383,7 @@ TransfersDialog::TransfersDialog(QWidget *parent) copyLinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy RetroShare Link" ), this ); - connect( copyLinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) ); + connect( copyLinkAct , SIGNAL( triggered() ), this, SLOT( dlCopyLink() ) ); pasteLinkAct = new QAction(QIcon(IMAGE_PASTELINK), tr( "Paste RetroShare Link" ), this ); connect( pasteLinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) ); queueDownAct = new QAction(QIcon(":/images/go-down.png"), tr("Down"), this); @@ -424,7 +407,7 @@ TransfersDialog::TransfersDialog(QWidget *parent) chunkProgressiveAct = new QAction(QIcon(IMAGE_PRIORITYAUTO), tr("Progressive"), this); connect(chunkProgressiveAct, SIGNAL(triggered()), this, SLOT(chunkProgressive())); playAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play" ), this ); - connect( playAct , SIGNAL( triggered() ), this, SLOT( openTransfer() ) ); + connect( playAct , SIGNAL( triggered() ), this, SLOT( dlOpenFile() ) ); renameFileAct = new QAction(QIcon(IMAGE_RENAMEFILE), tr("Rename file..."), this); connect(renameFileAct, SIGNAL(triggered()), this, SLOT(renameFile())); specifyDestinationDirectoryAct = new QAction(QIcon(IMAGE_SEARCH),tr("Specify..."),this) ; @@ -610,7 +593,7 @@ void TransfersDialog::processSettings(bool bLoad) void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) { std::set items ; - getSelectedItems(&items, NULL) ; + getDLSelectedItems(&items, NULL) ; bool single = (items.size() == 1) ; @@ -847,27 +830,16 @@ void TransfersDialog::downloadListHeaderCustomPopupMenu( QPoint /*point*/ ) void TransfersDialog::uploadsListCustomPopupMenu( QPoint /*point*/ ) { - std::cerr << "TransfersDialog::uploadsListCustomPopupMenu()" << std::endl; - std::set items; getULSelectedItems(&items, NULL); bool single = (items.size() == 1); - bool add_CopyLink = false; + bool add_CopyLink = !items.empty(); QMenu contextMnu( this ); - - if(!items.empty()) - { - add_CopyLink = true; - - }//if(!items.empty()) - if(single) - { contextMnu.addAction( ulOpenFolderAct); - } if (add_CopyLink) contextMnu.addAction( ulCopyLinkAct); @@ -883,7 +855,7 @@ void TransfersDialog::chooseDestinationDirectory() return ; std::set items ; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for(std::set::const_iterator it(items.begin());it!=items.end();++it) { @@ -896,7 +868,7 @@ void TransfersDialog::setDestinationDirectory() std::string dest_dir(qobject_cast(sender())->data().toString().toUtf8().data()) ; std::set items ; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for(std::set::const_iterator it(items.begin());it!=items.end();++it) { @@ -905,9 +877,9 @@ void TransfersDialog::setDestinationDirectory() } } -int TransfersDialog::addItem(int row, const FileInfo &fileInfo) +int TransfersDialog::addDLItem(int row, const FileInfo &fileInfo) { - QString fileHash = QString::fromStdString(fileInfo.hash.toStdString()); + QString fileHash = QString::fromStdString(fileInfo.hash.toStdString()); double fileDlspeed = (fileInfo.downloadStatus == FT_STATE_DOWNLOADING) ? (fileInfo.tfRate * 1024.0) : 0.0; QString status; @@ -958,7 +930,6 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo) QString strPath = QString::fromUtf8(fileInfo.path.c_str()); QString strPathAfterDL = strPath; strPathAfterDL.replace(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()),""); - QStringList qslPath = strPathAfterDL.split("/"); FileChunksInfo fcinfo; if (!rsFiles->FileDownloadChunksDetails(fileInfo.hash, fcinfo)) { @@ -994,53 +965,46 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo) DLListModel->insertRow(row); // change progress column to own class for sorting - DLListModel->setItem(row, COLUMN_PROGRESS, new ProgressItem(NULL)); - DLListModel->setItem(row, COLUMN_PRIORITY, new PriorityItem(NULL)); + DLListModel->setItem(row, COLUMN_PROGRESS, new ProgressItem(NULL)); + DLListModel->setItem(row, COLUMN_PRIORITY, new PriorityItem(NULL)); - DLListModel->setData(DLListModel->index(row, COLUMN_SIZE), QVariant((qlonglong) fileInfo.size)); - DLListModel->setData(DLListModel->index(row, COLUMN_ID), fileHash, Qt::DisplayRole); - DLListModel->setData(DLListModel->index(row, COLUMN_ID), fileHash, Qt::UserRole); + DLListModel->setData(DLListModel->index(row, COLUMN_SIZE), QVariant((qlonglong) fileInfo.size)); + DLListModel->setData(DLListModel->index(row, COLUMN_ID), fileHash, Qt::DisplayRole); + DLListModel->setData(DLListModel->index(row, COLUMN_ID), fileHash, Qt::UserRole); } QString fileName = QString::fromUtf8(fileInfo.fname.c_str()); - DLListModel->setData(DLListModel->index(row, COLUMN_NAME), fileName); - DLListModel->setData(DLListModel->index(row, COLUMN_NAME), FilesDefs::getIconFromFilename(fileName), Qt::DecorationRole); + DLListModel->setData(DLListModel->index(row, COLUMN_NAME), fileName); + DLListModel->setData(DLListModel->index(row, COLUMN_NAME), FilesDefs::getIconFromFilename(fileName), Qt::DecorationRole); - DLListModel->setData(DLListModel->index(row, COLUMN_COMPLETED), QVariant((qlonglong)completed)); - DLListModel->setData(DLListModel->index(row, COLUMN_DLSPEED), QVariant((double)fileDlspeed)); - DLListModel->setData(DLListModel->index(row, COLUMN_PROGRESS), QVariant::fromValue(pinfo)); - DLListModel->setData(DLListModel->index(row, COLUMN_STATUS), QVariant(status)); - DLListModel->setData(DLListModel->index(row, COLUMN_PRIORITY), QVariant(priority)); - DLListModel->setData(DLListModel->index(row, COLUMN_REMAINING), QVariant((qlonglong)remaining)); - DLListModel->setData(DLListModel->index(row, COLUMN_DOWNLOADTIME), QVariant((qlonglong)downloadtime)); - DLListModel->setData(DLListModel->index(row, COLUMN_LASTDL), QVariant(qi64LastDL)); - DLListModel->setData(DLListModel->index(row, COLUMN_PATH), QVariant(strPathAfterDL)); - DLListModel->item(row,COLUMN_PATH)->setToolTip(strPath); - DLListModel->item(row,COLUMN_STATUS)->setToolTip(tooltip); + DLListModel->setData(DLListModel->index(row, COLUMN_COMPLETED), QVariant((qlonglong)completed)); + DLListModel->setData(DLListModel->index(row, COLUMN_DLSPEED), QVariant((double)fileDlspeed)); + DLListModel->setData(DLListModel->index(row, COLUMN_PROGRESS), QVariant::fromValue(pinfo)); + DLListModel->setData(DLListModel->index(row, COLUMN_STATUS), QVariant(status)); + DLListModel->setData(DLListModel->index(row, COLUMN_PRIORITY), QVariant(priority)); + DLListModel->setData(DLListModel->index(row, COLUMN_REMAINING), QVariant((qlonglong)remaining)); + DLListModel->setData(DLListModel->index(row, COLUMN_DOWNLOADTIME), QVariant((qlonglong)downloadtime)); + DLListModel->setData(DLListModel->index(row, COLUMN_LASTDL), QVariant(qi64LastDL)); + DLListModel->setData(DLListModel->index(row, COLUMN_PATH), QVariant(strPathAfterDL)); + DLListModel->item(row,COLUMN_PATH)->setToolTip(strPath); + DLListModel->item(row,COLUMN_STATUS)->setToolTip(tooltip); QStandardItem *dlItem = DLListModel->item(row); - std::map::const_iterator vit; - std::set used_rows ; int active = 0; if (fileInfo.downloadStatus != FT_STATE_COMPLETE) { - std::list::const_iterator pit; - for (pit = fileInfo.peers.begin(); pit != fileInfo.peers.end(); ++pit) { + for (std::list::const_iterator pit = fileInfo.peers.begin() + ; pit != fileInfo.peers.end(); ++pit) + { const TransferInfo &transferInfo = *pit; QString peerName = getPeerName(transferInfo.peerId); //unique combination: fileHash + peerId, variant: hash + peerName (too long) - QString hashFileAndPeerId = fileHash + QString::fromStdString(transferInfo.peerId.toStdString()); - QString version; - std::string rsversion; - if (rsDisc->getPeerVersion(transferInfo.peerId, rsversion)) - { - version = tr("version:")+" " + QString::fromStdString(rsversion); - } + QString hashFileAndPeerId = fileHash + QString::fromStdString(transferInfo.peerId.toStdString()); - double peerDlspeed = 0; + double peerDlspeed = 0; if ((uint32_t)transferInfo.status == FT_STATE_DOWNLOADING && fileInfo.downloadStatus != FT_STATE_PAUSED && fileInfo.downloadStatus != FT_STATE_COMPLETE) peerDlspeed = transferInfo.tfRate * 1024.0; @@ -1050,7 +1014,7 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo) peerpinfo.progress = 0.0; // we don't display completion for sources. peerpinfo.nb_chunks = peerpinfo.cmap._map.empty() ? 0 : fcinfo.chunks.size(); - int row_id = addPeerToItem(dlItem, peerName, hashFileAndPeerId, peerDlspeed, transferInfo.status, peerpinfo); + int row_id = addPeerToDLItem(dlItem, peerName, hashFileAndPeerId, peerDlspeed, transferInfo.status, peerpinfo); used_rows.insert(row_id); @@ -1073,17 +1037,15 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo) } return row; - } -int TransfersDialog::addPeerToItem(QStandardItem *dlItem, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo) +int TransfersDialog::addPeerToDLItem(QStandardItem *dlItem, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo) { // try to find the item int childRow = -1; - int count = 0; - QStandardItem *childId = NULL; - for (count = 0; (childId = dlItem->child(count, COLUMN_ID)) != NULL; ++count) { + QStandardItem *childId = NULL; + for (int count = 0; (childId = dlItem->child(count, COLUMN_ID)) != NULL; ++count) { if (childId->data(Qt::UserRole).toString() == coreID) { childRow = count; break; @@ -1099,124 +1061,237 @@ int TransfersDialog::addPeerToItem(QStandardItem *dlItem, const QString& name, c QHeaderView *header = ui.downloadList->header(); - QStandardItem *iName = new QStandardItem(); - QStandardItem *iSize = new SortByNameItem(header); - QStandardItem *iCompleted = new SortByNameItem(header); - QStandardItem *iDlSpeed = new SortByNameItem(header); - QStandardItem *iProgress = new ProgressItem(header); - QStandardItem *iSource = new SortByNameItem(header); - QStandardItem *iStatus = new SortByNameItem(header); - QStandardItem *iPriority = new SortByNameItem(header); - QStandardItem *iRemaining = new SortByNameItem(header); - QStandardItem *iDownloadTime = new SortByNameItem(header); - QStandardItem *iID = new SortByNameItem(header); + QStandardItem *iName = new QStandardItem(); //COLUMN_NAME + QStandardItem *iSize = new SortByNameItem(header); //COLUMN_SIZE + QStandardItem *iCompleted = new SortByNameItem(header); //COLUMN_COMPLETED + QStandardItem *iDlSpeed = new SortByNameItem(header); //COLUMN_DLSPEED + QStandardItem *iProgress = new ProgressItem(header); //COLUMN_PROGRESS + QStandardItem *iSource = new SortByNameItem(header); //COLUMN_SOURCES + QStandardItem *iStatus = new SortByNameItem(header); //COLUMN_STATUS + QStandardItem *iPriority = new SortByNameItem(header); //COLUMN_PRIORITY + QStandardItem *iRemaining = new SortByNameItem(header); //COLUMN_REMAINING + QStandardItem *iDownloadTime = new SortByNameItem(header); //COLUMN_DOWNLOADTIME + QStandardItem *iID = new SortByNameItem(header); //COLUMN_ID + QStandardItem *iLastDL = new SortByNameItem(header); //COLUMN_LASTDL + QStandardItem *iPath = new SortByNameItem(header); //COLUMN_PATH - siName = iName; - siStatus = iStatus; + siName = iName; + siStatus = iStatus; QList items; - iName->setData(QVariant(" " + name), Qt::DisplayRole); - iSize->setData(QVariant(QString()), Qt::DisplayRole); - iCompleted->setData(QVariant(QString()), Qt::DisplayRole); - iDlSpeed->setData(QVariant((double)dlspeed), Qt::DisplayRole); - iProgress->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole); - iSource->setData(QVariant(QString()), Qt::DisplayRole); + iName->setData(QVariant(" " + name), Qt::DisplayRole); + iSize->setData(QVariant(QString()), Qt::DisplayRole); + iCompleted->setData(QVariant(QString()), Qt::DisplayRole); + iDlSpeed->setData(QVariant((double)dlspeed), Qt::DisplayRole); + iProgress->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole); + iSource->setData(QVariant(QString()), Qt::DisplayRole); - iPriority->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority - iRemaining->setData(QVariant(QString()), Qt::DisplayRole); - iDownloadTime->setData(QVariant(QString()), Qt::DisplayRole); - iID->setData(QVariant() , Qt::DisplayRole); - iID->setData(QVariant(coreID), Qt::UserRole); + iPriority->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority + iRemaining->setData(QVariant(QString()), Qt::DisplayRole); + iDownloadTime->setData(QVariant(QString()), Qt::DisplayRole); + iID->setData(QVariant() , Qt::DisplayRole); + iID->setData(QVariant(coreID), Qt::UserRole); + iLastDL->setData(QVariant(QString()), Qt::DisplayRole); + iPath->setData(QVariant(QString()), Qt::DisplayRole); - items.append(iName); - items.append(iSize); - items.append(iCompleted); - items.append(iDlSpeed); - items.append(iProgress); - items.append(iSource); - items.append(iStatus); - items.append(iPriority); - items.append(iRemaining); - items.append(iDownloadTime); - items.append(iID); + items.append(iName); + items.append(iSize); + items.append(iCompleted); + items.append(iDlSpeed); + items.append(iProgress); + items.append(iSource); + items.append(iStatus); + items.append(iPriority); + items.append(iRemaining); + items.append(iDownloadTime); + items.append(iID); + items.append(iLastDL); + items.append(iPath); dlItem->appendRow(items); childRow = dlItem->rowCount() - 1; } else { // just update the child (peer) - dlItem->child(childRow, COLUMN_DLSPEED)->setData(QVariant((double)dlspeed), Qt::DisplayRole); - dlItem->child(childRow, COLUMN_PROGRESS)->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole); + dlItem->child(childRow, COLUMN_DLSPEED)->setData(QVariant((double)dlspeed), Qt::DisplayRole); + dlItem->child(childRow, COLUMN_PROGRESS)->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole); - siName = dlItem->child(childRow,COLUMN_NAME); - siStatus = dlItem->child(childRow, COLUMN_STATUS); + siName = dlItem->child(childRow,COLUMN_NAME); + siStatus = dlItem->child(childRow, COLUMN_STATUS); } switch (status) { case FT_STATE_FAILED: - siStatus->setData(QVariant(tr("Failed"))) ; - siName->setData(QIcon(":/images/Client1.png"), Qt::DecorationRole); + siStatus->setData(QVariant(tr("Failed"))) ; + siName->setData(QIcon(":/images/Client1.png"), Qt::DecorationRole); break ; - case FT_STATE_OKAY: - siStatus->setData(QVariant(tr("Okay"))); - siName->setData(QIcon(":/images/Client2.png"), Qt::DecorationRole); + case FT_STATE_OKAY: + siStatus->setData(QVariant(tr("Okay"))); + siName->setData(QIcon(":/images/Client2.png"), Qt::DecorationRole); break ; - case FT_STATE_WAITING: - siStatus->setData(QVariant(tr(""))); - siName->setData(QIcon(":/images/Client3.png"), Qt::DecorationRole); + case FT_STATE_WAITING: + siStatus->setData(QVariant(tr(""))); + siName->setData(QIcon(":/images/Client3.png"), Qt::DecorationRole); break ; - case FT_STATE_DOWNLOADING: - siStatus->setData(QVariant(tr("Transferring"))); - siName->setData(QIcon(":/images/Client0.png"), Qt::DecorationRole); + case FT_STATE_DOWNLOADING: + siStatus->setData(QVariant(tr("Transferring"))); + siName->setData(QIcon(":/images/Client0.png"), Qt::DecorationRole); break ; - case FT_STATE_COMPLETE: - siStatus->setData(QVariant(tr("Complete"))); - siName->setData(QIcon(":/images/Client0.png"), Qt::DecorationRole); + case FT_STATE_COMPLETE: + siStatus->setData(QVariant(tr("Complete"))); + siName->setData(QIcon(":/images/Client0.png"), Qt::DecorationRole); break ; - default: - siStatus->setData(QVariant(tr(""))); - siName->setData(QIcon(":/images/Client4.png"), Qt::DecorationRole); + default: + siStatus->setData(QVariant(tr(""))); + siName->setData(QIcon(":/images/Client4.png"), Qt::DecorationRole); } return childRow; } -int TransfersDialog::addUploadItem( const QString&, const QString& name, const QString& coreID, - qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed, - const QString& source, const QString& peer_id, const QString& status, qlonglong completed, qlonglong) +int TransfersDialog::addULItem(int row, const FileInfo &fileInfo) { - // Find items does not work reliably, because it (apparently) needs Qt to flush pending events to work, so we can't call it - // on a table that was just filled in. - // - int row ; - for(row=0;rowrowCount();++row) - if(ULListModel->item(row,COLUMN_UUSERID)->data(Qt::EditRole).toString() == peer_id && ULListModel->item(row,COLUMN_UHASH)->data(Qt::EditRole).toString() == coreID) - break ; + QString fileHash = QString::fromStdString(fileInfo.hash.toStdString()); - if(row >= ULListModel->rowCount() ) + RsPeerId ownId = rsPeers->getOwnId(); + + QString fileName = QString::fromUtf8(fileInfo.fname.c_str()); + qlonglong fileSize = fileInfo.size; + + if(row < 0 ) { row = ULListModel->rowCount(); ULListModel->insertRow(row); // change progress column to own class for sorting - ULListModel->setItem(row, COLUMN_UPROGRESS, new ProgressItem(NULL)); + //ULListModel->setItem(row, COLUMN_UPROGRESS, new ProgressItem(NULL)); - ULListModel->setData(ULListModel->index(row, COLUMN_UNAME), QVariant((QString)" "+name), Qt::DisplayRole); - ULListModel->setData(ULListModel->index(row, COLUMN_USERNAME), QVariant((QString)source)); - ULListModel->setData(ULListModel->index(row, COLUMN_UHASH), QVariant((QString)coreID)); - ULListModel->setData(ULListModel->index(row, COLUMN_UUSERID), QVariant((QString)peer_id)); - - ULListModel->setData(ULListModel->index(row,COLUMN_UNAME), FilesDefs::getIconFromFilename(name), Qt::DecorationRole); + ULListModel->setData(ULListModel->index(row, COLUMN_UNAME), fileName); + ULListModel->setData(ULListModel->index(row, COLUMN_UNAME), FilesDefs::getIconFromFilename(fileName), Qt::DecorationRole); + ULListModel->setData(ULListModel->index(row, COLUMN_UHASH), fileHash); + ULListModel->setData(ULListModel->index(row, COLUMN_UHASH), fileHash, Qt::UserRole); } - ULListModel->setData(ULListModel->index(row, COLUMN_USIZE), QVariant((qlonglong)fileSize)); - ULListModel->setData(ULListModel->index(row, COLUMN_UTRANSFERRED), QVariant((qlonglong)completed)); - ULListModel->setData(ULListModel->index(row, COLUMN_ULSPEED), QVariant((double)dlspeed)); - ULListModel->setData(ULListModel->index(row, COLUMN_UPROGRESS), QVariant::fromValue(pinfo)); - ULListModel->setData(ULListModel->index(row, COLUMN_USTATUS), QVariant((QString)status)); + ULListModel->setData(ULListModel->index(row, COLUMN_USIZE), QVariant((qlonglong)fileSize)); + + QStandardItem *ulItem = ULListModel->item(row); + std::set used_rows ; + double peerULSpeedTotal = 0; + + for(std::list::const_iterator pit = fileInfo.peers.begin() + ; pit != fileInfo.peers.end(); ++pit) + { + const TransferInfo &transferInfo = *pit; + + if (transferInfo.peerId == ownId) //don't display transfer to ourselves + continue ; + + //unique combination: fileHash + peerId, variant: hash + peerName (too long) + QString hashFileAndPeerId = fileHash + QString::fromStdString(transferInfo.peerId.toStdString()); + qlonglong completed = transferInfo.transfered; + + double peerULSpeed = transferInfo.tfRate * 1024.0; + + FileProgressInfo peerpinfo ; + if(!rsFiles->FileUploadChunksDetails(fileInfo.hash, transferInfo.peerId, peerpinfo.cmap) ) + continue ; + + // Estimate the completion. We need something more accurate, meaning that we need to + // transmit the completion info. + // + uint32_t chunk_size = 1024*1024 ; + uint32_t nb_chunks = (uint32_t)((fileInfo.size + (uint64_t)chunk_size - 1) / (uint64_t)(chunk_size)) ; + + uint32_t filled_chunks = peerpinfo.cmap.filledChunks(nb_chunks) ; + peerpinfo.type = FileProgressInfo::UPLOAD_LINE ; + peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:nb_chunks ; + + if(filled_chunks > 0 && nb_chunks > 0) + { + completed = peerpinfo.cmap.computeProgress(fileInfo.size,chunk_size) ; + peerpinfo.progress = completed / (float)fileInfo.size * 100.0f ; + } + else + { + completed = transferInfo.transfered % chunk_size ; // use the position with respect to last request. + peerpinfo.progress = (fileInfo.size>0)?((transferInfo.transfered % chunk_size)*100.0/fileInfo.size):0 ; + } + + int row_id = addPeerToULItem(ulItem, transferInfo.peerId, hashFileAndPeerId, completed, peerULSpeed, peerpinfo); + + used_rows.insert(row_id); + peerULSpeedTotal += peerULSpeed; + + } + + // Update Parent UpLoad Speed + ULListModel->setData(ULListModel->index(row, COLUMN_ULSPEED), QVariant((double)peerULSpeedTotal)); + + + // This is not optimal, but we deal with a small number of elements. The reverse order is really important, + // because rows after the deleted rows change positions ! + // + for (int r = ulItem->rowCount() - 1; r >= 0; --r) { + if (used_rows.find(r) == used_rows.end()) { + ulItem->removeRow(r); + } + } return row; } +int TransfersDialog::addPeerToULItem(QStandardItem *ulItem, const RsPeerId& peer_ID, const QString& coreID, qlonglong completed, double ulspeed, const FileProgressInfo& peerInfo) +{ + // try to find the item + int childRow = -1; + + QStandardItem *childId = NULL; + for (int count = 0; (childId = ulItem->child(count, COLUMN_UHASH)) != NULL; ++count) { + if (childId->data(Qt::UserRole).toString() == coreID) { + childRow = count; + break; + } + } + + if (childRow == -1) { + // set this false if you want to expand on double click + ulItem->setEditable(false); + + QHeaderView *header = ui.uploadsList->header(); + + QStandardItem *iName = new QStandardItem(); //COLUMN_UNAME + QStandardItem *iSize = new SortByNameItem(header); //COLUMN_USIZE + QStandardItem *iTransferred = new SortByNameItem(header); //COLUMN_UTRANSFERRED + QStandardItem *iULSpeed = new SortByNameItem(header); //COLUMN_ULSPEED + QStandardItem *iProgress = new ProgressItem(header); //COLUMN_UPROGRESS + QStandardItem *iHash = new SortByNameItem(header); //COLUMN_UHASH + + QList items; + iName->setData( QVariant(getPeerName(peer_ID)), Qt::DisplayRole); + iSize->setData( QVariant(QString()), Qt::DisplayRole); + iTransferred->setData(QVariant((qlonglong)completed), Qt::DisplayRole); + iULSpeed->setData( QVariant((double)ulspeed), Qt::DisplayRole); + iProgress->setData( QVariant::fromValue(peerInfo), Qt::DisplayRole); + iHash->setData( QVariant(), Qt::DisplayRole); + iHash->setData( QVariant(coreID), Qt::UserRole); + + items.append(iName); + items.append(iSize); + items.append(iTransferred); + items.append(iULSpeed); + items.append(iProgress); + items.append(iHash); + ulItem->appendRow(items); + + childRow = ulItem->rowCount() - 1; + } else { + // just update the child (peer) + ulItem->child(childRow, COLUMN_ULSPEED)->setData(QVariant((double)ulspeed), Qt::DisplayRole); + ulItem->child(childRow, COLUMN_UTRANSFERRED)->setData(QVariant((qlonglong)completed), Qt::DisplayRole); + ulItem->child(childRow, COLUMN_UPROGRESS)->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole); + } + + return childRow; +} /* get the list of Transfers from the RsIface. **/ void TransfersDialog::updateDisplay() @@ -1231,26 +1306,24 @@ void TransfersDialog::insertTransfers() ui.downloadList->setSortingEnabled(false); /* get the download lists */ - std::list downHashes; + std::list downHashes; rsFiles->FileDownloads(downHashes); /* build set for quick search */ - std::set hashs; - std::list::iterator it; - for (it = downHashes.begin(); it != downHashes.end(); ++it) { + std::set hashs; + + for (std::list::iterator it = downHashes.begin(); it != downHashes.end(); ++it) { hashs.insert(*it); } /* add downloads, first iterate all rows in list */ int rowCount = DLListModel->rowCount(); - int row ; - std::set::iterator hashIt; - for (row = 0; row < rowCount; ) { - RsFileHash hash ( DLListModel->item(row, COLUMN_ID)->data(Qt::UserRole).toString().toStdString()); + for (int row = 0; row < rowCount; ) { + RsFileHash hash ( DLListModel->item(row, COLUMN_ID)->data(Qt::UserRole).toString().toStdString()); - hashIt = hashs.find(hash); + std::set::iterator hashIt = hashs.find(hash); if (hashIt == hashs.end()) { // remove not existing downloads DLListModel->removeRow(row); @@ -1267,7 +1340,7 @@ void TransfersDialog::insertTransfers() hashs.erase(hashIt); - if (addItem(row, fileInfo) < 0) { + if (addDLItem(row, fileInfo) < 0) { DLListModel->removeRow(row); rowCount = DLListModel->rowCount(); continue; @@ -1278,109 +1351,80 @@ void TransfersDialog::insertTransfers() /* then add new downloads to the list */ - for (hashIt = hashs.begin(); hashIt != hashs.end(); ++hashIt) { + for (std::set::iterator hashIt = hashs.begin() + ; hashIt != hashs.end(); ++hashIt) + { FileInfo fileInfo; if (!rsFiles->FileDetails(*hashIt, RS_FILE_HINTS_DOWNLOAD, fileInfo)) { continue; } - addItem(-1, fileInfo); + addDLItem(-1, fileInfo); } ui.downloadList->setSortingEnabled(true); - ui.uploadsList->setSortingEnabled(false); - // Now show upload hashes // - std::list upHashes; + + /* disable for performance issues, enable after insert all transfers */ + ui.uploadsList->setSortingEnabled(false); + + /* get the upload lists */ + std::list upHashes; rsFiles->FileUploads(upHashes); - RsPeerId ownId = rsPeers->getOwnId(); + /* build set for quick search */ + hashs.clear(); - std::set used_hashes ; - - for(it = upHashes.begin(); it != upHashes.end(); ++it) - { - FileInfo info; - if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info)) - continue; - - std::list::iterator pit; - for(pit = info.peers.begin(); pit != info.peers.end(); ++pit) - { - if (pit->peerId == ownId) //don't display transfer to ourselves - continue ; - - QString fileHash = QString::fromStdString(info.hash.toStdString()); - QString fileName = QString::fromUtf8(info.fname.c_str()); - QString source = getPeerName(pit->peerId); - - QString status; - 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("Uploading"); break; - case FT_STATE_COMPLETE: status = tr("Complete"); break; - default: status = tr("Complete"); break; - - } - - FileProgressInfo pinfo ; - - if(!rsFiles->FileUploadChunksDetails(*it,pit->peerId,pinfo.cmap) ) - continue ; - - double dlspeed = pit->tfRate * 1024.0; - qlonglong fileSize = info.size; - qlonglong completed = pit->transfered; -// double progress = (info.size > 0)?(pit->transfered * 100.0 / info.size):0.0; - qlonglong remaining = (pit->tfRate>0)?((info.size - pit->transfered) / (pit->tfRate * 1024.0)):0; - - // Estimate the completion. We need something more accurate, meaning that we need to - // transmit the completion info. - // - uint32_t chunk_size = 1024*1024 ; - uint32_t nb_chunks = (uint32_t)((info.size + (uint64_t)chunk_size - 1) / (uint64_t)(chunk_size)) ; - - uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ; - pinfo.type = FileProgressInfo::UPLOAD_LINE ; - pinfo.nb_chunks = pinfo.cmap._map.empty()?0:nb_chunks ; - - if(filled_chunks > 0 && nb_chunks > 0) - { - completed = pinfo.cmap.computeProgress(info.size,chunk_size) ; - pinfo.progress = completed / (float)info.size * 100.0f ; - } - else - { - completed = pit->transfered % chunk_size ; // use the position with respect to last request. - pinfo.progress = (info.size>0)?((pit->transfered % chunk_size)*100.0/info.size):0 ; - } - - addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, source,QString::fromStdString(pit->peerId.toStdString()), status, completed, remaining); - - used_hashes.insert(fileHash.toStdString() + pit->peerId.toStdString()) ; - } + for(std::list::iterator it = upHashes.begin(); it != upHashes.end(); ++it) { + hashs.insert(*it); } - - // remove hashes that where not shown - //first clean the model in case some files are not download anymore - //remove items that are not fiends anymore - int removeIndex = 0; - rowCount = ULListModel->rowCount(); - while (removeIndex < rowCount) - { - std::string hash = ULListModel->item(removeIndex, COLUMN_UHASH)->data(Qt::EditRole).toString().toStdString(); - std::string peer = ULListModel->item(removeIndex, COLUMN_UUSERID)->data(Qt::EditRole).toString().toStdString(); - if(used_hashes.find(hash + peer) == used_hashes.end()) { - ULListModel->removeRow(removeIndex); + /* add uploads, first iterate all rows in list */ + + rowCount = ULListModel->rowCount(); + + for (int row = 0; row < rowCount; ) { + RsFileHash hash ( ULListModel->item(row, COLUMN_UHASH)->data(Qt::UserRole).toString().toStdString()); + + std::set::iterator hashIt = hashs.find(hash); + if (hashIt == hashs.end()) { + // remove not existing uploads + ULListModel->removeRow(row); rowCount = ULListModel->rowCount(); - } else - ++removeIndex; + continue; + } + + FileInfo fileInfo; + if (!rsFiles->FileDetails(hash, RS_FILE_HINTS_UPLOAD, fileInfo)) { + ULListModel->removeRow(row); + rowCount = ULListModel->rowCount(); + continue; + } + + hashs.erase(hashIt); + + if (addULItem(row, fileInfo) < 0) { + ULListModel->removeRow(row); + rowCount = ULListModel->rowCount(); + continue; + } + + ++row; + } + + /* then add new uploads to the list */ + + for (std::set::iterator hashIt = hashs.begin() + ; hashIt != hashs.end(); ++hashIt) + { + FileInfo fileInfo; + if (!rsFiles->FileDetails(*hashIt, RS_FILE_HINTS_UPLOAD, fileInfo)) { + continue; + } + + addULItem(-1, fileInfo); } ui.uploadsList->setSortingEnabled(true); @@ -1423,7 +1467,7 @@ void TransfersDialog::cancel() std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { if (first) { first = false; @@ -1464,13 +1508,13 @@ void TransfersDialog::cancel() // } //} -void TransfersDialog::copyLink () +void TransfersDialog::dlCopyLink () { QList links ; std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { FileInfo info; @@ -1527,7 +1571,7 @@ void TransfersDialog::showDetailsDialog() void TransfersDialog::updateDetailsDialog() { std::set items; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); if (!items.empty()) detailsDialog()->setFileHash(*items.begin()); @@ -1538,7 +1582,7 @@ void TransfersDialog::pasteLink() RSLinkClipboard::process(RetroShareLink::TYPE_FILE); } -void TransfersDialog::getSelectedItems(std::set *ids, std::set *rows) +void TransfersDialog::getDLSelectedItems(std::set *ids, std::set *rows) { if (ids == NULL && rows == NULL) { return; @@ -1598,7 +1642,7 @@ bool TransfersDialog::controlTransferFile(uint32_t flags) std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { result &= rsFiles->FileControl(*it, flags); } @@ -1622,13 +1666,13 @@ void TransfersDialog::resumeFileTransfer() } } -void TransfersDialog::openFolderTransfer() +void TransfersDialog::dlOpenFolder() { FileInfo info; std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue; break; @@ -1647,7 +1691,7 @@ void TransfersDialog::openFolderTransfer() qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists() && qinfo.isDir()) { if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) { - std::cerr << "openFolderTransfer(): can't open folder " << path << std::endl; + std::cerr << "dlOpenFolder(): can't open folder " << path << std::endl; } } } @@ -1679,13 +1723,13 @@ void TransfersDialog::ulOpenFolder() } -void TransfersDialog::previewTransfer() +void TransfersDialog::dlPreviewFile() { FileInfo info; std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue; break; @@ -1749,13 +1793,13 @@ void TransfersDialog::previewTransfer() } } -void TransfersDialog::openTransfer() +void TransfersDialog::dlOpenFile() { FileInfo info; std::set items ; std::set::iterator it ; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue; break; @@ -1814,7 +1858,7 @@ void TransfersDialog::setChunkStrategy(FileChunksInfo::ChunkStrategy s) { std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { rsFiles->setChunkStrategy(*it, s); @@ -1855,7 +1899,7 @@ void TransfersDialog::changeSpeed(int speed) { std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { @@ -1884,7 +1928,7 @@ static bool checkFileName(const QString& name) void TransfersDialog::renameFile() { std::set items; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); if(items.size() != 1) { @@ -1920,7 +1964,7 @@ void TransfersDialog::changeQueuePosition(QueueMove mv) // std::cerr << "In changeQueuePosition (gui)"<< std::endl ; std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { @@ -1937,7 +1981,7 @@ void TransfersDialog::clearcompleted() void TransfersDialog::showFileDetails() { std::set items ; - getSelectedItems(&items, NULL) ; + getDLSelectedItems(&items, NULL) ; if(items.size() != 1) detailsDialog()->setFileHash(RsFileHash()); else @@ -2031,7 +2075,7 @@ void TransfersDialog::collCreate() std::set items ; std::set::iterator it ; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); for (it = items.begin(); it != items.end(); ++it) { FileInfo info; @@ -2055,7 +2099,7 @@ void TransfersDialog::collModif() std::set items ; std::set::iterator it ; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); if (items.size() != 1) return; it = items.begin(); @@ -2085,7 +2129,7 @@ void TransfersDialog::collView() std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); if (items.size() != 1) return; it = items.begin(); @@ -2115,7 +2159,7 @@ void TransfersDialog::collOpen() std::set items; std::set::iterator it; - getSelectedItems(&items, NULL); + getDLSelectedItems(&items, NULL); if (items.size() == 1) { it = items.begin(); diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h index bde0036cd..e6385821f 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h @@ -95,7 +95,7 @@ private slots: /** removes finished Downloads**/ void clearcompleted(); - void copyLink(); + void dlCopyLink(); void pasteLink(); void renameFile(); void setDestinationDirectory(); @@ -109,9 +109,9 @@ private slots: void pauseFileTransfer(); void resumeFileTransfer(); - void openFolderTransfer(); - void openTransfer(); - void previewTransfer(); + void dlOpenFolder(); + void dlOpenFile(); + void dlPreviewFile(); void ulOpenFolder(); void ulCopyLink(); @@ -235,7 +235,7 @@ private: bool m_bProcessSettings; void processSettings(bool bLoad); - void getSelectedItems(std::set *ids, std::set *rows); + void getDLSelectedItems(std::set *ids, std::set *rows); void getULSelectedItems(std::set *ids, std::set *rows); bool controlTransferFile(uint32_t flags); void changePriority(int priority); @@ -255,12 +255,11 @@ private: Ui::TransfersDialog ui; public slots: - // these two functions add entries to the transfers dialog, and return the row id of the entry modified/added - // - int addItem(int row, const FileInfo &fileInfo); - int addPeerToItem(QStandardItem *dlItem, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo); - - int addUploadItem(const QString& symbol, const QString& name, const QString& coreID, qlonglong size, const FileProgressInfo& pinfo, double dlspeed, const QString& sources,const QString& source_id, const QString& status, qlonglong completed, qlonglong remaining); + // these four functions add entries to the transfers dialog, and return the row id of the entry modified/added + int addDLItem(int row, const FileInfo &fileInfo); + int addPeerToDLItem(QStandardItem *dlItem, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo); + int addULItem(int row, const FileInfo &fileInfo); + int addPeerToULItem(QStandardItem *ulItem, const RsPeerId& peer_ID, const QString &coreID, qlonglong completed, double ulspeed, const FileProgressInfo& peerInfo); void showFileDetails() ; diff --git a/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp b/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp index 6a6f58c2c..f38506658 100644 --- a/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp +++ b/retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp @@ -45,7 +45,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti QPixmap pixmap; qlonglong fileSize; double ulspeed, multi; - QString temp , status; + QString temp; qlonglong transferred; // prepare @@ -65,7 +65,12 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti } // draw the background color - if(index.column() != COLUMN_UPROGRESS) { + bool bDrawBackground = true; + if(index.column() == COLUMN_UPROGRESS) { + FileProgressInfo pinfo = index.data().value() ; + bDrawBackground = (pinfo.type == FileProgressInfo::UNINIT); + } + if( bDrawBackground ) { if(option.showDecorationSelected && (option.state & QStyle::State_Selected)) { if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) { cg = QPalette::Inactive; @@ -78,6 +83,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti } } } + switch(index.column()) { case COLUMN_USIZE: fileSize = index.data().toLongLong(); @@ -128,15 +134,17 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti } painter->drawText(option.rect, Qt::AlignRight, temp); break; - case COLUMN_UPROGRESS: + case COLUMN_UPROGRESS: { FileProgressInfo pinfo = index.data().value() ; + if (pinfo.type == FileProgressInfo::UNINIT) + break; // create a xProgressBar painter->save() ; xProgressBar progressBar(pinfo,option.rect,painter,0);// the 3rd param is the color schema (0 is the default value) - QString ext = QFileInfo(QString::fromStdString(index.sibling(index.row(), COLUMN_UNAME).data().toString().toStdString())).suffix();; + QString ext = QFileInfo(QString::fromStdString(index.sibling(index.row(), COLUMN_UNAME).data().toString().toStdString())).suffix();; if (ext == "rsfc" || ext == "rsrl" || ext == "dist" || ext == "rsfb") progressBar.setColorSchema( 9); else @@ -161,9 +169,6 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti } painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, index.data().toString()); break; - case COLUMN_USTATUS: - painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignCenter, index.data().toString()); - break; default: painter->drawText(option.rect, Qt::AlignCenter, index.data().toString()); } diff --git a/retroshare-gui/src/gui/FileTransfer/ULListDelegate.h b/retroshare-gui/src/gui/FileTransfer/ULListDelegate.h index 5c080f656..cd0522e5f 100644 --- a/retroshare-gui/src/gui/FileTransfer/ULListDelegate.h +++ b/retroshare-gui/src/gui/FileTransfer/ULListDelegate.h @@ -30,11 +30,8 @@ #define COLUMN_UTRANSFERRED 2 #define COLUMN_ULSPEED 3 #define COLUMN_UPROGRESS 4 -#define COLUMN_USTATUS 5 -#define COLUMN_USERNAME 6 -#define COLUMN_UHASH 7 -#define COLUMN_UUSERID 8 -#define COLUMN_UCOUNT 9 +#define COLUMN_UHASH 5 +#define COLUMN_UCOUNT 6 #define MAX_CHAR_TMP 128 diff --git a/retroshare-gui/src/gui/FileTransfer/xprogressbar.h b/retroshare-gui/src/gui/FileTransfer/xprogressbar.h index ba590a86e..1f072f52a 100644 --- a/retroshare-gui/src/gui/FileTransfer/xprogressbar.h +++ b/retroshare-gui/src/gui/FileTransfer/xprogressbar.h @@ -39,7 +39,9 @@ class FileProgressInfo { public: - typedef enum { DOWNLOAD_LINE,UPLOAD_LINE,DOWNLOAD_SOURCE } LineType ; + typedef enum { UNINIT, DOWNLOAD_LINE, UPLOAD_LINE, DOWNLOAD_SOURCE } LineType ; + + FileProgressInfo() : type(UNINIT), progress(0.0) {} LineType type ; CompressedChunkMap cmap ;