2009-11-07 22:55:33 +03:00
/*
* Bittorrent Client using Qt4 and libtorrent .
* Copyright ( C ) 2006 Christophe Dumez
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* In addition , as a special exception , the copyright holders give permission to
* link this program with the OpenSSL project ' s " OpenSSL " library ( or with
* modified versions of it that use the same license as the " OpenSSL " library ) ,
* and distribute the linked executables . You must obey the GNU General Public
* License in all respects for all of the code used other than " OpenSSL " . If you
* modify file ( s ) , you may extend this exception to your version of the file ( s ) ,
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
*
* Contact : chris @ qbittorrent . org
*/
2014-10-25 15:49:57 +04:00
# include <QDebug>
2014-09-13 17:12:07 +04:00
# include <QShortcut>
2009-11-07 22:55:33 +03:00
# include <QStandardItemModel>
# include <QSortFilterProxyModel>
# include <QDesktopServices>
2009-11-07 23:00:38 +03:00
# include <QTimer>
2009-11-07 22:55:33 +03:00
# include <QClipboard>
# include <QColor>
# include <QUrl>
# include <QMenu>
2009-11-08 16:19:00 +03:00
# include <QRegExp>
2010-05-21 18:26:18 +04:00
# include <QFileDialog>
2010-12-26 12:51:37 +03:00
# include <QMessageBox>
# include <libtorrent/version.hpp>
2014-10-25 15:49:57 +04:00
# include <libtorrent/magnet_uri.hpp>
2009-11-07 22:55:33 +03:00
# include <vector>
2010-12-19 16:37:12 +03:00
# include <queue>
2009-11-07 22:55:33 +03:00
2010-12-26 12:51:37 +03:00
# include "transferlistwidget.h"
# include "qbtsession.h"
# include "torrentpersistentdata.h"
# include "transferlistdelegate.h"
# include "previewselect.h"
# include "speedlimitdlg.h"
2011-03-07 22:26:44 +03:00
# include "updownratiodlg.h"
2010-12-26 12:51:37 +03:00
# include "options_imp.h"
# include "mainwindow.h"
# include "preferences.h"
# include "torrentmodel.h"
# include "deletionconfirmationdlg.h"
# include "propertieswidget.h"
2011-01-01 16:05:28 +03:00
# include "iconprovider.h"
2012-05-16 22:19:05 +04:00
# include "fs_utils.h"
2013-07-22 15:46:10 +04:00
# include "autoexpandabledialog.h"
2014-09-13 17:12:07 +04:00
# include "transferlistsortmodel.h"
2010-07-16 19:03:18 +04:00
2010-12-19 16:37:12 +03:00
using namespace libtorrent ;
2010-11-14 00:15:52 +03:00
TransferListWidget : : TransferListWidget ( QWidget * parent , MainWindow * main_window , QBtSession * _BTSession ) :
2010-10-19 20:45:23 +04:00
QTreeView ( parent ) , BTSession ( _BTSession ) , main_window ( main_window ) {
2011-03-13 13:09:31 +03:00
2013-06-29 18:58:41 +04:00
setUniformRowHeights ( true ) ;
2011-03-13 13:09:31 +03:00
// Load settings
2011-03-13 20:49:56 +03:00
bool column_loaded = loadSettings ( ) ;
2011-03-13 13:09:31 +03:00
2009-11-07 22:55:33 +03:00
// Create and apply delegate
listDelegate = new TransferListDelegate ( this ) ;
setItemDelegate ( listDelegate ) ;
// Create transfer list model
2010-11-14 18:28:22 +03:00
listModel = new TorrentModel ( this ) ;
2009-11-07 22:55:33 +03:00
2013-07-05 21:24:20 +04:00
nameFilterModel = new TransferListSortModel ( ) ;
2010-08-20 16:27:20 +04:00
nameFilterModel - > setDynamicSortFilter ( true ) ;
2014-11-09 02:49:21 +03:00
nameFilterModel - > setSourceModel ( listModel ) ;
2010-11-14 18:28:22 +03:00
nameFilterModel - > setFilterKeyColumn ( TorrentModelItem : : TR_NAME ) ;
2010-08-20 16:27:20 +04:00
nameFilterModel - > setFilterRole ( Qt : : DisplayRole ) ;
2011-12-29 01:31:50 +04:00
nameFilterModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
2010-11-14 18:28:22 +03:00
2010-08-20 16:27:20 +04:00
setModel ( nameFilterModel ) ;
2009-11-07 22:55:33 +03:00
// Visual settings
setRootIsDecorated ( false ) ;
setAllColumnsShowFocus ( true ) ;
setSortingEnabled ( true ) ;
2009-11-08 22:54:22 +03:00
setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
setItemsExpandable ( false ) ;
setAutoScroll ( true ) ;
2009-12-16 17:55:07 +03:00
setDragDropMode ( QAbstractItemView : : DragOnly ) ;
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_MAC)
2012-06-30 19:25:09 +04:00
setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
# endif
2014-10-15 17:35:54 +04:00
header ( ) - > setStretchLastSection ( false ) ;
2009-11-08 22:54:22 +03:00
2010-12-04 12:51:43 +03:00
// Default hidden columns
2012-02-20 21:30:53 +04:00
if ( ! column_loaded ) {
2011-03-13 20:49:56 +03:00
setColumnHidden ( TorrentModelItem : : TR_PRIORITY , true ) ;
setColumnHidden ( TorrentModelItem : : TR_ADD_DATE , true ) ;
setColumnHidden ( TorrentModelItem : : TR_SEED_DATE , true ) ;
setColumnHidden ( TorrentModelItem : : TR_UPLIMIT , true ) ;
setColumnHidden ( TorrentModelItem : : TR_DLLIMIT , true ) ;
setColumnHidden ( TorrentModelItem : : TR_TRACKER , true ) ;
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_DOWNLOADED , true ) ;
2012-12-27 17:55:40 +04:00
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_UPLOADED , true ) ;
2011-03-13 20:49:56 +03:00
setColumnHidden ( TorrentModelItem : : TR_AMOUNT_LEFT , true ) ;
setColumnHidden ( TorrentModelItem : : TR_TIME_ELAPSED , true ) ;
2013-05-01 09:52:06 +04:00
setColumnHidden ( TorrentModelItem : : TR_SAVE_PATH , true ) ;
2014-08-14 21:19:35 +04:00
setColumnHidden ( TorrentModelItem : : TR_COMPLETED , true ) ;
2014-08-14 21:46:55 +04:00
setColumnHidden ( TorrentModelItem : : TR_RATIO_LIMIT , true ) ;
2014-10-24 23:41:03 +04:00
setColumnHidden ( TorrentModelItem : : TR_SEEN_COMPLETE_DATE , true ) ;
2014-10-24 23:41:06 +04:00
setColumnHidden ( TorrentModelItem : : TR_LAST_ACTIVITY , true ) ;
2014-10-26 20:02:46 +03:00
setColumnHidden ( TorrentModelItem : : TR_TOTAL_SIZE , true ) ;
2011-03-13 20:49:56 +03:00
}
2009-11-07 22:55:33 +03:00
2014-01-02 22:49:35 +04:00
//Ensure that at least one column is visible at all times
bool atLeastOne = false ;
for ( unsigned int i = 0 ; i < TorrentModelItem : : NB_COLUMNS ; i + + ) {
if ( ! isColumnHidden ( i ) ) {
atLeastOne = true ;
break ;
}
}
if ( ! atLeastOne )
setColumnHidden ( TorrentModelItem : : TR_NAME , false ) ;
2013-06-29 19:16:23 +04:00
//When adding/removing columns between versions some may
//end up being size 0 when the new version is launched with
//a conf file from the previous version.
for ( unsigned int i = 0 ; i < TorrentModelItem : : NB_COLUMNS ; i + + )
if ( ! columnWidth ( i ) )
resizeColumnToContents ( i ) ;
2010-12-04 12:51:43 +03:00
setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2009-11-07 22:55:33 +03:00
// Listen for list events
connect ( this , SIGNAL ( doubleClicked ( QModelIndex ) ) , this , SLOT ( torrentDoubleClicked ( QModelIndex ) ) ) ;
2009-11-08 00:04:56 +03:00
connect ( this , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayListMenu ( const QPoint & ) ) ) ;
2009-11-17 12:07:37 +03:00
header ( ) - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2009-11-07 22:55:33 +03:00
connect ( header ( ) , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayDLHoSMenu ( const QPoint & ) ) ) ;
2013-07-22 18:39:48 +04:00
editHotkey = new QShortcut ( QKeySequence ( " F2 " ) , this , SLOT ( renameSelectedTorrent ( ) ) , 0 , Qt : : WidgetShortcut ) ;
2013-07-22 21:48:55 +04:00
deleteHotkey = new QShortcut ( QKeySequence : : Delete , this , SLOT ( deleteSelectedTorrents ( ) ) , 0 , Qt : : WidgetShortcut ) ;
2009-11-07 22:55:33 +03:00
}
TransferListWidget : : ~ TransferListWidget ( ) {
2011-03-14 22:18:52 +03:00
qDebug ( ) < < Q_FUNC_INFO < < " ENTER " ;
2009-11-08 12:14:54 +03:00
// Save settings
2010-12-04 12:51:43 +03:00
saveSettings ( ) ;
2009-11-08 12:14:54 +03:00
// Clean up
2010-08-20 16:27:20 +04:00
delete nameFilterModel ;
2009-11-07 22:55:33 +03:00
delete listModel ;
delete listDelegate ;
2013-07-22 18:39:48 +04:00
delete editHotkey ;
2013-07-22 21:48:55 +04:00
delete deleteHotkey ;
2011-03-14 22:18:52 +03:00
qDebug ( ) < < Q_FUNC_INFO < < " EXIT " ;
2009-11-07 22:55:33 +03:00
}
2010-11-14 18:28:22 +03:00
TorrentModel * TransferListWidget : : getSourceModel ( ) const {
2010-01-03 21:51:24 +03:00
return listModel ;
}
2009-11-27 14:38:42 +03:00
void TransferListWidget : : previewFile ( QString filePath ) {
2013-11-10 23:53:38 +04:00
openUrl ( filePath ) ;
2009-11-27 14:38:42 +03:00
}
2009-11-07 22:55:33 +03:00
void TransferListWidget : : setRefreshInterval ( int t ) {
2009-11-22 21:08:05 +03:00
qDebug ( " Settings transfer list refresh interval to %dms " , t ) ;
2010-11-14 18:28:22 +03:00
listModel - > setRefreshInterval ( t ) ;
2009-11-07 22:55:33 +03:00
}
2012-02-20 23:32:58 +04:00
int TransferListWidget : : getRowFromHash ( QString hash ) const {
2010-11-14 18:28:22 +03:00
return listModel - > torrentRow ( hash ) ;
2009-11-07 22:55:33 +03:00
}
2010-03-04 00:59:12 +03:00
inline QString TransferListWidget : : getHashFromRow ( int row ) const {
2010-11-14 18:28:22 +03:00
return listModel - > torrentHash ( row ) ;
2009-11-07 22:55:33 +03:00
}
2010-03-04 00:59:12 +03:00
inline QModelIndex TransferListWidget : : mapToSource ( const QModelIndex & index ) const {
2010-09-28 20:53:58 +04:00
Q_ASSERT ( index . isValid ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( index . model ( ) = = nameFilterModel )
2014-11-09 02:49:21 +03:00
return nameFilterModel - > mapToSource ( index ) ;
return index ;
2009-12-15 22:52:43 +03:00
}
2010-03-04 00:59:12 +03:00
inline QModelIndex TransferListWidget : : mapFromSource ( const QModelIndex & index ) const {
2010-09-28 20:53:58 +04:00
Q_ASSERT ( index . isValid ( ) ) ;
2014-11-09 02:49:21 +03:00
Q_ASSERT ( index . model ( ) = = nameFilterModel ) ;
return nameFilterModel - > mapFromSource ( index ) ;
2010-01-03 17:38:59 +03:00
}
2010-03-04 00:59:12 +03:00
void TransferListWidget : : torrentDoubleClicked ( const QModelIndex & index ) {
const int row = mapToSource ( index ) . row ( ) ;
2010-07-23 18:05:53 +04:00
const QString hash = getHashFromRow ( row ) ;
2009-11-07 22:55:33 +03:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( ! h . is_valid ( ) ) return ;
2009-11-07 22:55:33 +03:00
int action ;
2012-02-20 21:30:53 +04:00
if ( h . is_seed ( ) ) {
2014-07-05 16:44:13 +04:00
action = Preferences : : instance ( ) - > getActionOnDblClOnTorrentFn ( ) ;
2009-11-07 22:55:33 +03:00
} else {
2014-07-05 16:44:13 +04:00
action = Preferences : : instance ( ) - > getActionOnDblClOnTorrentDl ( ) ;
2009-11-07 22:55:33 +03:00
}
switch ( action ) {
case TOGGLE_PAUSE :
2012-02-20 21:30:53 +04:00
if ( h . is_paused ( ) ) {
2009-11-07 22:55:33 +03:00
h . resume ( ) ;
} else {
h . pause ( ) ;
}
break ;
case OPEN_DEST :
2013-11-10 23:53:38 +04:00
const QString path = h . root_path ( ) ;
openUrl ( path ) ;
2009-11-07 22:55:33 +03:00
}
}
2010-02-09 23:44:33 +03:00
QStringList TransferListWidget : : getSelectedTorrentsHashes ( ) const {
QStringList hashes ;
2010-07-23 18:05:53 +04:00
const QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QModelIndex & index , selectedIndexes ) {
2010-02-09 23:44:33 +03:00
hashes < < getHashFromRow ( mapToSource ( index ) . row ( ) ) ;
}
return hashes ;
}
2010-05-21 18:26:18 +04:00
void TransferListWidget : : setSelectedTorrentsLocation ( ) {
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
if ( hashes . isEmpty ( ) ) return ;
2010-05-21 18:26:18 +04:00
QString dir ;
2010-08-18 12:46:04 +04:00
const QDir saveDir ( TorrentPersistentData : : getSavePath ( hashes . first ( ) ) ) ;
2010-10-18 23:23:39 +04:00
qDebug ( " Old save path is %s " , qPrintable ( saveDir . absolutePath ( ) ) ) ;
2011-01-27 20:30:27 +03:00
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , saveDir . absolutePath ( ) ,
QFileDialog : : DontConfirmOverwrite | QFileDialog : : ShowDirsOnly | QFileDialog : : HideNameFilterDetails ) ;
2012-02-20 21:30:53 +04:00
if ( ! dir . isNull ( ) ) {
2010-10-18 23:23:39 +04:00
qDebug ( " New path is %s " , qPrintable ( dir ) ) ;
2010-05-21 18:26:18 +04:00
// Check if savePath exists
2013-11-10 23:25:16 +04:00
QDir savePath ( fsutils : : expandPathAbs ( dir ) ) ;
2010-10-18 23:23:39 +04:00
qDebug ( " New path after clean up is %s " , qPrintable ( savePath . absolutePath ( ) ) ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-07-20 13:02:41 +04:00
// Actually move storage
2010-05-21 18:26:18 +04:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( ! BTSession - > useTemporaryFolder ( ) | | h . is_seed ( ) ) {
if ( ! savePath . exists ( ) ) savePath . mkpath ( savePath . absolutePath ( ) ) ;
2010-07-20 13:02:41 +04:00
h . move_storage ( savePath . absolutePath ( ) ) ;
2010-08-18 12:46:04 +04:00
} else {
TorrentPersistentData : : saveSavePath ( h . hash ( ) , savePath . absolutePath ( ) ) ;
main_window - > getProperties ( ) - > updateSavePath ( h ) ;
}
2010-05-21 18:26:18 +04:00
}
}
}
2010-02-09 23:44:33 +03:00
void TransferListWidget : : startSelectedTorrents ( ) {
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-11-14 22:32:29 +03:00
BTSession - > resumeTorrent ( hash ) ;
2009-11-07 22:55:33 +03:00
}
}
2010-08-17 12:42:30 +04:00
void TransferListWidget : : startVisibleTorrents ( ) {
2010-08-18 12:07:17 +04:00
QStringList hashes ;
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
2010-08-20 16:27:20 +04:00
const int row = mapToSource ( nameFilterModel - > index ( i , 0 ) ) . row ( ) ;
2010-08-18 12:07:17 +04:00
hashes < < getHashFromRow ( row ) ;
}
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-11-14 22:32:29 +03:00
BTSession - > resumeTorrent ( hash ) ;
2010-08-17 12:42:30 +04:00
}
}
2009-11-07 22:55:33 +03:00
void TransferListWidget : : pauseSelectedTorrents ( ) {
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-11-14 22:32:29 +03:00
BTSession - > pauseTorrent ( hash ) ;
2009-11-07 22:55:33 +03:00
}
}
2010-08-17 12:42:30 +04:00
void TransferListWidget : : pauseVisibleTorrents ( ) {
2010-08-18 12:07:17 +04:00
QStringList hashes ;
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
2010-08-20 16:27:20 +04:00
const int row = mapToSource ( nameFilterModel - > index ( i , 0 ) ) . row ( ) ;
2010-08-18 12:07:17 +04:00
hashes < < getHashFromRow ( row ) ;
}
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-11-14 22:32:29 +03:00
BTSession - > pauseTorrent ( hash ) ;
2010-08-17 12:42:30 +04:00
}
}
2009-11-07 22:55:33 +03:00
void TransferListWidget : : deleteSelectedTorrents ( ) {
2012-02-20 21:30:53 +04:00
if ( main_window - > getCurrentTabWidget ( ) ! = this ) return ;
2010-03-04 00:59:12 +03:00
const QStringList & hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
if ( hashes . empty ( ) ) return ;
2013-11-21 19:07:38 +04:00
QTorrentHandle torrent = BTSession - > getTorrentHandle ( hashes [ 0 ] ) ;
2011-01-16 18:29:44 +03:00
bool delete_local_files = false ;
2014-07-05 16:44:13 +04:00
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
2013-11-21 19:07:38 +04:00
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , hashes . size ( ) , torrent . name ( ) ) )
2011-01-16 18:29:44 +03:00
return ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2011-01-16 18:29:44 +03:00
BTSession - > deleteTorrent ( hash , delete_local_files ) ;
2009-11-07 22:55:33 +03:00
}
}
2010-08-17 12:42:30 +04:00
void TransferListWidget : : deleteVisibleTorrents ( ) {
2012-02-20 21:30:53 +04:00
if ( nameFilterModel - > rowCount ( ) < = 0 ) return ;
2013-11-21 19:07:38 +04:00
QTorrentHandle torrent = BTSession - > getTorrentHandle ( getHashFromRow ( 0 ) ) ;
2010-08-17 12:42:30 +04:00
bool delete_local_files = false ;
2014-07-05 16:44:13 +04:00
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
2013-11-21 19:07:38 +04:00
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , nameFilterModel - > rowCount ( ) , torrent . name ( ) ) )
2011-01-16 18:29:44 +03:00
return ;
QStringList hashes ;
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
2011-01-16 18:29:44 +03:00
const int row = mapToSource ( nameFilterModel - > index ( i , 0 ) ) . row ( ) ;
hashes < < getHashFromRow ( row ) ;
}
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2011-01-16 18:29:44 +03:00
BTSession - > deleteTorrent ( hash , delete_local_files ) ;
2010-08-17 12:42:30 +04:00
}
}
2009-11-07 22:55:33 +03:00
void TransferListWidget : : increasePrioSelectedTorrents ( ) {
2010-12-19 16:37:12 +03:00
qDebug ( ) < < Q_FUNC_INFO ;
2012-02-20 21:30:53 +04:00
if ( main_window - > getCurrentTabWidget ( ) ! = this ) return ;
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2010-12-19 16:37:12 +03:00
std : : priority_queue < QPair < int , QTorrentHandle > , std : : vector < QPair < int , QTorrentHandle > > , std : : greater < QPair < int , QTorrentHandle > > > torrent_queue ;
// Sort torrents by priority
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-12-19 16:37:12 +03:00
try {
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( ! h . is_seed ( ) ) {
2010-12-19 16:37:12 +03:00
torrent_queue . push ( qMakePair ( h . queue_position ( ) , h ) ) ;
}
2012-02-20 21:56:07 +04:00
} catch ( invalid_handle & ) { }
2010-12-19 16:37:12 +03:00
}
// Increase torrents priority (starting with the ones with highest priority)
while ( ! torrent_queue . empty ( ) ) {
QTorrentHandle h = torrent_queue . top ( ) . second ;
try {
2009-11-17 11:15:26 +03:00
h . queue_position_up ( ) ;
2010-12-19 16:37:12 +03:00
} catch ( invalid_handle & h ) { }
torrent_queue . pop ( ) ;
2009-11-07 22:55:33 +03:00
}
}
void TransferListWidget : : decreasePrioSelectedTorrents ( ) {
2010-12-19 16:37:12 +03:00
qDebug ( ) < < Q_FUNC_INFO ;
2012-02-20 21:30:53 +04:00
if ( main_window - > getCurrentTabWidget ( ) ! = this ) return ;
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2010-12-19 16:37:12 +03:00
std : : priority_queue < QPair < int , QTorrentHandle > , std : : vector < QPair < int , QTorrentHandle > > , std : : less < QPair < int , QTorrentHandle > > > torrent_queue ;
// Sort torrents by priority
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-12-19 16:37:12 +03:00
try {
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( ! h . is_seed ( ) ) {
2010-12-19 16:37:12 +03:00
torrent_queue . push ( qMakePair ( h . queue_position ( ) , h ) ) ;
}
2012-02-20 21:56:07 +04:00
} catch ( invalid_handle & ) { }
2010-12-19 16:37:12 +03:00
}
// Decrease torrents priority (starting with the ones with lowest priority)
while ( ! torrent_queue . empty ( ) ) {
QTorrentHandle h = torrent_queue . top ( ) . second ;
try {
2009-11-17 11:15:26 +03:00
h . queue_position_down ( ) ;
2010-12-19 16:37:12 +03:00
} catch ( invalid_handle & h ) { }
torrent_queue . pop ( ) ;
2009-11-07 22:55:33 +03:00
}
}
2010-08-14 19:53:05 +04:00
void TransferListWidget : : topPrioSelectedTorrents ( ) {
2012-02-20 21:30:53 +04:00
if ( main_window - > getCurrentTabWidget ( ) ! = this ) return ;
2010-08-14 19:53:05 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-08-14 19:53:05 +04:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) & & ! h . is_seed ( ) ) {
2010-08-14 19:53:05 +04:00
h . queue_position_top ( ) ;
}
}
}
void TransferListWidget : : bottomPrioSelectedTorrents ( ) {
2012-02-20 21:30:53 +04:00
if ( main_window - > getCurrentTabWidget ( ) ! = this ) return ;
2010-08-14 19:53:05 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-08-14 19:53:05 +04:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) & & ! h . is_seed ( ) ) {
2010-08-14 19:53:05 +04:00
h . queue_position_bottom ( ) ;
}
}
2009-11-07 22:55:33 +03:00
}
void TransferListWidget : : copySelectedMagnetURIs ( ) const {
QStringList magnet_uris ;
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-07-23 18:05:53 +04:00
const QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2013-03-06 01:15:39 +04:00
if ( h . is_valid ( ) )
magnet_uris < < misc : : toQString ( make_magnet_uri ( h ) ) ;
2009-11-07 22:55:33 +03:00
}
qApp - > clipboard ( ) - > setText ( magnet_uris . join ( " \n " ) ) ;
}
void TransferListWidget : : hidePriorityColumn ( bool hide ) {
2010-10-18 21:06:11 +04:00
qDebug ( " hidePriorityColumn(%d) " , hide ) ;
2010-11-14 18:28:22 +03:00
setColumnHidden ( TorrentModelItem : : TR_PRIORITY , hide ) ;
2009-11-07 22:55:33 +03:00
}
void TransferListWidget : : openSelectedTorrentsFolder ( ) const {
2012-07-02 20:51:26 +04:00
QSet < QString > pathsList ;
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-07-23 18:05:53 +04:00
const QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) ) {
2012-07-02 20:51:26 +04:00
QString rootFolder = h . root_path ( ) ;
qDebug ( " Opening path at %s " , qPrintable ( rootFolder ) ) ;
if ( ! pathsList . contains ( rootFolder ) ) {
pathsList . insert ( rootFolder ) ;
2013-11-10 23:53:38 +04:00
openUrl ( rootFolder ) ;
2009-11-07 22:55:33 +03:00
}
}
}
}
void TransferListWidget : : previewSelectedTorrents ( ) {
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-07-23 18:05:53 +04:00
const QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) & & h . has_metadata ( ) ) {
2010-12-26 12:51:37 +03:00
new PreviewSelect ( this , h ) ;
2009-11-07 22:55:33 +03:00
}
}
}
2009-11-08 00:04:56 +03:00
void TransferListWidget : : setDlLimitSelectedTorrents ( ) {
2009-11-17 16:11:32 +03:00
QList < QTorrentHandle > selected_torrents ;
bool first = true ;
bool all_same_limit = true ;
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-07-23 18:05:53 +04:00
const QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) & & ! h . is_seed ( ) ) {
2009-11-17 16:11:32 +03:00
selected_torrents < < h ;
// Determine current limit for selected torrents
2012-02-20 21:30:53 +04:00
if ( first ) {
2009-11-17 16:11:32 +03:00
first = false ;
} else {
2012-02-20 21:30:53 +04:00
if ( all_same_limit & & h . download_limit ( ) ! = selected_torrents . first ( ) . download_limit ( ) )
2009-11-17 16:11:32 +03:00
all_same_limit = false ;
}
}
}
2012-02-20 21:30:53 +04:00
if ( selected_torrents . empty ( ) ) return ;
2009-11-17 16:11:32 +03:00
bool ok = false ;
int default_limit = - 1 ;
2012-02-20 21:30:53 +04:00
if ( all_same_limit )
2009-11-17 16:11:32 +03:00
default_limit = selected_torrents . first ( ) . download_limit ( ) ;
2014-07-05 16:44:13 +04:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Torrent Download Speed Limiting " ) , default_limit , Preferences : : instance ( ) - > getGlobalDownloadLimit ( ) * 1024. ) ;
2012-02-20 21:30:53 +04:00
if ( ok ) {
foreach ( const QTorrentHandle & h , selected_torrents ) {
2010-03-04 23:19:25 +03:00
qDebug ( " Applying download speed limit of %ld Kb/s to torrent %s " , ( long ) ( new_limit / 1024. ) , qPrintable ( h . hash ( ) ) ) ;
2009-11-17 16:16:25 +03:00
BTSession - > setDownloadLimit ( h . hash ( ) , new_limit ) ;
2009-11-17 16:11:32 +03:00
}
2009-11-08 00:04:56 +03:00
}
}
void TransferListWidget : : setUpLimitSelectedTorrents ( ) {
2009-11-17 16:11:32 +03:00
QList < QTorrentHandle > selected_torrents ;
bool first = true ;
bool all_same_limit = true ;
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-07-23 18:05:53 +04:00
const QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) ) {
2009-11-17 16:11:32 +03:00
selected_torrents < < h ;
// Determine current limit for selected torrents
2012-02-20 21:30:53 +04:00
if ( first ) {
2009-11-17 16:11:32 +03:00
first = false ;
} else {
2012-02-20 21:30:53 +04:00
if ( all_same_limit & & h . upload_limit ( ) ! = selected_torrents . first ( ) . upload_limit ( ) )
2009-11-17 16:11:32 +03:00
all_same_limit = false ;
}
}
}
2012-02-20 21:30:53 +04:00
if ( selected_torrents . empty ( ) ) return ;
2009-11-17 16:11:32 +03:00
bool ok = false ;
int default_limit = - 1 ;
2012-02-20 21:30:53 +04:00
if ( all_same_limit )
2009-11-17 16:11:32 +03:00
default_limit = selected_torrents . first ( ) . upload_limit ( ) ;
2014-07-05 16:44:13 +04:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Torrent Upload Speed Limiting " ) , default_limit , Preferences : : instance ( ) - > getGlobalUploadLimit ( ) * 1024. ) ;
2012-02-20 21:30:53 +04:00
if ( ok ) {
foreach ( const QTorrentHandle & h , selected_torrents ) {
2010-03-04 23:19:25 +03:00
qDebug ( " Applying upload speed limit of %ld Kb/s to torrent %s " , ( long ) ( new_limit / 1024. ) , qPrintable ( h . hash ( ) ) ) ;
2009-11-17 16:16:25 +03:00
BTSession - > setUploadLimit ( h . hash ( ) , new_limit ) ;
2009-11-17 16:11:32 +03:00
}
2009-11-08 00:04:56 +03:00
}
}
2011-03-07 22:26:44 +03:00
void TransferListWidget : : setMaxRatioSelectedTorrents ( ) {
2011-03-13 20:49:56 +03:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
if ( hashes . isEmpty ( ) )
return ;
bool useGlobalValue ;
qreal currentMaxRatio ;
if ( hashes . count ( ) = = 1 ) {
currentMaxRatio = BTSession - > getMaxRatioPerTorrent ( hashes . first ( ) , & useGlobalValue ) ;
} else {
useGlobalValue = true ;
currentMaxRatio = BTSession - > getGlobalMaxRatio ( ) ;
}
UpDownRatioDlg dlg ( useGlobalValue , currentMaxRatio , QBtSession : : MAX_RATIO , this ) ;
if ( dlg . exec ( ) ! = QDialog : : Accepted )
return ;
foreach ( const QString & hash , hashes ) {
if ( dlg . useDefault ( ) )
BTSession - > removeRatioPerTorrent ( hash ) ;
else
BTSession - > setMaxRatioPerTorrent ( hash , dlg . ratio ( ) ) ;
}
2011-03-07 22:26:44 +03:00
}
2009-11-08 00:04:56 +03:00
void TransferListWidget : : recheckSelectedTorrents ( ) {
2012-10-07 17:21:11 +04:00
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 ;
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-02-09 23:44:33 +03:00
BTSession - > recheckTorrent ( hash ) ;
2009-11-08 00:04:56 +03:00
}
}
2009-11-07 22:55:33 +03:00
// hide/show columns menu
2012-02-20 21:56:07 +04:00
void TransferListWidget : : displayDLHoSMenu ( const QPoint & ) {
2009-11-07 22:55:33 +03:00
QMenu hideshowColumn ( this ) ;
hideshowColumn . setTitle ( tr ( " Column visibility " ) ) ;
QList < QAction * > actions ;
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < listModel - > columnCount ( ) ; + + i ) {
if ( ! BTSession - > isQueueingEnabled ( ) & & i = = TorrentModelItem : : TR_PRIORITY ) {
2009-12-13 00:59:06 +03:00
actions . append ( 0 ) ;
continue ;
}
2010-11-14 18:28:22 +03:00
QAction * myAct = hideshowColumn . addAction ( listModel - > headerData ( i , Qt : : Horizontal , Qt : : DisplayRole ) . toString ( ) ) ;
2010-06-22 02:07:36 +04:00
myAct - > setCheckable ( true ) ;
myAct - > setChecked ( ! isColumnHidden ( i ) ) ;
actions . append ( myAct ) ;
2009-11-07 22:55:33 +03:00
}
2014-01-02 22:49:35 +04:00
int visibleCols = 0 ;
for ( unsigned int i = 0 ; i < TorrentModelItem : : NB_COLUMNS ; i + + ) {
if ( ! isColumnHidden ( i ) )
visibleCols + + ;
if ( visibleCols > 1 )
break ;
}
2009-11-07 22:55:33 +03:00
// Call menu
2010-06-22 02:07:36 +04:00
QAction * act = hideshowColumn . exec ( QCursor : : pos ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( act ) {
2009-12-13 00:59:06 +03:00
int col = actions . indexOf ( act ) ;
2010-06-02 17:08:26 +04:00
Q_ASSERT ( col > = 0 ) ;
2014-01-02 22:49:35 +04:00
Q_ASSERT ( visibleCols > 0 ) ;
if ( ! isColumnHidden ( col ) & & visibleCols = = 1 )
return ;
2010-06-02 17:08:26 +04:00
qDebug ( " Toggling column %d visibility " , col ) ;
2009-12-13 00:59:06 +03:00
setColumnHidden ( col , ! isColumnHidden ( col ) ) ;
2012-02-20 21:30:53 +04:00
if ( ! isColumnHidden ( col ) & & columnWidth ( col ) < = 5 )
2010-06-02 17:08:26 +04:00
setColumnWidth ( col , 100 ) ;
2009-12-13 00:59:06 +03:00
}
2009-11-07 22:55:33 +03:00
}
2009-11-08 00:04:56 +03:00
2010-03-04 00:59:12 +03:00
void TransferListWidget : : toggleSelectedTorrentsSuperSeeding ( ) const {
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2009-11-18 14:04:19 +03:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) & & h . has_metadata ( ) ) {
2014-01-01 04:49:16 +04:00
h . super_seeding ( ! h . status ( 0 ) . super_seeding ) ;
2009-11-18 14:04:19 +03:00
}
}
2011-08-10 22:44:37 +04:00
}
2009-11-18 14:04:19 +03:00
2010-03-04 00:59:12 +03:00
void TransferListWidget : : toggleSelectedTorrentsSequentialDownload ( ) const {
2010-07-23 18:05:53 +04:00
const QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2009-11-19 15:45:11 +03:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) & & h . has_metadata ( ) ) {
2010-11-22 21:43:52 +03:00
bool was_sequential = h . is_sequential_download ( ) ;
h . set_sequential_download ( ! was_sequential ) ;
2012-02-20 21:30:53 +04:00
if ( ! was_sequential )
2010-11-22 21:43:52 +03:00
h . prioritize_first_last_piece ( true ) ;
2009-11-19 15:45:11 +03:00
}
}
}
2010-03-04 00:59:12 +03:00
void TransferListWidget : : toggleSelectedFirstLastPiecePrio ( ) const {
2010-02-09 23:44:33 +03:00
QStringList hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2009-11-21 13:17:57 +03:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( h . is_valid ( ) & & h . has_metadata ( ) ) {
2009-11-21 13:17:57 +03:00
h . prioritize_first_last_piece ( ! h . first_last_piece_first ( ) ) ;
}
}
}
2009-12-15 22:52:43 +03:00
void TransferListWidget : : askNewLabelForSelection ( ) {
// Ask for label
bool ok ;
2010-01-05 15:18:17 +03:00
bool invalid ;
do {
invalid = false ;
2013-07-22 15:46:10 +04:00
const QString label = AutoExpandableDialog : : getText ( this , tr ( " New Label " ) , tr ( " Label: " ) , QLineEdit : : Normal , " " , & ok ) . trimmed ( ) ;
2010-01-05 15:18:17 +03:00
if ( ok & & ! label . isEmpty ( ) ) {
2012-05-16 22:19:05 +04:00
if ( fsutils : : isValidFileSystemName ( label ) ) {
2010-01-05 15:18:17 +03:00
setSelectionLabel ( label ) ;
} else {
QMessageBox : : warning ( this , tr ( " Invalid label name " ) , tr ( " Please don't use any special characters in the label name. " ) ) ;
invalid = true ;
}
}
} while ( invalid ) ;
2009-12-15 22:52:43 +03:00
}
2013-11-10 23:53:38 +04:00
bool TransferListWidget : : openUrl ( const QString & _path ) const {
const QString path = fsutils : : fromNativePath ( _path ) ;
// Hack to access samba shares with QDesktopServices::openUrl
2014-10-05 17:34:58 +04:00
if ( path . startsWith ( " // " ) )
return QDesktopServices : : openUrl ( fsutils : : toNativePath ( " file: " + path ) ) ;
else
return QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( path ) ) ;
2013-11-10 23:53:38 +04:00
}
2010-01-01 16:25:59 +03:00
void TransferListWidget : : renameSelectedTorrent ( ) {
2010-07-23 18:05:53 +04:00
const QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
2012-02-20 21:30:53 +04:00
if ( selectedIndexes . size ( ) ! = 1 ) return ;
if ( ! selectedIndexes . first ( ) . isValid ( ) ) return ;
2013-06-30 23:29:48 +04:00
QModelIndex mi = mapToSource ( selectedIndexes . first ( ) ) ;
const QString hash = getHashFromRow ( mi . row ( ) ) ;
2010-07-23 18:05:53 +04:00
const QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( ! h . is_valid ( ) ) return ;
2010-01-30 20:47:01 +03:00
// Ask for a new Name
bool ok ;
2013-07-22 15:46:10 +04:00
QString name = AutoExpandableDialog : : getText ( this , tr ( " Rename " ) , tr ( " New name: " ) , QLineEdit : : Normal , h . name ( ) , & ok ) ;
2010-01-30 20:47:01 +03:00
if ( ok & & ! name . isEmpty ( ) ) {
2013-07-11 14:16:13 +04:00
name . replace ( QRegExp ( " \r ? \n | \r " ) , " " ) ;
2010-11-14 18:28:22 +03:00
// Rename the torrent
2013-06-30 23:29:48 +04:00
listModel - > setData ( mi , name , Qt : : DisplayRole ) ;
2010-01-30 20:47:01 +03:00
}
2010-01-01 16:25:59 +03:00
}
2009-12-15 22:52:43 +03:00
void TransferListWidget : : setSelectionLabel ( QString label ) {
2010-03-04 00:59:12 +03:00
const QStringList & hashes = getSelectedTorrentsHashes ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & hash , hashes ) {
2010-02-07 00:31:51 +03:00
Q_ASSERT ( ! hash . isEmpty ( ) ) ;
2010-03-04 00:59:12 +03:00
const int row = getRowFromHash ( hash ) ;
2010-11-14 18:28:22 +03:00
const QString old_label = listModel - > data ( listModel - > index ( row , TorrentModelItem : : TR_LABEL ) ) . toString ( ) ;
2010-11-14 21:46:16 +03:00
listModel - > setData ( listModel - > index ( row , TorrentModelItem : : TR_LABEL ) , QVariant ( label ) , Qt : : DisplayRole ) ;
2009-12-18 16:36:47 +03:00
// Update save path if necessary
2010-07-18 16:53:16 +04:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
BTSession - > changeLabelInTorrentSavePath ( h , old_label , label ) ;
2009-12-15 22:52:43 +03:00
}
}
void TransferListWidget : : removeLabelFromRows ( QString label ) {
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < listModel - > rowCount ( ) ; + + i ) {
if ( listModel - > data ( listModel - > index ( i , TorrentModelItem : : TR_LABEL ) ) = = label ) {
2010-07-23 18:05:53 +04:00
const QString hash = getHashFromRow ( i ) ;
2010-11-14 18:28:22 +03:00
listModel - > setData ( listModel - > index ( i , TorrentModelItem : : TR_LABEL ) , " " , Qt : : DisplayRole ) ;
2010-01-05 21:11:52 +03:00
// Update save path if necessary
2010-07-18 16:53:16 +04:00
QTorrentHandle h = BTSession - > getTorrentHandle ( hash ) ;
BTSession - > changeLabelInTorrentSavePath ( h , label , " " ) ;
2010-01-03 01:53:27 +03:00
}
2009-12-15 22:52:43 +03:00
}
}
2009-11-08 00:04:56 +03:00
void TransferListWidget : : displayListMenu ( const QPoint & ) {
2014-01-26 16:13:49 +04:00
QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
if ( selectedIndexes . size ( ) = = 0 )
return ;
2009-11-08 00:04:56 +03:00
// Create actions
2011-01-01 16:05:28 +03:00
QAction actionStart ( IconProvider : : instance ( ) - > getIcon ( " media-playback-start " ) , tr ( " Resume " , " Resume/start the torrent " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionStart , SIGNAL ( triggered ( ) ) , this , SLOT ( startSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionPause ( IconProvider : : instance ( ) - > getIcon ( " media-playback-pause " ) , tr ( " Pause " , " Pause the torrent " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionPause , SIGNAL ( triggered ( ) ) , this , SLOT ( pauseSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionDelete ( IconProvider : : instance ( ) - > getIcon ( " edit-delete " ) , tr ( " Delete " , " Delete the torrent " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionDelete , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionPreview_file ( IconProvider : : instance ( ) - > getIcon ( " view-preview " ) , tr ( " Preview file... " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionPreview_file , SIGNAL ( triggered ( ) ) , this , SLOT ( previewSelectedTorrents ( ) ) ) ;
2011-03-07 22:26:44 +03:00
QAction actionSet_max_ratio ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/ratio.png " ) ) , tr ( " Limit share ratio... " ) , 0 ) ;
connect ( & actionSet_max_ratio , SIGNAL ( triggered ( ) ) , this , SLOT ( setMaxRatioSelectedTorrents ( ) ) ) ;
2010-06-21 22:32:01 +04:00
QAction actionSet_upload_limit ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/seeding.png " ) ) , tr ( " Limit upload rate... " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionSet_upload_limit , SIGNAL ( triggered ( ) ) , this , SLOT ( setUpLimitSelectedTorrents ( ) ) ) ;
2010-06-21 22:32:01 +04:00
QAction actionSet_download_limit ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/download.png " ) ) , tr ( " Limit download rate... " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionSet_download_limit , SIGNAL ( triggered ( ) ) , this , SLOT ( setDlLimitSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionOpen_destination_folder ( IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) , tr ( " Open destination folder " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionOpen_destination_folder , SIGNAL ( triggered ( ) ) , this , SLOT ( openSelectedTorrentsFolder ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionIncreasePriority ( IconProvider : : instance ( ) - > getIcon ( " go-up " ) , tr ( " Move up " , " i.e. move up in the queue " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionIncreasePriority , SIGNAL ( triggered ( ) ) , this , SLOT ( increasePrioSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionDecreasePriority ( IconProvider : : instance ( ) - > getIcon ( " go-down " ) , tr ( " Move down " , " i.e. Move down in the queue " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionDecreasePriority , SIGNAL ( triggered ( ) ) , this , SLOT ( decreasePrioSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionTopPriority ( IconProvider : : instance ( ) - > getIcon ( " go-top " ) , tr ( " Move to top " , " i.e. Move to top of the queue " ) , 0 ) ;
2010-08-14 19:53:05 +04:00
connect ( & actionTopPriority , SIGNAL ( triggered ( ) ) , this , SLOT ( topPrioSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionBottomPriority ( IconProvider : : instance ( ) - > getIcon ( " go-bottom " ) , tr ( " Move to bottom " , " i.e. Move to bottom of the queue " ) , 0 ) ;
2010-08-14 19:53:05 +04:00
connect ( & actionBottomPriority , SIGNAL ( triggered ( ) ) , this , SLOT ( bottomPrioSelectedTorrents ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionSetTorrentPath ( IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) , tr ( " Set location... " ) , 0 ) ;
2010-08-14 19:53:05 +04:00
connect ( & actionSetTorrentPath , SIGNAL ( triggered ( ) ) , this , SLOT ( setSelectedTorrentsLocation ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionForce_recheck ( IconProvider : : instance ( ) - > getIcon ( " document-edit-verify " ) , tr ( " Force recheck " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionForce_recheck , SIGNAL ( triggered ( ) ) , this , SLOT ( recheckSelectedTorrents ( ) ) ) ;
2010-12-12 22:37:59 +03:00
QAction actionCopy_magnet_link ( QIcon ( " :/Icons/magnet.png " ) , tr ( " Copy magnet link " ) , 0 ) ;
2009-11-08 00:04:56 +03:00
connect ( & actionCopy_magnet_link , SIGNAL ( triggered ( ) ) , this , SLOT ( copySelectedMagnetURIs ( ) ) ) ;
2009-11-18 14:04:19 +03:00
QAction actionSuper_seeding_mode ( tr ( " Super seeding mode " ) , 0 ) ;
2010-06-22 02:07:36 +04:00
actionSuper_seeding_mode . setCheckable ( true ) ;
2009-11-18 14:04:19 +03:00
connect ( & actionSuper_seeding_mode , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleSelectedTorrentsSuperSeeding ( ) ) ) ;
2011-01-01 16:05:28 +03:00
QAction actionRename ( IconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename... " ) , 0 ) ;
2010-01-01 16:25:59 +03:00
connect ( & actionRename , SIGNAL ( triggered ( ) ) , this , SLOT ( renameSelectedTorrent ( ) ) ) ;
2009-11-19 15:45:11 +03:00
QAction actionSequential_download ( tr ( " Download in sequential order " ) , 0 ) ;
2010-06-22 02:07:36 +04:00
actionSequential_download . setCheckable ( true ) ;
2009-11-19 15:45:11 +03:00
connect ( & actionSequential_download , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleSelectedTorrentsSequentialDownload ( ) ) ) ;
2009-11-21 13:17:57 +03:00
QAction actionFirstLastPiece_prio ( tr ( " Download first and last piece first " ) , 0 ) ;
2010-06-22 02:07:36 +04:00
actionFirstLastPiece_prio . setCheckable ( true ) ;
2009-11-21 13:17:57 +03:00
connect ( & actionFirstLastPiece_prio , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleSelectedFirstLastPiecePrio ( ) ) ) ;
2009-11-08 00:04:56 +03:00
// End of actions
QMenu listMenu ( this ) ;
// Enable/disable pause/start action given the DL state
bool has_pause = false , has_start = false , has_preview = false ;
2009-11-22 14:16:30 +03:00
bool all_same_super_seeding = true ;
bool super_seeding_mode = false ;
bool all_same_sequential_download_mode = true , all_same_prio_firstlast = true ;
bool sequential_download_mode = false , prioritize_first_last = false ;
2009-11-21 15:35:26 +03:00
bool one_has_metadata = false , one_not_seed = false ;
2009-11-18 14:04:19 +03:00
bool first = true ;
2009-11-08 00:04:56 +03:00
QTorrentHandle h ;
qDebug ( " Displaying menu " ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QModelIndex & index , selectedIndexes ) {
2009-11-08 00:04:56 +03:00
// Get the file name
2009-12-15 22:52:43 +03:00
QString hash = getHashFromRow ( mapToSource ( index ) . row ( ) ) ;
2009-11-08 00:04:56 +03:00
// Get handle and pause the torrent
h = BTSession - > getTorrentHandle ( hash ) ;
2012-02-20 21:30:53 +04:00
if ( ! h . is_valid ( ) ) continue ;
if ( h . has_metadata ( ) )
2009-11-08 00:04:56 +03:00
one_has_metadata = true ;
2012-02-20 21:30:53 +04:00
if ( ! h . is_seed ( ) ) {
2009-11-08 11:56:20 +03:00
one_not_seed = true ;
2012-02-20 21:30:53 +04:00
if ( h . has_metadata ( ) ) {
if ( first ) {
2009-12-02 23:24:34 +03:00
sequential_download_mode = h . is_sequential_download ( ) ;
prioritize_first_last = h . first_last_piece_first ( ) ;
} else {
2012-02-20 21:30:53 +04:00
if ( sequential_download_mode ! = h . is_sequential_download ( ) ) {
2009-12-02 23:24:34 +03:00
all_same_sequential_download_mode = false ;
}
2012-02-20 21:30:53 +04:00
if ( prioritize_first_last ! = h . first_last_piece_first ( ) ) {
2009-12-02 23:24:34 +03:00
all_same_prio_firstlast = false ;
}
2009-11-21 13:17:57 +03:00
}
2009-11-19 15:45:11 +03:00
}
2009-11-22 14:16:30 +03:00
}
else {
2012-02-20 21:30:53 +04:00
if ( ! one_not_seed & & all_same_super_seeding & & h . has_metadata ( ) ) {
if ( first ) {
2014-01-01 04:49:16 +04:00
super_seeding_mode = h . status ( 0 ) . super_seeding ;
2009-11-18 14:04:19 +03:00
} else {
2014-01-01 04:49:16 +04:00
if ( super_seeding_mode ! = h . status ( 0 ) . super_seeding ) {
2009-11-18 14:04:19 +03:00
all_same_super_seeding = false ;
}
}
}
}
2012-02-20 21:30:53 +04:00
if ( h . is_paused ( ) ) {
if ( ! has_start ) {
2009-11-08 00:04:56 +03:00
listMenu . addAction ( & actionStart ) ;
has_start = true ;
}
} else {
2012-02-20 21:30:53 +04:00
if ( ! has_pause ) {
2009-11-08 00:04:56 +03:00
listMenu . addAction ( & actionPause ) ;
has_pause = true ;
}
}
2012-02-20 21:30:53 +04:00
if ( h . has_metadata ( ) & & BTSession - > isFilePreviewPossible ( hash ) & & ! has_preview ) {
2009-11-08 00:04:56 +03:00
has_preview = true ;
}
2009-11-18 14:04:19 +03:00
first = false ;
2012-02-20 21:30:53 +04:00
if ( has_pause & & has_start & & has_preview & & one_not_seed ) break ;
2009-11-08 00:04:56 +03:00
}
listMenu . addSeparator ( ) ;
listMenu . addAction ( & actionDelete ) ;
listMenu . addSeparator ( ) ;
2010-05-21 18:26:18 +04:00
listMenu . addAction ( & actionSetTorrentPath ) ;
2012-02-20 21:30:53 +04:00
if ( selectedIndexes . size ( ) = = 1 )
2010-01-01 16:25:59 +03:00
listMenu . addAction ( & actionRename ) ;
2009-12-15 22:52:43 +03:00
// Label Menu
2014-07-05 16:44:13 +04:00
QStringList customLabels = Preferences : : instance ( ) - > getTorrentLabels ( ) ;
2010-05-12 23:03:31 +04:00
customLabels . sort ( ) ;
2009-12-15 22:52:43 +03:00
QList < QAction * > labelActions ;
2011-01-01 16:05:28 +03:00
QMenu * labelMenu = listMenu . addMenu ( IconProvider : : instance ( ) - > getIcon ( " view-categories " ) , tr ( " Label " ) ) ;
labelActions < < labelMenu - > addAction ( IconProvider : : instance ( ) - > getIcon ( " list-add " ) , tr ( " New... " , " New label... " ) ) ;
labelActions < < labelMenu - > addAction ( IconProvider : : instance ( ) - > getIcon ( " edit-clear " ) , tr ( " Reset " , " Reset label " ) ) ;
2009-12-15 22:52:43 +03:00
labelMenu - > addSeparator ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QString & label , customLabels ) {
2011-01-01 16:05:28 +03:00
labelActions < < labelMenu - > addAction ( IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) , label ) ;
2009-12-15 22:52:43 +03:00
}
listMenu . addSeparator ( ) ;
2012-02-20 21:30:53 +04:00
if ( one_not_seed )
2009-11-08 11:56:20 +03:00
listMenu . addAction ( & actionSet_download_limit ) ;
2011-03-07 22:26:44 +03:00
listMenu . addAction ( & actionSet_max_ratio ) ;
2009-11-08 00:04:56 +03:00
listMenu . addAction ( & actionSet_upload_limit ) ;
2012-02-20 21:30:53 +04:00
if ( ! one_not_seed & & all_same_super_seeding & & one_has_metadata ) {
2010-06-22 02:07:36 +04:00
actionSuper_seeding_mode . setChecked ( super_seeding_mode ) ;
2009-11-18 14:04:19 +03:00
listMenu . addAction ( & actionSuper_seeding_mode ) ;
}
2009-11-21 13:17:57 +03:00
listMenu . addSeparator ( ) ;
bool added_preview_action = false ;
2012-02-20 21:30:53 +04:00
if ( has_preview ) {
2009-11-21 13:17:57 +03:00
listMenu . addAction ( & actionPreview_file ) ;
added_preview_action = true ;
}
2012-02-20 21:30:53 +04:00
if ( one_not_seed & & one_has_metadata ) {
if ( all_same_sequential_download_mode ) {
2010-06-22 02:07:36 +04:00
actionSequential_download . setChecked ( sequential_download_mode ) ;
2009-11-21 13:17:57 +03:00
listMenu . addAction ( & actionSequential_download ) ;
added_preview_action = true ;
}
2012-02-20 21:30:53 +04:00
if ( all_same_prio_firstlast ) {
2010-06-22 02:07:36 +04:00
actionFirstLastPiece_prio . setChecked ( prioritize_first_last ) ;
2009-11-21 13:17:57 +03:00
listMenu . addAction ( & actionFirstLastPiece_prio ) ;
added_preview_action = true ;
2009-11-19 15:45:11 +03:00
}
}
2012-02-20 21:30:53 +04:00
if ( added_preview_action )
2009-11-21 16:51:15 +03:00
listMenu . addSeparator ( ) ;
2012-02-20 21:30:53 +04:00
if ( one_has_metadata ) {
2009-11-08 00:04:56 +03:00
listMenu . addAction ( & actionForce_recheck ) ;
listMenu . addSeparator ( ) ;
}
listMenu . addAction ( & actionOpen_destination_folder ) ;
2012-02-20 21:30:53 +04:00
if ( BTSession - > isQueueingEnabled ( ) & & one_not_seed ) {
2009-11-08 00:04:56 +03:00
listMenu . addSeparator ( ) ;
2010-08-14 19:53:05 +04:00
QMenu * prioMenu = listMenu . addMenu ( tr ( " Priority " ) ) ;
prioMenu - > addAction ( & actionTopPriority ) ;
prioMenu - > addAction ( & actionIncreasePriority ) ;
prioMenu - > addAction ( & actionDecreasePriority ) ;
prioMenu - > addAction ( & actionBottomPriority ) ;
2009-11-08 00:04:56 +03:00
}
listMenu . addSeparator ( ) ;
2013-03-06 01:15:39 +04:00
listMenu . addAction ( & actionCopy_magnet_link ) ;
2009-11-08 00:04:56 +03:00
// Call menu
2009-12-15 22:52:43 +03:00
QAction * act = 0 ;
act = listMenu . exec ( QCursor : : pos ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( act ) {
2009-12-15 22:52:43 +03:00
// Parse label actions only (others have slots assigned)
int i = labelActions . indexOf ( act ) ;
2012-02-20 21:30:53 +04:00
if ( i > = 0 ) {
2009-12-15 22:52:43 +03:00
// Label action
2012-02-20 21:30:53 +04:00
if ( i = = 0 ) {
2009-12-15 22:52:43 +03:00
// New Label
askNewLabelForSelection ( ) ;
} else {
QString label = " " ;
2012-02-20 21:30:53 +04:00
if ( i > 1 )
2009-12-15 22:52:43 +03:00
label = customLabels . at ( i - 2 ) ;
// Update Label
setSelectionLabel ( label ) ;
}
}
}
2009-11-08 00:04:56 +03:00
}
2009-11-08 12:14:54 +03:00
2009-11-08 18:41:32 +03:00
void TransferListWidget : : currentChanged ( const QModelIndex & current , const QModelIndex & ) {
2010-09-28 20:53:58 +04:00
qDebug ( " CURRENT CHANGED " ) ;
2009-11-08 22:54:22 +03:00
QTorrentHandle h ;
2012-02-20 21:30:53 +04:00
if ( current . isValid ( ) ) {
2010-03-04 00:59:12 +03:00
const int row = mapToSource ( current ) . row ( ) ;
2009-11-08 22:54:22 +03:00
h = BTSession - > getTorrentHandle ( getHashFromRow ( row ) ) ;
2009-11-25 21:20:42 +03:00
// Scroll Fix
scrollTo ( current ) ;
2009-11-08 22:54:22 +03:00
}
2009-11-08 18:41:32 +03:00
emit currentTorrentChanged ( h ) ;
}
2014-11-09 03:36:53 +03:00
void TransferListWidget : : applyLabelFilterAll ( ) {
nameFilterModel - > disableLabelFilter ( ) ;
}
2009-12-15 22:52:43 +03:00
void TransferListWidget : : applyLabelFilter ( QString label ) {
2010-03-04 23:19:25 +03:00
qDebug ( " Applying Label filter: %s " , qPrintable ( label ) ) ;
2014-11-09 02:49:21 +03:00
nameFilterModel - > setLabelFilter ( label ) ;
2009-12-15 22:52:43 +03:00
}
2012-08-28 19:36:10 +04:00
void TransferListWidget : : applyNameFilter ( const QString & name ) {
nameFilterModel - > setFilterRegExp ( QRegExp ( QRegExp : : escape ( name ) , Qt : : CaseInsensitive ) ) ;
2010-08-20 16:27:20 +04:00
}
2009-12-15 22:52:43 +03:00
void TransferListWidget : : applyStatusFilter ( int f ) {
2014-11-09 01:58:01 +03:00
nameFilterModel - > setStatusFilter ( ( TorrentFilter : : TorrentFilter ) f ) ;
2009-11-09 10:05:06 +03:00
// Select first item if nothing is selected
2012-02-20 21:30:53 +04:00
if ( selectionModel ( ) - > selectedRows ( 0 ) . empty ( ) & & nameFilterModel - > rowCount ( ) > 0 ) {
2010-11-14 18:28:22 +03:00
qDebug ( " Nothing is selected, selecting first row: %s " , qPrintable ( nameFilterModel - > index ( 0 , TorrentModelItem : : TR_NAME ) . data ( ) . toString ( ) ) ) ;
selectionModel ( ) - > setCurrentIndex ( nameFilterModel - > index ( 0 , TorrentModelItem : : TR_NAME ) , QItemSelectionModel : : SelectCurrent | QItemSelectionModel : : Rows ) ;
2010-10-17 13:09:40 +04:00
}
2009-11-08 16:19:00 +03:00
}
2009-11-09 11:56:21 +03:00
2010-12-04 12:51:43 +03:00
void TransferListWidget : : saveSettings ( )
{
2014-07-05 16:44:13 +04:00
Preferences : : instance ( ) - > setTransHeaderState ( header ( ) - > saveState ( ) ) ;
2010-12-04 12:51:43 +03:00
}
2011-03-13 20:49:56 +03:00
bool TransferListWidget : : loadSettings ( )
2010-12-04 12:51:43 +03:00
{
2014-07-05 16:44:13 +04:00
bool ok = header ( ) - > restoreState ( Preferences : : instance ( ) - > getTransHeaderState ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( ! ok ) {
2011-03-13 20:49:56 +03:00
header ( ) - > resizeSection ( 0 , 200 ) ; // Default
}
return ok ;
2010-12-04 12:51:43 +03:00
}