@ -61,6 +61,8 @@
# include "autoexpandabledialog.h"
# include "autoexpandabledialog.h"
# include "transferlistsortmodel.h"
# include "transferlistsortmodel.h"
static QStringList extractHashes ( const QList < BitTorrent : : TorrentHandle * > & torrents ) ;
TransferListWidget : : TransferListWidget ( QWidget * parent , MainWindow * main_window )
TransferListWidget : : TransferListWidget ( QWidget * parent , MainWindow * main_window )
: QTreeView ( parent )
: QTreeView ( parent )
, main_window ( main_window )
, main_window ( main_window )
@ -80,7 +82,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window)
nameFilterModel = new TransferListSortModel ( ) ;
nameFilterModel = new TransferListSortModel ( ) ;
nameFilterModel - > setDynamicSortFilter ( true ) ;
nameFilterModel - > setDynamicSortFilter ( true ) ;
nameFilterModel - > setSourceModel ( listModel ) ;
nameFilterModel - > setSourceModel ( listModel ) ;
nameFilterModel - > setFilterKeyColumn ( TorrentModelItem : : TR_NAME ) ;
nameFilterModel - > setFilterKeyColumn ( TorrentModel : : TR_NAME ) ;
nameFilterModel - > setFilterRole ( Qt : : DisplayRole ) ;
nameFilterModel - > setFilterRole ( Qt : : DisplayRole ) ;
nameFilterModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
nameFilterModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
@ -101,40 +103,40 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window)
// Default hidden columns
// Default hidden columns
if ( ! column_loaded ) {
if ( ! column_loaded ) {
setColumnHidden ( TorrentModelItem : : TR_ADD_DATE , true ) ;
setColumnHidden ( TorrentModel : : TR_ADD_DATE , true ) ;
setColumnHidden ( TorrentModelItem : : TR_SEED_DATE , true ) ;
setColumnHidden ( TorrentModel : : TR_SEED_DATE , true ) ;
setColumnHidden ( TorrentModelItem : : TR_UPLIMIT , true ) ;
setColumnHidden ( TorrentModel : : TR_UPLIMIT , true ) ;
setColumnHidden ( TorrentModelItem : : TR_DLLIMIT , true ) ;
setColumnHidden ( TorrentModel : : TR_DLLIMIT , true ) ;
setColumnHidden ( TorrentModelItem : : TR_TRACKER , true ) ;
setColumnHidden ( TorrentModel : : TR_TRACKER , true ) ;
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_DOWNLOADED , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_DOWNLOADED , true ) ;
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_UPLOADED , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_UPLOADED , true ) ;
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_DOWNLOADED_SESSION , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_DOWNLOADED_SESSION , true ) ;
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_UPLOADED_SESSION , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_UPLOADED_SESSION , true ) ;
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_LEFT , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_LEFT , true ) ;
setColumnHidden ( TorrentModelItem : : TR_TIME_ELAPSED , true ) ;
setColumnHidden ( TorrentModel : : TR_TIME_ELAPSED , true ) ;
setColumnHidden ( TorrentModelItem : : TR_SAVE_PATH , true ) ;
setColumnHidden ( TorrentModel : : TR_SAVE_PATH , true ) ;
setColumnHidden ( TorrentModelItem : : TR_COMPLETED , true ) ;
setColumnHidden ( TorrentModel : : TR_COMPLETED , true ) ;
setColumnHidden ( TorrentModelItem : : TR_RATIO_LIMIT , true ) ;
setColumnHidden ( TorrentModel : : TR_RATIO_LIMIT , true ) ;
setColumnHidden ( TorrentModelItem : : TR_SEEN_COMPLETE_DATE , true ) ;
setColumnHidden ( TorrentModel : : TR_SEEN_COMPLETE_DATE , true ) ;
setColumnHidden ( TorrentModelItem : : TR_LAST_ACTIVITY , true ) ;
setColumnHidden ( TorrentModel : : TR_LAST_ACTIVITY , true ) ;
setColumnHidden ( TorrentModelItem : : TR_TOTAL_SIZE , true ) ;
setColumnHidden ( TorrentModel : : TR_TOTAL_SIZE , true ) ;
}
}
//Ensure that at least one column is visible at all times
//Ensure that at least one column is visible at all times
bool atLeastOne = false ;
bool atLeastOne = false ;
for ( unsigned int i = 0 ; i < TorrentModelItem : : NB_COLUMNS ; i + + ) {
for ( unsigned int i = 0 ; i < TorrentModel : : NB_COLUMNS ; i + + ) {
if ( ! isColumnHidden ( i ) ) {
if ( ! isColumnHidden ( i ) ) {
atLeastOne = true ;
atLeastOne = true ;
break ;
break ;
}
}
}
}
if ( ! atLeastOne )
if ( ! atLeastOne )
setColumnHidden ( TorrentModelItem : : TR_NAME , false ) ;
setColumnHidden ( TorrentModel : : TR_NAME , false ) ;
//When adding/removing columns between versions some may
//When adding/removing columns between versions some may
//end up being size 0 when the new version is launched with
//end up being size 0 when the new version is launched with
//a conf file from the previous version.
//a conf file from the previous version.
for ( unsigned int i = 0 ; i < TorrentModelItem : : NB_COLUMNS ; i + + )
for ( unsigned int i = 0 ; i < TorrentModel : : NB_COLUMNS ; i + + )
if ( ! columnWidth ( i ) )
if ( ! columnWidth ( i ) )
resizeColumnToContents ( i ) ;
resizeColumnToContents ( i ) ;
@ -177,16 +179,6 @@ void TransferListWidget::previewFile(QString filePath)
openUrl ( filePath ) ;
openUrl ( filePath ) ;
}
}
int TransferListWidget : : getRowFromHash ( QString hash ) const
{
return listModel - > torrentRow ( hash ) ;
}
inline QString TransferListWidget : : getHashFromRow ( int row ) const
{
return listModel - > torrentHash ( row ) ;
}
inline QModelIndex TransferListWidget : : mapToSource ( const QModelIndex & index ) const
inline QModelIndex TransferListWidget : : mapToSource ( const QModelIndex & index ) const
{
{
Q_ASSERT ( index . isValid ( ) ) ;
Q_ASSERT ( index . isValid ( ) ) ;
@ -204,9 +196,7 @@ inline QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) c
void TransferListWidget : : torrentDoubleClicked ( const QModelIndex & index )
void TransferListWidget : : torrentDoubleClicked ( const QModelIndex & index )
{
{
const int row = mapToSource ( index ) . row ( ) ;
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mapToSource ( index ) ) ;
const QString hash = getHashFromRow ( row ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( ! torrent ) return ;
if ( ! torrent ) return ;
int action ;
int action ;
@ -227,37 +217,30 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index)
}
}
}
}
QStringList TransferListWidget : : getSelectedTorrentsHashe s ( ) const
QList < BitTorrent : : TorrentHandle * > TransferListWidget : : getSelectedTorrents ( ) const
{
{
QStringList hashe s ;
QList < BitTorrent : : TorrentHandle * > torrent s ;
const QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
foreach ( const QModelIndex & index , selectionModel ( ) - > selectedRows ( ) )
foreach ( const QModelIndex & index , selectedIndexes )
torrents < < listModel - > torrentHandle ( mapToSource ( index ) ) ;
hashes < < getHashFromRow ( mapToSource ( index ) . row ( ) ) ;
return hashe s;
return torrent s;
}
}
void TransferListWidget : : setSelectedTorrentsLocation ( )
void TransferListWidget : : setSelectedTorrentsLocation ( )
{
{
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
const QList < BitTorrent : : TorrentHandle * > torrents = getSelectedTorrents ( ) ;
if ( hashes . isEmpty ( ) ) return ;
if ( torrents . isEmpty ( ) ) return ;
BitTorrent : : TorrentHandle * const firstTorrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hashes . first ( ) ) ;
if ( ! firstTorrent ) return ;
QString dir ;
QString dir ;
const QDir saveDir ( firs tT orrent- > savePath ( ) ) ;
const QDir saveDir ( torrents [ 0 ] - > savePath ( ) ) ;
qDebug ( " Old save path is %s " , qPrintable ( saveDir . absolutePath ( ) ) ) ;
qDebug ( " Old save path is %s " , qPrintable ( saveDir . absolutePath ( ) ) ) ;
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , saveDir . absolutePath ( ) ,
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , saveDir . absolutePath ( ) ,
QFileDialog : : DontConfirmOverwrite | QFileDialog : : ShowDirsOnly | QFileDialog : : HideNameFilterDetails ) ;
QFileDialog : : DontConfirmOverwrite | QFileDialog : : ShowDirsOnly | QFileDialog : : HideNameFilterDetails ) ;
if ( ! dir . isNull ( ) ) {
if ( ! dir . isNull ( ) ) {
qDebug ( " New path is %s " , qPrintable ( dir ) ) ;
qDebug ( " New path is %s " , qPrintable ( dir ) ) ;
foreach ( const QString & hash , hashe s) {
foreach ( BitTorrent : : TorrentHandle * const torrent , torrent s) {
// Actually move storage
// Actually move storage
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( ! torrent ) continue ;
torrent - > move ( Utils : : Fs : : expandPathAbs ( dir ) ) ;
torrent - > move ( Utils : : Fs : : expandPathAbs ( dir ) ) ;
main_window - > getProperties ( ) - > updateSavePath ( torrent ) ;
}
}
}
}
}
}
@ -276,27 +259,20 @@ void TransferListWidget::resumeAllTorrents()
void TransferListWidget : : startSelectedTorrents ( )
void TransferListWidget : : startSelectedTorrents ( )
{
{
foreach ( const QString & hash , getSelectedTorrentsHashes ( ) ) {
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
torrent - > resume ( ) ;
if ( torrent )
torrent - > resume ( ) ;
}
}
}
void TransferListWidget : : forceStartSelectedTorrents ( )
void TransferListWidget : : forceStartSelectedTorrents ( )
{
{
foreach ( const QString & hash , getSelectedTorrentsHashes ( ) ) {
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
torrent - > resume ( true ) ;
if ( torrent )
torrent - > resume ( true ) ;
}
}
}
void TransferListWidget : : startVisibleTorrents ( )
void TransferListWidget : : startVisibleTorrents ( )
{
{
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
const int row = mapToSource ( nameFilterModel - > index ( i , 0 ) ) . row ( ) ;
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mapToSource ( nameFilterModel - > index ( i , 0 ) ) ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( getHashFromRow ( row ) ) ;
if ( torrent )
if ( torrent )
torrent - > resume ( ) ;
torrent - > resume ( ) ;
}
}
@ -304,18 +280,14 @@ void TransferListWidget::startVisibleTorrents()
void TransferListWidget : : pauseSelectedTorrents ( )
void TransferListWidget : : pauseSelectedTorrents ( )
{
{
foreach ( const QString & hash , getSelectedTorrentsHashes ( ) ) {
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
torrent - > pause ( ) ;
if ( torrent )
torrent - > pause ( ) ;
}
}
}
void TransferListWidget : : pauseVisibleTorrents ( )
void TransferListWidget : : pauseVisibleTorrents ( )
{
{
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
const int row = mapToSource ( nameFilterModel - > index ( i , 0 ) ) . row ( ) ;
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mapToSource ( nameFilterModel - > index ( i , 0 ) ) ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( getHashFromRow ( row ) ) ;
if ( torrent )
if ( torrent )
torrent - > pause ( ) ;
torrent - > pause ( ) ;
}
}
@ -324,117 +296,103 @@ void TransferListWidget::pauseVisibleTorrents()
void TransferListWidget : : deleteSelectedTorrents ( )
void TransferListWidget : : deleteSelectedTorrents ( )
{
{
if ( main_window - > getCurrentTabWidget ( ) ! = this ) return ;
if ( main_window - > getCurrentTabWidget ( ) ! = this ) return ;
const QStringList & hashes = getSelectedTorrentsHashes ( ) ;
if ( hashes . empty ( ) ) return ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hashes [ 0 ] ) ;
const QList < BitTorrent : : TorrentHandle * > torrents = getSelectedTorrents ( ) ;
if ( torrents . empty ( ) ) return ;
bool delete_local_files = false ;
bool delete_local_files = false ;
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , hashe s. size ( ) , torrent - > name ( ) ) )
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , torrent s. size ( ) , torrents [ 0 ] - > name ( ) ) )
return ;
return ;
foreach ( const QString & hash , hashe s)
foreach ( BitTorrent : : TorrentHandle * const torrent , torrent s)
BitTorrent : : Session : : instance ( ) - > deleteTorrent ( hash , delete_local_files ) ;
BitTorrent : : Session : : instance ( ) - > deleteTorrent ( torrent - > hash ( ) , delete_local_files ) ;
}
}
void TransferListWidget : : deleteVisibleTorrents ( )
void TransferListWidget : : deleteVisibleTorrents ( )
{
{
if ( nameFilterModel - > rowCount ( ) < = 0 ) return ;
if ( nameFilterModel - > rowCount ( ) < = 0 ) return ;
QStringList hashes ;
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
const int row = mapToSource ( nameFilterModel - > index ( i , 0 ) ) . row ( ) ;
hashes < < getHashFromRow ( row ) ;
}
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hashes [ 0 ] ) ;
QList < BitTorrent : : TorrentHandle * > torrents ;
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i )
torrents < < listModel - > torrentHandle ( mapToSource ( nameFilterModel - > index ( i , 0 ) ) ) ;
bool delete_local_files = false ;
bool delete_local_files = false ;
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , hashes . size ( ) , torrent - > name ( ) ) )
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , torrent s. size ( ) , torrents [ 0 ] - > name ( ) ) )
return ;
return ;
foreach ( const QString & hash , hashe s)
foreach ( BitTorrent : : TorrentHandle * const torrent , torrent s)
BitTorrent : : Session : : instance ( ) - > deleteTorrent ( hash , delete_local_files ) ;
BitTorrent : : Session : : instance ( ) - > deleteTorrent ( torrent - > hash ( ) , delete_local_files ) ;
}
}
void TransferListWidget : : increasePrioSelectedTorrents ( )
void TransferListWidget : : increasePrioSelectedTorrents ( )
{
{
qDebug ( ) < < Q_FUNC_INFO ;
qDebug ( ) < < Q_FUNC_INFO ;
if ( main_window - > getCurrentTabWidget ( ) = = this )
if ( main_window - > getCurrentTabWidget ( ) = = this )
BitTorrent : : Session : : instance ( ) - > increaseTorrentsPriority ( getSelectedTorrentsHashes ( ) ) ;
BitTorrent : : Session : : instance ( ) - > increaseTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
}
}
void TransferListWidget : : decreasePrioSelectedTorrents ( )
void TransferListWidget : : decreasePrioSelectedTorrents ( )
{
{
qDebug ( ) < < Q_FUNC_INFO ;
qDebug ( ) < < Q_FUNC_INFO ;
if ( main_window - > getCurrentTabWidget ( ) = = this )
if ( main_window - > getCurrentTabWidget ( ) = = this )
BitTorrent : : Session : : instance ( ) - > decreaseTorrentsPriority ( getSelectedTorrentsHashes ( ) ) ;
BitTorrent : : Session : : instance ( ) - > decreaseTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
}
}
void TransferListWidget : : topPrioSelectedTorrents ( )
void TransferListWidget : : topPrioSelectedTorrents ( )
{
{
if ( main_window - > getCurrentTabWidget ( ) = = this )
if ( main_window - > getCurrentTabWidget ( ) = = this )
BitTorrent : : Session : : instance ( ) - > topTorrentsPriority ( getSelectedTorrentsHashes ( ) ) ;
BitTorrent : : Session : : instance ( ) - > topTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
}
}
void TransferListWidget : : bottomPrioSelectedTorrents ( )
void TransferListWidget : : bottomPrioSelectedTorrents ( )
{
{
if ( main_window - > getCurrentTabWidget ( ) = = this )
if ( main_window - > getCurrentTabWidget ( ) = = this )
BitTorrent : : Session : : instance ( ) - > bottomTorrentsPriority ( getSelectedTorrentsHashes ( ) ) ;
BitTorrent : : Session : : instance ( ) - > bottomTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
}
}
void TransferListWidget : : copySelectedMagnetURIs ( ) const
void TransferListWidget : : copySelectedMagnetURIs ( ) const
{
{
QStringList magnet_uris ;
QStringList magnet_uris ;
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
foreach ( const QString & hash , hashes ) {
magnet_uris < < torrent - > toMagnetUri ( ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent )
magnet_uris < < torrent - > toMagnetUri ( ) ;
}
qApp - > clipboard ( ) - > setText ( magnet_uris . join ( " \n " ) ) ;
qApp - > clipboard ( ) - > setText ( magnet_uris . join ( " \n " ) ) ;
}
}
void TransferListWidget : : copySelectedNames ( ) const
void TransferListWidget : : copySelectedNames ( ) const
{
{
QStringList torrent_names ;
QStringList torrent_names ;
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
foreach ( const QString & hash , hashes ) {
torrent_names < < torrent - > name ( ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent )
torrent_names < < torrent - > name ( ) ;
}
qApp - > clipboard ( ) - > setText ( torrent_names . join ( " \n " ) ) ;
qApp - > clipboard ( ) - > setText ( torrent_names . join ( " \n " ) ) ;
}
}
void TransferListWidget : : hidePriorityColumn ( bool hide )
void TransferListWidget : : hidePriorityColumn ( bool hide )
{
{
qDebug ( " hidePriorityColumn(%d) " , hide ) ;
qDebug ( " hidePriorityColumn(%d) " , hide ) ;
setColumnHidden ( TorrentModelItem : : TR_PRIORITY , hide ) ;
setColumnHidden ( TorrentModel : : TR_PRIORITY , hide ) ;
if ( ! hide & & ! columnWidth ( TorrentModelItem : : TR_PRIORITY ) )
if ( ! hide & & ! columnWidth ( TorrentModel : : TR_PRIORITY ) )
resizeColumnToContents ( TorrentModelItem : : TR_PRIORITY ) ;
resizeColumnToContents ( TorrentModel : : TR_PRIORITY ) ;
}
}
void TransferListWidget : : openSelectedTorrentsFolder ( ) const
void TransferListWidget : : openSelectedTorrentsFolder ( ) const
{
{
QSet < QString > pathsList ;
QSet < QString > pathsList ;
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
foreach ( const QString & hash , hashes ) {
QString rootFolder = torrent - > rootPath ( ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
qDebug ( " Opening path at %s " , qPrintable ( rootFolder ) ) ;
if ( torrent ) {
if ( ! pathsList . contains ( rootFolder ) ) {
QString rootFolder = torrent - > rootPath ( ) ;
pathsList . insert ( rootFolder ) ;
qDebug ( " Opening path at %s " , qPrintable ( rootFolder ) ) ;
openUrl ( rootFolder ) ;
if ( ! pathsList . contains ( rootFolder ) ) {
pathsList . insert ( rootFolder ) ;
openUrl ( rootFolder ) ;
}
}
}
}
}
}
}
void TransferListWidget : : previewSelectedTorrents ( )
void TransferListWidget : : previewSelectedTorrents ( )
{
{
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
foreach ( const QString & hash , hashes ) {
if ( torrent - > hasMetadata ( ) )
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent & & torrent - > hasMetadata ( ) )
new PreviewSelect ( this , torrent ) ;
new PreviewSelect ( this , torrent ) ;
}
}
}
}
@ -444,19 +402,17 @@ void TransferListWidget::setDlLimitSelectedTorrents()
QList < BitTorrent : : TorrentHandle * > selected_torrents ;
QList < BitTorrent : : TorrentHandle * > selected_torrents ;
bool first = true ;
bool first = true ;
bool all_same_limit = true ;
bool all_same_limit = true ;
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
foreach ( const QString & hash , hashes ) {
if ( ! torrent - > isSeed ( ) ) {
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent & & ! torrent - > isSeed ( ) ) {
selected_torrents < < torrent ;
selected_torrents < < torrent ;
// Determine current limit for selected torrents
// Determine current limit for selected torrents
if ( first )
if ( first )
first = false ;
first = false ;
else
else if ( all_same_limit & & ( torrent - > downloadLimit ( ) ! = selected_torrents . first ( ) - > downloadLimit ( ) ) )
if ( all_same_limit & & ( torrent - > downloadLimit ( ) ! = selected_torrents . first ( ) - > downloadLimit ( ) ) )
all_same_limit = false ;
all_same_limit = false ;
}
}
}
}
if ( selected_torrents . empty ( ) ) return ;
if ( selected_torrents . empty ( ) ) return ;
bool ok = false ;
bool ok = false ;
@ -477,19 +433,15 @@ void TransferListWidget::setUpLimitSelectedTorrents()
QList < BitTorrent : : TorrentHandle * > selected_torrents ;
QList < BitTorrent : : TorrentHandle * > selected_torrents ;
bool first = true ;
bool first = true ;
bool all_same_limit = true ;
bool all_same_limit = true ;
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
foreach ( const QString & hash , hashes ) {
selected_torrents < < torrent ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
// Determine current limit for selected torrents
if ( torrent ) {
if ( first )
selected_torrents < < torrent ;
first = false ;
// Determine current limit for selected torrents
else if ( all_same_limit & & ( torrent - > uploadLimit ( ) ! = selected_torrents . first ( ) - > uploadLimit ( ) ) )
if ( first )
all_same_limit = false ;
first = false ;
else
if ( all_same_limit & & ( torrent - > uploadLimit ( ) ! = selected_torrents . first ( ) - > uploadLimit ( ) ) )
all_same_limit = false ;
}
}
}
if ( selected_torrents . empty ( ) ) return ;
if ( selected_torrents . empty ( ) ) return ;
bool ok = false ;
bool ok = false ;
@ -507,26 +459,20 @@ void TransferListWidget::setUpLimitSelectedTorrents()
void TransferListWidget : : setMaxRatioSelectedTorrents ( )
void TransferListWidget : : setMaxRatioSelectedTorrents ( )
{
{
const QStringList hashe s = getSelectedTorrentsHashe s ( ) ;
const QList < BitTorrent : : TorrentHandle * > torrent s = getSelectedTorrents ( ) ;
if ( hashe s. isEmpty ( ) )
if ( torrent s. isEmpty ( ) ) return ;
return ;
bool useGlobalValue = true ;
bool useGlobalValue = true ;
qreal currentMaxRatio = BitTorrent : : Session : : instance ( ) - > globalMaxRatio ( ) ; ;
qreal currentMaxRatio = BitTorrent : : Session : : instance ( ) - > globalMaxRatio ( ) ; ;
if ( hashes . count ( ) = = 1 ) {
if ( torrents . count ( ) = = 1 )
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hashes . first ( ) ) ;
currentMaxRatio = torrents [ 0 ] - > maxRatio ( & useGlobalValue ) ;
if ( torrent )
currentMaxRatio = torrent - > maxRatio ( & useGlobalValue ) ;
}
UpDownRatioDlg dlg ( useGlobalValue , currentMaxRatio , BitTorrent : : TorrentHandle : : MAX_RATIO , this ) ;
UpDownRatioDlg dlg ( useGlobalValue , currentMaxRatio , BitTorrent : : TorrentHandle : : MAX_RATIO , this ) ;
if ( dlg . exec ( ) ! = QDialog : : Accepted ) return ;
if ( dlg . exec ( ) ! = QDialog : : Accepted ) return ;
foreach ( const QString & hash , hashes ) {
foreach ( BitTorrent : : TorrentHandle * const torrent , torrents ) {
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
qreal ratio = ( dlg . useDefault ( ) ? BitTorrent : : TorrentHandle : : USE_GLOBAL_RATIO : dlg . ratio ( ) ) ;
if ( torrent ) {
torrent - > setRatioLimit ( ratio ) ;
qreal ratio = ( dlg . useDefault ( ) ? BitTorrent : : TorrentHandle : : USE_GLOBAL_RATIO : dlg . ratio ( ) ) ;
torrent - > setRatioLimit ( ratio ) ;
}
}
}
}
}
@ -535,12 +481,8 @@ void TransferListWidget::recheckSelectedTorrents()
QMessageBox : : StandardButton ret = QMessageBox : : question ( this , tr ( " Recheck confirmation " ) , tr ( " Are you sure you want to recheck the selected torrent(s)? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ;
QMessageBox : : StandardButton ret = QMessageBox : : question ( this , tr ( " Recheck confirmation " ) , tr ( " Are you sure you want to recheck the selected torrent(s)? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ;
if ( ret ! = QMessageBox : : Yes ) return ;
if ( ret ! = QMessageBox : : Yes ) return ;
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
foreach ( const QString & hash , hashes ) {
torrent - > forceRecheck ( ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent )
torrent - > forceRecheck ( ) ;
}
}
}
// hide/show columns menu
// hide/show columns menu
@ -550,7 +492,7 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&)
hideshowColumn . setTitle ( tr ( " Column visibility " ) ) ;
hideshowColumn . setTitle ( tr ( " Column visibility " ) ) ;
QList < QAction * > actions ;
QList < QAction * > actions ;
for ( int i = 0 ; i < listModel - > columnCount ( ) ; + + i ) {
for ( int i = 0 ; i < listModel - > columnCount ( ) ; + + i ) {
if ( ! BitTorrent : : Session : : instance ( ) - > isQueueingEnabled ( ) & & i = = TorrentModelItem : : TR_PRIORITY ) {
if ( ! BitTorrent : : Session : : instance ( ) - > isQueueingEnabled ( ) & & i = = TorrentModel : : TR_PRIORITY ) {
actions . append ( 0 ) ;
actions . append ( 0 ) ;
continue ;
continue ;
}
}
@ -560,7 +502,7 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&)
actions . append ( myAct ) ;
actions . append ( myAct ) ;
}
}
int visibleCols = 0 ;
int visibleCols = 0 ;
for ( unsigned int i = 0 ; i < TorrentModelItem : : NB_COLUMNS ; i + + ) {
for ( unsigned int i = 0 ; i < TorrentModel : : NB_COLUMNS ; i + + ) {
if ( ! isColumnHidden ( i ) )
if ( ! isColumnHidden ( i ) )
visibleCols + + ;
visibleCols + + ;
@ -586,32 +528,22 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&)
void TransferListWidget : : toggleSelectedTorrentsSuperSeeding ( ) const
void TransferListWidget : : toggleSelectedTorrentsSuperSeeding ( ) const
{
{
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
foreach ( const QString & hash , hashes ) {
if ( torrent - > hasMetadata ( ) )
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent & & torrent - > hasMetadata ( ) )
torrent - > setSuperSeeding ( ! torrent - > superSeeding ( ) ) ;
torrent - > setSuperSeeding ( ! torrent - > superSeeding ( ) ) ;
}
}
}
}
void TransferListWidget : : toggleSelectedTorrentsSequentialDownload ( ) const
void TransferListWidget : : toggleSelectedTorrentsSequentialDownload ( ) const
{
{
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
foreach ( const QString & hash , hashes ) {
torrent - > toggleSequentialDownload ( ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent )
torrent - > toggleSequentialDownload ( ) ;
}
}
}
void TransferListWidget : : toggleSelectedFirstLastPiecePrio ( ) const
void TransferListWidget : : toggleSelectedFirstLastPiecePrio ( ) const
{
{
QStringList hashes = getSelectedTorrentsHashes ( ) ;
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
foreach ( const QString & hash , hashes ) {
torrent - > setFirstLastPiecePriority ( ! torrent - > hasFirstLastPiecePriority ( ) ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
if ( torrent )
torrent - > setFirstLastPiecePriority ( ! torrent - > hasFirstLastPiecePriority ( ) ) ;
}
}
}
void TransferListWidget : : askNewLabelForSelection ( )
void TransferListWidget : : askNewLabelForSelection ( )
@ -649,9 +581,9 @@ void TransferListWidget::renameSelectedTorrent()
const QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
const QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
if ( selectedIndexes . size ( ) ! = 1 ) return ;
if ( selectedIndexes . size ( ) ! = 1 ) return ;
if ( ! selectedIndexes . first ( ) . isValid ( ) ) return ;
if ( ! selectedIndexes . first ( ) . isValid ( ) ) return ;
QModelIndex mi = listModel - > index ( mapToSource ( selectedIndexes . first ( ) ) . row ( ) , TorrentModelItem : : TR_NAME ) ;
const QString hash = getHashFromRow ( mi . row ( ) ) ;
const QModelIndex mi = listModel - > index ( mapToSource ( selectedIndexes . first ( ) ) . row ( ) , TorrentModel : : TR_NAME ) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mi ) ;
if ( ! torrent ) return ;
if ( ! torrent ) return ;
// Ask for a new Name
// Ask for a new Name
@ -666,19 +598,15 @@ void TransferListWidget::renameSelectedTorrent()
void TransferListWidget : : setSelectionLabel ( QString label )
void TransferListWidget : : setSelectionLabel ( QString label )
{
{
const QStringList & hashes = getSelectedTorrentsHashes ( ) ;
foreach ( const QModelIndex & index , selectionModel ( ) - > selectedRows ( ) )
foreach ( const QString & hash , hashes ) {
listModel - > setData ( listModel - > index ( mapToSource ( index ) . row ( ) , TorrentModel : : TR_LABEL ) , label , Qt : : DisplayRole ) ;
Q_ASSERT ( ! hash . isEmpty ( ) ) ;
const int row = getRowFromHash ( hash ) ;
listModel - > setData ( listModel - > index ( row , TorrentModelItem : : TR_LABEL ) , QVariant ( label ) , Qt : : DisplayRole ) ;
}
}
}
void TransferListWidget : : removeLabelFromRows ( QString label )
void TransferListWidget : : removeLabelFromRows ( QString label )
{
{
for ( int i = 0 ; i < listModel - > rowCount ( ) ; + + i ) {
for ( int i = 0 ; i < listModel - > rowCount ( ) ; + + i ) {
if ( listModel - > data ( listModel - > index ( i , TorrentModelItem : : TR_LABEL ) ) = = label ) {
if ( listModel - > data ( listModel - > index ( i , TorrentModel : : TR_LABEL ) ) = = label ) {
listModel - > setData ( listModel - > index ( i , TorrentModelItem : : TR_LABEL ) , " " , Qt : : DisplayRole ) ;
listModel - > setData ( listModel - > index ( i , TorrentModel : : TR_LABEL ) , " " , Qt : : DisplayRole ) ;
}
}
}
}
}
}
@ -750,9 +678,8 @@ void TransferListWidget::displayListMenu(const QPoint&)
qDebug ( " Displaying menu " ) ;
qDebug ( " Displaying menu " ) ;
foreach ( const QModelIndex & index , selectedIndexes ) {
foreach ( const QModelIndex & index , selectedIndexes ) {
// Get the file name
// Get the file name
QString hash = getHashFromRow ( mapToSource ( index ) . row ( ) ) ;
// Get handle and pause the torrent
// Get handle and pause the torrent
torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( hash ) ;
torrent = listModel - > torrentHandle ( mapToSource ( index ) ) ;
if ( ! torrent ) continue ;
if ( ! torrent ) continue ;
if ( torrent - > hasMetadata ( ) )
if ( torrent - > hasMetadata ( ) )
@ -907,8 +834,7 @@ void TransferListWidget::currentChanged(const QModelIndex& current, const QModel
qDebug ( " CURRENT CHANGED " ) ;
qDebug ( " CURRENT CHANGED " ) ;
BitTorrent : : TorrentHandle * torrent = 0 ;
BitTorrent : : TorrentHandle * torrent = 0 ;
if ( current . isValid ( ) ) {
if ( current . isValid ( ) ) {
const int row = mapToSource ( current ) . row ( ) ;
torrent = listModel - > torrentHandle ( mapToSource ( current ) ) ;
torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( getHashFromRow ( row ) ) ;
// Scroll Fix
// Scroll Fix
scrollTo ( current ) ;
scrollTo ( current ) ;
}
}
@ -946,8 +872,8 @@ void TransferListWidget::applyStatusFilter(int f)
nameFilterModel - > setStatusFilter ( static_cast < TorrentFilter : : Type > ( f ) ) ;
nameFilterModel - > setStatusFilter ( static_cast < TorrentFilter : : Type > ( f ) ) ;
// Select first item if nothing is selected
// Select first item if nothing is selected
if ( selectionModel ( ) - > selectedRows ( 0 ) . empty ( ) & & nameFilterModel - > rowCount ( ) > 0 ) {
if ( selectionModel ( ) - > selectedRows ( 0 ) . empty ( ) & & nameFilterModel - > rowCount ( ) > 0 ) {
qDebug ( " Nothing is selected, selecting first row: %s " , qPrintable ( nameFilterModel - > index ( 0 , TorrentModelItem : : TR_NAME ) . data ( ) . toString ( ) ) ) ;
qDebug ( " Nothing is selected, selecting first row: %s " , qPrintable ( nameFilterModel - > index ( 0 , TorrentModel : : TR_NAME ) . data ( ) . toString ( ) ) ) ;
selectionModel ( ) - > setCurrentIndex ( nameFilterModel - > index ( 0 , TorrentModelItem : : TR_NAME ) , QItemSelectionModel : : SelectCurrent | QItemSelectionModel : : Rows ) ;
selectionModel ( ) - > setCurrentIndex ( nameFilterModel - > index ( 0 , TorrentModel : : TR_NAME ) , QItemSelectionModel : : SelectCurrent | QItemSelectionModel : : Rows ) ;
}
}
}
}
@ -964,3 +890,11 @@ bool TransferListWidget::loadSettings()
return ok ;
return ok ;
}
}
QStringList extractHashes ( const QList < BitTorrent : : TorrentHandle * > & torrents )
{
QStringList hashes ;
foreach ( BitTorrent : : TorrentHandle * const torrent , torrents )
hashes < < torrent - > hash ( ) ;
return hashes ;
}