From ddda0f14e80b37a59248909b2b8794e93ccd162f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 23 Apr 2010 03:58:42 +0000 Subject: [PATCH] (trunk qt) #2564 "Confirm on torrent remove" -- committed Longinus00's patch to trunk for 2.00 --- qt/mainwin.cc | 97 +++++++++++++++++++++++++++++++++++++++++++++++++-- qt/mainwin.h | 1 + 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/qt/mainwin.cc b/qt/mainwin.cc index ede8abead..cbd1fe05a 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -843,12 +844,12 @@ TrMainWindow :: pauseAll( ) void TrMainWindow :: removeSelected( ) { - mySession.removeTorrents( getSelectedTorrents( ), false ); + removeTorrents( false ); } void TrMainWindow :: deleteSelected( ) { - mySession.removeTorrents( getSelectedTorrents( ), true ); + removeTorrents( true ); } void TrMainWindow :: verifySelected( ) @@ -1145,6 +1146,98 @@ TrMainWindow :: addTorrent( const QString& filename ) } } +void +TrMainWindow :: removeTorrents( const bool deleteFiles ) +{ + QSet ids; + QMessageBox msgBox( this ); + QString primary_text, secondary_text; + int incomplete = 0; + int connected = 0; + int count; + + foreach( QModelIndex index, ui.listView->selectionModel( )->selectedRows( ) ) + { + const Torrent * tor( index.model()->data( index, TorrentModel::TorrentRole ).value( ) ); + ids.insert( tor->id( ) ); + if( tor->connectedPeers( ) ) + ++connected; + if( !tor->isDone( ) ) + ++incomplete; + } + + if( ids.isEmpty() ) + return; + count = ids.size(); + + if( !deleteFiles ) + { + primary_text = ( count == 1 ) + ? tr( "Remove torrent?" ) + : tr( "Remove %1 torrents?" ).arg( count ); + } + else + { + primary_text = ( count == 1 ) + ? tr( "Delete this torrent's downloaded files?" ) + : tr( "Delete these %1 torrents' downloaded files?" ).arg( count ); + } + + if( !incomplete && !connected ) + { + secondary_text = ( count == 1 ) + ? tr( "Once removed, continuing the transfer will require the torrent file or magnet link." ) + : tr( "Once removed, continuing the transfers will require the torrent files or magnet links." ); + } + else if( count == incomplete ) + { + secondary_text = ( count == 1 ) + ? tr( "This torrent has not finished downloading." ) + : tr( "These torrents have not finished downloading." ); + } + else if( count == connected ) + { + secondary_text = ( count == 1 ) + ? tr( "This torrent is connected to peers." ) + : tr( "These torrents are connected to peers." ); + } + else + { + if( connected ) + { + secondary_text = ( connected == 1 ) + ? tr( "One of these torrents is connected to peers." ) + : tr( "Some of these torrents are connected to peers." ); + } + + if( connected && incomplete ) + { + secondary_text += "\n"; + } + + if( incomplete ) + { + secondary_text += ( incomplete == 1 ) + ? tr( "One of these torrents has not finished downloading." ) + : tr( "Some of these torrents have not finished downloading." ); + } + } + + msgBox.setWindowTitle( QString(" ") ); + msgBox.setText( QString( "%1" ).arg( primary_text ) ); + msgBox.setInformativeText( secondary_text ); + msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel ); + msgBox.setDefaultButton( QMessageBox::Cancel ); + msgBox.setIcon( QMessageBox::Question ); + /* hack needed to keep the dialog from being too narrow */ + QGridLayout* layout = (QGridLayout*)msgBox.layout(); + QSpacerItem* spacer = new QSpacerItem( 450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ); + layout->addItem( spacer, layout->rowCount(), 0, 1, layout->columnCount() ); + + if( msgBox.exec() == QMessageBox::Ok ) + mySession.removeTorrents( ids, deleteFiles ); +} + /*** **** ***/ diff --git a/qt/mainwin.h b/qt/mainwin.h index 1d0bfcad2..2d4096ada 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -115,6 +115,7 @@ class TrMainWindow: public QMainWindow void trayActivated( QSystemTrayIcon::ActivationReason ); void refreshPref( int key ); void addTorrents( const QStringList& filenames ); + void removeTorrents( const bool deleteFiles ); void openHelp( ); void openFolder( ); void copyMagnetLinkToClipboard( );