@ -1,6 +1,6 @@
/*
/*
* Bittorrent Client using Qt and libtorrent .
* Bittorrent Client using Qt and libtorrent .
* Copyright ( C ) 2012 Christophe Dumez
* Copyright ( C ) 2012 Christophe Dumez < chris @ qbittorrent . org >
*
*
* This program is free software ; you can redistribute it and / or
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file ( s ) , you may extend this exception to your version of the file ( s ) ,
* 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
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
* exception statement from your version .
*
* Contact : chris @ qbittorrent . org
*/
*/
# include "addnewtorrentdialog.h"
# include "addnewtorrentdialog.h"
@ -38,7 +36,6 @@
# include <QString>
# include <QString>
# include <QUrl>
# include <QUrl>
# include "autoexpandabledialog.h"
# include "base/bittorrent/magneturi.h"
# include "base/bittorrent/magneturi.h"
# include "base/bittorrent/session.h"
# include "base/bittorrent/session.h"
# include "base/bittorrent/torrenthandle.h"
# include "base/bittorrent/torrenthandle.h"
@ -53,6 +50,7 @@
# include "base/utils/fs.h"
# include "base/utils/fs.h"
# include "base/utils/misc.h"
# include "base/utils/misc.h"
# include "base/utils/string.h"
# include "base/utils/string.h"
# include "autoexpandabledialog.h"
# include "guiiconprovider.h"
# include "guiiconprovider.h"
# include "messageboxraised.h"
# include "messageboxraised.h"
# include "proplistdelegate.h"
# include "proplistdelegate.h"
@ -85,7 +83,7 @@ constexpr int AddNewTorrentDialog::maxPathHistoryLength;
AddNewTorrentDialog : : AddNewTorrentDialog ( const BitTorrent : : AddTorrentParams & inParams , QWidget * parent )
AddNewTorrentDialog : : AddNewTorrentDialog ( const BitTorrent : : AddTorrentParams & inParams , QWidget * parent )
: QDialog ( parent )
: QDialog ( parent )
, ui ( new Ui : : AddNewTorrentDialog )
, m_ ui( new Ui : : AddNewTorrentDialog )
, m_contentModel ( nullptr )
, m_contentModel ( nullptr )
, m_contentDelegate ( nullptr )
, m_contentDelegate ( nullptr )
, m_hasMetadata ( false )
, m_hasMetadata ( false )
@ -93,40 +91,40 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
, m_torrentParams ( inParams )
, m_torrentParams ( inParams )
{
{
// TODO: set dialog file properties using m_torrentParams.filePriorities
// TODO: set dialog file properties using m_torrentParams.filePriorities
ui - > setupUi ( this ) ;
m_ ui- > setupUi ( this ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
ui - > lblMetaLoading - > setVisible ( false ) ;
m_ ui- > lblMetaLoading - > setVisible ( false ) ;
ui - > progMetaLoading - > setVisible ( false ) ;
m_ ui- > progMetaLoading - > setVisible ( false ) ;
ui - > savePath - > setMode ( FileSystemPathEdit : : Mode : : DirectorySave ) ;
m_ ui- > savePath - > setMode ( FileSystemPathEdit : : Mode : : DirectorySave ) ;
ui - > savePath - > setDialogCaption ( tr ( " Choose save path " ) ) ;
m_ ui- > savePath - > setDialogCaption ( tr ( " Choose save path " ) ) ;
ui - > savePath - > setMaxVisibleItems ( 20 ) ;
m_ ui- > savePath - > setMaxVisibleItems ( 20 ) ;
auto session = BitTorrent : : Session : : instance ( ) ;
auto session = BitTorrent : : Session : : instance ( ) ;
if ( m_torrentParams . addPaused = = TriStateBool : : True )
if ( m_torrentParams . addPaused = = TriStateBool : : True )
ui - > startTorrentCheckBox - > setChecked ( false ) ;
m_ ui- > startTorrentCheckBox - > setChecked ( false ) ;
else if ( m_torrentParams . addPaused = = TriStateBool : : False )
else if ( m_torrentParams . addPaused = = TriStateBool : : False )
ui - > startTorrentCheckBox - > setChecked ( true ) ;
m_ ui- > startTorrentCheckBox - > setChecked ( true ) ;
else
else
ui - > startTorrentCheckBox - > setChecked ( ! session - > isAddTorrentPaused ( ) ) ;
m_ ui- > startTorrentCheckBox - > setChecked ( ! session - > isAddTorrentPaused ( ) ) ;
ui - > comboTTM - > blockSignals ( true ) ; // the TreeView size isn't correct if the slot does it job at this point
m_ ui- > comboTTM - > blockSignals ( true ) ; // the TreeView size isn't correct if the slot does it job at this point
ui - > comboTTM - > setCurrentIndex ( ! session - > isAutoTMMDisabledByDefault ( ) ) ;
m_ ui- > comboTTM - > setCurrentIndex ( ! session - > isAutoTMMDisabledByDefault ( ) ) ;
ui - > comboTTM - > blockSignals ( false ) ;
m_ ui- > comboTTM - > blockSignals ( false ) ;
populateSavePathComboBox ( ) ;
populateSavePathComboBox ( ) ;
connect ( ui - > savePath , & FileSystemPathEdit : : selectedPathChanged , this , & AddNewTorrentDialog : : onSavePathChanged ) ;
connect ( m_ ui- > savePath , & FileSystemPathEdit : : selectedPathChanged , this , & AddNewTorrentDialog : : onSavePathChanged ) ;
ui - > defaultSavePathCheckBox - > setVisible ( false ) ; // Default path is selected by default
m_ ui- > defaultSavePathCheckBox - > setVisible ( false ) ; // Default path is selected by default
if ( m_torrentParams . createSubfolder = = TriStateBool : : True )
if ( m_torrentParams . createSubfolder = = TriStateBool : : True )
ui - > createSubfolderCheckBox - > setChecked ( true ) ;
m_ ui- > createSubfolderCheckBox - > setChecked ( true ) ;
else if ( m_torrentParams . createSubfolder = = TriStateBool : : False )
else if ( m_torrentParams . createSubfolder = = TriStateBool : : False )
ui - > createSubfolderCheckBox - > setChecked ( false ) ;
m_ ui- > createSubfolderCheckBox - > setChecked ( false ) ;
else
else
ui - > createSubfolderCheckBox - > setChecked ( session - > isCreateTorrentSubfolder ( ) ) ;
m_ ui- > createSubfolderCheckBox - > setChecked ( session - > isCreateTorrentSubfolder ( ) ) ;
ui - > skipCheckingCheckBox - > setChecked ( m_torrentParams . skipChecking ) ;
m_ ui- > skipCheckingCheckBox - > setChecked ( m_torrentParams . skipChecking ) ;
ui - > doNotDeleteTorrentCheckBox - > setVisible ( TorrentFileGuard : : autoDeleteMode ( ) ! = TorrentFileGuard : : Never ) ;
m_ ui- > doNotDeleteTorrentCheckBox - > setVisible ( TorrentFileGuard : : autoDeleteMode ( ) ! = TorrentFileGuard : : Never ) ;
// Load categories
// Load categories
QStringList categories = session - > categories ( ) . keys ( ) ;
QStringList categories = session - > categories ( ) . keys ( ) ;
@ -134,25 +132,25 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
QString defaultCategory = settings ( ) - > loadValue ( KEY_DEFAULTCATEGORY ) . toString ( ) ;
QString defaultCategory = settings ( ) - > loadValue ( KEY_DEFAULTCATEGORY ) . toString ( ) ;
if ( ! m_torrentParams . category . isEmpty ( ) )
if ( ! m_torrentParams . category . isEmpty ( ) )
ui - > categoryComboBox - > addItem ( m_torrentParams . category ) ;
m_ ui- > categoryComboBox - > addItem ( m_torrentParams . category ) ;
if ( ! defaultCategory . isEmpty ( ) )
if ( ! defaultCategory . isEmpty ( ) )
ui - > categoryComboBox - > addItem ( defaultCategory ) ;
m_ ui- > categoryComboBox - > addItem ( defaultCategory ) ;
ui - > categoryComboBox - > addItem ( " " ) ;
m_ ui- > categoryComboBox - > addItem ( " " ) ;
foreach ( const QString & category , categories )
foreach ( const QString & category , categories )
if ( category ! = defaultCategory & & category ! = m_torrentParams . category )
if ( category ! = defaultCategory & & category ! = m_torrentParams . category )
ui - > categoryComboBox - > addItem ( category ) ;
m_ ui- > categoryComboBox - > addItem ( category ) ;
ui - > contentTreeView - > header ( ) - > setSortIndicator ( 0 , Qt : : AscendingOrder ) ;
m_ ui- > contentTreeView - > header ( ) - > setSortIndicator ( 0 , Qt : : AscendingOrder ) ;
loadState ( ) ;
loadState ( ) ;
// Signal / slots
// Signal / slots
connect ( ui - > adv_button , & QToolButton : : clicked , this , & AddNewTorrentDialog : : showAdvancedSettings ) ;
connect ( m_ ui- > adv_button , & QToolButton : : clicked , this , & AddNewTorrentDialog : : showAdvancedSettings ) ;
connect ( ui - > doNotDeleteTorrentCheckBox , & QCheckBox : : clicked , this , & AddNewTorrentDialog : : doNotDeleteTorrentClicked ) ;
connect ( m_ ui- > doNotDeleteTorrentCheckBox , & QCheckBox : : clicked , this , & AddNewTorrentDialog : : doNotDeleteTorrentClicked ) ;
QShortcut * editHotkey = new QShortcut ( Qt : : Key_F2 , ui - > contentTreeView , nullptr , nullptr , Qt : : WidgetShortcut ) ;
QShortcut * editHotkey = new QShortcut ( Qt : : Key_F2 , m_ ui- > contentTreeView , nullptr , nullptr , Qt : : WidgetShortcut ) ;
connect ( editHotkey , & QShortcut : : activated , this , & AddNewTorrentDialog : : renameSelectedFile ) ;
connect ( editHotkey , & QShortcut : : activated , this , & AddNewTorrentDialog : : renameSelectedFile ) ;
connect ( ui - > contentTreeView , & QAbstractItemView : : doubleClicked , this , & AddNewTorrentDialog : : renameSelectedFile ) ;
connect ( m_ ui- > contentTreeView , & QAbstractItemView : : doubleClicked , this , & AddNewTorrentDialog : : renameSelectedFile ) ;
ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setFocus ( ) ;
m_ ui- > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setFocus ( ) ;
}
}
AddNewTorrentDialog : : ~ AddNewTorrentDialog ( )
AddNewTorrentDialog : : ~ AddNewTorrentDialog ( )
@ -160,7 +158,7 @@ AddNewTorrentDialog::~AddNewTorrentDialog()
saveState ( ) ;
saveState ( ) ;
delete m_contentDelegate ;
delete m_contentDelegate ;
delete ui ;
delete m_ ui;
}
}
bool AddNewTorrentDialog : : isEnabled ( )
bool AddNewTorrentDialog : : isEnabled ( )
@ -220,15 +218,15 @@ void AddNewTorrentDialog::loadState()
const int height = newSize . height ( ) ;
const int height = newSize . height ( ) ;
resize ( width , height ) ;
resize ( width , height ) ;
ui - > adv_button - > setChecked ( settings ( ) - > loadValue ( KEY_EXPANDED ) . toBool ( ) ) ;
m_ ui- > adv_button - > setChecked ( settings ( ) - > loadValue ( KEY_EXPANDED ) . toBool ( ) ) ;
}
}
void AddNewTorrentDialog : : saveState ( )
void AddNewTorrentDialog : : saveState ( )
{
{
if ( m_contentModel )
if ( m_contentModel )
settings ( ) - > storeValue ( KEY_TREEHEADERSTATE , ui - > contentTreeView - > header ( ) - > saveState ( ) ) ;
settings ( ) - > storeValue ( KEY_TREEHEADERSTATE , m_ ui- > contentTreeView - > header ( ) - > saveState ( ) ) ;
settings ( ) - > storeValue ( KEY_WIDTH , width ( ) ) ;
settings ( ) - > storeValue ( KEY_WIDTH , width ( ) ) ;
settings ( ) - > storeValue ( KEY_EXPANDED , ui - > adv_button - > isChecked ( ) ) ;
settings ( ) - > storeValue ( KEY_EXPANDED , m_ ui- > adv_button - > isChecked ( ) ) ;
}
}
void AddNewTorrentDialog : : show ( QString source , const BitTorrent : : AddTorrentParams & inParams , QWidget * parent )
void AddNewTorrentDialog : : show ( QString source , const BitTorrent : : AddTorrentParams & inParams , QWidget * parent )
@ -316,9 +314,9 @@ bool AddNewTorrentDialog::loadTorrent(const QString &torrentPath)
return false ;
return false ;
}
}
ui - > lblhash - > setText ( m_hash ) ;
m_ ui- > lblhash - > setText ( m_hash ) ;
setupTreeview ( ) ;
setupTreeview ( ) ;
TMMChanged ( ui - > comboTTM - > currentIndex ( ) ) ;
TMMChanged ( m_ ui- > comboTTM - > currentIndex ( ) ) ;
return true ;
return true ;
}
}
@ -353,15 +351,15 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri)
connect ( BitTorrent : : Session : : instance ( ) , & BitTorrent : : Session : : metadataLoaded , this , & AddNewTorrentDialog : : updateMetadata ) ;
connect ( BitTorrent : : Session : : instance ( ) , & BitTorrent : : Session : : metadataLoaded , this , & AddNewTorrentDialog : : updateMetadata ) ;
// Set dialog title
// Set dialog title
QString torrent_n ame = magnetUri . name ( ) ;
QString torrentN ame = magnetUri . name ( ) ;
setWindowTitle ( torrent_n ame . isEmpty ( ) ? tr ( " Magnet link " ) : torrent_n ame ) ;
setWindowTitle ( torrentN ame . isEmpty ( ) ? tr ( " Magnet link " ) : torrentN ame ) ;
setupTreeview ( ) ;
setupTreeview ( ) ;
TMMChanged ( ui - > comboTTM - > currentIndex ( ) ) ;
TMMChanged ( m_ ui- > comboTTM - > currentIndex ( ) ) ;
BitTorrent : : Session : : instance ( ) - > loadMetadata ( magnetUri ) ;
BitTorrent : : Session : : instance ( ) - > loadMetadata ( magnetUri ) ;
setMetadataProgressIndicator ( true , tr ( " Retrieving metadata... " ) ) ;
setMetadataProgressIndicator ( true , tr ( " Retrieving metadata... " ) ) ;
ui - > lblhash - > setText ( m_hash ) ;
m_ ui- > lblhash - > setText ( m_hash ) ;
return true ;
return true ;
}
}
@ -378,19 +376,19 @@ void AddNewTorrentDialog::showEvent(QShowEvent *event)
void AddNewTorrentDialog : : showAdvancedSettings ( bool show )
void AddNewTorrentDialog : : showAdvancedSettings ( bool show )
{
{
const int minimumW = minimumWidth ( ) ;
const int minimumW = minimumWidth ( ) ;
setMinimumWidth ( width ( ) ) ; // to remain the same width
setMinimumWidth ( width ( ) ) ; // to remain the same width
if ( show ) {
if ( show ) {
ui - > adv_button - > setText ( QString : : fromUtf8 ( C_UP ) ) ;
m_ ui- > adv_button - > setText ( QString : : fromUtf8 ( C_UP ) ) ;
ui - > settings_group - > setVisible ( true ) ;
m_ ui- > settings_group - > setVisible ( true ) ;
ui - > infoGroup - > setVisible ( true ) ;
m_ ui- > infoGroup - > setVisible ( true ) ;
ui - > contentTreeView - > setVisible ( m_hasMetadata ) ;
m_ ui- > contentTreeView - > setVisible ( m_hasMetadata ) ;
static_cast < QVBoxLayout * > ( layout ( ) ) - > insertWidget ( layout ( ) - > indexOf ( ui - > never_show_cb ) + 1 , ui - > adv_button ) ;
static_cast < QVBoxLayout * > ( layout ( ) ) - > insertWidget ( layout ( ) - > indexOf ( m_ ui- > never_show_cb ) + 1 , m_ ui- > adv_button ) ;
}
}
else {
else {
ui - > adv_button - > setText ( QString : : fromUtf8 ( C_DOWN ) ) ;
m_ ui- > adv_button - > setText ( QString : : fromUtf8 ( C_DOWN ) ) ;
ui - > settings_group - > setVisible ( false ) ;
m_ ui- > settings_group - > setVisible ( false ) ;
ui - > infoGroup - > setVisible ( false ) ;
m_ ui- > infoGroup - > setVisible ( false ) ;
ui - > buttonsHLayout - > insertWidget ( 0 , layout ( ) - > takeAt ( layout ( ) - > indexOf ( ui - > never_show_cb ) + 1 ) - > widget ( ) ) ;
m_ ui- > buttonsHLayout - > insertWidget ( 0 , layout ( ) - > takeAt ( layout ( ) - > indexOf ( m_ ui- > never_show_cb ) + 1 ) - > widget ( ) ) ;
}
}
adjustSize ( ) ;
adjustSize ( ) ;
setMinimumWidth ( minimumW ) ;
setMinimumWidth ( minimumW ) ;
@ -398,7 +396,7 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
void AddNewTorrentDialog : : saveSavePathHistory ( ) const
void AddNewTorrentDialog : : saveSavePathHistory ( ) const
{
{
QDir selectedSavePath ( ui - > savePath - > selectedPath ( ) ) ;
QDir selectedSavePath ( m_ ui- > savePath - > selectedPath ( ) ) ;
// Get current history
// Get current history
QStringList history = settings ( ) - > loadValue ( KEY_SAVEPATHHISTORY ) . toStringList ( ) ;
QStringList history = settings ( ) - > loadValue ( KEY_SAVEPATHHISTORY ) . toStringList ( ) ;
if ( history . size ( ) > savePathHistoryLength ( ) )
if ( history . size ( ) > savePathHistoryLength ( ) )
@ -417,12 +415,12 @@ void AddNewTorrentDialog::saveSavePathHistory() const
}
}
}
}
// save_p ath is a folder, not an absolute file path
// saveP ath is a folder, not an absolute file path
int AddNewTorrentDialog : : indexOfSavePath ( const QString & save_p ath )
int AddNewTorrentDialog : : indexOfSavePath ( const QString & saveP ath )
{
{
QDir saveDir ( save_p ath ) ;
QDir saveDir ( saveP ath ) ;
for ( int i = 0 ; i < ui - > savePath - > count ( ) ; + + i )
for ( int i = 0 ; i < m_ ui- > savePath - > count ( ) ; + + i )
if ( QDir ( ui - > savePath - > item ( i ) ) = = saveDir )
if ( QDir ( m_ ui- > savePath - > item ( i ) ) = = saveDir )
return i ;
return i ;
return - 1 ;
return - 1 ;
}
}
@ -430,7 +428,7 @@ int AddNewTorrentDialog::indexOfSavePath(const QString &save_path)
void AddNewTorrentDialog : : updateDiskSpaceLabel ( )
void AddNewTorrentDialog : : updateDiskSpaceLabel ( )
{
{
// Determine torrent size
// Determine torrent size
qulonglong torrent_s ize = 0 ;
qulonglong torrentS ize = 0 ;
if ( m_hasMetadata ) {
if ( m_hasMetadata ) {
if ( m_contentModel ) {
if ( m_contentModel ) {
@ -438,28 +436,28 @@ void AddNewTorrentDialog::updateDiskSpaceLabel()
Q_ASSERT ( priorities . size ( ) = = m_torrentInfo . filesCount ( ) ) ;
Q_ASSERT ( priorities . size ( ) = = m_torrentInfo . filesCount ( ) ) ;
for ( int i = 0 ; i < priorities . size ( ) ; + + i )
for ( int i = 0 ; i < priorities . size ( ) ; + + i )
if ( priorities [ i ] > 0 )
if ( priorities [ i ] > 0 )
torrent_s ize + = m_torrentInfo . fileSize ( i ) ;
torrentS ize + = m_torrentInfo . fileSize ( i ) ;
}
}
else {
else {
torrent_s ize = m_torrentInfo . totalSize ( ) ;
torrentS ize = m_torrentInfo . totalSize ( ) ;
}
}
}
}
QString size_string = torrent_s ize ? Utils : : Misc : : friendlyUnit ( torrent_s ize ) : QString ( tr ( " Not Available " , " This size is unavailable. " ) ) ;
QString sizeString = torrentS ize ? Utils : : Misc : : friendlyUnit ( torrentS ize ) : QString ( tr ( " Not Available " , " This size is unavailable. " ) ) ;
size_s tring + = " ( " ;
sizeS tring + = " ( " ;
size_s tring + = tr ( " Free space on disk: %1 " ) . arg ( Utils : : Misc : : friendlyUnit ( Utils : : Fs : : freeDiskSpaceOnPath (
sizeS tring + = tr ( " Free space on disk: %1 " ) . arg ( Utils : : Misc : : friendlyUnit ( Utils : : Fs : : freeDiskSpaceOnPath (
ui - > savePath - > selectedPath ( ) ) ) ) ;
m_ ui- > savePath - > selectedPath ( ) ) ) ) ;
size_s tring + = " ) " ;
sizeS tring + = " ) " ;
ui - > size_lbl - > setText ( size_s tring ) ;
m_ ui- > size_lbl - > setText ( sizeS tring ) ;
}
}
void AddNewTorrentDialog : : onSavePathChanged ( const QString & newPath )
void AddNewTorrentDialog : : onSavePathChanged ( const QString & newPath )
{
{
// Toggle default save path setting checkbox visibility
// Toggle default save path setting checkbox visibility
ui - > defaultSavePathCheckBox - > setChecked ( false ) ;
m_ ui- > defaultSavePathCheckBox - > setChecked ( false ) ;
ui - > defaultSavePathCheckBox - > setVisible ( QDir ( newPath ) ! = QDir ( BitTorrent : : Session : : instance ( ) - > defaultSavePath ( ) ) ) ;
m_ ui- > defaultSavePathCheckBox - > setVisible ( QDir ( newPath ) ! = QDir ( BitTorrent : : Session : : instance ( ) - > defaultSavePath ( ) ) ) ;
// Remember index
// Remember index
m_oldIndex = ui - > savePath - > currentIndex ( ) ;
m_oldIndex = m_ ui- > savePath - > currentIndex ( ) ;
updateDiskSpaceLabel ( ) ;
updateDiskSpaceLabel ( ) ;
}
}
@ -467,9 +465,9 @@ void AddNewTorrentDialog::categoryChanged(int index)
{
{
Q_UNUSED ( index ) ;
Q_UNUSED ( index ) ;
if ( ui - > comboTTM - > currentIndex ( ) = = 1 ) {
if ( m_ ui- > comboTTM - > currentIndex ( ) = = 1 ) {
QString savePath = BitTorrent : : Session : : instance ( ) - > categorySavePath ( ui - > categoryComboBox - > currentText ( ) ) ;
QString savePath = BitTorrent : : Session : : instance ( ) - > categorySavePath ( m_ ui- > categoryComboBox - > currentText ( ) ) ;
ui - > savePath - > setSelectedPath ( Utils : : Fs : : toNativePath ( savePath ) ) ;
m_ ui- > savePath - > setSelectedPath ( Utils : : Fs : : toNativePath ( savePath ) ) ;
}
}
}
}
@ -478,16 +476,16 @@ void AddNewTorrentDialog::setSavePath(const QString &newPath)
int existingIndex = indexOfSavePath ( newPath ) ;
int existingIndex = indexOfSavePath ( newPath ) ;
if ( existingIndex < 0 ) {
if ( existingIndex < 0 ) {
// New path, prepend to combo box
// New path, prepend to combo box
ui - > savePath - > insertItem ( 0 , newPath ) ;
m_ ui- > savePath - > insertItem ( 0 , newPath ) ;
existingIndex = 0 ;
existingIndex = 0 ;
}
}
ui - > savePath - > setCurrentIndex ( existingIndex ) ;
m_ ui- > savePath - > setCurrentIndex ( existingIndex ) ;
onSavePathChanged ( newPath ) ;
onSavePathChanged ( newPath ) ;
}
}
void AddNewTorrentDialog : : renameSelectedFile ( )
void AddNewTorrentDialog : : renameSelectedFile ( )
{
{
const QModelIndexList selectedIndexes = ui - > contentTreeView - > selectionModel ( ) - > selectedRows ( 0 ) ;
const QModelIndexList selectedIndexes = m_ ui- > contentTreeView - > selectionModel ( ) - > selectedRows ( 0 ) ;
if ( selectedIndexes . size ( ) ! = 1 ) return ;
if ( selectedIndexes . size ( ) ! = 1 ) return ;
const QModelIndex modelIndex = selectedIndexes . first ( ) ;
const QModelIndex modelIndex = selectedIndexes . first ( ) ;
@ -590,13 +588,13 @@ void AddNewTorrentDialog::populateSavePathComboBox()
{
{
QString defSavePath = BitTorrent : : Session : : instance ( ) - > defaultSavePath ( ) ;
QString defSavePath = BitTorrent : : Session : : instance ( ) - > defaultSavePath ( ) ;
ui - > savePath - > clear ( ) ;
m_ ui- > savePath - > clear ( ) ;
ui - > savePath - > addItem ( defSavePath ) ;
m_ ui- > savePath - > addItem ( defSavePath ) ;
QDir defaultSaveDir ( defSavePath ) ;
QDir defaultSaveDir ( defSavePath ) ;
// Load save path history
// Load save path history
foreach ( const QString & savePath , settings ( ) - > loadValue ( KEY_SAVEPATHHISTORY ) . toStringList ( ) )
foreach ( const QString & savePath , settings ( ) - > loadValue ( KEY_SAVEPATHHISTORY ) . toStringList ( ) )
if ( QDir ( savePath ) ! = defaultSaveDir )
if ( QDir ( savePath ) ! = defaultSaveDir )
ui - > savePath - > addItem ( savePath ) ;
m_ ui- > savePath - > addItem ( savePath ) ;
if ( ! m_torrentParams . savePath . isEmpty ( ) )
if ( ! m_torrentParams . savePath . isEmpty ( ) )
setSavePath ( m_torrentParams . savePath ) ;
setSavePath ( m_torrentParams . savePath ) ;
@ -605,7 +603,7 @@ void AddNewTorrentDialog::populateSavePathComboBox()
void AddNewTorrentDialog : : displayContentTreeMenu ( const QPoint & )
void AddNewTorrentDialog : : displayContentTreeMenu ( const QPoint & )
{
{
QMenu myFilesLlistMenu ;
QMenu myFilesLlistMenu ;
const QModelIndexList selectedRows = ui - > contentTreeView - > selectionModel ( ) - > selectedRows ( 0 ) ;
const QModelIndexList selectedRows = m_ ui- > contentTreeView - > selectionModel ( ) - > selectedRows ( 0 ) ;
QAction * actRename = nullptr ;
QAction * actRename = nullptr ;
if ( selectedRows . size ( ) = = 1 ) {
if ( selectedRows . size ( ) = = 1 ) {
actRename = myFilesLlistMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename... " ) ) ;
actRename = myFilesLlistMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename... " ) ) ;
@ -613,10 +611,10 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
}
}
QMenu subMenu ;
QMenu subMenu ;
subMenu . setTitle ( tr ( " Priority " ) ) ;
subMenu . setTitle ( tr ( " Priority " ) ) ;
subMenu . addAction ( ui - > actionNot_downloaded ) ;
subMenu . addAction ( m_ ui- > actionNot_downloaded ) ;
subMenu . addAction ( ui - > actionNormal ) ;
subMenu . addAction ( m_ ui- > actionNormal ) ;
subMenu . addAction ( ui - > actionHigh ) ;
subMenu . addAction ( m_ ui- > actionHigh ) ;
subMenu . addAction ( ui - > actionMaximum ) ;
subMenu . addAction ( m_ ui- > actionMaximum ) ;
myFilesLlistMenu . addMenu ( & subMenu ) ;
myFilesLlistMenu . addMenu ( & subMenu ) ;
// Call menu
// Call menu
QAction * act = myFilesLlistMenu . exec ( QCursor : : pos ( ) ) ;
QAction * act = myFilesLlistMenu . exec ( QCursor : : pos ( ) ) ;
@ -626,11 +624,11 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
}
}
else {
else {
int prio = prio : : NORMAL ;
int prio = prio : : NORMAL ;
if ( act = = ui - > actionHigh )
if ( act = = m_ ui- > actionHigh )
prio = prio : : HIGH ;
prio = prio : : HIGH ;
else if ( act = = ui - > actionMaximum )
else if ( act = = m_ ui- > actionMaximum )
prio = prio : : MAXIMUM ;
prio = prio : : MAXIMUM ;
else if ( act = = ui - > actionNot_downloaded )
else if ( act = = m_ ui- > actionNot_downloaded )
prio = prio : : IGNORED ;
prio = prio : : IGNORED ;
qDebug ( " Setting files priority " ) ;
qDebug ( " Setting files priority " ) ;
@ -648,34 +646,34 @@ void AddNewTorrentDialog::accept()
disconnect ( this , SLOT ( updateMetadata ( const BitTorrent : : TorrentInfo & ) ) ) ;
disconnect ( this , SLOT ( updateMetadata ( const BitTorrent : : TorrentInfo & ) ) ) ;
// TODO: Check if destination actually exists
// TODO: Check if destination actually exists
m_torrentParams . skipChecking = ui - > skipCheckingCheckBox - > isChecked ( ) ;
m_torrentParams . skipChecking = m_ ui- > skipCheckingCheckBox - > isChecked ( ) ;
// Category
// Category
m_torrentParams . category = ui - > categoryComboBox - > currentText ( ) ;
m_torrentParams . category = m_ ui- > categoryComboBox - > currentText ( ) ;
if ( ui - > defaultCategoryCheckbox - > isChecked ( ) )
if ( m_ ui- > defaultCategoryCheckbox - > isChecked ( ) )
settings ( ) - > storeValue ( KEY_DEFAULTCATEGORY , m_torrentParams . category ) ;
settings ( ) - > storeValue ( KEY_DEFAULTCATEGORY , m_torrentParams . category ) ;
// Save file priorities
// Save file priorities
if ( m_contentModel )
if ( m_contentModel )
m_torrentParams . filePriorities = m_contentModel - > model ( ) - > getFilePriorities ( ) ;
m_torrentParams . filePriorities = m_contentModel - > model ( ) - > getFilePriorities ( ) ;
m_torrentParams . addPaused = TriStateBool ( ! ui - > startTorrentCheckBox - > isChecked ( ) ) ;
m_torrentParams . addPaused = TriStateBool ( ! m_ ui- > startTorrentCheckBox - > isChecked ( ) ) ;
m_torrentParams . createSubfolder = TriStateBool ( ui - > createSubfolderCheckBox - > isChecked ( ) ) ;
m_torrentParams . createSubfolder = TriStateBool ( m_ ui- > createSubfolderCheckBox - > isChecked ( ) ) ;
QString savePath = ui - > savePath - > selectedPath ( ) ;
QString savePath = m_ ui- > savePath - > selectedPath ( ) ;
if ( ui - > comboTTM - > currentIndex ( ) ! = 1 ) { // 0 is Manual mode and 1 is Automatic mode. Handle all non 1 values as manual mode.
if ( m_ ui- > comboTTM - > currentIndex ( ) ! = 1 ) { // 0 is Manual mode and 1 is Automatic mode. Handle all non 1 values as manual mode.
m_torrentParams . useAutoTMM = TriStateBool : : False ;
m_torrentParams . useAutoTMM = TriStateBool : : False ;
m_torrentParams . savePath = savePath ;
m_torrentParams . savePath = savePath ;
saveSavePathHistory ( ) ;
saveSavePathHistory ( ) ;
if ( ui - > defaultSavePathCheckBox - > isChecked ( ) )
if ( m_ ui- > defaultSavePathCheckBox - > isChecked ( ) )
BitTorrent : : Session : : instance ( ) - > setDefaultSavePath ( savePath ) ;
BitTorrent : : Session : : instance ( ) - > setDefaultSavePath ( savePath ) ;
}
}
else {
else {
m_torrentParams . useAutoTMM = TriStateBool : : True ;
m_torrentParams . useAutoTMM = TriStateBool : : True ;
}
}
setEnabled ( ! ui - > never_show_cb - > isChecked ( ) ) ;
setEnabled ( ! m_ ui- > never_show_cb - > isChecked ( ) ) ;
// Add torrent
// Add torrent
if ( ! m_hasMetadata )
if ( ! m_hasMetadata )
@ -722,16 +720,16 @@ void AddNewTorrentDialog::updateMetadata(const BitTorrent::TorrentInfo &info)
void AddNewTorrentDialog : : setMetadataProgressIndicator ( bool visibleIndicator , const QString & labelText )
void AddNewTorrentDialog : : setMetadataProgressIndicator ( bool visibleIndicator , const QString & labelText )
{
{
// Always show info label when waiting for metadata
// Always show info label when waiting for metadata
ui - > lblMetaLoading - > setVisible ( true ) ;
m_ ui- > lblMetaLoading - > setVisible ( true ) ;
ui - > lblMetaLoading - > setText ( labelText ) ;
m_ ui- > lblMetaLoading - > setText ( labelText ) ;
ui - > progMetaLoading - > setVisible ( visibleIndicator ) ;
m_ ui- > progMetaLoading - > setVisible ( visibleIndicator ) ;
}
}
void AddNewTorrentDialog : : setupTreeview ( )
void AddNewTorrentDialog : : setupTreeview ( )
{
{
if ( ! m_hasMetadata ) {
if ( ! m_hasMetadata ) {
setCommentText ( tr ( " Not Available " , " This comment is unavailable " ) ) ;
setCommentText ( tr ( " Not Available " , " This comment is unavailable " ) ) ;
ui - > date_lbl - > setText ( tr ( " Not Available " , " This date is unavailable " ) ) ;
m_ ui- > date_lbl - > setText ( tr ( " Not Available " , " This date is unavailable " ) ) ;
}
}
else {
else {
// Set dialog title
// Set dialog title
@ -739,30 +737,30 @@ void AddNewTorrentDialog::setupTreeview()
// Set torrent information
// Set torrent information
setCommentText ( Utils : : Misc : : parseHtmlLinks ( m_torrentInfo . comment ( ) ) ) ;
setCommentText ( Utils : : Misc : : parseHtmlLinks ( m_torrentInfo . comment ( ) ) ) ;
ui - > date_lbl - > setText ( ! m_torrentInfo . creationDate ( ) . isNull ( ) ? m_torrentInfo . creationDate ( ) . toString ( Qt : : DefaultLocaleShortDate ) : tr ( " Not available " ) ) ;
m_ ui- > date_lbl - > setText ( ! m_torrentInfo . creationDate ( ) . isNull ( ) ? m_torrentInfo . creationDate ( ) . toString ( Qt : : DefaultLocaleShortDate ) : tr ( " Not available " ) ) ;
// Prepare content tree
// Prepare content tree
m_contentModel = new TorrentContentFilterModel ( this ) ;
m_contentModel = new TorrentContentFilterModel ( this ) ;
connect ( m_contentModel - > model ( ) , & TorrentContentModel : : filteredFilesChanged , this , & AddNewTorrentDialog : : updateDiskSpaceLabel ) ;
connect ( m_contentModel - > model ( ) , & TorrentContentModel : : filteredFilesChanged , this , & AddNewTorrentDialog : : updateDiskSpaceLabel ) ;
ui - > contentTreeView - > setModel ( m_contentModel ) ;
m_ ui- > contentTreeView - > setModel ( m_contentModel ) ;
m_contentDelegate = new PropListDelegate ( nullptr ) ;
m_contentDelegate = new PropListDelegate ( nullptr ) ;
ui - > contentTreeView - > setItemDelegate ( m_contentDelegate ) ;
m_ ui- > contentTreeView - > setItemDelegate ( m_contentDelegate ) ;
connect ( ui - > contentTreeView , & QAbstractItemView : : clicked , ui - > contentTreeView
connect ( m_ ui- > contentTreeView , & QAbstractItemView : : clicked , m_ ui- > contentTreeView
, static_cast < void ( QAbstractItemView : : * ) ( const QModelIndex & ) > ( & QAbstractItemView : : edit ) ) ;
, static_cast < void ( QAbstractItemView : : * ) ( const QModelIndex & ) > ( & QAbstractItemView : : edit ) ) ;
connect ( ui - > contentTreeView , & QWidget : : customContextMenuRequested , this , & AddNewTorrentDialog : : displayContentTreeMenu ) ;
connect ( m_ ui- > contentTreeView , & QWidget : : customContextMenuRequested , this , & AddNewTorrentDialog : : displayContentTreeMenu ) ;
// List files in torrent
// List files in torrent
m_contentModel - > model ( ) - > setupModelData ( m_torrentInfo ) ;
m_contentModel - > model ( ) - > setupModelData ( m_torrentInfo ) ;
if ( ! m_headerState . isEmpty ( ) )
if ( ! m_headerState . isEmpty ( ) )
ui - > contentTreeView - > header ( ) - > restoreState ( m_headerState ) ;
m_ ui- > contentTreeView - > header ( ) - > restoreState ( m_headerState ) ;
// Hide useless columns after loading the header state
// Hide useless columns after loading the header state
ui - > contentTreeView - > hideColumn ( PROGRESS ) ;
m_ ui- > contentTreeView - > hideColumn ( PROGRESS ) ;
ui - > contentTreeView - > hideColumn ( REMAINING ) ;
m_ ui- > contentTreeView - > hideColumn ( REMAINING ) ;
ui - > contentTreeView - > hideColumn ( AVAILABILITY ) ;
m_ ui- > contentTreeView - > hideColumn ( AVAILABILITY ) ;
// Expand root folder
// Expand root folder
ui - > contentTreeView - > setExpanded ( m_contentModel - > index ( 0 , 0 ) , true ) ;
m_ ui- > contentTreeView - > setExpanded ( m_contentModel - > index ( 0 , 0 ) , true ) ;
}
}
updateDiskSpaceLabel ( ) ;
updateDiskSpaceLabel ( ) ;
@ -798,33 +796,33 @@ void AddNewTorrentDialog::TMMChanged(int index)
{
{
if ( index ! = 1 ) { // 0 is Manual mode and 1 is Automatic mode. Handle all non 1 values as manual mode.
if ( index ! = 1 ) { // 0 is Manual mode and 1 is Automatic mode. Handle all non 1 values as manual mode.
populateSavePathComboBox ( ) ;
populateSavePathComboBox ( ) ;
ui - > groupBoxSavePath - > setEnabled ( true ) ;
m_ ui- > groupBoxSavePath - > setEnabled ( true ) ;
ui - > savePath - > blockSignals ( false ) ;
m_ ui- > savePath - > blockSignals ( false ) ;
ui - > savePath - > setCurrentIndex ( m_oldIndex < ui - > savePath - > count ( ) ? m_oldIndex : ui - > savePath - > count ( ) - 1 ) ;
m_ ui- > savePath - > setCurrentIndex ( m_oldIndex < m_ ui- > savePath - > count ( ) ? m_oldIndex : m_ ui- > savePath - > count ( ) - 1 ) ;
ui - > adv_button - > setEnabled ( true ) ;
m_ ui- > adv_button - > setEnabled ( true ) ;
}
}
else {
else {
ui - > groupBoxSavePath - > setEnabled ( false ) ;
m_ ui- > groupBoxSavePath - > setEnabled ( false ) ;
ui - > savePath - > blockSignals ( true ) ;
m_ ui- > savePath - > blockSignals ( true ) ;
ui - > savePath - > clear ( ) ;
m_ ui- > savePath - > clear ( ) ;
QString savePath = BitTorrent : : Session : : instance ( ) - > categorySavePath ( ui - > categoryComboBox - > currentText ( ) ) ;
QString savePath = BitTorrent : : Session : : instance ( ) - > categorySavePath ( m_ ui- > categoryComboBox - > currentText ( ) ) ;
ui - > savePath - > addItem ( savePath ) ;
m_ ui- > savePath - > addItem ( savePath ) ;
ui - > defaultSavePathCheckBox - > setVisible ( false ) ;
m_ ui- > defaultSavePathCheckBox - > setVisible ( false ) ;
ui - > adv_button - > setChecked ( true ) ;
m_ ui- > adv_button - > setChecked ( true ) ;
ui - > adv_button - > setEnabled ( false ) ;
m_ ui- > adv_button - > setEnabled ( false ) ;
showAdvancedSettings ( true ) ;
showAdvancedSettings ( true ) ;
}
}
}
}
void AddNewTorrentDialog : : setCommentText ( const QString & str ) const
void AddNewTorrentDialog : : setCommentText ( const QString & str ) const
{
{
ui - > commentLabel - > setText ( str ) ;
m_ ui- > commentLabel - > setText ( str ) ;
// workaround for the additional space introduced by QScrollArea
// workaround for the additional space introduced by QScrollArea
int lineHeight = ui - > commentLabel - > fontMetrics ( ) . lineSpacing ( ) ;
int lineHeight = m_ ui- > commentLabel - > fontMetrics ( ) . lineSpacing ( ) ;
int lines = 1 + str . count ( " \n " ) ;
int lines = 1 + str . count ( " \n " ) ;
int height = lineHeight * lines ;
int height = lineHeight * lines ;
ui - > scrollArea - > setMaximumHeight ( height ) ;
m_ ui- > scrollArea - > setMaximumHeight ( height ) ;
}
}
void AddNewTorrentDialog : : doNotDeleteTorrentClicked ( bool checked )
void AddNewTorrentDialog : : doNotDeleteTorrentClicked ( bool checked )