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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2013-07-01 17:03:20 -04:00
# include <QDateTime>
2012-04-04 18:45:40 -04:00
# include <QDir>
2017-09-02 11:57:04 -04:00
# include <QFileDialog>
# include <QFileInfo>
# include <QHeaderView>
# include <QInputDialog>
# include <QMenu>
2010-07-23 14:52:58 -04:00
# include <QMessageBox>
2017-09-02 11:57:04 -04:00
# include <QShortcut>
# include <QStandardItemModel>
2011-12-07 08:08:12 -05:00
# include <gui/common/FilesDefs.h>
2017-10-19 16:14:04 -04:00
# include <gui/common/RsCollection.h>
2017-09-02 11:57:04 -04:00
# include <gui/common/RsUrlHandler.h>
# include <gui/common/RSTreeView.h>
2008-12-12 16:42:44 -05:00
2010-09-14 19:51:55 -04:00
# include <algorithm>
2013-09-01 09:56:05 -04:00
# include <limits>
2013-10-06 08:09:36 -04:00
# include <math.h>
2010-09-14 19:51:55 -04:00
2008-12-12 16:42:44 -05:00
# include "TransfersDialog.h"
2013-07-14 08:53:38 -04:00
# include <gui/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"
2016-01-22 09:31:40 -05:00
# include <gui/FileTransfer/SearchDialog.h>
2017-09-07 13:37:53 -04:00
# include <gui/FileTransfer/SharedFilesDialog.h>
2010-01-11 11:00:42 -05:00
# include "xprogressbar.h"
2013-07-14 08:53:38 -04:00
# include <gui/settings/rsharesettings.h>
2011-11-25 18:46:41 -05:00
# include "util/misc.h"
2017-10-19 16:14:04 -04:00
# include <gui/common/RsCollection.h>
2013-07-14 08:53:38 -04:00
# include "TransferUserNotify.h"
2013-10-19 09:25:06 -04:00
# include "util/QtVersion.h"
2014-04-28 19:20:29 -04:00
# include "util/RsFile.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>
2012-02-21 16:53:25 -05:00
# include <retroshare/rsplugin.h>
2008-12-12 16:42:44 -05:00
2017-03-10 01:27:46 -05:00
# include <retroshare/rsturtle.h>
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"
2014-05-29 10:49:45 -04:00
# define IMAGE_PLAY ": / images / player_play.png"
2009-05-18 10:23:55 -04:00
# 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"
2018-02-04 16:56:13 -05:00
# define IMAGE_PRIORITYLOW ": / images / prioritylow.png"
# define IMAGE_PRIORITYNORMAL ": / images / prioritynormal.png"
# define IMAGE_PRIORITYHIGH ": / images / priorityhigh.png"
# define IMAGE_PRIORITYAUTO ": / images / priorityauto.png"
2016-08-30 11:18:27 -04:00
# define IMAGE_SEARCH ": / icons / svg / magnifying-glass.svg"
2014-05-29 10:49:45 -04:00
# define IMAGE_EXPAND ": / images / edit_add24.png"
# define IMAGE_COLLAPSE ": / images / edit_remove24.png"
# define IMAGE_LIBRARY ": / images / library.png"
# define IMAGE_COLLCREATE ": / images / library_add.png"
# define IMAGE_COLLMODIF ": / images / library_edit.png"
# define IMAGE_COLLVIEW ": / images / library_view.png"
# define IMAGE_COLLOPEN ": / images / library.png"
2016-08-30 11:18:27 -04:00
# define IMAGE_FRIENDSFILES ": / icons / svg / folders.svg"
# define IMAGE_MYFILES ":icons / svg / folders1.svg"
2014-05-29 10:49:45 -04:00
# define IMAGE_RENAMEFILE ":images / filecomments.png"
2017-09-16 13:28:50 -04:00
# define IMAGE_STREAMING ":images / streaming.png"
# define IMAGE_TUNNEL_ANON_E2E ": / images / blue_lock.png"
# define IMAGE_TUNNEL_ANON ": / images / blue_lock_open.png"
# define IMAGE_TUNNEL_FRIEND ": / icons / avatar_128.png"
2009-07-04 19:36:04 -04:00
2018-03-03 09:49:45 -05:00
//#define DEBUG_DOWNLOADLIST 1
2017-09-16 13:28:50 -04:00
Q_DECLARE_METATYPE ( FileProgressInfo )
2010-01-11 11:00:42 -05:00
2018-03-03 09:49:45 -05:00
std : : ostream & operator < < ( std : : ostream & o , const QModelIndex & i )
{
return o < < i . row ( ) < < " , " < < i . column ( ) < < " , " < < i . internalPointer ( ) ;
}
2018-02-04 16:56:13 -05:00
class RsDownloadListModel : public QAbstractItemModel
{
// Q_OBJECT
public :
explicit RsDownloadListModel ( QObject * parent = NULL ) : QAbstractItemModel ( parent ) { }
~ RsDownloadListModel ( ) { }
2018-02-07 15:57:32 -05:00
enum Roles { SortRole = Qt : : UserRole + 1 } ;
2018-02-04 16:56:13 -05:00
int rowCount ( const QModelIndex & parent = QModelIndex ( ) ) const
{
void * ref = ( parent . isValid ( ) ) ? parent . internalPointer ( ) : NULL ;
if ( ! ref )
2018-03-03 09:49:45 -05:00
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " rowCount-1( " < < parent < < " ) : " < < mDownloads . size ( ) < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
return mDownloads . size ( ) ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
uint32_t entry = 0 ;
int source_id ;
2018-03-02 16:57:14 -05:00
if ( ! convertRefPointerToTabEntry ( ref , entry , source_id ) | | entry > = mDownloads . size ( ) | | source_id > - 1 )
2018-03-03 09:49:45 -05:00
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " rowCount-2( " < < parent < < " ) : " < < 0 < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
return 0 ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " rowCount-3( " < < parent < < " ) : " < < mDownloads [ entry ] . peers . size ( ) < < std : : endl ;
# endif
return mDownloads [ entry ] . peers . size ( ) ;
2018-02-04 16:56:13 -05:00
}
int columnCount ( const QModelIndex & parent = QModelIndex ( ) ) const
{
2018-03-03 09:49:45 -05:00
return COLUMN_COUNT ;
2018-02-04 16:56:13 -05:00
}
bool hasChildren ( const QModelIndex & parent = QModelIndex ( ) ) const
{
void * ref = ( parent . isValid ( ) ) ? parent . internalPointer ( ) : NULL ;
uint32_t entry = 0 ;
int source_id = 0 ;
if ( ! ref )
2018-03-03 09:49:45 -05:00
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " hasChildren-1( " < < parent < < " ) : " < < true < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
return true ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
2018-02-06 18:25:41 -05:00
if ( ! convertRefPointerToTabEntry ( ref , entry , source_id ) | | entry > = mDownloads . size ( ) | | source_id > - 1 )
2018-03-03 09:49:45 -05:00
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " hasChildren-2( " < < parent < < " ) : " < < false < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
return false ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " hasChildren-3( " < < parent < < " ) : " < < ! mDownloads [ entry ] . peers . empty ( ) < < std : : endl ;
# endif
2018-02-20 15:07:02 -05:00
return ! mDownloads [ entry ] . peers . empty ( ) ;
2018-02-04 16:56:13 -05:00
}
2018-02-06 18:25:41 -05:00
QModelIndex index ( int row , int column , const QModelIndex & parent = QModelIndex ( ) ) const
2018-02-04 16:56:13 -05:00
{
2018-03-03 09:49:45 -05:00
if ( row < 0 | | column < 0 | | column > = COLUMN_COUNT )
2018-02-04 16:56:13 -05:00
return QModelIndex ( ) ;
2018-03-03 09:49:45 -05:00
void * parent_ref = ( parent . isValid ( ) ) ? parent . internalPointer ( ) : NULL ;
2018-02-04 16:56:13 -05:00
uint32_t entry = 0 ;
int source_id = 0 ;
2018-03-03 09:49:45 -05:00
if ( ! parent_ref ) // top level. The entry is that of a transfer
2018-02-04 16:56:13 -05:00
{
2018-03-03 09:49:45 -05:00
void * ref = NULL ;
if ( row > = ( int ) mDownloads . size ( ) | | ! convertTabEntryToRefPointer ( row , - 1 , ref ) )
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " index-1( " < < row < < " , " < < column < < " parent= " < < parent < < " ) : " < < " NULL " < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
return QModelIndex ( ) ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " index-2( " < < row < < " , " < < column < < " parent= " < < parent < < " ) : " < < createIndex ( row , column , ref ) < < std : : endl ;
# endif
return createIndex ( row , column , ref ) ;
2018-02-04 16:56:13 -05:00
}
2018-03-03 09:49:45 -05:00
if ( ! convertRefPointerToTabEntry ( parent_ref , entry , source_id ) | | entry > = mDownloads . size ( ) | | int ( mDownloads [ entry ] . peers . size ( ) ) < = row )
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " index-5( " < < row < < " , " < < column < < " parent= " < < parent < < " ) : " < < " NULL " < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
return QModelIndex ( ) ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
if ( source_id ! = - 1 )
std : : cerr < < " ERROR: parent.source_id != -1 in index() " < < std : : endl ;
2018-03-03 09:49:45 -05:00
void * ref = NULL ;
if ( ! convertTabEntryToRefPointer ( entry , row , ref ) )
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " index-4( " < < row < < " , " < < column < < " parent= " < < parent < < " ) : " < < " NULL " < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
return QModelIndex ( ) ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " index-3( " < < row < < " , " < < column < < " parent= " < < parent < < " ) : " < < createIndex ( row , column , ref ) < < std : : endl ;
# endif
return createIndex ( row , column , ref ) ;
2018-02-04 16:56:13 -05:00
}
QModelIndex parent ( const QModelIndex & child ) const
{
2018-03-03 09:49:45 -05:00
void * child_ref = ( child . isValid ( ) ) ? child . internalPointer ( ) : NULL ;
2018-02-04 16:56:13 -05:00
uint32_t entry = 0 ;
int source_id = 0 ;
2018-03-03 09:49:45 -05:00
if ( ! child_ref )
2018-02-04 16:56:13 -05:00
return QModelIndex ( ) ;
2018-03-03 09:49:45 -05:00
if ( ! convertRefPointerToTabEntry ( child_ref , entry , source_id ) | | entry > = mDownloads . size ( ) | | int ( mDownloads [ entry ] . peers . size ( ) ) < = source_id )
2018-02-04 16:56:13 -05:00
return QModelIndex ( ) ;
if ( source_id < 0 )
return QModelIndex ( ) ;
2018-03-03 09:49:45 -05:00
void * parent_ref = NULL ;
2018-02-04 16:56:13 -05:00
2018-03-03 09:49:45 -05:00
if ( ! convertTabEntryToRefPointer ( entry , - 1 , parent_ref ) )
2018-02-04 16:56:13 -05:00
return QModelIndex ( ) ;
2018-03-03 09:49:45 -05:00
return createIndex ( entry , child . column ( ) , parent_ref ) ;
2018-02-04 16:56:13 -05:00
}
QVariant headerData ( int section , Qt : : Orientation orientation , int role = Qt : : DisplayRole ) const
{
if ( role ! = Qt : : DisplayRole )
return QVariant ( ) ;
switch ( section )
{
default :
case COLUMN_NAME : return tr ( " Name " , " i.e: file name " ) ;
case COLUMN_SIZE : return tr ( " Size " , " i.e: file size " ) ;
case COLUMN_COMPLETED : return tr ( " Completed " , " " ) ;
case COLUMN_DLSPEED : return tr ( " Speed " , " i.e: Download speed " ) ;
case COLUMN_PROGRESS : return tr ( " Progress / Availability " , " i.e: % downloaded " ) ;
case COLUMN_SOURCES : return tr ( " Sources " , " i.e: Sources " ) ;
case COLUMN_STATUS : return tr ( " Status " ) ;
case COLUMN_PRIORITY : return tr ( " Speed / Queue position " ) ;
case COLUMN_REMAINING : return tr ( " Remaining " ) ;
case COLUMN_DOWNLOADTIME : return tr ( " Download time " , " i.e: Estimated Time of Arrival / Time left " ) ;
case COLUMN_ID : return tr ( " Hash " ) ;
case COLUMN_LASTDL : return tr ( " Last Time Seen " , " i.e: Last Time Receiced Data " ) ;
case COLUMN_PATH : return tr ( " Path " , " i.e: Where file is saved " ) ;
}
}
QVariant data ( const QModelIndex & index , int role = Qt : : DisplayRole ) const
{
if ( ! index . isValid ( ) )
return QVariant ( ) ;
int coln = index . column ( ) ;
switch ( role )
{
case Qt : : SizeHintRole : return sizeHintRole ( index . column ( ) ) ;
case Qt : : TextAlignmentRole :
case Qt : : TextColorRole :
case Qt : : WhatsThisRole :
case Qt : : EditRole :
case Qt : : ToolTipRole :
case Qt : : StatusTipRole :
return QVariant ( ) ;
}
void * ref = ( index . isValid ( ) ) ? index . internalPointer ( ) : NULL ;
uint32_t entry = 0 ;
int source_id = 0 ;
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " data( " < < index < < " ) " ;
# endif
2018-02-04 16:56:13 -05:00
if ( ! ref )
2018-03-03 09:49:45 -05:00
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " [empty] " < < std : : endl ;
# endif
2018-02-20 15:07:02 -05:00
return QVariant ( ) ;
2018-03-03 09:49:45 -05:00
}
2018-02-04 16:56:13 -05:00
if ( ! convertRefPointerToTabEntry ( ref , entry , source_id ) | | entry > = mDownloads . size ( ) )
{
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
2018-02-04 16:56:13 -05:00
std : : cerr < < " Bad pointer: " < < ( void * ) ref < < std : : endl ;
2018-03-03 09:49:45 -05:00
# endif
2018-02-20 15:07:02 -05:00
return QVariant ( ) ;
2018-02-04 16:56:13 -05:00
}
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " source_id= " < < source_id ;
# endif
2018-03-02 16:57:14 -05:00
2018-03-03 09:49:45 -05:00
if ( source_id > = int ( mDownloads [ entry ] . peers . size ( ) ) )
{
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " [empty] " < < std : : endl ;
# endif
return QVariant ( ) ;
}
2018-03-02 16:57:14 -05:00
2018-02-04 16:56:13 -05:00
const FileInfo & finfo ( mDownloads [ entry ] ) ;
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " [ok] " < < std : : endl ;
# endif
2018-02-04 16:56:13 -05:00
switch ( role )
{
case Qt : : DisplayRole : return displayRole ( finfo , source_id , index . column ( ) ) ;
case Qt : : DecorationRole : return decorationRole ( finfo , source_id , index . column ( ) ) ;
case Qt : : UserRole : return userRole ( finfo , source_id , index . column ( ) ) ;
default :
return QVariant ( ) ;
}
}
QVariant sizeHintRole ( int col ) const
{
2018-03-02 12:13:09 -05:00
float factor = QFontMetricsF ( QApplication : : font ( ) ) . height ( ) / 14.0f ;
2018-03-02 12:05:11 -05:00
2018-02-04 16:56:13 -05:00
switch ( col )
{
default :
2018-03-02 12:05:11 -05:00
case COLUMN_NAME : return QVariant ( factor * 170 ) ;
case COLUMN_SIZE : return QVariant ( factor * 70 ) ;
case COLUMN_COMPLETED : return QVariant ( factor * 75 ) ;
case COLUMN_DLSPEED : return QVariant ( factor * 75 ) ;
case COLUMN_PROGRESS : return QVariant ( factor * 170 ) ;
case COLUMN_SOURCES : return QVariant ( factor * 90 ) ;
case COLUMN_STATUS : return QVariant ( factor * 100 ) ;
case COLUMN_PRIORITY : return QVariant ( factor * 100 ) ;
case COLUMN_REMAINING : return QVariant ( factor * 100 ) ;
case COLUMN_DOWNLOADTIME : return QVariant ( factor * 100 ) ;
case COLUMN_ID : return QVariant ( factor * 100 ) ;
case COLUMN_LASTDL : return QVariant ( factor * 100 ) ;
case COLUMN_PATH : return QVariant ( factor * 100 ) ;
2018-02-04 16:56:13 -05:00
}
}
QVariant displayRole ( const FileInfo & fileInfo , int source_id , int col ) const
{
2018-02-05 15:37:06 -05:00
if ( source_id = = - 1 ) // toplevel
2018-02-04 16:56:13 -05:00
switch ( col )
{
case COLUMN_NAME : return QVariant ( QString : : fromUtf8 ( fileInfo . fname . c_str ( ) ) ) ;
case COLUMN_COMPLETED : return QVariant ( ( qlonglong ) fileInfo . transfered ) ;
case COLUMN_DLSPEED : return QVariant ( ( double ) ( ( fileInfo . downloadStatus = = FT_STATE_DOWNLOADING ) ? ( fileInfo . tfRate * 1024.0 ) : 0.0 ) ) ;
case COLUMN_PROGRESS : return QVariant ( ( float ) ( ( fileInfo . size = = 0 ) ? 0 : ( fileInfo . transfered * 100.0 / ( float ) fileInfo . size ) ) ) ;
case COLUMN_STATUS :
{
QString status ;
switch ( fileInfo . 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 ;
case FT_STATE_PAUSED : status = tr ( " Paused " ) ; break ;
case FT_STATE_CHECKING_HASH : status = tr ( " Checking... " ) ; break ;
default : status = tr ( " Unknown " ) ; break ;
}
return QVariant ( status ) ;
}
case COLUMN_PRIORITY :
{
double priority = PRIORITY_NULL ;
if ( fileInfo . downloadStatus = = FT_STATE_QUEUED )
priority = fileInfo . queue_position ;
else if ( fileInfo . downloadStatus = = FT_STATE_COMPLETE )
priority = 0 ;
else
switch ( fileInfo . priority )
{
case SPEED_LOW : priority = PRIORITY_SLOWER ; break ;
case SPEED_NORMAL : priority = PRIORITY_AVERAGE ; break ;
case SPEED_HIGH : priority = PRIORITY_FASTER ; break ;
default : priority = PRIORITY_AVERAGE ; break ;
}
return QVariant ( priority ) ;
}
case COLUMN_REMAINING : return QVariant ( ( qlonglong ) ( fileInfo . size - fileInfo . transfered ) ) ;
case COLUMN_DOWNLOADTIME : return QVariant ( ( qlonglong ) ( fileInfo . tfRate > 0 ) ? ( ( fileInfo . size - fileInfo . transfered ) / ( fileInfo . tfRate * 1024.0 ) ) : 0 ) ;
case COLUMN_LASTDL :
{
qint64 qi64LastDL = fileInfo . lastTS ;
if ( qi64LastDL = = 0 ) // file is complete, or any raison why the time has not been set properly
{
QFileInfo file ;
if ( fileInfo . downloadStatus = = FT_STATE_COMPLETE )
file = QFileInfo ( QString : : fromUtf8 ( fileInfo . path . c_str ( ) ) , QString : : fromUtf8 ( fileInfo . fname . c_str ( ) ) ) ;
else
file = QFileInfo ( QString : : fromUtf8 ( rsFiles - > getPartialsDirectory ( ) . c_str ( ) ) , QString : : fromUtf8 ( fileInfo . hash . toStdString ( ) . c_str ( ) ) ) ;
//Get Last Access on File
if ( file . exists ( ) )
qi64LastDL = file . lastModified ( ) . toTime_t ( ) ;
}
return QVariant ( qi64LastDL ) ;
}
case COLUMN_PATH :
{
QString strPath = QString : : fromUtf8 ( fileInfo . path . c_str ( ) ) ;
QString strPathAfterDL = strPath ;
strPathAfterDL . replace ( QString : : fromUtf8 ( rsFiles - > getDownloadDirectory ( ) . c_str ( ) ) , " " ) ;
return QVariant ( strPathAfterDL ) ;
}
2018-02-05 15:37:06 -05:00
case COLUMN_SOURCES :
{
int active = 0 ;
QString fileHash = QString : : fromStdString ( fileInfo . hash . toStdString ( ) ) ;
if ( fileInfo . downloadStatus ! = FT_STATE_COMPLETE )
for ( std : : vector < TransferInfo > : : const_iterator pit = fileInfo . peers . begin ( ) ; pit ! = fileInfo . peers . end ( ) ; + + pit )
{
const TransferInfo & transferInfo = * pit ;
// //unique combination: fileHash + peerId, variant: hash + peerName (too long)
// QString hashFileAndPeerId = fileHash + QString::fromStdString(transferInfo.peerId.toStdString());
// double peerDlspeed = 0;
// if ((uint32_t)transferInfo.status == FT_STATE_DOWNLOADING && fileInfo.downloadStatus != FT_STATE_PAUSED && fileInfo.downloadStatus != FT_STATE_COMPLETE)
// peerDlspeed = transferInfo.tfRate * 1024.0;
// FileProgressInfo peerpinfo;
// peerpinfo.cmap = fcinfo.compressed_peer_availability_maps[transferInfo.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();
// get the sources (number of online peers)
if ( transferInfo . tfRate > 0 & & fileInfo . downloadStatus = = FT_STATE_DOWNLOADING )
+ + active ;
}
2018-02-06 18:25:41 -05:00
return QVariant ( ( float ) active + fileInfo . peers . size ( ) / 1000.0f ) ;
2018-02-05 15:37:06 -05:00
}
case COLUMN_SIZE : return QVariant ( ( qlonglong ) fileInfo . size ) ;
case COLUMN_ID : return QVariant ( QString : : fromStdString ( fileInfo . hash . toStdString ( ) ) ) ;
2018-02-04 16:56:13 -05:00
default :
return QVariant ( " [ TODO ] " ) ;
}
else
2018-02-06 18:25:41 -05:00
{
uint32_t chunk_size = 1024 * 1024 ;
switch ( col )
{
default :
case COLUMN_SOURCES :
case COLUMN_COMPLETED :
case COLUMN_REMAINING :
case COLUMN_LASTDL :
case COLUMN_ID :
case COLUMN_PATH :
case COLUMN_DOWNLOADTIME :
case COLUMN_SIZE : return QVariant ( ) ;
case COLUMN_PROGRESS : return QVariant ( ( fileInfo . size > 0 ) ? ( ( fileInfo . peers [ source_id ] . transfered % chunk_size ) * 100.0 / fileInfo . size ) : 0.0 ) ;
case COLUMN_DLSPEED :
{
double peerDlspeed = 0 ;
if ( ( uint32_t ) fileInfo . peers [ source_id ] . status = = FT_STATE_DOWNLOADING & & fileInfo . downloadStatus ! = FT_STATE_PAUSED & & fileInfo . downloadStatus ! = FT_STATE_COMPLETE )
peerDlspeed = fileInfo . peers [ source_id ] . tfRate * 1024.0 ;
return QVariant ( ( double ) peerDlspeed ) ;
}
case COLUMN_NAME :
{
QString iconName , tooltip ;
return QVariant ( TransfersDialog : : getPeerName ( fileInfo . peers [ source_id ] . peerId , iconName , tooltip ) ) ;
}
case COLUMN_PRIORITY : return QVariant ( ( double ) PRIORITY_NULL ) ;
}
}
return QVariant ( " [ERROR] " ) ;
2018-02-04 16:56:13 -05:00
}
virtual QVariant userRole ( const FileInfo & fileInfo , int source_id , int col ) const
{
2018-02-06 18:25:41 -05:00
if ( source_id = = - 1 )
switch ( col )
{
case COLUMN_PROGRESS :
{
FileChunksInfo fcinfo ;
if ( ! rsFiles - > FileDownloadChunksDetails ( fileInfo . hash , fcinfo ) )
2018-03-02 12:01:56 -05:00
return QVariant ( ) ;
2018-02-06 18:25:41 -05:00
FileProgressInfo pinfo ;
pinfo . cmap = fcinfo . chunks ;
pinfo . type = FileProgressInfo : : DOWNLOAD_LINE ;
pinfo . progress = ( fileInfo . size = = 0 ) ? 0 : ( fileInfo . transfered * 100.0 / fileInfo . size ) ;
pinfo . nb_chunks = pinfo . cmap . _map . empty ( ) ? 0 : fcinfo . chunks . size ( ) ;
for ( uint32_t i = 0 ; i < fcinfo . chunks . size ( ) ; + + i )
switch ( fcinfo . chunks [ i ] )
{
case FileChunksInfo : : CHUNK_CHECKING : pinfo . chunks_in_checking . push_back ( i ) ;
break ;
case FileChunksInfo : : CHUNK_ACTIVE : pinfo . chunks_in_progress . push_back ( i ) ;
break ;
case FileChunksInfo : : CHUNK_DONE :
case FileChunksInfo : : CHUNK_OUTSTANDING :
break ;
}
return QVariant : : fromValue ( pinfo ) ;
}
case COLUMN_ID : return QVariant ( QString : : fromStdString ( fileInfo . hash . toStdString ( ) ) ) ;
default :
return QVariant ( ) ;
}
else
switch ( col )
{
case COLUMN_PROGRESS :
{
2018-03-02 12:01:56 -05:00
FileChunksInfo fcinfo ;
if ( ! rsFiles - > FileDownloadChunksDetails ( fileInfo . hash , fcinfo ) )
2018-02-06 18:25:41 -05:00
return QVariant ( ) ;
2018-03-02 12:01:56 -05:00
RsPeerId pid = fileInfo . peers [ source_id ] . peerId ;
CompressedChunkMap & cmap ( fcinfo . compressed_peer_availability_maps [ pid ] ) ;
2018-02-06 18:25:41 -05:00
2018-03-02 12:01:56 -05:00
FileProgressInfo pinfo ;
pinfo . cmap = cmap ;
pinfo . type = FileProgressInfo : : DOWNLOAD_SOURCE ;
pinfo . progress = 0.0 ; // we dont display completion for sources
pinfo . nb_chunks = pinfo . cmap . _map . empty ( ) ? 0 : fcinfo . chunks . size ( ) ;
2018-02-04 16:56:13 -05:00
2018-03-02 16:57:14 -05:00
//std::cerr << "User role of source id " << source_id << std::endl;
2018-03-02 12:01:56 -05:00
return QVariant : : fromValue ( pinfo ) ;
2018-02-06 18:25:41 -05:00
}
2018-02-04 16:56:13 -05:00
2018-02-06 18:25:41 -05:00
case COLUMN_ID : return QVariant ( QString : : fromStdString ( fileInfo . hash . toStdString ( ) ) + QString : : fromStdString ( fileInfo . peers [ source_id ] . peerId . toStdString ( ) ) ) ;
2018-02-05 15:37:06 -05:00
2018-02-06 18:25:41 -05:00
default :
return QVariant ( ) ;
}
2018-02-05 15:37:06 -05:00
2018-02-04 16:56:13 -05:00
}
QVariant decorationRole ( const FileInfo & fileInfo , int source_id , int col ) const
{
if ( col = = COLUMN_NAME )
2018-02-06 18:25:41 -05:00
{
if ( source_id = = - 1 )
return QVariant ( FilesDefs : : getIconFromFilename ( QString : : fromUtf8 ( fileInfo . fname . c_str ( ) ) ) ) ;
else
{
QString iconName , tooltip ;
TransfersDialog : : getPeerName ( fileInfo . peers [ source_id ] . peerId , iconName , tooltip ) ;
2018-03-10 10:05:52 -05:00
return QVariant ( QIcon ( iconName ) ) ;
2018-02-06 18:25:41 -05:00
}
}
2018-02-04 16:56:13 -05:00
else
return QVariant ( ) ;
}
void update_transfers ( )
{
std : : list < RsFileHash > downHashes ;
rsFiles - > FileDownloads ( downHashes ) ;
2018-02-09 17:02:27 -05:00
size_t old_size = mDownloads . size ( ) ;
2018-02-04 16:56:13 -05:00
mDownloads . resize ( downHashes . size ( ) ) ;
2018-02-09 17:02:27 -05:00
if ( old_size < mDownloads . size ( ) )
{
2018-02-20 15:07:02 -05:00
beginInsertRows ( QModelIndex ( ) , old_size , mDownloads . size ( ) - 1 ) ;
2018-02-09 17:02:27 -05:00
insertRows ( old_size , mDownloads . size ( ) - old_size ) ;
endInsertRows ( ) ;
}
else if ( mDownloads . size ( ) < old_size )
{
2018-02-20 15:07:02 -05:00
beginRemoveRows ( QModelIndex ( ) , mDownloads . size ( ) , old_size - 1 ) ;
2018-03-02 15:26:38 -05:00
removeRows ( mDownloads . size ( ) , old_size - mDownloads . size ( ) ) ;
2018-02-09 17:02:27 -05:00
endRemoveRows ( ) ;
}
2018-02-04 16:56:13 -05:00
uint32_t i = 0 ;
2018-02-09 17:02:27 -05:00
2018-02-04 16:56:13 -05:00
for ( auto it ( downHashes . begin ( ) ) ; it ! = downHashes . end ( ) ; + + it , + + i )
{
2018-03-03 09:49:45 -05:00
FileInfo fileInfo ( mDownloads [ i ] ) ; // we dont update the data itself but only a copy of it....
2018-03-02 15:26:38 -05:00
int old_size = fileInfo . peers . size ( ) ;
2018-02-04 16:56:13 -05:00
rsFiles - > FileDetails ( * it , RS_FILE_HINTS_DOWNLOAD , fileInfo ) ;
2018-03-02 15:26:38 -05:00
int new_size = fileInfo . peers . size ( ) ;
if ( old_size < new_size )
{
beginInsertRows ( index ( i , 0 ) , old_size , new_size - 1 ) ;
insertRows ( old_size , new_size - old_size , index ( i , 0 ) ) ;
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " called insert rows ( " < < old_size < < " , " < < new_size - old_size < < " ,index( " < < index ( i , 0 ) < < " )) " < < std : : endl ;
# endif
2018-03-02 15:26:38 -05:00
endInsertRows ( ) ;
}
else if ( new_size < old_size )
{
beginRemoveRows ( index ( i , 0 ) , new_size , old_size - 1 ) ;
removeRows ( new_size , old_size - new_size , index ( i , 0 ) ) ;
2018-03-03 09:49:45 -05:00
# ifdef DEBUG_DOWNLOADLIST
std : : cerr < < " called remove rows ( " < < old_size < < " , " < < old_size - new_size < < " ,index( " < < index ( i , 0 ) < < " )) " < < std : : endl ;
# endif
2018-03-02 15:26:38 -05:00
endRemoveRows ( ) ;
}
2018-02-06 18:25:41 -05:00
2018-03-13 15:25:38 -04:00
uint32_t old_status = mDownloads [ i ] . downloadStatus ;
2018-03-03 09:49:45 -05:00
mDownloads [ i ] = fileInfo ; // ... because insertRows() calls rowCount() which needs to be consistent with the *old* number of rows.
2018-02-04 16:56:13 -05:00
2018-03-13 15:25:38 -04:00
if ( fileInfo . downloadStatus = = FT_STATE_DOWNLOADING | | old_status ! = fileInfo . downloadStatus )
{
QModelIndex topLeft = createIndex ( i , 0 ) , bottomRight = createIndex ( i , COLUMN_COUNT - 1 ) ;
emit dataChanged ( topLeft , bottomRight ) ;
}
2018-03-03 09:49:45 -05:00
// This is apparently not needed.
//
// if(!mDownloads.empty())
// {
// QModelIndex topLeft = createIndex(0,0), bottomRight = createIndex(mDownloads.size()-1, COLUMN_COUNT-1);
// emit dataChanged(topLeft, bottomRight);
// mDownloads[i] = fileInfo ;
// }
2018-03-02 16:57:14 -05:00
}
2018-02-04 16:56:13 -05:00
}
private :
2018-03-03 09:49:45 -05:00
static const uint32_t TRANSFERS_NB_DOWNLOADS_BITS_32BITS = 22 ; // Means 2^22 simultaneous transfers
static const uint32_t TRANSFERS_NB_SOURCES_BITS_32BITS = 10 ; // Means 2^10 simultaneous sources
static const uint32_t TRANSFERS_NB_SOURCES_BIT_MASK_32BITS = ( 1 < < TRANSFERS_NB_SOURCES_BITS_32BITS ) - 1 ; // actual bit mask corresponding to previous number of bits
2018-02-04 16:56:13 -05:00
static bool convertTabEntryToRefPointer ( uint32_t entry , int source_id , void * & ref )
{
if ( source_id < - 1 )
{
std : : cerr < < " (EE) inconsistent source id = " < < source_id < < " in convertTabEntryToRefPointer() " < < std : : endl ;
return false ;
}
// the pointer is formed the following way:
//
2018-03-03 09:49:45 -05:00
// [ 22 bits | 10 bits ]
2018-02-04 16:56:13 -05:00
//
2018-03-03 09:49:45 -05:00
// This means that the whole software has the following build-in limitation:
2018-02-04 16:56:13 -05:00
// * 4M simultaenous file transfers
2018-03-03 09:49:45 -05:00
// * 1023 sources
2018-02-04 16:56:13 -05:00
2018-03-03 09:49:45 -05:00
if ( uint32_t ( source_id + 1 ) > = ( 1u < < TRANSFERS_NB_SOURCES_BITS_32BITS ) | | uint32_t ( entry + 1 ) > = ( 1u < < TRANSFERS_NB_DOWNLOADS_BITS_32BITS ) )
2018-02-04 16:56:13 -05:00
{
std : : cerr < < " (EE) cannot convert download index " < < entry < < " and source " < < source_id < < " to pointer. " < < std : : endl ;
return false ;
}
2018-03-03 09:49:45 -05:00
ref = reinterpret_cast < void * > ( ( uint32_t ( 1 + entry ) < < TRANSFERS_NB_SOURCES_BITS_32BITS ) + ( ( source_id + 1 ) & TRANSFERS_NB_SOURCES_BIT_MASK_32BITS ) ) ;
2018-02-04 16:56:13 -05:00
2018-03-03 09:49:45 -05:00
assert ( ref ! = NULL ) ;
2018-02-04 16:56:13 -05:00
return true ;
}
static bool convertRefPointerToTabEntry ( void * ref , uint32_t & entry , int & source_id )
{
2018-03-03 09:49:45 -05:00
assert ( ref ! = NULL ) ;
2018-02-04 16:56:13 -05:00
// we pack the couple (id of DL, id of source) into a single 32-bits pointer that is required by the AbstractItemModel class.
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
2018-03-03 09:49:45 -05:00
uint32_t src = uint32_t ( * reinterpret_cast < uint32_t * > ( & ref ) & TRANSFERS_NB_SOURCES_BIT_MASK_32BITS ) ;
uint32_t ntr = ( * reinterpret_cast < uint32_t * > ( & ref ) ) > > TRANSFERS_NB_SOURCES_BITS_32BITS ;
2018-02-04 16:56:13 -05:00
# pragma GCC diagnostic pop
if ( ntr = = 0 )
{
std : : cerr < < " ERROR! ntr=0! " < < std : : endl ;
return false ;
}
source_id = int ( src ) - 1 ;
entry = ntr - 1 ;
return true ;
}
std : : vector < FileInfo > mDownloads ; // store the list of downloads, updated from rsFiles.
} ;
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 ) ;
}
2013-07-01 17:03:20 -04:00
QStandardItem * myName = myParent - > child ( index ( ) . row ( ) , COLUMN_NAME ) ;
QStandardItem * otherName = otherParent - > child ( other . index ( ) . row ( ) , COLUMN_NAME ) ;
2011-02-07 19:41:13 -05:00
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 ;
2013-02-27 11:59:16 -05:00
connect ( ui . downloadList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( downloadListCustomPopupMenu ( QPoint ) ) ) ;
2008-12-12 16:42:44 -05:00
2018-02-04 16:56:13 -05:00
DLListModel = new RsDownloadListModel ;
2008-12-12 16:42:44 -05:00
// Set Download list model
2018-02-07 15:57:32 -05:00
DLLFilterModel = new QSortFilterProxyModel ( this ) ;
DLLFilterModel - > setSourceModel ( DLListModel ) ;
DLLFilterModel - > setFilterCaseSensitivity ( Qt : : CaseInsensitive ) ;
ui . downloadList - > setModel ( DLLFilterModel ) ;
2017-09-02 11:57:04 -04:00
2008-12-12 16:42:44 -05:00
DLDelegate = new DLListDelegate ( ) ;
ui . downloadList - > setItemDelegate ( DLDelegate ) ;
2009-05-20 18:06:20 -04:00
2013-07-06 15:34:34 -04:00
QHeaderView * qhvDLList = ui . downloadList - > header ( ) ;
qhvDLList - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( qhvDLList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( downloadListHeaderCustomPopupMenu ( QPoint ) ) ) ;
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
2016-04-22 18:49:42 -04:00
mShortcut = new QShortcut ( QKeySequence ( Qt : : Key_Delete ) , ui . downloadList , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( mShortcut , SIGNAL ( activated ( ) ) , this , SLOT ( cancel ( ) ) ) ;
2010-05-06 10:39:50 -04:00
2017-09-06 13:57:33 -04: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 ) ;
2018-02-04 16:56:13 -05:00
// /* Set header resize modes and initial section sizes Downloads TreeView*/
2017-09-06 13:57:33 -04:00
QHeaderView * dlheader = ui . downloadList - > header ( ) ;
2018-02-07 15:57:32 -05:00
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_NAME , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_SIZE , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_COMPLETED , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_DLSPEED , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_PROGRESS , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_SOURCES , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_STATUS , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_PRIORITY , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_REMAINING , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_DOWNLOADTIME , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_ID , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_LASTDL , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( dlheader , COLUMN_PATH , QHeaderView : : Interactive ) ;
2009-05-20 18:06:20 -04:00
2010-09-14 07:37:50 -04:00
// set default column and sort order for download
2013-07-01 17:03:20 -04:00
ui . downloadList - > sortByColumn ( COLUMN_NAME , Qt : : AscendingOrder ) ;
2017-09-02 11:57:04 -04:00
connect ( ui . filterLineEdit , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( filterChanged ( QString ) ) ) ;
/* Add filter actions */
QString headerName = DLListModel - > headerData ( COLUMN_NAME , Qt : : Horizontal ) . toString ( ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , headerName , COLUMN_NAME , QString ( " %1 %2 " ) . arg ( tr ( " Search " ) , headerName ) ) ;
QString headerID = DLListModel - > headerData ( COLUMN_ID , Qt : : Horizontal ) . toString ( ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , headerID , COLUMN_ID , QString ( " %1 %2 " ) . arg ( tr ( " Search " ) , headerID ) ) ;
2013-08-23 16:46:11 -04:00
connect ( ui . uploadsList , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( uploadsListCustomPopupMenu ( QPoint ) ) ) ;
2009-05-07 18:40:57 -04:00
// Set Upload list model
2013-07-01 17:03:20 -04:00
ULListModel = new QStandardItemModel ( 0 , COLUMN_UCOUNT ) ;
ULListModel - > setHeaderData ( COLUMN_UNAME , Qt : : Horizontal , tr ( " Name " , " i.e: file name " ) ) ;
2017-09-15 08:58:19 -04:00
ULListModel - > setHeaderData ( COLUMN_UPEER , Qt : : Horizontal , tr ( " Peer " , " i.e: user name / tunnel id " ) ) ;
2013-07-01 17:03:20 -04:00
ULListModel - > setHeaderData ( COLUMN_USIZE , Qt : : Horizontal , tr ( " Size " , " i.e: file size " ) ) ;
ULListModel - > setHeaderData ( COLUMN_UTRANSFERRED , Qt : : Horizontal , tr ( " Transferred " , " " ) ) ;
2017-09-06 13:57:33 -04:00
ULListModel - > setHeaderData ( COLUMN_ULSPEED , Qt : : Horizontal , tr ( " Speed " , " i.e: upload speed " ) ) ;
ULListModel - > setHeaderData ( COLUMN_UPROGRESS , Qt : : Horizontal , tr ( " Progress " , " i.e: % uploaded " ) ) ;
2013-07-01 17:03:20 -04:00
ULListModel - > setHeaderData ( COLUMN_UHASH , Qt : : Horizontal , tr ( " Hash " , " " ) ) ;
2017-09-06 13:57:33 -04:00
2008-12-12 16:42:44 -05:00
ui . uploadsList - > setModel ( ULListModel ) ;
2017-09-06 13:57:33 -04:00
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
2017-09-06 13:57:33 -04:00
//Selection Setup
2013-08-23 16:46:11 -04:00
selectionUp = ui . uploadsList - > selectionModel ( ) ;
2017-09-06 13:57:33 -04:00
2010-09-14 07:37:50 -04:00
ui . uploadsList - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
2009-07-24 18:39:34 -04:00
2017-09-06 13:57:33 -04:00
ui . uploadsList - > setRootIsDecorated ( true ) ;
2009-07-24 18:39:34 -04:00
/* Set header resize modes and initial section sizes Uploads TreeView*/
QHeaderView * upheader = ui . uploadsList - > header ( ) ;
2015-06-26 04:14:09 -04:00
QHeaderView_setSectionResizeModeColumn ( upheader , COLUMN_UNAME , QHeaderView : : Interactive ) ;
2017-09-15 08:58:19 -04:00
QHeaderView_setSectionResizeModeColumn ( upheader , COLUMN_UPEER , QHeaderView : : Interactive ) ;
2015-06-26 04:14:09 -04:00
QHeaderView_setSectionResizeModeColumn ( upheader , COLUMN_USIZE , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( upheader , COLUMN_UTRANSFERRED , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( upheader , COLUMN_ULSPEED , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeModeColumn ( upheader , COLUMN_UPROGRESS , QHeaderView : : Interactive ) ;
2013-07-01 17:03:20 -04:00
2014-01-07 15:58:56 -05:00
upheader - > resizeSection ( COLUMN_UNAME , 260 ) ;
2017-09-15 08:58:19 -04:00
upheader - > resizeSection ( COLUMN_UPEER , 120 ) ;
2013-07-01 17:03:20 -04:00
upheader - > resizeSection ( COLUMN_USIZE , 70 ) ;
upheader - > resizeSection ( COLUMN_UTRANSFERRED , 75 ) ;
upheader - > resizeSection ( COLUMN_ULSPEED , 75 ) ;
upheader - > resizeSection ( COLUMN_UPROGRESS , 170 ) ;
2009-07-26 11:02:16 -04:00
2010-09-14 07:37:50 -04:00
// set default column and sort order for upload
2013-07-01 17:03:20 -04:00
ui . uploadsList - > sortByColumn ( COLUMN_UNAME , Qt : : AscendingOrder ) ;
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
2013-02-22 16:42:27 -05:00
ui . tabWidget - > insertTab ( 2 , searchDialog = new SearchDialog ( ) , QIcon ( IMAGE_SEARCH ) , tr ( " Search " ) ) ;
2013-08-15 12:20:14 -04:00
ui . tabWidget - > insertTab ( 3 , remoteSharedFiles = new RemoteSharedFilesDialog ( ) , QIcon ( IMAGE_FRIENDSFILES ) , tr ( " Friends files " ) ) ;
2013-02-22 16:42:27 -05:00
2013-08-15 12:20:14 -04:00
ui . tabWidget - > addTab ( localSharedFiles = new LocalSharedFilesDialog ( ) , QIcon ( IMAGE_MYFILES ) , tr ( " My files " ) ) ;
2011-05-31 17:39:44 -04:00
2012-02-21 16:53:25 -05:00
for ( int i = 0 ; i < rsPlugins - > nbPlugins ( ) ; + + i )
if ( rsPlugins - > plugin ( i ) ! = NULL & & rsPlugins - > plugin ( i ) - > qt_transfers_tab ( ) ! = NULL )
2012-02-28 13:25:57 -05:00
ui . tabWidget - > addTab ( rsPlugins - > plugin ( i ) - > qt_transfers_tab ( ) , QString : : fromUtf8 ( rsPlugins - > plugin ( i ) - > qt_transfers_tab_name ( ) . c_str ( ) ) ) ;
2011-05-28 18:25:42 -04:00
2012-06-01 16:51:14 -04:00
ui . tabWidget - > setCurrentWidget ( ui . uploadsTab ) ;
2013-07-06 15:34:34 -04:00
/** Setup the actions for the context menu */
2013-02-22 16:42:27 -05:00
// Actions. Only need to be defined once.
2010-03-28 16:46:45 -04:00
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 ( ) ) ) ;
2013-08-23 16:46:11 -04:00
openFolderAct = new QAction ( QIcon ( IMAGE_OPENFOLDER ) , tr ( " Open Folder " ) , this ) ;
2017-09-06 13:57:33 -04:00
connect ( openFolderAct , SIGNAL ( triggered ( ) ) , this , SLOT ( dlOpenFolder ( ) ) ) ;
2010-03-28 16:46:45 -04:00
2013-08-23 16:46:11 -04:00
openFileAct = new QAction ( QIcon ( IMAGE_OPENFILE ) , tr ( " Open File " ) , this ) ;
2017-09-06 13:57:33 -04:00
connect ( openFileAct , SIGNAL ( triggered ( ) ) , this , SLOT ( dlOpenFile ( ) ) ) ;
2010-03-28 16:46:45 -04:00
2013-08-23 16:46:11 -04:00
previewFileAct = new QAction ( QIcon ( IMAGE_PREVIEW ) , tr ( " Preview File " ) , this ) ;
2017-09-06 13:57:33 -04:00
connect ( previewFileAct , SIGNAL ( triggered ( ) ) , this , SLOT ( dlPreviewFile ( ) ) ) ;
2010-03-28 16:46:45 -04:00
2013-08-23 16:46:11 -04:00
detailsFileAct = new QAction ( QIcon ( IMAGE_INFO ) , tr ( " Details... " ) , this ) ;
connect ( detailsFileAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showDetailsDialog ( ) ) ) ;
2010-03-28 16:46:45 -04:00
2013-08-23 16:46:11 -04:00
clearCompletedAct = new QAction ( QIcon ( IMAGE_CLEARCOMPLETED ) , tr ( " Clear Completed " ) , this ) ;
connect ( clearCompletedAct , SIGNAL ( triggered ( ) ) , this , SLOT ( clearcompleted ( ) ) ) ;
2010-03-28 16:46:45 -04:00
2010-04-10 10:56:34 -04:00
2013-08-23 16:46:11 -04:00
copyLinkAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Copy RetroShare Link " ) , this ) ;
2017-09-06 13:57:33 -04:00
connect ( copyLinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( dlCopyLink ( ) ) ) ;
2013-08-23 16:46:11 -04:00
pasteLinkAct = new QAction ( QIcon ( IMAGE_PASTELINK ) , tr ( " Paste RetroShare Link " ) , this ) ;
connect ( pasteLinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( pasteLink ( ) ) ) ;
2010-03-28 16:46:45 -04:00
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 ( ) ) ) ;
2013-10-22 12:07:31 -04:00
chunkStreamingAct = new QAction ( QIcon ( IMAGE_STREAMING ) , tr ( " Streaming " ) , this ) ;
2010-03-28 16:46:45 -04:00
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 ( ) ) ) ;
2013-02-28 15:42:01 -05:00
chunkProgressiveAct = new QAction ( QIcon ( IMAGE_PRIORITYAUTO ) , tr ( " Progressive " ) , this ) ;
connect ( chunkProgressiveAct , SIGNAL ( triggered ( ) ) , this , SLOT ( chunkProgressive ( ) ) ) ;
2010-03-28 16:46:45 -04:00
playAct = new QAction ( QIcon ( IMAGE_PLAY ) , tr ( " Play " ) , this ) ;
2017-09-06 13:57:33 -04:00
connect ( playAct , SIGNAL ( triggered ( ) ) , this , SLOT ( dlOpenFile ( ) ) ) ;
2017-09-14 13:22:37 -04:00
renameFileAct = new QAction ( QIcon ( IMAGE_RENAMEFILE ) , tr ( " Rename file... " ) , this ) ;
connect ( renameFileAct , SIGNAL ( triggered ( ) ) , this , SLOT ( renameFile ( ) ) ) ;
specifyDestinationDirectoryAct = new QAction ( QIcon ( IMAGE_SEARCH ) , tr ( " Specify... " ) , this ) ;
connect ( specifyDestinationDirectoryAct , SIGNAL ( triggered ( ) ) , this , SLOT ( chooseDestinationDirectory ( ) ) ) ;
expandAllDLAct = new QAction ( QIcon ( IMAGE_EXPAND ) , tr ( " Expand all " ) , this ) ;
connect ( expandAllDLAct , SIGNAL ( triggered ( ) ) , this , SLOT ( expandAllDL ( ) ) ) ;
collapseAllDLAct = new QAction ( QIcon ( IMAGE_COLLAPSE ) , tr ( " Collapse all " ) , this ) ;
connect ( collapseAllDLAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collapseAllDL ( ) ) ) ;
expandAllULAct = new QAction ( QIcon ( IMAGE_EXPAND ) , tr ( " Expand all " ) , this ) ;
connect ( expandAllULAct , SIGNAL ( triggered ( ) ) , this , SLOT ( expandAllUL ( ) ) ) ;
collapseAllULAct = new QAction ( QIcon ( IMAGE_COLLAPSE ) , tr ( " Collapse all " ) , this ) ;
connect ( collapseAllULAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collapseAllUL ( ) ) ) ;
collCreateAct = new QAction ( QIcon ( IMAGE_COLLCREATE ) , tr ( " Create Collection... " ) , this ) ;
connect ( collCreateAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collCreate ( ) ) ) ;
collModifAct = new QAction ( QIcon ( IMAGE_COLLMODIF ) , tr ( " Modify Collection... " ) , this ) ;
connect ( collModifAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collModif ( ) ) ) ;
collViewAct = new QAction ( QIcon ( IMAGE_COLLVIEW ) , tr ( " View Collection... " ) , this ) ;
connect ( collViewAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collView ( ) ) ) ;
collOpenAct = new QAction ( QIcon ( IMAGE_COLLOPEN ) , tr ( " Download from collection file... " ) , this ) ;
connect ( collOpenAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collOpen ( ) ) ) ;
2010-09-14 19:51:55 -04:00
2013-07-06 15:34:34 -04:00
/** Setup the actions for the header context menu */
showDLSizeAct = new QAction ( tr ( " Size " ) , this ) ;
showDLSizeAct - > setCheckable ( true ) ; showDLSizeAct - > setToolTip ( tr ( " Show Size Column " ) ) ;
connect ( showDLSizeAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLSizeColumn ( bool ) ) ) ;
showDLCompleteAct = new QAction ( tr ( " Completed " ) , this ) ;
showDLCompleteAct - > setCheckable ( true ) ; showDLCompleteAct - > setToolTip ( tr ( " Show Completed Column " ) ) ;
connect ( showDLCompleteAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLCompleteColumn ( bool ) ) ) ;
showDLDLSpeedAct = new QAction ( tr ( " Speed " ) , this ) ;
showDLDLSpeedAct - > setCheckable ( true ) ; showDLDLSpeedAct - > setToolTip ( tr ( " Show Speed Column " ) ) ;
connect ( showDLDLSpeedAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLDLSpeedColumn ( bool ) ) ) ;
showDLProgressAct = new QAction ( tr ( " Progress / Availability " ) , this ) ;
showDLProgressAct - > setCheckable ( true ) ; showDLProgressAct - > setToolTip ( tr ( " Show Progress / Availability Column " ) ) ;
connect ( showDLProgressAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLProgressColumn ( bool ) ) ) ;
showDLSourcesAct = new QAction ( tr ( " Sources " ) , this ) ;
showDLSourcesAct - > setCheckable ( true ) ; showDLSourcesAct - > setToolTip ( tr ( " Show Sources Column " ) ) ;
connect ( showDLSourcesAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLSourcesColumn ( bool ) ) ) ;
showDLStatusAct = new QAction ( tr ( " Status " ) , this ) ;
showDLStatusAct - > setCheckable ( true ) ; showDLStatusAct - > setToolTip ( tr ( " Show Status Column " ) ) ;
connect ( showDLStatusAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLStatusColumn ( bool ) ) ) ;
showDLPriorityAct = new QAction ( tr ( " Speed / Queue position " ) , this ) ;
showDLPriorityAct - > setCheckable ( true ) ; showDLPriorityAct - > setToolTip ( tr ( " Show Speed / Queue position Column " ) ) ;
connect ( showDLPriorityAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLPriorityColumn ( bool ) ) ) ;
showDLRemainingAct = new QAction ( tr ( " Remaining " ) , this ) ;
showDLRemainingAct - > setCheckable ( true ) ; showDLRemainingAct - > setToolTip ( tr ( " Show Remaining Column " ) ) ;
connect ( showDLRemainingAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLRemainingColumn ( bool ) ) ) ;
showDLDownloadTimeAct = new QAction ( tr ( " Download time " ) , this ) ;
showDLDownloadTimeAct - > setCheckable ( true ) ; showDLDownloadTimeAct - > setToolTip ( tr ( " Show Download time Column " ) ) ;
connect ( showDLDownloadTimeAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLDownloadTimeColumn ( bool ) ) ) ;
showDLIDAct = new QAction ( tr ( " Hash " ) , this ) ;
showDLIDAct - > setCheckable ( true ) ; showDLIDAct - > setToolTip ( tr ( " Show Hash Column " ) ) ;
connect ( showDLIDAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLIDColumn ( bool ) ) ) ;
showDLLastDLAct = new QAction ( tr ( " Last Time Seen " ) , this ) ;
showDLLastDLAct - > setCheckable ( true ) ; showDLLastDLAct - > setToolTip ( tr ( " Show Last Time Seen Column " ) ) ;
connect ( showDLLastDLAct , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLLastDLColumn ( bool ) ) ) ;
2013-08-25 16:35:29 -04:00
showDLPath = new QAction ( tr ( " Path " ) , this ) ;
showDLPath - > setCheckable ( true ) ; showDLPath - > setToolTip ( tr ( " Show Path Column " ) ) ;
connect ( showDLPath , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowDLPath ( bool ) ) ) ;
2013-07-06 15:34:34 -04:00
2013-08-23 16:46:11 -04:00
/** Setup the actions for the upload context menu */
ulOpenFolderAct = new QAction ( QIcon ( IMAGE_OPENFOLDER ) , tr ( " Open Folder " ) , this ) ;
connect ( ulOpenFolderAct , SIGNAL ( triggered ( ) ) , this , SLOT ( ulOpenFolder ( ) ) ) ;
ulCopyLinkAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Copy RetroShare Link " ) , this ) ;
connect ( ulCopyLinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( ulCopyLink ( ) ) ) ;
2010-09-14 19:51:55 -04:00
// load settings
processSettings ( true ) ;
2013-07-19 14:36:09 -04:00
2015-06-30 12:44:58 -04:00
int S = QFontMetricsF ( font ( ) ) . height ( ) ;
2013-09-08 11:08:36 -04:00
QString help_str = tr (
2015-06-30 12:44:58 -04:00
" <h1><img width= \" %1 \" src= \" :/icons/help_64.png \" > File Transfer</h1> \
2013-09-08 11:08:36 -04:00
< p > Retroshare brings two ways of transferring files : direct transfers from your friends , and \
distant anonymous tunnelled transfers . In addition , file transfer is multi - source and allows swarming \
( you can be a source while downloading ) < / p > \
2015-06-30 12:44:58 -04:00
< p > You can share files using the < img src = \ " :/images/directoryadd_24x24_shadow.png \" width=%2 /> icon from the left side bar. \
2013-09-08 11:08:36 -04:00
These files will be listed in the My Files tab . You can decide for each friend group whether they can or not see these files \
in their Friends Files tab < / p > \
< p > The search tab reports files from your friends ' file lists , and distant files that can be reached \
anonymously using the multi - hop tunnelling system . < / p > \
2015-06-30 12:44:58 -04:00
" ).arg(QString::number(2*S)).arg(QString::number(S)) ;
2013-07-19 14:36:09 -04:00
2017-02-25 17:52:57 -05:00
registerHelpButton ( ui . helpButton , help_str , " TransfersDialog " ) ;
2010-09-14 19:51:55 -04:00
}
TransfersDialog : : ~ TransfersDialog ( )
{
// save settings
processSettings ( false ) ;
}
2013-02-23 09:29:36 -05:00
void TransfersDialog : : activatePage ( TransfersDialog : : Page page )
{
switch ( page )
{
case TransfersDialog : : SearchTab : ui . tabWidget - > setCurrentWidget ( searchDialog ) ;
break ;
case TransfersDialog : : LocalSharedFilesTab : ui . tabWidget - > setCurrentWidget ( localSharedFiles ) ;
break ;
case TransfersDialog : : RemoteSharedFilesTab : ui . tabWidget - > setCurrentWidget ( remoteSharedFiles ) ;
break ;
}
}
2012-08-05 16:12:55 -04:00
UserNotify * TransfersDialog : : getUserNotify ( QObject * parent )
{
return new TransferUserNotify ( parent ) ;
}
2010-09-14 19:51:55 -04:00
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 the lists
DLHeader - > restoreState ( Settings - > value ( " downloadList " ) . toByteArray ( ) ) ;
ULHeader - > restoreState ( Settings - > value ( " uploadList " ) . toByteArray ( ) ) ;
// state of splitter
2014-01-04 14:54:07 -05:00
ui . splitter - > restoreState ( Settings - > value ( " Splitter " ) . toByteArray ( ) ) ;
2011-08-10 18:47:18 -04:00
2013-07-06 15:34:34 -04:00
setShowDLSizeColumn ( Settings - > value ( " showDLSizeColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_SIZE ) ) . toBool ( ) ) ;
setShowDLCompleteColumn ( Settings - > value ( " showDLCompleteColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_COMPLETED ) ) . toBool ( ) ) ;
setShowDLDLSpeedColumn ( Settings - > value ( " showDLDLSpeedColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_DLSPEED ) ) . toBool ( ) ) ;
setShowDLProgressColumn ( Settings - > value ( " showDLProgressColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_PROGRESS ) ) . toBool ( ) ) ;
setShowDLSourcesColumn ( Settings - > value ( " showDLSourcesColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_SOURCES ) ) . toBool ( ) ) ;
setShowDLStatusColumn ( Settings - > value ( " showDLStatusColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_STATUS ) ) . toBool ( ) ) ;
setShowDLPriorityColumn ( Settings - > value ( " showDLPriorityColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_PRIORITY ) ) . toBool ( ) ) ;
setShowDLRemainingColumn ( Settings - > value ( " showDLRemainingColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_REMAINING ) ) . toBool ( ) ) ;
setShowDLDownloadTimeColumn ( Settings - > value ( " showDLDownloadTimeColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_DOWNLOADTIME ) ) . toBool ( ) ) ;
setShowDLIDColumn ( Settings - > value ( " showDLIDColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_ID ) ) . toBool ( ) ) ;
setShowDLLastDLColumn ( Settings - > value ( " showDLLastDLColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_LASTDL ) ) . toBool ( ) ) ;
2013-08-25 16:35:29 -04:00
setShowDLPath ( Settings - > value ( " showDLPath " , ! ui . downloadList - > isColumnHidden ( COLUMN_PATH ) ) . toBool ( ) ) ;
2013-07-06 15:34:34 -04:00
2011-08-10 18:47:18 -04:00
// selected tab
ui . tabWidget - > setCurrentIndex ( Settings - > value ( " selectedTab " ) . toInt ( ) ) ;
2010-09-14 19:51:55 -04:00
} else {
// save settings
// state of the lists
Settings - > setValue ( " downloadList " , DLHeader - > saveState ( ) ) ;
Settings - > setValue ( " uploadList " , ULHeader - > saveState ( ) ) ;
// state of splitter
2014-01-04 14:54:07 -05:00
Settings - > setValue ( " Splitter " , ui . splitter - > saveState ( ) ) ;
2011-08-10 18:47:18 -04:00
2013-07-06 15:34:34 -04:00
Settings - > setValue ( " showDLSizeColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_SIZE ) ) ;
Settings - > setValue ( " showDLCompleteColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_COMPLETED ) ) ;
Settings - > setValue ( " showDLDLSpeedColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_DLSPEED ) ) ;
Settings - > setValue ( " showDLProgressColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_PROGRESS ) ) ;
Settings - > setValue ( " showDLSourcesColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_SOURCES ) ) ;
Settings - > setValue ( " showDLStatusColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_STATUS ) ) ;
Settings - > setValue ( " showDLPriorityColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_PRIORITY ) ) ;
Settings - > setValue ( " showDLRemainingColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_REMAINING ) ) ;
Settings - > setValue ( " showDLDownloadTimeColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_DOWNLOADTIME ) ) ;
Settings - > setValue ( " showDLIDColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_ID ) ) ;
Settings - > setValue ( " showDLLastDLColumn " , ! ui . downloadList - > isColumnHidden ( COLUMN_LASTDL ) ) ;
2013-08-25 16:35:29 -04:00
Settings - > setValue ( " showDLPath " , ! ui . downloadList - > isColumnHidden ( COLUMN_PATH ) ) ;
2013-07-06 15:34:34 -04:00
2011-08-10 18:47:18 -04:00
// selected tab
Settings - > setValue ( " selectedTab " , ui . tabWidget - > currentIndex ( ) ) ;
2010-09-14 19:51:55 -04:00
}
Settings - > endGroup ( ) ;
m_bProcessSettings = false ;
2008-12-12 16:42:44 -05:00
}
2013-02-27 11:59:16 -05:00
void TransfersDialog : : downloadListCustomPopupMenu ( QPoint /*point*/ )
2008-12-12 16:42:44 -05:00
{
2014-05-29 10:49:45 -04:00
std : : set < RsFileHash > items ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & 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
2014-05-29 10:49:45 -04:00
bool atLeastOne_Waiting = false ;
bool atLeastOne_Downloading = false ;
bool atLeastOne_Complete = false ;
bool atLeastOne_Queued = false ;
bool atLeastOne_Paused = false ;
bool add_PlayOption = false ;
bool add_PreviewOption = false ;
bool add_OpenFileOption = false ;
bool add_CopyLink = false ;
bool add_PasteLink = false ;
bool add_CollActions = false ;
2013-08-26 13:56:30 -04:00
2010-02-19 20:52:44 -05:00
FileInfo info ;
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 ) ;
2013-02-28 15:42:01 -05:00
chunkMenu . addAction ( chunkProgressiveAct ) ;
2010-03-28 16:46:45 -04:00
chunkMenu . addAction ( chunkRandomAct ) ;
2010-01-22 18:23:37 -05:00
2014-05-29 10:49:45 -04:00
QMenu collectionMenu ( tr ( " Collection " ) , this ) ;
collectionMenu . setIcon ( QIcon ( IMAGE_LIBRARY ) ) ;
collectionMenu . addAction ( collCreateAct ) ;
collectionMenu . addAction ( collModifAct ) ;
collectionMenu . addAction ( collViewAct ) ;
collectionMenu . addAction ( collOpenAct ) ;
2013-02-27 11:59:16 -05:00
QMenu contextMnu ( this ) ;
2010-01-26 18:25:00 -05:00
2017-10-21 10:16:23 -04:00
if ( ! RSLinkClipboard : : empty ( RetroShareLink : : TYPE_FILE ) ) add_PasteLink = true ;
if ( ! RSLinkClipboard : : empty ( RetroShareLink : : TYPE_FILE_TREE ) ) add_PasteLink = true ;
2010-01-22 18:23:37 -05:00
if ( ! items . empty ( ) )
{
2014-05-29 10:49:45 -04:00
add_CopyLink = true ;
2010-01-22 18:23:37 -05:00
2014-05-29 10:49:45 -04:00
//Look for all selected items
2017-09-02 11:57:04 -04:00
std : : set < RsFileHash > : : const_iterator it = items . begin ( ) ;
std : : set < RsFileHash > : : const_iterator end = items . end ( ) ;
for ( ; it ! = end ; + + it ) {
RsFileHash fileHash = * it ;
2014-05-29 10:49:45 -04:00
//Look only for first column == File List
2017-09-02 11:57:04 -04:00
//Get Info for current item
2017-10-21 09:44:45 -04:00
if ( rsFiles - > FileDetails ( fileHash , RS_FILE_HINTS_DOWNLOAD , info ) ) {
2014-05-29 10:49:45 -04:00
/*const uint32_t FT_STATE_FAILED = 0x0000;
* const uint32_t FT_STATE_OKAY = 0x0001 ;
* const uint32_t FT_STATE_WAITING = 0x0002 ;
* const uint32_t FT_STATE_DOWNLOADING = 0x0003 ;
* const uint32_t FT_STATE_COMPLETE = 0x0004 ;
* const uint32_t FT_STATE_QUEUED = 0x0005 ;
* const uint32_t FT_STATE_PAUSED = 0x0006 ;
* const uint32_t FT_STATE_CHECKING_HASH = 0x0007 ;
*/
2017-10-21 09:44:45 -04:00
if ( info . downloadStatus = = FT_STATE_WAITING )
2014-05-29 10:49:45 -04:00
atLeastOne_Waiting = true ;
2017-10-21 09:44:45 -04:00
if ( info . downloadStatus = = FT_STATE_DOWNLOADING )
2014-05-29 10:49:45 -04:00
atLeastOne_Downloading = true ;
2017-10-21 09:44:45 -04:00
2014-05-29 10:49:45 -04:00
if ( info . downloadStatus = = FT_STATE_COMPLETE ) {
atLeastOne_Complete = true ;
add_OpenFileOption = single ;
2017-10-19 16:14:04 -04:00
}
2017-10-21 09:44:45 -04:00
if ( info . downloadStatus = = FT_STATE_QUEUED )
2014-05-29 10:49:45 -04:00
atLeastOne_Queued = true ;
2017-10-21 09:44:45 -04:00
if ( info . downloadStatus = = FT_STATE_PAUSED )
2014-05-29 10:49:45 -04:00
atLeastOne_Paused = true ;
size_t pos = info . fname . find_last_of ( ' . ' ) ;
if ( pos ! = std : : string : : npos ) {
// Check if the file is a media file
if ( misc : : isPreviewable ( info . fname . substr ( pos + 1 ) . c_str ( ) ) ) {
add_PreviewOption = ( info . downloadStatus ! = FT_STATE_COMPLETE ) ;
add_PlayOption = ! add_PreviewOption ;
2017-10-19 16:14:04 -04:00
}
2014-05-29 10:49:45 -04:00
// Check if the file is a collection
2017-10-19 16:14:04 -04:00
if ( RsCollection : : ExtensionString = = info . fname . substr ( pos + 1 ) . c_str ( ) ) {
2014-05-29 10:49:45 -04:00
add_CollActions = ( info . downloadStatus = = FT_STATE_COMPLETE ) ;
2017-10-19 16:14:04 -04:00
}
}
2014-05-29 10:49:45 -04:00
2017-10-19 16:14:04 -04:00
}
}
}
2014-05-29 10:49:45 -04:00
2015-10-02 13:40:08 -04:00
if ( atLeastOne_Waiting | | atLeastOne_Downloading | | atLeastOne_Queued | | atLeastOne_Paused ) {
2014-05-29 10:49:45 -04:00
contextMnu . addMenu ( & prioritySpeedMenu ) ;
2015-10-02 13:40:08 -04:00
}
2014-05-29 10:49:45 -04:00
if ( atLeastOne_Queued ) {
contextMnu . addMenu ( & priorityQueueMenu ) ;
2017-10-19 16:14:04 -04:00
}
2014-05-29 10:49:45 -04:00
if ( ( ! items . empty ( ) )
& & ( atLeastOne_Downloading | | atLeastOne_Queued | | atLeastOne_Waiting | | atLeastOne_Paused ) ) {
contextMnu . addMenu ( & chunkMenu ) ;
if ( single ) {
contextMnu . addAction ( renameFileAct ) ;
2017-10-19 16:14:04 -04:00
}
2014-05-29 10:49:45 -04:00
QMenu * directoryMenu = contextMnu . addMenu ( QIcon ( IMAGE_OPENFOLDER ) , tr ( " Set destination directory " ) ) ;
directoryMenu - > addAction ( specifyDestinationDirectoryAct ) ;
// Now get the list of existing directories.
std : : list < SharedDirInfo > dirs ;
rsFiles - > getSharedDirectories ( dirs ) ;
for ( std : : list < SharedDirInfo > : : const_iterator it ( dirs . begin ( ) ) ; it ! = dirs . end ( ) ; + + it ) {
// Check for existence of directory name
QFile directory ( QString : : fromUtf8 ( ( * it ) . filename . c_str ( ) ) ) ;
if ( ! directory . exists ( ) ) continue ;
if ( ! ( directory . permissions ( ) & QFile : : WriteOwner ) ) continue ;
QAction * act = new QAction ( QString : : fromUtf8 ( ( * it ) . virtualname . c_str ( ) ) , directoryMenu ) ;
act - > setData ( QString : : fromUtf8 ( ( * it ) . filename . c_str ( ) ) ) ;
connect ( act , SIGNAL ( triggered ( ) ) , this , SLOT ( setDestinationDirectory ( ) ) ) ;
directoryMenu - > addAction ( act ) ;
2017-10-19 16:14:04 -04:00
}
}
2014-05-29 10:49:45 -04:00
2017-10-21 09:44:45 -04:00
if ( atLeastOne_Paused )
2014-05-29 10:49:45 -04:00
contextMnu . addAction ( resumeAct ) ;
2017-10-21 09:44:45 -04:00
if ( atLeastOne_Downloading | | atLeastOne_Queued | | atLeastOne_Waiting )
2014-05-29 10:49:45 -04:00
contextMnu . addAction ( pauseAct ) ;
if ( ! atLeastOne_Complete & & ! items . empty ( ) ) {
contextMnu . addAction ( forceCheckAct ) ;
contextMnu . addAction ( cancelAct ) ;
2017-10-19 16:14:04 -04:00
}
2017-10-21 09:44:45 -04:00
if ( add_PlayOption )
2014-05-29 10:49:45 -04:00
contextMnu . addAction ( playAct ) ;
2017-10-21 09:44:45 -04:00
if ( atLeastOne_Paused | | atLeastOne_Downloading | | atLeastOne_Complete | | add_PlayOption )
contextMnu . addSeparator ( ) ;
2014-05-29 10:49:45 -04:00
if ( single ) {
if ( add_OpenFileOption ) contextMnu . addAction ( openFileAct ) ;
if ( add_PreviewOption ) contextMnu . addAction ( previewFileAct ) ;
contextMnu . addAction ( openFolderAct ) ;
contextMnu . addAction ( detailsFileAct ) ;
contextMnu . addSeparator ( ) ; //--------------------------------------------
2017-10-19 16:14:04 -04:00
}
2014-05-29 10:49:45 -04:00
contextMnu . addAction ( clearCompletedAct ) ;
2017-10-21 09:44:45 -04:00
contextMnu . addSeparator ( ) ;
2014-05-29 10:49:45 -04:00
if ( add_CopyLink ) {
contextMnu . addAction ( copyLinkAct ) ;
2017-10-19 16:14:04 -04:00
}
2014-05-29 10:49:45 -04:00
if ( add_PasteLink ) {
contextMnu . addAction ( pasteLinkAct ) ;
2017-10-19 16:14:04 -04:00
}
2014-05-29 10:49:45 -04:00
if ( add_CopyLink | | add_PasteLink ) {
2017-10-21 09:44:45 -04:00
contextMnu . addSeparator ( ) ;
2017-10-19 16:14:04 -04:00
}
2010-01-22 18:23:37 -05:00
2017-09-02 11:57:04 -04:00
if ( DLLFilterModel - > rowCount ( ) > 0 ) {
2017-09-14 13:22:37 -04:00
contextMnu . addAction ( expandAllDLAct ) ;
contextMnu . addAction ( collapseAllDLAct ) ;
2013-07-06 11:48:40 -04:00
}
2014-05-29 10:49:45 -04:00
contextMnu . addSeparator ( ) ; //-----------------------------------------------
2013-07-06 11:48:40 -04:00
2014-05-29 10:49:45 -04:00
collCreateAct - > setEnabled ( true ) ;
collModifAct - > setEnabled ( single & & add_CollActions ) ;
collViewAct - > setEnabled ( single & & add_CollActions ) ;
collOpenAct - > setEnabled ( true ) ;
contextMnu . addMenu ( & collectionMenu ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
2008-12-12 16:42:44 -05:00
}
2013-07-06 15:34:34 -04:00
void TransfersDialog : : downloadListHeaderCustomPopupMenu ( QPoint /*point*/ )
{
std : : cerr < < " TransfersDialog::downloadListHeaderCustomPopupMenu() " < < std : : endl ;
QMenu contextMnu ( this ) ;
showDLSizeAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_SIZE ) ) ;
showDLCompleteAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_COMPLETED ) ) ;
showDLDLSpeedAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_DLSPEED ) ) ;
showDLProgressAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_PROGRESS ) ) ;
showDLSourcesAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_SOURCES ) ) ;
showDLStatusAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_STATUS ) ) ;
showDLPriorityAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_PRIORITY ) ) ;
showDLRemainingAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_REMAINING ) ) ;
showDLDownloadTimeAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_DOWNLOADTIME ) ) ;
showDLIDAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_ID ) ) ;
showDLLastDLAct - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_LASTDL ) ) ;
2013-08-25 16:35:29 -04:00
showDLPath - > setChecked ( ! ui . downloadList - > isColumnHidden ( COLUMN_PATH ) ) ;
2013-07-06 15:34:34 -04:00
QMenu * menu = contextMnu . addMenu ( tr ( " Columns " ) ) ;
menu - > addAction ( showDLSizeAct ) ;
menu - > addAction ( showDLCompleteAct ) ;
menu - > addAction ( showDLDLSpeedAct ) ;
menu - > addAction ( showDLProgressAct ) ;
menu - > addAction ( showDLSourcesAct ) ;
menu - > addAction ( showDLStatusAct ) ;
menu - > addAction ( showDLPriorityAct ) ;
menu - > addAction ( showDLRemainingAct ) ;
menu - > addAction ( showDLDownloadTimeAct ) ;
menu - > addAction ( showDLIDAct ) ;
menu - > addAction ( showDLLastDLAct ) ;
2013-08-25 16:35:29 -04:00
menu - > addAction ( showDLPath ) ;
2013-07-06 15:34:34 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
2013-08-23 16:46:11 -04:00
void TransfersDialog : : uploadsListCustomPopupMenu ( QPoint /*point*/ )
{
2017-09-14 13:22:37 -04:00
std : : set < RsFileHash > items ;
getULSelectedItems ( & items , NULL ) ;
2013-08-23 16:46:11 -04:00
2017-09-14 13:22:37 -04:00
bool single = ( items . size ( ) = = 1 ) ;
2013-08-23 16:46:11 -04:00
2017-09-14 13:22:37 -04:00
bool add_CopyLink = ! items . empty ( ) ;
2013-08-23 16:46:11 -04:00
2017-09-14 13:22:37 -04:00
QMenu contextMnu ( this ) ;
if ( single )
contextMnu . addAction ( ulOpenFolderAct ) ;
2013-08-23 16:46:11 -04:00
2017-09-14 13:22:37 -04:00
if ( add_CopyLink )
contextMnu . addAction ( ulCopyLinkAct ) ;
2013-08-23 16:46:11 -04:00
2017-09-14 13:22:37 -04:00
if ( ULListModel - > rowCount ( ) > 0 ) {
if ( single | | add_CopyLink )
contextMnu . addSeparator ( ) ; //-----------------------------------------------
2013-08-23 16:46:11 -04:00
2017-09-14 13:22:37 -04:00
contextMnu . addAction ( expandAllULAct ) ;
contextMnu . addAction ( collapseAllULAct ) ;
}
2013-08-23 16:46:11 -04:00
2017-09-14 13:22:37 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2013-08-23 16:46:11 -04:00
}
2013-02-27 11:59:16 -05:00
void TransfersDialog : : chooseDestinationDirectory ( )
{
QString dest_dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose directory " ) ) ;
if ( dest_dir . isNull ( ) )
return ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2013-02-27 11:59:16 -05:00
2014-03-17 16:56:06 -04:00
for ( std : : set < RsFileHash > : : const_iterator it ( items . begin ( ) ) ; it ! = items . end ( ) ; + + it )
2013-02-27 11:59:16 -05:00
{
std : : cerr < < " Setting new directory " < < dest_dir . toUtf8 ( ) . data ( ) < < " to file " < < * it < < std : : endl ;
2014-03-17 16:56:06 -04:00
rsFiles - > setDestinationDirectory ( * it , dest_dir . toUtf8 ( ) . data ( ) ) ;
2013-02-27 11:59:16 -05:00
}
}
void TransfersDialog : : setDestinationDirectory ( )
{
std : : string dest_dir ( qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toUtf8 ( ) . data ( ) ) ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2013-02-27 11:59:16 -05:00
2014-03-17 16:56:06 -04:00
for ( std : : set < RsFileHash > : : const_iterator it ( items . begin ( ) ) ; it ! = items . end ( ) ; + + it )
2013-02-27 11:59:16 -05:00
{
std : : cerr < < " Setting new directory " < < dest_dir < < " to file " < < * it < < std : : endl ;
rsFiles - > setDestinationDirectory ( * it , dest_dir ) ;
}
}
2018-02-04 16:56:13 -05:00
/*
2017-09-06 13:57:33 -04:00
int TransfersDialog : : addDLItem ( int row , const FileInfo & fileInfo )
2008-12-12 16:42:44 -05:00
{
2017-09-06 13:57:33 -04:00
QString fileHash = QString : : fromStdString ( fileInfo . hash . toStdString ( ) ) ;
2012-06-01 16:51:14 -04:00
double fileDlspeed = ( fileInfo . downloadStatus = = FT_STATE_DOWNLOADING ) ? ( fileInfo . tfRate * 1024.0 ) : 0.0 ;
QString status ;
switch ( fileInfo . 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 ;
case FT_STATE_PAUSED : status = tr ( " Paused " ) ; break ;
case FT_STATE_CHECKING_HASH : status = tr ( " Checking... " ) ; break ;
default : status = tr ( " Unknown " ) ; break ;
}
2010-07-29 17:07:07 -04:00
2017-11-04 08:57:55 -04:00
double priority = PRIORITY_NULL ;
2012-06-01 16:51:14 -04:00
if ( fileInfo . downloadStatus = = FT_STATE_QUEUED ) {
2017-10-29 11:45:45 -04:00
priority = fileInfo . queue_position ;
} else if ( fileInfo . downloadStatus = = FT_STATE_COMPLETE ) {
priority = 0 ;
2012-06-01 16:51:14 -04:00
} else {
switch ( fileInfo . priority ) {
2017-11-04 08:57:55 -04:00
case SPEED_LOW : priority = PRIORITY_SLOWER ; break ;
case SPEED_NORMAL : priority = PRIORITY_AVERAGE ; break ;
case SPEED_HIGH : priority = PRIORITY_FASTER ; break ;
default : priority = PRIORITY_AVERAGE ; break ;
2012-06-01 16:51:14 -04:00
}
}
qlonglong completed = fileInfo . transfered ;
qlonglong remaining = fileInfo . size - fileInfo . transfered ;
2016-04-21 12:58:48 -04:00
qlonglong downloadtime = ( fileInfo . tfRate > 0 ) ? ( ( fileInfo . size - fileInfo . transfered ) / ( fileInfo . tfRate * 1024.0 ) ) : 0 ;
2013-11-28 14:43:14 -05:00
qint64 qi64LastDL = fileInfo . lastTS ; //std::numeric_limits<qint64>::max();
2013-09-01 09:56:05 -04:00
2013-11-28 14:43:14 -05:00
if ( qi64LastDL = = 0 ) // file is complete, or any raison why the time has not been set properly
{
QFileInfo file ;
if ( fileInfo . downloadStatus = = FT_STATE_COMPLETE )
file = QFileInfo ( QString : : fromUtf8 ( fileInfo . path . c_str ( ) ) , QString : : fromUtf8 ( fileInfo . fname . c_str ( ) ) ) ;
else
2014-03-17 16:56:06 -04:00
file = QFileInfo ( QString : : fromUtf8 ( rsFiles - > getPartialsDirectory ( ) . c_str ( ) ) , QString : : fromUtf8 ( fileInfo . hash . toStdString ( ) . c_str ( ) ) ) ;
2013-11-28 14:43:14 -05:00
2018-02-04 16:56:13 -05:00
//Get Last Access on File
2013-11-28 14:43:14 -05:00
if ( file . exists ( ) )
qi64LastDL = file . lastModified ( ) . toTime_t ( ) ;
}
QString strPath = QString : : fromUtf8 ( fileInfo . path . c_str ( ) ) ;
QString strPathAfterDL = strPath ;
strPathAfterDL . replace ( QString : : fromUtf8 ( rsFiles - > getDownloadDirectory ( ) . c_str ( ) ) , " " ) ;
2012-06-01 16:51:14 -04:00
FileChunksInfo fcinfo ;
if ( ! rsFiles - > FileDownloadChunksDetails ( fileInfo . hash , fcinfo ) ) {
return - 1 ;
}
FileProgressInfo pinfo ;
pinfo . cmap = fcinfo . chunks ;
pinfo . type = FileProgressInfo : : DOWNLOAD_LINE ;
pinfo . progress = ( fileInfo . size = = 0 ) ? 0 : ( completed * 100.0 / fileInfo . size ) ;
pinfo . nb_chunks = pinfo . cmap . _map . empty ( ) ? 0 : fcinfo . chunks . size ( ) ;
2012-06-19 17:36:10 -04:00
for ( uint32_t i = 0 ; i < fcinfo . chunks . size ( ) ; + + i )
switch ( fcinfo . chunks [ i ] )
{
case FileChunksInfo : : CHUNK_CHECKING : pinfo . chunks_in_checking . push_back ( i ) ;
break ;
case FileChunksInfo : : CHUNK_ACTIVE : pinfo . chunks_in_progress . push_back ( i ) ;
break ;
2013-06-10 09:27:24 -04:00
case FileChunksInfo : : CHUNK_DONE :
case FileChunksInfo : : CHUNK_OUTSTANDING :
break ;
2012-06-19 17:36:10 -04:00
}
2012-06-01 16:51:14 -04:00
QString tooltip ;
if ( fileInfo . downloadStatus = = FT_STATE_CHECKING_HASH ) {
tooltip = tr ( " If the hash of the downloaded data does \n not correspond to the hash announced \n by the file source. The data is likely \n to be corrupted. \n \n RetroShare will ask the source a detailed \n map of the data; it will compare and invalidate \n bad blocks, and download them again \n \n Try to be patient! " ) ;
}
if ( row < 0 ) {
row = DLListModel - > 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
2017-09-06 13:57:33 -04:00
DLListModel - > setItem ( row , COLUMN_PROGRESS , new ProgressItem ( NULL ) ) ;
2012-06-01 16:51:14 -04:00
2017-09-06 13:57:33 -04:00
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_SIZE ) , QVariant ( ( qlonglong ) fileInfo . size ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_ID ) , fileHash , Qt : : DisplayRole ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_ID ) , fileHash , Qt : : UserRole ) ;
2010-07-29 17:07:07 -04:00
}
2013-02-27 11:59:16 -05:00
QString fileName = QString : : fromUtf8 ( fileInfo . fname . c_str ( ) ) ;
2017-09-06 13:57:33 -04:00
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_NAME ) , fileName ) ;
2018-01-20 11:18:50 -05:00
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_NAME ) , FilesDefs : : getIconFromFilename ( fileName ) , Qt : : DecorationRole ) ;
2017-09-06 13:57:33 -04:00
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_COMPLETED ) , QVariant ( ( qlonglong ) completed ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_DLSPEED ) , QVariant ( ( double ) fileDlspeed ) ) ;
2017-09-07 12:09:21 -04:00
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_PROGRESS ) , QVariant ( ( float ) pinfo . progress ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_PROGRESS ) , QVariant : : fromValue ( pinfo ) , Qt : : UserRole ) ;
2017-09-06 13:57:33 -04:00
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_STATUS ) , QVariant ( status ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_PRIORITY ) , QVariant ( priority ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_REMAINING ) , QVariant ( ( qlonglong ) remaining ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_DOWNLOADTIME ) , QVariant ( ( qlonglong ) downloadtime ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_LASTDL ) , QVariant ( qi64LastDL ) ) ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_PATH ) , QVariant ( strPathAfterDL ) ) ;
DLListModel - > item ( row , COLUMN_PATH ) - > setToolTip ( strPath ) ;
DLListModel - > item ( row , COLUMN_STATUS ) - > setToolTip ( tooltip ) ;
2010-07-29 17:07:07 -04:00
2012-06-01 16:51:14 -04:00
QStandardItem * dlItem = DLListModel - > item ( row ) ;
2010-07-27 12:05:21 -04:00
2012-06-01 16:51:14 -04:00
std : : set < int > used_rows ;
int active = 0 ;
if ( fileInfo . downloadStatus ! = FT_STATE_COMPLETE ) {
2018-02-04 16:56:13 -05:00
for ( std : : vector < TransferInfo > : : const_iterator pit = fileInfo . peers . begin ( ) ; pit ! = fileInfo . peers . end ( ) ; + + pit )
2017-09-06 13:57:33 -04:00
{
2012-06-01 16:51:14 -04:00
const TransferInfo & transferInfo = * pit ;
//unique combination: fileHash + peerId, variant: hash + peerName (too long)
2017-09-06 13:57:33 -04:00
QString hashFileAndPeerId = fileHash + QString : : fromStdString ( transferInfo . peerId . toStdString ( ) ) ;
2012-06-01 16:51:14 -04:00
2017-09-06 13:57:33 -04:00
double peerDlspeed = 0 ;
2012-06-01 16:51:14 -04:00
if ( ( uint32_t ) transferInfo . status = = FT_STATE_DOWNLOADING & & fileInfo . downloadStatus ! = FT_STATE_PAUSED & & fileInfo . downloadStatus ! = FT_STATE_COMPLETE )
peerDlspeed = transferInfo . tfRate * 1024.0 ;
2010-04-10 10:56:34 -04:00
2012-06-01 16:51:14 -04:00
FileProgressInfo peerpinfo ;
peerpinfo . cmap = fcinfo . compressed_peer_availability_maps [ transferInfo . 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
2017-09-16 13:28:50 -04:00
int row_id = addPeerToDLItem ( dlItem , transferInfo . peerId , hashFileAndPeerId , peerDlspeed , transferInfo . status , peerpinfo ) ;
2010-04-10 10:56:34 -04:00
2012-06-01 16:51:14 -04:00
used_rows . insert ( row_id ) ;
2010-04-10 10:56:34 -04:00
2018-02-04 16:56:13 -05:00
// get the sources (number of online peers)
2012-06-01 16:51:14 -04:00
if ( transferInfo . tfRate > 0 & & fileInfo . downloadStatus = = FT_STATE_DOWNLOADING )
2014-10-21 18:33:02 -04:00
+ + active ;
2012-06-01 16:51:14 -04:00
}
}
2010-04-10 10:56:34 -04:00
2013-10-06 08:09:36 -04:00
float fltSources = active + ( float ) fileInfo . peers . size ( ) / 1000 ;
DLListModel - > setData ( DLListModel - > index ( row , COLUMN_SOURCES ) , fltSources ) ;
2010-04-10 10:56:34 -04:00
2012-06-01 16:51:14 -04:00
// 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 ( ) ) {
dlItem - > removeRow ( r ) ;
}
}
2010-04-10 10:56:34 -04:00
2012-06-01 16:51:14 -04:00
return row ;
2009-05-20 18:06:20 -04:00
}
2017-09-16 13:28:50 -04:00
int TransfersDialog : : addPeerToDLItem ( QStandardItem * dlItem , const RsPeerId & peer_ID , const QString & coreID , double dlspeed , uint32_t status , const FileProgressInfo & peerInfo )
2012-06-01 16:51:14 -04:00
{
// try to find the item
int childRow = - 1 ;
2017-09-06 13:57:33 -04:00
QStandardItem * childId = NULL ;
for ( int count = 0 ; ( childId = dlItem - > child ( count , COLUMN_ID ) ) ! = NULL ; + + count ) {
2013-09-10 14:33:22 -04:00
if ( childId - > data ( Qt : : UserRole ) . toString ( ) = = coreID ) {
2012-06-01 16:51:14 -04:00
childRow = count ;
break ;
}
}
2013-08-25 16:35:29 -04:00
QStandardItem * siName = NULL ;
QStandardItem * siStatus = NULL ;
2012-06-01 16:51:14 -04:00
if ( childRow = = - 1 ) {
// set this false if you want to expand on double click
dlItem - > setEditable ( false ) ;
QHeaderView * header = ui . downloadList - > header ( ) ;
2017-09-06 13:57:33 -04:00
QStandardItem * iName = new QStandardItem ( ) ; //COLUMN_NAME
QStandardItem * iSize = new SortByNameItem ( header ) ; //COLUMN_SIZE
QStandardItem * iCompleted = new SortByNameItem ( header ) ; //COLUMN_COMPLETED
QStandardItem * iDlSpeed = new SortByNameItem ( header ) ; //COLUMN_DLSPEED
QStandardItem * iProgress = new ProgressItem ( header ) ; //COLUMN_PROGRESS
QStandardItem * iSource = new SortByNameItem ( header ) ; //COLUMN_SOURCES
QStandardItem * iStatus = new SortByNameItem ( header ) ; //COLUMN_STATUS
QStandardItem * iPriority = new SortByNameItem ( header ) ; //COLUMN_PRIORITY
QStandardItem * iRemaining = new SortByNameItem ( header ) ; //COLUMN_REMAINING
QStandardItem * iDownloadTime = new SortByNameItem ( header ) ; //COLUMN_DOWNLOADTIME
QStandardItem * iID = new SortByNameItem ( header ) ; //COLUMN_ID
QStandardItem * iLastDL = new SortByNameItem ( header ) ; //COLUMN_LASTDL
QStandardItem * iPath = new SortByNameItem ( header ) ; //COLUMN_PATH
siName = iName ;
siStatus = iStatus ;
2012-06-01 16:51:14 -04:00
QList < QStandardItem * > items ;
2017-09-16 13:28:50 -04:00
QString iconName ;
QString tooltip ;
iName - > setData ( QVariant ( getPeerName ( peer_ID , iconName , tooltip ) ) , Qt : : DisplayRole ) ;
iName - > setData ( QIcon ( iconName ) , Qt : : DecorationRole ) ;
iName - > setData ( QVariant ( tooltip ) , Qt : : ToolTipRole ) ;
2017-09-06 13:57:33 -04:00
iSize - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
iCompleted - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
iDlSpeed - > setData ( QVariant ( ( double ) dlspeed ) , Qt : : DisplayRole ) ;
2017-09-07 12:09:21 -04:00
iProgress - > setData ( QVariant ( ( float ) peerInfo . progress ) , Qt : : DisplayRole ) ;
iProgress - > setData ( QVariant : : fromValue ( peerInfo ) , Qt : : UserRole ) ;
2017-09-06 13:57:33 -04:00
iSource - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
2017-11-04 08:57:55 -04:00
iPriority - > setData ( QVariant ( ( double ) PRIORITY_NULL ) , Qt : : DisplayRole ) ; // blank field for priority
2017-09-06 13:57:33 -04:00
iRemaining - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
iDownloadTime - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
iID - > setData ( QVariant ( ) , Qt : : DisplayRole ) ;
iID - > setData ( QVariant ( coreID ) , Qt : : UserRole ) ;
iLastDL - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
iPath - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
items . append ( iName ) ;
items . append ( iSize ) ;
items . append ( iCompleted ) ;
items . append ( iDlSpeed ) ;
items . append ( iProgress ) ;
items . append ( iSource ) ;
items . append ( iStatus ) ;
items . append ( iPriority ) ;
items . append ( iRemaining ) ;
items . append ( iDownloadTime ) ;
items . append ( iID ) ;
items . append ( iLastDL ) ;
items . append ( iPath ) ;
2012-06-01 16:51:14 -04:00
dlItem - > appendRow ( items ) ;
childRow = dlItem - > rowCount ( ) - 1 ;
} else {
// just update the child (peer)
2017-09-06 13:57:33 -04:00
dlItem - > child ( childRow , COLUMN_DLSPEED ) - > setData ( QVariant ( ( double ) dlspeed ) , Qt : : DisplayRole ) ;
2017-09-07 12:09:21 -04:00
dlItem - > child ( childRow , COLUMN_PROGRESS ) - > setData ( QVariant ( ( float ) peerInfo . progress ) , Qt : : DisplayRole ) ;
dlItem - > child ( childRow , COLUMN_PROGRESS ) - > setData ( QVariant : : fromValue ( peerInfo ) , Qt : : UserRole ) ;
2012-06-01 16:51:14 -04:00
2017-09-06 13:57:33 -04:00
siName = dlItem - > child ( childRow , COLUMN_NAME ) ;
siStatus = dlItem - > child ( childRow , COLUMN_STATUS ) ;
2012-06-01 16:51:14 -04:00
}
switch ( status ) {
case FT_STATE_FAILED :
2017-09-06 13:57:33 -04:00
siStatus - > setData ( QVariant ( tr ( " Failed " ) ) ) ;
2017-09-16 13:28:50 -04:00
siName - > setData ( QIcon ( " :/images/Client1.png " ) , Qt : : StatusTipRole ) ;
2012-06-01 16:51:14 -04:00
break ;
2017-09-06 13:57:33 -04:00
case FT_STATE_OKAY :
siStatus - > setData ( QVariant ( tr ( " Okay " ) ) ) ;
2017-09-16 13:28:50 -04:00
siName - > setData ( QIcon ( " :/images/Client2.png " ) , Qt : : StatusTipRole ) ;
2012-06-01 16:51:14 -04:00
break ;
2017-09-06 13:57:33 -04:00
case FT_STATE_WAITING :
siStatus - > setData ( QVariant ( tr ( " " ) ) ) ;
2017-09-16 13:28:50 -04:00
siName - > setData ( QIcon ( " :/images/Client3.png " ) , Qt : : StatusTipRole ) ;
2012-06-01 16:51:14 -04:00
break ;
2017-09-06 13:57:33 -04:00
case FT_STATE_DOWNLOADING :
siStatus - > setData ( QVariant ( tr ( " Transferring " ) ) ) ;
2017-09-16 13:28:50 -04:00
siName - > setData ( QIcon ( " :/images/Client0.png " ) , Qt : : StatusTipRole ) ;
2012-06-01 16:51:14 -04:00
break ;
2017-09-06 13:57:33 -04:00
case FT_STATE_COMPLETE :
siStatus - > setData ( QVariant ( tr ( " Complete " ) ) ) ;
2017-09-16 13:28:50 -04:00
siName - > setData ( QIcon ( " :/images/Client0.png " ) , Qt : : StatusTipRole ) ;
2012-06-01 16:51:14 -04:00
break ;
2017-09-06 13:57:33 -04:00
default :
siStatus - > setData ( QVariant ( tr ( " " ) ) ) ;
2017-09-16 13:28:50 -04:00
siName - > setData ( QIcon ( " :/images/Client4.png " ) , Qt : : StatusTipRole ) ;
2012-06-01 16:51:14 -04:00
}
return childRow ;
}
2018-02-04 16:56:13 -05:00
*/
2008-12-12 16:42:44 -05:00
2017-09-06 13:57:33 -04:00
int TransfersDialog : : addULItem ( int row , const FileInfo & fileInfo )
2008-12-12 16:42:44 -05:00
{
2017-09-16 13:28:50 -04:00
if ( fileInfo . peers . empty ( ) )
return - 1 ; //No Peers, nothing to do.
2017-09-06 13:57:33 -04:00
QString fileHash = QString : : fromStdString ( fileInfo . hash . toStdString ( ) ) ;
RsPeerId ownId = rsPeers - > getOwnId ( ) ;
QString fileName = QString : : fromUtf8 ( fileInfo . fname . c_str ( ) ) ;
qlonglong fileSize = fileInfo . size ;
2010-02-16 21:10:25 -05:00
2017-09-06 13:57:33 -04:00
if ( row < 0 )
2010-07-27 12:05:21 -04:00
{
row = ULListModel - > rowCount ( ) ;
ULListModel - > insertRow ( row ) ;
2010-10-04 16:15:52 -04:00
// change progress column to own class for sorting
2017-09-06 13:57:33 -04:00
//ULListModel->setItem(row, COLUMN_UPROGRESS, new ProgressItem(NULL));
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UNAME ) , fileName ) ;
2018-01-20 11:18:50 -05:00
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UNAME ) , FilesDefs : : getIconFromFilename ( fileName ) , Qt : : DecorationRole ) ;
2017-09-06 13:57:33 -04:00
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UHASH ) , fileHash ) ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UHASH ) , fileHash , Qt : : UserRole ) ;
}
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_USIZE ) , QVariant ( ( qlonglong ) fileSize ) ) ;
2012-06-01 16:51:14 -04:00
2017-09-14 13:22:37 -04:00
//Reset Parent info if child present
2017-09-16 13:28:50 -04:00
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPEER ) , QVariant ( QString ( tr ( " %1 tunnels " ) . arg ( fileInfo . peers . size ( ) ) ) ) ) ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPEER ) , QIcon ( ) , Qt : : DecorationRole ) ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPEER ) , QVariant ( ) , Qt : : ToolTipRole ) ;
2017-09-14 13:22:37 -04:00
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UTRANSFERRED ) , QVariant ( ) ) ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPROGRESS ) , QVariant ( ) ) ;
2017-09-06 13:57:33 -04:00
QStandardItem * ulItem = ULListModel - > item ( row ) ;
std : : set < int > used_rows ;
double peerULSpeedTotal = 0 ;
2017-09-14 13:22:37 -04:00
bool bOnlyOne = ( fileInfo . peers . size ( ) = = 1 ) ;
2012-06-01 16:51:14 -04:00
2018-02-04 16:56:13 -05:00
for ( std : : vector < TransferInfo > : : const_iterator pit = fileInfo . peers . begin ( ) ; pit ! = fileInfo . peers . end ( ) ; + + pit )
2017-09-06 13:57:33 -04:00
{
const TransferInfo & transferInfo = * pit ;
if ( transferInfo . peerId = = ownId ) //don't display transfer to ourselves
continue ;
//unique combination: fileHash + peerId, variant: hash + peerName (too long)
QString hashFileAndPeerId = fileHash + QString : : fromStdString ( transferInfo . peerId . toStdString ( ) ) ;
qlonglong completed = transferInfo . transfered ;
double peerULSpeed = transferInfo . tfRate * 1024.0 ;
FileProgressInfo peerpinfo ;
if ( ! rsFiles - > FileUploadChunksDetails ( fileInfo . hash , transferInfo . peerId , peerpinfo . cmap ) )
continue ;
// Estimate the completion. We need something more accurate, meaning that we need to
// transmit the completion info.
//
uint32_t chunk_size = 1024 * 1024 ;
uint32_t nb_chunks = ( uint32_t ) ( ( fileInfo . size + ( uint64_t ) chunk_size - 1 ) / ( uint64_t ) ( chunk_size ) ) ;
uint32_t filled_chunks = peerpinfo . cmap . filledChunks ( nb_chunks ) ;
peerpinfo . type = FileProgressInfo : : UPLOAD_LINE ;
peerpinfo . nb_chunks = peerpinfo . cmap . _map . empty ( ) ? 0 : nb_chunks ;
if ( filled_chunks > 0 & & nb_chunks > 0 )
{
completed = peerpinfo . cmap . computeProgress ( fileInfo . size , chunk_size ) ;
peerpinfo . progress = completed / ( float ) fileInfo . size * 100.0f ;
}
else
{
completed = transferInfo . transfered % chunk_size ; // use the position with respect to last request.
peerpinfo . progress = ( fileInfo . size > 0 ) ? ( ( transferInfo . transfered % chunk_size ) * 100.0 / fileInfo . size ) : 0 ;
}
2017-09-14 13:22:37 -04:00
if ( bOnlyOne )
{
//Only one peer so update parent
2017-09-16 13:28:50 -04:00
QString iconName ;
QString tooltip ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPEER ) , QVariant ( getPeerName ( transferInfo . peerId , iconName , tooltip ) ) ) ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPEER ) , QIcon ( iconName ) , Qt : : DecorationRole ) ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPEER ) , QVariant ( tooltip ) , Qt : : ToolTipRole ) ;
2017-09-14 13:22:37 -04:00
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UTRANSFERRED ) , QVariant ( completed ) ) ;
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_UPROGRESS ) , QVariant : : fromValue ( peerpinfo ) ) ;
} else {
int row_id = addPeerToULItem ( ulItem , transferInfo . peerId , hashFileAndPeerId , completed , peerULSpeed , peerpinfo ) ;
2017-09-06 13:57:33 -04:00
2017-09-14 13:22:37 -04:00
used_rows . insert ( row_id ) ;
}
2017-09-06 13:57:33 -04:00
peerULSpeedTotal + = peerULSpeed ;
2012-06-01 16:51:14 -04:00
2010-07-27 12:05:21 -04:00
}
2017-09-06 13:57:33 -04:00
// Update Parent UpLoad Speed
ULListModel - > setData ( ULListModel - > index ( row , COLUMN_ULSPEED ) , QVariant ( ( double ) peerULSpeedTotal ) ) ;
// This is not optimal, but we deal with a small number of elements. The reverse order is really important,
// because rows after the deleted rows change positions !
//
for ( int r = ulItem - > rowCount ( ) - 1 ; r > = 0 ; - - r ) {
if ( used_rows . find ( r ) = = used_rows . end ( ) ) {
ulItem - > removeRow ( r ) ;
}
}
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
}
2017-09-06 13:57:33 -04:00
int TransfersDialog : : addPeerToULItem ( QStandardItem * ulItem , const RsPeerId & peer_ID , const QString & coreID , qlonglong completed , double ulspeed , const FileProgressInfo & peerInfo )
{
// try to find the item
int childRow = - 1 ;
QStandardItem * childId = NULL ;
for ( int count = 0 ; ( childId = ulItem - > child ( count , COLUMN_UHASH ) ) ! = NULL ; + + count ) {
if ( childId - > data ( Qt : : UserRole ) . toString ( ) = = coreID ) {
childRow = count ;
break ;
}
}
if ( childRow = = - 1 ) {
// set this false if you want to expand on double click
ulItem - > setEditable ( false ) ;
QHeaderView * header = ui . uploadsList - > header ( ) ;
QStandardItem * iName = new QStandardItem ( ) ; //COLUMN_UNAME
2017-09-15 08:58:19 -04:00
QStandardItem * iPeer = new QStandardItem ( ) ; //COLUMN_UPEER
2017-09-06 13:57:33 -04:00
QStandardItem * iSize = new SortByNameItem ( header ) ; //COLUMN_USIZE
QStandardItem * iTransferred = new SortByNameItem ( header ) ; //COLUMN_UTRANSFERRED
QStandardItem * iULSpeed = new SortByNameItem ( header ) ; //COLUMN_ULSPEED
QStandardItem * iProgress = new ProgressItem ( header ) ; //COLUMN_UPROGRESS
QStandardItem * iHash = new SortByNameItem ( header ) ; //COLUMN_UHASH
QList < QStandardItem * > items ;
2017-09-15 08:58:19 -04:00
iName - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
2017-09-16 13:28:50 -04:00
QString iconName ;
QString tooltip ;
iPeer - > setData ( QVariant ( getPeerName ( peer_ID , iconName , tooltip ) ) , Qt : : DisplayRole ) ;
iPeer - > setData ( QIcon ( iconName ) , Qt : : DecorationRole ) ;
iPeer - > setData ( QVariant ( tooltip ) , Qt : : ToolTipRole ) ;
2017-09-06 13:57:33 -04:00
iSize - > setData ( QVariant ( QString ( ) ) , Qt : : DisplayRole ) ;
iTransferred - > setData ( QVariant ( ( qlonglong ) completed ) , Qt : : DisplayRole ) ;
iULSpeed - > setData ( QVariant ( ( double ) ulspeed ) , Qt : : DisplayRole ) ;
iProgress - > setData ( QVariant : : fromValue ( peerInfo ) , Qt : : DisplayRole ) ;
iHash - > setData ( QVariant ( ) , Qt : : DisplayRole ) ;
iHash - > setData ( QVariant ( coreID ) , Qt : : UserRole ) ;
items . append ( iName ) ;
2017-09-15 08:58:19 -04:00
items . append ( iPeer ) ;
2017-09-06 13:57:33 -04:00
items . append ( iSize ) ;
items . append ( iTransferred ) ;
items . append ( iULSpeed ) ;
items . append ( iProgress ) ;
items . append ( iHash ) ;
ulItem - > appendRow ( items ) ;
childRow = ulItem - > rowCount ( ) - 1 ;
} else {
// just update the child (peer)
ulItem - > child ( childRow , COLUMN_ULSPEED ) - > setData ( QVariant ( ( double ) ulspeed ) , Qt : : DisplayRole ) ;
ulItem - > child ( childRow , COLUMN_UTRANSFERRED ) - > setData ( QVariant ( ( qlonglong ) completed ) , Qt : : DisplayRole ) ;
ulItem - > child ( childRow , COLUMN_UPROGRESS ) - > setData ( QVariant : : fromValue ( peerInfo ) , Qt : : DisplayRole ) ;
}
return childRow ;
}
2009-05-20 18:06:20 -04:00
2012-06-01 16:51:14 -04:00
/* get the list of Transfers from the RsIface. **/
2009-11-17 07:45:06 -05:00
void TransfersDialog : : updateDisplay ( )
{
insertTransfers ( ) ;
2012-06-01 16:51:14 -04:00
updateDetailsDialog ( ) ;
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 ( )
{
2018-02-08 03:07:48 -05:00
// Since downloads use an AstractItemModel, we just need to update it, while saving the selected and expanded items.
2018-02-06 18:25:41 -05:00
std : : set < QString > expanded_hashes ;
2018-02-07 16:59:24 -05:00
std : : set < QString > selected_hashes ;
2018-02-04 16:56:13 -05:00
DLListModel - > update_transfers ( ) ;
2018-02-08 03:07:48 -05:00
// Now show upload hashes. Here we use the "old" way, since the number of uploads is generally not so large.
2010-03-21 17:07:12 -04:00
//
2017-09-06 13:57:33 -04:00
/* disable for performance issues, enable after insert all transfers */
2018-02-09 17:02:27 -05:00
ui . uploadsList - > setSortingEnabled ( false ) ;
2017-09-06 13:57:33 -04:00
/* get the upload lists */
std : : list < RsFileHash > upHashes ;
2010-03-06 18:29:47 -05:00
rsFiles - > FileUploads ( upHashes ) ;
2017-09-06 13:57:33 -04:00
/* build set for quick search */
2018-02-04 16:56:13 -05:00
std : : set < RsFileHash > hashs ;
2010-09-14 19:51:55 -04:00
2017-09-06 13:57:33 -04:00
for ( std : : list < RsFileHash > : : iterator it = upHashes . begin ( ) ; it ! = upHashes . end ( ) ; + + it ) {
hashs . insert ( * it ) ;
}
2010-09-14 19:51:55 -04:00
2017-09-06 13:57:33 -04:00
/* add uploads, first iterate all rows in list */
2010-04-10 10:56:34 -04:00
2018-02-04 16:56:13 -05:00
int rowCount = ULListModel - > rowCount ( ) ;
2010-03-06 18:29:47 -05:00
2017-09-06 13:57:33 -04:00
for ( int row = 0 ; row < rowCount ; ) {
RsFileHash hash ( ULListModel - > item ( row , COLUMN_UHASH ) - > data ( Qt : : UserRole ) . toString ( ) . toStdString ( ) ) ;
2010-03-06 18:29:47 -05:00
2017-09-06 13:57:33 -04:00
std : : set < RsFileHash > : : iterator hashIt = hashs . find ( hash ) ;
if ( hashIt = = hashs . end ( ) ) {
// remove not existing uploads
ULListModel - > removeRow ( row ) ;
rowCount = ULListModel - > rowCount ( ) ;
continue ;
}
2010-04-10 10:56:34 -04:00
2017-09-06 13:57:33 -04:00
FileInfo fileInfo ;
if ( ! rsFiles - > FileDetails ( hash , RS_FILE_HINTS_UPLOAD , fileInfo ) ) {
ULListModel - > removeRow ( row ) ;
rowCount = ULListModel - > rowCount ( ) ;
continue ;
2010-03-06 18:29:47 -05:00
}
2017-09-06 13:57:33 -04:00
hashs . erase ( hashIt ) ;
2010-04-10 10:56:34 -04:00
2017-09-06 13:57:33 -04:00
if ( addULItem ( row , fileInfo ) < 0 ) {
ULListModel - > removeRow ( row ) ;
rowCount = ULListModel - > rowCount ( ) ;
continue ;
2010-03-06 18:29:47 -05:00
}
2017-09-06 13:57:33 -04:00
+ + row ;
2010-04-10 10:56:34 -04:00
}
2017-09-06 13:57:33 -04:00
/* then add new uploads to the list */
for ( std : : set < RsFileHash > : : iterator hashIt = hashs . begin ( )
; hashIt ! = hashs . end ( ) ; + + hashIt )
2010-04-10 10:56:34 -04:00
{
2017-09-06 13:57:33 -04:00
FileInfo fileInfo ;
if ( ! rsFiles - > FileDetails ( * hashIt , RS_FILE_HINTS_UPLOAD , fileInfo ) ) {
continue ;
}
2010-03-06 18:29:47 -05:00
2017-09-06 13:57:33 -04:00
addULItem ( - 1 , fileInfo ) ;
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 ) ;
2015-11-24 13:41:13 -05:00
downloads = tr ( " Downloads " ) + " ( " + QString : : number ( DLListModel - > rowCount ( ) ) + " ) " ;
2017-09-02 11:57:04 -04:00
uploads = tr ( " Uploads " ) + " ( " + QString : : number ( ULListModel - > rowCount ( ) ) + " ) " ;
2015-11-24 13:41:13 -05:00
2017-09-02 11:57:04 -04:00
ui . tabWidget - > setTabText ( 0 , downloads ) ;
ui . tabWidget_UL - > setTabText ( 0 , uploads ) ;
2015-11-24 13:41:13 -05:00
2008-12-12 16:42:44 -05:00
}
2018-02-06 18:25:41 -05:00
QString TransfersDialog : : getPeerName ( const RsPeerId & id , QString & iconName , QString & tooltip )
2009-06-03 14:47:14 -04:00
{
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
2017-09-16 13:28:50 -04:00
// csoler 2009-06-03: This is because turtle tunnels have no name (I didn't want to bother with
2009-06-03 14:47:14 -04:00
// connect mgr). In such a case their id can suitably hold for a name.
//
if ( res = = " " )
2017-09-16 13:28:50 -04:00
{
2017-09-25 15:31:49 -04:00
res = QString : : fromUtf8 ( rsTurtle - > getPeerNameForVirtualPeerId ( id ) . c_str ( ) ) ;
2017-09-16 13:28:50 -04:00
if ( rsFiles - > isEncryptedSource ( id ) )
{
iconName = IMAGE_TUNNEL_ANON_E2E ;
tooltip = tr ( " Anonymous end-to-end encrypted tunnel 0x " ) + QString : : fromStdString ( id . toStdString ( ) ) . left ( 8 ) ;
2017-09-25 14:43:41 -04:00
return tr ( " Tunnel " ) + " via " + res ;
2017-09-16 13:28:50 -04:00
}
iconName = IMAGE_TUNNEL_ANON ;
tooltip = tr ( " Anonymous tunnel 0x " ) + QString : : fromStdString ( id . toStdString ( ) ) . left ( 8 ) ;
2017-09-25 14:50:12 -04:00
return tr ( " Tunnel " ) + " via " + res ;
2017-09-16 13:28:50 -04:00
}
iconName = IMAGE_TUNNEL_FRIEND ;
tooltip = res ;
return res ;
2009-06-03 14:47:14 -04:00
}
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 ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-10-21 18:33:02 -04:00
for ( it = items . begin ( ) ; it ! = items . end ( ) ; + + it ) {
2011-02-07 19:41:13 -05:00
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
2017-09-06 13:57:33 -04:00
void TransfersDialog : : dlCopyLink ( )
2009-05-18 10:23:55 -04:00
{
2011-09-11 18:07:24 -04:00
QList < RetroShareLink > links ;
2009-05-18 10:23:55 -04:00
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2009-05-18 10:23:55 -04:00
2014-10-21 18:33:02 -04:00
for ( it = items . begin ( ) ; it ! = items . end ( ) ; + + it ) {
2011-02-07 19:41:13 -05:00
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
2017-07-16 07:11:47 -04:00
RetroShareLink link = RetroShareLink : : createFile ( QString : : fromUtf8 ( info . fname . c_str ( ) ) , info . size , QString : : fromStdString ( info . hash . toStdString ( ) ) ) ;
if ( link . valid ( ) ) {
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
}
2013-08-23 16:46:11 -04:00
void TransfersDialog : : ulCopyLink ( )
{
QList < RetroShareLink > links ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2013-08-23 16:46:11 -04:00
getULSelectedItems ( & items , NULL ) ;
2014-10-21 18:33:02 -04:00
for ( it = items . begin ( ) ; it ! = items . end ( ) ; + + it ) {
2013-08-23 16:46:11 -04:00
FileInfo info ;
if ( ! rsFiles - > FileDetails ( * it , RS_FILE_HINTS_UPLOAD , info ) ) {
continue ;
}
2017-07-16 07:11:47 -04:00
RetroShareLink link = RetroShareLink : : createFile ( QString : : fromUtf8 ( info . fname . c_str ( ) ) , info . size , QString : : fromStdString ( info . hash . toStdString ( ) ) ) ;
if ( link . valid ( ) ) {
2013-08-23 16:46:11 -04:00
links . push_back ( link ) ;
}
}
RSLinkClipboard : : copyLinks ( links ) ;
}
2013-02-22 16:42:27 -05:00
DetailsDialog * TransfersDialog : : detailsDialog ( )
2010-01-05 19:10:15 -05:00
{
2013-02-22 16:42:27 -05:00
static DetailsDialog * detailsdlg = new DetailsDialog ;
2010-05-03 18:44:53 -04:00
2013-02-22 16:42:27 -05:00
return detailsdlg ;
}
void TransfersDialog : : showDetailsDialog ( )
{
2010-05-03 18:44:53 -04:00
updateDetailsDialog ( ) ;
2013-02-22 16:42:27 -05:00
detailsDialog ( ) - > show ( ) ;
2010-05-03 18:44:53 -04:00
}
void TransfersDialog : : updateDetailsDialog ( )
{
2017-09-02 11:57:04 -04:00
std : : set < RsFileHash > items ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2010-05-03 18:44:53 -04:00
2017-09-02 11:57:04 -04:00
if ( ! items . empty ( ) )
detailsDialog ( ) - > setFileHash ( * items . begin ( ) ) ;
2010-01-05 19:10:15 -05:00
}
2009-05-18 10:23:55 -04:00
void TransfersDialog : : pasteLink ( )
{
2017-10-21 11:35:06 -04:00
QList < RetroShareLink > links ;
// We want to capture and process all links at once here, because we're possibly pasting a large collection of files. So we first
// merge all links into a single RsCollection and then process it.
RsCollection col ;
RSLinkClipboard : : pasteLinks ( links , RetroShareLink : : TYPE_FILE_TREE ) ;
for ( QList < RetroShareLink > : : const_iterator it ( links . begin ( ) ) ; it ! = links . end ( ) ; + + it )
{
FileTree * ft = FileTree : : create ( ( * it ) . radix ( ) . toStdString ( ) ) ;
col . merge_in ( * ft ) ;
}
links . clear ( ) ;
RSLinkClipboard : : pasteLinks ( links , RetroShareLink : : TYPE_FILE ) ;
for ( QList < RetroShareLink > : : const_iterator it ( links . begin ( ) ) ; it ! = links . end ( ) ; + + it )
col . merge_in ( ( * it ) . name ( ) , ( * it ) . size ( ) , RsFileHash ( ( * it ) . hash ( ) . toStdString ( ) ) ) ;
col . downloadFiles ( ) ;
2009-05-18 10:23:55 -04:00
}
2017-09-06 13:57:33 -04:00
void TransfersDialog : : getDLSelectedItems ( std : : set < RsFileHash > * 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
2017-09-02 11:57:04 -04:00
QModelIndexList selectedRows = selection - > selectedRows ( COLUMN_ID ) ;
int i , imax = selectedRows . count ( ) ;
2014-10-21 18:33:02 -04:00
for ( i = 0 ; i < imax ; + + i ) {
2017-09-02 11:57:04 -04:00
QModelIndex index = selectedRows . at ( i ) ;
if ( index . parent ( ) . isValid ( ) )
index = index . model ( ) - > index ( index . parent ( ) . row ( ) , COLUMN_ID ) ;
if ( ids ) {
ids - > insert ( RsFileHash ( index . data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ) ) ;
ids - > insert ( RsFileHash ( index . data ( Qt : : UserRole ) . toString ( ) . toStdString ( ) ) ) ;
2009-07-02 14:40:31 -04:00
}
2017-09-02 11:57:04 -04:00
if ( rows ) {
rows - > insert ( index . row ( ) ) ;
2009-07-02 14:40:31 -04:00
}
2017-09-02 11:57:04 -04:00
2009-07-02 14:40:31 -04:00
}
2009-07-04 17:54:58 -04:00
}
2014-03-17 16:56:06 -04:00
void TransfersDialog : : getULSelectedItems ( std : : set < RsFileHash > * ids , std : : set < int > * rows )
2013-08-23 16:46:11 -04:00
{
if ( ids = = NULL & & rows = = NULL ) {
return ;
}
if ( ids ) ids - > clear ( ) ;
if ( rows ) rows - > clear ( ) ;
QModelIndexList indexes = selectionUp - > selectedIndexes ( ) ;
QModelIndex index ;
foreach ( index , indexes ) {
if ( ids ) {
QStandardItem * id = ULListModel - > item ( index . row ( ) , COLUMN_UHASH ) ;
2014-03-17 16:56:06 -04:00
ids - > insert ( RsFileHash ( id - > data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ) ) ;
2013-08-23 16:46:11 -04:00
}
if ( rows ) {
rows - > insert ( index . row ( ) ) ;
}
}
}
2009-07-04 17:54:58 -04:00
bool TransfersDialog : : controlTransferFile ( uint32_t flags )
{
bool result = true ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-10-21 18:33:02 -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 ;
}
}
2017-09-06 13:57:33 -04:00
void TransfersDialog : : dlOpenFolder ( )
2009-07-02 14:40:31 -04:00
{
FileInfo info ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-10-21 18:33:02 -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 ( ) ) {
2011-11-07 18:07:25 -05:00
if ( ! RsUrlHandler : : openUrl ( QUrl : : fromLocalFile ( qinfo . absoluteFilePath ( ) ) ) ) {
2017-09-06 13:57:33 -04:00
std : : cerr < < " dlOpenFolder(): can't open folder " < < path < < std : : endl ;
2009-07-04 17:54:58 -04:00
}
}
2009-07-05 12:27:58 -04:00
}
2013-08-23 16:46:11 -04:00
void TransfersDialog : : ulOpenFolder ( )
{
FileInfo info ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2013-08-23 16:46:11 -04:00
getULSelectedItems ( & items , NULL ) ;
2014-10-21 18:33:02 -04:00
for ( it = items . begin ( ) ; it ! = items . end ( ) ; + + it ) {
2013-08-23 16:46:11 -04:00
if ( ! rsFiles - > FileDetails ( * it , RS_FILE_HINTS_UPLOAD , info ) ) continue ;
break ;
}
/* make path for uploading files */
QFileInfo qinfo ;
std : : string path ;
path = info . path . substr ( 0 , info . path . length ( ) - info . fname . length ( ) ) ;
/* open folder with a suitable application */
qinfo . setFile ( QString : : fromUtf8 ( path . c_str ( ) ) ) ;
if ( qinfo . exists ( ) & & qinfo . isDir ( ) ) {
if ( ! RsUrlHandler : : openUrl ( QUrl : : fromLocalFile ( qinfo . absoluteFilePath ( ) ) ) ) {
std : : cerr < < " ulOpenFolder(): can't open folder " < < path < < std : : endl ;
}
}
}
2017-09-06 13:57:33 -04:00
void TransfersDialog : : dlPreviewFile ( )
2009-07-05 12:27:58 -04:00
{
FileInfo info ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-10-21 18:33:02 -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 ;
}
2014-04-28 19:20:29 -04:00
QFileInfo fileNameInfo ( QString : : fromUtf8 ( info . fname . c_str ( ) ) ) ;
2009-07-05 12:27:58 -04:00
/* check if the file is a media file */
2014-04-28 19:20:29 -04:00
if ( ! misc : : isPreviewable ( fileNameInfo . suffix ( ) ) ) return ;
2009-07-05 12:27:58 -04:00
/* make path for downloaded or downloading files */
2012-04-04 18:45:40 -04:00
QFileInfo fileInfo ;
2009-07-05 12:27:58 -04:00
if ( info . downloadStatus = = FT_STATE_COMPLETE ) {
2012-04-04 18:45:40 -04:00
fileInfo = QFileInfo ( QString : : fromUtf8 ( info . path . c_str ( ) ) , QString : : fromUtf8 ( info . fname . c_str ( ) ) ) ;
2009-07-05 12:27:58 -04:00
} else {
2014-03-17 16:56:06 -04:00
fileInfo = QFileInfo ( QString : : fromUtf8 ( rsFiles - > getPartialsDirectory ( ) . c_str ( ) ) , QString : : fromUtf8 ( info . hash . toStdString ( ) . c_str ( ) ) ) ;
2012-04-04 18:45:40 -04:00
2014-04-28 19:20:29 -04:00
QDir temp ;
# ifdef WINDOWS_SYS
/* the symbolic link must be created on the same drive like the real file, use partial directory */
temp = fileInfo . absoluteDir ( ) ;
# else
temp = QDir : : temp ( ) ;
# endif
QString linkName = QFileInfo ( temp , fileNameInfo . fileName ( ) ) . absoluteFilePath ( ) ;
if ( RsFile : : CreateLink ( fileInfo . absoluteFilePath ( ) , linkName ) ) {
2012-04-04 18:45:40 -04:00
fileInfo . setFile ( linkName ) ;
} else {
std : : cerr < < " previewTransfer(): can't create link for file " < < fileInfo . absoluteFilePath ( ) . toStdString ( ) < < std : : endl ;
QMessageBox : : warning ( this , tr ( " File preview " ) , tr ( " Can't create link for file %1. " ) . arg ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
2009-07-05 12:27:58 -04:00
}
2009-07-02 14:40:31 -04:00
2012-04-04 18:45:40 -04:00
bool previewStarted = false ;
2009-07-04 17:54:58 -04:00
/* open or preview them with a suitable application */
2012-04-04 18:45:40 -04:00
if ( fileInfo . exists ( ) & & RsUrlHandler : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ) {
previewStarted = true ;
2009-07-28 11:29:21 -04:00
} else {
2012-04-04 18:45:40 -04:00
QMessageBox : : warning ( this , tr ( " File preview " ) , tr ( " File %1 preview failed. " ) . arg ( fileInfo . absoluteFilePath ( ) ) ) ;
std : : cerr < < " previewTransfer(): can't preview file " < < fileInfo . absoluteFilePath ( ) . toStdString ( ) < < std : : endl ;
}
if ( info . downloadStatus ! = FT_STATE_COMPLETE ) {
if ( previewStarted ) {
2009-07-28 11:29:21 -04:00
/* wait for the file to open then remove the link */
2012-04-04 18:45:40 -04:00
QMessageBox : : information ( this , tr ( " File preview " ) , tr ( " Click OK when program terminates! " ) ) ;
2009-07-02 14:40:31 -04:00
}
2014-04-28 19:20:29 -04:00
/* try to delete the preview file */
forever {
if ( QFile : : remove ( fileInfo . absoluteFilePath ( ) ) ) {
/* preview file could be removed */
break ;
}
/* ask user to try it again */
if ( QMessageBox : : question ( this , tr ( " File preview " ) , QString ( " %1 \n \n %2 \n \n %3 " ) . arg ( tr ( " Could not delete preview file " ) , fileInfo . absoluteFilePath ( ) , tr ( " Try it again? " ) ) , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No ) {
break ;
}
}
2009-07-02 14:40:31 -04:00
}
2009-07-04 17:54:58 -04:00
}
2009-07-02 14:40:31 -04:00
2017-09-06 13:57:33 -04:00
void TransfersDialog : : dlOpenFile ( )
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
2014-05-29 10:49:45 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-10-21 18:33:02 -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 ( ) ) {
2011-11-07 18:07:25 -05:00
if ( ! RsUrlHandler : : openUrl ( QUrl : : fromLocalFile ( qinfo . absoluteFilePath ( ) ) ) ) {
2009-07-05 12:27:58 -04:00
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
//
2014-10-21 18:33:02 -04:00
// for (it = items.begin(); it != items.end(); ++it) {
2010-01-26 18:25:00 -05:00
// 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 ) ;
}
2013-02-28 15:42:01 -05:00
void TransfersDialog : : chunkProgressive ( )
{
setChunkStrategy ( FileChunksInfo : : CHUNK_STRATEGY_PROGRESSIVE ) ;
}
2009-12-08 17:29:52 -05:00
void TransfersDialog : : setChunkStrategy ( FileChunksInfo : : ChunkStrategy s )
{
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2009-12-08 17:29:52 -05:00
2014-10-21 18:33:02 -04: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
{
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2009-07-27 13:22:56 -04:00
2014-10-21 18:33:02 -04:00
for ( it = items . begin ( ) ; it ! = items . end ( ) ; + + it )
2010-03-06 18:29:47 -05:00
{
2011-02-07 19:41:13 -05:00
rsFiles - > changeDownloadSpeed ( * it , speed ) ;
2010-01-26 18:25:00 -05:00
}
}
2013-02-27 11:59:16 -05:00
static bool checkFileName ( const QString & name )
{
if ( name . contains ( ' / ' ) ) return false ;
if ( name . contains ( ' \\ ' ) ) return false ;
if ( name . contains ( ' | ' ) ) return false ;
if ( name . contains ( ' : ' ) ) return false ;
if ( name . contains ( ' ? ' ) ) return false ;
if ( name . contains ( ' > ' ) ) return false ;
if ( name . contains ( ' < ' ) ) return false ;
if ( name . contains ( ' * ' ) ) return false ;
if ( name . length ( ) = = 0 )
return false ;
if ( name . length ( ) > 255 )
return false ;
return true ;
}
void TransfersDialog : : renameFile ( )
{
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2010-01-26 18:25:00 -05:00
2013-02-27 11:59:16 -05:00
if ( items . size ( ) ! = 1 )
{
std : : cerr < < " Can't rename more than one file. This should not be called. " < < std : : endl ;
return ;
}
2014-03-17 16:56:06 -04:00
RsFileHash hash = * ( items . begin ( ) ) ;
2013-02-27 11:59:16 -05:00
FileInfo info ;
if ( ! rsFiles - > FileDetails ( hash , RS_FILE_HINTS_DOWNLOAD , info ) )
return ;
bool ok = true ;
bool first = true ;
QString new_name ;
do
{
new_name = QInputDialog : : getText ( NULL , tr ( " Change file name " ) , first ? tr ( " Please enter a new file name " ) : tr ( " Please enter a new--and valid--filename " ) , QLineEdit : : Normal , QString : : fromUtf8 ( info . fname . c_str ( ) ) , & ok ) ;
if ( ! ok )
return ;
first = false ;
}
while ( ! checkFileName ( new_name ) ) ;
rsFiles - > setDestinationName ( hash , new_name . toUtf8 ( ) . data ( ) ) ;
}
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
{
2013-02-27 11:59:16 -05:00
// std::cerr << "In changeQueuePosition (gui)"<< std::endl ;
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2010-01-26 18:25:00 -05:00
2014-10-21 18:33:02 -04:00
for ( it = items . begin ( ) ; it ! = items . end ( ) ; + + it )
2010-01-26 18:25:00 -05:00
{
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 ( )
{
2013-02-23 08:24:16 -05:00
// std::cerr << "TransfersDialog::clearcompleted()" << std::endl;
2011-02-07 19:41:13 -05:00
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
{
2017-09-02 11:57:04 -04:00
std : : set < RsFileHash > items ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2017-09-02 11:57:04 -04:00
if ( items . size ( ) ! = 1 )
detailsDialog ( ) - > setFileHash ( RsFileHash ( ) ) ;
2010-01-11 11:00:42 -05:00
else
2017-09-02 11:57:04 -04:00
detailsDialog ( ) - > setFileHash ( * items . begin ( ) ) ;
2013-02-22 16:42:27 -05: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 )
{
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_DLSPEED ) , Qt : : DisplayRole ) . toDouble ( ) ;
2008-12-12 16:42:44 -05:00
}
QString TransfersDialog : : getFileName ( int row , QStandardItemModel * model )
{
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_NAME ) , Qt : : DisplayRole ) . toString ( ) ;
2008-12-12 16:42:44 -05:00
}
QString TransfersDialog : : getStatus ( int row , QStandardItemModel * model )
{
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_STATUS ) , Qt : : DisplayRole ) . toString ( ) ;
2008-12-12 16:42:44 -05:00
}
QString TransfersDialog : : getID ( int row , QStandardItemModel * model )
{
2013-09-10 14:33:22 -04:00
return model - > data ( model - > index ( row , COLUMN_ID ) , Qt : : UserRole ) . toString ( ) . left ( 40 ) ; // gets only the "hash" part of the name
2008-12-12 16:42:44 -05:00
}
2017-09-02 11:57:04 -04:00
QString TransfersDialog : : getID ( int row , QSortFilterProxyModel * filter )
{
QModelIndex index = filter - > mapToSource ( filter - > index ( row , COLUMN_ID ) ) ;
return filter - > sourceModel ( ) - > data ( index , Qt : : UserRole ) . toString ( ) . left ( 40 ) ; // gets only the "hash" part of the name
}
2009-08-14 16:48:53 -04:00
QString TransfersDialog : : getPriority ( int row , QStandardItemModel * model )
{
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_PRIORITY ) , Qt : : DisplayRole ) . toString ( ) ;
2009-08-14 16:48:53 -04:00
}
2008-12-12 16:42:44 -05:00
qlonglong TransfersDialog : : getFileSize ( int row , QStandardItemModel * model )
{
bool ok = false ;
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_SIZE ) , Qt : : DisplayRole ) . toULongLong ( & ok ) ;
2008-12-12 16:42:44 -05:00
}
qlonglong TransfersDialog : : getTransfered ( int row , QStandardItemModel * model )
{
bool ok = false ;
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_COMPLETED ) , Qt : : DisplayRole ) . toULongLong ( & ok ) ;
2008-12-12 16:42:44 -05:00
}
qlonglong TransfersDialog : : getRemainingTime ( int row , QStandardItemModel * model )
{
bool ok = false ;
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_REMAINING ) , Qt : : DisplayRole ) . toULongLong ( & ok ) ;
2008-12-12 16:42:44 -05:00
}
2011-02-07 19:41:13 -05:00
qlonglong TransfersDialog : : getDownloadTime ( int row , QStandardItemModel * model )
{
2013-07-01 17:03:20 -04:00
return model - > data ( model - > index ( row , COLUMN_DOWNLOADTIME ) , Qt : : DisplayRole ) . toULongLong ( ) ;
}
qlonglong TransfersDialog : : getLastDL ( int row , QStandardItemModel * model )
{
return model - > data ( model - > index ( row , COLUMN_LASTDL ) , Qt : : DisplayRole ) . toULongLong ( ) ;
2011-02-07 19:41:13 -05:00
}
2013-08-25 16:35:29 -04:00
qlonglong TransfersDialog : : getPath ( int row , QStandardItemModel * model )
{
return model - > data ( model - > index ( row , COLUMN_PATH ) , Qt : : DisplayRole ) . toULongLong ( ) ;
}
2011-02-07 19:41:13 -05:00
QString TransfersDialog : : getSources ( int row , QStandardItemModel * model )
{
2013-10-06 08:09:36 -04:00
double dblValue = model - > data ( model - > index ( row , COLUMN_SOURCES ) , Qt : : DisplayRole ) . toDouble ( ) ;
QString temp = QString ( " %1 (%2) " ) . arg ( ( int ) dblValue ) . arg ( ( int ) ( ( fmod ( dblValue , 1 ) * 1000 ) + 0.5 ) ) ;
return temp ;
2011-02-07 19:41:13 -05:00
}
2011-11-25 18:46:41 -05:00
2014-05-29 10:49:45 -04:00
void TransfersDialog : : collCreate ( )
2011-11-25 18:46:41 -05:00
{
2014-05-29 10:49:45 -04:00
std : : vector < DirDetails > dirVec ;
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-05-29 10:49:45 -04:00
2017-11-12 16:46:29 -05:00
for ( it = items . begin ( ) ; it ! = items . end ( ) ; + + it )
{
2014-05-29 10:49:45 -04:00
FileInfo info ;
if ( ! rsFiles - > FileDetails ( * it , RS_FILE_HINTS_DOWNLOAD , info ) ) continue ;
DirDetails details ;
details . name = info . fname ;
details . hash = info . hash ;
details . count = info . size ;
details . type = DIR_TYPE_FILE ;
dirVec . push_back ( details ) ;
2017-11-12 16:46:29 -05:00
}
2014-05-29 10:49:45 -04:00
2017-11-12 16:46:29 -05:00
RsCollection ( dirVec , RS_FILE_HINTS_LOCAL ) . openNewColl ( this ) ;
2014-05-29 10:49:45 -04:00
}
void TransfersDialog : : collModif ( )
{
FileInfo info ;
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-05-29 10:49:45 -04:00
if ( items . size ( ) ! = 1 ) return ;
it = items . begin ( ) ;
RsFileHash hash = * it ;
if ( ! rsFiles - > FileDetails ( hash , RS_FILE_HINTS_DOWNLOAD , info ) ) return ;
/* make path for downloaded files */
if ( info . downloadStatus = = FT_STATE_COMPLETE ) {
std : : string path ;
path = info . path + " / " + info . fname ;
/* open collection */
QFileInfo qinfo ;
qinfo . setFile ( QString : : fromUtf8 ( path . c_str ( ) ) ) ;
if ( qinfo . exists ( ) ) {
2017-10-19 16:14:04 -04:00
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollection : : ExtensionString ) ) {
RsCollection collection ;
2014-05-29 10:49:45 -04:00
collection . openColl ( qinfo . absoluteFilePath ( ) ) ;
2017-10-19 16:14:04 -04:00
}
}
}
2014-05-29 10:49:45 -04:00
}
void TransfersDialog : : collView ( )
{
FileInfo info ;
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-05-29 10:49:45 -04:00
if ( items . size ( ) ! = 1 ) return ;
it = items . begin ( ) ;
RsFileHash hash = * it ;
if ( ! rsFiles - > FileDetails ( hash , RS_FILE_HINTS_DOWNLOAD , info ) ) return ;
/* make path for downloaded files */
if ( info . downloadStatus = = FT_STATE_COMPLETE ) {
std : : string path ;
path = info . path + " / " + info . fname ;
/* open collection */
QFileInfo qinfo ;
qinfo . setFile ( QString : : fromUtf8 ( path . c_str ( ) ) ) ;
if ( qinfo . exists ( ) ) {
2017-10-19 16:14:04 -04:00
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollection : : ExtensionString ) ) {
RsCollection collection ;
2014-05-29 10:49:45 -04:00
collection . openColl ( qinfo . absoluteFilePath ( ) , true ) ;
2017-10-19 16:14:04 -04:00
}
}
}
2014-05-29 10:49:45 -04:00
}
void TransfersDialog : : collOpen ( )
{
FileInfo info ;
std : : set < RsFileHash > items ;
std : : set < RsFileHash > : : iterator it ;
2017-09-06 13:57:33 -04:00
getDLSelectedItems ( & items , NULL ) ;
2014-05-29 10:49:45 -04:00
if ( items . size ( ) = = 1 ) {
it = items . begin ( ) ;
RsFileHash hash = * it ;
if ( rsFiles - > FileDetails ( hash , RS_FILE_HINTS_DOWNLOAD , info ) ) {
/* make path for downloaded files */
if ( info . downloadStatus = = FT_STATE_COMPLETE ) {
std : : string path ;
path = info . path + " / " + info . fname ;
/* open file with a suitable application */
QFileInfo qinfo ;
qinfo . setFile ( QString : : fromUtf8 ( path . c_str ( ) ) ) ;
if ( qinfo . exists ( ) ) {
2017-10-19 16:14:04 -04:00
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollection : : ExtensionString ) ) {
RsCollection collection ;
2016-05-16 05:32:17 -04:00
if ( collection . load ( qinfo . absoluteFilePath ( ) ) ) {
2014-05-29 10:49:45 -04:00
collection . downloadFiles ( ) ;
return ;
2016-05-16 05:32:17 -04:00
}
}
}
}
}
}
2014-05-29 10:49:45 -04:00
2017-10-19 16:14:04 -04:00
RsCollection collection ;
2014-05-29 10:49:45 -04:00
if ( collection . load ( this ) ) {
collection . downloadFiles ( ) ;
2017-10-19 16:14:04 -04:00
}
2011-11-25 18:46:41 -05:00
}
2014-05-29 10:49:45 -04:00
2017-10-21 09:44:45 -04:00
void TransfersDialog : : setShowDLSizeColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_SIZE , ! show ) ; }
void TransfersDialog : : setShowDLCompleteColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_COMPLETED , ! show ) ; }
void TransfersDialog : : setShowDLDLSpeedColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_DLSPEED , ! show ) ; }
void TransfersDialog : : setShowDLProgressColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_PROGRESS , ! show ) ; }
void TransfersDialog : : setShowDLSourcesColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_SOURCES , ! show ) ; }
void TransfersDialog : : setShowDLStatusColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_STATUS , ! show ) ; }
void TransfersDialog : : setShowDLPriorityColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_PRIORITY , ! show ) ; }
void TransfersDialog : : setShowDLRemainingColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_REMAINING , ! show ) ; }
void TransfersDialog : : setShowDLDownloadTimeColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_DOWNLOADTIME , ! show ) ; }
void TransfersDialog : : setShowDLIDColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_ID , ! show ) ; }
void TransfersDialog : : setShowDLLastDLColumn ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_LASTDL , ! show ) ; }
void TransfersDialog : : setShowDLPath ( bool show ) { ui . downloadList - > setColumnHidden ( COLUMN_PATH , ! show ) ; }
2013-08-25 16:35:29 -04:00
2017-09-14 13:22:37 -04:00
void TransfersDialog : : expandAllDL ( )
2013-07-06 11:48:40 -04:00
{
ui . downloadList - > expandAll ( ) ;
}
2017-09-14 13:22:37 -04:00
void TransfersDialog : : collapseAllDL ( )
2013-07-06 11:48:40 -04:00
{
ui . downloadList - > collapseAll ( ) ;
}
2017-09-02 11:57:04 -04:00
2017-09-14 13:22:37 -04:00
void TransfersDialog : : expandAllUL ( )
{
ui . uploadsList - > expandAll ( ) ;
}
void TransfersDialog : : collapseAllUL ( )
{
ui . uploadsList - > collapseAll ( ) ;
}
2017-09-02 11:57:04 -04:00
void TransfersDialog : : filterChanged ( const QString & /*text*/ )
{
int filterColumn = ui . filterLineEdit - > currentFilter ( ) ;
QString text = ui . filterLineEdit - > text ( ) ;
DLLFilterModel - > setFilterKeyColumn ( filterColumn ) ;
DLLFilterModel - > setFilterRegExp ( text ) ;
}