consistent renaming of columns in transfers tab and display of last time file has been written (Patch from Phenom)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6471 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-07-01 21:03:20 +00:00
parent 30c4a6ef93
commit f78e5da41e
6 changed files with 173 additions and 143 deletions

View File

@ -72,7 +72,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
// draw the background color if not the progress column or if progress is not displayed // draw the background color if not the progress column or if progress is not displayed
if(index.column() != PROGRESS) { if(index.column() != COLUMN_PROGRESS) {
if(option.showDecorationSelected && (option.state & QStyle::State_Selected)) { if(option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) { if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
cg = QPalette::Inactive; cg = QPalette::Inactive;
@ -86,7 +86,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
} }
switch(index.column()) { switch(index.column()) {
case SIZE: case COLUMN_SIZE:
fileSize = index.data().toLongLong(); fileSize = index.data().toLongLong();
if(fileSize <= 0){ if(fileSize <= 0){
temp = ""; temp = "";
@ -105,7 +105,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignRight, temp); painter->drawText(option.rect, Qt::AlignRight, temp);
break; break;
case REMAINING: case COLUMN_REMAINING:
remaining = index.data().toLongLong(); remaining = index.data().toLongLong();
if(remaining <= 0){ if(remaining <= 0){
temp = ""; temp = "";
@ -124,7 +124,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignRight, temp); painter->drawText(option.rect, Qt::AlignRight, temp);
break; break;
case COMPLETED: case COLUMN_COMPLETED:
completed = index.data().toLongLong(); completed = index.data().toLongLong();
if(completed <= 0){ if(completed <= 0){
temp = ""; temp = "";
@ -143,7 +143,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignRight, temp); painter->drawText(option.rect, Qt::AlignRight, temp);
break; break;
case DLSPEED: case COLUMN_DLSPEED:
dlspeed = index.data().toDouble(); dlspeed = index.data().toDouble();
if (dlspeed <= 0) { if (dlspeed <= 0) {
temp = ""; temp = "";
@ -154,7 +154,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignRight, temp); painter->drawText(option.rect, Qt::AlignRight, temp);
break; break;
case PROGRESS: case COLUMN_PROGRESS:
{ {
// create a xProgressBar // create a xProgressBar
FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ; FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ;
@ -183,7 +183,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignCenter, newopt.text); painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
break; break;
case DOWNLOADTIME: case COLUMN_DOWNLOADTIME:
downloadtime = index.data().toLongLong(); downloadtime = index.data().toLongLong();
minutes = downloadtime / 60; minutes = downloadtime / 60;
seconds = downloadtime % 60; seconds = downloadtime % 60;
@ -203,7 +203,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
temp = "" ; temp = "" ;
painter->drawText(option.rect, Qt::AlignCenter, temp); painter->drawText(option.rect, Qt::AlignCenter, temp);
break; break;
case NAME: case COLUMN_NAME:
// decoration // decoration
value = index.data(Qt::DecorationRole); value = index.data(Qt::DecorationRole);
temp = index.data().toString(); temp = index.data().toString();

View File

@ -27,17 +27,19 @@
// Defines for download list list columns // Defines for download list list columns
#define NAME 0 #define COLUMN_NAME 0
#define SIZE 1 #define COLUMN_SIZE 1
#define COMPLETED 2 #define COLUMN_COMPLETED 2
#define DLSPEED 3 #define COLUMN_DLSPEED 3
#define PROGRESS 4 #define COLUMN_PROGRESS 4
#define SOURCES 5 #define COLUMN_SOURCES 5
#define STATUS 6 #define COLUMN_STATUS 6
#define PRIORITY 7 #define COLUMN_PRIORITY 7
#define REMAINING 8 #define COLUMN_REMAINING 8
#define DOWNLOADTIME 9 #define COLUMN_DOWNLOADTIME 9
#define ID 10 #define COLUMN_ID 10
#define COLUMN_LASTDL 11
#define COLUMN_COUNT 12
#define MAX_CHAR_TMP 128 #define MAX_CHAR_TMP 128

View File

@ -30,6 +30,7 @@
#include <QTreeView> #include <QTreeView>
#include <QShortcut> #include <QShortcut>
#include <QFileInfo> #include <QFileInfo>
#include <QDateTime>
#include <QDir> #include <QDir>
#include <QMessageBox> #include <QMessageBox>
#include <gui/common/RsUrlHandler.h> #include <gui/common/RsUrlHandler.h>
@ -110,8 +111,8 @@ public:
return QStandardItem::operator<(other); return QStandardItem::operator<(other);
} }
QStandardItem *myName = myParent->child(index().row(), NAME); QStandardItem *myName = myParent->child(index().row(), COLUMN_NAME);
QStandardItem *otherName = otherParent->child(other.index().row(), NAME); QStandardItem *otherName = otherParent->child(other.index().row(), COLUMN_NAME);
if (header == NULL || header->sortIndicatorOrder() == Qt::AscendingOrder) { if (header == NULL || header->sortIndicatorOrder() == Qt::AscendingOrder) {
/* Ascending */ /* Ascending */
@ -187,20 +188,21 @@ TransfersDialog::TransfersDialog(QWidget *parent)
connect( ui.downloadList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( downloadListCustomPopupMenu( QPoint ) ) ); connect( ui.downloadList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( downloadListCustomPopupMenu( QPoint ) ) );
// Set Download list model // Set Download list model
DLListModel = new QStandardItemModel(0,ID + 1); DLListModel = new QStandardItemModel(0,COLUMN_COUNT);
DLListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name", "i.e: file name")); DLListModel->setHeaderData(COLUMN_NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
DLListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); DLListModel->setHeaderData(COLUMN_SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
DLListModel->setHeaderData(COMPLETED, Qt::Horizontal, tr("Completed", "")); DLListModel->setHeaderData(COLUMN_COMPLETED, Qt::Horizontal, tr("Completed", ""));
DLListModel->setHeaderData(DLSPEED, Qt::Horizontal, tr("Speed", "i.e: Download speed")); DLListModel->setHeaderData(COLUMN_DLSPEED, Qt::Horizontal, tr("Speed", "i.e: Download speed"));
DLListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress / Availability", "i.e: % downloaded")); DLListModel->setHeaderData(COLUMN_PROGRESS, Qt::Horizontal, tr("Progress / Availability", "i.e: % downloaded"));
DLListModel->setHeaderData(SOURCES, Qt::Horizontal, tr("Sources", "i.e: Sources")); DLListModel->setHeaderData(COLUMN_SOURCES, Qt::Horizontal, tr("Sources", "i.e: Sources"));
DLListModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status")); DLListModel->setHeaderData(COLUMN_STATUS, Qt::Horizontal, tr("Status"));
DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Speed / Queue position")); DLListModel->setHeaderData(COLUMN_PRIORITY, Qt::Horizontal, tr("Speed / Queue position"));
DLListModel->setHeaderData(REMAINING, Qt::Horizontal, tr("Remaining")); DLListModel->setHeaderData(COLUMN_REMAINING, Qt::Horizontal, tr("Remaining"));
DLListModel->setHeaderData(DOWNLOADTIME, Qt::Horizontal, tr("Download time", "i.e: Estimated Time of Arrival / Time left")); DLListModel->setHeaderData(COLUMN_DOWNLOADTIME, Qt::Horizontal, tr("Download time", "i.e: Estimated Time of Arrival / Time left"));
DLListModel->setHeaderData(ID, Qt::Horizontal, tr("Core-ID")); DLListModel->setHeaderData(COLUMN_ID, Qt::Horizontal, tr("Core-ID"));
DLListModel->setHeaderData(COLUMN_LASTDL, Qt::Horizontal, tr("Last Time Seen", "i.e: Last Time Receiced Data"));
ui.downloadList->setModel(DLListModel); ui.downloadList->setModel(DLListModel);
ui.downloadList->hideColumn(ID); //ui.downloadList->hideColumn(ID);
DLDelegate = new DLListDelegate(); DLDelegate = new DLListDelegate();
ui.downloadList->setItemDelegate(DLDelegate); ui.downloadList->setItemDelegate(DLDelegate);
@ -223,42 +225,49 @@ TransfersDialog::TransfersDialog(QWidget *parent)
/* Set header resize modes and initial section sizes Downloads TreeView*/ /* Set header resize modes and initial section sizes Downloads TreeView*/
QHeaderView * _header = ui.downloadList->header () ; QHeaderView * _header = ui.downloadList->header () ;
_header->setResizeMode (NAME, QHeaderView::Interactive); _header->setResizeMode (COLUMN_NAME, QHeaderView::Interactive);
_header->setResizeMode (SIZE, QHeaderView::Interactive); _header->setResizeMode (COLUMN_SIZE, QHeaderView::Interactive);
_header->setResizeMode (COMPLETED, QHeaderView::Interactive); _header->setResizeMode (COLUMN_COMPLETED, QHeaderView::Interactive);
_header->setResizeMode (DLSPEED, QHeaderView::Interactive); _header->setResizeMode (COLUMN_DLSPEED, QHeaderView::Interactive);
_header->setResizeMode (PROGRESS, QHeaderView::Interactive); _header->setResizeMode (COLUMN_PROGRESS, QHeaderView::Interactive);
_header->setResizeMode (SOURCES, QHeaderView::Interactive); _header->setResizeMode (COLUMN_SOURCES, QHeaderView::Interactive);
_header->setResizeMode (STATUS, QHeaderView::Interactive); _header->setResizeMode (COLUMN_STATUS, QHeaderView::Interactive);
_header->setResizeMode (PRIORITY, QHeaderView::Interactive); _header->setResizeMode (COLUMN_PRIORITY, QHeaderView::Interactive);
_header->setResizeMode (REMAINING, QHeaderView::Interactive); _header->setResizeMode (COLUMN_REMAINING, QHeaderView::Interactive);
_header->setResizeMode (COLUMN_DOWNLOADTIME, QHeaderView::Interactive);
_header->setResizeMode (COLUMN_ID, QHeaderView::Interactive);
_header->setResizeMode (COLUMN_LASTDL, QHeaderView::Interactive);
_header->resizeSection ( NAME, 170 ); _header->resizeSection ( COLUMN_NAME, 170 );
_header->resizeSection ( SIZE, 70 ); _header->resizeSection ( COLUMN_SIZE, 70 );
_header->resizeSection ( COMPLETED, 75 ); _header->resizeSection ( COLUMN_COMPLETED, 75 );
_header->resizeSection ( DLSPEED, 75 ); _header->resizeSection ( COLUMN_DLSPEED, 75 );
_header->resizeSection ( PROGRESS, 170 ); _header->resizeSection ( COLUMN_PROGRESS, 170 );
_header->resizeSection ( SOURCES, 90 ); _header->resizeSection ( COLUMN_SOURCES, 90 );
_header->resizeSection ( STATUS, 100 ); _header->resizeSection ( COLUMN_STATUS, 100 );
_header->resizeSection ( PRIORITY, 100 ); _header->resizeSection ( COLUMN_PRIORITY, 100 );
_header->resizeSection ( REMAINING, 100 ); _header->resizeSection ( COLUMN_REMAINING, 100 );
_header->resizeSection ( COLUMN_DOWNLOADTIME, 100 );
_header->resizeSection ( COLUMN_ID, 100 );
_header->resizeSection ( COLUMN_LASTDL, 100 );
// set default column and sort order for download // set default column and sort order for download
ui.downloadList->sortByColumn(NAME, Qt::AscendingOrder); ui.downloadList->sortByColumn(COLUMN_NAME, Qt::AscendingOrder);
// Set Upload list model // Set Upload list model
ULListModel = new QStandardItemModel(0,8); ULListModel = new QStandardItemModel(0,COLUMN_UCOUNT);
ULListModel->setHeaderData(UNAME, Qt::Horizontal, tr("Name", "i.e: file name")); ULListModel->setHeaderData(COLUMN_UNAME, Qt::Horizontal, tr("Name", "i.e: file name"));
ULListModel->setHeaderData(USIZE, Qt::Horizontal, tr("Size", "i.e: file size")); ULListModel->setHeaderData(COLUMN_USIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
ULListModel->setHeaderData(USERNAME, Qt::Horizontal, tr("Peer", "i.e: user name")); ULListModel->setHeaderData(COLUMN_USERNAME, Qt::Horizontal, tr("Peer", "i.e: user name"));
ULListModel->setHeaderData(UPROGRESS, Qt::Horizontal, tr("Progress", "i.e: % uploaded")); ULListModel->setHeaderData(COLUMN_UPROGRESS, Qt::Horizontal, tr("Progress", "i.e: % uploaded"));
ULListModel->setHeaderData(ULSPEED, Qt::Horizontal, tr("Speed", "i.e: upload speed")); ULListModel->setHeaderData(COLUMN_ULSPEED, Qt::Horizontal, tr("Speed", "i.e: upload speed"));
ULListModel->setHeaderData(USTATUS, Qt::Horizontal, tr("Status")); ULListModel->setHeaderData(COLUMN_USTATUS, Qt::Horizontal, tr("Status"));
ULListModel->setHeaderData(UTRANSFERRED, Qt::Horizontal, tr("Transferred", "")); ULListModel->setHeaderData(COLUMN_UTRANSFERRED, Qt::Horizontal, tr("Transferred", ""));
ULListModel->setHeaderData(UHASH, Qt::Horizontal, tr("Hash", "")); ULListModel->setHeaderData(COLUMN_UHASH, Qt::Horizontal, tr("Hash", ""));
ULListModel->setHeaderData(COLUMN_UUSERID, Qt::Horizontal, tr("UserID", ""));
ui.uploadsList->setModel(ULListModel); ui.uploadsList->setModel(ULListModel);
ULListModel->insertColumn(UUSERID); //ULListModel->insertColumn(COLUMN_UUSERID);
ui.uploadsList->hideColumn(UUSERID); //ui.uploadsList->hideColumn(COLUMN_UUSERID);
ULDelegate = new ULListDelegate(); ULDelegate = new ULListDelegate();
ui.uploadsList->setItemDelegate(ULDelegate); ui.uploadsList->setItemDelegate(ULDelegate);
@ -275,24 +284,24 @@ TransfersDialog::TransfersDialog(QWidget *parent)
/* Set header resize modes and initial section sizes Uploads TreeView*/ /* Set header resize modes and initial section sizes Uploads TreeView*/
QHeaderView * upheader = ui.uploadsList->header () ; QHeaderView * upheader = ui.uploadsList->header () ;
upheader->setResizeMode (UNAME, QHeaderView::Interactive); upheader->setResizeMode (COLUMN_UNAME, QHeaderView::Interactive);
upheader->setResizeMode (USIZE, QHeaderView::Interactive); upheader->setResizeMode (COLUMN_USIZE, QHeaderView::Interactive);
upheader->setResizeMode (UTRANSFERRED, QHeaderView::Interactive); upheader->setResizeMode (COLUMN_UTRANSFERRED, QHeaderView::Interactive);
upheader->setResizeMode (ULSPEED, QHeaderView::Interactive); upheader->setResizeMode (COLUMN_ULSPEED, QHeaderView::Interactive);
upheader->setResizeMode (UPROGRESS, QHeaderView::Interactive); upheader->setResizeMode (COLUMN_UPROGRESS, QHeaderView::Interactive);
upheader->setResizeMode (USTATUS, QHeaderView::Interactive); upheader->setResizeMode (COLUMN_USTATUS, QHeaderView::Interactive);
upheader->setResizeMode (USERNAME, QHeaderView::Interactive); upheader->setResizeMode (COLUMN_USERNAME, QHeaderView::Interactive);
upheader->resizeSection ( UNAME, 190 ); upheader->resizeSection ( COLUMN_UNAME, 190 );
upheader->resizeSection ( USIZE, 70 ); upheader->resizeSection ( COLUMN_USIZE, 70 );
upheader->resizeSection ( UTRANSFERRED, 75 ); upheader->resizeSection ( COLUMN_UTRANSFERRED, 75 );
upheader->resizeSection ( ULSPEED, 75 ); upheader->resizeSection ( COLUMN_ULSPEED, 75 );
upheader->resizeSection ( UPROGRESS, 170 ); upheader->resizeSection ( COLUMN_UPROGRESS, 170 );
upheader->resizeSection ( USTATUS, 100 ); upheader->resizeSection ( COLUMN_USTATUS, 100 );
upheader->resizeSection ( USERNAME, 120 ); upheader->resizeSection ( COLUMN_USERNAME, 120 );
// set default column and sort order for upload // set default column and sort order for upload
ui.uploadsList->sortByColumn(UNAME, Qt::AscendingOrder); ui.uploadsList->sortByColumn(COLUMN_UNAME, Qt::AscendingOrder);
// FileTransferInfoWidget *ftiw = new FileTransferInfoWidget(); // FileTransferInfoWidget *ftiw = new FileTransferInfoWidget();
// ui.fileTransferInfoWidget->setWidget(ftiw); // ui.fileTransferInfoWidget->setWidget(ftiw);
@ -742,6 +751,18 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo, const std::map<s
qlonglong completed = fileInfo.transfered; qlonglong completed = fileInfo.transfered;
qlonglong remaining = fileInfo.size - fileInfo.transfered; qlonglong remaining = fileInfo.size - fileInfo.transfered;
qlonglong downloadtime = (fileInfo.size - fileInfo.transfered) / (fileInfo.tfRate * 1024.0); qlonglong downloadtime = (fileInfo.size - fileInfo.transfered) / (fileInfo.tfRate * 1024.0);
QString strLastDL = tr("File Never Seen");
QFileInfo file;
if (fileInfo.downloadStatus == FT_STATE_COMPLETE) {
file = QFileInfo(QString::fromUtf8(fileInfo.path.c_str()), QString::fromUtf8(fileInfo.fname.c_str()));
} else {
file = QFileInfo(QString::fromUtf8(rsFiles->getPartialsDirectory().c_str()), QString::fromUtf8(fileInfo.hash.c_str()));
}
/*Get Last Access on File */
if (file.exists()) {
strLastDL= file.lastModified().toString("yyyy-MM-dd_hh:mm:ss");
}
FileChunksInfo fcinfo; FileChunksInfo fcinfo;
if (!rsFiles->FileDownloadChunksDetails(fileInfo.hash, fcinfo)) { if (!rsFiles->FileDownloadChunksDetails(fileInfo.hash, fcinfo)) {
@ -777,26 +798,27 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo, const std::map<s
DLListModel->insertRow(row); DLListModel->insertRow(row);
// change progress column to own class for sorting // change progress column to own class for sorting
DLListModel->setItem(row, PROGRESS, new ProgressItem(NULL)); DLListModel->setItem(row, COLUMN_PROGRESS, new ProgressItem(NULL));
DLListModel->setItem(row, PRIORITY, new PriorityItem(NULL)); DLListModel->setItem(row, COLUMN_PRIORITY, new PriorityItem(NULL));
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong) fileInfo.size)); DLListModel->setData(DLListModel->index(row, COLUMN_SIZE), QVariant((qlonglong) fileInfo.size));
DLListModel->setData(DLListModel->index(row, ID), fileHash); DLListModel->setData(DLListModel->index(row, COLUMN_ID), fileHash);
} }
QString fileName = QString::fromUtf8(fileInfo.fname.c_str()); QString fileName = QString::fromUtf8(fileInfo.fname.c_str());
DLListModel->setData(DLListModel->index(row, NAME), fileName); DLListModel->setData(DLListModel->index(row, COLUMN_NAME), fileName);
DLListModel->setData(DLListModel->index(row, NAME), FilesDefs::getIconFromFilename(fileName), Qt::DecorationRole); DLListModel->setData(DLListModel->index(row, COLUMN_NAME), FilesDefs::getIconFromFilename(fileName), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(row, COMPLETED), QVariant((qlonglong)completed)); DLListModel->setData(DLListModel->index(row, COLUMN_COMPLETED), QVariant((qlonglong)completed));
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)fileDlspeed)); DLListModel->setData(DLListModel->index(row, COLUMN_DLSPEED), QVariant((double)fileDlspeed));
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant::fromValue(pinfo)); DLListModel->setData(DLListModel->index(row, COLUMN_PROGRESS), QVariant::fromValue(pinfo));
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(status)); DLListModel->setData(DLListModel->index(row, COLUMN_STATUS), QVariant(status));
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant(priority)); DLListModel->setData(DLListModel->index(row, COLUMN_PRIORITY), QVariant(priority));
DLListModel->setData(DLListModel->index(row, REMAINING), QVariant((qlonglong)remaining)); DLListModel->setData(DLListModel->index(row, COLUMN_REMAINING), QVariant((qlonglong)remaining));
DLListModel->setData(DLListModel->index(row, DOWNLOADTIME), QVariant((qlonglong)downloadtime)); DLListModel->setData(DLListModel->index(row, COLUMN_DOWNLOADTIME), QVariant((qlonglong)downloadtime));
DLListModel->setData(DLListModel->index(row, COLUMN_LASTDL), QVariant(strLastDL));
DLListModel->item(row,STATUS)->setToolTip(tooltip); DLListModel->item(row,COLUMN_STATUS)->setToolTip(tooltip);
QStandardItem *dlItem = DLListModel->item(row); QStandardItem *dlItem = DLListModel->item(row);
@ -839,7 +861,7 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo, const std::map<s
} }
QString sources = QString("%1 (%2)").arg(active).arg(fileInfo.peers.size()); QString sources = QString("%1 (%2)").arg(active).arg(fileInfo.peers.size());
DLListModel->setData(DLListModel->index(row, SOURCES), QVariant(sources)); DLListModel->setData(DLListModel->index(row, COLUMN_SOURCES), QVariant(sources));
// This is not optimal, but we deal with a small number of elements. The reverse order is really important, // 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 ! // because rows after the deleted rows change positions !
@ -860,7 +882,7 @@ int TransfersDialog::addPeerToItem(QStandardItem *dlItem, const QString& name, c
int count = 0; int count = 0;
QStandardItem *childId = NULL; QStandardItem *childId = NULL;
for (count = 0; (childId = dlItem->child(count, ID)) != NULL; ++count) { for (count = 0; (childId = dlItem->child(count, COLUMN_ID)) != NULL; ++count) {
if (childId->data(Qt::DisplayRole).toString() == coreID) { if (childId->data(Qt::DisplayRole).toString() == coreID) {
childRow = count; childRow = count;
break; break;
@ -920,11 +942,11 @@ int TransfersDialog::addPeerToItem(QStandardItem *dlItem, const QString& name, c
childRow = dlItem->rowCount() - 1; childRow = dlItem->rowCount() - 1;
} else { } else {
// just update the child (peer) // just update the child (peer)
dlItem->child(childRow, DLSPEED)->setData(QVariant((double)dlspeed), Qt::DisplayRole); dlItem->child(childRow, COLUMN_DLSPEED)->setData(QVariant((double)dlspeed), Qt::DisplayRole);
dlItem->child(childRow, PROGRESS)->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole); dlItem->child(childRow, COLUMN_PROGRESS)->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole);
si1 = dlItem->child(childRow,NAME); si1 = dlItem->child(childRow,COLUMN_NAME);
si7 = dlItem->child(childRow, STATUS); si7 = dlItem->child(childRow, COLUMN_STATUS);
} }
switch (status) { switch (status) {
@ -965,7 +987,7 @@ int TransfersDialog::addUploadItem( const QString&, const QString& name, const Q
// //
int row ; int row ;
for(row=0;row<ULListModel->rowCount();++row) for(row=0;row<ULListModel->rowCount();++row)
if(ULListModel->item(row,UUSERID)->data(Qt::EditRole).toString() == peer_id && ULListModel->item(row,UHASH)->data(Qt::EditRole).toString() == coreID) if(ULListModel->item(row,COLUMN_UUSERID)->data(Qt::EditRole).toString() == peer_id && ULListModel->item(row,COLUMN_UHASH)->data(Qt::EditRole).toString() == coreID)
break ; break ;
if(row >= ULListModel->rowCount() ) if(row >= ULListModel->rowCount() )
@ -974,21 +996,21 @@ int TransfersDialog::addUploadItem( const QString&, const QString& name, const Q
ULListModel->insertRow(row); ULListModel->insertRow(row);
// change progress column to own class for sorting // change progress column to own class for sorting
ULListModel->setItem(row, UPROGRESS, new ProgressItem(NULL)); ULListModel->setItem(row, COLUMN_UPROGRESS, new ProgressItem(NULL));
ULListModel->setData(ULListModel->index(row, UNAME), QVariant((QString)" "+name), Qt::DisplayRole); ULListModel->setData(ULListModel->index(row, COLUMN_UNAME), QVariant((QString)" "+name), Qt::DisplayRole);
ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)source)); ULListModel->setData(ULListModel->index(row, COLUMN_USERNAME), QVariant((QString)source));
ULListModel->setData(ULListModel->index(row, UHASH), QVariant((QString)coreID)); ULListModel->setData(ULListModel->index(row, COLUMN_UHASH), QVariant((QString)coreID));
ULListModel->setData(ULListModel->index(row, UUSERID), QVariant((QString)peer_id)); ULListModel->setData(ULListModel->index(row, COLUMN_UUSERID), QVariant((QString)peer_id));
ULListModel->setData(ULListModel->index(row,UNAME), FilesDefs::getIconFromFilename(name), Qt::DecorationRole); ULListModel->setData(ULListModel->index(row,COLUMN_UNAME), FilesDefs::getIconFromFilename(name), Qt::DecorationRole);
} }
ULListModel->setData(ULListModel->index(row, USIZE), QVariant((qlonglong)fileSize)); ULListModel->setData(ULListModel->index(row, COLUMN_USIZE), QVariant((qlonglong)fileSize));
ULListModel->setData(ULListModel->index(row, UTRANSFERRED), QVariant((qlonglong)completed)); ULListModel->setData(ULListModel->index(row, COLUMN_UTRANSFERRED), QVariant((qlonglong)completed));
ULListModel->setData(ULListModel->index(row, ULSPEED), QVariant((double)dlspeed)); ULListModel->setData(ULListModel->index(row, COLUMN_ULSPEED), QVariant((double)dlspeed));
ULListModel->setData(ULListModel->index(row, UPROGRESS), QVariant::fromValue(pinfo)); ULListModel->setData(ULListModel->index(row, COLUMN_UPROGRESS), QVariant::fromValue(pinfo));
ULListModel->setData(ULListModel->index(row, USTATUS), QVariant((QString)status)); ULListModel->setData(ULListModel->index(row, COLUMN_USTATUS), QVariant((QString)status));
return row; return row;
} }
@ -1028,7 +1050,7 @@ void TransfersDialog::insertTransfers()
std::set<std::string>::iterator hashIt; std::set<std::string>::iterator hashIt;
for (row = 0; row < rowCount; ) { for (row = 0; row < rowCount; ) {
std::string hash = DLListModel->item(row, ID)->data(Qt::DisplayRole).toString().toStdString(); std::string hash = DLListModel->item(row, COLUMN_ID)->data(Qt::DisplayRole).toString().toStdString();
hashIt = hashs.find(hash); hashIt = hashs.find(hash);
if (hashIt == hashs.end()) { if (hashIt == hashs.end()) {
@ -1168,8 +1190,8 @@ void TransfersDialog::insertTransfers()
rowCount = ULListModel->rowCount(); rowCount = ULListModel->rowCount();
while (removeIndex < rowCount) while (removeIndex < rowCount)
{ {
std::string hash = ULListModel->item(removeIndex, UHASH)->data(Qt::EditRole).toString().toStdString(); std::string hash = ULListModel->item(removeIndex, COLUMN_UHASH)->data(Qt::EditRole).toString().toStdString();
std::string peer = ULListModel->item(removeIndex, UUSERID)->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()) { if(used_hashes.find(hash + peer) == used_hashes.end()) {
ULListModel->removeRow(removeIndex); ULListModel->removeRow(removeIndex);
@ -1339,7 +1361,7 @@ void TransfersDialog::getSelectedItems(std::set<std::string> *ids, std::set<int>
/* if transfered file or it's peers are selected control it*/ /* if transfered file or it's peers are selected control it*/
if (isParentSelected || isChildSelected) { if (isParentSelected || isChildSelected) {
if (ids) { if (ids) {
QStandardItem *id = DLListModel->item(i, ID); QStandardItem *id = DLListModel->item(i, COLUMN_ID);
ids->insert(id->data(Qt::DisplayRole).toString().toStdString()); ids->insert(id->data(Qt::DisplayRole).toString().toStdString());
} }
if (rows) { if (rows) {
@ -1671,55 +1693,60 @@ return 0.0 ;
double TransfersDialog::getSpeed(int row, QStandardItemModel *model) double TransfersDialog::getSpeed(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, DLSPEED), Qt::DisplayRole).toDouble(); return model->data(model->index(row, COLUMN_DLSPEED), Qt::DisplayRole).toDouble();
} }
QString TransfersDialog::getFileName(int row, QStandardItemModel *model) QString TransfersDialog::getFileName(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, NAME), Qt::DisplayRole).toString(); return model->data(model->index(row, COLUMN_NAME), Qt::DisplayRole).toString();
} }
QString TransfersDialog::getStatus(int row, QStandardItemModel *model) QString TransfersDialog::getStatus(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, STATUS), Qt::DisplayRole).toString(); return model->data(model->index(row, COLUMN_STATUS), Qt::DisplayRole).toString();
} }
QString TransfersDialog::getID(int row, QStandardItemModel *model) QString TransfersDialog::getID(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, ID), Qt::DisplayRole).toString().left(40); // gets only the "hash" part of the name return model->data(model->index(row, COLUMN_ID), Qt::DisplayRole).toString().left(40); // gets only the "hash" part of the name
} }
QString TransfersDialog::getPriority(int row, QStandardItemModel *model) QString TransfersDialog::getPriority(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, PRIORITY), Qt::DisplayRole).toString(); return model->data(model->index(row, COLUMN_PRIORITY), Qt::DisplayRole).toString();
} }
qlonglong TransfersDialog::getFileSize(int row, QStandardItemModel *model) qlonglong TransfersDialog::getFileSize(int row, QStandardItemModel *model)
{ {
bool ok = false; bool ok = false;
return model->data(model->index(row, SIZE), Qt::DisplayRole).toULongLong(&ok); return model->data(model->index(row, COLUMN_SIZE), Qt::DisplayRole).toULongLong(&ok);
} }
qlonglong TransfersDialog::getTransfered(int row, QStandardItemModel *model) qlonglong TransfersDialog::getTransfered(int row, QStandardItemModel *model)
{ {
bool ok = false; bool ok = false;
return model->data(model->index(row, COMPLETED), Qt::DisplayRole).toULongLong(&ok); return model->data(model->index(row, COLUMN_COMPLETED), Qt::DisplayRole).toULongLong(&ok);
} }
qlonglong TransfersDialog::getRemainingTime(int row, QStandardItemModel *model) qlonglong TransfersDialog::getRemainingTime(int row, QStandardItemModel *model)
{ {
bool ok = false; bool ok = false;
return model->data(model->index(row, REMAINING), Qt::DisplayRole).toULongLong(&ok); return model->data(model->index(row, COLUMN_REMAINING), Qt::DisplayRole).toULongLong(&ok);
} }
qlonglong TransfersDialog::getDownloadTime(int row, QStandardItemModel *model) qlonglong TransfersDialog::getDownloadTime(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, DOWNLOADTIME), Qt::DisplayRole).toULongLong(); return model->data(model->index(row, COLUMN_DOWNLOADTIME), Qt::DisplayRole).toULongLong();
}
qlonglong TransfersDialog::getLastDL(int row, QStandardItemModel *model)
{
return model->data(model->index(row, COLUMN_LASTDL), Qt::DisplayRole).toULongLong();
} }
QString TransfersDialog::getSources(int row, QStandardItemModel *model) QString TransfersDialog::getSources(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, SOURCES), Qt::DisplayRole).toString(); return model->data(model->index(row, COLUMN_SOURCES), Qt::DisplayRole).toString();
} }
void TransfersDialog::openCollection() void TransfersDialog::openCollection()

View File

@ -213,6 +213,7 @@ public slots:
qlonglong getTransfered(int row, QStandardItemModel *model); qlonglong getTransfered(int row, QStandardItemModel *model);
qlonglong getRemainingTime(int row, QStandardItemModel *model); qlonglong getRemainingTime(int row, QStandardItemModel *model);
qlonglong getDownloadTime(int row, QStandardItemModel *model); qlonglong getDownloadTime(int row, QStandardItemModel *model);
qlonglong getLastDL(int row, QStandardItemModel *model);
QString getSources(int row, QStandardItemModel *model); QString getSources(int row, QStandardItemModel *model);
}; };

View File

@ -65,7 +65,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
// draw the background color // draw the background color
if(index.column() != UPROGRESS) { if(index.column() != COLUMN_UPROGRESS) {
if(option.showDecorationSelected && (option.state & QStyle::State_Selected)) { if(option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) { if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
cg = QPalette::Inactive; cg = QPalette::Inactive;
@ -79,7 +79,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
} }
switch(index.column()) { switch(index.column()) {
case USIZE: case COLUMN_USIZE:
fileSize = index.data().toLongLong(); fileSize = index.data().toLongLong();
if(fileSize <= 0){ if(fileSize <= 0){
temp = ""; temp = "";
@ -98,7 +98,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignRight, temp); painter->drawText(option.rect, Qt::AlignRight, temp);
break; break;
case UTRANSFERRED: case COLUMN_UTRANSFERRED:
transferred = index.data().toLongLong(); transferred = index.data().toLongLong();
if(transferred <= 0){ if(transferred <= 0){
temp = ""; temp = "";
@ -117,7 +117,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignRight, temp); painter->drawText(option.rect, Qt::AlignRight, temp);
break; break;
case ULSPEED: case COLUMN_ULSPEED:
ulspeed = index.data().toDouble(); ulspeed = index.data().toDouble();
if (ulspeed <= 0) { if (ulspeed <= 0) {
temp = ""; temp = "";
@ -128,7 +128,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignRight, temp); painter->drawText(option.rect, Qt::AlignRight, temp);
break; break;
case UPROGRESS: case COLUMN_UPROGRESS:
{ {
FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ; FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ;
@ -136,7 +136,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
painter->save() ; painter->save() ;
xProgressBar progressBar(pinfo,option.rect,painter,0);// the 3rd param is the color schema (0 is the default value) 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(), 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") if (ext == "rsfc" || ext == "rsrl" || ext == "dist" || ext == "rsfb")
progressBar.setColorSchema( 9); progressBar.setColorSchema( 9);
else else
@ -150,7 +150,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect, Qt::AlignCenter, newopt.text); painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
break; break;
case UNAME: case COLUMN_UNAME:
// decoration // decoration
value = index.data(Qt::DecorationRole); value = index.data(Qt::DecorationRole);
pixmap = qvariant_cast<QIcon>(value).pixmap(option.decorationSize, option.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled, option.state & QStyle::State_Open ? QIcon::On : QIcon::Off); pixmap = qvariant_cast<QIcon>(value).pixmap(option.decorationSize, option.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled, option.state & QStyle::State_Open ? QIcon::On : QIcon::Off);
@ -161,7 +161,7 @@ void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, index.data().toString()); painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, index.data().toString());
break; break;
case USTATUS: case COLUMN_USTATUS:
painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignCenter, index.data().toString()); painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignCenter, index.data().toString());
break; break;
default: default:

View File

@ -25,16 +25,16 @@
#include <QAbstractItemDelegate> #include <QAbstractItemDelegate>
// Defines for upload list list columns // Defines for upload list list columns
#define UNAME 0 #define COLUMN_UNAME 0
#define USIZE 1 #define COLUMN_USIZE 1
#define UTRANSFERRED 2 #define COLUMN_UTRANSFERRED 2
#define ULSPEED 3 #define COLUMN_ULSPEED 3
#define UPROGRESS 4 #define COLUMN_UPROGRESS 4
#define USTATUS 5 #define COLUMN_USTATUS 5
#define USERNAME 6 #define COLUMN_USERNAME 6
#define UHASH 7 #define COLUMN_UHASH 7
#define UUSERID 8 #define COLUMN_UUSERID 8
#define COLUMN_UCOUNT 9
#define MAX_CHAR_TMP 128 #define MAX_CHAR_TMP 128