diff --git a/src/libtomahawk/album.cpp b/src/libtomahawk/album.cpp index f6baa3baa..625aedfa5 100644 --- a/src/libtomahawk/album.cpp +++ b/src/libtomahawk/album.cpp @@ -40,12 +40,12 @@ Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& void -Album::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ) +Album::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ) { qDebug() << Q_FUNC_INFO; m_queries << tracks; - emit tracksAdded( tracks, collection ); + emit tracksAdded( tracks ); } @@ -75,8 +75,8 @@ Album::tracks() cmd->setAlbum( this ); cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); - connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); + connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), + SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); } diff --git a/src/libtomahawk/album.h b/src/libtomahawk/album.h index e6ea7f5bb..e11521b81 100644 --- a/src/libtomahawk/album.h +++ b/src/libtomahawk/album.h @@ -47,12 +47,12 @@ signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); - void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& ); + void tracksAdded( const QList<Tomahawk::query_ptr>& tracks ); void trackCountChanged( unsigned int tracks ); void sourceTrackCountChanged( unsigned int tracks ); private slots: - void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ); + void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ); private: unsigned int m_id; diff --git a/src/libtomahawk/artist.cpp b/src/libtomahawk/artist.cpp index aa1f69704..87ce124af 100644 --- a/src/libtomahawk/artist.cpp +++ b/src/libtomahawk/artist.cpp @@ -49,12 +49,12 @@ Artist::collection() const void -Artist::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ) +Artist::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ) { qDebug() << Q_FUNC_INFO; m_queries << tracks; - emit tracksAdded( tracks, collection ); + emit tracksAdded( tracks ); } @@ -84,8 +84,8 @@ Artist::tracks() cmd->setArtist( this ); cmd->setSortOrder( DatabaseCommand_AllTracks::Album ); - connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); + connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), + SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); } diff --git a/src/libtomahawk/artist.h b/src/libtomahawk/artist.h index b9081a7f9..a1f7c0457 100644 --- a/src/libtomahawk/artist.h +++ b/src/libtomahawk/artist.h @@ -48,12 +48,12 @@ signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); - void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& ); + void tracksAdded( const QList<Tomahawk::query_ptr>& tracks ); void trackCountChanged( unsigned int tracks ); void sourceTrackCountChanged( unsigned int tracks ); private slots: - void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ); + void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ); private: unsigned int m_id; diff --git a/src/libtomahawk/collection.cpp b/src/libtomahawk/collection.cpp index 7017257b9..85e7262e4 100644 --- a/src/libtomahawk/collection.cpp +++ b/src/libtomahawk/collection.cpp @@ -13,9 +13,10 @@ Collection::Collection( const source_ptr& source, const QString& name, QObject* : QObject( parent ) , m_name( name ) , m_lastmodified( 0 ) + , m_isLoaded( false ) , m_source( source ) { -// qDebug() << Q_FUNC_INFO; + qDebug() << Q_FUNC_INFO << name << source->friendlyName(); } @@ -127,7 +128,7 @@ Collection::dynamicPlaylist( const QString& guid ) if( pp->guid() == guid ) return pp; } - + return dynplaylist_ptr(); } @@ -146,26 +147,27 @@ void Collection::setDynamicPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists ) { qDebug() << Q_FUNC_INFO << plists.count(); - + m_dynplaylists.append( plists ); emit dynamicPlaylistsAdded( plists ); } void -Collection::setTracks( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ) +Collection::setTracks( const QList<Tomahawk::query_ptr>& tracks ) { - qDebug() << Q_FUNC_INFO << tracks.count() << collection->name(); + qDebug() << Q_FUNC_INFO << tracks.count() << name(); + m_isLoaded = true; m_tracks << tracks; - emit tracksAdded( tracks, collection ); + emit tracksAdded( tracks ); } void -Collection::delTracks( const QStringList& files, const Tomahawk::collection_ptr& collection ) +Collection::delTracks( const QStringList& files ) { - qDebug() << Q_FUNC_INFO << files.count() << collection->name(); + qDebug() << Q_FUNC_INFO << files.count() << name(); QList<Tomahawk::query_ptr> tracks; @@ -188,5 +190,5 @@ Collection::delTracks( const QStringList& files, const Tomahawk::collection_ptr& i++; } - emit tracksRemoved( tracks, collection ); + emit tracksRemoved( tracks ); } diff --git a/src/libtomahawk/collection.h b/src/libtomahawk/collection.h index 4b467ee3f..76ab19897 100644 --- a/src/libtomahawk/collection.h +++ b/src/libtomahawk/collection.h @@ -33,6 +33,7 @@ public: Collection( const source_ptr& source, const QString& name, QObject* parent = 0 ); virtual ~Collection(); + virtual bool isLoaded() const { return m_isLoaded; } virtual QString name() const; virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; } @@ -41,13 +42,13 @@ public: virtual Tomahawk::playlist_ptr playlist( const QString& guid ); virtual Tomahawk::dynplaylist_ptr dynamicPlaylist( const QString& guid ); - + virtual void addPlaylist( const Tomahawk::playlist_ptr& p ); virtual void deletePlaylist( const Tomahawk::playlist_ptr& p ); - + virtual void addDynamicPlaylist( const Tomahawk::dynplaylist_ptr& p ); virtual void deleteDynamicPlaylist( const Tomahawk::dynplaylist_ptr& p ); - + virtual QList< Tomahawk::playlist_ptr > playlists() { return m_playlists; } virtual QList< Tomahawk::dynplaylist_ptr > dynamicPlaylists() { return m_dynplaylists; } virtual QList< Tomahawk::query_ptr > tracks() { return m_tracks; } @@ -56,13 +57,12 @@ public: unsigned int lastmodified() const { return m_lastmodified; } signals: - void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& ); - void tracksRemoved( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& ); - void tracksFinished( const Tomahawk::collection_ptr& ); + void tracksAdded( const QList<Tomahawk::query_ptr>& tracks ); + void tracksRemoved( const QList<Tomahawk::query_ptr>& tracks ); void playlistsAdded( const QList<Tomahawk::playlist_ptr>& ); void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& ); - + void dynamicPlaylistsAdded( const QList<Tomahawk::dynplaylist_ptr>& ); void dynamicPlaylistsDeleted( const QList<Tomahawk::dynplaylist_ptr>& ); @@ -72,15 +72,17 @@ public slots: void setPlaylists( const QList<Tomahawk::playlist_ptr>& plists ); void setDynamicPlaylists( const QList< Tomahawk::dynplaylist_ptr >& dynplists ); - void setTracks( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ); + void setTracks( const QList<Tomahawk::query_ptr>& tracks ); - void delTracks( const QStringList& files, const Tomahawk::collection_ptr& collection ); + void delTracks( const QStringList& files ); protected: QString m_name; unsigned int m_lastmodified; // unix time of last change to collection private: + bool m_isLoaded; + source_ptr m_source; QList< Tomahawk::query_ptr > m_tracks; QList< Tomahawk::playlist_ptr > m_playlists; diff --git a/src/libtomahawk/database/databasecollection.cpp b/src/libtomahawk/database/databasecollection.cpp index 7d4a48e3a..6383098b1 100644 --- a/src/libtomahawk/database/databasecollection.cpp +++ b/src/libtomahawk/database/databasecollection.cpp @@ -51,8 +51,8 @@ DatabaseCollection::loadTracks() m_loadedTracks = true; DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( source()->collection() ); - connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - SLOT( setTracks( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); + connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), + SLOT( setTracks( QList<Tomahawk::query_ptr> ) ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); } @@ -73,7 +73,7 @@ DatabaseCollection::removeTracks( const QDir& dir ) { qDebug() << Q_FUNC_INFO << dir; DatabaseCommand_DeleteFiles* cmd = new DatabaseCommand_DeleteFiles( dir, source() ); - + Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); } diff --git a/src/libtomahawk/database/databasecollection.h b/src/libtomahawk/database/databasecollection.h index cd5ea869f..5c2ce4832 100644 --- a/src/libtomahawk/database/databasecollection.h +++ b/src/libtomahawk/database/databasecollection.h @@ -31,7 +31,7 @@ public: public slots: virtual void addTracks( const QList<QVariant>& newitems ); virtual void removeTracks( const QDir& dir ); - + private slots: void dynamicPlaylistCreated( const Tomahawk::source_ptr& source, const QVariantList& data ); diff --git a/src/libtomahawk/database/databasecommand_alltracks.cpp b/src/libtomahawk/database/databasecommand_alltracks.cpp index 95fb8df29..cc9ed161c 100644 --- a/src/libtomahawk/database/databasecommand_alltracks.cpp +++ b/src/libtomahawk/database/databasecommand_alltracks.cpp @@ -110,6 +110,6 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi ) qDebug() << Q_FUNC_INFO << ql.length(); - emit tracks( ql, m_collection ); + emit tracks( ql ); emit done( m_collection ); } diff --git a/src/libtomahawk/database/databasecommand_alltracks.h b/src/libtomahawk/database/databasecommand_alltracks.h index 2c6004522..50df59aa3 100644 --- a/src/libtomahawk/database/databasecommand_alltracks.h +++ b/src/libtomahawk/database/databasecommand_alltracks.h @@ -45,7 +45,7 @@ public: void setSortDescending( bool descending ) { m_sortDescending = descending; } signals: - void tracks( const QList<Tomahawk::query_ptr>&, const Tomahawk::collection_ptr& ); + void tracks( const QList<Tomahawk::query_ptr>& ); void done( const Tomahawk::collection_ptr& ); private: diff --git a/src/libtomahawk/playlist/collectionflatmodel.cpp b/src/libtomahawk/playlist/collectionflatmodel.cpp index 5edf161d5..d2c869361 100644 --- a/src/libtomahawk/playlist/collectionflatmodel.cpp +++ b/src/libtomahawk/playlist/collectionflatmodel.cpp @@ -52,17 +52,16 @@ CollectionFlatModel::addCollection( const collection_ptr& collection ) << collection->source()->id() << collection->source()->userName(); - emit loadingStarts(); + connect( collection.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ), + SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); + connect( collection.data(), SIGNAL( tracksRemoved( QList<Tomahawk::query_ptr> ) ), + SLOT( onTracksRemoved( QList<Tomahawk::query_ptr> ) ) ); - onTracksAdded( collection->tracks(), collection ); + if ( collection->isLoaded() ) + onTracksAdded( collection->tracks() ); + else + collection->tracks(); // data will arrive via signals - connect( collection.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); - connect( collection.data(), SIGNAL( tracksFinished( Tomahawk::collection_ptr ) ), - SLOT( onTracksAddingFinished( Tomahawk::collection_ptr ) ) ); - connect( collection.data(), SIGNAL( tracksRemoved( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - SLOT( onTracksRemoved( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); - if ( collection->source()->isLocal() ) setTitle( tr( "Your Collection" ) ); else @@ -78,8 +77,6 @@ CollectionFlatModel::addFilteredCollection( const collection_ptr& collection, un << collection->source()->userName() << amount << order; - emit loadingStarts(); - DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( collection ); cmd->setLimit( amount ); cmd->setSortOrder( order ); @@ -97,10 +94,8 @@ CollectionFlatModel::removeCollection( const collection_ptr& collection ) { return; // FIXME - disconnect( collection.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - this, SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); - disconnect( collection.data(), SIGNAL( tracksFinished( Tomahawk::collection_ptr ) ), - this, SLOT( onTracksAddingFinished( Tomahawk::collection_ptr ) ) ); + disconnect( collection.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ), + this, SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); QTime timer; timer.start(); @@ -160,56 +155,58 @@ CollectionFlatModel::removeCollection( const collection_ptr& collection ) qDebug() << "Collection removed, time elapsed:" << timer.elapsed(); - emit trackCountChanged( rowCount( QModelIndex() ) ); +// emit trackCountChanged( rowCount( QModelIndex() ) ); } void -CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ) +CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ) { - qDebug() << Q_FUNC_INFO; + qDebug() << Q_FUNC_INFO << tracks.count() << rowCount( QModelIndex() ); - if ( !tracks.count() ) - { - emit trackCountChanged( rowCount( QModelIndex() ) ); - return; - } + bool kickOff = m_tracksToAdd.isEmpty(); + m_tracksToAdd << tracks; + emit trackCountChanged( trackCount() ); + + if ( m_tracksToAdd.count() && kickOff ) + processTracksToAdd(); +} + + +void +CollectionFlatModel::processTracksToAdd() +{ + int chunkSize = 5000; + int maxc = qMin( chunkSize, m_tracksToAdd.count() ); int c = rowCount( QModelIndex() ); - QPair< int, int > crows; - crows.first = c; - crows.second = c + tracks.count() - 1; - emit beginInsertRows( QModelIndex(), crows.first, crows.second ); + emit beginInsertRows( QModelIndex(), c, c + maxc - 1 ); + int i = 0; PlItem* plitem; - foreach( const query_ptr& query, tracks ) + foreach( const query_ptr& query, m_tracksToAdd ) { plitem = new PlItem( query, m_rootItem ); plitem->index = createIndex( m_rootItem->children.count() - 1, 0, plitem ); connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); + + m_tracksToAdd.removeFirst(); + if ( ++i % chunkSize == 0 ) + break; } - m_collectionRows.insertMulti( collection, crows ); emit endInsertRows(); - - emit trackCountChanged( rowCount( QModelIndex() ) ); qDebug() << Q_FUNC_INFO << rowCount( QModelIndex() ); + + if ( m_tracksToAdd.count() ) + QTimer::singleShot( 250, this, SLOT( processTracksToAdd() ) ); } void -CollectionFlatModel::onTracksAddingFinished( const Tomahawk::collection_ptr& collection ) -{ - qDebug() << "Finished loading tracks" << collection->source()->friendlyName(); - - emit loadingFinished(); -} - - -void -CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ) +CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks ) { QList<Tomahawk::query_ptr> t = tracks; for ( int i = rowCount( QModelIndex() ); i >= 0 && t.count(); i-- ) @@ -235,8 +232,8 @@ CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks, j++; } } - - emit trackCountChanged( rowCount( QModelIndex() ) ); + +// emit trackCountChanged( rowCount( QModelIndex() ) ); qDebug() << Q_FUNC_INFO << rowCount( QModelIndex() ); } diff --git a/src/libtomahawk/playlist/collectionflatmodel.h b/src/libtomahawk/playlist/collectionflatmodel.h index 95abdf1ac..f67110332 100644 --- a/src/libtomahawk/playlist/collectionflatmodel.h +++ b/src/libtomahawk/playlist/collectionflatmodel.h @@ -29,6 +29,8 @@ public: int columnCount( const QModelIndex& parent = QModelIndex() ) const; + virtual int trackCount() const { return rowCount( QModelIndex() ) + m_tracksToAdd.count(); } + QVariant data( const QModelIndex& index, int role ) const; QVariant headerData( int section, Qt::Orientation orientation, int role ) const; @@ -45,21 +47,19 @@ signals: void itemSizeChanged( const QModelIndex& index ); - void loadingStarts(); - void loadingFinished(); - private slots: void onDataChanged(); - void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ); - void onTracksAddingFinished( const Tomahawk::collection_ptr& collection ); + void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ); + void onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks ); - void onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ); - void onSourceOffline( const Tomahawk::source_ptr& src ); + void processTracksToAdd(); + private: QMap< Tomahawk::collection_ptr, QPair< int, int > > m_collectionRows; + QList<Tomahawk::query_ptr> m_tracksToAdd; }; #endif // COLLECTIONFLATMODEL_H diff --git a/src/libtomahawk/playlist/playlistmanager.cpp b/src/libtomahawk/playlist/playlistmanager.cpp index cdf7ab594..fca6313a4 100644 --- a/src/libtomahawk/playlist/playlistmanager.cpp +++ b/src/libtomahawk/playlist/playlistmanager.cpp @@ -576,7 +576,12 @@ PlaylistManager::updateView() if ( currentPage()->showStatsBar() && currentPlaylistInterface() ) { emit numTracksChanged( currentPlaylistInterface()->unfilteredTrackCount() ); - emit numShownChanged( currentPlaylistInterface()->trackCount() ); + + if ( !currentPlaylistInterface()->filter().isEmpty() ) + emit numShownChanged( currentPlaylistInterface()->trackCount() ); + else + emit numShownChanged( currentPlaylistInterface()->unfilteredTrackCount() ); + emit repeatModeChanged( currentPlaylistInterface()->repeatMode() ); emit shuffleModeChanged( currentPlaylistInterface()->shuffled() ); emit modeChanged( currentPlaylistInterface()->viewMode() ); @@ -586,7 +591,7 @@ PlaylistManager::updateView() m_queueView->show(); else m_queueView->hide(); - + emit statsAvailable( currentPage()->showStatsBar() ); emit modesAvailable( currentPage()->showModes() ); @@ -687,7 +692,7 @@ PlaylistManager::positionInHistory( ViewPage* page ) const if ( page == m_pageHistory.at( i ) ) return i; } - + return -1; } @@ -747,7 +752,7 @@ PlaylistManager::dynamicPlaylistForInterface( PlaylistInterface* interface ) con return m_dynamicWidgets.key( view ); } } - + return dynplaylist_ptr(); } @@ -769,7 +774,7 @@ PlaylistManager::collectionForInterface( PlaylistInterface* interface ) const return m_collectionAlbumViews.key( view ); } } - + return collection_ptr(); } diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index 660e9a1a7..6f6359537 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -155,10 +155,10 @@ PlaylistModel::append( const Tomahawk::album_ptr& album ) if ( album.isNull() ) return; - connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); + connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ), + SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); - onTracksAdded( album->tracks(), album->collection() ); + onTracksAdded( album->tracks() ); } @@ -168,10 +168,10 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist ) if ( artist.isNull() ) return; - connect( artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), - SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) ); + connect( artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ), + SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); - onTracksAdded( artist->tracks(), artist->collection() ); + onTracksAdded( artist->tracks() ); } @@ -189,14 +189,14 @@ PlaylistModel::insert( unsigned int row, const Tomahawk::query_ptr& query ) void -PlaylistModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ) +PlaylistModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ) { - onTracksInserted( rowCount( QModelIndex() ), tracks, collection ); + onTracksInserted( rowCount( QModelIndex() ), tracks ); } void -PlaylistModel::onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ) +PlaylistModel::onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks ) { if ( !tracks.count() ) { diff --git a/src/libtomahawk/playlist/playlistmodel.h b/src/libtomahawk/playlist/playlistmodel.h index 9a20d7377..ad8be01d5 100644 --- a/src/libtomahawk/playlist/playlistmodel.h +++ b/src/libtomahawk/playlist/playlistmodel.h @@ -37,7 +37,7 @@ public: void loadHistory( const Tomahawk::source_ptr& source, unsigned int amount = 50 ); void clear(); - + void append( const Tomahawk::query_ptr& query ); void append( const Tomahawk::album_ptr& album ); void append( const Tomahawk::artist_ptr& artist ); @@ -61,8 +61,8 @@ private slots: void onRevisionLoaded( Tomahawk::PlaylistRevision revision ); void onPlaylistChanged( bool waitForUpdate = true ); - void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ); - void onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ); + void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ); + void onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks ); private: QList<Tomahawk::plentry_ptr> playlistEntries() const; diff --git a/src/libtomahawk/playlist/trackmodel.h b/src/libtomahawk/playlist/trackmodel.h index f67b6631a..2f001d5b4 100644 --- a/src/libtomahawk/playlist/trackmodel.h +++ b/src/libtomahawk/playlist/trackmodel.h @@ -39,7 +39,7 @@ public: virtual void setTitle( const QString& title ) { m_title = title; } virtual QString description() const { return m_description; } virtual void setDescription( const QString& description ) { m_description = description; } - + virtual int trackCount() const { return rowCount( QModelIndex() ); } virtual int rowCount( const QModelIndex& parent ) const; diff --git a/src/libtomahawk/playlist/trackproxymodel.cpp b/src/libtomahawk/playlist/trackproxymodel.cpp index c6ac1b86b..7d3bbfff6 100644 --- a/src/libtomahawk/playlist/trackproxymodel.cpp +++ b/src/libtomahawk/playlist/trackproxymodel.cpp @@ -137,9 +137,6 @@ TrackProxyModel::siblingItem( int itemsAway ) bool TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const { - if ( filterRegExp().isEmpty() ) - return true; - PlItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) ); if ( !pi ) return false; @@ -147,34 +144,39 @@ TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParen const Tomahawk::query_ptr& q = pi->query(); Tomahawk::result_ptr r; if ( q->numResults() ) - r = q->results().at( 0 ); + r = q->results().first(); + +// if ( !r.isNull() && !r->collection()->source()->isOnline() ) +// return false; + + if ( filterRegExp().isEmpty() ) + return true; QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts ); - bool found = true; - - foreach( const QString& s, sl ) + foreach( QString s, sl ) { + s = s.toLower(); if ( !r.isNull() ) { - if ( !r->artist()->name().contains( s, Qt::CaseInsensitive ) && - !r->album()->name().contains( s, Qt::CaseInsensitive ) && - !r->track() .contains( s, Qt::CaseInsensitive ) ) + if ( !r->artist()->name().toLower().contains( s ) && + !r->album()->name().toLower().contains( s ) && + !r->track().toLower().contains( s ) ) { - found = false; + return false; } } else { - if ( !q->artist().contains( s, Qt::CaseInsensitive ) && - !q->album() .contains( s, Qt::CaseInsensitive ) && - !q->track() .contains( s, Qt::CaseInsensitive ) ) + if ( !q->artist().toLower().contains( s ) && + !q->album().toLower().contains( s ) && + !q->track().toLower().contains( s ) ) { - found = false; + return false; } } } - return found; + return true; } diff --git a/src/libtomahawk/playlist/trackproxymodel.h b/src/libtomahawk/playlist/trackproxymodel.h index 2fbeb0cd7..7faab3086 100644 --- a/src/libtomahawk/playlist/trackproxymodel.h +++ b/src/libtomahawk/playlist/trackproxymodel.h @@ -23,7 +23,7 @@ public: virtual QList<Tomahawk::query_ptr> tracks(); - virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); } + virtual int unfilteredTrackCount() const { return sourceModel()->trackCount(); } virtual int trackCount() const { return rowCount( QModelIndex() ); } virtual void removeIndex( const QModelIndex& index ); diff --git a/src/libtomahawk/query.cpp b/src/libtomahawk/query.cpp index 8eaff3429..55ef56959 100644 --- a/src/libtomahawk/query.cpp +++ b/src/libtomahawk/query.cpp @@ -70,7 +70,8 @@ Query::refreshResults() void Query::onResultStatusChanged() { - qStableSort( m_results.begin(), m_results.end(), Query::resultSorter ); + if ( m_results.count() ) + qStableSort( m_results.begin(), m_results.end(), Query::resultSorter ); checkResults(); emit resultsChanged();