From 633ade23fc20fc4f9dc62cd595a9b414b4927f2c Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 21 Nov 2011 14:46:29 +0100 Subject: [PATCH] * Assert on empty friendlynames. --- .../database/databasecommand_addsource.cpp | 7 ++-- ...basecommand_loaddynamicplaylistentries.cpp | 2 +- src/libtomahawk/playlist/albummodel.cpp | 34 +++++++++++++++++++ src/libtomahawk/playlist/albummodel.h | 6 ++++ .../widgets/infowidgets/sourceinfowidget.cpp | 27 ++++++++++++++- .../widgets/infowidgets/sourceinfowidget.h | 5 +++ src/libtomahawk/widgets/whatshotwidget.cpp | 28 +++++---------- 7 files changed, 84 insertions(+), 25 deletions(-) diff --git a/src/libtomahawk/database/databasecommand_addsource.cpp b/src/libtomahawk/database/databasecommand_addsource.cpp index 58015d0bb..d029dd7b3 100644 --- a/src/libtomahawk/database/databasecommand_addsource.cpp +++ b/src/libtomahawk/database/databasecommand_addsource.cpp @@ -35,20 +35,21 @@ DatabaseCommand_addSource::DatabaseCommand_addSource( const QString& username, c void DatabaseCommand_addSource::exec( DatabaseImpl* dbi ) { + Q_ASSERT( !m_fname.isEmpty() ); + TomahawkSqlQuery query = dbi->newquery(); - query.prepare( "SELECT id, friendlyname FROM source WHERE name = ?" ); + query.prepare( "SELECT id FROM source WHERE name = ?" ); query.addBindValue( m_username ); query.exec(); if ( query.next() ) { unsigned int id = query.value( 0 ).toInt(); - QString fname = query.value( 1 ).toString(); query.prepare( "UPDATE source SET isonline = 'true', friendlyname = ? WHERE id = ?" ); query.addBindValue( m_fname ); query.addBindValue( id ); query.exec(); - emit done( id, fname ); + emit done( id, m_fname ); return; } diff --git a/src/libtomahawk/database/databasecommand_loaddynamicplaylistentries.cpp b/src/libtomahawk/database/databasecommand_loaddynamicplaylistentries.cpp index 4b342cf18..40e87e9c9 100644 --- a/src/libtomahawk/database/databasecommand_loaddynamicplaylistentries.cpp +++ b/src/libtomahawk/database/databasecommand_loaddynamicplaylistentries.cpp @@ -100,7 +100,7 @@ DatabaseCommand_LoadDynamicPlaylistEntries::exec( DatabaseImpl* dbi ) if( mode == OnDemand ) { - Q_ASSERT( m_entrymap.isEmpty() ); // ondemand should have no entry +// Q_ASSERT( m_entrymap.isEmpty() ); // ondemand should have no entry emit done( revisionGuid(), m_islatest, type, controls, true ); } diff --git a/src/libtomahawk/playlist/albummodel.cpp b/src/libtomahawk/playlist/albummodel.cpp index db1f2afbb..44569e246 100644 --- a/src/libtomahawk/playlist/albummodel.cpp +++ b/src/libtomahawk/playlist/albummodel.cpp @@ -25,6 +25,7 @@ #include "artist.h" #include "albumitem.h" #include "source.h" +#include "sourcelist.h" #include "database/database.h" #include "utils/tomahawkutils.h" #include "utils/logger.h" @@ -247,6 +248,7 @@ AlbumModel::addCollection( const collection_ptr& collection, bool overwrite ) DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection ); m_overwriteOnAdd = overwrite; + m_collection = collection; connect( cmd, SIGNAL( albums( QList, QVariant ) ), SLOT( addAlbums( QList ) ) ); @@ -255,6 +257,21 @@ AlbumModel::addCollection( const collection_ptr& collection, bool overwrite ) m_title = tr( "All albums from %1" ).arg( collection->source()->friendlyName() ); + if ( collection.isNull() ) + { + connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); + + QList sources = SourceList::instance()->sources(); + foreach ( const source_ptr& source, sources ) + { + connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); + } + } + else + { + connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); + } + emit loadingStarted(); } @@ -318,6 +335,23 @@ AlbumModel::addAlbums( const QList& albums ) } +void +AlbumModel::onSourceAdded( const Tomahawk::source_ptr& source ) +{ + connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); +} + + +void +AlbumModel::onCollectionChanged() +{ + if ( m_collection ) + addCollection( m_collection, true ); + else + addCollection( m_collection, true ); +} + + void AlbumModel::clear() { diff --git a/src/libtomahawk/playlist/albummodel.h b/src/libtomahawk/playlist/albummodel.h index 6a73124ac..0980d97ba 100644 --- a/src/libtomahawk/playlist/albummodel.h +++ b/src/libtomahawk/playlist/albummodel.h @@ -96,9 +96,13 @@ signals: void loadingStarted(); void loadingFinished(); + private slots: void onDataChanged(); + void onSourceAdded( const Tomahawk::source_ptr& source ); + void onCollectionChanged(); + void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemFinished( QString target ); @@ -110,6 +114,8 @@ private: QString m_description; bool m_overwriteOnAdd; + Tomahawk::collection_ptr m_collection; + QHash m_coverHash; }; diff --git a/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp b/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp index b6e08a513..8aee771ca 100644 --- a/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp @@ -26,6 +26,7 @@ #include "playlist/collectionflatmodel.h" #include "playlist/playlistmodel.h" +#include "database/database.h" #include "database/databasecommand_alltracks.h" #include "database/databasecommand_allalbums.h" @@ -38,6 +39,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent ) : QWidget( parent ) , ui( new Ui::SourceInfoWidget ) + , m_source( source ) { ui->setupUi( this ); @@ -56,7 +58,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* m_recentCollectionModel->setStyle( TrackModel::Short ); ui->recentCollectionView->setTrackModel( m_recentCollectionModel ); ui->recentCollectionView->sortByColumn( TrackModel::Age, Qt::DescendingOrder ); - m_recentCollectionModel->addFilteredCollection( source->collection(), 250, DatabaseCommand_AllTracks::ModificationTime ); + loadTracks(); m_historyModel = new PlaylistModel( ui->historyView ); m_historyModel->setStyle( TrackModel::Short ); @@ -90,6 +92,29 @@ SourceInfoWidget::~SourceInfoWidget() } +void +SourceInfoWidget::loadTracks() +{ + DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_source->collection() ); + cmd->setLimit( 250 ); + cmd->setSortOrder( DatabaseCommand_AllTracks::ModificationTime ); + cmd->setSortDescending( true ); + + connect( cmd, SIGNAL( tracks( QList, QVariant ) ), + SLOT( onLoadedTrackHistory( QList ) ), Qt::QueuedConnection ); + + Database::instance()->enqueue( QSharedPointer( cmd ) ); +} + + +void +SourceInfoWidget::onLoadedTrackHistory( const QList& queries ) +{ + m_recentCollectionModel->clear(); + m_recentCollectionModel->append( queries ); +} + + void SourceInfoWidget::onPlaybackFinished( const Tomahawk::query_ptr& query ) { diff --git a/src/libtomahawk/widgets/infowidgets/sourceinfowidget.h b/src/libtomahawk/widgets/infowidgets/sourceinfowidget.h index 15d9f9188..211052aa2 100644 --- a/src/libtomahawk/widgets/infowidgets/sourceinfowidget.h +++ b/src/libtomahawk/widgets/infowidgets/sourceinfowidget.h @@ -60,6 +60,9 @@ protected: private slots: void onPlaybackFinished( const Tomahawk::query_ptr& query ); + void loadTracks(); + void onLoadedTrackHistory( const QList& queries ); + private: Ui::SourceInfoWidget *ui; @@ -67,6 +70,8 @@ private: PlaylistModel* m_historyModel; AlbumModel* m_recentAlbumModel; + Tomahawk::source_ptr m_source; + QString m_title; QString m_description; QPixmap m_pixmap; diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 9e5717eec..cd4e5cec8 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -21,9 +21,9 @@ #include "whatshotwidget_p.h" #include "ui_whatshotwidget.h" -#include -#include -#include +#include +#include +#include #include "viewmanager.h" #include "sourcelist.h" @@ -37,7 +37,7 @@ #include "widgets/overlaywidget.h" #include "utils/tomahawkutils.h" #include "utils/logger.h" -#include +#include "pipeline.h" #define HISTORY_TRACK_ITEMS 25 #define HISTORY_PLAYLIST_ITEMS 10 @@ -110,6 +110,7 @@ WhatsHotWidget::~WhatsHotWidget() delete ui; } + PlaylistInterface* WhatsHotWidget::playlistInterface() const { @@ -129,6 +130,7 @@ WhatsHotWidget::isBeingPlayed() const return false; } + bool WhatsHotWidget::jumpToCurrentTrack() { @@ -159,15 +161,13 @@ WhatsHotWidget::fetchData() tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities"; } + void WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) { if ( requestData.caller != s_whatsHotIdentifier ) - { return; - } - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got something..."; if ( !output.canConvert< QVariantMap >() ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: Could not parse output"; @@ -175,15 +175,11 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat } QVariantMap returnedData = output.toMap(); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot::" << returnedData; switch ( requestData.type ) { case InfoSystem::InfoChartCapabilities: { - tDebug( LOGVERBOSE ) << "WhatsHot:: info chart capabilities"; QStandardItem *rootItem= m_crumbModelLeft->invisibleRootItem(); - tDebug( LOGVERBOSE ) << "WhatsHot:: " << returnedData.keys(); - QVariantMap defaults; if ( returnedData.contains( "defaults" ) ) defaults = returnedData.take( "defaults" ).toMap(); @@ -191,9 +187,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat foreach ( const QString label, returnedData.keys() ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot:: parsing " << label; QStandardItem *childItem = parseNode( rootItem, label, returnedData[label] ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot:: appending" << childItem->text(); rootItem->appendRow(childItem); } @@ -204,7 +198,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat QStandardItem* source = rootItem->child( i, 0 ); if ( defaultSource.toLower() == source->text().toLower() ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Setting DEFAULT SOURCE:" << source->text(); source->setData( true, Breadcrumb::DefaultRole ); } @@ -220,7 +213,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat { if ( cur->child( k, 0 )->text() == index ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Found DEFAULT ITEM:" << index; cur = cur->child( k, 0 ); // this is the default, drill down into the default to pick the next default cur->setData( true, Breadcrumb::DefaultRole ); break; @@ -235,6 +227,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat ui->breadCrumbLeft->setModel( m_sortedProxy ); break; } + case InfoSystem::InfoChart: { if( !returnedData.contains("type") ) @@ -246,11 +239,9 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat const QString chartId = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >().value( "chart_id" ); m_queuedFetches.remove( chartId ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got chart! " << type << " on " << side; if( type == "artists" ) { const QStringList artists = returnedData["artists"].toStringList(); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got artists! " << artists.size(); TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft ); artistsModel->setColumnStyle( TreeModel::TrackOnly ); @@ -269,7 +260,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat { QList al; const QList< Tomahawk::InfoSystem::InfoStringHash > albums = returnedData[ "albums" ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >(); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got albums! " << albums.size(); AlbumModel* albumModel = new AlbumModel( ui->additionsView ); foreach ( const Tomahawk::InfoSystem::InfoStringHash& album, albums ) @@ -280,7 +270,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat al << albumPtr; } - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding albums to model"; albumModel->addAlbums( al ); m_albumModels[ chartId ] = albumModel; @@ -291,7 +280,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat else if( type == "tracks" ) { const QList< Tomahawk::InfoSystem::InfoStringHash > tracks = returnedData[ "tracks" ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >(); - tDebug( LOGVERBOSE ) << "WhatsHot: got tracks! " << tracks.size(); PlaylistModel* trackModel = new PlaylistModel( ui->tracksViewLeft ); trackModel->setStyle( TrackModel::Short );