{
case COL_NAME: {
const QFontMetrics fm( item.font );
- const QString text = index.model()->data(index).toString();
+ const QString text = index.data().toString();
const int iconSize = QApplication::style()->pixelMetric( QStyle::PM_SmallIconSize );
size.rwidth() = HIG::PAD_SMALL + iconSize;
size.rheight() = std::max( iconSize, fm.height( ) );
default: {
const QFontMetrics fm( item.font );
- const QString text = index.model()->data(index).toString();
+ const QString text = index.data().toString();
size = fm.size( 0, text );
break;
}
icon = style->standardIcon( QStyle::StandardPixmap( QStyle::SP_DirOpenIcon ) );
else
{
- QString name = index.model()->data(index).toString();
+ QString name = index.data().toString();
icon = Utils :: guessMimeIcon( name.left( name.lastIndexOf( " (" ) ) );
}
icon.paint( painter, iconArea, Qt::AlignCenter, QIcon::Normal, QIcon::On );
p.maximum = 100;
p.textAlignment = Qt::AlignCenter;
p.textVisible = true;
- p.progress = (int)(100.0*index.model()->data(index).toDouble());
+ p.progress = (int)(100.0*index.data().toDouble());
p.text = QString( ).sprintf( "%d%%", p.progress );
style->drawControl( QStyle::CE_ProgressBar, &p, painter );
}
o.rect.setSize( QSize( 20, option.rect.height( ) ) );
o.rect.moveCenter( option.rect.center( ) );
o.fontMetrics = QApplication::fontMetrics();
- switch( index.model()->data(index).toInt() ) {
+ switch( index.data().toInt() ) {
case Qt::Unchecked: o.state |= QStyle::State_Off; break;
case Qt::Checked: o.state |= QStyle::State_On; break;
default: o.state |= QStyle::State_NoChange;break;
TorrentDelegate :: sizeHint( const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
- const Torrent * tor( index.model()->data( index, TorrentModel::TorrentRole ).value<const Torrent*>() );
+ const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>() );
return sizeHint( option, *tor );
}
const QStyleOptionViewItem & option,
const QModelIndex & index) const
{
- const Torrent * tor( index.model()->data( index, TorrentModel::TorrentRole ).value<const Torrent*>() );
+ const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>() );
painter->save( );
painter->setClipRect( option.rect );
drawBackground( painter, option, index );
#include <iostream>
#include "filters.h"
+#include "hig.h"
#include "prefs.h"
#include "torrent.h"
#include "torrent-filter.h"
#include "torrent-model.h"
+#include "utils.h"
TorrentFilter :: TorrentFilter( Prefs& prefs ):
- myPrefs( prefs ),
- myTextMode( FILTER_BY_NAME )
+ myPrefs( prefs )
{
// listen for changes to the preferences to know when to refilter / resort
connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)));
// initialize our state from the current prefs
QList<int> initKeys;
initKeys << Prefs :: SORT_MODE
- << Prefs :: FILTER_MODE;
+ << Prefs :: FILTER_MODE
+ << Prefs :: FILTER_TRACKERS
+ << Prefs :: FILTER_TEXT;
foreach( int key, initKeys )
refreshPref( key );
}
{
switch( key )
{
+ case Prefs :: FILTER_TEXT:
case Prefs :: FILTER_MODE:
+ case Prefs :: FILTER_TRACKERS:
invalidateFilter( );
/* force a re-sort */
sort( 0, !myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder );
+
case Prefs :: SORT_MODE:
case Prefs :: SORT_REVERSED:
sort( 0, myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder );
****
***/
-void
-TorrentFilter :: setTextMode( int i )
-{
- if( myTextMode != i )
- {
- myTextMode = TextMode( i );
- invalidateFilter( );
- }
-}
-
-void
-TorrentFilter :: setText( QString text )
-{
- QString trimmed = text.trimmed( );
-
- if( myText != trimmed )
- {
- myText = trimmed;
- invalidateFilter( );
- }
-}
-
-/***
-****
-***/
-
namespace
{
template <typename T> int compare( const T a, const T b )
***/
bool
-TorrentFilter :: filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
+TorrentFilter :: trackerFilterAcceptsTorrent( const Torrent * tor, const QString& tracker ) const
+{
+ return tracker.isEmpty() || tor->hasTrackerSubstring( tracker );
+}
+
+bool
+TorrentFilter :: activityFilterAcceptsTorrent( const Torrent * tor, const FilterMode& m ) const
{
- QModelIndex childIndex = sourceModel()->index( sourceRow, 0, sourceParent );
- const Torrent * tor = childIndex.model()->data( childIndex, TorrentModel::TorrentRole ).value<const Torrent*>();
- const tr_torrent_activity activity = tor->getActivity( );
bool accepts;
+ const tr_torrent_activity activity = tor->getActivity( );
- switch( myPrefs.get<FilterMode>(Prefs::FILTER_MODE).mode() )
+ switch( m.mode( ) )
{
case FilterMode::SHOW_ALL:
accepts = true;
case FilterMode::SHOW_PAUSED:
accepts = activity == TR_STATUS_STOPPED;
break;
+ case FilterMode::SHOW_QUEUED:
+ accepts = activity == TR_STATUS_CHECK_WAIT;
+ break;
+ case FilterMode::SHOW_VERIFYING:
+ accepts = activity == TR_STATUS_CHECK;
+ break;
+ case FilterMode::SHOW_ERROR:
+ accepts = tor->hasError( );
+ break;
+ }
+
+ return accepts;
+}
+
+bool
+TorrentFilter :: filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
+{
+ QModelIndex childIndex = sourceModel()->index( sourceRow, 0, sourceParent );
+ const Torrent * tor = childIndex.model()->data( childIndex, TorrentModel::TorrentRole ).value<const Torrent*>();
+ bool accepts = true;
+
+ if( accepts ) {
+ const FilterMode m = myPrefs.get<FilterMode>(Prefs::FILTER_MODE);
+ accepts = activityFilterAcceptsTorrent( tor, m );
+ }
+
+ if( accepts ) {
+ const QString trackers = myPrefs.getString(Prefs::FILTER_TRACKERS);
+ accepts = trackerFilterAcceptsTorrent( tor, trackers );
}
+ if( accepts ) {
+ const QString text = myPrefs.getString( Prefs::FILTER_TEXT );
+ if( !text.isEmpty( ) )
+ accepts = tor->name().contains( text, Qt::CaseInsensitive );
+ }
+
+#if 0
if( accepts && !myText.isEmpty( ) ) switch( myTextMode )
{
case FILTER_BY_NAME:
accepts = tor->hasTrackerSubstring( myText );
break;
}
+#endif
return accepts;
}
{
return sourceModel()->rowCount( ) - rowCount( );
}
+
+int
+TorrentFilter :: count( const FilterMode& mode ) const
+{
+ int count = 0;
+
+ for( int row=0; ; ++row ) {
+ QModelIndex index = sourceModel()->index( row, 0 );
+ if( !index.isValid( ) )
+ break;
+ const Torrent * tor = index.data( TorrentModel::TorrentRole ).value<const Torrent*>();
+ if( activityFilterAcceptsTorrent( tor, mode ) )
+ ++count;
+ }
+
+ return count;
+}