2009-11-08 17:20:58 +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>
2009-11-08 18:41:32 +03:00
# include <QTimer>
2009-11-08 19:19:21 +03:00
# include <QListWidgetItem>
2009-11-08 18:41:32 +03:00
# include <QVBoxLayout>
2009-11-08 19:19:21 +03:00
# include <QStackedWidget>
2009-11-08 22:09:10 +03:00
# include <QSplitter>
2009-11-29 00:46:46 +03:00
# include <QHeaderView>
2009-11-09 11:56:21 +03:00
# include <QAction>
# include <QMessageBox>
# include <QMenu>
# include <QFileDialog>
2010-01-05 23:57:33 +03:00
# include <QDesktopServices>
2015-04-19 18:17:47 +03:00
# include <QBitArray>
# include "core/bittorrent/session.h"
2015-06-02 12:09:15 +03:00
# include "core/preferences.h"
# include "core/utils/fs.h"
# include "core/utils/misc.h"
# include "core/utils/string.h"
2015-06-15 12:36:14 +03:00
# include "core/unicodestrings.h"
2009-11-20 10:48:44 +03:00
# include "proplistdelegate.h"
2012-02-21 23:54:24 +04:00
# include "torrentcontentfiltermodel.h"
# include "torrentcontentmodel.h"
2009-11-14 13:37:45 +03:00
# include "peerlistwidget.h"
2014-08-25 15:58:48 +04:00
# include "speedwidget.h"
2009-11-19 14:09:03 +03:00
# include "trackerlist.h"
2010-11-14 00:15:52 +03:00
# include "mainwindow.h"
2009-11-21 21:36:12 +03:00
# include "downloadedpiecesbar.h"
2009-11-21 22:40:24 +03:00
# include "pieceavailabilitybar.h"
2010-10-22 22:59:18 +04:00
# include "proptabbar.h"
2015-04-19 18:17:47 +03:00
# include "guiiconprovider.h"
2011-02-27 17:40:46 +03:00
# include "lineedit.h"
2015-06-02 12:09:15 +03:00
# include "transferlistwidget.h"
2013-07-22 15:46:10 +04:00
# include "autoexpandabledialog.h"
2015-06-02 12:09:15 +03:00
# include "propertieswidget.h"
2010-11-23 00:55:32 +03:00
2010-11-14 00:15:52 +03:00
PropertiesWidget : : PropertiesWidget ( QWidget * parent , MainWindow * main_window , TransferListWidget * transferList ) :
2015-04-19 18:17:47 +03:00
QWidget ( parent ) , transferList ( transferList ) , main_window ( main_window ) , m_torrent ( 0 ) {
2009-11-08 17:20:58 +03:00
setupUi ( this ) ;
2011-03-13 13:09:31 +03:00
2010-12-12 22:37:59 +03:00
// Icons
2015-04-19 18:17:47 +03:00
trackerUpButton - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " go-up " ) ) ;
trackerDownButton - > setIcon ( GuiIconProvider : : instance ( ) - > getIcon ( " go-down " ) ) ;
2010-12-12 22:37:59 +03:00
2009-11-08 22:09:10 +03:00
state = VISIBLE ;
2009-11-17 11:32:52 +03:00
2009-11-09 11:56:21 +03:00
// Set Properties list model
2012-02-21 23:54:24 +04:00
PropListModel = new TorrentContentFilterModel ( ) ;
2009-11-09 11:56:21 +03:00
filesList - > setModel ( PropListModel ) ;
2009-11-24 18:38:47 +03:00
PropDelegate = new PropListDelegate ( this ) ;
2009-11-09 11:56:21 +03:00
filesList - > setItemDelegate ( PropDelegate ) ;
2011-03-10 21:58:35 +03:00
filesList - > setSortingEnabled ( true ) ;
2011-02-27 17:40:46 +03:00
// Torrent content filtering
m_contentFilerLine = new LineEdit ( this ) ;
2014-11-16 18:07:33 +03:00
m_contentFilerLine - > setPlaceholderText ( tr ( " Filter files... " ) ) ;
2013-11-10 05:59:53 +04:00
connect ( m_contentFilerLine , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( filterText ( QString ) ) ) ;
2014-11-26 22:35:29 +03:00
contentFilterLayout - > insertWidget ( 4 , m_contentFilerLine ) ;
2009-11-09 11:56:21 +03:00
// SIGNAL/SLOTS
connect ( filesList , SIGNAL ( clicked ( const QModelIndex & ) ) , filesList , SLOT ( edit ( const QModelIndex & ) ) ) ;
2011-02-27 17:40:46 +03:00
connect ( selectAllButton , SIGNAL ( clicked ( ) ) , PropListModel , SLOT ( selectAll ( ) ) ) ;
connect ( selectNoneButton , SIGNAL ( clicked ( ) ) , PropListModel , SLOT ( selectNone ( ) ) ) ;
2009-11-09 11:56:21 +03:00
connect ( filesList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayFilesListMenu ( const QPoint & ) ) ) ;
2014-08-15 13:50:42 +04:00
connect ( filesList , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( openDoubleClickedFile ( const QModelIndex & ) ) ) ;
2009-12-19 21:55:04 +03:00
connect ( PropListModel , SIGNAL ( filteredFilesChanged ( ) ) , this , SLOT ( filteredFilesChanged ( ) ) ) ;
2013-02-28 23:00:04 +04:00
connect ( listWebSeeds , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayWebSeedListMenu ( const QPoint & ) ) ) ;
2015-04-19 18:17:47 +03:00
connect ( transferList , SIGNAL ( currentTorrentChanged ( BitTorrent : : TorrentHandle * const ) ) , this , SLOT ( loadTorrentInfos ( BitTorrent : : TorrentHandle * const ) ) ) ;
2009-11-09 11:56:21 +03:00
connect ( PropDelegate , SIGNAL ( filteredFilesChanged ( ) ) , this , SLOT ( filteredFilesChanged ( ) ) ) ;
2009-11-15 16:10:31 +03:00
connect ( stackedProperties , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( loadDynamicData ( ) ) ) ;
2015-04-19 18:17:47 +03:00
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( torrentSavePathChanged ( BitTorrent : : TorrentHandle * const ) ) , this , SLOT ( updateSavePath ( BitTorrent : : TorrentHandle * const ) ) ) ;
connect ( BitTorrent : : Session : : instance ( ) , SIGNAL ( torrentMetadataLoaded ( BitTorrent : : TorrentHandle * const ) ) , this , SLOT ( updateTorrentInfos ( BitTorrent : : TorrentHandle * const ) ) ) ;
2014-12-20 19:09:35 +03:00
connect ( filesList - > header ( ) , SIGNAL ( sectionMoved ( int , int , int ) ) , this , SLOT ( saveSettings ( ) ) ) ;
connect ( filesList - > header ( ) , SIGNAL ( sectionResized ( int , int , int ) ) , this , SLOT ( saveSettings ( ) ) ) ;
connect ( filesList - > header ( ) , SIGNAL ( sortIndicatorChanged ( int , Qt : : SortOrder ) ) , this , SLOT ( saveSettings ( ) ) ) ;
2009-11-08 22:09:10 +03:00
2009-11-08 18:41:32 +03:00
// Downloaded pieces progress bar
2009-11-21 21:36:12 +03:00
downloaded_pieces = new DownloadedPiecesBar ( this ) ;
ProgressHLayout - > insertWidget ( 1 , downloaded_pieces ) ;
2009-11-21 22:40:24 +03:00
// Pieces availability bar
pieces_availability = new PieceAvailabilityBar ( this ) ;
ProgressHLayout_2 - > insertWidget ( 1 , pieces_availability ) ;
2009-11-19 14:09:03 +03:00
// Tracker list
trackerList = new TrackerList ( this ) ;
2010-01-05 22:59:25 +03:00
connect ( trackerUpButton , SIGNAL ( clicked ( ) ) , trackerList , SLOT ( moveSelectionUp ( ) ) ) ;
connect ( trackerDownButton , SIGNAL ( clicked ( ) ) , trackerList , SLOT ( moveSelectionDown ( ) ) ) ;
horizontalLayout_trackers - > insertWidget ( 0 , trackerList ) ;
2014-12-22 01:25:05 +03:00
connect ( trackerList - > header ( ) , SIGNAL ( sectionMoved ( int , int , int ) ) , trackerList , SLOT ( saveSettings ( ) ) ) ;
connect ( trackerList - > header ( ) , SIGNAL ( sectionResized ( int , int , int ) ) , trackerList , SLOT ( saveSettings ( ) ) ) ;
connect ( trackerList - > header ( ) , SIGNAL ( sortIndicatorChanged ( int , Qt : : SortOrder ) ) , trackerList , SLOT ( saveSettings ( ) ) ) ;
2009-11-14 13:37:45 +03:00
// Peers list
2009-11-15 13:00:07 +03:00
peersList = new PeerListWidget ( this ) ;
2009-11-14 13:37:45 +03:00
peerpage_layout - > addWidget ( peersList ) ;
2014-12-22 01:25:05 +03:00
connect ( peersList - > header ( ) , SIGNAL ( sectionMoved ( int , int , int ) ) , peersList , SLOT ( saveSettings ( ) ) ) ;
connect ( peersList - > header ( ) , SIGNAL ( sectionResized ( int , int , int ) ) , peersList , SLOT ( saveSettings ( ) ) ) ;
connect ( peersList - > header ( ) , SIGNAL ( sortIndicatorChanged ( int , Qt : : SortOrder ) ) , peersList , SLOT ( saveSettings ( ) ) ) ;
2014-08-25 15:58:48 +04:00
// Speed widget
speedWidget = new SpeedWidget ( this ) ;
speed_layout - > addWidget ( speedWidget ) ;
2010-10-22 22:59:18 +04:00
// Tab bar
m_tabBar = new PropTabBar ( ) ;
verticalLayout - > addLayout ( m_tabBar ) ;
connect ( m_tabBar , SIGNAL ( tabChanged ( int ) ) , stackedProperties , SLOT ( setCurrentIndex ( int ) ) ) ;
2014-12-20 19:09:35 +03:00
connect ( m_tabBar , SIGNAL ( tabChanged ( int ) ) , this , SLOT ( saveSettings ( ) ) ) ;
2010-10-22 22:59:18 +04:00
connect ( m_tabBar , SIGNAL ( visibilityToggled ( bool ) ) , SLOT ( setVisibility ( bool ) ) ) ;
2014-12-20 19:09:35 +03:00
connect ( m_tabBar , SIGNAL ( visibilityToggled ( bool ) ) , this , SLOT ( saveSettings ( ) ) ) ;
2009-11-08 18:41:32 +03:00
// Dynamic data refresher
refreshTimer = new QTimer ( this ) ;
connect ( refreshTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( loadDynamicData ( ) ) ) ;
2009-11-19 14:09:03 +03:00
refreshTimer - > start ( 3000 ) ; // 3sec
2013-07-22 18:39:48 +04:00
editHotkeyFile = new QShortcut ( QKeySequence ( " F2 " ) , filesList , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( editHotkeyFile , SIGNAL ( activated ( ) ) , SLOT ( renameSelectedFile ( ) ) ) ;
editHotkeyWeb = new QShortcut ( QKeySequence ( " F2 " ) , listWebSeeds , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( editHotkeyWeb , SIGNAL ( activated ( ) ) , SLOT ( editWebSeed ( ) ) ) ;
connect ( listWebSeeds , SIGNAL ( doubleClicked ( QModelIndex ) ) , SLOT ( editWebSeed ( ) ) ) ;
2013-07-22 21:48:55 +04:00
deleteHotkeyWeb = new QShortcut ( QKeySequence ( QKeySequence : : Delete ) , listWebSeeds , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( deleteHotkeyWeb , SIGNAL ( activated ( ) ) , SLOT ( deleteSelectedUrlSeeds ( ) ) ) ;
2015-04-16 19:36:53 +03:00
openHotkeyFile = new QShortcut ( QKeySequence ( " Return " ) , filesList , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( openHotkeyFile , SIGNAL ( activated ( ) ) , SLOT ( openSelectedFile ( ) ) ) ;
2009-11-08 17:20:58 +03:00
}
PropertiesWidget : : ~ PropertiesWidget ( ) {
2011-03-14 22:18:52 +03:00
qDebug ( ) < < Q_FUNC_INFO < < " ENTER " ;
2009-11-08 18:41:32 +03:00
delete refreshTimer ;
2009-11-19 14:09:03 +03:00
delete trackerList ;
2009-11-14 13:37:45 +03:00
delete peersList ;
2014-08-25 15:58:48 +04:00
delete speedWidget ;
2009-11-21 21:36:12 +03:00
delete downloaded_pieces ;
2009-11-21 22:40:24 +03:00
delete pieces_availability ;
2009-11-09 11:56:21 +03:00
delete PropListModel ;
2009-11-14 22:28:35 +03:00
delete PropDelegate ;
2010-10-22 22:59:18 +04:00
delete m_tabBar ;
2013-07-22 18:39:48 +04:00
delete editHotkeyFile ;
delete editHotkeyWeb ;
2013-07-22 21:48:55 +04:00
delete deleteHotkeyWeb ;
2015-04-16 19:36:53 +03:00
delete openHotkeyFile ;
2011-03-14 22:18:52 +03:00
qDebug ( ) < < Q_FUNC_INFO < < " EXIT " ;
2009-11-08 18:41:32 +03:00
}
2009-12-02 23:41:59 +03:00
void PropertiesWidget : : showPiecesAvailability ( bool show ) {
2009-11-21 22:47:54 +03:00
avail_pieces_lbl - > setVisible ( show ) ;
pieces_availability - > setVisible ( show ) ;
2009-12-02 23:41:59 +03:00
avail_average_lbl - > setVisible ( show ) ;
2012-02-20 21:30:53 +04:00
if ( show | | ( ! show & & ! downloaded_pieces - > isVisible ( ) ) )
2009-12-02 23:41:59 +03:00
line_2 - > setVisible ( show ) ;
}
void PropertiesWidget : : showPiecesDownloaded ( bool show ) {
2009-11-21 22:47:54 +03:00
downloaded_pieces_lbl - > setVisible ( show ) ;
downloaded_pieces - > setVisible ( show ) ;
progress_lbl - > setVisible ( show ) ;
2012-02-20 21:30:53 +04:00
if ( show | | ( ! show & & ! pieces_availability - > isVisible ( ) ) )
2009-12-02 23:41:59 +03:00
line_2 - > setVisible ( show ) ;
2009-11-21 22:47:54 +03:00
}
2010-10-22 22:59:18 +04:00
void PropertiesWidget : : setVisibility ( bool visible ) {
2012-02-20 21:30:53 +04:00
if ( ! visible & & state = = VISIBLE ) {
2009-11-11 19:22:57 +03:00
QSplitter * hSplitter = static_cast < QSplitter * > ( parentWidget ( ) ) ;
stackedProperties - > setVisible ( false ) ;
2011-02-05 20:45:32 +03:00
slideSizes = hSplitter - > sizes ( ) ;
2009-11-11 19:22:57 +03:00
hSplitter - > handle ( 1 ) - > setVisible ( false ) ;
hSplitter - > handle ( 1 ) - > setDisabled ( true ) ;
2011-02-05 20:45:32 +03:00
QList < int > sizes = QList < int > ( ) < < hSplitter - > geometry ( ) . height ( ) - 30 < < 30 ;
hSplitter - > setSizes ( sizes ) ;
2009-11-08 22:09:10 +03:00
state = REDUCED ;
2011-02-05 20:45:32 +03:00
return ;
2009-11-08 22:09:10 +03:00
}
2012-02-20 21:30:53 +04:00
if ( visible & & state = = REDUCED ) {
2009-11-11 19:22:57 +03:00
stackedProperties - > setVisible ( true ) ;
QSplitter * hSplitter = static_cast < QSplitter * > ( parentWidget ( ) ) ;
hSplitter - > handle ( 1 ) - > setDisabled ( false ) ;
hSplitter - > handle ( 1 ) - > setVisible ( true ) ;
hSplitter - > setSizes ( slideSizes ) ;
2009-11-08 22:09:10 +03:00
state = VISIBLE ;
2009-11-16 18:29:44 +03:00
// Force refresh
loadDynamicData ( ) ;
2009-11-08 22:09:10 +03:00
}
}
2009-11-08 22:54:22 +03:00
void PropertiesWidget : : clear ( ) {
2009-11-15 13:00:07 +03:00
qDebug ( " Clearing torrent properties " ) ;
2009-11-08 22:54:22 +03:00
save_path - > clear ( ) ;
2009-11-12 10:42:21 +03:00
lbl_creationDate - > clear ( ) ;
2015-06-17 00:11:45 +03:00
label_total_pieces_val - > clear ( ) ;
2009-11-08 22:54:22 +03:00
hash_lbl - > clear ( ) ;
2009-11-19 15:17:51 +03:00
comment_text - > clear ( ) ;
2009-11-21 21:36:12 +03:00
progress_lbl - > clear ( ) ;
2009-11-19 14:09:03 +03:00
trackerList - > clear ( ) ;
2009-11-21 21:36:12 +03:00
downloaded_pieces - > clear ( ) ;
2009-11-21 22:40:24 +03:00
pieces_availability - > clear ( ) ;
2009-11-21 23:01:09 +03:00
avail_average_lbl - > clear ( ) ;
2009-11-12 10:42:21 +03:00
wasted - > clear ( ) ;
2009-11-08 22:54:22 +03:00
upTotal - > clear ( ) ;
dlTotal - > clear ( ) ;
2009-11-15 13:00:07 +03:00
peersList - > clear ( ) ;
2009-11-12 10:42:21 +03:00
lbl_uplimit - > clear ( ) ;
lbl_dllimit - > clear ( ) ;
lbl_elapsed - > clear ( ) ;
lbl_connections - > clear ( ) ;
2010-05-18 13:35:55 +04:00
reannounce_lbl - > clear ( ) ;
2009-11-08 22:54:22 +03:00
shareRatio - > clear ( ) ;
2009-11-09 14:49:18 +03:00
listWebSeeds - > clear ( ) ;
2011-02-27 17:40:46 +03:00
m_contentFilerLine - > clear ( ) ;
PropListModel - > model ( ) - > clear ( ) ;
2015-06-17 00:11:45 +03:00
label_eta_val - > clear ( ) ;
label_seeds_val - > clear ( ) ;
label_peers_val - > clear ( ) ;
label_dl_speed_val - > clear ( ) ;
label_upload_speed_val - > clear ( ) ;
label_total_size_val - > clear ( ) ;
label_completed_on_val - > clear ( ) ;
label_last_complete_val - > clear ( ) ;
label_created_by_val - > clear ( ) ;
label_added_on_val - > clear ( ) ;
2009-11-08 22:54:22 +03:00
}
2015-04-19 18:17:47 +03:00
BitTorrent : : TorrentHandle * PropertiesWidget : : getCurrentTorrent ( ) const
{
return m_torrent ;
2009-11-15 13:00:07 +03:00
}
2015-04-19 18:17:47 +03:00
void PropertiesWidget : : updateSavePath ( BitTorrent : : TorrentHandle * const torrent )
{
if ( m_torrent = = torrent ) {
2015-07-19 13:07:36 +03:00
save_path - > setText ( m_torrent - > rootPath ( ) ) ;
2009-12-18 19:56:57 +03:00
}
}
2015-04-19 18:17:47 +03:00
void PropertiesWidget : : loadTrackers ( BitTorrent : : TorrentHandle * const torrent )
2015-03-22 01:42:14 +03:00
{
2015-04-19 18:17:47 +03:00
if ( torrent = = m_torrent )
2015-03-22 01:42:14 +03:00
trackerList - > loadTrackers ( ) ;
}
2015-04-19 18:17:47 +03:00
void PropertiesWidget : : updateTorrentInfos ( BitTorrent : : TorrentHandle * const torrent )
{
if ( m_torrent = = torrent )
loadTorrentInfos ( m_torrent ) ;
2010-07-19 22:17:37 +04:00
}
2015-04-19 18:17:47 +03:00
void PropertiesWidget : : loadTorrentInfos ( BitTorrent : : TorrentHandle * const torrent )
2012-08-26 16:00:37 +04:00
{
2009-12-02 23:13:10 +03:00
clear ( ) ;
2015-04-19 18:17:47 +03:00
m_torrent = torrent ;
if ( ! m_torrent ) return ;
2009-11-11 15:22:48 +03:00
2009-11-08 18:41:32 +03:00
// Save path
2015-04-19 18:17:47 +03:00
updateSavePath ( m_torrent ) ;
2009-11-08 18:41:32 +03:00
// Hash
2015-04-19 18:17:47 +03:00
hash_lbl - > setText ( m_torrent - > hash ( ) ) ;
2011-02-27 17:40:46 +03:00
PropListModel - > model ( ) - > clear ( ) ;
2015-04-19 18:17:47 +03:00
if ( m_torrent - > hasMetadata ( ) ) {
2010-10-28 20:22:40 +04:00
// Creation date
2015-06-17 00:11:45 +03:00
lbl_creationDate - > setText ( m_torrent - > creationDate ( ) . toString ( Qt : : DefaultLocaleShortDate ) ) ;
label_total_size_val - > setText ( Utils : : Misc : : friendlyUnit ( m_torrent - > totalSize ( ) ) ) ;
2010-10-28 20:22:40 +04:00
// Comment
2015-06-21 08:44:06 +03:00
comment_text - > setText ( Utils : : Misc : : parseHtmlLinks ( m_torrent - > comment ( ) ) ) ;
2015-06-17 00:11:45 +03:00
2010-10-28 20:22:40 +04:00
// URL seeds
loadUrlSeeds ( ) ;
2015-06-17 00:11:45 +03:00
label_created_by_val - > setText ( m_torrent - > creator ( ) ) ;
2010-10-28 20:22:40 +04:00
// List files in torrent
2015-04-19 18:17:47 +03:00
PropListModel - > model ( ) - > setupModelData ( m_torrent - > info ( ) ) ;
2012-07-02 20:27:39 +04:00
filesList - > setExpanded ( PropListModel - > index ( 0 , 0 ) , true ) ;
2015-06-17 00:11:45 +03:00
2012-08-26 21:59:51 +04:00
// Load file priorities
2015-04-19 18:17:47 +03:00
PropListModel - > model ( ) - > updateFilesPriorities ( m_torrent - > filePriorities ( ) ) ;
2010-10-28 20:22:40 +04:00
}
2009-11-08 18:41:32 +03:00
// Load dynamic data
loadDynamicData ( ) ;
}
2009-11-08 17:20:58 +03:00
2009-11-09 22:30:13 +03:00
void PropertiesWidget : : readSettings ( ) {
2014-07-05 16:44:13 +04:00
const Preferences * const pref = Preferences : : instance ( ) ;
2009-11-11 19:22:57 +03:00
// Restore splitter sizes
2014-07-05 16:44:13 +04:00
QStringList sizes_str = pref - > getPropSplitterSizes ( ) . split ( " , " ) ;
2012-02-20 21:30:53 +04:00
if ( sizes_str . size ( ) = = 2 ) {
2009-11-11 19:22:57 +03:00
slideSizes < < sizes_str . first ( ) . toInt ( ) ;
slideSizes < < sizes_str . last ( ) . toInt ( ) ;
QSplitter * hSplitter = static_cast < QSplitter * > ( parentWidget ( ) ) ;
hSplitter - > setSizes ( slideSizes ) ;
}
2014-12-22 01:25:05 +03:00
const int current_tab = pref - > getPropCurTab ( ) ;
const bool visible = pref - > getPropVisible ( ) ;
// the following will call saveSettings but shouldn't change any state
2014-07-05 16:44:13 +04:00
if ( ! filesList - > header ( ) - > restoreState ( pref - > getPropFileListState ( ) ) ) {
2011-06-05 20:08:30 +04:00
filesList - > header ( ) - > resizeSection ( 0 , 400 ) ; //Default
}
2011-01-22 22:39:43 +03:00
m_tabBar - > setCurrentIndex ( current_tab ) ;
2014-12-22 01:25:05 +03:00
if ( ! visible ) {
2010-10-22 22:59:18 +04:00
setVisibility ( false ) ;
2009-11-11 19:22:57 +03:00
}
2009-11-09 22:30:13 +03:00
}
void PropertiesWidget : : saveSettings ( ) {
2014-07-05 16:44:13 +04:00
Preferences * const pref = Preferences : : instance ( ) ;
pref - > setPropVisible ( state = = VISIBLE ) ;
2009-11-15 11:40:26 +03:00
// Splitter sizes
2009-11-11 19:22:57 +03:00
QSplitter * hSplitter = static_cast < QSplitter * > ( parentWidget ( ) ) ;
QList < int > sizes ;
2012-02-20 21:30:53 +04:00
if ( state = = VISIBLE )
2009-11-11 19:22:57 +03:00
sizes = hSplitter - > sizes ( ) ;
else
sizes = slideSizes ;
qDebug ( " Sizes: %d " , sizes . size ( ) ) ;
2012-02-20 21:30:53 +04:00
if ( sizes . size ( ) = = 2 ) {
2015-06-17 00:11:45 +03:00
pref - > setPropSplitterSizes ( QString : : number ( sizes . first ( ) ) + ' , ' + QString : : number ( sizes . last ( ) ) ) ;
2009-11-11 19:22:57 +03:00
}
2014-07-05 16:44:13 +04:00
pref - > setPropFileListState ( filesList - > header ( ) - > saveState ( ) ) ;
2010-10-22 21:30:17 +04:00
// Remember current tab
2014-07-05 16:44:13 +04:00
pref - > setPropCurTab ( m_tabBar - > currentIndex ( ) ) ;
2009-11-09 22:30:13 +03:00
}
2009-11-15 13:00:07 +03:00
void PropertiesWidget : : reloadPreferences ( ) {
// Take program preferences into consideration
peersList - > updatePeerHostNameResolutionState ( ) ;
2009-11-15 15:57:25 +03:00
peersList - > updatePeerCountryResolutionState ( ) ;
2009-11-12 22:44:47 +03:00
}
2009-11-08 18:41:32 +03:00
void PropertiesWidget : : loadDynamicData ( ) {
2015-06-17 00:11:45 +03:00
// Refresh only if the torrent handle is valid and if visible
if ( ! m_torrent | | ( main_window - > getCurrentTabWidget ( ) ! = transferList ) | | ( state ! = VISIBLE ) ) return ;
2015-04-19 18:17:47 +03:00
2009-11-12 10:42:21 +03:00
// Transfer infos
2015-06-17 00:11:45 +03:00
switch ( stackedProperties - > currentIndex ( ) ) {
case PropTabBar : : MAIN_TAB : {
wasted - > setText ( Utils : : Misc : : friendlyUnit ( m_torrent - > wastedSize ( ) ) ) ;
upTotal - > setText ( Utils : : Misc : : friendlyUnit ( m_torrent - > totalUpload ( ) ) + " ( " + Utils : : Misc : : friendlyUnit ( m_torrent - > totalPayloadUpload ( ) ) + " " + tr ( " this session " ) + " ) " ) ;
dlTotal - > setText ( Utils : : Misc : : friendlyUnit ( m_torrent - > totalDownload ( ) ) + " ( " + Utils : : Misc : : friendlyUnit ( m_torrent - > totalPayloadDownload ( ) ) + " " + tr ( " this session " ) + " ) " ) ;
2015-06-15 12:36:14 +03:00
lbl_uplimit - > setText ( m_torrent - > uploadLimit ( ) < = 0 ? QString : : fromUtf8 ( C_INFINITY ) : Utils : : Misc : : friendlyUnit ( m_torrent - > uploadLimit ( ) ) + tr ( " /s " , " /second (i.e. per second) " ) ) ;
lbl_dllimit - > setText ( m_torrent - > downloadLimit ( ) < = 0 ? QString : : fromUtf8 ( C_INFINITY ) : Utils : : Misc : : friendlyUnit ( m_torrent - > downloadLimit ( ) ) + tr ( " /s " , " /second (i.e. per second) " ) ) ;
2015-06-17 00:11:45 +03:00
QString elapsed_txt = Utils : : Misc : : userFriendlyDuration ( m_torrent - > activeTime ( ) ) ;
if ( m_torrent - > isSeed ( ) )
elapsed_txt + = " ( " + tr ( " Seeded for %1 " , " e.g. Seeded for 3m10s " ) . arg ( Utils : : Misc : : userFriendlyDuration ( m_torrent - > seedingTime ( ) ) ) + " ) " ;
lbl_elapsed - > setText ( elapsed_txt ) ;
2015-06-28 13:15:17 +03:00
lbl_connections - > setText ( QString : : number ( m_torrent - > connectionsCount ( ) ) + " ( " + tr ( " %1 max " , " e.g. 10 max " ) . arg ( QString : : number ( m_torrent - > connectionsLimit ( ) ) ) + " ) " ) ;
2015-06-17 00:11:45 +03:00
label_eta_val - > setText ( Utils : : Misc : : userFriendlyDuration ( m_torrent - > eta ( ) ) ) ;
// Update next announce time
reannounce_lbl - > setText ( Utils : : Misc : : userFriendlyDuration ( m_torrent - > nextAnnounce ( ) ) ) ;
// Update ratio info
const qreal ratio = m_torrent - > realRatio ( ) ;
2015-06-15 12:36:14 +03:00
shareRatio - > setText ( ratio > BitTorrent : : TorrentHandle : : MAX_RATIO ? QString : : fromUtf8 ( C_INFINITY ) : Utils : : String : : fromDouble ( ratio , 2 ) ) ;
2015-06-17 00:11:45 +03:00
label_seeds_val - > setText ( QString : : number ( m_torrent - > seedsCount ( ) ) + " " + tr ( " (%1 total) " , " e.g. (10 total) " ) . arg ( QString : : number ( m_torrent - > totalSeedsCount ( ) ) ) ) ;
label_peers_val - > setText ( QString : : number ( m_torrent - > leechsCount ( ) ) + " " + tr ( " (%1 total) " , " e.g. (10 total) " ) . arg ( QString : : number ( m_torrent - > totalLeechersCount ( ) ) ) ) ;
label_dl_speed_val - > setText ( Utils : : Misc : : friendlyUnit ( m_torrent - > downloadPayloadRate ( ) ) + tr ( " /s " , " /second (i.e. per second) " ) + " "
+ tr ( " (%1/s avg.) " , " e.g. (100KiB/s avg.) " ) . arg ( Utils : : Misc : : friendlyUnit ( m_torrent - > totalDownload ( ) / ( 1 + m_torrent - > activeTime ( ) - m_torrent - > finishedTime ( ) ) ) ) ) ;
label_upload_speed_val - > setText ( Utils : : Misc : : friendlyUnit ( m_torrent - > uploadPayloadRate ( ) ) + tr ( " /s " , " /second (i.e. per second) " ) + " "
+ tr ( " (%1/s avg.) " , " e.g. (100KiB/s avg.) " ) . arg ( Utils : : Misc : : friendlyUnit ( m_torrent - > totalUpload ( ) / ( 1 + m_torrent - > activeTime ( ) ) ) ) ) ;
label_last_complete_val - > setText ( m_torrent - > lastSeenComplete ( ) . isValid ( ) ? m_torrent - > lastSeenComplete ( ) . toString ( Qt : : DefaultLocaleShortDate ) : tr ( " Never " ) ) ;
label_completed_on_val - > setText ( m_torrent - > completedTime ( ) . isValid ( ) ? m_torrent - > completedTime ( ) . toString ( Qt : : DefaultLocaleShortDate ) : " " ) ;
label_added_on_val - > setText ( m_torrent - > addedTime ( ) . toString ( Qt : : DefaultLocaleShortDate ) ) ;
if ( m_torrent - > hasMetadata ( ) ) {
label_total_pieces_val - > setText ( tr ( " %1 x %2 (have %3) " , " (torrent pieces) eg 152 x 4MB (have 25) " ) . arg ( m_torrent - > piecesCount ( ) ) . arg ( Utils : : Misc : : friendlyUnit ( m_torrent - > pieceLength ( ) ) ) . arg ( m_torrent - > piecesHave ( ) ) ) ;
if ( ! m_torrent - > isSeed ( ) & & ! m_torrent - > isPaused ( ) & & ! m_torrent - > isQueued ( ) & & ! m_torrent - > isChecking ( ) ) {
// Pieces availability
showPiecesAvailability ( true ) ;
pieces_availability - > setAvailability ( m_torrent - > pieceAvailability ( ) ) ;
avail_average_lbl - > setText ( Utils : : String : : fromDouble ( m_torrent - > distributedCopies ( ) , 3 ) ) ;
}
else {
showPiecesAvailability ( false ) ;
}
// Progress
qreal progress = m_torrent - > progress ( ) * 100. ;
progress_lbl - > setText ( Utils : : String : : fromDouble ( progress , 1 ) + " % " ) ;
downloaded_pieces - > setProgress ( m_torrent - > pieces ( ) , m_torrent - > downloadingPieces ( ) ) ;
2009-12-02 23:13:10 +03:00
}
2015-06-17 00:11:45 +03:00
else {
showPiecesAvailability ( false ) ;
}
return ;
}
case PropTabBar : : TRACKERS_TAB : {
// Trackers
trackerList - > loadTrackers ( ) ;
return ;
2009-11-15 16:10:31 +03:00
}
2015-06-17 00:11:45 +03:00
case PropTabBar : : PEERS_TAB : {
// Load peers
peersList - > loadPeers ( m_torrent ) ;
return ;
2009-11-19 14:09:03 +03:00
}
2015-06-17 00:11:45 +03:00
case PropTabBar : : FILES_TAB : {
// Files progress
if ( m_torrent - > hasMetadata ( ) ) {
qDebug ( " Updating priorities in files tab " ) ;
filesList - > setUpdatesEnabled ( false ) ;
PropListModel - > model ( ) - > updateFilesProgress ( m_torrent - > filesProgress ( ) ) ;
// XXX: We don't update file priorities regularly for performance
// reasons. This means that priorities will not be updated if
// set from the Web UI.
// PropListModel->model()->updateFilesPriorities(h.file_priorities());
filesList - > setUpdatesEnabled ( true ) ;
}
2009-11-15 16:10:31 +03:00
}
2015-06-17 00:11:45 +03:00
default :
return ;
2009-11-08 18:41:32 +03:00
}
2009-11-08 17:20:58 +03:00
}
2009-11-08 18:50:00 +03:00
2012-02-20 21:56:07 +04:00
void PropertiesWidget : : loadUrlSeeds ( ) {
2009-11-08 23:23:02 +03:00
listWebSeeds - > clear ( ) ;
2010-01-27 23:34:53 +03:00
qDebug ( " Loading URL seeds " ) ;
2015-04-19 18:17:47 +03:00
const QList < QUrl > hc_seeds = m_torrent - > urlSeeds ( ) ;
2010-01-27 23:34:53 +03:00
// Add url seeds
2015-04-19 18:17:47 +03:00
foreach ( const QUrl & hc_seed , hc_seeds ) {
qDebug ( " Loading URL seed: %s " , qPrintable ( hc_seed . toString ( ) ) ) ;
new QListWidgetItem ( hc_seed . toString ( ) , listWebSeeds ) ;
2009-11-08 23:23:02 +03:00
}
}
2014-08-15 13:50:42 +04:00
void PropertiesWidget : : openDoubleClickedFile ( const QModelIndex & index ) {
2012-02-20 21:30:53 +04:00
if ( ! index . isValid ( ) ) return ;
2015-04-19 18:17:47 +03:00
if ( ! m_torrent | | ! m_torrent - > hasMetadata ( ) ) return ;
2014-08-15 13:50:42 +04:00
if ( PropListModel - > itemType ( index ) = = TorrentContentModelItem : : FileType )
openFile ( index ) ;
else
openFolder ( index , false ) ;
}
void PropertiesWidget : : openFile ( const QModelIndex & index ) {
int i = PropListModel - > getFileIndex ( index ) ;
2015-04-19 18:17:47 +03:00
const QDir saveDir ( m_torrent - > actualSavePath ( ) ) ;
const QString filename = m_torrent - > filePath ( i ) ;
2015-05-06 14:53:27 +03:00
const QString file_path = Utils : : Fs : : expandPath ( saveDir . absoluteFilePath ( filename ) ) ;
2014-08-15 13:50:42 +04:00
qDebug ( " Trying to open file at %s " , qPrintable ( file_path ) ) ;
// Flush data
2015-04-19 18:17:47 +03:00
m_torrent - > flushCache ( ) ;
2014-08-15 13:50:42 +04:00
if ( QFile : : exists ( file_path ) ) {
2014-10-05 17:34:58 +04:00
if ( file_path . startsWith ( " // " ) )
2015-05-06 14:53:27 +03:00
QDesktopServices : : openUrl ( Utils : : Fs : : toNativePath ( " file: " + file_path ) ) ;
2014-10-05 17:34:58 +04:00
else
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( file_path ) ) ;
2014-08-15 13:50:42 +04:00
}
else {
QMessageBox : : warning ( this , tr ( " I/O Error " ) , tr ( " This file does not exist yet. " ) ) ;
}
}
void PropertiesWidget : : openFolder ( const QModelIndex & index , bool containing_folder ) {
2014-12-20 20:08:59 +03:00
QString absolute_path ;
2014-08-15 13:50:42 +04:00
// FOLDER
2014-12-20 20:08:59 +03:00
if ( PropListModel - > itemType ( index ) = = TorrentContentModelItem : : FolderType ) {
// Generate relative path to selected folder
QStringList path_items ;
path_items < < index . data ( ) . toString ( ) ;
QModelIndex parent = PropListModel - > parent ( index ) ;
while ( parent . isValid ( ) ) {
path_items . prepend ( parent . data ( ) . toString ( ) ) ;
parent = PropListModel - > parent ( parent ) ;
}
if ( path_items . isEmpty ( ) )
return ;
# if !(defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)))
if ( containing_folder )
path_items . removeLast ( ) ;
# endif
2015-04-19 18:17:47 +03:00
const QDir saveDir ( m_torrent - > actualSavePath ( ) ) ;
2014-12-20 20:08:59 +03:00
const QString relative_path = path_items . join ( " / " ) ;
2015-05-06 14:53:27 +03:00
absolute_path = Utils : : Fs : : expandPath ( saveDir . absoluteFilePath ( relative_path ) ) ;
2014-12-20 20:08:59 +03:00
}
else {
2015-04-19 18:17:47 +03:00
int i = PropListModel - > getFileIndex ( index ) ;
const QDir saveDir ( m_torrent - > actualSavePath ( ) ) ;
const QString relative_path = m_torrent - > filePath ( i ) ;
2015-05-06 14:53:27 +03:00
absolute_path = Utils : : Fs : : expandPath ( saveDir . absoluteFilePath ( relative_path ) ) ;
2013-07-04 14:49:28 +04:00
2014-10-25 19:59:25 +04:00
# if !(defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)))
2015-04-19 18:17:47 +03:00
if ( containing_folder )
2015-05-06 14:53:27 +03:00
absolute_path = Utils : : Fs : : folderName ( absolute_path ) ;
2013-07-04 14:49:28 +04:00
# endif
2014-12-20 20:08:59 +03:00
}
2013-07-04 14:49:28 +04:00
2014-08-15 13:50:42 +04:00
// Flush data
2015-04-19 18:17:47 +03:00
m_torrent - > flushCache ( ) ;
2014-12-20 20:08:59 +03:00
if ( ! QFile : : exists ( absolute_path ) )
2014-12-20 18:40:06 +03:00
return ;
2014-12-20 20:08:59 +03:00
qDebug ( " Trying to open folder at %s " , qPrintable ( absolute_path ) ) ;
2014-12-16 01:00:00 +03:00
2013-07-04 14:49:28 +04:00
# ifdef Q_OS_WIN
if ( containing_folder ) {
// Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select"
// Dir separators MUST be win-style slashes
2015-05-06 14:53:27 +03:00
QProcess : : startDetached ( " explorer.exe " , QStringList ( ) < < " /select, " < < Utils : : Fs : : toNativePath ( absolute_path ) ) ;
2010-01-07 23:48:52 +03:00
} else {
2014-10-25 19:59:25 +04:00
# elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
if ( containing_folder ) {
QProcess proc ;
QString output ;
proc . start ( " xdg-mime " , QStringList ( ) < < " query " < < " default " < < " inode/directory " ) ;
proc . waitForFinished ( ) ;
output = proc . readLine ( ) . simplified ( ) ;
if ( output = = " dolphin.desktop " )
2015-05-06 14:53:27 +03:00
proc . startDetached ( " dolphin " , QStringList ( ) < < " --select " < < Utils : : Fs : : toNativePath ( absolute_path ) ) ;
2014-10-25 19:59:25 +04:00
else if ( output = = " nautilus-folder-handler.desktop " )
2015-05-06 14:53:27 +03:00
proc . startDetached ( " nautilus " , QStringList ( ) < < " --no-desktop " < < Utils : : Fs : : toNativePath ( absolute_path ) ) ;
2014-10-25 19:59:25 +04:00
else if ( output = = " kfmclient_dir.desktop " )
2015-05-06 14:53:27 +03:00
proc . startDetached ( " konqueror " , QStringList ( ) < < " --select " < < Utils : : Fs : : toNativePath ( absolute_path ) ) ;
2014-10-25 19:59:25 +04:00
else
2014-12-20 20:08:59 +03:00
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( QFileInfo ( absolute_path ) . absolutePath ( ) ) ) ;
2014-10-25 19:59:25 +04:00
} else {
2013-07-04 14:49:28 +04:00
# endif
2014-12-20 20:08:59 +03:00
if ( QFile : : exists ( absolute_path ) ) {
2013-07-04 14:49:28 +04:00
// Hack to access samba shares with QDesktopServices::openUrl
2014-12-20 20:08:59 +03:00
if ( absolute_path . startsWith ( " // " ) )
2015-05-06 14:53:27 +03:00
QDesktopServices : : openUrl ( Utils : : Fs : : toNativePath ( " file: " + absolute_path ) ) ;
2014-10-05 17:34:58 +04:00
else
2014-12-20 20:08:59 +03:00
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( absolute_path ) ) ;
2013-07-04 14:49:28 +04:00
} else {
QMessageBox : : warning ( this , tr ( " I/O Error " ) , tr ( " This folder does not exist yet. " ) ) ;
}
2014-10-25 19:59:25 +04:00
# if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
2010-01-05 23:57:33 +03:00
}
2013-07-04 14:49:28 +04:00
# endif
2010-01-05 23:57:33 +03:00
}
2012-02-20 21:56:07 +04:00
void PropertiesWidget : : displayFilesListMenu ( const QPoint & ) {
2015-04-19 18:17:47 +03:00
if ( ! m_torrent ) return ;
2010-06-06 14:10:45 +04:00
QModelIndexList selectedRows = filesList - > selectionModel ( ) - > selectedRows ( 0 ) ;
2014-09-30 11:23:02 +04:00
if ( selectedRows . empty ( ) )
return ;
QMenu myFilesLlistMenu ;
2014-08-15 13:50:42 +04:00
QAction * actOpen = 0 ;
QAction * actOpenContainingFolder = 0 ;
2009-12-19 17:59:38 +03:00
QAction * actRename = 0 ;
2012-02-20 21:30:53 +04:00
if ( selectedRows . size ( ) = = 1 ) {
2015-04-19 18:17:47 +03:00
actOpen = myFilesLlistMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " folder-documents " ) , tr ( " Open " ) ) ;
actOpenContainingFolder = myFilesLlistMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " inode-directory " ) , tr ( " Open Containing Folder " ) ) ;
actRename = myFilesLlistMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename... " ) ) ;
2010-02-16 23:50:44 +03:00
myFilesLlistMenu . addSeparator ( ) ;
2009-12-19 17:59:38 +03:00
}
2011-01-15 00:18:45 +03:00
QMenu subMenu ;
2015-04-19 18:17:47 +03:00
if ( ! m_torrent - > isSeed ( ) ) {
2011-01-04 19:58:44 +03:00
subMenu . setTitle ( tr ( " Priority " ) ) ;
subMenu . addAction ( actionNot_downloaded ) ;
subMenu . addAction ( actionNormal ) ;
subMenu . addAction ( actionHigh ) ;
subMenu . addAction ( actionMaximum ) ;
myFilesLlistMenu . addMenu ( & subMenu ) ;
}
2009-11-09 11:56:21 +03:00
// Call menu
2010-03-04 21:03:12 +03:00
const QAction * act = myFilesLlistMenu . exec ( QCursor : : pos ( ) ) ;
2015-05-04 02:09:30 +03:00
// The selected torrent might have disappeared during exec()
2014-05-15 21:58:59 +04:00
// from the current view thus leaving invalid indices.
2014-08-15 13:50:42 +04:00
const QModelIndex index = * ( selectedRows . begin ( ) ) ;
if ( ! index . isValid ( ) )
2014-05-15 21:58:59 +04:00
return ;
2012-02-20 21:30:53 +04:00
if ( act ) {
2014-08-15 13:50:42 +04:00
if ( act = = actOpen )
openDoubleClickedFile ( index ) ;
else if ( act = = actOpenContainingFolder )
openFolder ( index , true ) ;
else if ( act = = actRename )
2009-12-19 17:59:38 +03:00
renameSelectedFile ( ) ;
2014-08-15 13:50:42 +04:00
else {
int prio = prio : : NORMAL ;
if ( act = = actionHigh )
2011-01-25 20:26:25 +03:00
prio = prio : : HIGH ;
2014-08-15 13:50:42 +04:00
else if ( act = = actionMaximum )
prio = prio : : MAXIMUM ;
else if ( act = = actionNot_downloaded )
prio = prio : : IGNORED ;
2010-02-16 23:50:44 +03:00
qDebug ( " Setting files priority " ) ;
2012-02-20 21:30:53 +04:00
foreach ( QModelIndex index , selectedRows ) {
2010-02-16 23:50:44 +03:00
qDebug ( " Setting priority(%d) for file at row %d " , prio , index . row ( ) ) ;
PropListModel - > setData ( PropListModel - > index ( index . row ( ) , PRIORITY , index . parent ( ) ) , prio ) ;
}
// Save changes
filteredFilesChanged ( ) ;
2009-12-19 17:59:38 +03:00
}
}
}
2013-02-28 23:00:04 +04:00
void PropertiesWidget : : displayWebSeedListMenu ( const QPoint & ) {
2015-04-19 18:17:47 +03:00
if ( ! m_torrent ) return ;
2013-02-28 23:00:04 +04:00
QMenu seedMenu ;
QModelIndexList rows = listWebSeeds - > selectionModel ( ) - > selectedRows ( ) ;
2015-04-19 18:17:47 +03:00
QAction * actAdd = seedMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " list-add " ) , tr ( " New Web seed " ) ) ;
2013-02-28 23:00:04 +04:00
QAction * actDel = 0 ;
QAction * actCpy = 0 ;
QAction * actEdit = 0 ;
if ( rows . size ( ) ) {
2015-04-19 18:17:47 +03:00
actDel = seedMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Remove Web seed " ) ) ;
2013-02-28 23:00:04 +04:00
seedMenu . addSeparator ( ) ;
2015-04-19 18:17:47 +03:00
actCpy = seedMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-copy " ) , tr ( " Copy Web seed URL " ) ) ;
actEdit = seedMenu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Edit Web seed URL " ) ) ;
2013-02-28 23:00:04 +04:00
}
const QAction * act = seedMenu . exec ( QCursor : : pos ( ) ) ;
if ( act ) {
if ( act = = actAdd )
askWebSeed ( ) ;
else if ( act = = actDel )
deleteSelectedUrlSeeds ( ) ;
else if ( act = = actCpy )
copySelectedWebSeedsToClipboard ( ) ;
else if ( act = = actEdit )
editWebSeed ( ) ;
}
}
2009-12-19 17:59:38 +03:00
void PropertiesWidget : : renameSelectedFile ( ) {
2010-07-23 18:05:53 +04:00
const QModelIndexList selectedIndexes = filesList - > selectionModel ( ) - > selectedRows ( 0 ) ;
2013-07-22 18:39:48 +04:00
if ( selectedIndexes . size ( ) ! = 1 )
return ;
2010-07-23 18:05:53 +04:00
const QModelIndex index = selectedIndexes . first ( ) ;
2014-07-14 23:00:40 +04:00
if ( ! index . isValid ( ) )
return ;
2009-12-19 17:59:38 +03:00
// Ask for new name
bool ok ;
2013-07-22 15:46:10 +04:00
QString new_name_last = AutoExpandableDialog : : getText ( this , tr ( " Rename the file " ) ,
2009-12-19 18:31:50 +03:00
tr ( " New name: " ) , QLineEdit : : Normal ,
2013-02-07 22:46:40 +04:00
index . data ( ) . toString ( ) , & ok ) . trimmed ( ) ;
2009-12-19 17:59:38 +03:00
if ( ok & & ! new_name_last . isEmpty ( ) ) {
2015-05-06 14:53:27 +03:00
if ( ! Utils : : Fs : : isValidFileSystemName ( new_name_last ) ) {
2010-01-05 15:28:42 +03:00
QMessageBox : : warning ( this , tr ( " The file could not be renamed " ) ,
tr ( " This file name contains forbidden characters, please choose a different one. " ) ,
QMessageBox : : Ok ) ;
return ;
}
2012-08-26 19:10:32 +04:00
if ( PropListModel - > itemType ( index ) = = TorrentContentModelItem : : FileType ) {
2009-12-19 18:31:50 +03:00
// File renaming
2010-03-04 21:03:12 +03:00
const int file_index = PropListModel - > getFileIndex ( index ) ;
2015-04-19 18:17:47 +03:00
if ( ! m_torrent | | ! m_torrent - > hasMetadata ( ) ) return ;
QString old_name = m_torrent - > filePath ( file_index ) ;
2012-02-20 21:30:53 +04:00
if ( old_name . endsWith ( " .!qB " ) & & ! new_name_last . endsWith ( " .!qB " ) ) {
2009-12-19 18:31:50 +03:00
new_name_last + = " .!qB " ;
}
2010-06-06 17:58:43 +04:00
QStringList path_items = old_name . split ( " / " ) ;
2009-12-19 18:31:50 +03:00
path_items . removeLast ( ) ;
path_items < < new_name_last ;
2010-06-06 17:58:43 +04:00
QString new_name = path_items . join ( " / " ) ;
2012-02-20 21:30:53 +04:00
if ( old_name = = new_name ) {
2009-12-19 18:31:50 +03:00
qDebug ( " Name did not change " ) ;
2009-12-19 17:59:38 +03:00
return ;
}
2015-05-06 14:53:27 +03:00
new_name = Utils : : Fs : : expandPath ( new_name ) ;
2009-12-19 18:31:50 +03:00
// Check if that name is already used
2015-04-19 18:17:47 +03:00
for ( int i = 0 ; i < m_torrent - > filesCount ( ) ; + + i ) {
2012-02-20 21:30:53 +04:00
if ( i = = file_index ) continue ;
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
2015-04-19 18:17:47 +03:00
if ( m_torrent - > filePath ( i ) . compare ( new_name , Qt : : CaseSensitive ) = = 0 ) {
2009-12-19 18:39:39 +03:00
# else
2015-04-19 18:17:47 +03:00
if ( m_torrent - > filePath ( i ) . compare ( new_name , Qt : : CaseInsensitive ) = = 0 ) {
2009-12-19 18:39:39 +03:00
# endif
2010-12-04 23:47:20 +03:00
// Display error message
QMessageBox : : warning ( this , tr ( " The file could not be renamed " ) ,
tr ( " This name is already in use in this folder. Please use a different name. " ) ,
QMessageBox : : Ok ) ;
return ;
2009-12-19 19:53:27 +03:00
}
2010-12-04 23:47:20 +03:00
}
2015-04-19 18:17:47 +03:00
const bool force_recheck = QFile : : exists ( m_torrent - > actualSavePath ( ) + " / " + new_name ) ;
2010-12-04 23:47:20 +03:00
qDebug ( " Renaming %s to %s " , qPrintable ( old_name ) , qPrintable ( new_name ) ) ;
2015-04-19 18:17:47 +03:00
m_torrent - > renameFile ( file_index , new_name ) ;
2010-12-04 23:47:20 +03:00
// Force recheck
2015-04-19 18:17:47 +03:00
if ( force_recheck ) m_torrent - > forceRecheck ( ) ;
2010-12-04 23:47:20 +03:00
// Rename if torrent files model too
2012-02-20 21:30:53 +04:00
if ( new_name_last . endsWith ( " .!qB " ) )
2010-12-04 23:47:20 +03:00
new_name_last . chop ( 4 ) ;
PropListModel - > setData ( index , new_name_last ) ;
} else {
// Folder renaming
QStringList path_items ;
path_items < < index . data ( ) . toString ( ) ;
QModelIndex parent = PropListModel - > parent ( index ) ;
while ( parent . isValid ( ) ) {
path_items . prepend ( parent . data ( ) . toString ( ) ) ;
parent = PropListModel - > parent ( parent ) ;
}
const QString old_path = path_items . join ( " / " ) ;
path_items . removeLast ( ) ;
path_items < < new_name_last ;
QString new_path = path_items . join ( " / " ) ;
2012-02-20 21:30:53 +04:00
if ( ! new_path . endsWith ( " / " ) ) new_path + = " / " ;
2010-12-04 23:47:20 +03:00
// Check for overwriting
2015-04-19 18:17:47 +03:00
const int num_files = m_torrent - > filesCount ( ) ;
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < num_files ; + + i ) {
2015-04-19 18:17:47 +03:00
const QString current_name = m_torrent - > filePath ( i ) ;
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
2012-02-20 21:30:53 +04:00
if ( current_name . startsWith ( new_path , Qt : : CaseSensitive ) ) {
2009-12-19 18:39:39 +03:00
# else
2012-02-20 21:30:53 +04:00
if ( current_name . startsWith ( new_path , Qt : : CaseInsensitive ) ) {
2009-12-19 18:39:39 +03:00
# endif
2010-12-04 23:47:20 +03:00
QMessageBox : : 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 ;
2009-12-19 18:39:39 +03:00
}
}
2010-12-04 23:47:20 +03:00
bool force_recheck = false ;
// Replace path in all files
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < num_files ; + + i ) {
2015-04-19 18:17:47 +03:00
const QString current_name = m_torrent - > filePath ( i ) ;
2012-02-20 21:30:53 +04:00
if ( current_name . startsWith ( old_path ) ) {
2010-12-04 23:47:20 +03:00
QString new_name = current_name ;
new_name . replace ( 0 , old_path . length ( ) , new_path ) ;
2015-04-19 18:17:47 +03:00
if ( ! force_recheck & & QDir ( m_torrent - > actualSavePath ( ) ) . exists ( new_name ) )
2010-12-04 23:47:20 +03:00
force_recheck = true ;
2015-05-06 14:53:27 +03:00
new_name = Utils : : Fs : : expandPath ( new_name ) ;
2010-12-04 23:47:20 +03:00
qDebug ( " Rename %s to %s " , qPrintable ( current_name ) , qPrintable ( new_name ) ) ;
2015-04-19 18:17:47 +03:00
m_torrent - > renameFile ( i , new_name ) ;
2010-12-04 23:47:20 +03:00
}
2009-12-19 19:53:27 +03:00
}
2010-12-04 23:47:20 +03:00
// Force recheck
2015-04-19 18:17:47 +03:00
if ( force_recheck ) m_torrent - > forceRecheck ( ) ;
2010-12-04 23:47:20 +03:00
// Rename folder in torrent files model too
PropListModel - > setData ( index , new_name_last ) ;
// Remove old folder
2015-04-19 18:17:47 +03:00
const QDir old_folder ( m_torrent - > actualSavePath ( ) + " / " + old_path ) ;
2010-12-04 23:47:20 +03:00
int timeout = 10 ;
2010-12-29 23:29:55 +03:00
while ( ! QDir ( ) . rmpath ( old_folder . absolutePath ( ) ) & & timeout > 0 ) {
2015-05-06 14:53:27 +03:00
// FIXME: We should not sleep here (freezes the UI for 1 second)
Utils : : Misc : : msleep ( 100 ) ;
2010-12-04 23:47:20 +03:00
- - timeout ;
2009-12-19 19:53:27 +03:00
}
}
2010-12-04 23:47:20 +03:00
}
}
2009-11-09 11:56:21 +03:00
2015-04-16 19:36:53 +03:00
void PropertiesWidget : : openSelectedFile ( ) {
const QModelIndexList selectedIndexes = filesList - > selectionModel ( ) - > selectedRows ( 0 ) ;
if ( selectedIndexes . size ( ) ! = 1 )
return ;
openDoubleClickedFile ( selectedIndexes . first ( ) ) ;
}
2012-02-20 21:56:07 +04:00
void PropertiesWidget : : askWebSeed ( ) {
2010-12-04 23:47:20 +03:00
bool ok ;
// Ask user for a new url seed
2015-03-30 14:15:48 +03:00
const QString url_seed = AutoExpandableDialog : : getText ( this , tr ( " New URL seed " , " New HTTP source " ) ,
tr ( " New URL seed: " ) , QLineEdit : : Normal ,
2010-12-04 23:47:20 +03:00
QString : : fromUtf8 ( " http://www. " ) , & ok ) ;
2012-02-20 21:30:53 +04:00
if ( ! ok ) return ;
2010-12-04 23:47:20 +03:00
qDebug ( " Adding %s web seed " , qPrintable ( url_seed ) ) ;
2012-02-20 21:30:53 +04:00
if ( ! listWebSeeds - > findItems ( url_seed , Qt : : MatchFixedString ) . empty ( ) ) {
2013-07-03 11:35:02 +04:00
QMessageBox : : warning ( this , " qBittorrent " ,
2015-03-30 14:15:48 +03:00
tr ( " This URL seed is already in the list. " ) ,
2010-12-04 23:47:20 +03:00
QMessageBox : : Ok ) ;
return ;
}
2015-04-19 18:17:47 +03:00
if ( m_torrent )
m_torrent - > addUrlSeeds ( QList < QUrl > ( ) < < url_seed ) ;
2010-12-04 23:47:20 +03:00
// Refresh the seeds list
loadUrlSeeds ( ) ;
}
2012-02-20 21:56:07 +04:00
void PropertiesWidget : : deleteSelectedUrlSeeds ( ) {
2010-12-04 23:47:20 +03:00
const QList < QListWidgetItem * > selectedItems = listWebSeeds - > selectedItems ( ) ;
2015-04-19 18:17:47 +03:00
if ( selectedItems . isEmpty ( ) ) return ;
QList < QUrl > urlSeeds ;
foreach ( const QListWidgetItem * item , selectedItems )
urlSeeds < < item - > text ( ) ;
m_torrent - > removeUrlSeeds ( urlSeeds ) ;
// Refresh list
loadUrlSeeds ( ) ;
2010-12-04 23:47:20 +03:00
}
2009-11-09 21:01:54 +03:00
2013-02-28 23:00:04 +04:00
void PropertiesWidget : : copySelectedWebSeedsToClipboard ( ) const {
const QList < QListWidgetItem * > selected_items = listWebSeeds - > selectedItems ( ) ;
if ( selected_items . isEmpty ( ) )
return ;
QStringList urls_to_copy ;
foreach ( QListWidgetItem * item , selected_items )
urls_to_copy < < item - > text ( ) ;
QApplication : : clipboard ( ) - > setText ( urls_to_copy . join ( " \n " ) ) ;
}
void PropertiesWidget : : editWebSeed ( ) {
const QList < QListWidgetItem * > selected_items = listWebSeeds - > selectedItems ( ) ;
2013-07-22 21:48:55 +04:00
if ( selected_items . size ( ) ! = 1 )
2013-02-28 23:00:04 +04:00
return ;
const QListWidgetItem * selected_item = selected_items . last ( ) ;
const QString old_seed = selected_item - > text ( ) ;
bool result ;
2013-07-22 15:46:10 +04:00
const QString new_seed = AutoExpandableDialog : : getText ( this , tr ( " Web seed editing " ) ,
2013-02-28 23:00:04 +04:00
tr ( " Web seed URL: " ) , QLineEdit : : Normal ,
old_seed , & result ) ;
if ( ! result )
return ;
if ( ! listWebSeeds - > findItems ( new_seed , Qt : : MatchFixedString ) . empty ( ) ) {
QMessageBox : : warning ( this , tr ( " qBittorrent " ) ,
2015-03-30 14:15:48 +03:00
tr ( " This URL seed is already in the list. " ) ,
2013-02-28 23:00:04 +04:00
QMessageBox : : Ok ) ;
return ;
}
2015-04-19 18:17:47 +03:00
m_torrent - > removeUrlSeeds ( QList < QUrl > ( ) < < old_seed ) ;
m_torrent - > addUrlSeeds ( QList < QUrl > ( ) < < new_seed ) ;
loadUrlSeeds ( ) ;
2013-02-28 23:00:04 +04:00
}
2010-12-04 23:47:20 +03:00
bool PropertiesWidget : : applyPriorities ( ) {
qDebug ( " Saving files priorities " ) ;
2015-04-19 18:17:47 +03:00
const QVector < int > priorities = PropListModel - > model ( ) - > getFilePriorities ( ) ;
2010-12-04 23:47:20 +03:00
// Save first/last piece first option state
2015-04-19 18:17:47 +03:00
bool first_last_piece_first = m_torrent - > hasFirstLastPiecePriority ( ) ;
2010-12-04 23:47:20 +03:00
// Prioritize the files
qDebug ( " prioritize files: %d " , priorities [ 0 ] ) ;
2015-04-19 18:17:47 +03:00
m_torrent - > prioritizeFiles ( priorities ) ;
2010-12-04 23:47:20 +03:00
// Restore first/last piece first option if necessary
2012-02-20 21:30:53 +04:00
if ( first_last_piece_first )
2015-04-19 18:17:47 +03:00
m_torrent - > setFirstLastPiecePriority ( true ) ;
2010-12-04 23:47:20 +03:00
return true ;
}
2009-11-09 21:01:54 +03:00
2010-12-04 23:47:20 +03:00
void PropertiesWidget : : filteredFilesChanged ( ) {
2015-04-19 18:17:47 +03:00
if ( m_torrent )
2010-12-04 23:47:20 +03:00
applyPriorities ( ) ;
}
2013-11-10 05:59:53 +04:00
void PropertiesWidget : : filterText ( const QString & filter ) {
PropListModel - > setFilterFixedString ( filter ) ;
if ( filter . isEmpty ( ) ) {
filesList - > collapseAll ( ) ;
filesList - > expand ( PropListModel - > index ( 0 , 0 ) ) ;
}
else
filesList - > expandAll ( ) ;
}