2012-05-15 20:57:31 +04:00
/*
2015-04-19 18:17:47 +03:00
* Bittorrent Client using Qt and libtorrent .
2012-05-15 20:57:31 +04:00
* Copyright ( C ) 2012 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
*/
2015-06-02 12:09:15 +03:00
# include <QDebug>
# include <QString>
# include <QFile>
# include <QUrl>
# include <QMenu>
# include <QFileDialog>
2016-04-23 02:55:59 +03:00
# include <QPushButton>
2015-06-02 12:09:15 +03:00
2015-11-07 21:44:53 +03:00
# include "base/preferences.h"
2016-02-09 11:56:48 +03:00
# include "base/settingsstorage.h"
2015-09-25 11:10:05 +03:00
# include "base/net/downloadmanager.h"
# include "base/net/downloadhandler.h"
# include "base/bittorrent/session.h"
# include "base/bittorrent/magneturi.h"
# include "base/bittorrent/torrentinfo.h"
# include "base/bittorrent/torrenthandle.h"
# include "base/utils/fs.h"
# include "base/utils/misc.h"
2016-02-09 11:56:48 +03:00
# include "base/utils/string.h"
2016-04-07 17:58:30 +03:00
# include "base/torrentfileguard.h"
2015-09-25 11:10:05 +03:00
# include "base/unicodestrings.h"
2015-06-02 12:09:15 +03:00
# include "guiiconprovider.h"
2013-07-22 15:46:10 +04:00
# include "autoexpandabledialog.h"
2014-02-01 16:02:37 +04:00
# include "messageboxraised.h"
2015-06-02 12:09:15 +03:00
# include "proplistdelegate.h"
# include "torrentcontentmodel.h"
# include "torrentcontentfiltermodel.h"
2016-02-09 11:56:48 +03:00
# include "ui_addnewtorrentdialog.h"
2015-06-02 12:09:15 +03:00
# include "addnewtorrentdialog.h"
2012-05-15 20:57:31 +04:00
2016-02-09 11:56:48 +03:00
# define SETTINGS_KEY(name) "AddNewTorrentDialog / " name
const QString KEY_ENABLED = SETTINGS_KEY ( " Enabled " ) ;
const QString KEY_DEFAULTCATEGORY = SETTINGS_KEY ( " DefaultCategory " ) ;
const QString KEY_TREEHEADERSTATE = SETTINGS_KEY ( " TreeHeaderState " ) ;
const QString KEY_WIDTH = SETTINGS_KEY ( " Width " ) ;
const QString KEY_EXPANDED = SETTINGS_KEY ( " Expanded " ) ;
const QString KEY_TOPLEVEL = SETTINGS_KEY ( " TopLevel " ) ;
const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY ( " SavePathHistory " ) ;
namespace
{
2017-04-05 10:21:12 +03:00
// just a shortcut
inline SettingsStorage * settings ( )
{
return SettingsStorage : : instance ( ) ;
}
2016-02-09 11:56:48 +03:00
}
2016-07-15 05:15:10 +03:00
AddNewTorrentDialog : : AddNewTorrentDialog ( const BitTorrent : : AddTorrentParams & inParams , QWidget * parent )
2015-02-01 02:27:51 +03:00
: QDialog ( parent )
, ui ( new Ui : : AddNewTorrentDialog )
2017-05-09 08:15:01 +03:00
, m_contentModel ( nullptr )
, m_contentDelegate ( nullptr )
2015-02-01 02:27:51 +03:00
, m_hasMetadata ( false )
, m_oldIndex ( 0 )
2016-07-15 05:15:10 +03:00
, m_torrentParams ( inParams )
2012-05-15 20:57:31 +04:00
{
2015-10-26 10:45:14 +03:00
// TODO: set dialog file properties using m_torrentParams.filePriorities
2015-02-01 02:27:51 +03:00
ui - > setupUi ( this ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
ui - > lblMetaLoading - > setVisible ( false ) ;
ui - > progMetaLoading - > setVisible ( false ) ;
2016-04-23 02:55:59 +03:00
ui - > savePath - > setMode ( FileSystemPathEdit : : Mode : : DirectorySave ) ;
ui - > savePath - > setDialogCaption ( tr ( " Choose save path " ) ) ;
2016-02-09 11:56:48 +03:00
auto session = BitTorrent : : Session : : instance ( ) ;
2016-07-15 05:15:10 +03:00
if ( m_torrentParams . addPaused = = TriStateBool : : True )
ui - > startTorrentCheckBox - > setChecked ( false ) ;
else if ( m_torrentParams . addPaused = = TriStateBool : : False )
ui - > startTorrentCheckBox - > setChecked ( true ) ;
else
ui - > startTorrentCheckBox - > setChecked ( ! session - > isAddTorrentPaused ( ) ) ;
2015-10-26 10:45:14 +03:00
2017-04-05 10:21:12 +03:00
ui - > comboTTM - > blockSignals ( true ) ; // the TreeView size isn't correct if the slot does it job at this point
2016-05-08 22:47:50 +03:00
ui - > comboTTM - > setCurrentIndex ( ! session - > isAutoTMMDisabledByDefault ( ) ) ;
ui - > comboTTM - > blockSignals ( false ) ;
2016-02-09 11:56:48 +03:00
populateSavePathComboBox ( ) ;
2016-04-23 02:55:59 +03:00
connect ( ui - > savePath , & FileSystemPathEdit : : selectedPathChanged , this , & AddNewTorrentDialog : : onSavePathChanged ) ;
2016-02-09 11:56:48 +03:00
ui - > defaultSavePathCheckBox - > setVisible ( false ) ; // Default path is selected by default
2015-02-01 02:27:51 +03:00
2016-07-15 05:15:10 +03:00
if ( m_torrentParams . createSubfolder = = TriStateBool : : True )
ui - > createSubfolderCheckBox - > setChecked ( true ) ;
else if ( m_torrentParams . createSubfolder = = TriStateBool : : False )
ui - > createSubfolderCheckBox - > setChecked ( false ) ;
else
ui - > createSubfolderCheckBox - > setChecked ( session - > isCreateTorrentSubfolder ( ) ) ;
2015-10-26 10:45:14 +03:00
2016-07-15 05:15:10 +03:00
ui - > skipCheckingCheckBox - > setChecked ( m_torrentParams . skipChecking ) ;
2016-04-07 17:58:30 +03:00
ui - > doNotDeleteTorrentCheckBox - > setVisible ( TorrentFileGuard : : autoDeleteMode ( ) ! = TorrentFileGuard : : Never ) ;
2016-02-09 11:56:48 +03:00
// Load categories
QStringList categories = session - > categories ( ) ;
2016-05-04 12:15:58 +03:00
std : : sort ( categories . begin ( ) , categories . end ( ) , Utils : : String : : naturalCompareCaseInsensitive ) ;
2016-02-09 11:56:48 +03:00
QString defaultCategory = settings ( ) - > loadValue ( KEY_DEFAULTCATEGORY ) . toString ( ) ;
2015-11-03 18:05:15 +03:00
2016-07-15 05:15:10 +03:00
if ( ! m_torrentParams . category . isEmpty ( ) )
ui - > categoryComboBox - > addItem ( m_torrentParams . category ) ;
2016-02-09 11:56:48 +03:00
if ( ! defaultCategory . isEmpty ( ) )
ui - > categoryComboBox - > addItem ( defaultCategory ) ;
ui - > categoryComboBox - > addItem ( " " ) ;
2015-11-03 18:05:15 +03:00
2016-02-09 11:56:48 +03:00
foreach ( const QString & category , categories )
2016-07-15 05:15:10 +03:00
if ( category ! = defaultCategory & & category ! = m_torrentParams . category )
2016-02-09 11:56:48 +03:00
ui - > categoryComboBox - > addItem ( category ) ;
2015-11-03 18:05:15 +03:00
2016-02-09 11:56:48 +03:00
ui - > contentTreeView - > header ( ) - > setSortIndicator ( 0 , Qt : : AscendingOrder ) ;
2015-02-01 02:27:51 +03:00
loadState ( ) ;
// Signal / slots
connect ( ui - > adv_button , SIGNAL ( clicked ( bool ) ) , SLOT ( showAdvancedSettings ( bool ) ) ) ;
2016-04-07 17:58:30 +03:00
connect ( ui - > doNotDeleteTorrentCheckBox , SIGNAL ( clicked ( bool ) ) , SLOT ( doNotDeleteTorrentClicked ( bool ) ) ) ;
2017-05-09 08:01:28 +03:00
QShortcut * editHotkey = new QShortcut ( Qt : : Key_F2 , ui - > contentTreeView , 0 , 0 , Qt : : WidgetShortcut ) ;
2015-02-01 02:27:51 +03:00
connect ( editHotkey , SIGNAL ( activated ( ) ) , SLOT ( renameSelectedFile ( ) ) ) ;
2016-02-09 11:56:48 +03:00
connect ( ui - > contentTreeView , SIGNAL ( doubleClicked ( QModelIndex ) ) , SLOT ( renameSelectedFile ( ) ) ) ;
2015-05-24 10:12:07 +03:00
ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setFocus ( ) ;
2012-05-15 20:57:31 +04:00
}
AddNewTorrentDialog : : ~ AddNewTorrentDialog ( )
{
2015-02-01 02:27:51 +03:00
saveState ( ) ;
2017-05-09 08:15:01 +03:00
delete m_contentDelegate ;
2015-02-01 02:27:51 +03:00
delete ui ;
2012-05-15 20:57:31 +04:00
}
2016-02-09 11:56:48 +03:00
bool AddNewTorrentDialog : : isEnabled ( )
{
return SettingsStorage : : instance ( ) - > loadValue ( KEY_ENABLED , true ) . toBool ( ) ;
}
void AddNewTorrentDialog : : setEnabled ( bool value )
{
SettingsStorage : : instance ( ) - > storeValue ( KEY_ENABLED , value ) ;
}
bool AddNewTorrentDialog : : isTopLevel ( )
{
return SettingsStorage : : instance ( ) - > loadValue ( KEY_TOPLEVEL , true ) . toBool ( ) ;
}
void AddNewTorrentDialog : : setTopLevel ( bool value )
{
SettingsStorage : : instance ( ) - > storeValue ( KEY_TOPLEVEL , value ) ;
}
2012-07-03 19:37:24 +04:00
void AddNewTorrentDialog : : loadState ( )
{
2016-02-09 11:56:48 +03:00
m_headerState = settings ( ) - > loadValue ( KEY_TREEHEADERSTATE ) . toByteArray ( ) ;
int width = settings ( ) - > loadValue ( KEY_WIDTH , - 1 ) . toInt ( ) ;
2015-10-26 10:45:14 +03:00
QSize geo = size ( ) ;
geo . setWidth ( width ) ;
resize ( geo ) ;
2016-02-09 11:56:48 +03:00
ui - > adv_button - > setChecked ( settings ( ) - > loadValue ( KEY_EXPANDED ) . toBool ( ) ) ;
2012-07-03 19:37:24 +04:00
}
void AddNewTorrentDialog : : saveState ( )
{
2015-02-01 02:27:51 +03:00
if ( m_contentModel )
2016-02-09 11:56:48 +03:00
settings ( ) - > storeValue ( KEY_TREEHEADERSTATE , ui - > contentTreeView - > header ( ) - > saveState ( ) ) ;
settings ( ) - > storeValue ( KEY_WIDTH , width ( ) ) ;
settings ( ) - > storeValue ( KEY_EXPANDED , ui - > adv_button - > isChecked ( ) ) ;
2012-07-03 19:37:24 +04:00
}
2016-07-15 05:15:10 +03:00
void AddNewTorrentDialog : : show ( QString source , const BitTorrent : : AddTorrentParams & inParams , QWidget * parent )
2012-05-15 20:57:31 +04:00
{
2016-07-15 05:15:10 +03:00
AddNewTorrentDialog * dlg = new AddNewTorrentDialog ( inParams , parent ) ;
2013-09-17 16:18:01 +04:00
2015-05-06 14:53:27 +03:00
if ( Utils : : Misc : : isUrl ( source ) ) {
2015-04-19 18:17:47 +03:00
// Launch downloader
2015-06-03 11:49:39 +03:00
Net : : DownloadHandler * handler = Net : : DownloadManager : : instance ( ) - > downloadUrl ( source , true , 10485760 /* 10MB */ , true ) ;
2017-04-05 10:21:12 +03:00
connect ( handler , SIGNAL ( downloadFinished ( QString , QString ) ) , dlg , SLOT ( handleDownloadFinished ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( downloadFailed ( QString , QString ) ) , dlg , SLOT ( handleDownloadFailed ( QString , QString ) ) ) ;
connect ( handler , SIGNAL ( redirectedToMagnet ( QString , QString ) ) , dlg , SLOT ( handleRedirectedToMagnet ( QString , QString ) ) ) ;
2015-02-01 02:27:51 +03:00
}
else {
2015-04-19 18:17:47 +03:00
bool ok = false ;
2016-01-07 14:22:35 +03:00
BitTorrent : : MagnetUri magnetUri ( source ) ;
if ( magnetUri . isValid ( ) )
ok = dlg - > loadMagnet ( magnetUri ) ;
2015-04-19 18:17:47 +03:00
else
ok = dlg - > loadTorrent ( source ) ;
if ( ok )
dlg - > open ( ) ;
else
delete dlg ;
2012-05-15 20:57:31 +04:00
}
}
2016-07-15 05:15:10 +03:00
void AddNewTorrentDialog : : show ( QString source , QWidget * parent )
{
show ( source , BitTorrent : : AddTorrentParams ( ) , parent ) ;
}
2016-01-07 14:22:35 +03:00
bool AddNewTorrentDialog : : loadTorrent ( const QString & torrentPath )
2012-05-15 20:57:31 +04:00
{
2016-01-07 14:22:35 +03:00
if ( torrentPath . startsWith ( " file:// " , Qt : : CaseInsensitive ) )
m_filePath = QUrl : : fromEncoded ( torrentPath . toLocal8Bit ( ) ) . toLocalFile ( ) ;
2015-02-01 02:27:51 +03:00
else
2016-01-07 14:22:35 +03:00
m_filePath = torrentPath ;
2015-02-01 02:27:51 +03:00
if ( ! QFile : : exists ( m_filePath ) ) {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " I/O Error " ) , tr ( " The torrent file '%1' does not exist. " ) . arg ( Utils : : Fs : : toNativePath ( m_filePath ) ) ) ;
2015-02-01 02:27:51 +03:00
return false ;
}
2015-03-02 22:22:45 +03:00
QFileInfo fileinfo ( m_filePath ) ;
if ( ! fileinfo . isReadable ( ) ) {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " I/O Error " ) , tr ( " The torrent file '%1' cannot be read from the disk. Probably you don't have enough permissions. " ) . arg ( Utils : : Fs : : toNativePath ( m_filePath ) ) ) ;
2015-03-02 22:22:45 +03:00
return false ;
}
2015-02-01 02:27:51 +03:00
m_hasMetadata = true ;
2015-04-19 18:17:47 +03:00
QString error ;
m_torrentInfo = BitTorrent : : TorrentInfo : : loadFromFile ( m_filePath , error ) ;
if ( ! m_torrentInfo . isValid ( ) ) {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " Invalid torrent " ) , tr ( " Failed to load the torrent: %1. \n Error: %2 " , " Don't remove the ' \n ' characters. They insert a newline. " ) . arg ( Utils : : Fs : : toNativePath ( m_filePath ) ) . arg ( error ) ) ;
2015-02-01 02:27:51 +03:00
return false ;
}
2016-04-07 17:58:30 +03:00
m_torrentGuard . reset ( new TorrentFileGuard ( m_filePath ) ) ;
2015-04-19 18:17:47 +03:00
m_hash = m_torrentInfo . hash ( ) ;
2015-02-01 02:27:51 +03:00
// Prevent showing the dialog if download is already present
2015-04-19 18:17:47 +03:00
if ( BitTorrent : : Session : : instance ( ) - > isKnownTorrent ( m_hash ) ) {
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( m_hash ) ;
if ( torrent ) {
2016-02-15 04:24:22 +03:00
if ( torrent - > isPrivate ( ) | | m_torrentInfo . isPrivate ( ) ) {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " Already in download list " ) , tr ( " Torrent is already in download list. Trackers weren't merged because it is a private torrent. " ) , QMessageBox : : Ok ) ;
2016-02-15 04:24:22 +03:00
}
else {
torrent - > addTrackers ( m_torrentInfo . trackers ( ) ) ;
torrent - > addUrlSeeds ( m_torrentInfo . urlSeeds ( ) ) ;
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : information ( this , tr ( " Already in download list " ) , tr ( " Torrent is already in download list. Trackers were merged. " ) , QMessageBox : : Ok ) ;
2016-02-15 04:24:22 +03:00
}
2015-04-19 18:17:47 +03:00
}
else {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " Cannot add torrent " ) , tr ( " Cannot add this torrent. Perhaps it is already in adding state. " ) , QMessageBox : : Ok ) ;
2015-04-19 18:17:47 +03:00
}
2015-02-01 02:27:51 +03:00
return false ;
}
2015-02-01 19:11:43 +03:00
ui - > lblhash - > setText ( m_hash ) ;
2015-02-01 02:27:51 +03:00
setupTreeview ( ) ;
2016-05-08 22:47:50 +03:00
TMMChanged ( ui - > comboTTM - > currentIndex ( ) ) ;
2015-02-01 02:27:51 +03:00
return true ;
2012-05-15 20:57:31 +04:00
}
2016-01-07 14:22:35 +03:00
bool AddNewTorrentDialog : : loadMagnet ( const BitTorrent : : MagnetUri & magnetUri )
2012-05-15 20:57:31 +04:00
{
2016-01-07 14:22:35 +03:00
if ( ! magnetUri . isValid ( ) ) {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " Invalid magnet link " ) , tr ( " This magnet link was not recognized " ) ) ;
2015-02-01 02:27:51 +03:00
return false ;
}
2013-07-27 23:05:19 +04:00
2016-05-13 21:35:02 +03:00
m_torrentGuard . reset ( new TorrentFileGuard ( QString ( ) ) ) ;
2016-01-07 14:22:35 +03:00
m_hash = magnetUri . hash ( ) ;
2015-02-01 02:27:51 +03:00
// Prevent showing the dialog if download is already present
2015-04-19 18:17:47 +03:00
if ( BitTorrent : : Session : : instance ( ) - > isKnownTorrent ( m_hash ) ) {
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( m_hash ) ;
if ( torrent ) {
2016-02-15 04:24:22 +03:00
if ( torrent - > isPrivate ( ) ) {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " Already in download list " ) , tr ( " Torrent is already in download list. Trackers weren't merged because it is a private torrent. " ) , QMessageBox : : Ok ) ;
2016-02-15 04:24:22 +03:00
}
else {
torrent - > addTrackers ( magnetUri . trackers ( ) ) ;
torrent - > addUrlSeeds ( magnetUri . urlSeeds ( ) ) ;
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : information ( this , tr ( " Already in download list " ) , tr ( " Magnet link is already in download list. Trackers were merged. " ) , QMessageBox : : Ok ) ;
2016-02-15 04:24:22 +03:00
}
2015-04-19 18:17:47 +03:00
}
else {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " Cannot add torrent " ) , tr ( " Cannot add this torrent. Perhaps it is already in adding. " ) , QMessageBox : : Ok ) ;
2015-04-19 18:17:47 +03:00
}
2015-02-01 02:27:51 +03:00
return false ;
}
2015-04-19 18:17:47 +03:00
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( metadataLoaded ( BitTorrent : : TorrentInfo ) ) , SLOT ( updateMetadata ( BitTorrent : : TorrentInfo ) ) ) ;
2015-02-01 02:27:51 +03:00
// Set dialog title
2016-01-07 14:22:35 +03:00
QString torrent_name = magnetUri . name ( ) ;
2015-02-01 02:27:51 +03:00
setWindowTitle ( torrent_name . isEmpty ( ) ? tr ( " Magnet link " ) : torrent_name ) ;
2012-05-15 20:57:31 +04:00
2015-02-01 02:27:51 +03:00
setupTreeview ( ) ;
2016-05-08 22:47:50 +03:00
TMMChanged ( ui - > comboTTM - > currentIndex ( ) ) ;
2012-05-20 19:14:02 +04:00
2016-01-07 14:22:35 +03:00
BitTorrent : : Session : : instance ( ) - > loadMetadata ( magnetUri ) ;
2015-02-01 02:27:51 +03:00
setMetadataProgressIndicator ( true , tr ( " Retrieving metadata... " ) ) ;
2015-02-01 19:11:43 +03:00
ui - > lblhash - > setText ( m_hash ) ;
2013-07-27 23:04:16 +04:00
2015-02-01 02:27:51 +03:00
return true ;
2012-05-15 20:57:31 +04:00
}
2015-04-19 18:17:47 +03:00
void AddNewTorrentDialog : : showEvent ( QShowEvent * event )
{
QDialog : : showEvent ( event ) ;
2016-02-09 11:56:48 +03:00
if ( ! isTopLevel ( ) ) return ;
2015-04-19 18:17:47 +03:00
activateWindow ( ) ;
raise ( ) ;
}
void AddNewTorrentDialog : : showAdvancedSettings ( bool show )
{
2016-02-15 10:15:40 +03:00
const int minimumW = minimumWidth ( ) ;
setMinimumWidth ( width ( ) ) ; // to remain the same width
2015-04-19 18:17:47 +03:00
if ( show ) {
2015-06-15 12:36:14 +03:00
ui - > adv_button - > setText ( QString : : fromUtf8 ( C_UP ) ) ;
2015-04-19 18:17:47 +03:00
ui - > settings_group - > setVisible ( true ) ;
2015-11-30 16:30:56 +03:00
ui - > infoGroup - > setVisible ( true ) ;
2016-02-09 11:56:48 +03:00
ui - > contentTreeView - > setVisible ( m_hasMetadata ) ;
2017-04-05 10:21:12 +03:00
static_cast < QVBoxLayout * > ( layout ( ) ) - > insertWidget ( layout ( ) - > indexOf ( ui - > never_show_cb ) + 1 , ui - > adv_button ) ;
2015-04-19 18:17:47 +03:00
}
else {
2015-06-15 12:36:14 +03:00
ui - > adv_button - > setText ( QString : : fromUtf8 ( C_DOWN ) ) ;
2015-04-19 18:17:47 +03:00
ui - > settings_group - > setVisible ( false ) ;
2015-11-30 16:30:56 +03:00
ui - > infoGroup - > setVisible ( false ) ;
2015-04-19 18:17:47 +03:00
ui - > buttonsHLayout - > insertWidget ( 0 , layout ( ) - > takeAt ( layout ( ) - > indexOf ( ui - > never_show_cb ) + 1 ) - > widget ( ) ) ;
}
2016-02-15 10:15:40 +03:00
adjustSize ( ) ;
setMinimumWidth ( minimumW ) ;
2015-04-19 18:17:47 +03:00
}
2012-05-15 20:57:31 +04:00
void AddNewTorrentDialog : : saveSavePathHistory ( ) const
{
2016-04-23 02:55:59 +03:00
QDir selectedSavePath ( ui - > savePath - > selectedPath ( ) ) ;
2015-02-01 02:27:51 +03:00
// Get current history
2016-02-09 11:56:48 +03:00
QStringList history = settings ( ) - > loadValue ( KEY_SAVEPATHHISTORY ) . toStringList ( ) ;
QList < QDir > historyDirs ;
2017-04-05 10:21:12 +03:00
foreach ( const QString dir , history )
2016-02-09 11:56:48 +03:00
historyDirs < < QDir ( dir ) ;
if ( ! historyDirs . contains ( selectedSavePath ) ) {
2015-02-01 02:27:51 +03:00
// Add save path to history
2016-02-09 11:56:48 +03:00
history . push_front ( selectedSavePath . absolutePath ( ) ) ;
2015-02-01 02:27:51 +03:00
// Limit list size
if ( history . size ( ) > 8 )
2015-02-01 02:37:53 +03:00
history . pop_back ( ) ;
2015-02-01 02:27:51 +03:00
// Save history
2016-02-09 11:56:48 +03:00
settings ( ) - > storeValue ( KEY_SAVEPATHHISTORY , history ) ;
2015-02-01 02:27:51 +03:00
}
2012-05-15 20:57:31 +04:00
}
// save_path is a folder, not an absolute file path
int AddNewTorrentDialog : : indexOfSavePath ( const QString & save_path )
{
2015-02-01 02:27:51 +03:00
QDir saveDir ( save_path ) ;
2016-04-23 02:55:59 +03:00
for ( int i = 0 ; i < ui - > savePath - > count ( ) ; + + i )
if ( QDir ( ui - > savePath - > item ( i ) ) = = saveDir )
2015-02-01 02:27:51 +03:00
return i ;
return - 1 ;
2012-05-15 20:57:31 +04:00
}
2015-02-01 02:27:51 +03:00
void AddNewTorrentDialog : : updateDiskSpaceLabel ( )
{
// Determine torrent size
qulonglong torrent_size = 0 ;
if ( m_hasMetadata ) {
if ( m_contentModel ) {
2015-04-19 18:17:47 +03:00
const QVector < int > priorities = m_contentModel - > model ( ) - > getFilePriorities ( ) ;
Q_ASSERT ( priorities . size ( ) = = m_torrentInfo . filesCount ( ) ) ;
for ( int i = 0 ; i < priorities . size ( ) ; + + i )
2015-02-01 02:27:51 +03:00
if ( priorities [ i ] > 0 )
2015-04-19 18:17:47 +03:00
torrent_size + = m_torrentInfo . fileSize ( i ) ;
2015-02-01 02:27:51 +03:00
}
else {
2015-04-19 18:17:47 +03:00
torrent_size = m_torrentInfo . totalSize ( ) ;
2015-02-01 02:27:51 +03:00
}
2012-05-15 20:57:31 +04:00
}
2015-02-01 02:27:51 +03:00
2015-05-06 14:53:27 +03:00
QString size_string = torrent_size ? Utils : : Misc : : friendlyUnit ( torrent_size ) : QString ( tr ( " Not Available " , " This size is unavailable. " ) ) ;
2015-02-01 02:27:51 +03:00
size_string + = " ( " ;
2015-11-30 17:16:44 +03:00
size_string + = tr ( " Free space on disk: %1 " ) . arg ( Utils : : Misc : : friendlyUnit ( Utils : : Fs : : freeDiskSpaceOnPath (
2016-04-23 02:55:59 +03:00
ui - > savePath - > selectedPath ( ) ) ) ) ;
2015-02-01 02:27:51 +03:00
size_string + = " ) " ;
ui - > size_lbl - > setText ( size_string ) ;
2012-05-15 20:57:31 +04:00
}
2016-04-23 02:55:59 +03:00
void AddNewTorrentDialog : : onSavePathChanged ( const QString & newPath )
2012-05-15 20:57:31 +04:00
{
2015-02-01 02:27:51 +03:00
// Toggle default save path setting checkbox visibility
2016-02-09 11:56:48 +03:00
ui - > defaultSavePathCheckBox - > setChecked ( false ) ;
2016-04-23 02:55:59 +03:00
ui - > defaultSavePathCheckBox - > setVisible ( QDir ( newPath ) ! = QDir ( BitTorrent : : Session : : instance ( ) - > defaultSavePath ( ) ) ) ;
2015-02-01 02:27:51 +03:00
// Remember index
2016-04-23 02:55:59 +03:00
m_oldIndex = ui - > savePath - > currentIndex ( ) ;
2015-06-28 10:57:40 +03:00
updateDiskSpaceLabel ( ) ;
2012-12-01 04:06:47 +04:00
}
2016-02-09 11:56:48 +03:00
void AddNewTorrentDialog : : categoryChanged ( int index )
{
Q_UNUSED ( index ) ;
2016-05-08 22:47:50 +03:00
if ( ui - > comboTTM - > currentIndex ( ) = = 1 ) {
2016-02-09 11:56:48 +03:00
QString savePath = BitTorrent : : Session : : instance ( ) - > categorySavePath ( ui - > categoryComboBox - > currentText ( ) ) ;
2016-04-23 02:55:59 +03:00
ui - > savePath - > setSelectedPath ( Utils : : Fs : : toNativePath ( savePath ) ) ;
2016-02-09 11:56:48 +03:00
}
}
2016-07-15 05:15:10 +03:00
void AddNewTorrentDialog : : setSavePath ( const QString & newPath )
{
int existingIndex = indexOfSavePath ( newPath ) ;
if ( existingIndex < 0 ) {
// New path, prepend to combo box
2016-04-23 02:55:59 +03:00
ui - > savePath - > insertItem ( 0 , newPath ) ;
2016-07-15 05:15:10 +03:00
existingIndex = 0 ;
}
2016-04-23 02:55:59 +03:00
ui - > savePath - > setCurrentIndex ( existingIndex ) ;
onSavePathChanged ( newPath ) ;
2012-05-15 20:57:31 +04:00
}
void AddNewTorrentDialog : : renameSelectedFile ( )
{
2016-02-09 11:56:48 +03:00
const QModelIndexList selectedIndexes = ui - > contentTreeView - > selectionModel ( ) - > selectedRows ( 0 ) ;
2017-02-07 08:17:41 +03:00
if ( selectedIndexes . size ( ) ! = 1 ) return ;
const QModelIndex modelIndex = selectedIndexes . first ( ) ;
if ( ! modelIndex . isValid ( ) ) return ;
2015-02-01 02:27:51 +03:00
// Ask for new name
2017-02-07 08:17:41 +03:00
bool ok = false ;
QString newName = AutoExpandableDialog : : getText ( this , tr ( " Renaming " ) , tr ( " New name: " ) , QLineEdit : : Normal , modelIndex . data ( ) . toString ( ) , & ok )
. trimmed ( ) ;
if ( ! ok ) return ;
if ( newName . isEmpty ( ) | | ! Utils : : Fs : : isValidFileSystemName ( newName ) ) {
MessageBoxRaised : : warning ( this , tr ( " Rename error " ) ,
tr ( " The name is empty or contains forbidden characters, please choose a different one. " ) ,
QMessageBox : : Ok ) ;
return ;
}
if ( m_contentModel - > itemType ( modelIndex ) = = TorrentContentModelItem : : FileType ) {
// renaming a file
const int fileIndex = m_contentModel - > getFileIndex ( modelIndex ) ;
if ( newName . endsWith ( QB_EXT ) )
newName . chop ( QB_EXT . size ( ) ) ;
const QString oldFileName = m_torrentInfo . fileName ( fileIndex ) ;
const QString oldFilePath = m_torrentInfo . filePath ( fileIndex ) ;
const QString newFilePath = oldFilePath . leftRef ( oldFilePath . size ( ) - oldFileName . size ( ) ) + newName ;
if ( oldFileName = = newName ) {
qDebug ( " Name did not change: %s " , qPrintable ( oldFileName ) ) ;
2015-02-01 02:27:51 +03:00
return ;
2012-05-15 20:57:31 +04:00
}
2017-02-07 08:17:41 +03:00
// check if that name is already used
for ( int i = 0 ; i < m_torrentInfo . filesCount ( ) ; + + i ) {
if ( i = = fileIndex ) continue ;
if ( Utils : : Fs : : sameFileNames ( m_torrentInfo . filePath ( i ) , newFilePath ) ) {
MessageBoxRaised : : warning ( this , tr ( " Rename error " ) ,
tr ( " This name is already in use in this folder. Please use a different name. " ) ,
QMessageBox : : Ok ) ;
2015-02-01 02:27:51 +03:00
return ;
}
}
2017-02-07 08:17:41 +03:00
qDebug ( " Renaming %s to %s " , qPrintable ( oldFilePath ) , qPrintable ( newFilePath ) ) ;
m_torrentInfo . renameFile ( fileIndex , newFilePath ) ;
m_contentModel - > setData ( modelIndex , newName ) ;
}
else {
// renaming a folder
QStringList pathItems ;
pathItems < < modelIndex . data ( ) . toString ( ) ;
QModelIndex parent = m_contentModel - > parent ( modelIndex ) ;
while ( parent . isValid ( ) ) {
pathItems . prepend ( parent . data ( ) . toString ( ) ) ;
parent = m_contentModel - > parent ( parent ) ;
}
const QString oldPath = pathItems . join ( " / " ) ;
pathItems . removeLast ( ) ;
pathItems < < newName ;
QString newPath = pathItems . join ( " / " ) ;
if ( Utils : : Fs : : sameFileNames ( oldPath , newPath ) ) {
qDebug ( " Name did not change " ) ;
return ;
}
if ( ! newPath . endsWith ( " / " ) ) newPath + = " / " ;
// Check for overwriting
for ( int i = 0 ; i < m_torrentInfo . filesCount ( ) ; + + i ) {
const QString & currentName = m_torrentInfo . filePath ( i ) ;
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
2017-02-07 08:17:41 +03:00
if ( currentName . startsWith ( newPath , Qt : : CaseSensitive ) ) {
2012-05-15 20:57:31 +04:00
# else
2017-02-07 08:17:41 +03:00
if ( currentName . startsWith ( newPath , Qt : : CaseInsensitive ) ) {
2012-05-15 20:57:31 +04:00
# endif
2017-02-07 08:17:41 +03:00
MessageBoxRaised : : warning ( this , tr ( " The folder could not be renamed " ) ,
tr ( " This name is already in use in this folder. Please use a different name. " ) ,
QMessageBox : : Ok ) ;
return ;
2015-02-01 02:27:51 +03:00
}
2017-02-07 08:17:41 +03:00
}
// Replace path in all files
for ( int i = 0 ; i < m_torrentInfo . filesCount ( ) ; + + i ) {
const QString & currentName = m_torrentInfo . filePath ( i ) ;
if ( currentName . startsWith ( oldPath ) ) {
QString newName = currentName ;
newName . replace ( 0 , oldPath . length ( ) , newPath ) ;
newName = Utils : : Fs : : expandPath ( newName ) ;
qDebug ( " Rename %s to %s " , qPrintable ( currentName ) , qPrintable ( newName ) ) ;
m_torrentInfo . renameFile ( i , newName ) ;
2015-02-01 02:27:51 +03:00
}
2012-05-15 20:57:31 +04:00
}
2017-02-07 08:17:41 +03:00
// Rename folder in torrent files model too
m_contentModel - > setData ( modelIndex , newName ) ;
2012-05-15 20:57:31 +04:00
}
}
2016-02-09 11:56:48 +03:00
void AddNewTorrentDialog : : populateSavePathComboBox ( )
2012-05-15 20:57:31 +04:00
{
2016-10-06 16:53:43 +03:00
QString defSavePath = BitTorrent : : Session : : instance ( ) - > defaultSavePath ( ) ;
2016-02-09 11:56:48 +03:00
2016-04-23 02:55:59 +03:00
ui - > savePath - > clear ( ) ;
ui - > savePath - > addItem ( defSavePath ) ;
2016-02-09 11:56:48 +03:00
QDir defaultSaveDir ( defSavePath ) ;
2015-02-01 02:27:51 +03:00
// Load save path history
2016-02-09 11:56:48 +03:00
foreach ( const QString & savePath , settings ( ) - > loadValue ( KEY_SAVEPATHHISTORY ) . toStringList ( ) )
if ( QDir ( savePath ) ! = defaultSaveDir )
2016-04-23 02:55:59 +03:00
ui - > savePath - > addItem ( savePath ) ;
2016-07-15 05:15:10 +03:00
if ( ! m_torrentParams . savePath . isEmpty ( ) )
setSavePath ( m_torrentParams . savePath ) ;
2012-05-15 20:57:31 +04:00
}
2017-04-05 10:21:12 +03:00
void AddNewTorrentDialog : : displayContentTreeMenu ( const QPoint & )
2015-02-01 02:27:51 +03:00
{
QMenu myFilesLlistMenu ;
2016-02-09 11:56:48 +03:00
const QModelIndexList selectedRows = ui - > contentTreeView - > selectionModel ( ) - > selectedRows ( 0 ) ;
2015-02-01 02:27:51 +03:00
QAction * actRename = 0 ;
2016-02-06 11:38:00 +03:00
if ( selectedRows . size ( ) = = 1 ) {
2015-04-19 18:17:47 +03:00
actRename = myFilesLlistMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename... " ) ) ;
2015-02-01 02:27:51 +03:00
myFilesLlistMenu . addSeparator ( ) ;
}
QMenu subMenu ;
subMenu . setTitle ( tr ( " Priority " ) ) ;
subMenu . addAction ( ui - > actionNot_downloaded ) ;
subMenu . addAction ( ui - > actionNormal ) ;
subMenu . addAction ( ui - > actionHigh ) ;
subMenu . addAction ( ui - > actionMaximum ) ;
myFilesLlistMenu . addMenu ( & subMenu ) ;
// Call menu
QAction * act = myFilesLlistMenu . exec ( QCursor : : pos ( ) ) ;
if ( act ) {
if ( act = = actRename ) {
renameSelectedFile ( ) ;
}
else {
int prio = prio : : NORMAL ;
2015-06-14 11:12:35 +03:00
if ( act = = ui - > actionHigh )
2015-02-01 02:27:51 +03:00
prio = prio : : HIGH ;
2015-06-14 11:12:35 +03:00
else if ( act = = ui - > actionMaximum )
prio = prio : : MAXIMUM ;
else if ( act = = ui - > actionNot_downloaded )
prio = prio : : IGNORED ;
2015-02-01 02:27:51 +03:00
qDebug ( " Setting files priority " ) ;
foreach ( const QModelIndex & index , selectedRows ) {
qDebug ( " Setting priority(%d) for file at row %d " , prio , index . row ( ) ) ;
m_contentModel - > setData ( m_contentModel - > index ( index . row ( ) , PRIORITY , index . parent ( ) ) , prio ) ;
}
2012-05-15 20:57:31 +04:00
}
}
}
2013-07-27 23:04:16 +04:00
void AddNewTorrentDialog : : accept ( )
2012-05-15 20:57:31 +04:00
{
2015-04-19 18:17:47 +03:00
if ( ! m_hasMetadata )
2017-04-05 10:21:12 +03:00
disconnect ( this , SLOT ( updateMetadata ( const BitTorrent : : TorrentInfo & ) ) ) ;
2015-04-19 18:17:47 +03:00
2015-11-07 21:44:53 +03:00
// TODO: Check if destination actually exists
2016-07-15 05:15:10 +03:00
m_torrentParams . skipChecking = ui - > skipCheckingCheckBox - > isChecked ( ) ;
2015-02-01 02:27:51 +03:00
2016-02-09 11:56:48 +03:00
// Category
2016-07-15 05:15:10 +03:00
m_torrentParams . category = ui - > categoryComboBox - > currentText ( ) ;
2015-02-01 02:27:51 +03:00
2016-02-09 11:56:48 +03:00
if ( ui - > defaultCategoryCheckbox - > isChecked ( ) )
2016-07-15 05:15:10 +03:00
settings ( ) - > storeValue ( KEY_DEFAULTCATEGORY , m_torrentParams . category ) ;
2015-11-03 18:05:15 +03:00
2015-02-01 02:27:51 +03:00
// Save file priorities
if ( m_contentModel )
2016-07-15 05:15:10 +03:00
m_torrentParams . filePriorities = m_contentModel - > model ( ) - > getFilePriorities ( ) ;
2015-02-01 02:27:51 +03:00
2016-07-15 05:15:10 +03:00
m_torrentParams . addPaused = TriStateBool ( ! ui - > startTorrentCheckBox - > isChecked ( ) ) ;
m_torrentParams . createSubfolder = TriStateBool ( ui - > createSubfolderCheckBox - > isChecked ( ) ) ;
2015-04-19 18:17:47 +03:00
2016-04-23 02:55:59 +03:00
QString savePath = ui - > savePath - > selectedPath ( ) ;
2016-05-08 22:47:50 +03:00
if ( ui - > comboTTM - > currentIndex ( ) ! = 1 ) { // 0 is Manual mode and 1 is Automatic mode. Handle all non 1 values as manual mode.
2016-07-15 05:15:10 +03:00
m_torrentParams . savePath = savePath ;
2016-02-09 11:56:48 +03:00
saveSavePathHistory ( ) ;
2016-10-06 16:53:43 +03:00
if ( ui - > defaultSavePathCheckBox - > isChecked ( ) )
2016-09-16 21:04:48 +03:00
BitTorrent : : Session : : instance ( ) - > setDefaultSavePath ( savePath ) ;
2015-04-19 18:17:47 +03:00
}
2016-02-09 11:56:48 +03:00
setEnabled ( ! ui - > never_show_cb - > isChecked ( ) ) ;
2015-04-19 18:17:47 +03:00
// Add torrent
if ( ! m_hasMetadata )
2016-07-15 05:15:10 +03:00
BitTorrent : : Session : : instance ( ) - > addTorrent ( m_hash , m_torrentParams ) ;
2015-04-19 18:17:47 +03:00
else
2016-07-15 05:15:10 +03:00
BitTorrent : : Session : : instance ( ) - > addTorrent ( m_torrentInfo , m_torrentParams ) ;
2015-04-19 18:17:47 +03:00
2016-04-07 17:58:30 +03:00
m_torrentGuard - > markAsAddedToSession ( ) ;
2015-02-01 02:27:51 +03:00
QDialog : : accept ( ) ;
2013-07-27 23:04:16 +04:00
}
2015-02-01 02:27:51 +03:00
void AddNewTorrentDialog : : reject ( )
{
2015-04-19 18:17:47 +03:00
if ( ! m_hasMetadata ) {
disconnect ( this , SLOT ( updateMetadata ( BitTorrent : : TorrentInfo ) ) ) ;
2015-02-01 02:27:51 +03:00
setMetadataProgressIndicator ( false ) ;
2015-04-19 18:17:47 +03:00
BitTorrent : : Session : : instance ( ) - > cancelLoadMetadata ( m_hash ) ;
2015-02-01 02:27:51 +03:00
}
2015-04-19 18:17:47 +03:00
2015-02-01 02:27:51 +03:00
QDialog : : reject ( ) ;
2013-07-27 23:04:16 +04:00
}
2015-04-19 18:17:47 +03:00
void AddNewTorrentDialog : : updateMetadata ( const BitTorrent : : TorrentInfo & info )
2015-02-01 02:27:51 +03:00
{
2015-04-19 18:17:47 +03:00
if ( info . hash ( ) ! = m_hash ) return ;
2013-07-27 23:04:16 +04:00
2015-04-19 18:17:47 +03:00
disconnect ( this , SLOT ( updateMetadata ( BitTorrent : : TorrentInfo ) ) ) ;
if ( ! info . isValid ( ) ) {
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " I/O Error " ) , ( " Invalid metadata. " ) ) ;
2015-04-19 18:17:47 +03:00
setMetadataProgressIndicator ( false , tr ( " Invalid metadata " ) ) ;
2015-02-01 02:27:51 +03:00
return ;
}
2015-04-19 18:17:47 +03:00
// Good to go
m_torrentInfo = info ;
m_hasMetadata = true ;
setMetadataProgressIndicator ( true , tr ( " Parsing metadata... " ) ) ;
// Update UI
setupTreeview ( ) ;
setMetadataProgressIndicator ( false , tr ( " Metadata retrieval complete " ) ) ;
2012-05-15 20:57:31 +04:00
}
2013-07-27 23:05:19 +04:00
2015-02-01 02:27:51 +03:00
void AddNewTorrentDialog : : setMetadataProgressIndicator ( bool visibleIndicator , const QString & labelText )
{
// Always show info label when waiting for metadata
ui - > lblMetaLoading - > setVisible ( true ) ;
ui - > lblMetaLoading - > setText ( labelText ) ;
ui - > progMetaLoading - > setVisible ( visibleIndicator ) ;
2013-07-27 23:05:19 +04:00
}
2014-02-02 21:54:19 +04:00
2015-02-01 02:27:51 +03:00
void AddNewTorrentDialog : : setupTreeview ( )
{
if ( ! m_hasMetadata ) {
2016-03-07 07:22:18 +03:00
setCommentText ( tr ( " Not Available " , " This comment is unavailable " ) ) ;
2015-02-01 02:27:51 +03:00
ui - > date_lbl - > setText ( tr ( " Not Available " , " This date is unavailable " ) ) ;
2014-08-10 00:10:20 +04:00
}
2015-02-01 02:27:51 +03:00
else {
// Set dialog title
2015-04-19 18:17:47 +03:00
setWindowTitle ( m_torrentInfo . name ( ) ) ;
2015-02-01 02:27:51 +03:00
// Set torrent information
2016-03-07 07:22:18 +03:00
setCommentText ( Utils : : Misc : : parseHtmlLinks ( m_torrentInfo . comment ( ) ) ) ;
2015-11-30 17:16:44 +03:00
ui - > date_lbl - > setText ( ! m_torrentInfo . creationDate ( ) . isNull ( ) ? m_torrentInfo . creationDate ( ) . toString ( Qt : : DefaultLocaleShortDate ) : tr ( " Not available " ) ) ;
2015-02-01 02:27:51 +03:00
// Prepare content tree
2016-02-06 11:38:00 +03:00
m_contentModel = new TorrentContentFilterModel ( this ) ;
connect ( m_contentModel - > model ( ) , SIGNAL ( filteredFilesChanged ( ) ) , SLOT ( updateDiskSpaceLabel ( ) ) ) ;
2016-02-09 11:56:48 +03:00
ui - > contentTreeView - > setModel ( m_contentModel ) ;
2017-03-08 08:01:59 +03:00
m_contentDelegate = new PropListDelegate ( nullptr ) ;
2016-02-09 11:56:48 +03:00
ui - > contentTreeView - > setItemDelegate ( m_contentDelegate ) ;
2017-04-05 10:21:12 +03:00
connect ( ui - > contentTreeView , SIGNAL ( clicked ( const QModelIndex & ) ) , ui - > contentTreeView , SLOT ( edit ( const QModelIndex & ) ) ) ;
connect ( ui - > contentTreeView , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayContentTreeMenu ( const QPoint & ) ) ) ;
2016-02-06 11:38:00 +03:00
// List files in torrent
m_contentModel - > model ( ) - > setupModelData ( m_torrentInfo ) ;
if ( ! m_headerState . isEmpty ( ) )
2016-02-09 11:56:48 +03:00
ui - > contentTreeView - > header ( ) - > restoreState ( m_headerState ) ;
2016-02-06 11:38:00 +03:00
2016-03-18 01:23:11 +03:00
// Hide useless columns after loading the header state
ui - > contentTreeView - > hideColumn ( PROGRESS ) ;
ui - > contentTreeView - > hideColumn ( REMAINING ) ;
2016-03-22 21:41:43 +03:00
ui - > contentTreeView - > hideColumn ( AVAILABILITY ) ;
2016-03-18 01:23:11 +03:00
2016-02-06 11:38:00 +03:00
// Expand root folder
2016-02-09 11:56:48 +03:00
ui - > contentTreeView - > setExpanded ( m_contentModel - > index ( 0 , 0 ) , true ) ;
2014-02-02 21:54:19 +04:00
}
2015-02-01 02:27:51 +03:00
updateDiskSpaceLabel ( ) ;
2016-02-09 11:56:48 +03:00
showAdvancedSettings ( settings ( ) - > loadValue ( KEY_EXPANDED , false ) . toBool ( ) ) ;
2014-02-02 21:54:19 +04:00
}
2015-04-19 18:17:47 +03:00
void AddNewTorrentDialog : : handleDownloadFailed ( const QString & url , const QString & reason )
{
2015-10-26 10:45:14 +03:00
MessageBoxRaised : : critical ( this , tr ( " Download Error " ) , QString ( " Cannot download '%1': %2 " ) . arg ( url ) . arg ( reason ) ) ;
2015-04-19 18:17:47 +03:00
this - > deleteLater ( ) ;
}
void AddNewTorrentDialog : : handleRedirectedToMagnet ( const QString & url , const QString & magnetUri )
{
Q_UNUSED ( url )
2016-01-07 14:22:35 +03:00
if ( loadMagnet ( BitTorrent : : MagnetUri ( magnetUri ) ) )
2015-04-19 18:17:47 +03:00
open ( ) ;
else
this - > deleteLater ( ) ;
}
void AddNewTorrentDialog : : handleDownloadFinished ( const QString & url , const QString & filePath )
{
Q_UNUSED ( url )
if ( loadTorrent ( filePath ) )
open ( ) ;
else
this - > deleteLater ( ) ;
}
2016-02-09 11:56:48 +03:00
2016-05-08 22:47:50 +03:00
void AddNewTorrentDialog : : TMMChanged ( int index )
2016-02-09 11:56:48 +03:00
{
2016-05-08 22:47:50 +03:00
if ( index ! = 1 ) { // 0 is Manual mode and 1 is Automatic mode. Handle all non 1 values as manual mode.
2016-02-09 11:56:48 +03:00
populateSavePathComboBox ( ) ;
2016-05-08 22:47:50 +03:00
ui - > groupBoxSavePath - > setEnabled ( true ) ;
2016-04-23 02:55:59 +03:00
ui - > savePath - > blockSignals ( false ) ;
ui - > savePath - > setCurrentIndex ( m_oldIndex < ui - > savePath - > count ( ) ? m_oldIndex : ui - > savePath - > count ( ) - 1 ) ;
2016-05-08 22:47:50 +03:00
ui - > adv_button - > setEnabled ( true ) ;
2016-02-09 11:56:48 +03:00
}
else {
2016-05-08 22:47:50 +03:00
ui - > groupBoxSavePath - > setEnabled ( false ) ;
2016-04-23 02:55:59 +03:00
ui - > savePath - > blockSignals ( true ) ;
ui - > savePath - > clear ( ) ;
2016-02-09 11:56:48 +03:00
QString savePath = BitTorrent : : Session : : instance ( ) - > categorySavePath ( ui - > categoryComboBox - > currentText ( ) ) ;
2016-04-23 02:55:59 +03:00
ui - > savePath - > addItem ( savePath ) ;
2016-02-09 11:56:48 +03:00
ui - > defaultSavePathCheckBox - > setVisible ( false ) ;
2016-05-08 22:47:50 +03:00
ui - > adv_button - > setChecked ( true ) ;
ui - > adv_button - > setEnabled ( false ) ;
showAdvancedSettings ( true ) ;
2016-02-09 11:56:48 +03:00
}
}
2016-03-07 07:22:18 +03:00
void AddNewTorrentDialog : : setCommentText ( const QString & str ) const
{
ui - > commentLabel - > setText ( str ) ;
// workaround for the additional space introduced by QScrollArea
int lineHeight = ui - > commentLabel - > fontMetrics ( ) . lineSpacing ( ) ;
int lines = 1 + str . count ( " \n " ) ;
int height = lineHeight * lines ;
ui - > scrollArea - > setMaximumHeight ( height ) ;
}
2016-04-07 17:58:30 +03:00
void AddNewTorrentDialog : : doNotDeleteTorrentClicked ( bool checked )
{
m_torrentGuard - > setAutoRemove ( ! checked ) ;
}