2008-12-12 16:42:44 -05:00
|
|
|
/****************************************************************
|
|
|
|
* 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
|
2009-05-20 18:06:20 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2008-12-12 16:42:44 -05:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
2009-07-31 09:12:46 -04:00
|
|
|
#ifdef WIN32
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <windows.h>
|
2009-07-31 09:12:46 -04:00
|
|
|
#endif
|
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QTreeView>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QDesktopServices>
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-09-14 19:51:55 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
#include "TransfersDialog.h"
|
2010-03-10 16:38:26 -05:00
|
|
|
#include "RetroShareLink.h"
|
2010-01-05 19:10:15 -05:00
|
|
|
#include "DetailsDialog.h"
|
2008-12-12 16:42:44 -05:00
|
|
|
#include "DLListDelegate.h"
|
|
|
|
#include "ULListDelegate.h"
|
2009-11-17 07:45:06 -05:00
|
|
|
#include "FileTransferInfoWidget.h"
|
2010-02-14 04:06:37 -05:00
|
|
|
#include "TurtleRouterDialog.h"
|
2011-05-31 17:39:44 -04:00
|
|
|
#include "TurtleRouterStatistics.h"
|
2010-01-11 11:00:42 -05:00
|
|
|
#include "xprogressbar.h"
|
2010-09-14 19:51:55 -04:00
|
|
|
#include "settings/rsharesettings.h"
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsfiles.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
#include <retroshare/rsdisc.h>
|
2009-07-05 12:27:58 -04:00
|
|
|
#include "util/misc.h"
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2011-08-04 11:01:11 -04:00
|
|
|
/****
|
|
|
|
* #define SHOW_RTT_STATISTICS 1
|
|
|
|
****/
|
|
|
|
|
|
|
|
#ifdef SHOW_RTT_STATISTICS
|
|
|
|
#include "VoipStatistics.h"
|
|
|
|
#endif
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
/* Images for context menu icons */
|
|
|
|
#define IMAGE_INFO ":/images/fileinfo.png"
|
|
|
|
#define IMAGE_CANCEL ":/images/delete.png"
|
|
|
|
#define IMAGE_CLEARCOMPLETED ":/images/deleteall.png"
|
2009-05-18 10:23:55 -04:00
|
|
|
#define IMAGE_PLAY ":/images/player_play.png"
|
|
|
|
#define IMAGE_COPYLINK ":/images/copyrslink.png"
|
|
|
|
#define IMAGE_PASTELINK ":/images/pasterslink.png"
|
2009-07-02 19:47:38 -04:00
|
|
|
#define IMAGE_PAUSE ":/images/pause.png"
|
|
|
|
#define IMAGE_RESUME ":/images/resume.png"
|
|
|
|
#define IMAGE_OPENFOLDER ":/images/folderopen.png"
|
|
|
|
#define IMAGE_OPENFILE ":/images/fileopen.png"
|
|
|
|
#define IMAGE_STOP ":/images/stop.png"
|
2009-07-04 19:36:04 -04:00
|
|
|
#define IMAGE_PREVIEW ":/images/preview.png"
|
2009-07-27 07:57:58 -04:00
|
|
|
#define IMAGE_PRIORITY ":/images/filepriority.png"
|
|
|
|
#define IMAGE_PRIORITYLOW ":/images/prioritylow.png"
|
|
|
|
#define IMAGE_PRIORITYNORMAL ":/images/prioritynormal.png"
|
|
|
|
#define IMAGE_PRIORITYHIGH ":/images/priorityhigh.png"
|
|
|
|
#define IMAGE_PRIORITYAUTO ":/images/priorityauto.png"
|
2009-07-04 19:36:04 -04:00
|
|
|
|
2010-01-11 11:00:42 -05:00
|
|
|
Q_DECLARE_METATYPE(FileProgressInfo)
|
|
|
|
|
2010-05-03 18:44:53 -04:00
|
|
|
DetailsDialog *TransfersDialog::detailsdlg = NULL;
|
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
class SortByNameItem : public QStandardItem
|
2010-10-04 16:15:52 -04:00
|
|
|
{
|
|
|
|
public:
|
2011-02-07 19:41:13 -05:00
|
|
|
SortByNameItem(QHeaderView *header) : QStandardItem()
|
|
|
|
{
|
|
|
|
this->header = header;
|
|
|
|
}
|
2010-10-04 16:15:52 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
virtual bool operator<(const QStandardItem &other) const
|
|
|
|
{
|
|
|
|
QStandardItemModel *m = model();
|
|
|
|
if (m == NULL) {
|
|
|
|
return QStandardItem::operator<(other);
|
|
|
|
}
|
2010-10-04 16:15:52 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
QStandardItem *myParent = parent();
|
|
|
|
QStandardItem *otherParent = other.parent();
|
2010-10-04 16:15:52 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
if (myParent == NULL || otherParent == NULL) {
|
|
|
|
return QStandardItem::operator<(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStandardItem *myName = myParent->child(index().row(), NAME);
|
|
|
|
QStandardItem *otherName = otherParent->child(other.index().row(), NAME);
|
|
|
|
|
|
|
|
if (header == NULL || header->sortIndicatorOrder() == Qt::AscendingOrder) {
|
|
|
|
/* Ascending */
|
|
|
|
return *myName < *otherName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Descending, sort peers in ascending order */
|
|
|
|
return !(*myName < *otherName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QHeaderView *header;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProgressItem : public SortByNameItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProgressItem(QHeaderView *header) : SortByNameItem(header) {}
|
|
|
|
|
|
|
|
virtual bool operator<(const QStandardItem &other) const
|
|
|
|
{
|
|
|
|
const int role = model() ? model()->sortRole() : Qt::DisplayRole;
|
|
|
|
|
|
|
|
FileProgressInfo l = data(role).value<FileProgressInfo>();
|
|
|
|
FileProgressInfo r = other.data(role).value<FileProgressInfo>();
|
|
|
|
|
|
|
|
if (l < r) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (l > r) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SortByNameItem::operator<(other);
|
|
|
|
}
|
2010-10-04 16:15:52 -04:00
|
|
|
};
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
/** Constructor */
|
|
|
|
TransfersDialog::TransfersDialog(QWidget *parent)
|
2009-11-17 07:45:06 -05:00
|
|
|
: RsAutoUpdatePage(1000,parent)
|
2008-12-12 16:42:44 -05:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2010-09-14 19:51:55 -04:00
|
|
|
m_bProcessSettings = false;
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
connect( ui.downloadList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( downloadListCostumPopupMenu( QPoint ) ) );
|
|
|
|
|
|
|
|
// Set Download list model
|
2009-08-11 16:27:59 -04:00
|
|
|
DLListModel = new QStandardItemModel(0,ID + 1);
|
2008-12-12 16:42:44 -05:00
|
|
|
DLListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
|
|
|
|
DLListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
|
|
|
|
DLListModel->setHeaderData(COMPLETED, Qt::Horizontal, tr("Completed", ""));
|
|
|
|
DLListModel->setHeaderData(DLSPEED, Qt::Horizontal, tr("Speed", "i.e: Download speed"));
|
2010-01-26 18:25:00 -05:00
|
|
|
DLListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress / Availability", "i.e: % downloaded"));
|
2008-12-12 16:42:44 -05:00
|
|
|
DLListModel->setHeaderData(SOURCES, Qt::Horizontal, tr("Sources", "i.e: Sources"));
|
|
|
|
DLListModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status"));
|
2010-03-06 18:29:47 -05:00
|
|
|
DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Speed / Queue position"));
|
2010-03-01 17:47:48 -05:00
|
|
|
DLListModel->setHeaderData(REMAINING, Qt::Horizontal, tr("Remaining"));
|
|
|
|
DLListModel->setHeaderData(DOWNLOADTIME, Qt::Horizontal, tr("Download time", "i.e: Estimated Time of Arrival / Time left"));
|
2008-12-12 16:42:44 -05:00
|
|
|
DLListModel->setHeaderData(ID, Qt::Horizontal, tr("Core-ID"));
|
|
|
|
ui.downloadList->setModel(DLListModel);
|
2009-05-07 18:40:57 -04:00
|
|
|
ui.downloadList->hideColumn(ID);
|
2008-12-12 16:42:44 -05:00
|
|
|
DLDelegate = new DLListDelegate();
|
|
|
|
ui.downloadList->setItemDelegate(DLDelegate);
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-09-15 15:26:25 -04:00
|
|
|
// Why disable autoscroll ?
|
|
|
|
// With disabled autoscroll, the treeview doesn't scroll with cursor move
|
|
|
|
// ui.downloadList->setAutoScroll(false) ;
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-05-06 10:39:50 -04:00
|
|
|
// workaround for Qt bug, should be solved in next Qt release 4.7.0
|
|
|
|
// http://bugreports.qt.nokia.com/browse/QTBUG-8270
|
|
|
|
QShortcut *Shortcut = new QShortcut(QKeySequence (Qt::Key_Delete), ui.downloadList, 0, 0, Qt::WidgetShortcut);
|
|
|
|
connect(Shortcut, SIGNAL(activated()), this, SLOT( cancel ()));
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
//Selection Setup
|
2009-05-07 18:40:57 -04:00
|
|
|
selection = ui.downloadList->selectionModel();
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2009-05-07 18:40:57 -04:00
|
|
|
ui.downloadList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
|
2009-05-20 18:06:20 -04:00
|
|
|
ui.downloadList->setRootIsDecorated(true);
|
|
|
|
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
/* Set header resize modes and initial section sizes Downloads TreeView*/
|
2009-05-07 18:40:57 -04:00
|
|
|
QHeaderView * _header = ui.downloadList->header () ;
|
2009-05-20 18:06:20 -04:00
|
|
|
_header->setResizeMode (NAME, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (SIZE, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (COMPLETED, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (DLSPEED, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (PROGRESS, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (SOURCES, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (STATUS, QHeaderView::Interactive);
|
2009-08-11 16:27:59 -04:00
|
|
|
_header->setResizeMode (PRIORITY, QHeaderView::Interactive);
|
2009-05-20 18:06:20 -04:00
|
|
|
_header->setResizeMode (REMAINING, QHeaderView::Interactive);
|
|
|
|
|
|
|
|
_header->resizeSection ( NAME, 170 );
|
|
|
|
_header->resizeSection ( SIZE, 70 );
|
|
|
|
_header->resizeSection ( COMPLETED, 75 );
|
|
|
|
_header->resizeSection ( DLSPEED, 75 );
|
2009-05-07 18:40:57 -04:00
|
|
|
_header->resizeSection ( PROGRESS, 170 );
|
2009-05-20 18:06:20 -04:00
|
|
|
_header->resizeSection ( SOURCES, 90 );
|
|
|
|
_header->resizeSection ( STATUS, 100 );
|
2009-08-11 16:27:59 -04:00
|
|
|
_header->resizeSection ( PRIORITY, 100 );
|
2009-05-20 18:06:20 -04:00
|
|
|
_header->resizeSection ( REMAINING, 100 );
|
|
|
|
|
2010-09-14 07:37:50 -04:00
|
|
|
// set default column and sort order for download
|
2010-10-04 16:15:52 -04:00
|
|
|
ui.downloadList->sortByColumn(NAME, Qt::AscendingOrder);
|
2010-09-14 07:37:50 -04:00
|
|
|
|
2009-05-07 18:40:57 -04:00
|
|
|
// Set Upload list model
|
2010-02-16 21:10:25 -05:00
|
|
|
ULListModel = new QStandardItemModel(0,8);
|
2008-12-12 16:42:44 -05:00
|
|
|
ULListModel->setHeaderData(UNAME, Qt::Horizontal, tr("Name", "i.e: file name"));
|
|
|
|
ULListModel->setHeaderData(USIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
|
2009-07-24 18:39:34 -04:00
|
|
|
ULListModel->setHeaderData(USERNAME, Qt::Horizontal, tr("Peer", "i.e: user name"));
|
2008-12-12 16:42:44 -05:00
|
|
|
ULListModel->setHeaderData(UPROGRESS, Qt::Horizontal, tr("Progress", "i.e: % uploaded"));
|
|
|
|
ULListModel->setHeaderData(ULSPEED, Qt::Horizontal, tr("Speed", "i.e: upload speed"));
|
|
|
|
ULListModel->setHeaderData(USTATUS, Qt::Horizontal, tr("Status"));
|
|
|
|
ULListModel->setHeaderData(UTRANSFERRED, Qt::Horizontal, tr("Transferred", ""));
|
2010-02-16 21:10:25 -05:00
|
|
|
ULListModel->setHeaderData(UHASH, Qt::Horizontal, tr("Hash", ""));
|
2008-12-12 16:42:44 -05:00
|
|
|
ui.uploadsList->setModel(ULListModel);
|
2010-07-27 12:05:21 -04:00
|
|
|
ULListModel->insertColumn(UUSERID);
|
|
|
|
ui.uploadsList->hideColumn(UUSERID);
|
2008-12-12 16:42:44 -05:00
|
|
|
ULDelegate = new ULListDelegate();
|
|
|
|
ui.uploadsList->setItemDelegate(ULDelegate);
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-09-15 15:26:25 -04:00
|
|
|
// Why disable autoscroll ?
|
|
|
|
// With disabled autoscroll, the treeview doesn't scroll with cursor move
|
|
|
|
// ui.uploadsList->setAutoScroll(false) ;
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
ui.uploadsList->setRootIsDecorated(false);
|
2009-05-20 18:06:20 -04:00
|
|
|
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
//Selection Setup
|
2010-09-14 07:37:50 -04:00
|
|
|
selectionup = ui.uploadsList->selectionModel();
|
|
|
|
ui.uploadsList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2009-07-24 18:39:34 -04:00
|
|
|
|
|
|
|
/* Set header resize modes and initial section sizes Uploads TreeView*/
|
|
|
|
QHeaderView * upheader = ui.uploadsList->header () ;
|
|
|
|
upheader->setResizeMode (UNAME, QHeaderView::Interactive);
|
|
|
|
upheader->setResizeMode (USIZE, QHeaderView::Interactive);
|
2009-07-26 11:02:16 -04:00
|
|
|
upheader->setResizeMode (UTRANSFERRED, QHeaderView::Interactive);
|
|
|
|
upheader->setResizeMode (ULSPEED, QHeaderView::Interactive);
|
|
|
|
upheader->setResizeMode (UPROGRESS, QHeaderView::Interactive);
|
|
|
|
upheader->setResizeMode (USTATUS, QHeaderView::Interactive);
|
|
|
|
upheader->setResizeMode (USERNAME, QHeaderView::Interactive);
|
2009-07-24 18:39:34 -04:00
|
|
|
|
2010-06-15 07:34:58 -04:00
|
|
|
upheader->resizeSection ( UNAME, 190 );
|
2009-07-24 18:39:34 -04:00
|
|
|
upheader->resizeSection ( USIZE, 70 );
|
|
|
|
upheader->resizeSection ( UTRANSFERRED, 75 );
|
2009-07-26 11:02:16 -04:00
|
|
|
upheader->resizeSection ( ULSPEED, 75 );
|
|
|
|
upheader->resizeSection ( UPROGRESS, 170 );
|
|
|
|
upheader->resizeSection ( USTATUS, 100 );
|
2010-03-29 14:11:17 -04:00
|
|
|
upheader->resizeSection ( USERNAME, 120 );
|
2009-07-26 11:02:16 -04:00
|
|
|
|
2010-09-14 07:37:50 -04:00
|
|
|
// set default column and sort order for upload
|
2010-10-04 16:15:52 -04:00
|
|
|
ui.uploadsList->sortByColumn(UNAME, Qt::AscendingOrder);
|
2010-09-14 07:37:50 -04:00
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
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);
|
2009-09-15 14:37:03 -04:00
|
|
|
|
2010-05-03 18:44:53 -04:00
|
|
|
QObject::connect(ui.downloadList->selectionModel(),SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),this,SLOT(showFileDetails())) ;
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2011-05-31 17:39:44 -04:00
|
|
|
ui.tabWidget->addTab( new TurtleRouterStatistics(), tr("Router Statistics")) ;
|
|
|
|
|
|
|
|
ui.tabWidget->addTab( new TurtleRouterDialog(), tr("Router Requests")) ;
|
2011-08-03 13:45:03 -04:00
|
|
|
|
2011-08-04 11:01:11 -04:00
|
|
|
#ifdef SHOW_RTT_STATISTICS
|
2011-08-03 13:45:03 -04:00
|
|
|
ui.tabWidget->addTab( new VoipStatistics(), tr("RTT Statistics")) ;
|
2011-08-04 11:01:11 -04:00
|
|
|
#endif
|
2011-05-31 17:39:44 -04:00
|
|
|
|
2011-05-28 18:25:42 -04:00
|
|
|
|
|
|
|
// TurtleRouterDialog *trdl = new TurtleRouterDialog();
|
|
|
|
// ui.tunnelInfoWidget->setWidget(trdl);
|
|
|
|
// ui.tunnelInfoWidget->setWidgetResizable(true);
|
|
|
|
// ui.tunnelInfoWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
// ui.tunnelInfoWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
// ui.tunnelInfoWidget->viewport()->setBackgroundRole(QPalette::NoRole);
|
|
|
|
// ui.tunnelInfoWidget->setFrameStyle(QFrame::NoFrame);
|
|
|
|
// ui.tunnelInfoWidget->setFocusPolicy(Qt::NoFocus);
|
2010-02-14 04:06:37 -05:00
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
2009-07-24 18:39:34 -04:00
|
|
|
|
2010-03-21 17:07:12 -04:00
|
|
|
QObject::connect(ui._showCacheTransfers_CB,SIGNAL(toggled(bool)),this,SLOT(insertTransfers())) ;
|
2009-07-24 18:39:34 -04:00
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
// Actions. Only need to be defined once.
|
|
|
|
pauseAct = new QAction(QIcon(IMAGE_PAUSE), tr("Pause"), this);
|
|
|
|
connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseFileTransfer()));
|
|
|
|
|
|
|
|
resumeAct = new QAction(QIcon(IMAGE_RESUME), tr("Resume"), this);
|
|
|
|
connect(resumeAct, SIGNAL(triggered()), this, SLOT(resumeFileTransfer()));
|
|
|
|
|
2010-07-21 19:14:10 -04:00
|
|
|
forceCheckAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Force Check" ), this );
|
|
|
|
connect( forceCheckAct , SIGNAL( triggered() ), this, SLOT( forceCheck() ) );
|
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Cancel" ), this );
|
|
|
|
connect( cancelAct , SIGNAL( triggered() ), this, SLOT( cancel() ) );
|
|
|
|
|
|
|
|
openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this);
|
|
|
|
connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openFolderTransfer()));
|
|
|
|
|
|
|
|
openfileAct = new QAction(QIcon(IMAGE_OPENFILE), tr("Open File"), this);
|
|
|
|
connect(openfileAct, SIGNAL(triggered()), this, SLOT(openTransfer()));
|
|
|
|
|
|
|
|
previewfileAct = new QAction(QIcon(IMAGE_PREVIEW), tr("Preview File"), this);
|
|
|
|
connect(previewfileAct, SIGNAL(triggered()), this, SLOT(previewTransfer()));
|
|
|
|
|
|
|
|
detailsfileAct = new QAction(QIcon(IMAGE_INFO), tr("Details..."), this);
|
|
|
|
connect(detailsfileAct, SIGNAL(triggered()), this, SLOT(showDetailsDialog()));
|
|
|
|
|
|
|
|
clearcompletedAct = new QAction(QIcon(IMAGE_CLEARCOMPLETED), tr( "Clear Completed" ), this );
|
|
|
|
connect( clearcompletedAct , SIGNAL( triggered() ), this, SLOT( clearcompleted() ) );
|
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
|
2010-11-21 16:12:35 -05:00
|
|
|
copylinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy RetroShare Link" ), this );
|
2010-03-28 16:46:45 -04:00
|
|
|
connect( copylinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) );
|
2010-11-21 16:12:35 -05:00
|
|
|
pastelinkAct = new QAction(QIcon(IMAGE_PASTELINK), tr( "Paste RetroShare Link" ), this );
|
2010-03-28 16:46:45 -04:00
|
|
|
connect( pastelinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) );
|
|
|
|
queueDownAct = new QAction(QIcon(":/images/go-down.png"), tr("Down"), this);
|
|
|
|
connect(queueDownAct, SIGNAL(triggered()), this, SLOT(priorityQueueDown()));
|
|
|
|
queueUpAct = new QAction(QIcon(":/images/go-up.png"), tr("Up"), this);
|
|
|
|
connect(queueUpAct, SIGNAL(triggered()), this, SLOT(priorityQueueUp()));
|
|
|
|
queueTopAct = new QAction(QIcon(":/images/go-top.png"), tr("Top"), this);
|
|
|
|
connect(queueTopAct, SIGNAL(triggered()), this, SLOT(priorityQueueTop()));
|
|
|
|
queueBottomAct = new QAction(QIcon(":/images/go-bottom.png"), tr("Bottom"), this);
|
|
|
|
connect(queueBottomAct, SIGNAL(triggered()), this, SLOT(priorityQueueBottom()));
|
|
|
|
chunkStreamingAct = new QAction(QIcon(IMAGE_PRIORITYAUTO), tr("Streaming"), this);
|
|
|
|
connect(chunkStreamingAct, SIGNAL(triggered()), this, SLOT(chunkStreaming()));
|
|
|
|
prioritySlowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Slower"), this);
|
|
|
|
connect(prioritySlowAct, SIGNAL(triggered()), this, SLOT(speedSlow()));
|
|
|
|
priorityMediumAct = new QAction(QIcon(IMAGE_PRIORITYNORMAL), tr("Average"), this);
|
|
|
|
connect(priorityMediumAct, SIGNAL(triggered()), this, SLOT(speedAverage()));
|
|
|
|
priorityFastAct = new QAction(QIcon(IMAGE_PRIORITYHIGH), tr("Faster"), this);
|
|
|
|
connect(priorityFastAct, SIGNAL(triggered()), this, SLOT(speedFast()));
|
|
|
|
chunkRandomAct = new QAction(QIcon(IMAGE_PRIORITYAUTO), tr("Random"), this);
|
|
|
|
connect(chunkRandomAct, SIGNAL(triggered()), this, SLOT(chunkRandom()));
|
|
|
|
playAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play" ), this );
|
|
|
|
connect( playAct , SIGNAL( triggered() ), this, SLOT( openTransfer() ) );
|
2010-09-14 19:51:55 -04:00
|
|
|
|
|
|
|
// load settings
|
|
|
|
processSettings(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TransfersDialog::~TransfersDialog()
|
|
|
|
{
|
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransfersDialog::processSettings(bool bLoad)
|
|
|
|
{
|
|
|
|
m_bProcessSettings = true;
|
|
|
|
|
|
|
|
QHeaderView *DLHeader = ui.downloadList->header () ;
|
|
|
|
QHeaderView *ULHeader = ui.uploadsList->header () ;
|
|
|
|
|
|
|
|
Settings->beginGroup(QString("TransfersDialog"));
|
|
|
|
|
|
|
|
if (bLoad) {
|
|
|
|
// load settings
|
|
|
|
|
|
|
|
// state of checks
|
|
|
|
ui._showCacheTransfers_CB->setChecked(Settings->value("showCacheTransfers", false).toBool());
|
|
|
|
|
|
|
|
// state of the lists
|
|
|
|
DLHeader->restoreState(Settings->value("downloadList").toByteArray());
|
|
|
|
ULHeader->restoreState(Settings->value("uploadList").toByteArray());
|
|
|
|
|
|
|
|
// state of splitter
|
|
|
|
ui.splitter->restoreState(Settings->value("Splitter").toByteArray());
|
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
|
|
|
|
// state of checks
|
|
|
|
Settings->setValue("showCacheTransfers", ui._showCacheTransfers_CB->isChecked());
|
|
|
|
|
|
|
|
// state of the lists
|
|
|
|
Settings->setValue("downloadList", DLHeader->saveState());
|
|
|
|
Settings->setValue("uploadList", ULHeader->saveState());
|
|
|
|
|
|
|
|
// state of splitter
|
|
|
|
Settings->setValue("Splitter", ui.splitter->saveState());
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings->endGroup();
|
|
|
|
m_bProcessSettings = false;
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2010-05-06 10:39:50 -04:00
|
|
|
// replaced by shortcut
|
|
|
|
//void TransfersDialog::keyPressEvent(QKeyEvent *e)
|
|
|
|
//{
|
|
|
|
// if(e->key() == Qt::Key_Delete)
|
|
|
|
// {
|
|
|
|
// cancel() ;
|
|
|
|
// e->accept() ;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// RsAutoUpdatePage::keyPressEvent(e) ;
|
|
|
|
//}
|
2009-05-07 18:40:57 -04:00
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
|
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
bool single = (items.size() == 1) ;
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
/* check which item is selected
|
|
|
|
* - if it is completed - play should appear in menu
|
|
|
|
*/
|
2008-12-12 16:42:44 -05:00
|
|
|
std::cerr << "TransfersDialog::downloadListCostumPopupMenu()" << std::endl;
|
2010-02-19 20:52:44 -05:00
|
|
|
|
|
|
|
FileInfo info;
|
|
|
|
|
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
2011-02-07 19:41:13 -05:00
|
|
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
2010-02-19 20:52:44 -05:00
|
|
|
break;
|
|
|
|
}
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
bool addPlayOption = false;
|
2010-02-19 20:52:44 -05:00
|
|
|
bool addOpenFileOption = false;
|
2009-11-17 07:45:06 -05:00
|
|
|
|
2010-02-19 20:52:44 -05:00
|
|
|
if (info.downloadStatus == FT_STATE_COMPLETE)
|
2010-04-10 10:56:34 -04:00
|
|
|
{
|
|
|
|
std::cerr << "Add Play Option" << std::endl;
|
2010-02-19 20:52:44 -05:00
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
addOpenFileOption = true;
|
2010-02-19 20:52:44 -05:00
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
size_t pos = info.fname.find_last_of('.');
|
2010-01-22 18:23:37 -05:00
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
/* check if the file is a media file */
|
|
|
|
if(pos != std::string::npos && misc::isPreviewable(info.fname.substr(pos + 1).c_str()))
|
|
|
|
addPlayOption = true;
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
QMenu priorityQueueMenu(tr("Move in Queue..."), this);
|
|
|
|
priorityQueueMenu.setIcon(QIcon(IMAGE_PRIORITY));
|
|
|
|
priorityQueueMenu.addAction(queueTopAct);
|
|
|
|
priorityQueueMenu.addAction(queueUpAct);
|
|
|
|
priorityQueueMenu.addAction(queueDownAct);
|
|
|
|
priorityQueueMenu.addAction(queueBottomAct);
|
2010-01-26 18:25:00 -05:00
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
QMenu prioritySpeedMenu(tr("Priority (Speed)..."), this);
|
|
|
|
prioritySpeedMenu.setIcon(QIcon(IMAGE_PRIORITY));
|
|
|
|
prioritySpeedMenu.addAction(prioritySlowAct);
|
|
|
|
prioritySpeedMenu.addAction(priorityMediumAct);
|
|
|
|
prioritySpeedMenu.addAction(priorityFastAct);
|
2010-01-26 18:25:00 -05:00
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
QMenu chunkMenu(tr("Chunk strategy"), this);
|
|
|
|
chunkMenu.setIcon(QIcon(IMAGE_PRIORITY));
|
|
|
|
chunkMenu.addAction(chunkStreamingAct);
|
|
|
|
chunkMenu.addAction(chunkRandomAct);
|
2010-01-22 18:23:37 -05:00
|
|
|
|
2010-05-14 16:55:44 -04:00
|
|
|
QMenu contextMnu( this );
|
2010-01-26 18:25:00 -05:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
if (addPlayOption)
|
|
|
|
contextMnu.addAction(playAct);
|
2010-01-26 18:25:00 -05:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
contextMnu.addSeparator();
|
|
|
|
|
|
|
|
if(!items.empty())
|
|
|
|
{
|
|
|
|
bool all_paused = true ;
|
|
|
|
bool all_downld = true ;
|
2010-01-26 18:25:00 -05:00
|
|
|
bool all_downloading = true ;
|
|
|
|
bool all_queued = true ;
|
2010-01-22 18:23:37 -05:00
|
|
|
|
|
|
|
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
|
|
|
|
|
|
|
|
for (int i = 0; i < lst.count (); i++)
|
|
|
|
{
|
2010-03-15 08:57:08 -04:00
|
|
|
if ( lst[i].column() == 0 && info.downloadStatus == FT_STATE_PAUSED )
|
2010-01-22 18:23:37 -05:00
|
|
|
all_downld = false ;
|
2010-02-22 12:45:55 -05:00
|
|
|
if ( lst[i].column() == 0 && info.downloadStatus == FT_STATE_DOWNLOADING )
|
2010-01-22 18:23:37 -05:00
|
|
|
all_paused = false ;
|
2010-01-26 18:25:00 -05:00
|
|
|
|
|
|
|
if ( lst[i].column() == 0)
|
2010-03-07 09:10:51 -05:00
|
|
|
{
|
2010-03-14 13:17:46 -04:00
|
|
|
if(info.downloadStatus == FT_STATE_QUEUED)
|
2010-01-26 18:25:00 -05:00
|
|
|
all_downloading = false ;
|
|
|
|
else
|
|
|
|
all_queued = false ;
|
2010-03-07 09:10:51 -05:00
|
|
|
}
|
2010-01-22 18:23:37 -05:00
|
|
|
}
|
|
|
|
|
2010-01-26 18:25:00 -05:00
|
|
|
if(all_downloading)
|
2010-03-28 16:46:45 -04:00
|
|
|
contextMnu.addMenu(&prioritySpeedMenu);
|
2010-01-26 18:25:00 -05:00
|
|
|
else if(all_queued)
|
2010-03-28 16:46:45 -04:00
|
|
|
contextMnu.addMenu(&priorityQueueMenu) ;
|
2010-01-26 18:25:00 -05:00
|
|
|
|
|
|
|
if(all_downloading)
|
2010-03-28 16:46:45 -04:00
|
|
|
contextMnu.addMenu( &chunkMenu);
|
2010-03-17 11:34:36 -04:00
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
if(!all_paused)
|
2010-03-15 12:22:21 -04:00
|
|
|
contextMnu.addAction( pauseAct);
|
2010-04-10 10:56:34 -04:00
|
|
|
if(!all_downld)
|
|
|
|
contextMnu.addAction( resumeAct);
|
|
|
|
|
|
|
|
if(single)
|
|
|
|
{
|
|
|
|
if(info.downloadStatus == FT_STATE_PAUSED)
|
|
|
|
contextMnu.addAction( resumeAct);
|
|
|
|
else if(info.downloadStatus != FT_STATE_COMPLETE)
|
|
|
|
contextMnu.addAction( pauseAct);
|
|
|
|
}
|
2010-03-06 18:29:47 -05:00
|
|
|
|
|
|
|
if(info.downloadStatus != FT_STATE_COMPLETE)
|
2010-07-21 19:14:10 -04:00
|
|
|
{
|
|
|
|
contextMnu.addAction( forceCheckAct);
|
2010-03-06 18:29:47 -05:00
|
|
|
contextMnu.addAction( cancelAct);
|
2010-07-21 19:14:10 -04:00
|
|
|
}
|
2010-03-06 18:29:47 -05:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
contextMnu.addSeparator();
|
|
|
|
}
|
2010-01-26 09:57:05 -05:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
if(single)
|
|
|
|
{
|
2010-03-17 11:34:36 -04:00
|
|
|
if (addOpenFileOption)
|
|
|
|
contextMnu.addAction( openfileAct);
|
2010-02-19 20:52:44 -05:00
|
|
|
|
2011-04-09 11:18:26 -04:00
|
|
|
#ifndef WIN32
|
2010-01-22 18:23:37 -05:00
|
|
|
contextMnu.addAction( previewfileAct);
|
2010-01-26 09:57:05 -05:00
|
|
|
#endif
|
2010-03-17 11:34:36 -04:00
|
|
|
contextMnu.addAction( openfolderAct);
|
2010-01-22 18:23:37 -05:00
|
|
|
contextMnu.addAction( detailsfileAct);
|
|
|
|
contextMnu.addSeparator();
|
|
|
|
}
|
2010-01-26 09:57:05 -05:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
contextMnu.addAction( clearcompletedAct);
|
|
|
|
contextMnu.addSeparator();
|
2010-04-10 10:56:34 -04:00
|
|
|
|
|
|
|
if(!items.empty())
|
2010-03-10 16:38:26 -05:00
|
|
|
contextMnu.addAction( copylinkAct);
|
2010-04-10 10:56:34 -04:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE)) {
|
|
|
|
pastelinkAct->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
pastelinkAct->setDisabled(true);
|
|
|
|
}
|
|
|
|
contextMnu.addAction( pastelinkAct);
|
2010-03-15 08:57:08 -04:00
|
|
|
|
2010-01-22 18:23:37 -05:00
|
|
|
contextMnu.addSeparator();
|
|
|
|
|
2010-05-14 16:55:44 -04:00
|
|
|
contextMnu.exec(QCursor::pos());
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2010-03-07 09:10:51 -05:00
|
|
|
int TransfersDialog::addItem(const QString&, const QString& name, const QString& coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed,
|
2010-03-01 17:47:48 -05:00
|
|
|
const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining, qlonglong downloadtime)
|
2008-12-12 16:42:44 -05:00
|
|
|
{
|
2010-09-14 19:51:55 -04:00
|
|
|
int rowCount = DLListModel->rowCount();
|
2010-07-29 17:07:07 -04:00
|
|
|
int row ;
|
2010-09-14 19:51:55 -04:00
|
|
|
for(row=0;row<rowCount;++row)
|
2011-02-07 19:41:13 -05:00
|
|
|
if(DLListModel->item(row,ID)->data(Qt::DisplayRole).toString() == coreID)
|
2010-07-29 17:07:07 -04:00
|
|
|
break ;
|
|
|
|
|
2010-09-14 19:51:55 -04:00
|
|
|
if(row >= rowCount )
|
2010-07-29 17:07:07 -04:00
|
|
|
{
|
2010-09-14 19:51:55 -04:00
|
|
|
row = rowCount;
|
2010-07-29 17:07:07 -04:00
|
|
|
DLListModel->insertRow(row);
|
2010-10-04 16:15:52 -04:00
|
|
|
|
|
|
|
// change progress column to own class for sorting
|
2011-02-07 19:41:13 -05:00
|
|
|
DLListModel->setItem(row, PROGRESS, new ProgressItem (NULL));
|
2010-07-29 17:07:07 -04:00
|
|
|
}
|
2010-02-16 21:10:25 -05:00
|
|
|
|
2010-07-29 17:07:07 -04:00
|
|
|
DLListModel->setData(DLListModel->index(row, NAME), QVariant(name));
|
|
|
|
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)fileSize));
|
|
|
|
DLListModel->setData(DLListModel->index(row, COMPLETED), QVariant((qlonglong)completed));
|
|
|
|
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)dlspeed));
|
|
|
|
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant::fromValue(pinfo));
|
|
|
|
DLListModel->setData(DLListModel->index(row, SOURCES), QVariant((QString)sources));
|
|
|
|
DLListModel->setData(DLListModel->index(row, STATUS), QVariant((QString)status));
|
|
|
|
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((QString)priority));
|
|
|
|
DLListModel->setData(DLListModel->index(row, REMAINING), QVariant((qlonglong)remaining));
|
|
|
|
DLListModel->setData(DLListModel->index(row, DOWNLOADTIME), QVariant((qlonglong)downloadtime));
|
|
|
|
DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID));
|
|
|
|
|
|
|
|
QString ext = QFileInfo(name).suffix();
|
|
|
|
DLListModel->setData(DLListModel->index(row,NAME), getIconFromExtension(ext), Qt::DecorationRole);
|
|
|
|
|
|
|
|
return row ;
|
2010-07-27 12:05:21 -04:00
|
|
|
}
|
|
|
|
|
2010-12-09 15:49:41 -05:00
|
|
|
QIcon TransfersDialog::getIconFromExtension(QString ext)
|
2010-07-27 12:05:21 -04:00
|
|
|
{
|
2010-12-09 15:49:41 -05:00
|
|
|
ext = ext.toLower();
|
|
|
|
if (ext == "jpg" || ext == "jpeg" || ext == "tif" || ext == "tiff" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg")
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypePicture.png")) ;
|
2010-12-09 15:49:41 -05:00
|
|
|
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "divx" || ext == "ts"
|
2010-07-27 12:05:21 -04:00
|
|
|
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "asf" || ext == "xvid"
|
2010-12-09 15:49:41 -05:00
|
|
|
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp" || ext == "ogm")
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeVideo.png")) ;
|
2010-12-09 15:49:41 -05:00
|
|
|
else if (ext == "ogg" || ext == "mp3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma" || ext == "m4a" || ext == "flac")
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeAudio.png")) ;
|
|
|
|
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z" || ext == "msi"
|
|
|
|
|| ext == "rar" || ext == "rpm" || ext == "ace" || ext == "jar" || ext == "tgz" || ext == "lha"
|
2010-12-09 15:49:41 -05:00
|
|
|
|| ext == "cab" || ext == "cbz"|| ext == "cbr" || ext == "alz" || ext == "sit" || ext == "arj" || ext == "deb")
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeArchive.png")) ;
|
|
|
|
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|
|
|
|
|| ext == "exe" || ext == "js" || ext == "pif"
|
2010-12-09 15:49:41 -05:00
|
|
|
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeProgram.png")) ;
|
2010-12-09 15:49:41 -05:00
|
|
|
else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" )
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeCDImage.png")) ;
|
2010-12-09 15:49:41 -05:00
|
|
|
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
|
|
|
|
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml"
|
2010-12-09 15:49:41 -05:00
|
|
|
|| ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" )
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
|
2010-12-09 15:49:41 -05:00
|
|
|
else if (ext == "html" || ext == "htm" || ext == "php")
|
2010-07-27 12:05:21 -04:00
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
|
|
|
|
else
|
|
|
|
return QIcon(QString::fromUtf8(":/images/FileTypeAny.png")) ;
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
int TransfersDialog::addPeerToItem(int row, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo)
|
2009-05-20 18:06:20 -04:00
|
|
|
{
|
|
|
|
QStandardItem *dlItem = DLListModel->item(row);
|
2010-03-07 09:10:51 -05:00
|
|
|
if (!dlItem) return -1;
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-02-16 21:10:25 -05:00
|
|
|
//try to find the item
|
|
|
|
int childRow = -1;
|
|
|
|
int count = 0;
|
2010-03-06 18:29:47 -05:00
|
|
|
QStandardItem* childId=NULL ;
|
2009-05-27 18:21:09 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
for(count=0; (childId = dlItem->child(count, ID)) != NULL;++count)
|
|
|
|
if (childId->data(Qt::DisplayRole).toString() == coreID)
|
|
|
|
{
|
2010-02-16 21:10:25 -05:00
|
|
|
childRow = count;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-07 09:10:51 -05:00
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
|
|
|
|
QStandardItem *si1 = NULL,*si7=NULL;
|
|
|
|
|
|
|
|
if (childRow == -1)
|
|
|
|
{
|
2010-02-16 21:10:25 -05:00
|
|
|
//set this false if you want to expand on double click
|
|
|
|
dlItem->setEditable(false);
|
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
QHeaderView *header = ui.downloadList->header ();
|
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
QStandardItem *i1 = new QStandardItem();
|
2011-02-07 19:41:13 -05:00
|
|
|
QStandardItem *i2 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i3 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i4 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i5 = new ProgressItem(header);
|
|
|
|
QStandardItem *i6 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i7 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i8 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i9 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i10 = new SortByNameItem(header);
|
|
|
|
QStandardItem *i11 = new SortByNameItem(header);
|
2010-04-10 10:56:34 -04:00
|
|
|
|
|
|
|
si1 = i1 ;
|
|
|
|
si7 = i7 ;
|
|
|
|
|
|
|
|
QList<QStandardItem *> items;
|
|
|
|
i1->setData(QVariant((QString)" "+name), Qt::DisplayRole);
|
|
|
|
i2->setData(QVariant(QString()), Qt::DisplayRole);
|
|
|
|
i3->setData(QVariant(QString()), Qt::DisplayRole);
|
|
|
|
i4->setData(QVariant((double)dlspeed), Qt::DisplayRole);
|
|
|
|
i5->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole);
|
|
|
|
i6->setData(QVariant(QString()), Qt::DisplayRole);
|
|
|
|
|
|
|
|
i8->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority
|
|
|
|
i9->setData(QVariant(QString()), Qt::DisplayRole);
|
|
|
|
i10->setData(QVariant(QString()), Qt::DisplayRole);
|
|
|
|
i11->setData(QVariant((QString)coreID), Qt::DisplayRole);
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-02-16 21:10:25 -05:00
|
|
|
items.append(i1);
|
|
|
|
items.append(i2);
|
|
|
|
items.append(i3);
|
|
|
|
items.append(i4);
|
|
|
|
items.append(i5);
|
|
|
|
items.append(i6);
|
|
|
|
items.append(i7);
|
|
|
|
items.append(i8);
|
|
|
|
items.append(i9);
|
|
|
|
items.append(i10);
|
2010-03-06 18:29:47 -05:00
|
|
|
items.append(i11);
|
2010-02-16 21:10:25 -05:00
|
|
|
dlItem->appendRow(items);
|
2010-03-07 09:10:51 -05:00
|
|
|
|
|
|
|
childRow = dlItem->rowCount()-1 ;
|
2010-04-10 10:56:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-16 21:10:25 -05:00
|
|
|
//just update the child (peer)
|
|
|
|
dlItem->child(childRow, DLSPEED)->setData(QVariant((double)dlspeed), Qt::DisplayRole);
|
2010-02-18 17:30:36 -05:00
|
|
|
dlItem->child(childRow, PROGRESS)->setData(QVariant::fromValue(peerInfo), Qt::DisplayRole);
|
2010-04-10 10:56:34 -04:00
|
|
|
|
|
|
|
si1 = dlItem->child(childRow,NAME) ;
|
|
|
|
si7 = dlItem->child(childRow, STATUS) ;
|
2010-02-16 21:10:25 -05:00
|
|
|
}
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
QString sstatus;
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case FT_STATE_FAILED: si7->setData(QVariant(tr("Failed"))) ;
|
|
|
|
si1->setData(QIcon(QString::fromUtf8(":/images/Client1.png")), Qt::DecorationRole);
|
|
|
|
break ;
|
|
|
|
|
|
|
|
case FT_STATE_OKAY: si7->setData(QVariant(tr("Okay")));
|
|
|
|
si1->setData(QIcon(QString::fromUtf8(":/images/Client2.png")), Qt::DecorationRole);
|
|
|
|
break ;
|
|
|
|
|
|
|
|
case FT_STATE_WAITING: si7->setData(QVariant(tr("")));
|
|
|
|
si1->setData(QIcon(QString::fromUtf8(":/images/Client3.png")), Qt::DecorationRole);
|
|
|
|
break ;
|
|
|
|
|
|
|
|
case FT_STATE_DOWNLOADING: si7->setData(QVariant(tr("Transferring")));
|
|
|
|
si1->setData(QIcon(QString::fromUtf8(":/images/Client0.png")), Qt::DecorationRole);
|
|
|
|
break ;
|
|
|
|
|
|
|
|
case FT_STATE_COMPLETE: si7->setData(QVariant(tr("Complete")));
|
|
|
|
si1->setData(QIcon(QString::fromUtf8(":/images/Client0.png")), Qt::DecorationRole);
|
|
|
|
break ;
|
|
|
|
|
|
|
|
default: si7->setData(QVariant(tr("")));
|
|
|
|
break ;
|
|
|
|
si1->setData(QIcon(QString::fromUtf8(":/images/Client4.png")), Qt::DecorationRole);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return childRow;
|
2009-05-20 18:06:20 -04:00
|
|
|
}
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-07-27 12:05:21 -04:00
|
|
|
int TransfersDialog::addUploadItem( const QString&, const QString& name, const QString& coreID,
|
|
|
|
qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed,
|
|
|
|
const QString& source, const QString& peer_id, const QString& status, qlonglong completed, qlonglong)
|
2008-12-12 16:42:44 -05:00
|
|
|
{
|
2010-07-27 12:05:21 -04:00
|
|
|
// Find items does not work reliably, because it (apparently) needs Qt to flush pending events to work, so we can't call it
|
|
|
|
// on a table that was just filled in.
|
|
|
|
//
|
|
|
|
int row ;
|
|
|
|
for(row=0;row<ULListModel->rowCount();++row)
|
|
|
|
if(ULListModel->item(row,UUSERID)->data(Qt::EditRole).toString() == peer_id && ULListModel->item(row,UHASH)->data(Qt::EditRole).toString() == coreID)
|
|
|
|
break ;
|
2010-02-16 21:10:25 -05:00
|
|
|
|
2010-07-27 12:05:21 -04:00
|
|
|
if(row >= ULListModel->rowCount() )
|
|
|
|
{
|
|
|
|
row = ULListModel->rowCount();
|
|
|
|
ULListModel->insertRow(row);
|
2010-10-04 16:15:52 -04:00
|
|
|
|
|
|
|
// change progress column to own class for sorting
|
2011-02-07 19:41:13 -05:00
|
|
|
ULListModel->setItem(row, UPROGRESS, new ProgressItem(NULL));
|
2010-07-27 12:05:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ULListModel->setData(ULListModel->index(row, UNAME), QVariant((QString)" "+name), Qt::DisplayRole);
|
|
|
|
ULListModel->setData(ULListModel->index(row, USIZE), QVariant((qlonglong)fileSize));
|
|
|
|
ULListModel->setData(ULListModel->index(row, UTRANSFERRED), QVariant((qlonglong)completed));
|
|
|
|
ULListModel->setData(ULListModel->index(row, ULSPEED), QVariant((double)dlspeed));
|
|
|
|
ULListModel->setData(ULListModel->index(row, UPROGRESS), QVariant::fromValue(pinfo));
|
|
|
|
ULListModel->setData(ULListModel->index(row, USTATUS), QVariant((QString)status));
|
|
|
|
ULListModel->setData(ULListModel->index(row, USERNAME), QVariant((QString)source));
|
|
|
|
ULListModel->setData(ULListModel->index(row, UHASH), QVariant((QString)coreID));
|
|
|
|
ULListModel->setData(ULListModel->index(row, UUSERID), QVariant((QString)peer_id));
|
2010-06-15 07:34:58 -04:00
|
|
|
|
2010-07-27 12:05:21 -04:00
|
|
|
QString ext = QFileInfo(name).suffix();
|
|
|
|
ULListModel->setData(ULListModel->index(row,UNAME), getIconFromExtension(ext), Qt::DecorationRole);
|
2010-02-16 21:10:25 -05:00
|
|
|
|
2010-07-27 12:05:21 -04:00
|
|
|
return row;
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
//void TransfersDialog::delItem(int row)
|
|
|
|
//{
|
|
|
|
// DLListModel->removeRow(row, QModelIndex());
|
|
|
|
//}
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
//void TransfersDialog::delUploadItem(int row)
|
|
|
|
//{
|
|
|
|
// ULListModel->removeRow(row, QModelIndex());
|
|
|
|
//}
|
2008-12-12 16:42:44 -05:00
|
|
|
|
|
|
|
/* get the list of Transfers from the RsIface. **/
|
2009-11-17 07:45:06 -05:00
|
|
|
void TransfersDialog::updateDisplay()
|
|
|
|
{
|
|
|
|
insertTransfers();
|
2010-05-03 18:44:53 -04:00
|
|
|
updateDetailsDialog ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void QListDelete (const QList <QStandardItem*> &List)
|
|
|
|
{
|
2010-10-04 16:15:52 -04:00
|
|
|
qDeleteAll (List);
|
2009-11-17 07:45:06 -05:00
|
|
|
}
|
2010-05-03 18:44:53 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
void TransfersDialog::insertTransfers()
|
|
|
|
{
|
2010-09-14 07:37:50 -04:00
|
|
|
/* disable for performance issues, enable after insert all transfers */
|
|
|
|
ui.downloadList->setSortingEnabled(false);
|
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
/* get the download lists */
|
2010-02-16 21:10:25 -05:00
|
|
|
std::list<std::string> downHashes;
|
|
|
|
rsFiles->FileDownloads(downHashes);
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
// std::list<DwlDetails> dwlDetails;
|
|
|
|
// rsFiles->getDwlDetails(dwlDetails);
|
|
|
|
|
2010-09-14 19:51:55 -04:00
|
|
|
bool showCacheTransfers = ui._showCacheTransfers_CB->isChecked();
|
|
|
|
|
|
|
|
/* get online peers only once */
|
|
|
|
std::list<std::string> onlineIds;
|
|
|
|
rsPeers->getOnlineList(onlineIds);
|
|
|
|
|
|
|
|
/* get also only once */
|
|
|
|
std::map<std::string, std::string> versions;
|
|
|
|
bool retv = rsDisc->getDiscVersions(versions);
|
|
|
|
|
2010-03-21 17:07:12 -04:00
|
|
|
std::set<std::string> used_hashes ;
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
// clear all source peers.
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
std::list<std::string>::iterator it;
|
2010-03-21 17:07:12 -04:00
|
|
|
for (it = downHashes.begin(); it != downHashes.end(); it++)
|
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
FileInfo info;
|
|
|
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) {
|
|
|
|
//if file transfer is a cache file index file, don't show it
|
|
|
|
continue;
|
|
|
|
}
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-10-16 11:21:37 -04:00
|
|
|
if((info.flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers)
|
2010-03-06 18:29:47 -05:00
|
|
|
continue;
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
QString fileName = QString::fromUtf8(info.fname.c_str());
|
|
|
|
QString fileHash = QString::fromStdString(info.hash);
|
|
|
|
qlonglong fileSize = info.size;
|
2010-12-26 05:58:02 -05:00
|
|
|
double fileDlspeed = (info.downloadStatus==FT_STATE_DOWNLOADING)?(info.tfRate * 1024.0):0.0;
|
2010-03-06 18:29:47 -05:00
|
|
|
|
|
|
|
/* get the sources (number of online peers) */
|
2011-02-03 17:26:54 -05:00
|
|
|
int active = 0;
|
2010-03-06 18:29:47 -05:00
|
|
|
std::list<TransferInfo>::iterator pit;
|
2011-02-03 17:26:54 -05:00
|
|
|
for (pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
|
|
|
if(pit->tfRate > 0 && info.downloadStatus==FT_STATE_DOWNLOADING)
|
|
|
|
active++;
|
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
QString sources = QString("%1 (%2)").arg(active).arg(info.peers.size());
|
2010-03-06 18:29:47 -05:00
|
|
|
|
|
|
|
QString status;
|
|
|
|
switch (info.downloadStatus) {
|
|
|
|
case FT_STATE_FAILED: status = tr("Failed"); break;
|
|
|
|
case FT_STATE_OKAY: status = tr("Okay"); break;
|
|
|
|
case FT_STATE_WAITING: status = tr("Waiting"); break;
|
|
|
|
case FT_STATE_DOWNLOADING: status = tr("Downloading"); break;
|
|
|
|
case FT_STATE_COMPLETE: status = tr("Complete"); break;
|
|
|
|
case FT_STATE_QUEUED: status = tr("Queued"); break;
|
2010-03-15 08:57:08 -04:00
|
|
|
case FT_STATE_PAUSED: status = tr("Paused"); break;
|
2010-07-06 01:04:11 -04:00
|
|
|
case FT_STATE_CHECKING_HASH:status = tr("Checking..."); break;
|
2010-03-06 18:29:47 -05:00
|
|
|
default: status = tr("Unknown"); break;
|
|
|
|
}
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
QString priority;
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
if(info.downloadStatus == FT_STATE_QUEUED)
|
|
|
|
priority = QString::number(info.queue_position) ;
|
|
|
|
else
|
|
|
|
switch (info.priority)
|
|
|
|
{
|
|
|
|
case SPEED_LOW: priority = tr("Slower");break;
|
|
|
|
case SPEED_NORMAL: priority = tr("Average");break;
|
|
|
|
case SPEED_HIGH: priority = tr("Faster");break;
|
|
|
|
default: priority = tr("Average");break;
|
|
|
|
}
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
qlonglong completed = info.transfered;
|
|
|
|
qlonglong remaining = info.size - info.transfered;
|
|
|
|
qlonglong downloadtime = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
FileChunksInfo fcinfo ;
|
|
|
|
if(!rsFiles->FileDownloadChunksDetails(*it,fcinfo))
|
|
|
|
continue ;
|
2009-05-20 18:06:20 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
FileProgressInfo pinfo ;
|
|
|
|
pinfo.cmap = fcinfo.chunks ;
|
|
|
|
pinfo.type = FileProgressInfo::DOWNLOAD_LINE ;
|
2010-03-28 16:46:45 -04:00
|
|
|
pinfo.progress = (info.size==0)?0:(completed*100.0/info.size) ;
|
2010-03-06 18:29:47 -05:00
|
|
|
pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ;
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-12-26 05:58:02 -05:00
|
|
|
for(uint32_t i=0;i<fcinfo.active_chunks.size();++i)
|
|
|
|
pinfo.chunks_in_progress.push_back(fcinfo.active_chunks[i].first) ;
|
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime);
|
2010-03-21 17:07:12 -04:00
|
|
|
used_hashes.insert(info.hash) ;
|
2008-12-12 16:42:44 -05:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
std::map<std::string, std::string>::iterator vit;
|
|
|
|
|
2010-03-07 09:10:51 -05:00
|
|
|
std::set<int> used_rows ;
|
|
|
|
|
2010-03-17 11:34:36 -04:00
|
|
|
if(info.downloadStatus != FT_STATE_COMPLETE)
|
2010-03-07 09:10:51 -05:00
|
|
|
for (pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
QString peerName = getPeerName(pit->peerId);
|
|
|
|
//unique combination: fileHash + peerId, variant: hash + peerName (too long)
|
|
|
|
QString hashFileAndPeerId = fileHash + QString::fromStdString(pit->peerId);
|
|
|
|
QString version;
|
|
|
|
if (retv && versions.end() != (vit = versions.find(pit->peerId))) {
|
|
|
|
version = tr("version: ") + QString::fromStdString(vit->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
double peerDlspeed = 0;
|
2010-03-17 11:34:36 -04:00
|
|
|
if ((uint32_t)pit->status == FT_STATE_DOWNLOADING && info.downloadStatus != FT_STATE_PAUSED && info.downloadStatus != FT_STATE_COMPLETE)
|
2010-03-06 18:29:47 -05:00
|
|
|
peerDlspeed = pit->tfRate * 1024.0;
|
|
|
|
|
|
|
|
FileProgressInfo peerpinfo ;
|
|
|
|
peerpinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId];
|
|
|
|
peerpinfo.type = FileProgressInfo::DOWNLOAD_SOURCE ;
|
|
|
|
peerpinfo.progress = 0.0 ; // we don't display completion for sources.
|
|
|
|
peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size();
|
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
int row_id = addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, pit->status, peerpinfo);
|
2010-03-07 09:10:51 -05:00
|
|
|
|
|
|
|
used_rows.insert(row_id) ;
|
2010-03-06 18:29:47 -05:00
|
|
|
}
|
2010-03-07 09:10:51 -05:00
|
|
|
|
|
|
|
QStandardItem *dlItem = DLListModel->item(addedRow);
|
|
|
|
|
|
|
|
// This is not optimal, but we deal with a small number of elements. The reverse order is really important,
|
|
|
|
// because rows after the deleted rows change positions !
|
|
|
|
//
|
|
|
|
for(int r=dlItem->rowCount()-1;r>=0;--r)
|
|
|
|
if(used_rows.find(r) == used_rows.end())
|
2010-05-03 18:44:53 -04:00
|
|
|
QListDelete (dlItem->takeRow(r)) ;
|
2010-03-06 18:29:47 -05:00
|
|
|
}
|
2011-02-07 19:41:13 -05:00
|
|
|
|
2010-03-21 17:07:12 -04:00
|
|
|
// remove hashes that where not shown
|
|
|
|
//first clean the model in case some files are not download anymore
|
|
|
|
//remove items that are not fiends anymore
|
|
|
|
int removeIndex = 0;
|
2011-02-19 19:59:47 -05:00
|
|
|
int rowCount = DLListModel->rowCount();
|
|
|
|
while (removeIndex < rowCount)
|
2010-03-21 17:07:12 -04:00
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
std::string hash = DLListModel->item(removeIndex, ID)->data(Qt::DisplayRole).toString().toStdString();
|
2010-03-06 18:29:47 -05:00
|
|
|
|
2011-02-19 19:59:47 -05:00
|
|
|
if(used_hashes.find(hash) == used_hashes.end()) {
|
2010-05-03 18:44:53 -04:00
|
|
|
QListDelete (DLListModel->takeRow(removeIndex));
|
2011-02-19 19:59:47 -05:00
|
|
|
rowCount = DLListModel->rowCount();
|
|
|
|
} else
|
2010-03-21 17:07:12 -04:00
|
|
|
removeIndex++;
|
|
|
|
}
|
2010-09-14 07:37:50 -04:00
|
|
|
|
2010-10-04 16:15:52 -04:00
|
|
|
ui.downloadList->setSortingEnabled(true);
|
2010-09-14 07:37:50 -04:00
|
|
|
|
2010-10-04 16:15:52 -04:00
|
|
|
ui.uploadsList->setSortingEnabled(false);
|
2010-03-06 18:29:47 -05:00
|
|
|
|
2010-03-21 17:07:12 -04:00
|
|
|
// Now show upload hashes
|
|
|
|
//
|
2010-03-06 18:29:47 -05:00
|
|
|
std::list<std::string> upHashes;
|
|
|
|
rsFiles->FileUploads(upHashes);
|
|
|
|
|
2010-09-14 19:51:55 -04:00
|
|
|
std::string ownId = rsPeers->getOwnId();
|
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
used_hashes.clear() ;
|
|
|
|
|
|
|
|
for(it = upHashes.begin(); it != upHashes.end(); it++)
|
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
FileInfo info;
|
2010-04-10 10:56:34 -04:00
|
|
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info))
|
2010-03-06 18:29:47 -05:00
|
|
|
continue;
|
2010-04-10 10:56:34 -04:00
|
|
|
|
2010-10-16 11:21:37 -04:00
|
|
|
if((info.flags & RS_FILE_HINTS_CACHE) && showCacheTransfers)
|
2010-03-06 18:29:47 -05:00
|
|
|
continue ;
|
|
|
|
|
|
|
|
std::list<TransferInfo>::iterator pit;
|
2010-04-10 10:56:34 -04:00
|
|
|
for(pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
|
|
|
{
|
2010-09-14 19:51:55 -04:00
|
|
|
if (pit->peerId == ownId) //don't display transfer to ourselves
|
2010-03-06 18:29:47 -05:00
|
|
|
continue ;
|
|
|
|
|
|
|
|
QString fileHash = QString::fromStdString(info.hash);
|
|
|
|
QString fileName = QString::fromUtf8(info.fname.c_str());
|
2010-07-27 12:05:21 -04:00
|
|
|
QString source = getPeerName(pit->peerId);
|
2010-03-06 18:29:47 -05:00
|
|
|
|
|
|
|
QString status;
|
|
|
|
switch(pit->status)
|
|
|
|
{
|
|
|
|
case FT_STATE_FAILED: status = tr("Failed"); break;
|
|
|
|
case FT_STATE_OKAY: status = tr("Okay"); break;
|
|
|
|
case FT_STATE_WAITING: status = tr("Waiting"); break;
|
|
|
|
case FT_STATE_DOWNLOADING: status = tr("Uploading"); break;
|
|
|
|
case FT_STATE_COMPLETE: status = tr("Complete"); break;
|
|
|
|
default: status = tr("Complete"); break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
FileProgressInfo pinfo ;
|
|
|
|
|
|
|
|
if(!rsFiles->FileUploadChunksDetails(*it,pit->peerId,pinfo.cmap) )
|
|
|
|
continue ;
|
|
|
|
|
|
|
|
double dlspeed = pit->tfRate * 1024.0;
|
|
|
|
qlonglong fileSize = info.size;
|
2010-07-27 12:05:21 -04:00
|
|
|
qlonglong completed = pit->transfered;
|
|
|
|
double progress = (info.size > 0)?(pit->transfered * 100.0 / info.size):0.0;
|
|
|
|
qlonglong remaining = (info.size - pit->transfered) / (pit->tfRate * 1024.0);
|
2010-03-06 18:29:47 -05:00
|
|
|
|
|
|
|
// Estimate the completion. We need something more accurate, meaning that we need to
|
|
|
|
// transmit the completion info.
|
|
|
|
//
|
|
|
|
uint32_t chunk_size = 1024*1024 ;
|
|
|
|
uint32_t nb_chunks = (uint32_t)(info.size / (uint64_t)(chunk_size) ) ;
|
|
|
|
if((info.size % (uint64_t)chunk_size) != 0)
|
|
|
|
++nb_chunks ;
|
|
|
|
|
|
|
|
uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ;
|
2010-03-28 16:46:45 -04:00
|
|
|
pinfo.type = FileProgressInfo::UPLOAD_LINE ;
|
2010-03-06 18:29:47 -05:00
|
|
|
pinfo.nb_chunks = pinfo.cmap._map.empty()?0:nb_chunks ;
|
|
|
|
|
2011-06-23 14:54:49 -04:00
|
|
|
if(filled_chunks > 0 && nb_chunks > 0)
|
|
|
|
{
|
|
|
|
pinfo.progress = filled_chunks*100.0/nb_chunks ;
|
|
|
|
completed = std::min(info.size,((uint64_t)filled_chunks)*chunk_size) ; // we use min, because the last chunk might be smaller than chunk_size.
|
2010-03-28 16:46:45 -04:00
|
|
|
}
|
|
|
|
else
|
2011-06-23 14:54:49 -04:00
|
|
|
{
|
|
|
|
completed = pit->transfered % chunk_size ; // use the position with respect to last request.
|
|
|
|
pinfo.progress = (info.size>0)?((pit->transfered % chunk_size)*100.0/info.size):0 ;
|
|
|
|
}
|
2010-03-06 18:29:47 -05:00
|
|
|
|
2010-07-27 12:05:21 -04:00
|
|
|
addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, source,QString::fromStdString(pit->peerId), status, completed, remaining);
|
2010-04-10 10:56:34 -04:00
|
|
|
|
2010-07-27 12:05:21 -04:00
|
|
|
used_hashes.insert(fileHash.toStdString() + pit->peerId) ;
|
2010-03-06 18:29:47 -05:00
|
|
|
}
|
2010-04-10 10:56:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove hashes that where not shown
|
|
|
|
//first clean the model in case some files are not download anymore
|
|
|
|
//remove items that are not fiends anymore
|
|
|
|
removeIndex = 0;
|
2011-02-19 19:59:47 -05:00
|
|
|
rowCount = ULListModel->rowCount();
|
|
|
|
while (removeIndex < rowCount)
|
2010-04-10 10:56:34 -04:00
|
|
|
{
|
|
|
|
std::string hash = ULListModel->item(removeIndex, UHASH)->data(Qt::EditRole).toString().toStdString();
|
2010-07-27 12:05:21 -04:00
|
|
|
std::string peer = ULListModel->item(removeIndex, UUSERID)->data(Qt::EditRole).toString().toStdString();
|
2010-03-06 18:29:47 -05:00
|
|
|
|
2011-02-19 19:59:47 -05:00
|
|
|
if(used_hashes.find(hash + peer) == used_hashes.end()) {
|
2010-05-03 18:44:53 -04:00
|
|
|
QListDelete (ULListModel->takeRow(removeIndex));
|
2011-02-19 19:59:47 -05:00
|
|
|
rowCount = ULListModel->rowCount();
|
|
|
|
} else
|
2010-04-10 10:56:34 -04:00
|
|
|
removeIndex++;
|
2010-03-06 18:29:47 -05:00
|
|
|
}
|
2010-04-10 10:56:34 -04:00
|
|
|
|
2010-10-04 16:15:52 -04:00
|
|
|
ui.uploadsList->setSortingEnabled(true);
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2009-06-03 14:47:14 -04:00
|
|
|
QString TransfersDialog::getPeerName(const std::string& id) const
|
|
|
|
{
|
2011-07-17 19:07:29 -04:00
|
|
|
QString res = QString::fromUtf8(rsPeers->getPeerName(id).c_str()) ;
|
2009-06-03 14:47:14 -04:00
|
|
|
|
|
|
|
// This is because turtle tunnels have no name (I didn't want to bother with
|
|
|
|
// connect mgr). In such a case their id can suitably hold for a name.
|
|
|
|
//
|
|
|
|
if(res == "")
|
|
|
|
return QString::fromStdString(id) ;
|
|
|
|
else
|
|
|
|
return res ;
|
|
|
|
}
|
|
|
|
|
2010-07-21 19:14:10 -04:00
|
|
|
void TransfersDialog::forceCheck()
|
|
|
|
{
|
|
|
|
if (!controlTransferFile(RS_FILE_CTRL_FORCE_CHECK))
|
|
|
|
std::cerr << "resumeFileTransfer(): can't force check file transfer" << std::endl;
|
|
|
|
}
|
2011-02-07 19:41:13 -05:00
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
void TransfersDialog::cancel()
|
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
QString queryWrn2;
|
|
|
|
queryWrn2.clear();
|
|
|
|
queryWrn2.append(tr("Are you sure that you want to cancel and delete these files?"));
|
|
|
|
|
|
|
|
if ((QMessageBox::question(this, tr("RetroShare"),queryWrn2,QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)) == QMessageBox::No) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rsFiles->FileCancel(*it);
|
|
|
|
}
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
//void TransfersDialog::handleDownloadRequest(const QString& url)
|
|
|
|
//{
|
|
|
|
// RetroShareLink link(url);
|
|
|
|
//
|
|
|
|
// if (!link.valid ())
|
|
|
|
// {
|
|
|
|
// QMessageBox::critical(NULL,"Link error","This link could not be parsed. This is a bug. Please contact the developers.") ;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// QVector<RetroShareLinkData> linkList;
|
|
|
|
// analyzer.getFileInformation (linkList);
|
|
|
|
//
|
|
|
|
// std::list<std::string> srcIds;
|
|
|
|
//
|
|
|
|
// for (int i = 0, n = linkList.size (); i < n; ++i)
|
|
|
|
// {
|
|
|
|
// const RetroShareLinkData& linkData = linkList[i];
|
|
|
|
//
|
|
|
|
// rsFiles->FileRequest (linkData.getName ().toStdString (), linkData.getHash ().toStdString (),
|
|
|
|
// linkData.getSize ().toInt (), "", 0, srcIds);
|
|
|
|
// }
|
|
|
|
//}
|
2009-05-18 10:23:55 -04:00
|
|
|
|
|
|
|
void TransfersDialog::copyLink ()
|
|
|
|
{
|
2010-04-10 10:56:34 -04:00
|
|
|
std::vector<RetroShareLink> links ;
|
2009-05-18 10:23:55 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2009-05-18 10:23:55 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
|
|
|
FileInfo info;
|
|
|
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) {
|
|
|
|
continue;
|
2010-03-10 16:38:26 -05:00
|
|
|
}
|
2011-02-07 19:41:13 -05:00
|
|
|
|
2011-05-04 06:22:49 -04:00
|
|
|
RetroShareLink link;
|
2011-05-08 19:11:27 -04:00
|
|
|
if (link.createFile(QString::fromUtf8(info.fname.c_str()), info.size, QString::fromStdString(info.hash))) {
|
2011-05-04 06:22:49 -04:00
|
|
|
links.push_back(link) ;
|
|
|
|
}
|
2011-02-07 19:41:13 -05:00
|
|
|
}
|
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
RSLinkClipboard::copyLinks(links) ;
|
2009-05-18 10:23:55 -04:00
|
|
|
}
|
|
|
|
|
2010-01-05 19:10:15 -05:00
|
|
|
void TransfersDialog::showDetailsDialog()
|
|
|
|
{
|
2010-05-03 18:44:53 -04:00
|
|
|
if (detailsdlg == NULL) {
|
|
|
|
// create window
|
|
|
|
detailsdlg = new DetailsDialog ();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDetailsDialog ();
|
|
|
|
|
|
|
|
detailsdlg->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransfersDialog::updateDetailsDialog()
|
|
|
|
{
|
|
|
|
if (detailsdlg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-26 09:57:05 -05:00
|
|
|
std::string file_hash ;
|
2010-05-03 18:44:53 -04:00
|
|
|
QString fhash;
|
|
|
|
QString fsize;
|
|
|
|
QString fname;
|
|
|
|
QString fstatus;
|
|
|
|
QString fpriority;
|
|
|
|
QString fsources;
|
|
|
|
|
|
|
|
qulonglong filesize = 0;
|
|
|
|
double fdatarate = 0;
|
|
|
|
qulonglong fcompleted = 0;
|
|
|
|
qulonglong fremaining = 0;
|
|
|
|
|
|
|
|
qulonglong fdownloadtime = 0;
|
2010-01-05 19:10:15 -05:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<int> rows;
|
|
|
|
std::set<int>::iterator it;
|
|
|
|
getSelectedItems(NULL, &rows);
|
2010-05-03 18:44:53 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
if (rows.size()) {
|
|
|
|
int row = *rows.begin();
|
2010-05-03 18:44:53 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
fhash = getID(row, DLListModel);
|
|
|
|
fsize = getFileSize(row, DLListModel);
|
|
|
|
fname = getFileName(row, DLListModel);
|
|
|
|
fstatus = getStatus(row, DLListModel);
|
|
|
|
fpriority = getPriority(row, DLListModel);
|
|
|
|
fsources = getSources(row, DLListModel);
|
2010-05-03 18:44:53 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
filesize = getFileSize(row, DLListModel);
|
|
|
|
fdatarate = getSpeed(row, DLListModel);
|
|
|
|
fcompleted = getTransfered(row, DLListModel);
|
|
|
|
fremaining = getRemainingTime(row, DLListModel);
|
|
|
|
|
|
|
|
fdownloadtime = getDownloadTime(row, DLListModel);
|
|
|
|
|
|
|
|
// maybe show all links in retroshare link(s) Tab
|
|
|
|
// int nb_select = 0 ;
|
|
|
|
//
|
|
|
|
// for(int i = 0; i <= DLListModel->rowCount(); i++)
|
|
|
|
// if(selection->isRowSelected(i, QModelIndex()))
|
|
|
|
// {
|
|
|
|
// file_hash = getID(i, DLListModel).toStdString();
|
|
|
|
// ++nb_select ;
|
|
|
|
// }
|
|
|
|
|
|
|
|
file_hash = getID(row, DLListModel).toStdString();
|
2010-01-05 19:10:15 -05:00
|
|
|
}
|
2010-05-03 18:44:53 -04:00
|
|
|
|
|
|
|
detailsdlg->setFileHash(file_hash);
|
|
|
|
|
|
|
|
// Set Details.. Window Title
|
|
|
|
detailsdlg->setWindowTitle(tr("Details:") + fname);
|
|
|
|
|
|
|
|
// General GroupBox
|
|
|
|
detailsdlg->setHash(fhash);
|
|
|
|
detailsdlg->setFileName(fname);
|
|
|
|
detailsdlg->setSize(filesize);
|
|
|
|
detailsdlg->setStatus(fstatus);
|
|
|
|
detailsdlg->setPriority(fpriority);
|
|
|
|
detailsdlg->setType(QFileInfo(fname).suffix());
|
|
|
|
|
|
|
|
// Transfer GroupBox
|
|
|
|
detailsdlg->setSources(fsources);
|
|
|
|
detailsdlg->setDatarate(fdatarate);
|
|
|
|
if (fname.isEmpty()) {
|
|
|
|
detailsdlg->setCompleted(misc::friendlyUnit(-1));
|
|
|
|
detailsdlg->setRemaining(misc::friendlyUnit(-1));
|
|
|
|
} else {
|
|
|
|
detailsdlg->setCompleted(misc::friendlyUnit(fcompleted));
|
|
|
|
detailsdlg->setRemaining(misc::friendlyUnit(fremaining));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Date GroupBox
|
|
|
|
if (fname.isEmpty()) {
|
|
|
|
detailsdlg->setDownloadtime(misc::userFriendlyDuration(-1));
|
|
|
|
} else {
|
|
|
|
detailsdlg->setDownloadtime(misc::userFriendlyDuration(fdownloadtime));
|
|
|
|
}
|
|
|
|
|
|
|
|
// retroshare link(s) Tab
|
|
|
|
if (fname.isEmpty()) {
|
|
|
|
detailsdlg->setLink("");
|
|
|
|
} else {
|
2011-05-04 06:22:49 -04:00
|
|
|
RetroShareLink link;
|
|
|
|
if (link.createFile(fname, filesize, fhash)) {
|
|
|
|
detailsdlg->setLink(link.toString());
|
|
|
|
} else {
|
|
|
|
detailsdlg->setLink("");
|
|
|
|
}
|
2010-05-03 18:44:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
FileChunksInfo info ;
|
|
|
|
if (fhash.isEmpty() == false && rsFiles->FileDownloadChunksDetails(fhash.toStdString(), info)) {
|
|
|
|
detailsdlg->setChunkSize(info.chunk_size);
|
|
|
|
detailsdlg->setNumberOfChunks(info.chunks.size());
|
|
|
|
} else {
|
|
|
|
detailsdlg->setChunkSize(0);
|
|
|
|
detailsdlg->setNumberOfChunks(0);
|
|
|
|
}
|
2010-01-05 19:10:15 -05:00
|
|
|
}
|
|
|
|
|
2009-05-18 10:23:55 -04:00
|
|
|
void TransfersDialog::pasteLink()
|
|
|
|
{
|
2010-07-15 07:25:34 -04:00
|
|
|
RSLinkClipboard::process(RetroShareLink::TYPE_FILE, RSLINK_PROCESS_NOTIFY_ERROR);
|
2009-05-18 10:23:55 -04:00
|
|
|
}
|
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
void TransfersDialog::getSelectedItems(std::set<std::string> *ids, std::set<int> *rows)
|
2009-07-02 14:40:31 -04:00
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
if (ids == NULL && rows == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ids) ids->clear();
|
|
|
|
if (rows) rows->clear();
|
2009-07-02 14:40:31 -04:00
|
|
|
|
|
|
|
int i, imax = DLListModel->rowCount();
|
|
|
|
for (i = 0; i < imax; i++) {
|
|
|
|
bool isParentSelected = false;
|
|
|
|
bool isChildSelected = false;
|
|
|
|
|
|
|
|
QStandardItem *parent = DLListModel->item(i);
|
|
|
|
if (!parent) continue;
|
|
|
|
QModelIndex pindex = parent->index();
|
|
|
|
if (selection->isSelected(pindex)) {
|
|
|
|
isParentSelected = true;
|
|
|
|
} else {
|
|
|
|
int j, jmax = parent->rowCount();
|
|
|
|
for (j = 0; j < jmax && !isChildSelected; j++) {
|
|
|
|
QStandardItem *child = parent->child(j);
|
|
|
|
if (!child) continue;
|
|
|
|
QModelIndex cindex = child->index();
|
|
|
|
if (selection->isSelected(cindex)) {
|
|
|
|
isChildSelected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if transfered file or it's peers are selected control it*/
|
|
|
|
if (isParentSelected || isChildSelected) {
|
2011-02-07 19:41:13 -05:00
|
|
|
if (ids) {
|
|
|
|
QStandardItem *id = DLListModel->item(i, ID);
|
|
|
|
ids->insert(id->data(Qt::DisplayRole).toString().toStdString());
|
|
|
|
}
|
|
|
|
if (rows) {
|
|
|
|
rows->insert(i);
|
|
|
|
}
|
2009-07-02 14:40:31 -04:00
|
|
|
}
|
|
|
|
}
|
2009-07-04 17:54:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TransfersDialog::controlTransferFile(uint32_t flags)
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2009-07-04 17:54:58 -04:00
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
2011-02-07 19:41:13 -05:00
|
|
|
result &= rsFiles->FileControl(*it, flags);
|
2009-07-04 17:54:58 -04:00
|
|
|
}
|
2009-07-02 14:40:31 -04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransfersDialog::pauseFileTransfer()
|
|
|
|
{
|
|
|
|
if (!controlTransferFile(RS_FILE_CTRL_PAUSE))
|
|
|
|
{
|
|
|
|
std::cerr << "pauseFileTransfer(): can't pause file transfer" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransfersDialog::resumeFileTransfer()
|
|
|
|
{
|
|
|
|
if (!controlTransferFile(RS_FILE_CTRL_START))
|
|
|
|
{
|
|
|
|
std::cerr << "resumeFileTransfer(): can't resume file transfer" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-05 12:27:58 -04:00
|
|
|
void TransfersDialog::openFolderTransfer()
|
2009-07-02 14:40:31 -04:00
|
|
|
{
|
|
|
|
FileInfo info;
|
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2009-07-04 17:54:58 -04:00
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
2011-02-07 19:41:13 -05:00
|
|
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
2009-07-04 17:54:58 -04:00
|
|
|
break;
|
|
|
|
}
|
2009-07-02 14:40:31 -04:00
|
|
|
|
2009-07-04 17:54:58 -04:00
|
|
|
/* make path for downloaded or downloading files */
|
|
|
|
QFileInfo qinfo;
|
|
|
|
std::string path;
|
|
|
|
if (info.downloadStatus == FT_STATE_COMPLETE) {
|
2009-07-05 12:27:58 -04:00
|
|
|
path = info.path;
|
2009-07-04 17:54:58 -04:00
|
|
|
} else {
|
|
|
|
path = rsFiles->getPartialsDirectory();
|
2009-07-05 12:27:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* open folder with a suitable application */
|
2011-03-06 15:19:16 -05:00
|
|
|
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
2009-07-05 12:27:58 -04:00
|
|
|
if (qinfo.exists() && qinfo.isDir()) {
|
|
|
|
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) {
|
|
|
|
std::cerr << "openFolderTransfer(): can't open folder " << path << std::endl;
|
2009-07-04 17:54:58 -04:00
|
|
|
}
|
|
|
|
}
|
2009-07-05 12:27:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransfersDialog::previewTransfer()
|
|
|
|
{
|
|
|
|
FileInfo info;
|
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2009-07-05 12:27:58 -04:00
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
2011-02-07 19:41:13 -05:00
|
|
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
2009-07-05 12:27:58 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t pos = info.fname.find_last_of('.');
|
2010-03-07 09:10:51 -05:00
|
|
|
if (pos == std::string::npos)
|
|
|
|
return; /* can't identify type of file */
|
2009-07-05 12:27:58 -04:00
|
|
|
|
|
|
|
/* check if the file is a media file */
|
|
|
|
if (!misc::isPreviewable(info.fname.substr(pos + 1).c_str())) return;
|
|
|
|
|
|
|
|
/* make path for downloaded or downloading files */
|
2009-07-28 11:29:21 -04:00
|
|
|
bool complete = false;
|
2009-07-05 12:27:58 -04:00
|
|
|
std::string path;
|
|
|
|
if (info.downloadStatus == FT_STATE_COMPLETE) {
|
|
|
|
path = info.path + "/" + info.fname;
|
2009-07-28 11:29:21 -04:00
|
|
|
complete = true;
|
2009-07-05 12:27:58 -04:00
|
|
|
} else {
|
2009-07-28 11:29:21 -04:00
|
|
|
path = rsFiles->getPartialsDirectory() + "/" + info.hash;
|
2009-07-05 12:27:58 -04:00
|
|
|
}
|
2009-07-02 14:40:31 -04:00
|
|
|
|
2011-04-09 11:18:26 -04:00
|
|
|
#ifndef WIN32
|
|
|
|
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromUtf8(path.c_str()))))
|
|
|
|
QMessageBox::warning(this, tr("File preview"), tr("File %1 preview failed.").arg(QString::fromUtf8(path.c_str())));
|
|
|
|
#else
|
2009-07-04 17:54:58 -04:00
|
|
|
/* open or preview them with a suitable application */
|
2009-07-28 11:29:21 -04:00
|
|
|
QFileInfo qinfo;
|
|
|
|
if (complete) {
|
2011-03-06 15:19:16 -05:00
|
|
|
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
2009-07-28 11:29:21 -04:00
|
|
|
if (qinfo.exists()) {
|
|
|
|
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) {
|
|
|
|
std::cerr << "previewTransfer(): can't preview file " << path << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-06 15:19:16 -05:00
|
|
|
QString linkName = QString::fromUtf8(path.c_str()) +
|
|
|
|
QString::fromUtf8(info.fname.substr(info.fname.find_last_of('.')).c_str());
|
|
|
|
if (QFile::link(QString::fromUtf8(path.c_str()), linkName)) {
|
2009-07-28 11:29:21 -04:00
|
|
|
qinfo.setFile(linkName);
|
|
|
|
if (qinfo.exists()) {
|
|
|
|
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) {
|
|
|
|
std::cerr << "previewTransfer(): can't preview file " << path << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* wait for the file to open then remove the link */
|
|
|
|
#ifdef WIN32
|
|
|
|
Sleep(2000);
|
|
|
|
#else
|
|
|
|
sleep(2);
|
|
|
|
#endif
|
|
|
|
QFile::remove(linkName);
|
|
|
|
} else {
|
|
|
|
std::cerr << "previewTransfer(): can't create link for file " << path << std::endl;
|
2009-07-02 14:40:31 -04:00
|
|
|
}
|
|
|
|
}
|
2011-04-09 11:18:26 -04:00
|
|
|
#endif
|
2009-07-04 17:54:58 -04:00
|
|
|
}
|
2009-07-02 14:40:31 -04:00
|
|
|
|
2009-07-05 12:27:58 -04:00
|
|
|
void TransfersDialog::openTransfer()
|
2009-07-04 17:54:58 -04:00
|
|
|
{
|
2009-07-05 12:27:58 -04:00
|
|
|
FileInfo info;
|
2009-07-04 17:54:58 -04:00
|
|
|
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2009-07-05 12:27:58 -04:00
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
2011-02-07 19:41:13 -05:00
|
|
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
2009-07-05 12:27:58 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make path for downloaded or downloading files */
|
|
|
|
std::string path;
|
|
|
|
if (info.downloadStatus == FT_STATE_COMPLETE) {
|
|
|
|
path = info.path + "/" + info.fname;
|
|
|
|
|
|
|
|
/* open file with a suitable application */
|
|
|
|
QFileInfo qinfo;
|
2011-03-06 15:19:16 -05:00
|
|
|
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
2009-07-05 12:27:58 -04:00
|
|
|
if (qinfo.exists()) {
|
|
|
|
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) {
|
|
|
|
std::cerr << "openTransfer(): can't open file " << path << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* rise a message box for incompleted download file */
|
|
|
|
QMessageBox::information(this, tr("Open Transfer"),
|
2011-03-06 15:19:16 -05:00
|
|
|
tr("File %1 is not completed. If it is a media file, try to preview it.").arg(QString::fromUtf8(info.fname.c_str())));
|
2009-07-05 12:27:58 -04:00
|
|
|
}
|
2009-07-02 14:40:31 -04:00
|
|
|
}
|
|
|
|
|
2009-07-27 13:22:56 -04:00
|
|
|
/* clear download or all queue - for pending dwls */
|
2010-01-26 18:25:00 -05:00
|
|
|
//void TransfersDialog::clearQueuedDwl()
|
|
|
|
//{
|
|
|
|
// std::set<QStandardItem *> items;
|
|
|
|
// std::set<QStandardItem *>::iterator it;
|
2011-02-07 19:41:13 -05:00
|
|
|
// getSelectedItems(&items, NULL);
|
2010-01-26 18:25:00 -05:00
|
|
|
//
|
|
|
|
// for (it = items.begin(); it != items.end(); it ++) {
|
|
|
|
// std::string hash = (*it)->data(Qt::DisplayRole).toString().toStdString();
|
|
|
|
// rsFiles->clearDownload(hash);
|
|
|
|
// }
|
|
|
|
//}
|
2010-03-06 18:29:47 -05:00
|
|
|
//void TransfersDialog::clearQueue()
|
|
|
|
//{
|
|
|
|
// rsFiles->clearQueue();
|
|
|
|
//}
|
2009-07-27 13:22:56 -04:00
|
|
|
|
2009-12-08 17:29:52 -05:00
|
|
|
void TransfersDialog::chunkStreaming()
|
|
|
|
{
|
|
|
|
setChunkStrategy(FileChunksInfo::CHUNK_STRATEGY_STREAMING) ;
|
|
|
|
}
|
|
|
|
void TransfersDialog::chunkRandom()
|
|
|
|
{
|
|
|
|
setChunkStrategy(FileChunksInfo::CHUNK_STRATEGY_RANDOM) ;
|
|
|
|
}
|
|
|
|
void TransfersDialog::setChunkStrategy(FileChunksInfo::ChunkStrategy s)
|
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2009-12-08 17:29:52 -05:00
|
|
|
|
|
|
|
for (it = items.begin(); it != items.end(); it ++) {
|
2011-02-07 19:41:13 -05:00
|
|
|
rsFiles->setChunkStrategy(*it, s);
|
2009-12-08 17:29:52 -05:00
|
|
|
}
|
|
|
|
}
|
2009-07-27 13:22:56 -04:00
|
|
|
/* modify download priority actions */
|
2010-01-26 18:25:00 -05:00
|
|
|
void TransfersDialog::speedSlow()
|
2009-07-27 13:22:56 -04:00
|
|
|
{
|
2010-01-26 18:25:00 -05:00
|
|
|
changeSpeed(0);
|
2009-07-27 13:22:56 -04:00
|
|
|
}
|
2010-01-26 18:25:00 -05:00
|
|
|
void TransfersDialog::speedAverage()
|
2009-07-27 13:22:56 -04:00
|
|
|
{
|
2010-01-26 18:25:00 -05:00
|
|
|
changeSpeed(1);
|
2009-07-27 13:22:56 -04:00
|
|
|
}
|
2010-01-26 18:25:00 -05:00
|
|
|
void TransfersDialog::speedFast()
|
2009-07-27 13:22:56 -04:00
|
|
|
{
|
2010-01-26 18:25:00 -05:00
|
|
|
changeSpeed(2);
|
2009-07-27 13:22:56 -04:00
|
|
|
}
|
2010-01-26 18:25:00 -05:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
void TransfersDialog::priorityQueueUp()
|
2009-07-27 13:22:56 -04:00
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
changeQueuePosition(QUEUE_UP);
|
2010-01-26 18:25:00 -05:00
|
|
|
}
|
2010-03-06 18:29:47 -05:00
|
|
|
void TransfersDialog::priorityQueueDown()
|
2010-01-26 18:25:00 -05:00
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
changeQueuePosition(QUEUE_DOWN);
|
2010-01-26 18:25:00 -05:00
|
|
|
}
|
2010-03-06 18:29:47 -05:00
|
|
|
void TransfersDialog::priorityQueueTop()
|
2010-01-26 18:25:00 -05:00
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
changeQueuePosition(QUEUE_TOP);
|
2010-01-26 18:25:00 -05:00
|
|
|
}
|
2010-03-06 18:29:47 -05:00
|
|
|
void TransfersDialog::priorityQueueBottom()
|
2010-01-26 18:25:00 -05:00
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
changeQueuePosition(QUEUE_BOTTOM);
|
2009-07-27 13:22:56 -04:00
|
|
|
}
|
|
|
|
|
2010-01-26 18:25:00 -05:00
|
|
|
void TransfersDialog::changeSpeed(int speed)
|
2009-07-27 13:22:56 -04:00
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2009-07-27 13:22:56 -04:00
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
for (it = items.begin(); it != items.end(); it ++)
|
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
rsFiles->changeDownloadSpeed(*it, speed);
|
2010-01-26 18:25:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-06 18:29:47 -05:00
|
|
|
void TransfersDialog::changeQueuePosition(QueueMove mv)
|
2010-01-26 18:25:00 -05:00
|
|
|
{
|
2010-03-06 18:29:47 -05:00
|
|
|
std::cerr << "In changeQueuePosition (gui)"<< std::endl ;
|
2011-02-07 19:41:13 -05:00
|
|
|
std::set<std::string> items;
|
|
|
|
std::set<std::string>::iterator it;
|
|
|
|
getSelectedItems(&items, NULL);
|
2010-01-26 18:25:00 -05:00
|
|
|
|
|
|
|
for (it = items.begin(); it != items.end(); it ++)
|
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
rsFiles->changeQueuePosition(*it, mv);
|
2009-07-27 13:22:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
void TransfersDialog::clearcompleted()
|
|
|
|
{
|
2011-02-07 19:41:13 -05:00
|
|
|
std::cerr << "TransfersDialog::clearcompleted()" << std::endl;
|
|
|
|
rsFiles->FileClearCompleted();
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
void TransfersDialog::showFileDetails()
|
2009-11-15 14:26:34 -05:00
|
|
|
{
|
2009-11-17 07:45:06 -05:00
|
|
|
std::string file_hash ;
|
|
|
|
int nb_select = 0 ;
|
2009-11-15 14:26:34 -05:00
|
|
|
|
2010-01-11 11:00:42 -05:00
|
|
|
std::cout << "new selection " << std::endl ;
|
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
for(int i = 0; i <= DLListModel->rowCount(); i++)
|
|
|
|
if(selection->isRowSelected(i, QModelIndex()))
|
|
|
|
{
|
|
|
|
file_hash = getID(i, DLListModel).toStdString();
|
|
|
|
++nb_select ;
|
|
|
|
}
|
|
|
|
if(nb_select != 1)
|
2010-01-11 11:00:42 -05:00
|
|
|
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->setFileHash("") ;
|
|
|
|
else
|
|
|
|
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->setFileHash(file_hash) ;
|
2009-11-17 07:45:06 -05:00
|
|
|
|
2010-01-11 11:00:42 -05:00
|
|
|
std::cout << "calling update " << std::endl ;
|
2009-11-17 07:45:06 -05:00
|
|
|
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->updateDisplay() ;
|
2010-01-11 11:00:42 -05:00
|
|
|
std::cout << "done" << std::endl ;
|
2010-05-03 18:44:53 -04:00
|
|
|
|
|
|
|
updateDetailsDialog ();
|
2009-11-17 07:45:06 -05:00
|
|
|
}
|
2009-11-15 14:26:34 -05:00
|
|
|
|
2010-03-07 09:10:51 -05:00
|
|
|
double TransfersDialog::getProgress(int , QStandardItemModel *)
|
2008-12-12 16:42:44 -05:00
|
|
|
{
|
2010-01-11 11:00:42 -05:00
|
|
|
// return model->data(model->index(row, PROGRESS), Qt::DisplayRole).toDouble();
|
|
|
|
return 0.0 ;
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double TransfersDialog::getSpeed(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
return model->data(model->index(row, DLSPEED), Qt::DisplayRole).toDouble();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TransfersDialog::getFileName(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
return model->data(model->index(row, NAME), Qt::DisplayRole).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TransfersDialog::getStatus(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
return model->data(model->index(row, STATUS), Qt::DisplayRole).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TransfersDialog::getID(int row, QStandardItemModel *model)
|
|
|
|
{
|
2011-02-03 17:26:54 -05:00
|
|
|
return model->data(model->index(row, ID), Qt::DisplayRole).toString().left(40); // gets only the "hash" part of the name
|
2008-12-12 16:42:44 -05:00
|
|
|
}
|
|
|
|
|
2009-08-14 16:48:53 -04:00
|
|
|
QString TransfersDialog::getPriority(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
return model->data(model->index(row, PRIORITY), Qt::DisplayRole).toString();
|
|
|
|
}
|
|
|
|
|
2008-12-12 16:42:44 -05:00
|
|
|
qlonglong TransfersDialog::getFileSize(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
return model->data(model->index(row, SIZE), Qt::DisplayRole).toULongLong(&ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
qlonglong TransfersDialog::getTransfered(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
return model->data(model->index(row, COMPLETED), Qt::DisplayRole).toULongLong(&ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
qlonglong TransfersDialog::getRemainingTime(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
return model->data(model->index(row, REMAINING), Qt::DisplayRole).toULongLong(&ok);
|
|
|
|
}
|
2011-02-07 19:41:13 -05:00
|
|
|
|
|
|
|
qlonglong TransfersDialog::getDownloadTime(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
return model->data(model->index(row, DOWNLOADTIME), Qt::DisplayRole).toULongLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TransfersDialog::getSources(int row, QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
return model->data(model->index(row, SOURCES), Qt::DisplayRole).toString();
|
|
|
|
}
|