Changeset 10515


Ignore:
Timestamp:
Apr 23, 2010, 3:58:42 AM (11 years ago)
Author:
charles
Message:

(trunk qt) #2564 "Confirm on torrent remove" -- committed Longinus00's patch to trunk for 2.00

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/mainwin.cc

    r10442 r10515  
    2121#include <QInputDialog>
    2222#include <QLabel>
     23#include <QMessageBox>
    2324#include <QSignalMapper>
    2425#include <QSize>
     
    844845TrMainWindow :: removeSelected( )
    845846{
    846     mySession.removeTorrents( getSelectedTorrents( ), false );
     847    removeTorrents( false );
    847848}
    848849void
    849850TrMainWindow :: deleteSelected( )
    850851{
    851     mySession.removeTorrents( getSelectedTorrents( ), true );
     852    removeTorrents( true );
    852853}
    853854void
     
    11461147}
    11471148
     1149void
     1150TrMainWindow :: removeTorrents( const bool deleteFiles )
     1151{
     1152    QSet<int> ids;
     1153    QMessageBox msgBox( this );
     1154    QString primary_text, secondary_text;
     1155    int incomplete = 0;
     1156    int connected  = 0;
     1157    int count;
     1158
     1159    foreach( QModelIndex index, ui.listView->selectionModel( )->selectedRows( ) )
     1160    {
     1161        const Torrent * tor( index.model()->data( index, TorrentModel::TorrentRole ).value<const Torrent*>( ) );
     1162        ids.insert( tor->id( ) );
     1163        if( tor->connectedPeers( ) )
     1164            ++connected;
     1165        if( !tor->isDone( ) )
     1166            ++incomplete;
     1167    }
     1168
     1169    if( ids.isEmpty() )
     1170        return;
     1171    count = ids.size();
     1172
     1173    if( !deleteFiles )
     1174    {
     1175        primary_text = ( count == 1 )
     1176            ? tr( "Remove torrent?" )
     1177            : tr( "Remove %1 torrents?" ).arg( count );
     1178    }
     1179    else
     1180    {
     1181        primary_text = ( count == 1 )
     1182            ? tr( "Delete this torrent's downloaded files?" )
     1183            : tr( "Delete these %1 torrents' downloaded files?" ).arg( count );
     1184    }
     1185
     1186    if( !incomplete && !connected )
     1187    {
     1188        secondary_text = ( count == 1 )
     1189            ? tr( "Once removed, continuing the transfer will require the torrent file or magnet link." )
     1190            : tr( "Once removed, continuing the transfers will require the torrent files or magnet links." );
     1191    }
     1192    else if( count == incomplete )
     1193    {
     1194        secondary_text = ( count == 1 )
     1195            ? tr( "This torrent has not finished downloading." )
     1196            : tr( "These torrents have not finished downloading." );
     1197    }
     1198    else if( count == connected )
     1199    {
     1200        secondary_text = ( count == 1 )
     1201            ? tr( "This torrent is connected to peers." )
     1202            : tr( "These torrents are connected to peers." );
     1203    }
     1204    else
     1205    {
     1206        if( connected )
     1207        {
     1208            secondary_text = ( connected == 1 )
     1209                ? tr( "One of these torrents is connected to peers." )
     1210                : tr( "Some of these torrents are connected to peers." );
     1211        }
     1212
     1213        if( connected && incomplete )
     1214        {
     1215            secondary_text += "\n";
     1216        }
     1217
     1218        if( incomplete )
     1219        {
     1220            secondary_text += ( incomplete == 1 )
     1221                ? tr( "One of these torrents has not finished downloading." )
     1222                : tr( "Some of these torrents have not finished downloading." );
     1223        }
     1224    }
     1225
     1226    msgBox.setWindowTitle( QString(" ") );
     1227    msgBox.setText( QString( "<big><b>%1</big></b>" ).arg( primary_text ) );
     1228    msgBox.setInformativeText( secondary_text );
     1229    msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
     1230    msgBox.setDefaultButton( QMessageBox::Cancel );
     1231    msgBox.setIcon( QMessageBox::Question );
     1232    /* hack needed to keep the dialog from being too narrow */
     1233    QGridLayout* layout = (QGridLayout*)msgBox.layout();
     1234    QSpacerItem* spacer = new QSpacerItem( 450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
     1235    layout->addItem( spacer, layout->rowCount(), 0, 1, layout->columnCount() );
     1236
     1237    if( msgBox.exec() == QMessageBox::Ok )
     1238        mySession.removeTorrents( ids, deleteFiles );
     1239}
     1240
    11481241/***
    11491242****
  • trunk/qt/mainwin.h

    r10384 r10515  
    116116        void refreshPref( int key );
    117117        void addTorrents( const QStringList& filenames );
     118        void removeTorrents( const bool deleteFiles );
    118119        void openHelp( );
    119120        void openFolder( );
Note: See TracChangeset for help on using the changeset viewer.