From 3517726d92d9d14f215763a1d3aeb6faa5066af9 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 5 Dec 2011 07:51:24 +0100 Subject: [PATCH] * Basic implementation of artist & album searches. --- .../database/databasecommand_resolve.cpp | 66 +++++++++++++---- .../database/databasecommand_resolve.h | 4 +- src/libtomahawk/database/databaseresolver.cpp | 18 +++++ src/libtomahawk/database/databaseresolver.h | 2 + src/libtomahawk/pipeline.cpp | 58 +++++++++++++++ src/libtomahawk/pipeline.h | 2 + src/libtomahawk/playlist/albumitem.cpp | 24 +++++++ src/libtomahawk/playlist/albumitem.h | 7 +- .../playlist/albumitemdelegate.cpp | 10 ++- src/libtomahawk/playlist/albummodel.cpp | 71 ++++++++++++++++--- src/libtomahawk/playlist/albummodel.h | 1 + src/libtomahawk/playlist/albumview.cpp | 14 +++- src/libtomahawk/playlist/albumview.h | 6 ++ src/libtomahawk/query.cpp | 24 +++++++ src/libtomahawk/query.h | 8 +++ src/libtomahawk/widgets/searchwidget.cpp | 43 +++++++++++ src/libtomahawk/widgets/searchwidget.h | 6 ++ src/libtomahawk/widgets/searchwidget.ui | 28 ++++++-- 18 files changed, 354 insertions(+), 38 deletions(-) diff --git a/src/libtomahawk/database/databasecommand_resolve.cpp b/src/libtomahawk/database/databasecommand_resolve.cpp index 2cd1d07e4..bbedc178d 100644 --- a/src/libtomahawk/database/databasecommand_resolve.cpp +++ b/src/libtomahawk/database/databasecommand_resolve.cpp @@ -185,11 +185,47 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) typedef QPair scorepair_t; // STEP 1 - QList< QPair > artists = lib->searchTable( "artist", m_query->fullTextQuery(), 10 ); - QList< QPair > tracks = lib->searchTable( "track", m_query->fullTextQuery(), 10 ); - QList< QPair > albums = lib->searchTable( "album", m_query->fullTextQuery(), 10 ); + QList< QPair > artistPairs = lib->searchTable( "artist", m_query->fullTextQuery(), 10 ); + QList< QPair > trackPairs = lib->searchTable( "track", m_query->fullTextQuery(), 10 ); + QList< QPair > albumPairs = lib->searchTable( "album", m_query->fullTextQuery(), 10 ); - if ( artists.length() == 0 && tracks.length() == 0 && albums.length() == 0 ) + foreach ( const scorepair_t& artistPair, artistPairs ) + { + TomahawkSqlQuery query = lib->newquery(); + + QString sql = QString( "SELECT name FROM artist WHERE id = %1" ).arg( artistPair.first ); + query.prepare( sql ); + query.exec(); + + QList artistList; + while ( query.next() ) + { + Tomahawk::artist_ptr artist = Tomahawk::Artist::get( artistPair.first, query.value( 0 ).toString() ); + artistList << artist; + } + + emit artists( m_query->id(), artistList ); + } + foreach ( const scorepair_t& albumPair, albumPairs ) + { + TomahawkSqlQuery query = lib->newquery(); + + QString sql = QString( "SELECT album.name, artist.id, artist.name FROM album, artist WHERE artist.id = album.artist AND album.id = %1" ).arg( albumPair.first ); + query.prepare( sql ); + query.exec(); + + QList albumList; + while ( query.next() ) + { + Tomahawk::artist_ptr artist = Tomahawk::Artist::get( query.value( 1 ).toUInt(), query.value( 2 ).toString() ); + Tomahawk::album_ptr album = Tomahawk::Album::get( albumPair.first, query.value( 0 ).toString(), artist ); + albumList << album; + } + + emit albums( m_query->id(), albumList ); + } + + if ( artistPairs.length() == 0 && trackPairs.length() == 0 && albumPairs.length() == 0 ) { qDebug() << "No candidates found in first pass, aborting resolve" << m_query->artist() << m_query->track(); emit results( m_query->id(), res ); @@ -200,12 +236,12 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) TomahawkSqlQuery files_query = lib->newquery(); QStringList artsl, trksl, albsl; - for ( int k = 0; k < artists.count(); k++ ) - artsl.append( QString::number( artists.at( k ).first ) ); - for ( int k = 0; k < tracks.count(); k++ ) - trksl.append( QString::number( tracks.at( k ).first ) ); - for ( int k = 0; k < albums.count(); k++ ) - albsl.append( QString::number( albums.at( k ).first ) ); + for ( int k = 0; k < artistPairs.count(); k++ ) + artsl.append( QString::number( artistPairs.at( k ).first ) ); + for ( int k = 0; k < trackPairs.count(); k++ ) + trksl.append( QString::number( trackPairs.at( k ).first ) ); + for ( int k = 0; k < albumPairs.count(); k++ ) + albsl.append( QString::number( albumPairs.at( k ).first ) ); QString artsToken = QString( "file_join.artist IN (%1)" ).arg( artsl.join( "," ) ); QString trksToken = QString( "file_join.track IN (%1)" ).arg( trksl.join( "," ) ); @@ -227,12 +263,12 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) "track.id = file_join.track AND " "file.id = file_join.file AND " "%1" ) - .arg( tracks.length() > 0 ? trksToken : QString( "0" ) ); + .arg( trackPairs.length() > 0 ? trksToken : QString( "0" ) ); files_query.prepare( sql ); files_query.exec(); - while( files_query.next() ) + while ( files_query.next() ) { source_ptr s; QString url = files_query.value( 0 ).toString(); @@ -270,11 +306,11 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) result->setTrackId( files_query.value( 9 ).toUInt() ); result->setYear( files_query.value( 17 ).toUInt() ); - for ( int k = 0; k < tracks.count(); k++ ) + for ( int k = 0; k < trackPairs.count(); k++ ) { - if ( tracks.at( k ).first == (int)result->trackId() ) + if ( trackPairs.at( k ).first == (int)result->trackId() ) { - result->setScore( tracks.at( k ).second ); + result->setScore( trackPairs.at( k ).second ); break; } } diff --git a/src/libtomahawk/database/databasecommand_resolve.h b/src/libtomahawk/database/databasecommand_resolve.h index 5049ac280..52b8fbe18 100644 --- a/src/libtomahawk/database/databasecommand_resolve.h +++ b/src/libtomahawk/database/databasecommand_resolve.h @@ -41,8 +41,8 @@ public: signals: void results( Tomahawk::QID qid, QList results ); - -public slots: + void albums( Tomahawk::QID qid, QList albums ); + void artists( Tomahawk::QID qid, QList artists ); private: DatabaseCommand_Resolve(); diff --git a/src/libtomahawk/database/databaseresolver.cpp b/src/libtomahawk/database/databaseresolver.cpp index 99e416a07..bb4f6df1d 100644 --- a/src/libtomahawk/database/databaseresolver.cpp +++ b/src/libtomahawk/database/databaseresolver.cpp @@ -40,6 +40,10 @@ DatabaseResolver::resolve( const Tomahawk::query_ptr& query ) connect( cmd, SIGNAL( results( Tomahawk::QID, QList< Tomahawk::result_ptr > ) ), SLOT( gotResults( Tomahawk::QID, QList< Tomahawk::result_ptr > ) ), Qt::QueuedConnection ); + connect( cmd, SIGNAL( albums( Tomahawk::QID, QList< Tomahawk::album_ptr > ) ), + SLOT( gotAlbums( Tomahawk::QID, QList< Tomahawk::album_ptr > ) ), Qt::QueuedConnection ); + connect( cmd, SIGNAL( artists( Tomahawk::QID, QList< Tomahawk::artist_ptr > ) ), + SLOT( gotArtists( Tomahawk::QID, QList< Tomahawk::artist_ptr > ) ), Qt::QueuedConnection ); Database::instance()->enqueue( QSharedPointer( cmd ) ); @@ -55,6 +59,20 @@ DatabaseResolver::gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_p } +void +DatabaseResolver::gotAlbums( const Tomahawk::QID qid, QList< Tomahawk::album_ptr> albums ) +{ + Tomahawk::Pipeline::instance()->reportAlbums( qid, albums ); +} + + +void +DatabaseResolver::gotArtists( const Tomahawk::QID qid, QList< Tomahawk::artist_ptr> artists ) +{ + Tomahawk::Pipeline::instance()->reportArtists( qid, artists ); +} + + QString DatabaseResolver::name() const { diff --git a/src/libtomahawk/database/databaseresolver.h b/src/libtomahawk/database/databaseresolver.h index 7d829029e..ae7b8fc50 100644 --- a/src/libtomahawk/database/databaseresolver.h +++ b/src/libtomahawk/database/databaseresolver.h @@ -41,6 +41,8 @@ public slots: private slots: void gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_ptr> results ); + void gotAlbums( const Tomahawk::QID qid, QList< Tomahawk::album_ptr> albums ); + void gotArtists( const Tomahawk::QID qid, QList< Tomahawk::artist_ptr> artists ); private: int m_weight; diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index 9403003e5..b5a4d89b5 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -286,6 +286,64 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) } +void +Pipeline::reportAlbums( QID qid, const QList< album_ptr >& albums ) +{ + if ( !m_running ) + return; + + if ( !m_qids.contains( qid ) ) + { + tDebug() << "Albums arrived too late for:" << qid; + return; + } + const query_ptr& q = m_qids.value( qid ); + Q_ASSERT( q->isFullTextQuery() ); + + QList< album_ptr > cleanAlbums; + foreach( const album_ptr& r, albums ) + { +// float score = q->howSimilar( r ); + + cleanAlbums << r; + } + + if ( !cleanAlbums.isEmpty() ) + { + q->addAlbums( cleanAlbums ); + } +} + + +void +Pipeline::reportArtists( QID qid, const QList< artist_ptr >& artists ) +{ + if ( !m_running ) + return; + + if ( !m_qids.contains( qid ) ) + { + tDebug() << "Artists arrived too late for:" << qid; + return; + } + const query_ptr& q = m_qids.value( qid ); + Q_ASSERT( q->isFullTextQuery() ); + + QList< artist_ptr > cleanArtists; + foreach( const artist_ptr& r, artists ) + { +// float score = q->howSimilar( r ); + + cleanArtists << r; + } + + if ( !cleanArtists.isEmpty() ) + { + q->addArtists( cleanArtists ); + } +} + + void Pipeline::shuntNext() { diff --git a/src/libtomahawk/pipeline.h b/src/libtomahawk/pipeline.h index 2aaa38a76..8ef9a607b 100644 --- a/src/libtomahawk/pipeline.h +++ b/src/libtomahawk/pipeline.h @@ -52,6 +52,8 @@ public: unsigned int activeQueryCount() const { return m_qidsState.count(); } void reportResults( QID qid, const QList< result_ptr >& results ); + void reportAlbums( QID qid, const QList< album_ptr >& albums ); + void reportArtists( QID qid, const QList< artist_ptr >& artists ); void addExternalResolverFactory( ResolverFactoryFunc resolverFactory ); Tomahawk::ExternalResolver* addScriptResolver( const QString& scriptPath, bool start = true ); diff --git a/src/libtomahawk/playlist/albumitem.cpp b/src/libtomahawk/playlist/albumitem.cpp index bad9eac64..6495472cd 100644 --- a/src/libtomahawk/playlist/albumitem.cpp +++ b/src/libtomahawk/playlist/albumitem.cpp @@ -75,3 +75,27 @@ AlbumItem::AlbumItem( const Tomahawk::album_ptr& album, AlbumItem* parent, int r toberemoved = false; } + + +AlbumItem::AlbumItem( const Tomahawk::artist_ptr& artist, AlbumItem* parent, int row ) + : QObject( parent ) + , m_artist( artist ) +{ + this->parent = parent; + if ( parent ) + { + if ( row < 0 ) + { + parent->children.append( this ); + row = parent->children.count() - 1; + } + else + { + parent->children.insert( row, this ); + } + + this->model = parent->model; + } + + toberemoved = false; +} diff --git a/src/libtomahawk/playlist/albumitem.h b/src/libtomahawk/playlist/albumitem.h index ece235c3e..8b7cb7774 100644 --- a/src/libtomahawk/playlist/albumitem.h +++ b/src/libtomahawk/playlist/albumitem.h @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -36,9 +36,11 @@ public: ~AlbumItem(); explicit AlbumItem( AlbumItem* parent = 0, QAbstractItemModel* model = 0 ); + explicit AlbumItem( const Tomahawk::artist_ptr& artist, AlbumItem* parent = 0, int row = -1 ); explicit AlbumItem( const Tomahawk::album_ptr& album, AlbumItem* parent = 0, int row = -1 ); - const Tomahawk::album_ptr& album() const { return m_album; }; + const Tomahawk::artist_ptr& artist() const { return m_artist; } + const Tomahawk::album_ptr& album() const { return m_album; } void setCover( const QPixmap& cover ) { this->cover = cover; emit dataChanged(); } AlbumItem* parent; @@ -54,6 +56,7 @@ signals: void dataChanged(); private: + Tomahawk::artist_ptr m_artist; Tomahawk::album_ptr m_album; }; diff --git a/src/libtomahawk/playlist/albumitemdelegate.cpp b/src/libtomahawk/playlist/albumitemdelegate.cpp index 4657598e0..54b037b0c 100644 --- a/src/libtomahawk/playlist/albumitemdelegate.cpp +++ b/src/libtomahawk/playlist/albumitemdelegate.cpp @@ -134,8 +134,14 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, QRect textRect = option.rect.adjusted( 0, option.rect.height() - 32, 0, -2 ); + QString name; + if ( !item->album().isNull() ) + name = item->album()->name(); + else if ( !item->artist().isNull() ) + name = item->artist()->name(); + bool oneLiner = false; - if ( item->album()->artist().isNull() ) + if ( item->album().isNull() || item->album()->artist().isNull() ) oneLiner = true; else oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() || @@ -144,7 +150,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, if ( oneLiner ) { to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); - text = painter->fontMetrics().elidedText( item->album()->name(), Qt::ElideRight, textRect.width() - 3 ); + text = painter->fontMetrics().elidedText( name, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); } else diff --git a/src/libtomahawk/playlist/albummodel.cpp b/src/libtomahawk/playlist/albummodel.cpp index 5845855b6..5066c7256 100644 --- a/src/libtomahawk/playlist/albummodel.cpp +++ b/src/libtomahawk/playlist/albummodel.cpp @@ -40,8 +40,6 @@ AlbumModel::AlbumModel( QObject* parent ) , m_rootItem( new AlbumItem( 0, this ) ) , m_overwriteOnAdd( false ) { - qDebug() << Q_FUNC_INFO; - connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); @@ -133,11 +131,16 @@ AlbumModel::data( const QModelIndex& index, int role ) const if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole ) return QVariant(); - const album_ptr& album = entry->album(); + QString name; + if ( !entry->album().isNull() ) + name = entry->album()->name(); + else if ( !entry->artist().isNull() ) + name = entry->artist()->name(); + switch( index.column() ) { case 0: - return album->name(); + return name; break; } @@ -342,6 +345,41 @@ AlbumModel::addAlbums( const QList& albums ) } +void +AlbumModel::addArtists( const QList& artists ) +{ + emit loadingFinished(); + + if ( m_overwriteOnAdd ) + clear(); + + if ( !artists.count() ) + { + emit itemCountChanged( rowCount( QModelIndex() ) ); + return; + } + + int c = rowCount( QModelIndex() ); + QPair< int, int > crows; + crows.first = c; + crows.second = c + artists.count() - 1; + + emit beginInsertRows( QModelIndex(), crows.first, crows.second ); + + AlbumItem* albumitem; + foreach( const artist_ptr& artist, artists ) + { + albumitem = new AlbumItem( artist, m_rootItem ); + albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem ); + + connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); + } + + emit endInsertRows(); + emit itemCountChanged( rowCount( QModelIndex() ) ); +} + + void AlbumModel::onSourceAdded( const Tomahawk::source_ptr& source ) { @@ -374,15 +412,26 @@ AlbumModel::getCover( const QModelIndex& index ) return false; Tomahawk::InfoSystem::InfoStringHash trackInfo; - if ( !item->album()->artist().isNull() ) - trackInfo["artist"] = item->album()->artist()->name(); - trackInfo["album"] = item->album()->name(); - trackInfo["pptr"] = QString::number( (qlonglong)item ); - m_coverHash.insert( (qlonglong)item, index ); - Tomahawk::InfoSystem::InfoRequestData requestData; + + if ( !item->artist().isNull() ) + { + requestData.type = Tomahawk::InfoSystem::InfoArtistImages; + + trackInfo["artist"] = item->artist()->name(); + } + else if ( !item->album().isNull() && !item->album()->artist().isNull() ) + { + requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt; + + trackInfo["artist"] = item->album()->artist()->name(); + trackInfo["album"] = item->album()->name(); + } + + m_coverHash.insert( (qlonglong)item, index ); + trackInfo["pptr"] = QString::number( (qlonglong)item ); + requestData.caller = s_tmInfoIdentifier; - requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt; requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ); requestData.customData = QVariantMap(); diff --git a/src/libtomahawk/playlist/albummodel.h b/src/libtomahawk/playlist/albummodel.h index 099423007..31ae6560a 100644 --- a/src/libtomahawk/playlist/albummodel.h +++ b/src/libtomahawk/playlist/albummodel.h @@ -89,6 +89,7 @@ public slots: virtual void setShuffled( bool /*shuffled*/ ) {} void addAlbums( const QList& albums ); + void addArtists( const QList& artists ); signals: void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); diff --git a/src/libtomahawk/playlist/albumview.cpp b/src/libtomahawk/playlist/albumview.cpp index 9152503b7..cd6d32c62 100644 --- a/src/libtomahawk/playlist/albumview.cpp +++ b/src/libtomahawk/playlist/albumview.cpp @@ -46,6 +46,7 @@ AlbumView::AlbumView( QWidget* parent ) , m_delegate( 0 ) , m_loadingSpinner( new LoadingSpinner( this ) ) , m_overlay( new OverlayWidget( this ) ) + , m_inited( false ) { setDragEnabled( true ); setDropIndicatorShown( false ); @@ -59,6 +60,7 @@ AlbumView::AlbumView( QWidget* parent ) setViewMode( IconMode ); setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); + setAutoFitItems( true ); setProxyModel( new AlbumProxyModel( this ) ); m_timer.setInterval( SCROLL_TIMEOUT ); @@ -129,7 +131,10 @@ AlbumView::onItemActivated( const QModelIndex& index ) // qDebug() << "Result activated:" << item->album()->tracks().first()->toString() << item->album()->tracks().first()->results().first()->url(); // APP->audioEngine()->playItem( item->album().data(), item->album()->tracks().first()->results().first() ); - ViewManager::instance()->show( item->album() ); + if ( !item->album().isNull() ) + ViewManager::instance()->show( item->album() ); + else if ( !item->artist().isNull() ) + ViewManager::instance()->show( item->artist() ); } } @@ -203,7 +208,8 @@ AlbumView::onScrollTimeout() void AlbumView::paintEvent( QPaintEvent* event ) { - QListView::paintEvent( event ); + if ( m_inited ) + QListView::paintEvent( event ); } @@ -212,6 +218,10 @@ AlbumView::resizeEvent( QResizeEvent* event ) { QListView::resizeEvent( event ); + m_inited = true; + if ( !autoFitItems() ) + return; + #ifdef Q_WS_X11 int scrollbar = !verticalScrollBar()->isVisible() ? verticalScrollBar()->rect().width() : 0; #else diff --git a/src/libtomahawk/playlist/albumview.h b/src/libtomahawk/playlist/albumview.h index f453ad4f8..5599b68e5 100644 --- a/src/libtomahawk/playlist/albumview.h +++ b/src/libtomahawk/playlist/albumview.h @@ -46,6 +46,9 @@ public: AlbumProxyModel* proxyModel() const { return m_proxyModel; } // PlaylistItemDelegate* delegate() { return m_delegate; } + bool autoFitItems() const { return m_autoFitItems; } + void setAutoFitItems( bool b ) { m_autoFitItems = b; } + void setAlbumModel( AlbumModel* model ); void setModel( QAbstractItemModel* model ); @@ -83,6 +86,9 @@ private: LoadingSpinner* m_loadingSpinner; OverlayWidget* m_overlay; + bool m_inited; + bool m_autoFitItems; + QTimer m_timer; }; diff --git a/src/libtomahawk/query.cpp b/src/libtomahawk/query.cpp index cdd4cfc43..f9f7a82c4 100644 --- a/src/libtomahawk/query.cpp +++ b/src/libtomahawk/query.cpp @@ -176,6 +176,30 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults ) } +void +Query::addAlbums( const QList< Tomahawk::album_ptr >& newalbums ) +{ + { + QMutexLocker lock( &m_mutex ); + m_albums << newalbums; + } + + emit albumsAdded( newalbums ); +} + + +void +Query::addArtists( const QList< Tomahawk::artist_ptr >& newartists ) +{ + { + QMutexLocker lock( &m_mutex ); + m_artists << newartists; + } + + emit artistsAdded( newartists ); +} + + void Query::refreshResults() { diff --git a/src/libtomahawk/query.h b/src/libtomahawk/query.h index 9939cb4f0..610c28d26 100644 --- a/src/libtomahawk/query.h +++ b/src/libtomahawk/query.h @@ -109,6 +109,9 @@ signals: void resultsAdded( const QList& ); void resultsRemoved( const Tomahawk::result_ptr& ); + void albumsAdded( const QList& ); + void artistsAdded( const QList& ); + void resultsChanged(); void solvedStateChanged( bool state ); void playableStateChanged( bool state ); @@ -119,6 +122,9 @@ public slots: void addResults( const QList< Tomahawk::result_ptr >& ); void removeResult( const Tomahawk::result_ptr& ); + void addAlbums( const QList< Tomahawk::album_ptr >& ); + void addArtists( const QList< Tomahawk::artist_ptr >& ); + void onResolvingFinished(); // resolve if not solved() @@ -141,6 +147,8 @@ private: void updateSortNames(); static int levenshtein( const QString& source, const QString& target ); + QList< Tomahawk::artist_ptr > m_artists; + QList< Tomahawk::album_ptr > m_albums; QList< Tomahawk::result_ptr > m_results; bool m_solved; bool m_playable; diff --git a/src/libtomahawk/widgets/searchwidget.cpp b/src/libtomahawk/widgets/searchwidget.cpp index 208c223bf..c7a547333 100644 --- a/src/libtomahawk/widgets/searchwidget.cpp +++ b/src/libtomahawk/widgets/searchwidget.cpp @@ -25,6 +25,7 @@ #include "sourcelist.h" #include "viewmanager.h" #include "dynamic/widgets/LoadingSpinner.h" +#include "playlist/albummodel.h" #include "playlist/playlistmodel.h" #include "widgets/overlaywidget.h" @@ -45,7 +46,30 @@ SearchWidget::SearchWidget( const QString& search, QWidget* parent ) ui->resultsView->overlay()->setEnabled( false ); ui->resultsView->sortByColumn( PlaylistModel::Score, Qt::DescendingOrder ); + m_albumsModel = new AlbumModel( ui->albumView ); + ui->albumView->setAlbumModel( m_albumsModel ); + + m_artistsModel = new AlbumModel( ui->artistView ); + ui->artistView->setAlbumModel( m_artistsModel ); + + ui->artistView->setAutoFitItems( false ); + ui->albumView->setAutoFitItems( false ); + ui->artistView->setSpacing( 8 ); + ui->albumView->setSpacing( 8 ); + + ui->artistView->proxyModel()->sort( -1 ); + ui->albumView->proxyModel()->sort( -1 ); + TomahawkUtils::unmarginLayout( ui->verticalLayout ); + + ui->artistView->setContentsMargins( 0, 0, 0, 0 ); + ui->artistView->setFrameShape( QFrame::NoFrame ); + ui->artistView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); + + ui->albumView->setContentsMargins( 0, 0, 0, 0 ); + ui->albumView->setFrameShape( QFrame::NoFrame ); + ui->albumView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); + ui->resultsView->setContentsMargins( 0, 0, 0, 0 ); ui->resultsView->setFrameShape( QFrame::NoFrame ); ui->resultsView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); @@ -53,8 +77,13 @@ SearchWidget::SearchWidget( const QString& search, QWidget* parent ) ui->resultsView->loadingSpinner()->fadeIn(); m_queries << Tomahawk::Query::get( search, uuid() ); + ui->splitter_2->setStretchFactor( 0, 0 ); + ui->splitter_2->setStretchFactor( 1, 1 ); + foreach ( const Tomahawk::query_ptr& query, m_queries ) { + connect( query.data(), SIGNAL( artistsAdded( QList ) ), SLOT( onArtistsFound( QList ) ) ); + connect( query.data(), SIGNAL( albumsAdded( QList ) ), SLOT( onAlbumsFound( QList ) ) ); connect( query.data(), SIGNAL( resultsAdded( QList ) ), SLOT( onResultsFound( QList ) ) ); connect( query.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryFinished() ) ); } @@ -103,6 +132,20 @@ SearchWidget::onResultsFound( const QList& results ) } +void +SearchWidget::onAlbumsFound( const QList& albums ) +{ + m_albumsModel->addAlbums( albums ); +} + + +void +SearchWidget::onArtistsFound( const QList& artists ) +{ + m_artistsModel->addArtists( artists ); +} + + void SearchWidget::onQueryFinished() { diff --git a/src/libtomahawk/widgets/searchwidget.h b/src/libtomahawk/widgets/searchwidget.h index 1a0484df4..9c00a3469 100644 --- a/src/libtomahawk/widgets/searchwidget.h +++ b/src/libtomahawk/widgets/searchwidget.h @@ -29,6 +29,7 @@ #include "dllmacro.h" class QPushButton; +class AlbumModel; class PlaylistModel; namespace Ui @@ -64,6 +65,9 @@ signals: private slots: void onResultsFound( const QList& results ); + void onAlbumsFound( const QList& albums ); + void onArtistsFound( const QList& artists ); + void onQueryFinished(); private: @@ -71,6 +75,8 @@ private: QString m_search; + AlbumModel* m_artistsModel; + AlbumModel* m_albumsModel; PlaylistModel* m_resultsModel; QList< Tomahawk::query_ptr > m_queries; }; diff --git a/src/libtomahawk/widgets/searchwidget.ui b/src/libtomahawk/widgets/searchwidget.ui index c259bced0..a8f94ab34 100644 --- a/src/libtomahawk/widgets/searchwidget.ui +++ b/src/libtomahawk/widgets/searchwidget.ui @@ -14,11 +14,26 @@ Qt::TabFocus - - 0 - - + + + Qt::Vertical + + + 1 + + + + Qt::Horizontal + + + 1 + + + + + + @@ -28,6 +43,11 @@ QTreeView
playlist/playlistview.h
+ + AlbumView + QListView +
playlist/albumview.h
+