2006-09-30 16:02:39 +00:00
/*
* Bittorrent Client using Qt4 and libtorrent .
2007-07-14 14:31:59 +00:00
* Copyright ( C ) 2006 Christophe Dumez
2006-09-30 16:02:39 +00:00
*
2007-07-14 14:31:59 +00:00
* 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 .
2006-09-30 16:02:39 +00:00
*
* 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
2007-07-14 14:31:59 +00:00
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* Contact : chris @ qbittorrent . org
2006-09-30 16:02:39 +00:00
*/
# include "properties_imp.h"
# include "misc.h"
# include "PropListDelegate.h"
2007-07-23 12:46:36 +00:00
# include "bittorrent.h"
2007-03-24 21:36:22 +00:00
# include <QInputDialog>
2007-05-16 18:55:34 +00:00
# include <QMessageBox>
2007-07-20 13:07:34 +00:00
# include <QMenu>
2007-07-23 12:46:36 +00:00
# include <QTimer>
# include <QStandardItemModel>
2006-09-30 16:02:39 +00:00
// Constructor
2007-07-04 10:06:22 +00:00
properties : : properties ( QWidget * parent , bittorrent * BTSession , torrent_handle & h , QStringList trackerErrors ) : QDialog ( parent ) , h ( h ) {
2006-09-30 16:02:39 +00:00
setupUi ( this ) ;
2007-07-04 10:06:22 +00:00
this - > BTSession = BTSession ;
changedFilteredfiles = false ;
2007-06-15 23:51:10 +00:00
lbl_priorities - > setText ( tr ( " Priorities: " ) + " <ul><li> " + tr ( " Ignored: file is not downloaded at all " ) + " </li><li> " + tr ( " Normal: normal priority. Download order is dependent on availability " ) + " </li><li> " + tr ( " High: higher than normal priority. Pieces are preferred over pieces with the same availability, but not over pieces with lower availability " ) + " </li><li> " + tr ( " Maximum: maximum priority, availability is disregarded, the piece is preferred over any other piece with lower priority " ) + " </li></ul> " ) ;
2006-09-30 16:02:39 +00:00
// set icons
2007-03-24 20:55:15 +00:00
addTracker_button - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/add.png " ) ) ) ;
removeTracker_button - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/remove.png " ) ) ) ;
lowerTracker_button - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/downarrow.png " ) ) ) ;
riseTracker_button - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/uparrow.png " ) ) ) ;
2007-07-27 09:53:55 +00:00
addWS_button - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/add.png " ) ) ) ;
deleteWS_button - > setIcon ( QIcon ( QString : : fromUtf8 ( " :/Icons/skin/remove.png " ) ) ) ;
2006-09-30 16:02:39 +00:00
setAttribute ( Qt : : WA_DeleteOnClose ) ;
// Set Properties list model
PropListModel = new QStandardItemModel ( 0 , 4 ) ;
2007-04-12 19:51:39 +00:00
PropListModel - > setHeaderData ( NAME , Qt : : Horizontal , tr ( " File name " ) ) ;
2006-09-30 16:02:39 +00:00
PropListModel - > setHeaderData ( SIZE , Qt : : Horizontal , tr ( " Size " ) ) ;
PropListModel - > setHeaderData ( PROGRESS , Qt : : Horizontal , tr ( " Progress " ) ) ;
2007-04-12 19:51:39 +00:00
PropListModel - > setHeaderData ( PRIORITY , Qt : : Horizontal , tr ( " Priority " ) ) ;
2006-09-30 16:02:39 +00:00
filesList - > setModel ( PropListModel ) ;
2007-07-04 10:06:22 +00:00
PropDelegate = new PropListDelegate ( 0 , & changedFilteredfiles ) ;
2006-09-30 16:02:39 +00:00
filesList - > setItemDelegate ( PropDelegate ) ;
2007-04-05 15:55:05 +00:00
connect ( filesList , SIGNAL ( clicked ( const QModelIndex & ) ) , filesList , SLOT ( edit ( const QModelIndex & ) ) ) ;
2007-07-20 13:07:34 +00:00
connect ( filesList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayFilesListMenu ( const QPoint & ) ) ) ;
2007-03-24 21:36:22 +00:00
connect ( addTracker_button , SIGNAL ( clicked ( ) ) , this , SLOT ( askForTracker ( ) ) ) ;
2007-03-25 13:45:20 +00:00
connect ( removeTracker_button , SIGNAL ( clicked ( ) ) , this , SLOT ( deleteSelectedTrackers ( ) ) ) ;
2007-03-25 18:39:27 +00:00
connect ( riseTracker_button , SIGNAL ( clicked ( ) ) , this , SLOT ( riseSelectedTracker ( ) ) ) ;
connect ( lowerTracker_button , SIGNAL ( clicked ( ) ) , this , SLOT ( lowerSelectedTracker ( ) ) ) ;
2007-07-20 13:07:34 +00:00
connect ( actionIgnored , SIGNAL ( triggered ( ) ) , this , SLOT ( ignoreSelection ( ) ) ) ;
connect ( actionNormal , SIGNAL ( triggered ( ) ) , this , SLOT ( normalSelection ( ) ) ) ;
connect ( actionHigh , SIGNAL ( triggered ( ) ) , this , SLOT ( highSelection ( ) ) ) ;
connect ( actionMaximum , SIGNAL ( triggered ( ) ) , this , SLOT ( maximumSelection ( ) ) ) ;
2007-07-27 09:53:55 +00:00
connect ( addWS_button , SIGNAL ( clicked ( ) ) , this , SLOT ( askWebSeed ( ) ) ) ;
connect ( deleteWS_button , SIGNAL ( clicked ( ) ) , this , SLOT ( deleteSelectedUrlSeeds ( ) ) ) ;
2006-09-30 16:02:39 +00:00
// get Infos from torrent handle
2007-02-23 22:52:24 +00:00
fileHash = QString ( misc : : toString ( h . info_hash ( ) ) . c_str ( ) ) ;
2006-09-30 16:02:39 +00:00
torrent_status torrentStatus = h . status ( ) ;
torrent_info torrentInfo = h . get_torrent_info ( ) ;
fileName - > setText ( torrentInfo . name ( ) . c_str ( ) ) ;
2007-03-24 17:50:53 +00:00
// Torrent Infos
save_path - > setText ( QString ( h . save_path ( ) . string ( ) . c_str ( ) ) ) ;
2007-07-20 13:07:34 +00:00
QString author = QString ( torrentInfo . creator ( ) . c_str ( ) ) . trimmed ( ) ;
if ( author . isEmpty ( ) )
author = tr ( " Unknown " ) ;
creator - > setText ( author ) ;
2007-03-24 17:50:53 +00:00
hash_lbl - > setText ( fileHash ) ;
comment_txt - > setText ( QString ( torrentInfo . comment ( ) . c_str ( ) ) ) ;
//Trackers
2007-03-24 21:36:22 +00:00
loadTrackers ( ) ;
2007-03-24 17:50:53 +00:00
// Session infos
2006-09-30 16:02:39 +00:00
char tmp [ MAX_CHAR_TMP ] ;
failed - > setText ( misc : : friendlyUnit ( torrentStatus . total_failed_bytes ) ) ;
upTotal - > setText ( misc : : friendlyUnit ( torrentStatus . total_payload_upload ) ) ;
dlTotal - > setText ( misc : : friendlyUnit ( torrentStatus . total_payload_download ) ) ;
// Update ratio info
2007-07-18 07:44:52 +00:00
float ratio ;
if ( torrentStatus . total_payload_download = = 0 ) {
if ( torrentStatus . total_payload_upload = = 0 )
ratio = 1. ;
else
ratio = 10. ; // Max ratio
2006-09-30 16:02:39 +00:00
} else {
ratio = ( float ) torrentStatus . total_payload_upload / ( float ) torrentStatus . total_payload_download ;
if ( ratio > 10. ) {
ratio = 10. ;
}
}
2007-07-18 07:44:52 +00:00
snprintf ( tmp , MAX_CHAR_TMP , " %.1f " , ratio ) ;
shareRatio - > setText ( tmp ) ;
2006-09-30 16:02:39 +00:00
// Tracker Errors
for ( int i = 0 ; i < trackerErrors . size ( ) ; + + i ) {
this - > trackerErrors - > append ( trackerErrors . at ( i ) ) ;
}
std : : vector < float > fp ;
h . file_progress ( fp ) ;
// List files in torrent
2007-04-12 20:22:42 +00:00
unsigned int nbFiles = torrentInfo . num_files ( ) ;
for ( unsigned int i = 0 ; i < nbFiles ; + + i ) {
unsigned int row = PropListModel - > rowCount ( ) ;
2006-09-30 16:02:39 +00:00
PropListModel - > insertRow ( row ) ;
PropListModel - > setData ( PropListModel - > index ( row , NAME ) , QVariant ( torrentInfo . file_at ( i ) . path . leaf ( ) . c_str ( ) ) ) ;
PropListModel - > setData ( PropListModel - > index ( row , SIZE ) , QVariant ( ( qlonglong ) torrentInfo . file_at ( i ) . size ) ) ;
PropListModel - > setData ( PropListModel - > index ( row , PROGRESS ) , QVariant ( ( double ) fp [ i ] ) ) ;
}
2007-04-12 19:51:39 +00:00
loadPiecesPriorities ( ) ;
2007-07-27 09:53:55 +00:00
// List web seeds
loadWebSeedsFromFile ( ) ;
loadWebSeeds ( ) ;
2006-09-30 16:02:39 +00:00
// Incremental download
2007-02-23 22:52:24 +00:00
if ( QFile : : exists ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + fileHash + " .incremental " ) ) {
2006-09-30 16:02:39 +00:00
incrementalDownload - > setChecked ( true ) ;
} else {
incrementalDownload - > setChecked ( false ) ;
}
2006-10-06 18:07:01 +00:00
updateProgressTimer = new QTimer ( this ) ;
connect ( updateProgressTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateProgress ( ) ) ) ;
updateProgressTimer - > start ( 2000 ) ;
}
properties : : ~ properties ( ) {
2007-03-07 22:36:01 +00:00
qDebug ( " Properties destroyed " ) ;
2006-10-06 18:07:01 +00:00
delete updateProgressTimer ;
delete PropDelegate ;
delete PropListModel ;
}
2007-07-27 09:53:55 +00:00
void properties : : loadWebSeeds ( ) {
QString url_seed ;
torrent_info torrentInfo = h . get_torrent_info ( ) ;
std : : vector < std : : string > url_seeds = torrentInfo . url_seeds ( ) ;
unsigned int nbSeeds = url_seeds . size ( ) ;
// Clear url seeds list
listWebSeeds - > clear ( ) ;
// Add hard coded url seeds
for ( unsigned int i = 0 ; i < nbSeeds ; + + i ) {
url_seed = QString ( url_seeds [ i ] . c_str ( ) ) ;
if ( manualUrlSeeds . indexOf ( url_seed ) = = - 1 )
qDebug ( " Added hard-coded url seed to list: %s " , ( const char * ) url_seed . toUtf8 ( ) ) ;
listWebSeeds - > addItem ( url_seed ) ;
}
// Add manually added url seeds
foreach ( url_seed , manualUrlSeeds ) {
listWebSeeds - > addItem ( url_seed ) ;
qDebug ( " Added custom url seed to list: %s " , ( const char * ) url_seed . toUtf8 ( ) ) ;
}
}
2007-04-12 19:51:39 +00:00
void properties : : loadPiecesPriorities ( ) {
2006-10-08 00:37:51 +00:00
torrent_info torrentInfo = h . get_torrent_info ( ) ;
2007-04-12 19:51:39 +00:00
unsigned int nbFiles = torrentInfo . num_files ( ) ;
2006-10-08 00:37:51 +00:00
QString fileName = QString ( torrentInfo . name ( ) . c_str ( ) ) ;
2007-04-12 19:51:39 +00:00
QFile pieces_file ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + fileHash + " .priorities " ) ;
2006-10-08 01:01:34 +00:00
has_filtered_files = false ;
2007-04-12 19:51:39 +00:00
qDebug ( " Loading pieces priorities " ) ;
2006-10-08 00:37:51 +00:00
// Read saved file
if ( ! pieces_file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) {
2006-10-10 21:44:59 +00:00
qDebug ( " Could not find pieces file " ) ;
2007-04-12 19:51:39 +00:00
setAllPiecesState ( NORMAL ) ;
2006-10-08 00:37:51 +00:00
return ;
}
2007-04-12 19:51:39 +00:00
QByteArray pieces_text = pieces_file . readAll ( ) ;
2006-10-08 00:37:51 +00:00
pieces_file . close ( ) ;
2007-04-12 19:51:39 +00:00
QList < QByteArray > pieces_priority_list = pieces_text . split ( ' \n ' ) ;
if ( ( unsigned int ) pieces_priority_list . size ( ) ! = nbFiles + 1 ) {
2006-10-16 09:02:53 +00:00
std : : cerr < < " Error: Corrupted pieces file \n " ;
2007-04-12 19:51:39 +00:00
setAllPiecesState ( NORMAL ) ;
2006-10-08 00:37:51 +00:00
return ;
}
2007-04-12 19:51:39 +00:00
for ( unsigned int i = 0 ; i < nbFiles ; + + i ) {
int priority = pieces_priority_list . at ( i ) . toInt ( ) ;
if ( priority < 0 | | priority > 7 ) {
// Normal priority as default
priority = 1 ;
2006-10-08 00:37:51 +00:00
}
2007-04-12 19:51:39 +00:00
if ( ! priority ) {
2006-10-08 00:37:51 +00:00
setRowColor ( i , " red " ) ;
2006-10-08 01:01:34 +00:00
has_filtered_files = true ;
2006-10-08 00:37:51 +00:00
} else {
setRowColor ( i , " green " ) ;
}
2007-04-12 19:51:39 +00:00
PropListModel - > setData ( PropListModel - > index ( i , PRIORITY ) , QVariant ( priority ) ) ;
2006-10-08 00:37:51 +00:00
}
}
2007-07-20 13:07:34 +00:00
void properties : : displayFilesListMenu ( const QPoint & pos ) {
QMenu myFilesLlistMenu ( this ) ;
QModelIndex index ;
// Enable/disable pause/start action given the DL state
QModelIndexList selectedIndexes = filesList - > selectionModel ( ) - > selectedIndexes ( ) ;
myFilesLlistMenu . setTitle ( tr ( " Priority " ) ) ;
myFilesLlistMenu . addAction ( actionIgnored ) ;
myFilesLlistMenu . addAction ( actionNormal ) ;
myFilesLlistMenu . addAction ( actionHigh ) ;
myFilesLlistMenu . addAction ( actionMaximum ) ;
// Call menu
// XXX: why mapToGlobal() is not enough?
myFilesLlistMenu . exec ( mapToGlobal ( pos ) + QPoint ( 22 , 95 ) ) ;
}
void properties : : ignoreSelection ( ) {
QModelIndexList selectedIndexes = filesList - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndex index ;
foreach ( index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( IGNORED ) ) ;
}
}
}
void properties : : normalSelection ( ) {
QModelIndexList selectedIndexes = filesList - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndex index ;
foreach ( index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( NORMAL ) ) ;
}
}
}
void properties : : highSelection ( ) {
QModelIndexList selectedIndexes = filesList - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndex index ;
foreach ( index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( HIGH ) ) ;
}
}
}
void properties : : maximumSelection ( ) {
QModelIndexList selectedIndexes = filesList - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndex index ;
foreach ( index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( MAXIMUM ) ) ;
}
}
}
2007-03-24 21:36:22 +00:00
void properties : : loadTrackers ( ) {
//Trackers
2007-03-25 13:45:20 +00:00
std : : vector < announce_entry > trackers = h . trackers ( ) ;
2007-03-24 21:36:22 +00:00
trackersURLS - > clear ( ) ;
for ( unsigned int i = 0 ; i < trackers . size ( ) ; + + i ) {
trackersURLS - > addItem ( QString ( trackers [ i ] . url . c_str ( ) ) ) ;
}
2007-03-25 13:45:20 +00:00
torrent_status torrentStatus = h . status ( ) ;
2007-03-24 21:36:22 +00:00
QString tracker = QString ( torrentStatus . current_tracker . c_str ( ) ) . trimmed ( ) ;
if ( ! tracker . isEmpty ( ) ) {
trackerURL - > setText ( tracker ) ;
} else {
trackerURL - > setText ( tr ( " None - Unreachable? " ) ) ;
}
}
2007-07-27 09:53:55 +00:00
void properties : : askWebSeed ( ) {
bool ok ;
// Ask user for a new url seed
QString url_seed = QInputDialog : : getText ( this , tr ( " New url seed " ) ,
tr ( " New url seed: " ) , QLineEdit : : Normal ,
" http://www. " , & ok ) ;
if ( ! ok ) return ;
torrent_info torrentInfo = h . get_torrent_info ( ) ;
qDebug ( " Adding %s web seed " , ( const char * ) url_seed . toUtf8 ( ) ) ;
if ( manualUrlSeeds . indexOf ( url_seed ) ! = - 1 ) {
QMessageBox : : warning ( this , tr ( " qBittorrent " ) ,
tr ( " This url seed is already in the list. " ) ,
QMessageBox : : Ok ) ;
return ;
}
manualUrlSeeds < < url_seed ;
torrentInfo . add_url_seed ( url_seed . toStdString ( ) ) ;
saveWebSeeds ( ) ;
// Refresh the seeds list
loadWebSeeds ( ) ;
}
2007-03-24 21:36:22 +00:00
// Ask the user for a new tracker
// and add it to the download list
// if it is not already in it
void properties : : askForTracker ( ) {
bool ok ;
// Ask user for a new tracker
QString trackerUrl = QInputDialog : : getText ( this , tr ( " New tracker " ) ,
tr ( " New tracker url: " ) , QLineEdit : : Normal ,
" http://www. " , & ok ) ;
if ( ! ok ) return ;
2007-03-25 13:45:20 +00:00
// Add the tracker to the list
std : : vector < announce_entry > trackers = h . trackers ( ) ;
announce_entry new_tracker ( trackerUrl . toStdString ( ) ) ;
new_tracker . tier = trackersURLS - > count ( ) ;
trackers . push_back ( new_tracker ) ;
h . replace_trackers ( trackers ) ;
h . force_reannounce ( ) ;
// Reload Trackers
loadTrackers ( ) ;
}
2007-07-27 09:53:55 +00:00
void properties : : deleteSelectedUrlSeeds ( ) {
QList < QListWidgetItem * > selectedItems ;
selectedItems = listWebSeeds - > selectedItems ( ) ;
QListWidgetItem * item ;
bool error = false ;
foreach ( item , selectedItems ) {
QString url_seed = item - > text ( ) ;
int index = manualUrlSeeds . indexOf ( url_seed ) ;
if ( index ! = - 1 ) {
manualUrlSeeds . removeAt ( index ) ;
qDebug ( " Removed an url seeds from manualUrlSeeds list " ) ;
} else {
error = true ;
}
}
// Save them to disk
saveWebSeeds ( ) ;
// Refresh list
loadWebSeeds ( ) ;
if ( error ) {
QMessageBox : : warning ( this , tr ( " qBittorrent " ) ,
tr ( " Hard-coded url seeds cannot be deleted. " ) ,
QMessageBox : : Ok ) ;
}
}
2007-03-25 13:45:20 +00:00
void properties : : deleteSelectedTrackers ( ) {
std : : vector < announce_entry > trackers = h . trackers ( ) ;
QList < QListWidgetItem * > selectedItems ;
selectedItems = trackersURLS - > selectedItems ( ) ;
QListWidgetItem * item ;
2007-07-27 09:53:55 +00:00
unsigned int nbTrackers = trackers . size ( ) ;
if ( nbTrackers = = ( unsigned int ) selectedItems . size ( ) ) {
QMessageBox : : warning ( this , tr ( " qBittorrent " ) ,
tr ( " Trackers list can't be empty. " ) ,
QMessageBox : : Ok ) ;
return ;
}
2007-03-25 13:45:20 +00:00
foreach ( item , selectedItems ) {
QString url = item - > text ( ) ;
2007-05-16 18:55:34 +00:00
for ( unsigned int i = 0 ; i < nbTrackers ; + + i ) {
2007-03-25 13:45:20 +00:00
if ( QString ( trackers . at ( i ) . url . c_str ( ) ) = = url ) {
trackers . erase ( trackers . begin ( ) + i ) ;
break ;
}
}
}
h . replace_trackers ( trackers ) ;
2007-03-24 21:36:22 +00:00
h . force_reannounce ( ) ;
// Reload Trackers
loadTrackers ( ) ;
}
2007-03-25 18:39:27 +00:00
void properties : : riseSelectedTracker ( ) {
2007-07-24 07:13:40 +00:00
unsigned int i = 0 ;
2007-03-25 18:39:27 +00:00
std : : vector < announce_entry > trackers = h . trackers ( ) ;
QList < QListWidgetItem * > selectedItems ;
selectedItems = trackersURLS - > selectedItems ( ) ;
QListWidgetItem * item ;
bool change = false ;
foreach ( item , selectedItems ) {
QString url = item - > text ( ) ;
for ( i = 0 ; i < trackers . size ( ) ; + + i ) {
if ( QString ( trackers . at ( i ) . url . c_str ( ) ) = = url ) {
if ( trackers [ i ] . tier > 0 & & i ! = 0 ) {
trackers [ i ] . tier - = 1 ;
announce_entry tmp = trackers [ i ] ;
trackers [ i ] = trackers [ i - 1 ] ;
trackers [ i - 1 ] = tmp ;
change = true ;
}
break ;
}
}
}
if ( change ) {
h . replace_trackers ( trackers ) ;
h . force_reannounce ( ) ;
// Reload Trackers
loadTrackers ( ) ;
trackersURLS - > item ( i - 1 ) - > setSelected ( true ) ;
}
}
void properties : : lowerSelectedTracker ( ) {
2007-07-24 07:13:40 +00:00
unsigned int i = 0 ;
2007-03-25 18:39:27 +00:00
std : : vector < announce_entry > trackers = h . trackers ( ) ;
QList < QListWidgetItem * > selectedItems ;
selectedItems = trackersURLS - > selectedItems ( ) ;
QListWidgetItem * item ;
bool change = false ;
foreach ( item , selectedItems ) {
QString url = item - > text ( ) ;
for ( i = 0 ; i < trackers . size ( ) ; + + i ) {
if ( QString ( trackers . at ( i ) . url . c_str ( ) ) = = url ) {
if ( i ! = trackers . size ( ) - 1 ) {
trackers [ i ] . tier + = 1 ;
announce_entry tmp = trackers [ i ] ;
trackers [ i ] = trackers [ i + 1 ] ;
trackers [ i + 1 ] = tmp ;
change = true ;
}
break ;
}
}
}
if ( change ) {
h . replace_trackers ( trackers ) ;
h . force_reannounce ( ) ;
// Reload Trackers
loadTrackers ( ) ;
trackersURLS - > item ( i + 1 ) - > setSelected ( true ) ;
}
}
2006-10-06 18:07:01 +00:00
void properties : : updateProgress ( ) {
std : : vector < float > fp ;
2006-10-16 18:16:56 +00:00
try {
h . file_progress ( fp ) ;
torrent_info torrentInfo = h . get_torrent_info ( ) ;
for ( int i = 0 ; i < torrentInfo . num_files ( ) ; + + i ) {
PropListModel - > setData ( PropListModel - > index ( i , PROGRESS ) , QVariant ( ( double ) fp [ i ] ) ) ;
}
} catch ( invalid_handle e ) {
// torrent was removed, closing properties
close ( ) ;
2006-10-06 18:07:01 +00:00
}
2006-09-30 16:02:39 +00:00
}
// Set the color of a row in data model
void properties : : setRowColor ( int row , QString color ) {
for ( int i = 0 ; i < PropListModel - > columnCount ( ) ; + + i ) {
PropListModel - > setData ( PropListModel - > index ( row , i ) , QVariant ( QColor ( color ) ) , Qt : : TextColorRole ) ;
}
}
2007-04-12 19:51:39 +00:00
void properties : : setAllPiecesState ( unsigned short priority ) {
2006-10-10 21:44:59 +00:00
torrent_info torrentInfo = h . get_torrent_info ( ) ;
for ( int i = 0 ; i < torrentInfo . num_files ( ) ; + + i ) {
2007-04-12 19:51:39 +00:00
if ( priority ) {
2006-10-10 21:44:59 +00:00
setRowColor ( i , " green " ) ;
} else {
setRowColor ( i , " red " ) ;
}
2007-04-12 19:51:39 +00:00
PropListModel - > setData ( PropListModel - > index ( i , PRIORITY ) , QVariant ( priority ) ) ;
2006-10-10 21:44:59 +00:00
}
}
2006-09-30 16:02:39 +00:00
void properties : : on_incrementalDownload_stateChanged ( int ) {
qDebug ( " Incremental download toggled " ) ;
torrent_info torrentInfo = h . get_torrent_info ( ) ;
if ( incrementalDownload - > isChecked ( ) ) {
// Create .incremental file
2007-02-23 22:52:24 +00:00
QFile incremental_file ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + fileHash + " .incremental " ) ;
2006-09-30 16:02:39 +00:00
incremental_file . open ( QIODevice : : WriteOnly | QIODevice : : Text ) ;
incremental_file . close ( ) ;
2006-10-02 08:26:25 +00:00
h . set_sequenced_download_threshold ( 15 ) ;
2006-09-30 16:02:39 +00:00
} else {
2007-02-23 22:52:24 +00:00
QFile : : remove ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + fileHash + " .incremental " ) ;
2006-09-30 16:02:39 +00:00
h . set_sequenced_download_threshold ( 100 ) ;
}
}
void properties : : on_okButton_clicked ( ) {
2007-04-12 19:51:39 +00:00
savePiecesPriorities ( ) ;
2006-09-30 16:02:39 +00:00
close ( ) ;
}
2007-07-27 09:53:55 +00:00
void properties : : loadWebSeedsFromFile ( ) {
QFile urlseeds_file ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + fileHash + " .urlseeds " ) ;
if ( ! urlseeds_file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) return ;
QByteArray urlseeds_lines = urlseeds_file . readAll ( ) ;
urlseeds_file . close ( ) ;
QList < QByteArray > url_seeds = urlseeds_lines . split ( ' \n ' ) ;
manualUrlSeeds . clear ( ) ;
QByteArray url_seed ;
foreach ( url_seed , url_seeds ) {
if ( ! url_seed . isEmpty ( ) )
manualUrlSeeds < < url_seed ;
}
}
void properties : : saveWebSeeds ( ) {
QFile urlseeds_file ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + fileHash + " .urlseeds " ) ;
if ( ! urlseeds_file . open ( QIODevice : : WriteOnly | QIODevice : : Text ) ) {
std : : cerr < < " Error: Could not save url seeds \n " ;
return ;
}
QString url_seed ;
foreach ( url_seed , manualUrlSeeds ) {
urlseeds_file . write ( QByteArray ( ( const char * ) ( url_seed + " \n " ) . toUtf8 ( ) ) ) ;
}
urlseeds_file . close ( ) ;
qDebug ( " url seeds were saved " ) ;
}
2007-04-12 19:51:39 +00:00
void properties : : savePiecesPriorities ( ) {
2007-07-04 10:06:22 +00:00
if ( ! changedFilteredfiles ) return ;
2007-04-12 19:51:39 +00:00
qDebug ( " Saving pieces priorities " ) ;
2006-10-06 18:07:01 +00:00
torrent_info torrentInfo = h . get_torrent_info ( ) ;
2006-10-08 01:01:34 +00:00
bool hasFilteredFiles = false ;
2006-10-06 18:07:01 +00:00
QString fileName = QString ( torrentInfo . name ( ) . c_str ( ) ) ;
2007-04-12 19:51:39 +00:00
QFile pieces_file ( misc : : qBittorrentPath ( ) + " BT_backup " + QDir : : separator ( ) + fileHash + " .priorities " ) ;
2006-10-06 18:07:01 +00:00
// First, remove old file
pieces_file . remove ( ) ;
// Write new files
if ( ! pieces_file . open ( QIODevice : : WriteOnly | QIODevice : : Text ) ) {
2007-04-12 19:51:39 +00:00
std : : cerr < < " Error: Could not save pieces priorities \n " ;
2006-10-06 18:07:01 +00:00
return ;
}
2007-04-12 19:51:39 +00:00
unsigned int nbRows = PropListModel - > rowCount ( ) ;
for ( unsigned int i = 0 ; i < nbRows ; + + i ) {
QStandardItem * item = PropListModel - > item ( i , PRIORITY ) ;
unsigned short priority = item - > text ( ) . toInt ( ) ;
if ( ! priority ) {
2006-10-08 01:01:34 +00:00
hasFilteredFiles = true ;
2006-10-06 18:07:01 +00:00
}
2007-04-12 19:51:39 +00:00
pieces_file . write ( QByteArray ( ( misc : : toString ( priority ) + " \n " ) . c_str ( ) ) ) ;
2006-10-06 18:07:01 +00:00
}
pieces_file . close ( ) ;
2007-07-04 10:06:22 +00:00
if ( hasFilteredFiles & & ! BTSession - > inFullAllocationMode ( fileHash ) ) {
emit mustHaveFullAllocationMode ( h ) ;
}
BTSession - > loadFilesPriorities ( h ) ;
emit filteredFilesChanged ( fileHash ) ;
2006-10-08 01:01:34 +00:00
has_filtered_files = hasFilteredFiles ;
2006-09-30 16:02:39 +00:00
}