1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-03 20:57:52 +02:00

* Assert on empty friendlynames.

This commit is contained in:
Christian Muehlhaeuser
2011-11-21 14:46:29 +01:00
parent f6d377275b
commit 633ade23fc
7 changed files with 84 additions and 25 deletions

View File

@@ -35,20 +35,21 @@ DatabaseCommand_addSource::DatabaseCommand_addSource( const QString& username, c
void void
DatabaseCommand_addSource::exec( DatabaseImpl* dbi ) DatabaseCommand_addSource::exec( DatabaseImpl* dbi )
{ {
Q_ASSERT( !m_fname.isEmpty() );
TomahawkSqlQuery query = dbi->newquery(); 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.addBindValue( m_username );
query.exec(); query.exec();
if ( query.next() ) if ( query.next() )
{ {
unsigned int id = query.value( 0 ).toInt(); unsigned int id = query.value( 0 ).toInt();
QString fname = query.value( 1 ).toString();
query.prepare( "UPDATE source SET isonline = 'true', friendlyname = ? WHERE id = ?" ); query.prepare( "UPDATE source SET isonline = 'true', friendlyname = ? WHERE id = ?" );
query.addBindValue( m_fname ); query.addBindValue( m_fname );
query.addBindValue( id ); query.addBindValue( id );
query.exec(); query.exec();
emit done( id, fname ); emit done( id, m_fname );
return; return;
} }

View File

@@ -100,7 +100,7 @@ DatabaseCommand_LoadDynamicPlaylistEntries::exec( DatabaseImpl* dbi )
if( mode == OnDemand ) 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 ); emit done( revisionGuid(), m_islatest, type, controls, true );
} }

View File

@@ -25,6 +25,7 @@
#include "artist.h" #include "artist.h"
#include "albumitem.h" #include "albumitem.h"
#include "source.h" #include "source.h"
#include "sourcelist.h"
#include "database/database.h" #include "database/database.h"
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "utils/logger.h" #include "utils/logger.h"
@@ -247,6 +248,7 @@ AlbumModel::addCollection( const collection_ptr& collection, bool overwrite )
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection ); DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
m_overwriteOnAdd = overwrite; m_overwriteOnAdd = overwrite;
m_collection = collection;
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ), connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( addAlbums( QList<Tomahawk::album_ptr> ) ) ); SLOT( addAlbums( QList<Tomahawk::album_ptr> ) ) );
@@ -255,6 +257,21 @@ AlbumModel::addCollection( const collection_ptr& collection, bool overwrite )
m_title = tr( "All albums from %1" ).arg( collection->source()->friendlyName() ); 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<Tomahawk::source_ptr> 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(); emit loadingStarted();
} }
@@ -318,6 +335,23 @@ AlbumModel::addAlbums( const QList<Tomahawk::album_ptr>& 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 void
AlbumModel::clear() AlbumModel::clear()
{ {

View File

@@ -96,9 +96,13 @@ signals:
void loadingStarted(); void loadingStarted();
void loadingFinished(); void loadingFinished();
private slots: private slots:
void onDataChanged(); void onDataChanged();
void onSourceAdded( const Tomahawk::source_ptr& source );
void onCollectionChanged();
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void infoSystemFinished( QString target ); void infoSystemFinished( QString target );
@@ -110,6 +114,8 @@ private:
QString m_description; QString m_description;
bool m_overwriteOnAdd; bool m_overwriteOnAdd;
Tomahawk::collection_ptr m_collection;
QHash<qlonglong, QPersistentModelIndex> m_coverHash; QHash<qlonglong, QPersistentModelIndex> m_coverHash;
}; };

View File

@@ -26,6 +26,7 @@
#include "playlist/collectionflatmodel.h" #include "playlist/collectionflatmodel.h"
#include "playlist/playlistmodel.h" #include "playlist/playlistmodel.h"
#include "database/database.h"
#include "database/databasecommand_alltracks.h" #include "database/databasecommand_alltracks.h"
#include "database/databasecommand_allalbums.h" #include "database/databasecommand_allalbums.h"
@@ -38,6 +39,7 @@
SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent ) SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::SourceInfoWidget ) , ui( new Ui::SourceInfoWidget )
, m_source( source )
{ {
ui->setupUi( this ); ui->setupUi( this );
@@ -56,7 +58,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
m_recentCollectionModel->setStyle( TrackModel::Short ); m_recentCollectionModel->setStyle( TrackModel::Short );
ui->recentCollectionView->setTrackModel( m_recentCollectionModel ); ui->recentCollectionView->setTrackModel( m_recentCollectionModel );
ui->recentCollectionView->sortByColumn( TrackModel::Age, Qt::DescendingOrder ); 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 = new PlaylistModel( ui->historyView );
m_historyModel->setStyle( TrackModel::Short ); 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<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onLoadedTrackHistory( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
void
SourceInfoWidget::onLoadedTrackHistory( const QList<Tomahawk::query_ptr>& queries )
{
m_recentCollectionModel->clear();
m_recentCollectionModel->append( queries );
}
void void
SourceInfoWidget::onPlaybackFinished( const Tomahawk::query_ptr& query ) SourceInfoWidget::onPlaybackFinished( const Tomahawk::query_ptr& query )
{ {

View File

@@ -60,6 +60,9 @@ protected:
private slots: private slots:
void onPlaybackFinished( const Tomahawk::query_ptr& query ); void onPlaybackFinished( const Tomahawk::query_ptr& query );
void loadTracks();
void onLoadedTrackHistory( const QList<Tomahawk::query_ptr>& queries );
private: private:
Ui::SourceInfoWidget *ui; Ui::SourceInfoWidget *ui;
@@ -67,6 +70,8 @@ private:
PlaylistModel* m_historyModel; PlaylistModel* m_historyModel;
AlbumModel* m_recentAlbumModel; AlbumModel* m_recentAlbumModel;
Tomahawk::source_ptr m_source;
QString m_title; QString m_title;
QString m_description; QString m_description;
QPixmap m_pixmap; QPixmap m_pixmap;

View File

@@ -21,9 +21,9 @@
#include "whatshotwidget_p.h" #include "whatshotwidget_p.h"
#include "ui_whatshotwidget.h" #include "ui_whatshotwidget.h"
#include <QtGui/QPainter> #include <QPainter>
#include <QtGui/QStandardItemModel> #include <QStandardItemModel>
#include <QtGui/QStandardItem> #include <QStandardItem>
#include "viewmanager.h" #include "viewmanager.h"
#include "sourcelist.h" #include "sourcelist.h"
@@ -37,7 +37,7 @@
#include "widgets/overlaywidget.h" #include "widgets/overlaywidget.h"
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "utils/logger.h" #include "utils/logger.h"
#include <pipeline.h> #include "pipeline.h"
#define HISTORY_TRACK_ITEMS 25 #define HISTORY_TRACK_ITEMS 25
#define HISTORY_PLAYLIST_ITEMS 10 #define HISTORY_PLAYLIST_ITEMS 10
@@ -110,6 +110,7 @@ WhatsHotWidget::~WhatsHotWidget()
delete ui; delete ui;
} }
PlaylistInterface* PlaylistInterface*
WhatsHotWidget::playlistInterface() const WhatsHotWidget::playlistInterface() const
{ {
@@ -129,6 +130,7 @@ WhatsHotWidget::isBeingPlayed() const
return false; return false;
} }
bool bool
WhatsHotWidget::jumpToCurrentTrack() WhatsHotWidget::jumpToCurrentTrack()
{ {
@@ -159,15 +161,13 @@ WhatsHotWidget::fetchData()
tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities"; tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities";
} }
void void
WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{ {
if ( requestData.caller != s_whatsHotIdentifier ) if ( requestData.caller != s_whatsHotIdentifier )
{
return; return;
}
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got something...";
if ( !output.canConvert< QVariantMap >() ) if ( !output.canConvert< QVariantMap >() )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: Could not parse output"; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: Could not parse output";
@@ -175,15 +175,11 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
} }
QVariantMap returnedData = output.toMap(); QVariantMap returnedData = output.toMap();
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot::" << returnedData;
switch ( requestData.type ) switch ( requestData.type )
{ {
case InfoSystem::InfoChartCapabilities: case InfoSystem::InfoChartCapabilities:
{ {
tDebug( LOGVERBOSE ) << "WhatsHot:: info chart capabilities";
QStandardItem *rootItem= m_crumbModelLeft->invisibleRootItem(); QStandardItem *rootItem= m_crumbModelLeft->invisibleRootItem();
tDebug( LOGVERBOSE ) << "WhatsHot:: " << returnedData.keys();
QVariantMap defaults; QVariantMap defaults;
if ( returnedData.contains( "defaults" ) ) if ( returnedData.contains( "defaults" ) )
defaults = returnedData.take( "defaults" ).toMap(); defaults = returnedData.take( "defaults" ).toMap();
@@ -191,9 +187,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
foreach ( const QString label, returnedData.keys() ) foreach ( const QString label, returnedData.keys() )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot:: parsing " << label;
QStandardItem *childItem = parseNode( rootItem, label, returnedData[label] ); QStandardItem *childItem = parseNode( rootItem, label, returnedData[label] );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot:: appending" << childItem->text();
rootItem->appendRow(childItem); rootItem->appendRow(childItem);
} }
@@ -204,7 +198,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
QStandardItem* source = rootItem->child( i, 0 ); QStandardItem* source = rootItem->child( i, 0 );
if ( defaultSource.toLower() == source->text().toLower() ) if ( defaultSource.toLower() == source->text().toLower() )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Setting DEFAULT SOURCE:" << source->text();
source->setData( true, Breadcrumb::DefaultRole ); source->setData( true, Breadcrumb::DefaultRole );
} }
@@ -220,7 +213,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
{ {
if ( cur->child( k, 0 )->text() == index ) 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 = cur->child( k, 0 ); // this is the default, drill down into the default to pick the next default
cur->setData( true, Breadcrumb::DefaultRole ); cur->setData( true, Breadcrumb::DefaultRole );
break; break;
@@ -235,6 +227,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
ui->breadCrumbLeft->setModel( m_sortedProxy ); ui->breadCrumbLeft->setModel( m_sortedProxy );
break; break;
} }
case InfoSystem::InfoChart: case InfoSystem::InfoChart:
{ {
if( !returnedData.contains("type") ) 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" ); const QString chartId = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >().value( "chart_id" );
m_queuedFetches.remove( chartId ); m_queuedFetches.remove( chartId );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got chart! " << type << " on " << side;
if( type == "artists" ) if( type == "artists" )
{ {
const QStringList artists = returnedData["artists"].toStringList(); const QStringList artists = returnedData["artists"].toStringList();
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got artists! " << artists.size();
TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft ); TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft );
artistsModel->setColumnStyle( TreeModel::TrackOnly ); artistsModel->setColumnStyle( TreeModel::TrackOnly );
@@ -269,7 +260,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
{ {
QList<album_ptr> al; QList<album_ptr> al;
const QList< Tomahawk::InfoSystem::InfoStringHash > albums = returnedData[ "albums" ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >(); 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 ); AlbumModel* albumModel = new AlbumModel( ui->additionsView );
foreach ( const Tomahawk::InfoSystem::InfoStringHash& album, albums ) foreach ( const Tomahawk::InfoSystem::InfoStringHash& album, albums )
@@ -280,7 +270,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
al << albumPtr; al << albumPtr;
} }
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding albums to model";
albumModel->addAlbums( al ); albumModel->addAlbums( al );
m_albumModels[ chartId ] = albumModel; m_albumModels[ chartId ] = albumModel;
@@ -291,7 +280,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
else if( type == "tracks" ) else if( type == "tracks" )
{ {
const QList< Tomahawk::InfoSystem::InfoStringHash > tracks = returnedData[ "tracks" ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >(); 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 ); PlaylistModel* trackModel = new PlaylistModel( ui->tracksViewLeft );
trackModel->setStyle( TrackModel::Short ); trackModel->setStyle( TrackModel::Short );