Ignore:
Timestamp:
Jul 13, 2011, 5:43:25 PM (10 years ago)
Author:
jordan
Message:

(trunk qt) #4357 "wrong torrent count on tracker filterbar" -- fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/filterbar.cc

    r11522 r12547  
    311311        const QStringList trackers = tor->trackers( );
    312312        QSet<QString> torrentHosts;
    313         foreach( QString tracker, trackers )
    314             torrentHosts.insert( Favicons::getHost( QUrl( tracker ) ) );
     313        foreach( QString tracker, trackers ) {
     314            const QString host = Favicons::getHost( QUrl( tracker ) );
     315            if( host.isEmpty( ) )
     316                qWarning() << "torrent" << qPrintable(tor->name()) << "has an invalid announce URL:" << tracker;
     317            else
     318                torrentHosts.insert( host );
     319        }
    315320        foreach( QString host, torrentHosts ) {
    316321            newHosts.insert( host );
    317             ++torrentsPerHost[host];
     322            ++torrentsPerHost[ readableHostName( host ) ];
    318323        }
    319324    }
     
    327332        const QString name = readableHostName( host );
    328333        QStandardItem * row = myTrackerModel->findItems(name).front();
    329         row->setData( getCountString(torrentsPerHost[host]), TorrentCountRole );
     334        row->setData( getCountString(torrentsPerHost[name]), TorrentCountRole );
    330335        row->setData( favicons.findFromHost(host), Qt::DecorationRole );
    331336    }
     
    345350        const QString name = readableHostName( host );
    346351
     352        if( !myTrackerModel->findItems(name).isEmpty() )
     353            continue;
     354
    347355        // find the sorted position to add this row
    348356        int i = firstTrackerRow;
    349         for( int n=myTrackerModel->rowCount(); i<n; ++i )
    350             if( myTrackerModel->index(i,0).data(Qt::DisplayRole).toString() > name )
     357        for( int n=myTrackerModel->rowCount(); i<n; ++i ) {
     358            const QString rowName = myTrackerModel->index(i,0).data(Qt::DisplayRole).toString();
     359            if( rowName >= name )
    351360                break;
     361        }
    352362
    353363        // add the row
    354         QStandardItem * row = new QStandardItem( favicons.findFromHost( host ), readableHostName( host ) );
     364        QStandardItem * row = new QStandardItem( favicons.findFromHost( host ), name );
    355365        row->setData( getCountString(torrentsPerHost[host]), TorrentCountRole );
    356366        row->setData( favicons.findFromHost(host), Qt::DecorationRole );
     
    474484        case Prefs :: FILTER_TRACKERS: {
    475485            const QString tracker = myPrefs.getString( key );
    476             QModelIndexList indices = myTrackerModel->match( myTrackerModel->index(0,0), TrackerRole, tracker, 1, Qt::MatchFixedString );
    477             if( !indices.isEmpty( )  )
    478                 myTrackerCombo->setCurrentIndex( indices.first().row() );
     486            const QString name = readableHostName( tracker );
     487            QList<QStandardItem*> rows = myTrackerModel->findItems(name);
     488            if( !rows.isEmpty() )
     489                myTrackerCombo->setCurrentIndex( rows.front()->row() );
    479490            else { // hm, we don't seem to have this tracker anymore...
    480491                const bool isBootstrapping = myTrackerModel->rowCount( ) <= 2;
     
    505516        QString str;
    506517        const bool isTracker = !myTrackerCombo->itemData(i,TrackerRole).toString().isEmpty();
    507         if( isTracker )
     518        if( !isTracker ) // show all
     519            str = "";
     520        else {
    508521            str = myTrackerCombo->itemData(i,TrackerRole).toString();
    509         else // show all
    510             str = "";
     522            const int pos = str.lastIndexOf( '.' );
     523            if( pos >= 0 )
     524              str.truncate( pos+1 );
     525        }
    511526        myPrefs.set( Prefs::FILTER_TRACKERS, str );
    512527    }
Note: See TracChangeset for help on using the changeset viewer.