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>
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>
2015-12-05 22:49:46 +03:00
# ifdef QBT_USES_QT5
2015-11-18 19:13:25 +03:00
# include <QTableView>
# endif
2010-12-26 12:51:37 +03:00
# include "transferlistwidget.h"
2015-09-25 11:10:05 +03:00
# include "base/bittorrent/session.h"
# include "base/bittorrent/torrenthandle.h"
# include "base/torrentfilter.h"
2010-12-26 12:51:37 +03:00
# 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"
2015-09-25 11:10:05 +03:00
# include "base/preferences.h"
2010-12-26 12:51:37 +03:00
# include "torrentmodel.h"
# include "deletionconfirmationdlg.h"
# include "propertieswidget.h"
2015-04-19 18:17:47 +03:00
# include "guiiconprovider.h"
2015-09-25 11:10:05 +03:00
# include "base/utils/fs.h"
2016-02-09 11:56:48 +03:00
# include "base/utils/string.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
2015-06-07 15:03:30 +03:00
static QStringList extractHashes ( const QList < BitTorrent : : TorrentHandle * > & torrents ) ;
2015-04-19 18:17:47 +03:00
TransferListWidget : : TransferListWidget ( QWidget * parent , MainWindow * main_window )
: QTreeView ( parent )
, main_window ( main_window )
2014-12-08 04:40:58 +03:00
{
setUniformRowHeights ( true ) ;
// Load settings
bool column_loaded = loadSettings ( ) ;
// Create and apply delegate
listDelegate = new TransferListDelegate ( this ) ;
setItemDelegate ( listDelegate ) ;
// Create transfer list model
listModel = new TorrentModel ( this ) ;
nameFilterModel = new TransferListSortModel ( ) ;
nameFilterModel - > setDynamicSortFilter ( true ) ;
nameFilterModel - > setSourceModel ( listModel ) ;
2015-06-07 15:03:30 +03:00
nameFilterModel - > setFilterKeyColumn ( TorrentModel : : TR_NAME ) ;
2014-12-08 04:40:58 +03:00
nameFilterModel - > setFilterRole ( Qt : : DisplayRole ) ;
nameFilterModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
setModel ( nameFilterModel ) ;
// Visual settings
setRootIsDecorated ( false ) ;
setAllColumnsShowFocus ( true ) ;
setSortingEnabled ( true ) ;
setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
setItemsExpandable ( false ) ;
setAutoScroll ( true ) ;
setDragDropMode ( QAbstractItemView : : DragOnly ) ;
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_MAC)
2014-12-08 04:40:58 +03:00
setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
2012-06-30 19:25:09 +04:00
# endif
2014-12-08 04:40:58 +03:00
header ( ) - > setStretchLastSection ( false ) ;
// Default hidden columns
if ( ! column_loaded ) {
2015-06-07 15:03:30 +03:00
setColumnHidden ( TorrentModel : : TR_ADD_DATE , true ) ;
setColumnHidden ( TorrentModel : : TR_SEED_DATE , true ) ;
setColumnHidden ( TorrentModel : : TR_UPLIMIT , true ) ;
setColumnHidden ( TorrentModel : : TR_DLLIMIT , true ) ;
setColumnHidden ( TorrentModel : : TR_TRACKER , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_DOWNLOADED , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_UPLOADED , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_DOWNLOADED_SESSION , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_UPLOADED_SESSION , true ) ;
setColumnHidden ( TorrentModel : : TR_AMOUNT_LEFT , true ) ;
setColumnHidden ( TorrentModel : : TR_TIME_ELAPSED , true ) ;
setColumnHidden ( TorrentModel : : TR_SAVE_PATH , true ) ;
setColumnHidden ( TorrentModel : : TR_COMPLETED , true ) ;
setColumnHidden ( TorrentModel : : TR_RATIO_LIMIT , true ) ;
setColumnHidden ( TorrentModel : : TR_SEEN_COMPLETE_DATE , true ) ;
setColumnHidden ( TorrentModel : : TR_LAST_ACTIVITY , true ) ;
setColumnHidden ( TorrentModel : : TR_TOTAL_SIZE , true ) ;
2014-12-08 04:40:58 +03:00
}
2009-11-08 22:54:22 +03:00
2014-12-08 04:40:58 +03:00
//Ensure that at least one column is visible at all times
bool atLeastOne = false ;
2015-06-07 15:03:30 +03:00
for ( unsigned int i = 0 ; i < TorrentModel : : NB_COLUMNS ; i + + ) {
2014-12-08 04:40:58 +03:00
if ( ! isColumnHidden ( i ) ) {
atLeastOne = true ;
break ;
}
2010-08-14 19:53:05 +04:00
}
2014-12-08 04:40:58 +03:00
if ( ! atLeastOne )
2015-06-07 15:03:30 +03:00
setColumnHidden ( TorrentModel : : TR_NAME , false ) ;
2014-12-08 04:40:58 +03: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.
2015-06-07 15:03:30 +03:00
for ( unsigned int i = 0 ; i < TorrentModel : : NB_COLUMNS ; i + + )
2014-12-08 04:40:58 +03:00
if ( ! columnWidth ( i ) )
resizeColumnToContents ( i ) ;
setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
// Listen for list events
connect ( this , SIGNAL ( doubleClicked ( QModelIndex ) ) , this , SLOT ( torrentDoubleClicked ( QModelIndex ) ) ) ;
connect ( this , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayListMenu ( const QPoint & ) ) ) ;
header ( ) - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( header ( ) , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayDLHoSMenu ( const QPoint & ) ) ) ;
2014-12-15 15:05:49 +03:00
connect ( header ( ) , SIGNAL ( sectionMoved ( int , int , int ) ) , this , SLOT ( saveSettings ( ) ) ) ;
connect ( header ( ) , SIGNAL ( sectionResized ( int , int , int ) ) , this , SLOT ( saveSettings ( ) ) ) ;
2014-12-20 19:09:35 +03:00
connect ( header ( ) , SIGNAL ( sortIndicatorChanged ( int , Qt : : SortOrder ) ) , this , SLOT ( saveSettings ( ) ) ) ;
2014-12-08 04:40:58 +03:00
editHotkey = new QShortcut ( QKeySequence ( " F2 " ) , this , SLOT ( renameSelectedTorrent ( ) ) , 0 , Qt : : WidgetShortcut ) ;
deleteHotkey = new QShortcut ( QKeySequence : : Delete , this , SLOT ( deleteSelectedTorrents ( ) ) , 0 , Qt : : WidgetShortcut ) ;
2015-11-18 19:13:25 +03:00
2015-12-05 22:49:46 +03:00
# ifdef QBT_USES_QT5
2015-11-18 19:13:25 +03:00
// This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused ;
unused . setVerticalHeader ( header ( ) ) ;
header ( ) - > setParent ( this ) ;
unused . setVerticalHeader ( new QHeaderView ( Qt : : Horizontal ) ) ;
# endif
2014-12-08 04:40:58 +03:00
}
TransferListWidget : : ~ TransferListWidget ( )
{
qDebug ( ) < < Q_FUNC_INFO < < " ENTER " ;
// Save settings
saveSettings ( ) ;
// Clean up
delete nameFilterModel ;
delete listModel ;
delete listDelegate ;
delete editHotkey ;
delete deleteHotkey ;
qDebug ( ) < < Q_FUNC_INFO < < " EXIT " ;
}
TorrentModel * TransferListWidget : : getSourceModel ( ) const
{
return listModel ;
}
void TransferListWidget : : previewFile ( QString filePath )
{
2015-06-28 21:58:39 +03:00
Utils : : Misc : : openPath ( filePath ) ;
2014-12-08 04:40:58 +03:00
}
inline QModelIndex TransferListWidget : : mapToSource ( const QModelIndex & index ) const
{
Q_ASSERT ( index . isValid ( ) ) ;
if ( index . model ( ) = = nameFilterModel )
return nameFilterModel - > mapToSource ( index ) ;
return index ;
}
inline QModelIndex TransferListWidget : : mapFromSource ( const QModelIndex & index ) const
{
Q_ASSERT ( index . isValid ( ) ) ;
Q_ASSERT ( index . model ( ) = = nameFilterModel ) ;
return nameFilterModel - > mapFromSource ( index ) ;
}
void TransferListWidget : : torrentDoubleClicked ( const QModelIndex & index )
{
2015-06-07 15:03:30 +03:00
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mapToSource ( index ) ) ;
2015-04-19 18:17:47 +03:00
if ( ! torrent ) return ;
2014-12-08 04:40:58 +03:00
int action ;
2015-04-19 18:17:47 +03:00
if ( torrent - > isSeed ( ) )
2014-12-08 04:40:58 +03:00
action = Preferences : : instance ( ) - > getActionOnDblClOnTorrentFn ( ) ;
else
action = Preferences : : instance ( ) - > getActionOnDblClOnTorrentDl ( ) ;
switch ( action ) {
case TOGGLE_PAUSE :
2015-04-19 18:17:47 +03:00
if ( torrent - > isPaused ( ) )
torrent - > resume ( ) ;
2014-12-08 04:40:58 +03:00
else
2015-04-19 18:17:47 +03:00
torrent - > pause ( ) ;
2014-12-08 04:40:58 +03:00
break ;
case OPEN_DEST :
2015-06-28 21:58:39 +03:00
if ( torrent - > filesCount ( ) = = 1 )
2015-10-24 15:28:29 +03:00
Utils : : Misc : : openFolderSelect ( torrent - > contentPath ( true ) ) ;
2015-06-28 21:58:39 +03:00
else
2015-10-24 15:28:29 +03:00
Utils : : Misc : : openPath ( torrent - > contentPath ( true ) ) ;
2015-06-28 21:58:39 +03:00
break ;
2010-08-14 19:53:05 +04:00
}
2009-11-07 22:55:33 +03:00
}
2015-06-07 15:03:30 +03:00
QList < BitTorrent : : TorrentHandle * > TransferListWidget : : getSelectedTorrents ( ) const
2014-12-08 04:40:58 +03:00
{
2015-06-07 15:03:30 +03:00
QList < BitTorrent : : TorrentHandle * > torrents ;
foreach ( const QModelIndex & index , selectionModel ( ) - > selectedRows ( ) )
torrents < < listModel - > torrentHandle ( mapToSource ( index ) ) ;
return torrents ;
2009-11-07 22:55:33 +03:00
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : setSelectedTorrentsLocation ( )
{
2015-06-07 15:03:30 +03:00
const QList < BitTorrent : : TorrentHandle * > torrents = getSelectedTorrents ( ) ;
if ( torrents . isEmpty ( ) ) return ;
2015-04-19 18:17:47 +03:00
2014-12-08 04:40:58 +03:00
QString dir ;
2015-06-07 15:03:30 +03:00
const QDir saveDir ( torrents [ 0 ] - > savePath ( ) ) ;
2014-12-08 04:40:58 +03:00
qDebug ( " Old save path is %s " , qPrintable ( saveDir . absolutePath ( ) ) ) ;
dir = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , saveDir . absolutePath ( ) ,
QFileDialog : : DontConfirmOverwrite | QFileDialog : : ShowDirsOnly | QFileDialog : : HideNameFilterDetails ) ;
if ( ! dir . isNull ( ) ) {
qDebug ( " New path is %s " , qPrintable ( dir ) ) ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , torrents ) {
2014-12-08 04:40:58 +03:00
// Actually move storage
2015-05-06 14:53:27 +03:00
torrent - > move ( Utils : : Fs : : expandPathAbs ( dir ) ) ;
2014-12-08 04:40:58 +03:00
}
}
2009-11-07 22:55:33 +03:00
}
2015-04-19 18:17:47 +03:00
void TransferListWidget : : pauseAllTorrents ( )
{
foreach ( BitTorrent : : TorrentHandle * const torrent , BitTorrent : : Session : : instance ( ) - > torrents ( ) )
torrent - > pause ( ) ;
}
void TransferListWidget : : resumeAllTorrents ( )
{
foreach ( BitTorrent : : TorrentHandle * const torrent , BitTorrent : : Session : : instance ( ) - > torrents ( ) )
torrent - > resume ( ) ;
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : startSelectedTorrents ( )
{
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
torrent - > resume ( ) ;
2014-12-08 04:40:58 +03:00
}
2015-04-14 02:22:14 +03:00
void TransferListWidget : : forceStartSelectedTorrents ( )
{
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
torrent - > resume ( true ) ;
2015-04-14 02:22:14 +03:00
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : startVisibleTorrents ( )
{
2015-04-19 18:17:47 +03:00
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
2015-06-07 15:03:30 +03:00
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mapToSource ( nameFilterModel - > index ( i , 0 ) ) ) ;
2015-04-19 18:17:47 +03:00
if ( torrent )
torrent - > resume ( ) ;
2009-11-07 22:55:33 +03:00
}
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : pauseSelectedTorrents ( )
{
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
torrent - > pause ( ) ;
2014-12-08 04:40:58 +03:00
}
void TransferListWidget : : pauseVisibleTorrents ( )
{
2015-04-19 18:17:47 +03:00
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i ) {
2015-06-07 15:03:30 +03:00
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mapToSource ( nameFilterModel - > index ( i , 0 ) ) ) ;
2015-04-19 18:17:47 +03:00
if ( torrent )
torrent - > pause ( ) ;
2009-11-07 22:55:33 +03:00
}
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : deleteSelectedTorrents ( )
{
2016-01-24 13:16:25 +03:00
if ( main_window - > currentTabWidget ( ) ! = this ) return ;
2015-04-19 18:17:47 +03:00
2015-06-07 15:03:30 +03:00
const QList < BitTorrent : : TorrentHandle * > torrents = getSelectedTorrents ( ) ;
if ( torrents . empty ( ) ) return ;
2014-12-08 04:40:58 +03:00
bool delete_local_files = false ;
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
2015-06-07 15:03:30 +03:00
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , torrents . size ( ) , torrents [ 0 ] - > name ( ) ) )
2014-12-08 04:40:58 +03:00
return ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , torrents )
BitTorrent : : Session : : instance ( ) - > deleteTorrent ( torrent - > hash ( ) , delete_local_files ) ;
2014-12-08 04:40:58 +03:00
}
void TransferListWidget : : deleteVisibleTorrents ( )
{
if ( nameFilterModel - > rowCount ( ) < = 0 ) return ;
2015-04-19 18:17:47 +03:00
2015-06-07 15:03:30 +03:00
QList < BitTorrent : : TorrentHandle * > torrents ;
for ( int i = 0 ; i < nameFilterModel - > rowCount ( ) ; + + i )
torrents < < listModel - > torrentHandle ( mapToSource ( nameFilterModel - > index ( i , 0 ) ) ) ;
2015-03-17 00:57:03 +03:00
bool delete_local_files = false ;
if ( Preferences : : instance ( ) - > confirmTorrentDeletion ( ) & &
2015-06-07 15:03:30 +03:00
! DeletionConfirmationDlg : : askForDeletionConfirmation ( delete_local_files , torrents . size ( ) , torrents [ 0 ] - > name ( ) ) )
2015-03-17 00:57:03 +03:00
return ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , torrents )
BitTorrent : : Session : : instance ( ) - > deleteTorrent ( torrent - > hash ( ) , delete_local_files ) ;
2014-12-08 04:40:58 +03:00
}
void TransferListWidget : : increasePrioSelectedTorrents ( )
{
qDebug ( ) < < Q_FUNC_INFO ;
2016-01-24 13:16:25 +03:00
if ( main_window - > currentTabWidget ( ) = = this )
2015-06-07 15:03:30 +03:00
BitTorrent : : Session : : instance ( ) - > increaseTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
2011-03-07 22:26:44 +03:00
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : decreasePrioSelectedTorrents ( )
{
qDebug ( ) < < Q_FUNC_INFO ;
2016-01-24 13:16:25 +03:00
if ( main_window - > currentTabWidget ( ) = = this )
2015-06-07 15:03:30 +03:00
BitTorrent : : Session : : instance ( ) - > decreaseTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
2009-11-08 00:04:56 +03:00
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : topPrioSelectedTorrents ( )
{
2016-01-24 13:16:25 +03:00
if ( main_window - > currentTabWidget ( ) = = this )
2015-06-07 15:03:30 +03:00
BitTorrent : : Session : : instance ( ) - > topTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
2011-08-10 22:44:37 +04:00
}
2009-11-18 14:04:19 +03:00
2014-12-08 04:40:58 +03:00
void TransferListWidget : : bottomPrioSelectedTorrents ( )
{
2016-01-24 13:16:25 +03:00
if ( main_window - > currentTabWidget ( ) = = this )
2015-06-07 15:03:30 +03:00
BitTorrent : : Session : : instance ( ) - > bottomTorrentsPriority ( extractHashes ( getSelectedTorrents ( ) ) ) ;
2009-11-19 15:45:11 +03:00
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : copySelectedMagnetURIs ( ) const
{
QStringList magnet_uris ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
magnet_uris < < torrent - > toMagnetUri ( ) ;
2014-12-08 04:40:58 +03:00
qApp - > clipboard ( ) - > setText ( magnet_uris . join ( " \n " ) ) ;
}
2015-02-06 21:56:24 +03:00
void TransferListWidget : : copySelectedNames ( ) const
2015-02-01 16:52:36 +03:00
{
2015-02-06 21:56:24 +03:00
QStringList torrent_names ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
torrent_names < < torrent - > name ( ) ;
2015-02-06 21:56:24 +03:00
qApp - > clipboard ( ) - > setText ( torrent_names . join ( " \n " ) ) ;
2015-02-01 16:52:36 +03:00
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : hidePriorityColumn ( bool hide )
{
qDebug ( " hidePriorityColumn(%d) " , hide ) ;
2015-06-07 15:03:30 +03:00
setColumnHidden ( TorrentModel : : TR_PRIORITY , hide ) ;
if ( ! hide & & ! columnWidth ( TorrentModel : : TR_PRIORITY ) )
resizeColumnToContents ( TorrentModel : : TR_PRIORITY ) ;
2014-12-08 04:40:58 +03:00
}
void TransferListWidget : : openSelectedTorrentsFolder ( ) const
{
QSet < QString > pathsList ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
2015-10-24 15:28:29 +03:00
QString path = torrent - > contentPath ( true ) ;
if ( ! pathsList . contains ( path ) ) {
if ( torrent - > filesCount ( ) = = 1 )
2015-06-28 21:58:39 +03:00
Utils : : Misc : : openFolderSelect ( path ) ;
2015-10-24 15:28:29 +03:00
else
2015-06-28 21:58:39 +03:00
Utils : : Misc : : openPath ( path ) ;
}
pathsList . insert ( path ) ;
2014-12-08 04:40:58 +03:00
}
}
void TransferListWidget : : previewSelectedTorrents ( )
{
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
if ( torrent - > hasMetadata ( ) )
2015-04-19 18:17:47 +03:00
new PreviewSelect ( this , torrent ) ;
2014-12-08 04:40:58 +03:00
}
}
void TransferListWidget : : setDlLimitSelectedTorrents ( )
{
2015-04-19 18:17:47 +03:00
QList < BitTorrent : : TorrentHandle * > selected_torrents ;
2014-12-08 04:40:58 +03:00
bool first = true ;
bool all_same_limit = true ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
if ( ! torrent - > isSeed ( ) ) {
2015-04-19 18:17:47 +03:00
selected_torrents < < torrent ;
2014-12-08 04:40:58 +03:00
// Determine current limit for selected torrents
if ( first )
first = false ;
2015-06-07 15:03:30 +03:00
else if ( all_same_limit & & ( torrent - > downloadLimit ( ) ! = selected_torrents . first ( ) - > downloadLimit ( ) ) )
all_same_limit = false ;
2014-12-08 04:40:58 +03:00
}
}
2015-06-07 15:03:30 +03:00
2014-12-08 04:40:58 +03:00
if ( selected_torrents . empty ( ) ) return ;
bool ok = false ;
int default_limit = - 1 ;
if ( all_same_limit )
2015-04-19 18:17:47 +03:00
default_limit = selected_torrents . first ( ) - > downloadLimit ( ) ;
2014-12-08 04:40:58 +03:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Torrent Download Speed Limiting " ) , default_limit , Preferences : : instance ( ) - > getGlobalDownloadLimit ( ) * 1024. ) ;
if ( ok ) {
2015-04-19 18:17:47 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , selected_torrents ) {
qDebug ( " Applying download speed limit of %ld Kb/s to torrent %s " , ( long ) ( new_limit / 1024. ) , qPrintable ( torrent - > hash ( ) ) ) ;
torrent - > setDownloadLimit ( new_limit ) ;
2014-12-08 04:40:58 +03:00
}
}
}
void TransferListWidget : : setUpLimitSelectedTorrents ( )
{
2015-04-19 18:17:47 +03:00
QList < BitTorrent : : TorrentHandle * > selected_torrents ;
2014-12-08 04:40:58 +03:00
bool first = true ;
bool all_same_limit = true ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
selected_torrents < < torrent ;
// Determine current limit for selected torrents
if ( first )
first = false ;
else if ( all_same_limit & & ( torrent - > uploadLimit ( ) ! = selected_torrents . first ( ) - > uploadLimit ( ) ) )
all_same_limit = false ;
2014-12-08 04:40:58 +03:00
}
2015-06-07 15:03:30 +03:00
2014-12-08 04:40:58 +03:00
if ( selected_torrents . empty ( ) ) return ;
bool ok = false ;
int default_limit = - 1 ;
if ( all_same_limit )
2015-04-19 18:17:47 +03:00
default_limit = selected_torrents . first ( ) - > uploadLimit ( ) ;
2014-12-08 04:40:58 +03:00
const long new_limit = SpeedLimitDialog : : askSpeedLimit ( & ok , tr ( " Torrent Upload Speed Limiting " ) , default_limit , Preferences : : instance ( ) - > getGlobalUploadLimit ( ) * 1024. ) ;
if ( ok ) {
2015-04-19 18:17:47 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , selected_torrents ) {
qDebug ( " Applying upload speed limit of %ld Kb/s to torrent %s " , ( long ) ( new_limit / 1024. ) , qPrintable ( torrent - > hash ( ) ) ) ;
torrent - > setUploadLimit ( new_limit ) ;
2014-12-08 04:40:58 +03:00
}
}
}
void TransferListWidget : : setMaxRatioSelectedTorrents ( )
{
2015-06-07 15:03:30 +03:00
const QList < BitTorrent : : TorrentHandle * > torrents = getSelectedTorrents ( ) ;
if ( torrents . isEmpty ( ) ) return ;
2015-04-19 18:17:47 +03:00
bool useGlobalValue = true ;
qreal currentMaxRatio = BitTorrent : : Session : : instance ( ) - > globalMaxRatio ( ) ; ;
2015-06-07 15:03:30 +03:00
if ( torrents . count ( ) = = 1 )
currentMaxRatio = torrents [ 0 ] - > maxRatio ( & useGlobalValue ) ;
2015-04-19 18:17:47 +03:00
UpDownRatioDlg dlg ( useGlobalValue , currentMaxRatio , BitTorrent : : TorrentHandle : : MAX_RATIO , this ) ;
if ( dlg . exec ( ) ! = QDialog : : Accepted ) return ;
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , torrents ) {
qreal ratio = ( dlg . useDefault ( ) ? BitTorrent : : TorrentHandle : : USE_GLOBAL_RATIO : dlg . ratio ( ) ) ;
torrent - > setRatioLimit ( ratio ) ;
2014-12-08 04:40:58 +03:00
}
}
void TransferListWidget : : recheckSelectedTorrents ( )
{
2015-07-08 23:29:31 +03:00
if ( Preferences : : instance ( ) - > confirmTorrentRecheck ( ) ) {
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 ;
}
2015-04-19 18:17:47 +03:00
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
torrent - > forceRecheck ( ) ;
2014-12-08 04:40:58 +03:00
}
// hide/show columns menu
void TransferListWidget : : displayDLHoSMenu ( const QPoint & )
{
QMenu hideshowColumn ( this ) ;
hideshowColumn . setTitle ( tr ( " Column visibility " ) ) ;
QList < QAction * > actions ;
for ( int i = 0 ; i < listModel - > columnCount ( ) ; + + i ) {
2015-06-07 15:03:30 +03:00
if ( ! BitTorrent : : Session : : instance ( ) - > isQueueingEnabled ( ) & & i = = TorrentModel : : TR_PRIORITY ) {
2014-12-08 04:40:58 +03:00
actions . append ( 0 ) ;
continue ;
2009-11-18 14:04:19 +03:00
}
2014-12-08 04:40:58 +03:00
QAction * myAct = hideshowColumn . addAction ( listModel - > headerData ( i , Qt : : Horizontal , Qt : : DisplayRole ) . toString ( ) ) ;
myAct - > setCheckable ( true ) ;
myAct - > setChecked ( ! isColumnHidden ( i ) ) ;
actions . append ( myAct ) ;
}
int visibleCols = 0 ;
2015-06-07 15:03:30 +03:00
for ( unsigned int i = 0 ; i < TorrentModel : : NB_COLUMNS ; i + + ) {
2014-12-08 04:40:58 +03:00
if ( ! isColumnHidden ( i ) )
visibleCols + + ;
if ( visibleCols > 1 )
break ;
}
// Call menu
QAction * act = hideshowColumn . exec ( QCursor : : pos ( ) ) ;
if ( act ) {
int col = actions . indexOf ( act ) ;
Q_ASSERT ( col > = 0 ) ;
Q_ASSERT ( visibleCols > 0 ) ;
if ( ! isColumnHidden ( col ) & & visibleCols = = 1 )
return ;
qDebug ( " Toggling column %d visibility " , col ) ;
setColumnHidden ( col , ! isColumnHidden ( col ) ) ;
if ( ! isColumnHidden ( col ) & & columnWidth ( col ) < = 5 )
setColumnWidth ( col , 100 ) ;
2014-12-15 15:05:49 +03:00
saveSettings ( ) ;
2014-12-08 04:40:58 +03:00
}
}
void TransferListWidget : : toggleSelectedTorrentsSuperSeeding ( ) const
{
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) ) {
if ( torrent - > hasMetadata ( ) )
2015-04-19 18:17:47 +03:00
torrent - > setSuperSeeding ( ! torrent - > superSeeding ( ) ) ;
2014-12-08 04:40:58 +03:00
}
}
void TransferListWidget : : toggleSelectedTorrentsSequentialDownload ( ) const
{
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
torrent - > toggleSequentialDownload ( ) ;
2014-12-08 04:40:58 +03:00
}
void TransferListWidget : : toggleSelectedFirstLastPiecePrio ( ) const
{
2015-06-07 15:03:30 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
2015-11-26 15:08:01 +03:00
torrent - > toggleFirstLastPiecePriority ( ) ;
2014-12-08 04:40:58 +03:00
}
2016-02-09 11:56:48 +03:00
void TransferListWidget : : setSelectedASMEnabled ( bool enabled ) const
2014-12-08 04:40:58 +03:00
{
2016-02-09 11:56:48 +03:00
foreach ( BitTorrent : : TorrentHandle * const torrent , getSelectedTorrents ( ) )
torrent - > setASMEnabled ( enabled ) ;
}
void TransferListWidget : : askNewCategoryForSelection ( )
{
// Ask for category
2014-12-08 04:40:58 +03:00
bool ok ;
bool invalid ;
do {
invalid = false ;
2016-02-09 11:56:48 +03:00
const QString category = AutoExpandableDialog : : getText ( this , tr ( " New Category " ) , tr ( " Category: " ) , QLineEdit : : Normal , " " , & ok ) . trimmed ( ) ;
if ( ok & & ! category . isEmpty ( ) ) {
if ( ! BitTorrent : : Session : : isValidCategoryName ( category ) ) {
QMessageBox : : warning ( this , tr ( " Invalid category name " ) ,
tr ( " Category name must not contain ' \\ '. \n "
" Category name must not start/end with '/'. \n "
" Category name must not contain '//' sequence. " ) ) ;
invalid = true ;
2014-12-08 04:40:58 +03:00
}
else {
2016-02-09 11:56:48 +03:00
setSelectionCategory ( category ) ;
2014-12-08 04:40:58 +03:00
}
}
} while ( invalid ) ;
}
void TransferListWidget : : renameSelectedTorrent ( )
{
const QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
if ( selectedIndexes . size ( ) ! = 1 ) return ;
if ( ! selectedIndexes . first ( ) . isValid ( ) ) return ;
2015-06-07 15:03:30 +03:00
const QModelIndex mi = listModel - > index ( mapToSource ( selectedIndexes . first ( ) ) . row ( ) , TorrentModel : : TR_NAME ) ;
BitTorrent : : TorrentHandle * const torrent = listModel - > torrentHandle ( mi ) ;
2015-04-19 18:17:47 +03:00
if ( ! torrent ) return ;
2014-12-08 04:40:58 +03:00
// Ask for a new Name
bool ok ;
2015-04-19 18:17:47 +03:00
QString name = AutoExpandableDialog : : getText ( this , tr ( " Rename " ) , tr ( " New name: " ) , QLineEdit : : Normal , torrent - > name ( ) , & ok ) ;
2014-12-08 04:40:58 +03:00
if ( ok & & ! name . isEmpty ( ) ) {
name . replace ( QRegExp ( " \r ? \n | \r " ) , " " ) ;
// Rename the torrent
listModel - > setData ( mi , name , Qt : : DisplayRole ) ;
}
}
2016-02-09 11:56:48 +03:00
void TransferListWidget : : setSelectionCategory ( QString category )
2014-12-08 04:40:58 +03:00
{
2015-06-07 15:03:30 +03:00
foreach ( const QModelIndex & index , selectionModel ( ) - > selectedRows ( ) )
2016-02-09 11:56:48 +03:00
listModel - > setData ( listModel - > index ( mapToSource ( index ) . row ( ) , TorrentModel : : TR_CATEGORY ) , category , Qt : : DisplayRole ) ;
2014-12-08 04:40:58 +03:00
}
void TransferListWidget : : displayListMenu ( const QPoint & )
{
QModelIndexList selectedIndexes = selectionModel ( ) - > selectedRows ( ) ;
if ( selectedIndexes . size ( ) = = 0 )
return ;
// Create actions
2015-04-19 18:17:47 +03:00
QAction actionStart ( GuiIconProvider : : instance ( ) - > getIcon ( " media-playback-start " ) , tr ( " Resume " , " Resume/start the torrent " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionStart , SIGNAL ( triggered ( ) ) , this , SLOT ( startSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionPause ( GuiIconProvider : : instance ( ) - > getIcon ( " media-playback-pause " ) , tr ( " Pause " , " Pause the torrent " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionPause , SIGNAL ( triggered ( ) ) , this , SLOT ( pauseSelectedTorrents ( ) ) ) ;
2015-07-12 17:40:25 +03:00
QAction actionForceStart ( GuiIconProvider : : instance ( ) - > getIcon ( " media-seek-forward " ) , tr ( " Force Resume " , " Force Resume/start the torrent " ) , 0 ) ;
connect ( & actionForceStart , SIGNAL ( triggered ( ) ) , this , SLOT ( forceStartSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionDelete ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-delete " ) , tr ( " Delete " , " Delete the torrent " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionDelete , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionPreview_file ( GuiIconProvider : : instance ( ) - > getIcon ( " view-preview " ) , tr ( " Preview file... " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionPreview_file , SIGNAL ( triggered ( ) ) , this , SLOT ( previewSelectedTorrents ( ) ) ) ;
2015-01-18 15:13:06 +03:00
QAction actionSet_max_ratio ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/ratio.png " ) ) , tr ( " Limit share ratio... " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionSet_max_ratio , SIGNAL ( triggered ( ) ) , this , SLOT ( setMaxRatioSelectedTorrents ( ) ) ) ;
2016-01-10 15:30:34 +03:00
QAction actionSet_upload_limit ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/uploadLimit.png " ) ) , tr ( " Limit upload rate... " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionSet_upload_limit , SIGNAL ( triggered ( ) ) , this , SLOT ( setUpLimitSelectedTorrents ( ) ) ) ;
2016-01-10 15:30:34 +03:00
QAction actionSet_download_limit ( QIcon ( QString : : fromUtf8 ( " :/icons/skin/downloadLimit.png " ) ) , tr ( " Limit download rate... " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionSet_download_limit , SIGNAL ( triggered ( ) ) , this , SLOT ( setDlLimitSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionOpen_destination_folder ( GuiIconProvider : : instance ( ) - > getIcon ( " inode-directory " ) , tr ( " Open destination folder " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionOpen_destination_folder , SIGNAL ( triggered ( ) ) , this , SLOT ( openSelectedTorrentsFolder ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionIncreasePriority ( GuiIconProvider : : instance ( ) - > getIcon ( " go-up " ) , tr ( " Move up " , " i.e. move up in the queue " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionIncreasePriority , SIGNAL ( triggered ( ) ) , this , SLOT ( increasePrioSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionDecreasePriority ( GuiIconProvider : : instance ( ) - > getIcon ( " go-down " ) , tr ( " Move down " , " i.e. Move down in the queue " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionDecreasePriority , SIGNAL ( triggered ( ) ) , this , SLOT ( decreasePrioSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionTopPriority ( GuiIconProvider : : instance ( ) - > getIcon ( " go-top " ) , tr ( " Move to top " , " i.e. Move to top of the queue " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionTopPriority , SIGNAL ( triggered ( ) ) , this , SLOT ( topPrioSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionBottomPriority ( GuiIconProvider : : instance ( ) - > getIcon ( " go-bottom " ) , tr ( " Move to bottom " , " i.e. Move to bottom of the queue " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionBottomPriority , SIGNAL ( triggered ( ) ) , this , SLOT ( bottomPrioSelectedTorrents ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionSetTorrentPath ( GuiIconProvider : : instance ( ) - > getIcon ( " inode-directory " ) , tr ( " Set location... " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionSetTorrentPath , SIGNAL ( triggered ( ) ) , this , SLOT ( setSelectedTorrentsLocation ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionForce_recheck ( GuiIconProvider : : instance ( ) - > getIcon ( " document-edit-verify " ) , tr ( " Force recheck " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionForce_recheck , SIGNAL ( triggered ( ) ) , this , SLOT ( recheckSelectedTorrents ( ) ) ) ;
2015-01-18 15:13:06 +03:00
QAction actionCopy_magnet_link ( QIcon ( " :/icons/magnet.png " ) , tr ( " Copy magnet link " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionCopy_magnet_link , SIGNAL ( triggered ( ) ) , this , SLOT ( copySelectedMagnetURIs ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionCopy_name ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-copy " ) , tr ( " Copy name " ) , 0 ) ;
2015-02-06 21:56:24 +03:00
connect ( & actionCopy_name , SIGNAL ( triggered ( ) ) , this , SLOT ( copySelectedNames ( ) ) ) ;
2014-12-08 04:40:58 +03:00
QAction actionSuper_seeding_mode ( tr ( " Super seeding mode " ) , 0 ) ;
actionSuper_seeding_mode . setCheckable ( true ) ;
connect ( & actionSuper_seeding_mode , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleSelectedTorrentsSuperSeeding ( ) ) ) ;
2015-04-19 18:17:47 +03:00
QAction actionRename ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename... " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
connect ( & actionRename , SIGNAL ( triggered ( ) ) , this , SLOT ( renameSelectedTorrent ( ) ) ) ;
QAction actionSequential_download ( tr ( " Download in sequential order " ) , 0 ) ;
actionSequential_download . setCheckable ( true ) ;
connect ( & actionSequential_download , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleSelectedTorrentsSequentialDownload ( ) ) ) ;
2015-09-18 05:58:16 +03:00
QAction actionFirstLastPiece_prio ( tr ( " Download first and last pieces first " ) , 0 ) ;
2014-12-08 04:40:58 +03:00
actionFirstLastPiece_prio . setCheckable ( true ) ;
connect ( & actionFirstLastPiece_prio , SIGNAL ( triggered ( ) ) , this , SLOT ( toggleSelectedFirstLastPiecePrio ( ) ) ) ;
2016-02-09 11:56:48 +03:00
QAction actionEnableASM ( tr ( " Enable Advanced Saving Management " ) , 0 ) ;
actionEnableASM . setCheckable ( true ) ;
connect ( & actionEnableASM , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setSelectedASMEnabled ( bool ) ) ) ;
2014-12-08 04:40:58 +03:00
// End of actions
2015-07-19 22:59:07 +03:00
2014-12-08 04:40:58 +03:00
// Enable/disable pause/start action given the DL state
2015-07-19 22:59:07 +03:00
bool needs_pause = false , needs_start = false , needs_force = false , needs_preview = false ;
2014-12-08 04:40:58 +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 ;
bool one_has_metadata = false , one_not_seed = false ;
2016-02-09 11:56:48 +03:00
bool allSameCategory = true ;
bool allSameASM = true ;
bool firstASM = false ;
QString firstCategory ;
2014-12-08 04:40:58 +03:00
bool first = true ;
2015-04-19 18:17:47 +03:00
BitTorrent : : TorrentHandle * torrent ;
2014-12-08 04:40:58 +03:00
qDebug ( " Displaying menu " ) ;
foreach ( const QModelIndex & index , selectedIndexes ) {
// Get the file name
// Get handle and pause the torrent
2015-06-07 15:03:30 +03:00
torrent = listModel - > torrentHandle ( mapToSource ( index ) ) ;
2015-04-19 18:17:47 +03:00
if ( ! torrent ) continue ;
2016-02-09 11:56:48 +03:00
if ( firstCategory . isEmpty ( ) & & first )
firstCategory = torrent - > category ( ) ;
if ( firstCategory ! = torrent - > category ( ) )
allSameCategory = false ;
2015-09-16 02:01:51 +03:00
2016-02-09 11:56:48 +03:00
if ( first )
firstASM = torrent - > isASMEnabled ( ) ;
if ( firstASM ! = torrent - > isASMEnabled ( ) )
allSameASM = false ;
2015-09-16 02:01:51 +03:00
2015-04-19 18:17:47 +03:00
if ( torrent - > hasMetadata ( ) )
2014-12-08 04:40:58 +03:00
one_has_metadata = true ;
2015-04-19 18:17:47 +03:00
if ( ! torrent - > isSeed ( ) ) {
2014-12-08 04:40:58 +03:00
one_not_seed = true ;
2015-04-19 18:17:47 +03:00
if ( torrent - > hasMetadata ( ) ) {
2014-12-08 04:40:58 +03:00
if ( first ) {
2015-04-19 18:17:47 +03:00
sequential_download_mode = torrent - > isSequentialDownload ( ) ;
prioritize_first_last = torrent - > hasFirstLastPiecePriority ( ) ;
2014-12-08 04:40:58 +03:00
}
else {
2015-04-19 18:17:47 +03:00
if ( sequential_download_mode ! = torrent - > isSequentialDownload ( ) )
2014-12-08 04:40:58 +03:00
all_same_sequential_download_mode = false ;
2015-04-19 18:17:47 +03:00
if ( prioritize_first_last ! = torrent - > hasFirstLastPiecePriority ( ) )
2014-12-08 04:40:58 +03:00
all_same_prio_firstlast = false ;
}
}
}
else {
2015-04-19 18:17:47 +03:00
if ( ! one_not_seed & & all_same_super_seeding & & torrent - > hasMetadata ( ) ) {
2014-12-08 04:40:58 +03:00
if ( first ) {
2015-04-19 18:17:47 +03:00
super_seeding_mode = torrent - > superSeeding ( ) ;
2014-12-08 04:40:58 +03:00
}
2015-04-19 18:17:47 +03:00
else if ( super_seeding_mode ! = torrent - > superSeeding ( ) )
2014-12-08 04:40:58 +03:00
all_same_super_seeding = false ;
}
}
2015-07-19 22:59:07 +03:00
if ( ! torrent - > isForced ( ) )
needs_force = true ;
else
needs_start = true ;
if ( torrent - > isPaused ( ) )
needs_start = true ;
else
needs_pause = true ;
if ( torrent - > hasMetadata ( ) )
needs_preview = true ;
2014-12-08 04:40:58 +03:00
first = false ;
2015-07-19 22:59:07 +03:00
if ( one_has_metadata & & one_not_seed & & ! all_same_sequential_download_mode
2016-02-09 11:56:48 +03:00
& & ! all_same_prio_firstlast & & ! all_same_super_seeding & & ! allSameCategory
& & needs_start & & needs_force & & needs_pause & & needs_preview & & ! allSameASM ) {
2015-07-19 22:59:07 +03:00
break ;
}
2014-12-08 04:40:58 +03:00
}
2015-07-19 22:59:07 +03:00
QMenu listMenu ( this ) ;
if ( needs_start )
listMenu . addAction ( & actionStart ) ;
if ( needs_pause )
listMenu . addAction ( & actionPause ) ;
if ( needs_force )
listMenu . addAction ( & actionForceStart ) ;
2009-11-21 16:51:15 +03:00
listMenu . addSeparator ( ) ;
2014-12-08 04:40:58 +03:00
listMenu . addAction ( & actionDelete ) ;
2009-11-08 00:04:56 +03:00
listMenu . addSeparator ( ) ;
2014-12-08 04:40:58 +03:00
listMenu . addAction ( & actionSetTorrentPath ) ;
if ( selectedIndexes . size ( ) = = 1 )
listMenu . addAction ( & actionRename ) ;
2016-02-09 11:56:48 +03:00
// Category Menu
QStringList categories = BitTorrent : : Session : : instance ( ) - > categories ( ) ;
2015-10-11 16:15:41 +03:00
std : : sort ( categories . begin ( ) , categories . end ( ) , Utils : : String : : naturalCompare ) ;
2016-02-09 11:56:48 +03:00
QList < QAction * > categoryActions ;
QMenu * categoryMenu = listMenu . addMenu ( GuiIconProvider : : instance ( ) - > getIcon ( " view-categories " ) , tr ( " Category " ) ) ;
categoryActions < < categoryMenu - > addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " list-add " ) , tr ( " New... " , " New category... " ) ) ;
categoryActions < < categoryMenu - > addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-clear " ) , tr ( " Reset " , " Reset category " ) ) ;
categoryMenu - > addSeparator ( ) ;
foreach ( QString category , categories ) {
category . replace ( ' & ' , " && " ) ; // avoid '&' becomes accelerator key
QAction * cat = new QAction ( GuiIconProvider : : instance ( ) - > getIcon ( " inode-directory " ) , category , categoryMenu ) ;
if ( allSameCategory & & ( category = = firstCategory ) ) {
cat - > setCheckable ( true ) ;
cat - > setChecked ( true ) ;
2015-09-16 02:01:51 +03:00
}
2016-02-09 11:56:48 +03:00
categoryMenu - > addAction ( cat ) ;
categoryActions < < cat ;
2015-07-19 08:02:41 +03:00
}
2016-02-09 11:56:48 +03:00
if ( allSameASM ) {
actionEnableASM . setChecked ( firstASM ) ;
listMenu . addAction ( & actionEnableASM ) ;
}
2014-12-08 04:40:58 +03:00
listMenu . addSeparator ( ) ;
if ( one_not_seed )
listMenu . addAction ( & actionSet_download_limit ) ;
listMenu . addAction ( & actionSet_upload_limit ) ;
2016-01-10 15:30:34 +03:00
listMenu . addAction ( & actionSet_max_ratio ) ;
2014-12-08 04:40:58 +03:00
if ( ! one_not_seed & & all_same_super_seeding & & one_has_metadata ) {
actionSuper_seeding_mode . setChecked ( super_seeding_mode ) ;
listMenu . addAction ( & actionSuper_seeding_mode ) ;
}
listMenu . addSeparator ( ) ;
bool added_preview_action = false ;
2015-07-19 22:59:07 +03:00
if ( needs_preview ) {
2014-12-08 04:40:58 +03:00
listMenu . addAction ( & actionPreview_file ) ;
added_preview_action = true ;
}
if ( one_not_seed & & one_has_metadata ) {
if ( all_same_sequential_download_mode ) {
actionSequential_download . setChecked ( sequential_download_mode ) ;
listMenu . addAction ( & actionSequential_download ) ;
added_preview_action = true ;
}
if ( all_same_prio_firstlast ) {
actionFirstLastPiece_prio . setChecked ( prioritize_first_last ) ;
listMenu . addAction ( & actionFirstLastPiece_prio ) ;
added_preview_action = true ;
}
}
2016-02-09 11:56:48 +03:00
2014-12-08 04:40:58 +03:00
if ( added_preview_action )
listMenu . addSeparator ( ) ;
if ( one_has_metadata ) {
listMenu . addAction ( & actionForce_recheck ) ;
listMenu . addSeparator ( ) ;
}
listMenu . addAction ( & actionOpen_destination_folder ) ;
2015-04-19 18:17:47 +03:00
if ( BitTorrent : : Session : : instance ( ) - > isQueueingEnabled ( ) & & one_not_seed ) {
2014-12-08 04:40:58 +03:00
listMenu . addSeparator ( ) ;
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 ( ) ;
2015-02-06 21:56:24 +03:00
listMenu . addAction ( & actionCopy_name ) ;
2015-02-06 06:47:59 +03:00
listMenu . addAction ( & actionCopy_magnet_link ) ;
2014-12-08 04:40:58 +03:00
// Call menu
QAction * act = 0 ;
act = listMenu . exec ( QCursor : : pos ( ) ) ;
if ( act ) {
2016-02-09 11:56:48 +03:00
// Parse category actions only (others have slots assigned)
int i = categoryActions . indexOf ( act ) ;
2014-12-08 04:40:58 +03:00
if ( i > = 0 ) {
2016-02-09 11:56:48 +03:00
// Category action
2014-12-08 04:40:58 +03:00
if ( i = = 0 ) {
2016-02-09 11:56:48 +03:00
// New Category
askNewCategoryForSelection ( ) ;
2014-12-08 04:40:58 +03:00
}
else {
2016-02-09 11:56:48 +03:00
QString category = " " ;
2014-12-08 04:40:58 +03:00
if ( i > 1 )
2016-02-09 11:56:48 +03:00
category = categories . at ( i - 2 ) ;
// Update Category
setSelectionCategory ( category ) ;
2014-12-08 04:40:58 +03:00
}
}
}
}
void TransferListWidget : : currentChanged ( const QModelIndex & current , const QModelIndex & )
{
qDebug ( " CURRENT CHANGED " ) ;
2015-04-19 18:17:47 +03:00
BitTorrent : : TorrentHandle * torrent = 0 ;
2014-12-08 04:40:58 +03:00
if ( current . isValid ( ) ) {
2015-06-07 15:03:30 +03:00
torrent = listModel - > torrentHandle ( mapToSource ( current ) ) ;
2014-12-08 04:40:58 +03:00
// Scroll Fix
scrollTo ( current ) ;
}
2015-04-19 18:17:47 +03:00
emit currentTorrentChanged ( torrent ) ;
2014-12-08 04:40:58 +03:00
}
2016-02-09 11:56:48 +03:00
void TransferListWidget : : applyCategoryFilter ( QString category )
2014-12-08 04:40:58 +03:00
{
2016-02-09 11:56:48 +03:00
if ( category . isNull ( ) )
nameFilterModel - > disableCategoryFilter ( ) ;
2015-07-14 16:03:51 +03:00
else
2016-02-09 11:56:48 +03:00
nameFilterModel - > setCategoryFilter ( category ) ;
2014-12-08 04:40:58 +03:00
}
2015-03-22 02:18:21 +03:00
void TransferListWidget : : applyTrackerFilterAll ( )
{
nameFilterModel - > disableTrackerFilter ( ) ;
}
void TransferListWidget : : applyTrackerFilter ( const QStringList & hashes )
{
nameFilterModel - > setTrackerFilter ( hashes ) ;
}
2014-12-08 04:40:58 +03:00
void TransferListWidget : : applyNameFilter ( const QString & name )
{
2015-11-26 21:02:43 +03:00
nameFilterModel - > setFilterRegExp ( QRegExp ( name , Qt : : CaseInsensitive , QRegExp : : WildcardUnix ) ) ;
2014-12-08 04:40:58 +03:00
}
void TransferListWidget : : applyStatusFilter ( int f )
{
2015-04-19 18:17:47 +03:00
nameFilterModel - > setStatusFilter ( static_cast < TorrentFilter : : Type > ( f ) ) ;
2014-12-08 04:40:58 +03:00
// Select first item if nothing is selected
if ( selectionModel ( ) - > selectedRows ( 0 ) . empty ( ) & & nameFilterModel - > rowCount ( ) > 0 ) {
2015-06-07 15:03:30 +03:00
qDebug ( " Nothing is selected, selecting first row: %s " , qPrintable ( nameFilterModel - > index ( 0 , TorrentModel : : TR_NAME ) . data ( ) . toString ( ) ) ) ;
selectionModel ( ) - > setCurrentIndex ( nameFilterModel - > index ( 0 , TorrentModel : : TR_NAME ) , QItemSelectionModel : : SelectCurrent | QItemSelectionModel : : Rows ) ;
2014-12-08 04:40:58 +03: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-12-08 04:40:58 +03: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-12-08 04:40:58 +03:00
bool ok = header ( ) - > restoreState ( Preferences : : instance ( ) - > getTransHeaderState ( ) ) ;
if ( ! ok )
header ( ) - > resizeSection ( 0 , 200 ) ; // Default
return ok ;
2010-12-04 12:51:43 +03:00
}
2015-06-07 15:03:30 +03:00
QStringList extractHashes ( const QList < BitTorrent : : TorrentHandle * > & torrents )
{
QStringList hashes ;
foreach ( BitTorrent : : TorrentHandle * const torrent , torrents )
hashes < < torrent - > hash ( ) ;
return hashes ;
}