mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-08 00:55:13 -04:00
moved all files related to file transfer in gui/FileTransfer/
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6501 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9eeacf7f83
commit
2e32892a27
26 changed files with 35 additions and 35 deletions
237
retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp
Normal file
237
retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp
Normal file
|
@ -0,0 +1,237 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006,2007 crypton
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <retroshare/rstypes.h>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionProgressBarV2>
|
||||
#include <QProgressBar>
|
||||
#include <QApplication>
|
||||
|
||||
#include "DLListDelegate.h"
|
||||
|
||||
Q_DECLARE_METATYPE(FileProgressInfo)
|
||||
|
||||
DLListDelegate::DLListDelegate(QObject *parent) : QAbstractItemDelegate(parent)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
DLListDelegate::~DLListDelegate(void)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
{
|
||||
QString byteUnits[4] = {tr("B"), tr("KB"), tr("MB"), tr("GB")};
|
||||
QStyleOptionViewItem opt = option;
|
||||
QStyleOptionProgressBarV2 newopt;
|
||||
QRect pixmapRect;
|
||||
QPixmap pixmap;
|
||||
qlonglong fileSize;
|
||||
double dlspeed, multi;
|
||||
int seconds,minutes, hours, days;
|
||||
qlonglong remaining;
|
||||
QString temp , status;
|
||||
qlonglong completed;
|
||||
qlonglong downloadtime;
|
||||
|
||||
// prepare
|
||||
painter->save();
|
||||
painter->setClipRect(opt.rect);
|
||||
|
||||
//set text color
|
||||
QVariant value = index.data(Qt::TextColorRole);
|
||||
if(value.isValid() && qvariant_cast<QColor>(value).isValid()) {
|
||||
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
|
||||
}
|
||||
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
|
||||
if(option.state & QStyle::State_Selected){
|
||||
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
|
||||
} else {
|
||||
painter->setPen(opt.palette.color(cg, QPalette::Text));
|
||||
}
|
||||
|
||||
// draw the background color if not the progress column or if progress is not displayed
|
||||
if(index.column() != COLUMN_PROGRESS) {
|
||||
if(option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
|
||||
if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
|
||||
cg = QPalette::Inactive;
|
||||
}
|
||||
painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
|
||||
} else {
|
||||
value = index.data(Qt::BackgroundRole);
|
||||
if(value.isValid() && qvariant_cast<QColor>(value).isValid()) {
|
||||
painter->fillRect(option.rect, qvariant_cast<QColor>(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
switch(index.column()) {
|
||||
case COLUMN_SIZE:
|
||||
fileSize = index.data().toLongLong();
|
||||
if(fileSize <= 0){
|
||||
temp = "";
|
||||
} else {
|
||||
multi = 1.0;
|
||||
for(int i = 0; i < 5; ++i) {
|
||||
if (fileSize < 1024) {
|
||||
fileSize = index.data().toLongLong();
|
||||
temp.sprintf("%.2f ", fileSize / multi);
|
||||
temp += byteUnits[i];
|
||||
break;
|
||||
}
|
||||
fileSize /= 1024;
|
||||
multi *= 1024.0;
|
||||
}
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case COLUMN_REMAINING:
|
||||
remaining = index.data().toLongLong();
|
||||
if(remaining <= 0){
|
||||
temp = "";
|
||||
} else {
|
||||
multi = 1.0;
|
||||
for(int i = 0; i < 5; ++i) {
|
||||
if (remaining < 1024) {
|
||||
remaining = index.data().toLongLong();
|
||||
temp.sprintf("%.2f ", remaining / multi);
|
||||
temp += byteUnits[i];
|
||||
break;
|
||||
}
|
||||
remaining /= 1024;
|
||||
multi *= 1024.0;
|
||||
}
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case COLUMN_COMPLETED:
|
||||
completed = index.data().toLongLong();
|
||||
if(completed <= 0){
|
||||
temp = "";
|
||||
} else {
|
||||
multi = 1.0;
|
||||
for(int i = 0; i < 5; ++i) {
|
||||
if (completed < 1024) {
|
||||
completed = index.data().toLongLong();
|
||||
temp.sprintf("%.2f ", completed / multi);
|
||||
temp += byteUnits[i];
|
||||
break;
|
||||
}
|
||||
completed /= 1024;
|
||||
multi *= 1024.0;
|
||||
}
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case COLUMN_DLSPEED:
|
||||
dlspeed = index.data().toDouble();
|
||||
if (dlspeed <= 0) {
|
||||
temp = "";
|
||||
} else {
|
||||
temp.clear();
|
||||
temp.sprintf("%.2f", dlspeed/1024.);
|
||||
temp += " KB/s";
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case COLUMN_PROGRESS:
|
||||
{
|
||||
// create a xProgressBar
|
||||
FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ;
|
||||
|
||||
// std::cerr << "drawing progress info: nb_chunks = " << pinfo.nb_chunks ;
|
||||
// for(uint i=0;i<pinfo.cmap._map.size();++i)
|
||||
// std::cerr << pinfo.cmap._map[i] << " " ;
|
||||
// std::cerr << std::endl ;
|
||||
|
||||
painter->save() ;
|
||||
xProgressBar progressBar(pinfo,option.rect, painter); // the 3rd param is the color schema (0 is the default value)
|
||||
if(pinfo.type == FileProgressInfo::DOWNLOAD_LINE)
|
||||
{
|
||||
progressBar.setDisplayText(true); // should display % text?
|
||||
progressBar.setColorSchema(0) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar.setDisplayText(false); // should display % text?
|
||||
progressBar.setColorSchema(1) ;
|
||||
}
|
||||
progressBar.setVerticalSpan(1);
|
||||
progressBar.paint(); // paint the progress bar
|
||||
|
||||
painter->restore() ;
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
|
||||
break;
|
||||
case COLUMN_DOWNLOADTIME:
|
||||
downloadtime = index.data().toLongLong();
|
||||
minutes = downloadtime / 60;
|
||||
seconds = downloadtime % 60;
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60 ;
|
||||
days = hours / 24;
|
||||
hours = hours % 24 ;
|
||||
if(days > 0) {
|
||||
temp = QString::number(days)+"d "+QString::number(hours)+"h" ;
|
||||
} else if(hours > 0 || days > 0) {
|
||||
temp = QString::number(hours)+"h "+QString::number(minutes)+"m" ;
|
||||
} else if(minutes > 0 || hours > 0) {
|
||||
temp = QString::number(minutes)+"m"+QString::number(seconds)+"s" ;
|
||||
} else if(seconds > 0) {
|
||||
temp = QString::number(seconds)+"s" ;
|
||||
} else
|
||||
temp = "" ;
|
||||
painter->drawText(option.rect, Qt::AlignCenter, temp);
|
||||
break;
|
||||
case COLUMN_NAME:
|
||||
// decoration
|
||||
value = index.data(Qt::DecorationRole);
|
||||
temp = index.data().toString();
|
||||
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);
|
||||
pixmapRect = (pixmap.isNull() ? QRect(0, 0, 0, 0): QRect(QPoint(0, 0), option.decorationSize));
|
||||
if (pixmapRect.isValid()){
|
||||
QPoint p = QStyle::alignedRect(option.direction, Qt::AlignLeft, pixmap.size(), option.rect).topLeft();
|
||||
painter->drawPixmap(p, pixmap);
|
||||
temp = " " + temp;
|
||||
}
|
||||
painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, temp);
|
||||
break;
|
||||
default:
|
||||
painter->drawText(option.rect, Qt::AlignCenter, index.data().toString());
|
||||
}
|
||||
|
||||
// done
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize DLListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
{
|
||||
return QSize(50,17);
|
||||
QVariant value = index.data(Qt::FontRole);
|
||||
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
|
||||
QFontMetrics fontMetrics(fnt);
|
||||
const QString text = index.data(Qt::DisplayRole).toString();
|
||||
QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1));
|
||||
return textRect.size();
|
||||
}
|
||||
|
71
retroshare-gui/src/gui/FileTransfer/DLListDelegate.h
Normal file
71
retroshare-gui/src/gui/FileTransfer/DLListDelegate.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006,2007,2008 crypton
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef DLLISTDELEGATE_H
|
||||
#define DLLISTDELEGATE_H
|
||||
|
||||
#include <QAbstractItemDelegate>
|
||||
#include "xprogressbar.h"
|
||||
|
||||
|
||||
// Defines for download list list columns
|
||||
#define COLUMN_NAME 0
|
||||
#define COLUMN_SIZE 1
|
||||
#define COLUMN_COMPLETED 2
|
||||
#define COLUMN_DLSPEED 3
|
||||
#define COLUMN_PROGRESS 4
|
||||
#define COLUMN_SOURCES 5
|
||||
#define COLUMN_STATUS 6
|
||||
#define COLUMN_PRIORITY 7
|
||||
#define COLUMN_REMAINING 8
|
||||
#define COLUMN_DOWNLOADTIME 9
|
||||
#define COLUMN_ID 10
|
||||
#define COLUMN_LASTDL 11
|
||||
#define COLUMN_COUNT 12
|
||||
|
||||
|
||||
#define MAX_CHAR_TMP 128
|
||||
|
||||
class QModelIndex;
|
||||
class QPainter;
|
||||
class QStyleOptionProgressBarV2;
|
||||
class QProgressBar;
|
||||
class QApplication;
|
||||
|
||||
|
||||
class DLListDelegate: public QAbstractItemDelegate {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DLListDelegate(QObject *parent=0);
|
||||
~DLListDelegate();
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
|
||||
private:
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
};
|
||||
#endif
|
||||
|
115
retroshare-gui/src/gui/FileTransfer/DetailsDialog.cpp
Normal file
115
retroshare-gui/src/gui/FileTransfer/DetailsDialog.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006-2010, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QClipboard>
|
||||
|
||||
#include "DetailsDialog.h"
|
||||
#include "TransfersDialog.h"
|
||||
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "util/misc.h"
|
||||
#include "FileTransferInfoWidget.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
|
||||
/** Default constructor */
|
||||
DetailsDialog::DetailsDialog(QWidget *parent, Qt::WFlags flags)
|
||||
: QDialog(parent, flags)
|
||||
{
|
||||
/* Invoke Qt Designer generated QObject setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
|
||||
setAttribute ( Qt::WA_DeleteOnClose, true );
|
||||
|
||||
CommentsModel = new QStandardItemModel(0, 3);
|
||||
CommentsModel->setHeaderData(0, Qt::Horizontal, tr("Rating"));
|
||||
CommentsModel->setHeaderData(1, Qt::Horizontal, tr("Comments"));
|
||||
CommentsModel->setHeaderData(2, Qt::Horizontal, tr("File Name"));
|
||||
|
||||
//ui.commentsTreeView->setModel(CommentsModel);
|
||||
//ui.commentsTreeView->setSortingEnabled(true);
|
||||
//ui.commentsTreeView->setRootIsDecorated(false);
|
||||
|
||||
/* Set header resize modes and initial section sizes */
|
||||
//QHeaderView * _coheader = ui.commentsTreeView->header();
|
||||
//_coheader->setResizeMode ( 0, QHeaderView::Custom);
|
||||
//_coheader->resizeSection ( 0, 100 );
|
||||
//_coheader->resizeSection ( 1, 240 );
|
||||
//_coheader->resizeSection ( 2, 100 );
|
||||
|
||||
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);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose,false) ;
|
||||
|
||||
connect(ui.copylinkdetailsButton,SIGNAL(clicked()),this,SLOT(copyLink())) ;
|
||||
}
|
||||
|
||||
void DetailsDialog::copyLink()
|
||||
{
|
||||
QApplication::clipboard()->setText( ui.Linktext->toPlainText() );
|
||||
}
|
||||
void DetailsDialog::on_ok_dButton_clicked()
|
||||
{
|
||||
QDialog::hide();
|
||||
}
|
||||
|
||||
void DetailsDialog::on_cancel_dButton_clicked()
|
||||
{
|
||||
//reject();
|
||||
QDialog::hide();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DetailsDialog::show()
|
||||
{
|
||||
ui.tabWidget->setCurrentIndex(0);
|
||||
if (!this->isVisible()) {
|
||||
QDialog::show();
|
||||
} else {
|
||||
QDialog::activateWindow();
|
||||
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||
QDialog::raise();
|
||||
}
|
||||
}
|
||||
|
||||
void DetailsDialog::setFileHash(const std::string & hash)
|
||||
{
|
||||
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->setFileHash(hash) ;
|
||||
|
||||
FileInfo nfo ;
|
||||
if(!rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, nfo))
|
||||
return ;
|
||||
|
||||
RetroShareLink link ;
|
||||
link.createFile(QString::fromStdString(nfo.fname),nfo.size,QString::fromStdString(nfo.hash)) ;
|
||||
|
||||
ui.Linktext->setText(link.toString()) ;
|
||||
}
|
||||
|
63
retroshare-gui/src/gui/FileTransfer/DetailsDialog.h
Normal file
63
retroshare-gui/src/gui/FileTransfer/DetailsDialog.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006-2010, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef _DETAILSDIALOG_H
|
||||
#define _DETAILSDIALOG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ui_DetailsDialog.h"
|
||||
|
||||
class FileChunksInfo ;
|
||||
|
||||
class DetailsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Default constructor */
|
||||
DetailsDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||
/** Default destructor */
|
||||
~DetailsDialog() {}
|
||||
|
||||
void setFileHash(const std::string& hash) ;
|
||||
|
||||
public slots:
|
||||
/** Overloaded QWidget.show */
|
||||
void show();
|
||||
void copyLink() ;
|
||||
|
||||
private slots:
|
||||
void on_ok_dButton_clicked();
|
||||
void on_cancel_dButton_clicked();
|
||||
|
||||
private:
|
||||
|
||||
class QStandardItemModel *CommentsModel;
|
||||
|
||||
std::string _file_hash ;
|
||||
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::DetailsDialog ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
222
retroshare-gui/src/gui/FileTransfer/DetailsDialog.ui
Normal file
222
retroshare-gui/src/gui/FileTransfer/DetailsDialog.ui
Normal file
|
@ -0,0 +1,222 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DetailsDialog</class>
|
||||
<widget class="QDialog" name="DetailsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>787</width>
|
||||
<height>644</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Details</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabGeneral">
|
||||
<attribute name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/blockdevice.png</normaloff>:/images/blockdevice.png</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout">
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="_2">
|
||||
<property name="margin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="images.qrc">:/images/graph-downloaded.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Done</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QGridLayout" name="_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="images.qrc">:/images/graph-downloading.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Active</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<layout class="QGridLayout" name="_5">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="images.qrc">:/images/graph-notdownload.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Outstanding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>368</width>
|
||||
<height>13</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="images.qrc">:/images/graph-checking.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Needs checking</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="fileTransferInfoWidget">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>747</width>
|
||||
<height>505</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabLinks">
|
||||
<attribute name="title">
|
||||
<string>retroshare link(s)</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>retroshare link</string>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QTextEdit" name="Linktext"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="copylinkdetailsButton">
|
||||
<property name="text">
|
||||
<string>Copy link to clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="images.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>DetailsDialog</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>262</x>
|
||||
<y>456</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>262</x>
|
||||
<y>238</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
283
retroshare-gui/src/gui/FileTransfer/FileTransferInfoWidget.cpp
Normal file
283
retroshare-gui/src/gui/FileTransfer/FileTransferInfoWidget.cpp
Normal file
|
@ -0,0 +1,283 @@
|
|||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2010, csoler
|
||||
* Copyright (c) 2009, defnax
|
||||
* Copyright (c) 2009, lsn752
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include <QStylePainter>
|
||||
#include <QDebug>
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
#include "util/misc.h"
|
||||
#include "FileTransferInfoWidget.h"
|
||||
#include <gui/RetroShareLink.h>
|
||||
|
||||
// Variables to decide of display behaviour. Should be adapted to window size.
|
||||
//
|
||||
static const int chunk_square_size = 13 ;
|
||||
static const int text_height = 10 ; // should be set according to the font size
|
||||
static const int block_sep = 4 ; // separator between blocks
|
||||
static const int ch_num_size = 50 ; // size of field for chunk number
|
||||
static const int availability_map_size_X = 400 ;// length of availability bar
|
||||
static const int availability_map_size_Y = 20 ; // height of availability bar
|
||||
static const int tab_size = 200 ;// size between tabulated entries
|
||||
|
||||
FileTransferInfoWidget::FileTransferInfoWidget(QWidget * /*parent*/, Qt::WFlags /*f*/ )
|
||||
{
|
||||
QRect TaskGraphRect = geometry();
|
||||
maxWidth = TaskGraphRect.width();
|
||||
maxHeight = 0;
|
||||
pixmap = QPixmap(size());
|
||||
pixmap.fill(this, 0, 0);
|
||||
|
||||
downloadedPixmap.load(":images/graph-downloaded.png");
|
||||
downloadingPixmap.load(":images/graph-downloading.png");
|
||||
notDownloadPixmap.load(":images/graph-notdownload.png");
|
||||
checkingPixmap.load(":images/graph-checking.png");
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
void FileTransferInfoWidget::resizeEvent(QResizeEvent */*event*/)
|
||||
{
|
||||
QRect TaskGraphRect = geometry();
|
||||
maxWidth = TaskGraphRect.width();
|
||||
|
||||
updateDisplay();
|
||||
}
|
||||
void FileTransferInfoWidget::updateDisplay()
|
||||
{
|
||||
//std::cout << "In TaskGraphPainterWidget::updateDisplay()" << std::endl ;
|
||||
|
||||
bool ok=true ;
|
||||
FileInfo nfo ;
|
||||
if(!rsFiles->FileDetails(_file_hash, RS_FILE_HINTS_DOWNLOAD, nfo))
|
||||
ok = false ;
|
||||
FileChunksInfo info ;
|
||||
if(!rsFiles->FileDownloadChunksDetails(_file_hash, info))
|
||||
ok = false ;
|
||||
|
||||
//std::cout << "got details for file " << nfo.fname << std::endl ;
|
||||
|
||||
// pixmap = QPixmap(size());
|
||||
// pixmap.fill(this, 0, 0);
|
||||
pixmap = QPixmap(maxWidth, maxHeight);
|
||||
pixmap.fill(this, 0, 0);
|
||||
setFixedHeight(maxHeight);
|
||||
|
||||
QPainter painter(&pixmap);
|
||||
painter.initFrom(this);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
int blocks = info.chunks.size() ;
|
||||
int columns = maxWidth/chunk_square_size;
|
||||
y = blocks/columns*chunk_square_size;
|
||||
x = blocks%columns*chunk_square_size;
|
||||
maxHeight = y+150+info.active_chunks.size()*(block_sep+text_height); // warning: this should be computed from the different size parameter and the number of objects drawn, otherwise the last objects to be displayed will be truncated.
|
||||
|
||||
draw(nfo,info,&painter) ;
|
||||
}
|
||||
pixmap2 = pixmap;
|
||||
}
|
||||
|
||||
void FileTransferInfoWidget::paintEvent(QPaintEvent */*event*/)
|
||||
{
|
||||
//std::cout << "In paint event" << std::endl ;
|
||||
QStylePainter painter(this);
|
||||
|
||||
painter.drawPixmap(0, 0, pixmap2);
|
||||
pixmap = pixmap2;
|
||||
}
|
||||
|
||||
void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info,QPainter *painter)
|
||||
{
|
||||
x=0;
|
||||
y=5;
|
||||
int blocks = info.chunks.size() ;
|
||||
uint64_t fileSize = info.file_size ;
|
||||
uint32_t blockSize = info.chunk_size ;
|
||||
|
||||
if (fileSize%blockSize == 0) blocks--;
|
||||
QRectF source(0.0, 0.0, 12.0, 12.0);
|
||||
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
y += text_height ;
|
||||
painter->drawText(0,y,tr("Chunk map") + ":") ;
|
||||
y += block_sep ;
|
||||
|
||||
// draw the chunk map
|
||||
//
|
||||
for (int i=0;i<blocks;i++)
|
||||
{
|
||||
if (x > maxWidth - chunk_square_size)
|
||||
{
|
||||
x = 0;
|
||||
y += chunk_square_size;
|
||||
}
|
||||
QRectF target(x, y, 12.0, 12.0);
|
||||
|
||||
switch(info.chunks[i])
|
||||
{
|
||||
case FileChunksInfo::CHUNK_DONE: painter->drawPixmap(target, downloadedPixmap, source);
|
||||
break ;
|
||||
|
||||
case FileChunksInfo::CHUNK_ACTIVE: painter->drawPixmap(target, downloadingPixmap, source);
|
||||
break ;
|
||||
|
||||
case FileChunksInfo::CHUNK_CHECKING: painter->drawPixmap(target, checkingPixmap, source);
|
||||
break ;
|
||||
|
||||
case FileChunksInfo::CHUNK_OUTSTANDING: painter->drawPixmap(target, notDownloadPixmap, source);
|
||||
break ;
|
||||
default: ;
|
||||
}
|
||||
x += chunk_square_size;
|
||||
}
|
||||
y += chunk_square_size ;
|
||||
|
||||
// draw the currently downloaded chunks
|
||||
//
|
||||
painter->setPen(QColor::fromRgb(70,70,70)) ;
|
||||
painter->drawLine(0,y,maxWidth,y) ;
|
||||
|
||||
uint32_t sizeX = 100 ;
|
||||
uint32_t sizeY = 10 ;
|
||||
y += block_sep ;
|
||||
y += text_height ;
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawText(0,y,tr("Active chunks") + ":") ;
|
||||
y += block_sep ;
|
||||
|
||||
for(uint i=0;i<info.active_chunks.size();++i)
|
||||
{
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawText(5,y+text_height,QString::number(info.active_chunks[i].first)) ;
|
||||
|
||||
int size_of_this_chunk = ( info.active_chunks[i].first == info.chunks.size()-1 && ((info.file_size % blockSize)>0) )?(info.file_size % blockSize):blockSize ;
|
||||
uint32_t s = (uint32_t)rint(sizeX*(size_of_this_chunk - info.active_chunks[i].second)/(float)size_of_this_chunk) ;
|
||||
|
||||
//std::cerr << "chunk " << info.active_chunks[i].first << ": Last received byte: " << size_of_this_chunk - info.active_chunks[i].second << std::endl;
|
||||
|
||||
// Already Downloaded.
|
||||
//
|
||||
painter->fillRect(ch_num_size,y,s,sizeY,QColor::fromHsv(200,200,255)) ;
|
||||
|
||||
// Remains to download
|
||||
//
|
||||
painter->fillRect(ch_num_size+s,y,sizeX-s,sizeY,QColor::fromHsv(200,50,255)) ;
|
||||
|
||||
// now draw the slices under pending requests
|
||||
//
|
||||
std::map<uint32_t,std::vector<FileChunksInfo::SliceInfo> >::const_iterator it(info.pending_slices.find(info.active_chunks[i].first)) ;
|
||||
|
||||
if(it != info.pending_slices.end())
|
||||
for(uint k=0;k<it->second.size();++k)
|
||||
{
|
||||
uint32_t s1 = (uint32_t)floor(sizeX*(it->second[k].start)/(float)size_of_this_chunk) ;
|
||||
uint32_t ss = (uint32_t)ceil(sizeX*(it->second[k].size )/(float)size_of_this_chunk) ;
|
||||
|
||||
painter->fillRect(ch_num_size+s1,y,ss,sizeY,QColor::fromHsv(50,250,250)) ;
|
||||
|
||||
}
|
||||
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
float percent = (size_of_this_chunk - info.active_chunks[i].second)*100.0/size_of_this_chunk ;
|
||||
|
||||
painter->drawText(sizeX+55,y+text_height,QString::number(percent,'f',2) + " %") ;
|
||||
|
||||
y += sizeY+block_sep ;
|
||||
}
|
||||
|
||||
// draw the availability map
|
||||
//
|
||||
painter->setPen(QColor::fromRgb(70,70,70)) ;
|
||||
painter->drawLine(0,y,maxWidth,y) ;
|
||||
|
||||
y += block_sep ;
|
||||
y += text_height ;
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawText(0,y,(info.compressed_peer_availability_maps.size() == 1 ? tr("Availability map (%1 active source)") : tr("Availability map (%1 active sources)")).arg(info.compressed_peer_availability_maps.size())) ;
|
||||
y += block_sep ;
|
||||
|
||||
// Note (for non geeks): the !! operator transforms anything positive into 1 and 0 into 0.
|
||||
//
|
||||
int nb_chunks = info.file_size/info.chunk_size + !!(info.file_size % info.chunk_size);
|
||||
|
||||
for(int i=0;i<availability_map_size_X;++i)
|
||||
{
|
||||
int nb_src = 0 ;
|
||||
int chunk_num = (int)floor(i/float(availability_map_size_X)*(nb_chunks-1)) ;
|
||||
|
||||
for(std::map<std::string,CompressedChunkMap>::const_iterator it(info.compressed_peer_availability_maps.begin());it!=info.compressed_peer_availability_maps.end();++it)
|
||||
nb_src += it->second[chunk_num] ;
|
||||
|
||||
painter->setPen(QColor::fromHsv(200,std::min(255,50*nb_src),200)) ; // the more sources, the more saturated
|
||||
painter->drawLine(i,y,i,y+availability_map_size_Y) ;
|
||||
}
|
||||
|
||||
y += block_sep + availability_map_size_Y ;
|
||||
painter->setPen(QColor::fromRgb(70,70,70)) ;
|
||||
painter->drawLine(0,y,maxWidth,y) ;
|
||||
y += block_sep ;
|
||||
|
||||
// various info:
|
||||
//
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
y += text_height ; painter->drawText(0,y,tr("File info") + ":") ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("File name") + ":") ; painter->drawText(tab_size,y,QString::fromStdString(nfo.fname)) ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Destination folder") + ":") ; painter->drawText(tab_size,y,QString::fromStdString(nfo.path)) ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("File hash") + ":") ; painter->drawText(tab_size,y,QString::fromStdString(nfo.hash)) ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("File size") + ":") ; painter->drawText(tab_size,y,QString::number(info.file_size) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.file_size) + ")") ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Chunk size") + ":") ; painter->drawText(tab_size,y,QString::number(info.chunk_size) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.chunk_size) + ")") ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Number of chunks") + ":") ; painter->drawText(tab_size,y,QString::number(info.chunks.size())) ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Transferred") + ":") ; painter->drawText(tab_size,y,QString::number(nfo.transfered) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(nfo.transfered) + ")") ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Remaining") + ":") ; painter->drawText(tab_size,y,QString::number(info.file_size - nfo.transfered) + " " + tr("bytes") + " " + "(" + misc::friendlyUnit(info.file_size - nfo.transfered) + ")") ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Number of sources") + ":") ; painter->drawText(tab_size,y,QString::number(info.compressed_peer_availability_maps.size())) ;
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Chunk strategy") + ":") ;
|
||||
switch(info.strategy)
|
||||
{
|
||||
case FileChunksInfo::CHUNK_STRATEGY_RANDOM: painter->drawText(tab_size,y,"Random") ; break ;
|
||||
case FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE: painter->drawText(tab_size,y,"Progressive") ; break ;
|
||||
default:
|
||||
case FileChunksInfo::CHUNK_STRATEGY_STREAMING: painter->drawText(tab_size,y,"Streaming") ; break ;
|
||||
}
|
||||
y += block_sep ;
|
||||
y += text_height ; painter->drawText(20,y,tr("Transfer type") + ":") ;
|
||||
if(nfo.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) painter->drawText(tab_size,y,tr("Anonymous F2F")) ;
|
||||
if(nfo.transfer_info_flags & RS_FILE_REQ_ASSUME_AVAILABILITY) painter->drawText(tab_size,y,tr("Direct friend transfer / Availability assumed")) ;
|
||||
y += text_height ;
|
||||
y += block_sep ;
|
||||
|
||||
maxHeight = y+15;
|
||||
}
|
||||
|
||||
|
62
retroshare-gui/src/gui/FileTransfer/FileTransferInfoWidget.h
Normal file
62
retroshare-gui/src/gui/FileTransfer/FileTransferInfoWidget.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
#pragma once
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2009, defnax
|
||||
* Copyright (c) 2009, lsn752
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QBitmap>
|
||||
#include "RsAutoUpdatePage.h"
|
||||
|
||||
class FileChunksInfo ;
|
||||
class FileInfo ;
|
||||
|
||||
class FileTransferInfoWidget : public RsAutoUpdatePage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FileTransferInfoWidget(QWidget * parent = 0, Qt::WFlags f = 0 );
|
||||
|
||||
void setFileHash(const std::string& hash) { _file_hash = hash ; }
|
||||
|
||||
virtual void updateDisplay() ; // update from RsAutoUpdateWidget
|
||||
protected:
|
||||
void draw(const FileInfo& nfo,const FileChunksInfo& details,QPainter *painter) ;
|
||||
|
||||
virtual void paintEvent(QPaintEvent *);
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
int x;
|
||||
int y;
|
||||
int maxWidth;
|
||||
int maxHeight;
|
||||
QPixmap pixmap;
|
||||
QPixmap pixmap2;
|
||||
QPixmap downloadedPixmap;
|
||||
QPixmap downloadingPixmap;
|
||||
QPixmap notDownloadPixmap;
|
||||
QPixmap checkingPixmap;
|
||||
|
||||
std::string _file_hash ;
|
||||
};
|
||||
|
118
retroshare-gui/src/gui/FileTransfer/TransferUserNotify.cpp
Normal file
118
retroshare-gui/src/gui/FileTransfer/TransferUserNotify.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2012 RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include "TransferUserNotify.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/MainWindow.h"
|
||||
|
||||
TransferUserNotify::TransferUserNotify(QObject *parent) :
|
||||
UserNotify(parent)
|
||||
{
|
||||
newTransferCount = 0;
|
||||
|
||||
connect(NotifyQt::getInstance(), SIGNAL(downloadCompleteCountChanged(int)), this, SLOT(downloadCountChanged(int)));
|
||||
}
|
||||
|
||||
bool TransferUserNotify::hasSetting(QString &name)
|
||||
{
|
||||
name = tr("Download completed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TransferUserNotify::notifyEnabled()
|
||||
{
|
||||
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_TRANSFERS);
|
||||
}
|
||||
|
||||
bool TransferUserNotify::notifyCombined()
|
||||
{
|
||||
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_TRANSFERS_COMBINED);
|
||||
}
|
||||
|
||||
bool TransferUserNotify::notifyBlink()
|
||||
{
|
||||
return (Settings->getTrayNotifyBlinkFlags() & TRAYNOTIFY_BLINK_TRANSFERS);
|
||||
}
|
||||
|
||||
void TransferUserNotify::setNotifyEnabled(bool enabled, bool combined, bool blink)
|
||||
{
|
||||
uint notifyFlags = Settings->getTrayNotifyFlags();
|
||||
uint blinkFlags = Settings->getTrayNotifyBlinkFlags();
|
||||
|
||||
if (enabled) {
|
||||
notifyFlags |= TRAYNOTIFY_TRANSFERS;
|
||||
} else {
|
||||
notifyFlags &= ~TRAYNOTIFY_TRANSFERS;
|
||||
}
|
||||
|
||||
if (combined) {
|
||||
notifyFlags |= TRAYNOTIFY_TRANSFERS_COMBINED;
|
||||
} else {
|
||||
notifyFlags &= ~TRAYNOTIFY_TRANSFERS_COMBINED;
|
||||
}
|
||||
|
||||
if (blink) {
|
||||
blinkFlags |= TRAYNOTIFY_BLINK_TRANSFERS;
|
||||
} else {
|
||||
blinkFlags &= ~TRAYNOTIFY_BLINK_TRANSFERS;
|
||||
}
|
||||
|
||||
Settings->setTrayNotifyFlags(notifyFlags);
|
||||
Settings->setTrayNotifyBlinkFlags(blinkFlags);
|
||||
}
|
||||
|
||||
QIcon TransferUserNotify::getIcon()
|
||||
{
|
||||
return QIcon(":/images/ktorrent32.png");
|
||||
}
|
||||
|
||||
QIcon TransferUserNotify::getMainIcon(bool hasNew)
|
||||
{
|
||||
return hasNew ? QIcon(":/images/transfers_new.png") : QIcon(":/images/ktorrent32.png");
|
||||
}
|
||||
|
||||
unsigned int TransferUserNotify::getNewCount()
|
||||
{
|
||||
return newTransferCount;
|
||||
}
|
||||
|
||||
QString TransferUserNotify::getTrayMessage(bool plural)
|
||||
{
|
||||
return plural ? tr("You have %1 completed downloads") : tr("You have %1 completed download");
|
||||
}
|
||||
|
||||
QString TransferUserNotify::getNotifyMessage(bool plural)
|
||||
{
|
||||
return plural ? tr("%1 completed downloads") : tr("%1 completed download");
|
||||
}
|
||||
|
||||
void TransferUserNotify::iconClicked()
|
||||
{
|
||||
MainWindow::showWindow(MainWindow::Transfers);
|
||||
}
|
||||
|
||||
void TransferUserNotify::downloadCountChanged(int count)
|
||||
{
|
||||
newTransferCount = count;
|
||||
updateIcon();
|
||||
}
|
54
retroshare-gui/src/gui/FileTransfer/TransferUserNotify.h
Normal file
54
retroshare-gui/src/gui/FileTransfer/TransferUserNotify.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2012 RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef TRANSFERUSERNOTIFY_H
|
||||
#define TRANSFERUSERNOTIFY_H
|
||||
|
||||
#include "gui/common/UserNotify.h"
|
||||
|
||||
class TransferUserNotify : public UserNotify
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TransferUserNotify(QObject *parent = 0);
|
||||
|
||||
virtual bool hasSetting(QString &name);
|
||||
virtual bool notifyEnabled();
|
||||
virtual bool notifyCombined();
|
||||
virtual bool notifyBlink();
|
||||
virtual void setNotifyEnabled(bool enabled, bool combined, bool blink);
|
||||
|
||||
private slots:
|
||||
void downloadCountChanged(int count);
|
||||
|
||||
private:
|
||||
virtual QIcon getIcon();
|
||||
virtual QIcon getMainIcon(bool hasNew);
|
||||
virtual unsigned int getNewCount();
|
||||
virtual QString getTrayMessage(bool plural);
|
||||
virtual QString getNotifyMessage(bool plural);
|
||||
virtual void iconClicked();
|
||||
|
||||
unsigned int newTransferCount;
|
||||
};
|
||||
|
||||
#endif // TRANSFERUSERNOTIFY_H
|
1954
retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp
Normal file
1954
retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp
Normal file
File diff suppressed because it is too large
Load diff
253
retroshare-gui/src/gui/FileTransfer/TransfersDialog.h
Normal file
253
retroshare-gui/src/gui/FileTransfer/TransfersDialog.h
Normal file
|
@ -0,0 +1,253 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006,2007 crypton
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef _TRANSFERSDIALOG_H
|
||||
#define _TRANSFERSDIALOG_H
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <retroshare/rstypes.h>
|
||||
#include "RsAutoUpdatePage.h"
|
||||
|
||||
#include "ui_TransfersDialog.h"
|
||||
|
||||
|
||||
class DLListDelegate;
|
||||
class ULListDelegate;
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
class DetailsDialog;
|
||||
class FileProgressInfo;
|
||||
class SearchDialog;
|
||||
class LocalSharedFilesDialog;
|
||||
class RemoteSharedFilesDialog;
|
||||
|
||||
class TransfersDialog : public RsAutoUpdatePage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Page {
|
||||
/* Fixed numbers for load and save the last page */
|
||||
SearchTab = 0, /** Network page. */
|
||||
LocalSharedFilesTab = 1, /** Network new graph. */
|
||||
RemoteSharedFilesTab = 2 /** Old group chat page. */
|
||||
};
|
||||
|
||||
|
||||
/** Default Constructor */
|
||||
TransfersDialog(QWidget *parent = 0);
|
||||
~TransfersDialog();
|
||||
|
||||
virtual UserNotify *getUserNotify(QObject *parent);
|
||||
|
||||
void activatePage(TransfersDialog::Page page) ;
|
||||
|
||||
virtual void updateDisplay() ; // derived from RsAutoUpdateWidget
|
||||
|
||||
static DetailsDialog *detailsDialog() ;
|
||||
|
||||
SearchDialog *searchDialog ;
|
||||
LocalSharedFilesDialog *localSharedFiles ;
|
||||
RemoteSharedFilesDialog *remoteSharedFiles ;
|
||||
|
||||
public slots:
|
||||
void insertTransfers();
|
||||
|
||||
// void handleDownloadRequest(const QString& url);
|
||||
|
||||
private slots:
|
||||
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void downloadListCustomPopupMenu( QPoint point );
|
||||
void downloadListHeaderCustomPopupMenu( QPoint point );
|
||||
|
||||
void cancel();
|
||||
void forceCheck();
|
||||
/** removes finished Downloads**/
|
||||
void clearcompleted();
|
||||
|
||||
void copyLink();
|
||||
void pasteLink();
|
||||
void renameFile();
|
||||
void setDestinationDirectory();
|
||||
void chooseDestinationDirectory();
|
||||
|
||||
void expandAll();
|
||||
void collapseAll();
|
||||
|
||||
// void rootdecorated();
|
||||
// void rootisnotdecorated();
|
||||
|
||||
void pauseFileTransfer();
|
||||
void resumeFileTransfer();
|
||||
void openFolderTransfer();
|
||||
void openTransfer();
|
||||
void previewTransfer();
|
||||
|
||||
/** clear download or all queue - for pending dwls */
|
||||
// void clearQueue();
|
||||
|
||||
/** modify download priority actions */
|
||||
void priorityQueueUp();
|
||||
void priorityQueueDown();
|
||||
void priorityQueueTop();
|
||||
void priorityQueueBottom();
|
||||
|
||||
void speedSlow();
|
||||
void speedAverage();
|
||||
void speedFast();
|
||||
|
||||
void changeSpeed(int) ;
|
||||
void changeQueuePosition(QueueMove) ;
|
||||
|
||||
void chunkRandom();
|
||||
void chunkProgressive();
|
||||
void chunkStreaming();
|
||||
|
||||
void showDetailsDialog();
|
||||
void updateDetailsDialog();
|
||||
|
||||
void openCollection();
|
||||
|
||||
void setShowDLSizeColumn(bool show);
|
||||
void setShowDLCompleteColumn(bool show);
|
||||
void setShowDLDLSpeedColumn(bool show);
|
||||
void setShowDLProgressColumn(bool show);
|
||||
void setShowDLSourcesColumn(bool show);
|
||||
void setShowDLStatusColumn(bool show);
|
||||
void setShowDLPriorityColumn(bool show);
|
||||
void setShowDLRemainingColumn(bool show);
|
||||
void setShowDLDownloadTimeColumn(bool show);
|
||||
void setShowDLIDColumn(bool show);
|
||||
void setShowDLLastDLColumn(bool show);
|
||||
|
||||
signals:
|
||||
void playFiles(QStringList files);
|
||||
|
||||
private:
|
||||
QString getPeerName(const std::string& peer_id) const ;
|
||||
|
||||
QStandardItemModel *DLListModel;
|
||||
QStandardItemModel *ULListModel;
|
||||
QItemSelectionModel *selection;
|
||||
QItemSelectionModel *selectionup;
|
||||
|
||||
DLListDelegate *DLDelegate;
|
||||
ULListDelegate *ULDelegate;
|
||||
|
||||
/** Create the actions on the tray menu or menubar */
|
||||
void createActions();
|
||||
|
||||
/** Defines the actions for the context menu */
|
||||
QAction* showdowninfoAct;
|
||||
QAction* playAct;
|
||||
QAction* cancelAct;
|
||||
QAction* forceCheckAct;
|
||||
QAction* clearcompletedAct;
|
||||
QAction* copylinkAct;
|
||||
QAction* pastelinkAct;
|
||||
QAction* rootisnotdecoratedAct;
|
||||
QAction* rootisdecoratedAct;
|
||||
QAction *pauseAct;
|
||||
QAction *resumeAct;
|
||||
QAction *openfolderAct;
|
||||
QAction *openfileAct;
|
||||
QAction *previewfileAct;
|
||||
// QAction *clearQueuedDwlAct;
|
||||
// QAction *clearQueueAct;
|
||||
QAction *changePriorityAct;
|
||||
QAction *prioritySlowAct;
|
||||
QAction *priorityMediumAct;
|
||||
QAction *priorityFastAct;
|
||||
QAction *queueDownAct;
|
||||
QAction *queueUpAct;
|
||||
QAction *queueTopAct;
|
||||
QAction *queueBottomAct;
|
||||
QAction *chunkRandomAct;
|
||||
QAction *chunkProgressiveAct;
|
||||
QAction *chunkStreamingAct;
|
||||
QAction *detailsfileAct;
|
||||
QAction *toggleShowCacheTransfersAct;
|
||||
QAction *openCollectionAct;
|
||||
QAction *renameFileAct;
|
||||
QAction *specifyDestinationDirectoryAct;
|
||||
QAction *expandAllAct;
|
||||
QAction *collapseAllAct;
|
||||
|
||||
/** Defines the actions for the header context menu */
|
||||
QAction* showDLSizeAct;
|
||||
QAction* showDLCompleteAct;
|
||||
QAction* showDLDLSpeedAct;
|
||||
QAction* showDLProgressAct;
|
||||
QAction* showDLSourcesAct;
|
||||
QAction* showDLStatusAct;
|
||||
QAction* showDLPriorityAct;
|
||||
QAction* showDLRemainingAct;
|
||||
QAction* showDLDownloadTimeAct;
|
||||
QAction* showDLIDAct;
|
||||
QAction* showDLLastDLAct;
|
||||
|
||||
|
||||
bool m_bProcessSettings;
|
||||
void processSettings(bool bLoad);
|
||||
|
||||
void getSelectedItems(std::set<std::string> *ids, std::set<int> *rows);
|
||||
bool controlTransferFile(uint32_t flags);
|
||||
void changePriority(int priority);
|
||||
void setChunkStrategy(FileChunksInfo::ChunkStrategy s) ;
|
||||
|
||||
QTreeView *downloadList;
|
||||
|
||||
/** Adds a new action to the toolbar. */
|
||||
void addAction(QAction *action, const char *slot = 0);
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::TransfersDialog ui;
|
||||
|
||||
bool _show_cache_transfers ;
|
||||
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, const std::map<std::string, std::string> &versions);
|
||||
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);
|
||||
|
||||
void showFileDetails() ;
|
||||
void toggleShowCacheTransfers() ;
|
||||
|
||||
double getProgress(int row, QStandardItemModel *model);
|
||||
double getSpeed(int row, QStandardItemModel *model);
|
||||
QString getFileName(int row, QStandardItemModel *model);
|
||||
QString getStatus(int row, QStandardItemModel *model);
|
||||
QString getID(int row, QStandardItemModel *model);
|
||||
QString getPriority(int row, QStandardItemModel *model);
|
||||
qlonglong getFileSize(int row, QStandardItemModel *model);
|
||||
qlonglong getTransfered(int row, QStandardItemModel *model);
|
||||
qlonglong getRemainingTime(int row, QStandardItemModel *model);
|
||||
qlonglong getDownloadTime(int row, QStandardItemModel *model);
|
||||
qlonglong getLastDL(int row, QStandardItemModel *model);
|
||||
QString getSources(int row, QStandardItemModel *model);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
127
retroshare-gui/src/gui/FileTransfer/TransfersDialog.ui
Normal file
127
retroshare-gui/src/gui/FileTransfer/TransfersDialog.ui
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TransfersDialog</class>
|
||||
<widget class="QWidget" name="TransfersDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>620</width>
|
||||
<height>353</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/down.png</normaloff>:/images/down.png</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>Downloads</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTreeView" name="downloadList">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
|
||||
</property>
|
||||
<property name="tabKeyNavigation">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::NoDragDrop</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="allColumnsShowFocus">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="uploadsTab">
|
||||
<attribute name="icon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/up.png</normaloff>:/images/up.png</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>Uploads</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QTreeView" name="uploadsList">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
216
retroshare-gui/src/gui/FileTransfer/TurtleRouterDialog.cpp
Normal file
216
retroshare-gui/src/gui/FileTransfer/TurtleRouterDialog.cpp
Normal file
|
@ -0,0 +1,216 @@
|
|||
#include <QObject>
|
||||
#include <retroshare/rsturtle.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include "TurtleRouterDialog.h"
|
||||
#include <QPainter>
|
||||
#include <QStylePainter>
|
||||
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
|
||||
static const uint MAX_TUNNEL_REQUESTS_DISPLAY = 10 ;
|
||||
|
||||
|
||||
TurtleRouterDialog::TurtleRouterDialog(QWidget *parent)
|
||||
: RsAutoUpdatePage(2000,parent)
|
||||
{
|
||||
setupUi(this) ;
|
||||
|
||||
m_bProcessSettings = false;
|
||||
|
||||
// Init the basic setup.
|
||||
//
|
||||
QStringList stl ;
|
||||
int n=0 ;
|
||||
|
||||
stl.clear() ;
|
||||
stl.push_back(tr("Search requests")) ;
|
||||
top_level_s_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
|
||||
_f2f_TW->insertTopLevelItem(n++,top_level_s_requests) ;
|
||||
|
||||
stl.clear() ;
|
||||
stl.push_back(tr("Tunnel requests")) ;
|
||||
top_level_t_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
|
||||
_f2f_TW->insertTopLevelItem(n++,top_level_t_requests) ;
|
||||
|
||||
top_level_hashes.clear() ;
|
||||
|
||||
// load settings
|
||||
processSettings(true);
|
||||
}
|
||||
|
||||
TurtleRouterDialog::~TurtleRouterDialog()
|
||||
{
|
||||
// save settings
|
||||
processSettings(false);
|
||||
}
|
||||
|
||||
void TurtleRouterDialog::processSettings(bool bLoad)
|
||||
{
|
||||
m_bProcessSettings = true;
|
||||
|
||||
Settings->beginGroup(QString("TurtleRouterDialog"));
|
||||
|
||||
if (bLoad) {
|
||||
// load settings
|
||||
|
||||
// state of splitter
|
||||
//splitter->restoreState(Settings->value("Splitter").toByteArray());
|
||||
} else {
|
||||
// save settings
|
||||
|
||||
// state of splitter
|
||||
//Settings->setValue("Splitter", splitter->saveState());
|
||||
|
||||
}
|
||||
|
||||
Settings->endGroup();
|
||||
|
||||
m_bProcessSettings = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TurtleRouterDialog::updateDisplay()
|
||||
{
|
||||
std::vector<std::vector<std::string> > hashes_info ;
|
||||
std::vector<std::vector<std::string> > tunnels_info ;
|
||||
std::vector<TurtleRequestDisplayInfo > search_reqs_info ;
|
||||
std::vector<TurtleRequestDisplayInfo > tunnel_reqs_info ;
|
||||
|
||||
rsTurtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
||||
|
||||
updateTunnelRequests(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
||||
|
||||
}
|
||||
|
||||
QString TurtleRouterDialog::getPeerName(const std::string& peer_id)
|
||||
{
|
||||
static std::map<std::string, QString> names ;
|
||||
|
||||
std::map<std::string,QString>::const_iterator it = names.find(peer_id) ;
|
||||
|
||||
if( it != names.end())
|
||||
return it->second ;
|
||||
else
|
||||
{
|
||||
RsPeerDetails detail ;
|
||||
if(!rsPeers->getPeerDetails(peer_id,detail))
|
||||
return "unknown peer";
|
||||
|
||||
return (names[peer_id] = QString::fromUtf8(detail.name.c_str())) ;
|
||||
}
|
||||
}
|
||||
|
||||
void TurtleRouterDialog::updateTunnelRequests( const std::vector<std::vector<std::string> >& hashes_info,
|
||||
const std::vector<std::vector<std::string> >& tunnels_info,
|
||||
const std::vector<TurtleRequestDisplayInfo >& search_reqs_info,
|
||||
const std::vector<TurtleRequestDisplayInfo >& tunnel_reqs_info)
|
||||
{
|
||||
// now display this in the QTableWidgets
|
||||
|
||||
QStringList stl ;
|
||||
|
||||
// remove all children of top level objects
|
||||
for(int i=0;i<_f2f_TW->topLevelItemCount();++i)
|
||||
{
|
||||
QTreeWidgetItem *taken ;
|
||||
while( (taken = _f2f_TW->topLevelItem(i)->takeChild(0)) != NULL)
|
||||
delete taken ;
|
||||
}
|
||||
|
||||
for(uint i=0;i<hashes_info.size();++i)
|
||||
findParentHashItem(hashes_info[i][0]) ;
|
||||
|
||||
bool unknown_hash_found = false ;
|
||||
|
||||
// check that an entry exist for all hashes
|
||||
for(uint i=0;i<tunnels_info.size();++i)
|
||||
{
|
||||
const std::string& hash(tunnels_info[i][3]) ;
|
||||
|
||||
QTreeWidgetItem *parent = findParentHashItem(hash) ;
|
||||
|
||||
if(parent->text(0).left(14) == tr("Unknown hashes"))
|
||||
unknown_hash_found = true ;
|
||||
|
||||
QString str = tr("Tunnel id") + ": " + QString::fromUtf8(tunnels_info[i][0].c_str()) + "\t [" + QString::fromUtf8(tunnels_info[i][2].c_str()) + "] --> [" + QString::fromUtf8(tunnels_info[i][1].c_str()) + "]\t\t " + tr("last transfer") + ": " + QString::fromStdString(tunnels_info[i][4]) + "\t " + tr("Speed") + ": " + QString::fromStdString(tunnels_info[i][5]) ;
|
||||
stl.clear() ;
|
||||
stl.push_back(str) ;
|
||||
|
||||
parent->addChild(new QTreeWidgetItem(stl)) ;
|
||||
}
|
||||
|
||||
for(uint i=0;i<search_reqs_info.size();++i)
|
||||
{
|
||||
QString str = tr("Request id: %1\t from [%2]\t %3 secs ago").arg(search_reqs_info[i].request_id,0,16).arg(getPeerName(search_reqs_info[i].source_peer_id)).arg(search_reqs_info[i].age);
|
||||
|
||||
stl.clear() ;
|
||||
stl.push_back(str) ;
|
||||
|
||||
top_level_s_requests->addChild(new QTreeWidgetItem(stl)) ;
|
||||
}
|
||||
top_level_s_requests->setText(0, tr("Search requests") + "(" + QString::number(search_reqs_info.size()) + ")" ) ;
|
||||
|
||||
for(uint i=0;i<tunnel_reqs_info.size();++i)
|
||||
if(i+MAX_TUNNEL_REQUESTS_DISPLAY >= tunnel_reqs_info.size() || i < MAX_TUNNEL_REQUESTS_DISPLAY)
|
||||
{
|
||||
QString str = tr("Request id: %1\t from [%2]\t %3 secs ago").arg(tunnel_reqs_info[i].request_id,0,16).arg(getPeerName(tunnel_reqs_info[i].source_peer_id)).arg(tunnel_reqs_info[i].age);
|
||||
|
||||
stl.clear() ;
|
||||
stl.push_back(str) ;
|
||||
|
||||
top_level_t_requests->addChild(new QTreeWidgetItem(stl)) ;
|
||||
}
|
||||
else if(i == MAX_TUNNEL_REQUESTS_DISPLAY)
|
||||
{
|
||||
stl.clear() ;
|
||||
stl.push_back(QString("...")) ;
|
||||
top_level_t_requests->addChild(new QTreeWidgetItem(stl)) ;
|
||||
|
||||
}
|
||||
|
||||
top_level_t_requests->setText(0, tr("Tunnel requests") + "("+QString::number(tunnel_reqs_info.size()) + ")") ;
|
||||
|
||||
QTreeWidgetItem *unknown_hashs_item = findParentHashItem("") ;
|
||||
unknown_hashs_item->setText(0,tr("Unknown hashes") + " (" + QString::number(unknown_hashs_item->childCount())+QString(")")) ;
|
||||
|
||||
// Ok, this is a N2 search, but there are very few elements in the list.
|
||||
for(int i=2;i<_f2f_TW->topLevelItemCount();)
|
||||
{
|
||||
bool found = false ;
|
||||
|
||||
if(_f2f_TW->topLevelItem(i)->text(0).left(14) == tr("Unknown hashes") && unknown_hash_found)
|
||||
found = true ;
|
||||
|
||||
if(_f2f_TW->topLevelItem(i)->childCount() > 0) // this saves uploading hashes
|
||||
found = true ;
|
||||
|
||||
for(uint j=0;j<hashes_info.size() && !found;++j)
|
||||
if(_f2f_TW->topLevelItem(i)->text(0).toStdString() == hashes_info[j][0])
|
||||
found=true ;
|
||||
|
||||
if(!found)
|
||||
delete _f2f_TW->takeTopLevelItem(i) ;
|
||||
else
|
||||
++i ;
|
||||
}
|
||||
}
|
||||
|
||||
QTreeWidgetItem *TurtleRouterDialog::findParentHashItem(const std::string& hash)
|
||||
{
|
||||
// look for the hash, and insert a new element if necessary.
|
||||
//
|
||||
QList<QTreeWidgetItem*> items = _f2f_TW->findItems((hash=="")?tr("Unknown hashes"):QString::fromStdString(hash),Qt::MatchStartsWith) ;
|
||||
|
||||
if(items.empty())
|
||||
{
|
||||
QStringList stl ;
|
||||
stl.push_back((hash=="")?tr("Unknown hashes"):QString::fromStdString(hash)) ;
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(_f2f_TW,stl) ;
|
||||
_f2f_TW->insertTopLevelItem(0,item) ;
|
||||
|
||||
return item ;
|
||||
}
|
||||
else
|
||||
return items.front() ;
|
||||
}
|
36
retroshare-gui/src/gui/FileTransfer/TurtleRouterDialog.h
Normal file
36
retroshare-gui/src/gui/FileTransfer/TurtleRouterDialog.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <retroshare/rsturtle.h>
|
||||
#include "ui_TurtleRouterDialog.h"
|
||||
#include "RsAutoUpdatePage.h"
|
||||
|
||||
|
||||
class TurtleRouterDialog: public RsAutoUpdatePage, public Ui::TurtleRouterDialogForm
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TurtleRouterDialog(QWidget *parent = NULL) ;
|
||||
~TurtleRouterDialog();
|
||||
|
||||
// Cache for peer names.
|
||||
static QString getPeerName(const std::string& peer_id) ;
|
||||
|
||||
private:
|
||||
void updateTunnelRequests( const std::vector<std::vector<std::basic_string<char> > >&,
|
||||
const std::vector<std::vector<std::basic_string<char> > >&,
|
||||
const std::vector<TurtleRequestDisplayInfo >&,
|
||||
const std::vector<TurtleRequestDisplayInfo >&) ;
|
||||
|
||||
void processSettings(bool bLoad);
|
||||
bool m_bProcessSettings;
|
||||
|
||||
virtual void updateDisplay() ;
|
||||
QTreeWidgetItem *findParentHashItem(const std::string& hash) ;
|
||||
|
||||
std::map<std::string,QTreeWidgetItem*> top_level_hashes ;
|
||||
QTreeWidgetItem *top_level_unknown_hashes ;
|
||||
QTreeWidgetItem *top_level_s_requests ;
|
||||
QTreeWidgetItem *top_level_t_requests ;
|
||||
|
||||
} ;
|
39
retroshare-gui/src/gui/FileTransfer/TurtleRouterDialog.ui
Normal file
39
retroshare-gui/src/gui/FileTransfer/TurtleRouterDialog.ui
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TurtleRouterDialogForm</class>
|
||||
<widget class="QWidget" name="TurtleRouterDialogForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>572</width>
|
||||
<height>350</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Router Statistics</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeWidget" name="_f2f_TW">
|
||||
<property name="headerHidden">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>F2F router information</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
353
retroshare-gui/src/gui/FileTransfer/TurtleRouterStatistics.cpp
Normal file
353
retroshare-gui/src/gui/FileTransfer/TurtleRouterStatistics.cpp
Normal file
|
@ -0,0 +1,353 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 20011, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <QTimer>
|
||||
#include <QObject>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStylePainter>
|
||||
|
||||
#include <retroshare/rsturtle.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include "TurtleRouterStatistics.h"
|
||||
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
|
||||
static const int MAX_TUNNEL_REQUESTS_DISPLAY = 10 ;
|
||||
|
||||
class TRHistogram
|
||||
{
|
||||
public:
|
||||
TRHistogram(const std::vector<TurtleRequestDisplayInfo >& info) :_infos(info) {}
|
||||
|
||||
QColor colorScale(float f)
|
||||
{
|
||||
if(f == 0)
|
||||
return QColor::fromHsv(0,0,192) ;
|
||||
else
|
||||
return QColor::fromHsv((int)((1.0-f)*280),200,255) ;
|
||||
}
|
||||
|
||||
virtual void draw(QPainter *painter,int& ox,int& oy,const QString& title)
|
||||
{
|
||||
static const int MaxTime = 61 ;
|
||||
static const int MaxDepth = 8 ;
|
||||
static const int cellx = 7 ;
|
||||
static const int celly = 12 ;
|
||||
|
||||
int save_ox = ox ;
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawText(2+ox,celly+oy,title) ;
|
||||
oy+=2+2*celly ;
|
||||
|
||||
if(_infos.empty())
|
||||
return ;
|
||||
|
||||
ox += 10 ;
|
||||
std::map<std::string,std::vector<int> > hits ;
|
||||
std::map<std::string,std::vector<int> > depths ;
|
||||
std::map<std::string,std::vector<int> >::iterator it ;
|
||||
|
||||
int max_hits = 1;
|
||||
int max_depth = 1;
|
||||
|
||||
for(uint32_t i=0;i<_infos.size();++i)
|
||||
{
|
||||
std::vector<int>& h(hits[_infos[i].source_peer_id]) ;
|
||||
std::vector<int>& g(depths[_infos[i].source_peer_id]) ;
|
||||
|
||||
if(h.size() <= _infos[i].age)
|
||||
h.resize(MaxTime,0) ;
|
||||
|
||||
if(g.empty())
|
||||
g.resize(MaxDepth,0) ;
|
||||
|
||||
if(_infos[i].age < h.size())
|
||||
{
|
||||
h[_infos[i].age]++ ;
|
||||
if(h[_infos[i].age] > max_hits)
|
||||
max_hits = h[_infos[i].age] ;
|
||||
}
|
||||
if(_infos[i].depth < g.size())
|
||||
{
|
||||
g[_infos[i].depth]++ ;
|
||||
|
||||
if(g[_infos[i].depth] > max_depth)
|
||||
max_depth = g[_infos[i].depth] ;
|
||||
}
|
||||
}
|
||||
|
||||
int max_bi = std::max(max_hits,max_depth) ;
|
||||
int p=0 ;
|
||||
|
||||
for(it=depths.begin();it!=depths.end();++it,++p)
|
||||
for(int i=0;i<MaxDepth;++i)
|
||||
painter->fillRect(ox+MaxTime*cellx+20+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
|
||||
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawRect(ox+MaxTime*cellx+20,oy,MaxDepth*cellx,p*celly) ;
|
||||
|
||||
for(int i=0;i<MaxTime;i+=5)
|
||||
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
|
||||
|
||||
p=0 ;
|
||||
int great_total = 0 ;
|
||||
|
||||
for(it=hits.begin();it!=hits.end();++it,++p)
|
||||
{
|
||||
int total = 0 ;
|
||||
|
||||
for(int i=0;i<MaxTime;++i)
|
||||
{
|
||||
painter->fillRect(ox+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
|
||||
total += it->second[i] ;
|
||||
}
|
||||
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx,oy+(p+1)*celly,TurtleRouterStatistics::getPeerName(it->first)) ;
|
||||
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+(p+1)*celly,"("+QString::number(total)+")") ;
|
||||
great_total += total ;
|
||||
}
|
||||
|
||||
painter->drawRect(ox,oy,MaxTime*cellx,p*celly) ;
|
||||
|
||||
for(int i=0;i<MaxTime;i+=5)
|
||||
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
|
||||
for(int i=0;i<MaxDepth;i++)
|
||||
painter->drawText(ox+MaxTime*cellx+20+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
|
||||
painter->setPen(QColor::fromRgb(255,130,80)) ;
|
||||
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+(p+1)*celly+4,"("+QString::number(great_total)+")");
|
||||
|
||||
oy += (p+1)*celly+6 ;
|
||||
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawText(ox,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Age in seconds")+")");
|
||||
painter->drawText(ox+MaxTime*cellx+20,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Depth")+")");
|
||||
|
||||
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "total")+")");
|
||||
|
||||
oy += 3*celly ;
|
||||
|
||||
// now, draw a scale
|
||||
|
||||
int last_hts = -1 ;
|
||||
int cellid = 0 ;
|
||||
|
||||
for(int i=0;i<=10;++i)
|
||||
{
|
||||
int hts = (int)(max_bi*i/10.0) ;
|
||||
|
||||
if(hts > last_hts)
|
||||
{
|
||||
painter->fillRect(ox+cellid*(cellx+22),oy,cellx,celly,colorScale(i/10.0f)) ;
|
||||
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
||||
painter->drawRect(ox+cellid*(cellx+22),oy,cellx,celly) ;
|
||||
painter->drawText(ox+cellid*(cellx+22)+cellx+4,oy+celly,QString::number(hts)) ;
|
||||
last_hts = hts ;
|
||||
++cellid ;
|
||||
}
|
||||
}
|
||||
|
||||
oy += celly*2 ;
|
||||
|
||||
ox = save_ox ;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::vector<TurtleRequestDisplayInfo>& _infos ;
|
||||
};
|
||||
|
||||
TurtleRouterStatistics::TurtleRouterStatistics(QWidget *parent)
|
||||
: RsAutoUpdatePage(2000,parent)
|
||||
{
|
||||
setupUi(this) ;
|
||||
|
||||
m_bProcessSettings = false;
|
||||
|
||||
_tunnel_statistics_F->setWidget( _tst_CW = new TurtleRouterStatisticsWidget() ) ;
|
||||
_tunnel_statistics_F->setWidgetResizable(true);
|
||||
_tunnel_statistics_F->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
_tunnel_statistics_F->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
_tunnel_statistics_F->viewport()->setBackgroundRole(QPalette::NoRole);
|
||||
_tunnel_statistics_F->setFrameStyle(QFrame::NoFrame);
|
||||
_tunnel_statistics_F->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
// load settings
|
||||
processSettings(true);
|
||||
}
|
||||
|
||||
TurtleRouterStatistics::~TurtleRouterStatistics()
|
||||
{
|
||||
|
||||
// save settings
|
||||
processSettings(false);
|
||||
}
|
||||
|
||||
void TurtleRouterStatistics::processSettings(bool bLoad)
|
||||
{
|
||||
m_bProcessSettings = true;
|
||||
|
||||
Settings->beginGroup(QString("TurtleRouterStatistics"));
|
||||
|
||||
if (bLoad) {
|
||||
// load settings
|
||||
|
||||
// state of splitter
|
||||
//splitter->restoreState(Settings->value("Splitter").toByteArray());
|
||||
} else {
|
||||
// save settings
|
||||
|
||||
// state of splitter
|
||||
//Settings->setValue("Splitter", splitter->saveState());
|
||||
|
||||
}
|
||||
|
||||
Settings->endGroup();
|
||||
|
||||
m_bProcessSettings = false;
|
||||
|
||||
}
|
||||
|
||||
void TurtleRouterStatistics::updateDisplay()
|
||||
{
|
||||
std::vector<std::vector<std::string> > hashes_info ;
|
||||
std::vector<std::vector<std::string> > tunnels_info ;
|
||||
std::vector<TurtleRequestDisplayInfo > search_reqs_info ;
|
||||
std::vector<TurtleRequestDisplayInfo > tunnel_reqs_info ;
|
||||
|
||||
rsTurtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
||||
|
||||
//updateTunnelRequests(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
||||
_tst_CW->updateTunnelStatistics(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
||||
_tst_CW->update();
|
||||
}
|
||||
|
||||
QString TurtleRouterStatistics::getPeerName(const std::string& peer_id)
|
||||
{
|
||||
static std::map<std::string, QString> names ;
|
||||
|
||||
std::map<std::string,QString>::const_iterator it = names.find(peer_id) ;
|
||||
|
||||
if( it != names.end())
|
||||
return it->second ;
|
||||
else
|
||||
{
|
||||
RsPeerDetails detail ;
|
||||
if(!rsPeers->getPeerDetails(peer_id,detail))
|
||||
return tr("Unknown Peer");
|
||||
|
||||
return (names[peer_id] = QString::fromUtf8(detail.name.c_str())) ;
|
||||
}
|
||||
}
|
||||
|
||||
TurtleRouterStatisticsWidget::TurtleRouterStatisticsWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
maxWidth = 200 ;
|
||||
maxHeight = 0 ;
|
||||
}
|
||||
|
||||
void TurtleRouterStatisticsWidget::updateTunnelStatistics(const std::vector<std::vector<std::string> >& /*hashes_info*/,
|
||||
const std::vector<std::vector<std::string> >& /*tunnels_info*/,
|
||||
const std::vector<TurtleRequestDisplayInfo >& search_reqs_info,
|
||||
const std::vector<TurtleRequestDisplayInfo >& tunnel_reqs_info)
|
||||
|
||||
{
|
||||
static const int cellx = 6 ;
|
||||
static const int celly = 10+4 ;
|
||||
|
||||
QPixmap tmppixmap(maxWidth, maxHeight);
|
||||
tmppixmap.fill(this, 0, 0);
|
||||
setFixedHeight(maxHeight);
|
||||
|
||||
QPainter painter(&tmppixmap);
|
||||
painter.initFrom(this);
|
||||
|
||||
maxHeight = 500 ;
|
||||
|
||||
// std::cerr << "Drawing into pixmap of size " << maxWidth << "x" << maxHeight << std::endl;
|
||||
// draw...
|
||||
int ox=5,oy=5 ;
|
||||
|
||||
TRHistogram(search_reqs_info).draw(&painter,ox,oy,tr("Search requests repartition") + ":") ;
|
||||
|
||||
painter.setPen(QColor::fromRgb(70,70,70)) ;
|
||||
painter.drawLine(0,oy,maxWidth,oy) ;
|
||||
oy += celly ;
|
||||
|
||||
TRHistogram(tunnel_reqs_info).draw(&painter,ox,oy,tr("Tunnel requests repartition") + ":") ;
|
||||
|
||||
// now give information about turtle traffic.
|
||||
//
|
||||
TurtleTrafficStatisticsInfo info ;
|
||||
rsTurtle->getTrafficStatistics(info) ;
|
||||
|
||||
painter.setPen(QColor::fromRgb(70,70,70)) ;
|
||||
painter.drawLine(0,oy,maxWidth,oy) ;
|
||||
oy += celly ;
|
||||
|
||||
painter.drawText(ox,oy+celly,tr("Turtle router traffic")+":") ; oy += celly*2 ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Up")+"\t: " + speedString(info.tr_up_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Dn")+"\t: " + speedString(info.tr_dn_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Incoming file data")+"\t: " + speedString(info.data_dn_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Outgoing file data")+"\t: " + speedString(info.data_up_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Forwarded data ")+"\t: " + speedString(info.unknown_updn_Bps) ) ; oy += celly ;
|
||||
|
||||
QString prob_string ;
|
||||
|
||||
for(uint i=0;i<info.forward_probabilities.size();++i)
|
||||
prob_string += QString::number(info.forward_probabilities[i],'g',2) + " (" + QString::number(i) + ") " ;
|
||||
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("TR Forward probabilities")+"\t: " + prob_string ) ;
|
||||
oy += celly ;
|
||||
oy += celly ;
|
||||
|
||||
// update the pixmap
|
||||
//
|
||||
pixmap = tmppixmap;
|
||||
maxHeight = oy ;
|
||||
}
|
||||
|
||||
QString TurtleRouterStatisticsWidget::speedString(float f)
|
||||
{
|
||||
if(f < 1.0f)
|
||||
return QString("0 B/s") ;
|
||||
if(f < 1024.0f)
|
||||
return QString::number((int)f)+" B/s" ;
|
||||
|
||||
return QString::number(f/1024.0,'f',2) + " KB/s";
|
||||
}
|
||||
|
||||
void TurtleRouterStatisticsWidget::paintEvent(QPaintEvent */*event*/)
|
||||
{
|
||||
QStylePainter(this).drawPixmap(0, 0, pixmap);
|
||||
}
|
||||
|
||||
void TurtleRouterStatisticsWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QRect TaskGraphRect = geometry();
|
||||
maxWidth = TaskGraphRect.width();
|
||||
maxHeight = TaskGraphRect.height() ;
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
update();
|
||||
}
|
73
retroshare-gui/src/gui/FileTransfer/TurtleRouterStatistics.h
Normal file
73
retroshare-gui/src/gui/FileTransfer/TurtleRouterStatistics.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 20011, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QPoint>
|
||||
#include <retroshare/rsturtle.h>
|
||||
#include "ui_TurtleRouterStatistics.h"
|
||||
#include "RsAutoUpdatePage.h"
|
||||
|
||||
class TurtleRouterStatisticsWidget ;
|
||||
|
||||
class TurtleRouterStatistics: public RsAutoUpdatePage, public Ui::TurtleRouterStatistics
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TurtleRouterStatistics(QWidget *parent = NULL) ;
|
||||
~TurtleRouterStatistics();
|
||||
|
||||
// Cache for peer names.
|
||||
static QString getPeerName(const std::string& peer_id) ;
|
||||
|
||||
private:
|
||||
|
||||
void processSettings(bool bLoad);
|
||||
bool m_bProcessSettings;
|
||||
|
||||
virtual void updateDisplay() ;
|
||||
|
||||
TurtleRouterStatisticsWidget *_tst_CW ;
|
||||
} ;
|
||||
|
||||
class TurtleRouterStatisticsWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TurtleRouterStatisticsWidget(QWidget *parent = NULL) ;
|
||||
|
||||
virtual void paintEvent(QPaintEvent *event) ;
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
|
||||
void updateTunnelStatistics( const std::vector<std::vector<std::basic_string<char> > >&,
|
||||
const std::vector<std::vector<std::basic_string<char> > >&,
|
||||
const std::vector<TurtleRequestDisplayInfo >&,
|
||||
const std::vector<TurtleRequestDisplayInfo >&) ;
|
||||
|
||||
private:
|
||||
static QString speedString(float f) ;
|
||||
|
||||
QPixmap pixmap ;
|
||||
int maxWidth,maxHeight ;
|
||||
};
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TurtleRouterStatistics</class>
|
||||
<widget class="QWidget" name="TurtleRouterStatistics">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>611</width>
|
||||
<height>408</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Router Statistics</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="images.qrc">
|
||||
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QScrollArea" name="_tunnel_statistics_F">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>593</width>
|
||||
<height>390</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
185
retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp
Normal file
185
retroshare-gui/src/gui/FileTransfer/ULListDelegate.cpp
Normal file
|
@ -0,0 +1,185 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006,2007 crypton
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "ULListDelegate.h"
|
||||
#include "xprogressbar.h"
|
||||
|
||||
Q_DECLARE_METATYPE(FileProgressInfo)
|
||||
|
||||
ULListDelegate::ULListDelegate(QObject *parent) : QAbstractItemDelegate(parent)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ULListDelegate::~ULListDelegate(void)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void ULListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
{
|
||||
QString byteUnits[4] = {tr("B"), tr("KB"), tr("MB"), tr("GB")};
|
||||
QStyleOptionViewItem opt = option;
|
||||
QStyleOptionProgressBarV2 newopt;
|
||||
QRect pixmapRect;
|
||||
QPixmap pixmap;
|
||||
qlonglong fileSize;
|
||||
double ulspeed, multi;
|
||||
QString temp , status;
|
||||
qlonglong transferred;
|
||||
|
||||
// prepare
|
||||
painter->save();
|
||||
painter->setClipRect(opt.rect);
|
||||
|
||||
//set text color
|
||||
QVariant value = index.data(Qt::TextColorRole);
|
||||
if(value.isValid() && qvariant_cast<QColor>(value).isValid()) {
|
||||
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
|
||||
}
|
||||
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
|
||||
if(option.state & QStyle::State_Selected){
|
||||
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
|
||||
} else {
|
||||
painter->setPen(opt.palette.color(cg, QPalette::Text));
|
||||
}
|
||||
|
||||
// draw the background color
|
||||
if(index.column() != COLUMN_UPROGRESS) {
|
||||
if(option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
|
||||
if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
|
||||
cg = QPalette::Inactive;
|
||||
}
|
||||
painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
|
||||
} else {
|
||||
value = index.data(Qt::BackgroundRole);
|
||||
if(value.isValid() && qvariant_cast<QColor>(value).isValid()) {
|
||||
painter->fillRect(option.rect, qvariant_cast<QColor>(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
switch(index.column()) {
|
||||
case COLUMN_USIZE:
|
||||
fileSize = index.data().toLongLong();
|
||||
if(fileSize <= 0){
|
||||
temp = "";
|
||||
} else {
|
||||
multi = 1.0;
|
||||
for(int i = 0; i < 5; ++i) {
|
||||
if (fileSize < 1024) {
|
||||
fileSize = index.data().toLongLong();
|
||||
temp.sprintf("%.2f ", fileSize / multi);
|
||||
temp += byteUnits[i];
|
||||
break;
|
||||
}
|
||||
fileSize /= 1024;
|
||||
multi *= 1024.0;
|
||||
}
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case COLUMN_UTRANSFERRED:
|
||||
transferred = index.data().toLongLong();
|
||||
if(transferred <= 0){
|
||||
temp = "";
|
||||
} else {
|
||||
multi = 1.0;
|
||||
for(int i = 0; i < 5; ++i) {
|
||||
if (transferred < 1024) {
|
||||
transferred = index.data().toLongLong();
|
||||
temp.sprintf("%.2f ", transferred / multi);
|
||||
temp += byteUnits[i];
|
||||
break;
|
||||
}
|
||||
transferred /= 1024;
|
||||
multi *= 1024.0;
|
||||
}
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case COLUMN_ULSPEED:
|
||||
ulspeed = index.data().toDouble();
|
||||
if (ulspeed <= 0) {
|
||||
temp = "";
|
||||
} else {
|
||||
temp.clear();
|
||||
temp.sprintf("%.2f", ulspeed/1024.);
|
||||
temp += " KB/s";
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignRight, temp);
|
||||
break;
|
||||
case COLUMN_UPROGRESS:
|
||||
{
|
||||
FileProgressInfo pinfo = index.data().value<FileProgressInfo>() ;
|
||||
|
||||
// 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();;
|
||||
if (ext == "rsfc" || ext == "rsrl" || ext == "dist" || ext == "rsfb")
|
||||
progressBar.setColorSchema( 9);
|
||||
else
|
||||
progressBar.setColorSchema( 8);
|
||||
|
||||
progressBar.setDisplayText(true); // should display % text?
|
||||
progressBar.setVerticalSpan(1);
|
||||
progressBar.paint(); // paint the progress bar
|
||||
|
||||
painter->restore() ;
|
||||
}
|
||||
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
|
||||
break;
|
||||
case COLUMN_UNAME:
|
||||
// decoration
|
||||
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);
|
||||
pixmapRect = (pixmap.isNull() ? QRect(0, 0, 0, 0): QRect(QPoint(0, 0), option.decorationSize));
|
||||
if (pixmapRect.isValid()){
|
||||
QPoint p = QStyle::alignedRect(option.direction, Qt::AlignLeft, pixmap.size(), option.rect).topLeft();
|
||||
painter->drawPixmap(p, pixmap);
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
// done
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize ULListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
{
|
||||
return QSize(50,17);
|
||||
QVariant value = index.data(Qt::FontRole);
|
||||
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
|
||||
QFontMetrics fontMetrics(fnt);
|
||||
const QString text = index.data(Qt::DisplayRole).toString();
|
||||
QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1));
|
||||
return textRect.size();
|
||||
}
|
||||
|
66
retroshare-gui/src/gui/FileTransfer/ULListDelegate.h
Normal file
66
retroshare-gui/src/gui/FileTransfer/ULListDelegate.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006,2007 crypton
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef ULLISTDELEGATE_H
|
||||
#define ULLISTDELEGATE_H
|
||||
|
||||
#include <QAbstractItemDelegate>
|
||||
|
||||
// Defines for upload list list columns
|
||||
#define COLUMN_UNAME 0
|
||||
#define COLUMN_USIZE 1
|
||||
#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 MAX_CHAR_TMP 128
|
||||
|
||||
class QModelIndex;
|
||||
class QPainter;
|
||||
class QStyleOptionProgressBarV2;
|
||||
class QProgressBar;
|
||||
class QApplication;
|
||||
|
||||
|
||||
class ULListDelegate: public QAbstractItemDelegate {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ULListDelegate(QObject *parent=0);
|
||||
~ULListDelegate();
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
|
||||
private:
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
};
|
||||
#endif
|
||||
|
306
retroshare-gui/src/gui/FileTransfer/xprogressbar.cpp
Normal file
306
retroshare-gui/src/gui/FileTransfer/xprogressbar.cpp
Normal file
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* xProgressBar: A custom progress bar for Qt 4.
|
||||
* Author: xEsk (Xesc & Technology 2008)
|
||||
*
|
||||
* Changelog:
|
||||
*
|
||||
* v1.0:
|
||||
* -----
|
||||
* - First release
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
#include "xprogressbar.h"
|
||||
|
||||
bool FileProgressInfo::operator<(const FileProgressInfo &other) const
|
||||
{
|
||||
return progress < other.progress;
|
||||
}
|
||||
|
||||
bool FileProgressInfo::operator>(const FileProgressInfo &other) const
|
||||
{
|
||||
return progress > other.progress;
|
||||
}
|
||||
|
||||
xProgressBar::xProgressBar(const FileProgressInfo& pinfo,QRect rect, QPainter *painter, int schemaIndex)
|
||||
: _pinfo(pinfo)
|
||||
{
|
||||
// assign internal data
|
||||
this->schemaIndex = schemaIndex;
|
||||
this->rect = rect;
|
||||
this->painter = painter;
|
||||
// set the progress bar colors
|
||||
setColor();
|
||||
// configure span
|
||||
vSpan = 0;
|
||||
hSpan = 0;
|
||||
// text color
|
||||
textColor = QColor("black");
|
||||
}
|
||||
|
||||
void xProgressBar::setColor()
|
||||
{
|
||||
/* TEMPORAL SCHEMA DEFINITION */
|
||||
|
||||
switch (schemaIndex)
|
||||
{
|
||||
/* blue schema */
|
||||
case 0:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(143, 180, 219);
|
||||
backgroundColor.setRgb(198, 209, 221);
|
||||
// progress
|
||||
gradBorderColor.setRgb(35, 96, 167);
|
||||
gradColor1.setRgb(100, 136, 252);
|
||||
gradColor2.setRgb(165, 183, 240);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* green schema */
|
||||
case 1:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(53, 194, 26);
|
||||
backgroundColor.setRgb(176, 214, 93);
|
||||
// progress
|
||||
gradBorderColor.setRgb(8, 77, 16);
|
||||
gradColor1.setRgb(0, 137, 16);
|
||||
gradColor2.setRgb(78, 194, 81);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* red schema */
|
||||
case 2:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(255, 62, 62);
|
||||
backgroundColor.setRgb(248, 175, 175);
|
||||
// progress
|
||||
gradBorderColor.setRgb(151, 0, 0);
|
||||
gradColor1.setRgb(251, 54, 54);
|
||||
gradColor2.setRgb(246, 118, 118);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* gray schema */
|
||||
case 3:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(116, 177, 160);
|
||||
backgroundColor.setRgb(178, 215, 205);
|
||||
// progress
|
||||
gradBorderColor.setRgb(106, 106, 106);
|
||||
gradColor1.setRgb(168, 168, 168);
|
||||
gradColor2.setRgb(197, 197, 197);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* yellow schema */
|
||||
case 4:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(227, 204, 79);
|
||||
backgroundColor.setRgb(255, 236, 130);
|
||||
// progress
|
||||
gradBorderColor.setRgb(215, 182, 0);
|
||||
gradColor1.setRgb(233, 197, 0);
|
||||
gradColor2.setRgb(255, 236, 130);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* black schema */
|
||||
case 5:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(99, 99, 99);
|
||||
backgroundColor.setRgb(134, 134, 134);
|
||||
// progress
|
||||
gradBorderColor.setRgb(0, 0, 0);
|
||||
gradColor1.setRgb(38, 38, 38);
|
||||
gradColor2.setRgb(113, 113, 113);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* purple schema */
|
||||
case 6:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(234, 127, 223);
|
||||
backgroundColor.setRgb(255, 164, 246);
|
||||
// progress
|
||||
gradBorderColor.setRgb(150, 0, 134);
|
||||
gradColor1.setRgb(218, 0, 195);
|
||||
gradColor2.setRgb(255, 121, 241);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* maroon schema */
|
||||
case 7:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(255, 174, 49);
|
||||
backgroundColor.setRgb(255, 204, 132);
|
||||
// progress
|
||||
gradBorderColor.setRgb(159, 94, 0);
|
||||
gradColor1.setRgb(223, 134, 6);
|
||||
gradColor2.setRgb(248, 170, 59);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* clean schema */
|
||||
case 8:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(143, 180, 219);
|
||||
backgroundColor.setRgb(198, 209, 221);
|
||||
// progress
|
||||
gradBorderColor.setRgb(209, 128, 24);
|
||||
gradColor1.setRgb(246, 199, 138);
|
||||
gradColor2.setRgb(255, 227, 190);
|
||||
// ok
|
||||
break;
|
||||
|
||||
/* light gray */
|
||||
case 9:
|
||||
// background
|
||||
backgroundBorderColor.setRgb(194, 194, 194);
|
||||
backgroundColor.setRgb(232, 233, 233);
|
||||
// progress
|
||||
gradBorderColor.setRgb(176, 176, 176);
|
||||
gradColor1.setRgb(201, 201, 201);
|
||||
gradColor2.setRgb(223, 223, 223);
|
||||
// set text color (white is not a good option)
|
||||
textColor = QColor(58, 58, 58);
|
||||
// ok
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void xProgressBar::overPaintSelectedChunks(const std::vector<uint32_t>& chunks,const QColor& gradColor_a1,const QColor& gradColor_a2, int width,uint32_t ss) const
|
||||
{
|
||||
QLinearGradient linearGrad(rect.x(), rect.y(), rect.x(), rect.y() + rect.height() - 1);
|
||||
|
||||
linearGrad.setColorAt(0.00, gradColor_a1);
|
||||
linearGrad.setColorAt(0.16, gradColor_a2);
|
||||
linearGrad.setColorAt(1.00, gradColor_a1);
|
||||
|
||||
painter->setBrush(linearGrad);
|
||||
|
||||
if(chunks.empty())
|
||||
return ;
|
||||
|
||||
int last_i = chunks[0] ;
|
||||
|
||||
for(uint32_t i=1;i<chunks.size();++i)
|
||||
if(chunks[i] > chunks[i-1]+1)
|
||||
{
|
||||
int nb_consecutive_chunks = chunks[i-1] - last_i + 1 ;
|
||||
|
||||
painter->drawRect(rect.x() + hSpan+(int)rint(last_i*width/(float)ss), rect.y() + vSpan, (int)ceil(nb_consecutive_chunks*width/(float)ss), rect.height() - 1 - vSpan * 2);
|
||||
last_i = chunks[i] ;
|
||||
}
|
||||
int nb_consecutive_chunks = chunks.back() - last_i + 1 ;
|
||||
painter->drawRect(rect.x() + hSpan+(int)rint(last_i*width/(float)ss), rect.y() + vSpan, (int)ceil(nb_consecutive_chunks*width/(float)ss), rect.height() - 1 - vSpan * 2);
|
||||
}
|
||||
|
||||
void xProgressBar::paint()
|
||||
{
|
||||
// paint the progressBar background
|
||||
painter->setBrush(backgroundColor);
|
||||
painter->setPen(backgroundBorderColor);
|
||||
painter->drawRect(rect.x() + hSpan, rect.y() + vSpan, rect.width() - 1 - hSpan, rect.height() - 1 - vSpan * 2);
|
||||
|
||||
// define gradient
|
||||
QLinearGradient linearGrad(rect.x(), rect.y(), rect.x(), rect.y() + rect.height() - 1);
|
||||
|
||||
linearGrad.setColorAt(0.00, gradColor1);
|
||||
linearGrad.setColorAt(0.16, gradColor2);
|
||||
linearGrad.setColorAt(1.00, gradColor1);
|
||||
painter->setPen(gradBorderColor);
|
||||
|
||||
int width = static_cast<int>(rect.width()-1-2*hSpan) ;
|
||||
|
||||
painter->setBrush(linearGrad);
|
||||
|
||||
uint32_t ss = _pinfo.nb_chunks ;
|
||||
|
||||
if(ss > 1) // for small files we use a more progressive display
|
||||
{
|
||||
if(!_pinfo.cmap._map.empty())
|
||||
for(uint32_t i=0;i<ss;++i)
|
||||
{
|
||||
uint32_t j=0 ;
|
||||
while(i+j<ss && _pinfo.cmap[i+j])
|
||||
++j ;
|
||||
|
||||
float o = std::min(1.0f,j/(float)ss*width) ;
|
||||
|
||||
if(j>0 && o >= 1.0f) // limits the number of regions drawn
|
||||
{
|
||||
painter->setOpacity(o) ;
|
||||
painter->drawRect(rect.x() + hSpan+(int)rint(i*width/(float)ss), rect.y() + vSpan, (int)ceil(j*width/(float)ss), rect.height() - 1 - vSpan * 2);
|
||||
}
|
||||
|
||||
i += j ;
|
||||
}
|
||||
|
||||
overPaintSelectedChunks( _pinfo.chunks_in_progress , QColor(170, 20,9), QColor(223,121,123), width,ss) ;
|
||||
overPaintSelectedChunks( _pinfo.chunks_in_checking , QColor(186,143,0), QColor(223,196, 61), width,ss) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// calculate progress value
|
||||
int preWidth = static_cast<int>((rect.width() - 1 - hSpan)*(_pinfo.progress/100.0f));
|
||||
int progressWidth = rect.width() - preWidth;
|
||||
if (progressWidth == rect.width() - hSpan) return;
|
||||
|
||||
// paint the progress
|
||||
painter->setBrush(linearGrad);
|
||||
painter->drawRect(rect.x() + hSpan, rect.y() + vSpan, rect.width() - progressWidth - hSpan, rect.height() - 1 - vSpan * 2);
|
||||
}
|
||||
painter->setOpacity(1.0f) ;
|
||||
|
||||
|
||||
// paint text?
|
||||
if (displayText)
|
||||
{
|
||||
QLocale locale;
|
||||
painter->setPen(textColor);
|
||||
painter->drawText(rect, Qt::AlignCenter, locale.toString(_pinfo.progress, 'f', 2) + "%");
|
||||
}
|
||||
|
||||
backgroundColor.setRgb(255, 255, 255);
|
||||
painter->setBrush(backgroundColor);
|
||||
backgroundBorderColor.setRgb(0, 0, 0);
|
||||
painter->setPen(backgroundBorderColor);
|
||||
}
|
||||
|
||||
void xProgressBar::setColorSchema(const int value)
|
||||
{
|
||||
schemaIndex = value;
|
||||
// set the progress bar colors
|
||||
setColor();
|
||||
}
|
||||
|
||||
void xProgressBar::setDisplayText(const bool display)
|
||||
{
|
||||
displayText = display;
|
||||
}
|
||||
|
||||
void xProgressBar::setVerticalSpan(const int value)
|
||||
{
|
||||
vSpan = value;
|
||||
}
|
||||
|
||||
void xProgressBar::setHorizontalSpan(const int value)
|
||||
{
|
||||
hSpan = value;
|
||||
}
|
92
retroshare-gui/src/gui/FileTransfer/xprogressbar.h
Normal file
92
retroshare-gui/src/gui/FileTransfer/xprogressbar.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* xProgressBar: A custom progress bar for Qt 4.
|
||||
* Author: xEsk (Xesc & Technology 2008)
|
||||
*
|
||||
* Changelog:
|
||||
*
|
||||
* v1.0:
|
||||
* -----
|
||||
* - First release
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef XPROGRESSBAR_H
|
||||
#define XPROGRESSBAR_H
|
||||
//
|
||||
#include <stdint.h>
|
||||
#include <QRect>
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QLinearGradient>
|
||||
#include <QLocale>
|
||||
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
class FileProgressInfo
|
||||
{
|
||||
public:
|
||||
typedef enum { DOWNLOAD_LINE,UPLOAD_LINE,DOWNLOAD_SOURCE } LineType ;
|
||||
|
||||
LineType type ;
|
||||
CompressedChunkMap cmap ;
|
||||
float progress ;
|
||||
uint32_t nb_chunks ;
|
||||
|
||||
std::vector<uint32_t> chunks_in_progress ;
|
||||
std::vector<uint32_t> chunks_in_checking ;
|
||||
|
||||
bool operator<(const FileProgressInfo &other) const;
|
||||
bool operator>(const FileProgressInfo &other) const;
|
||||
};
|
||||
//
|
||||
class xProgressBar : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
// progress vlues
|
||||
uint32_t _nb_chunks ;
|
||||
int schemaIndex;
|
||||
bool displayText;
|
||||
int vSpan;
|
||||
int hSpan;
|
||||
// painter config
|
||||
QRect rect;
|
||||
QPainter *painter;
|
||||
// text color
|
||||
QColor textColor;
|
||||
// progress colors
|
||||
QColor backgroundBorderColor;
|
||||
QColor backgroundColor;
|
||||
QColor gradBorderColor;
|
||||
QColor gradColor1;
|
||||
QColor gradColor2;
|
||||
// configure the color
|
||||
void setColor();
|
||||
|
||||
const FileProgressInfo& _pinfo ;
|
||||
public:
|
||||
xProgressBar(const FileProgressInfo& pinfo,QRect rect, QPainter *painter, int schemaIndex = 0);
|
||||
|
||||
void paint();
|
||||
|
||||
void overPaintSelectedChunks(const std::vector<uint32_t>& chunks,const QColor& gradColor_a1,const QColor& gradColor_a2, int width,uint32_t ss) const ;
|
||||
void setColorSchema(const int value);
|
||||
void setDisplayText(const bool display);
|
||||
void setVerticalSpan(const int value);
|
||||
void setHorizontalSpan(const int value);
|
||||
};
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue