1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-15 10:33:59 +02:00

Switch to using direct GenericSelect command

This commit is contained in:
Leo Franchi
2011-07-31 11:44:23 -04:00
parent 91bdfec734
commit 8e51953427
5 changed files with 178 additions and 98 deletions

View File

@@ -244,7 +244,7 @@ AlbumModel::addCollection( const collection_ptr& collection )
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection ); DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ), connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( onAlbumsAdded( QList<Tomahawk::album_ptr> ) ) ); SLOT( addAlbums( QList<Tomahawk::album_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
@@ -266,7 +266,7 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in
cmd->setSortDescending( true ); cmd->setSortDescending( true );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ), connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( onAlbumsAdded( QList<Tomahawk::album_ptr> ) ) ); SLOT( addAlbums( QList<Tomahawk::album_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
@@ -278,7 +278,7 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in
void void
AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums ) AlbumModel::addAlbums( const QList<Tomahawk::album_ptr>& albums )
{ {
if ( !albums.count() ) if ( !albums.count() )
return; return;
@@ -303,6 +303,15 @@ AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums )
qDebug() << rowCount( QModelIndex() ); qDebug() << rowCount( QModelIndex() );
} }
void
AlbumModel::clear()
{
beginResetModel();
delete m_rootItem;
m_rootItem = new AlbumItem( 0, this );
endResetModel();
}
void void
AlbumModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) AlbumModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )

View File

@@ -66,6 +66,8 @@ public:
void addCollection( const Tomahawk::collection_ptr& collection ); void addCollection( const Tomahawk::collection_ptr& collection );
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order ); void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order );
void clear();
virtual QString title() const { return m_title; } virtual QString title() const { return m_title; }
virtual QString description() const { return m_description; } virtual QString description() const { return m_description; }
virtual void setTitle( const QString& title ) { m_title = title; } virtual void setTitle( const QString& title ) { m_title = title; }
@@ -85,6 +87,8 @@ public slots:
virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {} virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
virtual void setShuffled( bool /*shuffled*/ ) {} virtual void setShuffled( bool /*shuffled*/ ) {}
void addAlbums( const QList<Tomahawk::album_ptr>& albums );
signals: signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled ); void shuffleModeChanged( bool enabled );
@@ -94,7 +98,6 @@ signals:
protected: protected:
private slots: private slots:
void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums );
void onDataChanged(); void onDataChanged();
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );

View File

@@ -26,21 +26,70 @@
#include "dynamic/database/DatabaseGenerator.h" #include "dynamic/database/DatabaseGenerator.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "database/databasecommand_genericselect.h" #include "database/databasecommand_genericselect.h"
#include "widgets/overlaywidget.h"
#define COOLPLAYLIST_GUID "TOMAHAWK_COOLPLAYLISTOHAI_GUID"
using namespace Tomahawk; using namespace Tomahawk;
QString SocialPlaylistWidget::s_popularAlbumsQuery = "SELECT * from album";
QString SocialPlaylistWidget::s_mostPlayedPlaylistsQuery = "asd";
QString SocialPlaylistWidget::s_topForeignTracksQuery = "select track.name, artist.name, count(*) as counter from (select track from playback_log group by track, source), track, artist where track not in (select track from playback_log where source is null group by track) and track.id = track and artist.id = track.artist group by track order by counter desc";
SocialPlaylistWidget::SocialPlaylistWidget ( QWidget* parent ) SocialPlaylistWidget::SocialPlaylistWidget ( QWidget* parent )
: QWidget ( parent ) : QWidget ( parent )
, ui( new Ui_SocialPlaylistWidget ) , ui( new Ui_SocialPlaylistWidget )
, m_coolQuery1Model( new PlaylistModel( this ) ) , m_topForeignTracksModel( 0 )
, m_popularNewAlbumsModel( 0 )
{ {
ui->setupUi( this ); ui->setupUi( this );
ui->playlistView->setPlaylistModel( m_coolQuery1Model );
load(); ui->splitter->setHandleWidth( 1 );
ui->splitter_2->setHandleWidth( 1 );
ui->splitter_2->setStretchFactor( 0, 2 );
ui->splitter_2->setStretchFactor( 0, 1 );
/*
WelcomePlaylistModel* model = new WelcomePlaylistModel( this );
model->setMaxPlaylists( HISTORY_PLAYLIST_ITEMS );
*/
ui->mostPlayedPlaylists->setFrameShape( QFrame::NoFrame );
ui->mostPlayedPlaylists->setAttribute( Qt::WA_MacShowFocusRect, 0 );
ui->newTracksView->setFrameShape( QFrame::NoFrame );
ui->newTracksView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
ui->newAlbumsView->setFrameShape( QFrame::NoFrame );
ui->newAlbumsView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
TomahawkUtils::unmarginLayout( layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout->layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout_2->layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout_3->layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout_4->layout() );
// ui->mostPlayedPlaylists->setItemDelegate( new PlaylistDelegate() );
// ui->mostPlayedPlaylists->setModel( model );
// ui->mostPlayedPlaylists->overlay()->resize( 380, 86 );
// connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) );
m_topForeignTracksModel = new PlaylistModel( ui->newTracksView );
ui->newTracksView->setPlaylistModel( m_topForeignTracksModel );
m_topForeignTracksModel->setStyle( TrackModel::Short );
ui->newTracksView->overlay()->setEnabled( false );
m_popularNewAlbumsModel = new AlbumModel( ui->newAlbumsView );
ui->newAlbumsView->setAlbumModel( m_popularNewAlbumsModel );
// TODO run the genericselect command
// m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime );
/*
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) );
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( updateRecentTracks() ) );
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
connect( AudioEngine::instance() ,SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( updatePlaylists() ), Qt::QueuedConnection );
*/
fetchFromDB();
} }
SocialPlaylistWidget::~SocialPlaylistWidget() SocialPlaylistWidget::~SocialPlaylistWidget()
@@ -49,91 +98,55 @@ SocialPlaylistWidget::~SocialPlaylistWidget()
} }
void void
SocialPlaylistWidget::load() SocialPlaylistWidget::fetchFromDB()
{ {
// Load the pre-baked custom playlists that we are going to show. // Load the pre-baked custom playlists that we are going to show.
// They also might not exist yet if this the first time this is shown, so then we create them. QSharedPointer<DatabaseCommand_GenericSelect> albumsCmd = QSharedPointer<DatabaseCommand_GenericSelect>( new DatabaseCommand_GenericSelect( s_popularAlbumsQuery, DatabaseCommand_GenericSelect::Album, 30, 0 ) );
DatabaseCommand_LoadDynamicPlaylist* cmd = new DatabaseCommand_LoadDynamicPlaylist( SourceList::instance()->getLocal(), COOLPLAYLIST_GUID, 0 ); connect( albumsCmd.data(), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ), this, SLOT( popularAlbumsFetched( QList<Tomahawk::album_ptr> ) ) );
connect( cmd, SIGNAL( dynamicPlaylistLoaded( Tomahawk::dynplaylist_ptr ) ), this, SLOT( dynamicPlaylistLoaded( Tomahawk::dynplaylist_ptr ) ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( albumsCmd ) );
connect( cmd, SIGNAL( done() ), this, SLOT( dynamicPlaylistLoadDone() ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); // QSharedPointer<DatabaseCommand_GenericSelect> plCmd = QSharedPointer<DatabaseCommand_GenericSelect>( new DatabaseCommand_GenericSelect( s_mostPlayedPlaylistsQuery, DatabaseCommand_GenericSelect::, 30, 0 ) );
// connect( albumsCmd.data(), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ), this, SLOT( popularAlbumsFetched( QList<Tomahawk::album_ptr> ) ) );
// Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( albumsCmd ) );
QSharedPointer<DatabaseCommand_GenericSelect> trackCmd = QSharedPointer<DatabaseCommand_GenericSelect>( new DatabaseCommand_GenericSelect( s_topForeignTracksQuery, DatabaseCommand_GenericSelect::Track, 50, 0 ) );
connect( trackCmd.data(), SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( topForeignTracksFetched( QList<Tomahawk::query_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( trackCmd ) );
} }
PlaylistInterface* PlaylistInterface*
SocialPlaylistWidget::playlistInterface() const SocialPlaylistWidget::playlistInterface() const
{ {
return ui->playlistView->proxyModel(); return 0;
} }
/*
void
SocialPlaylistWidget::dynamicPlaylistLoaded ( const dynplaylist_ptr& ptr )
{
m_coolQuery1 = ptr;
tLog() << "SocialPlaylistWidget got dynplaylist loaded with currev: " << m_coolQuery1->currentrevision();
connect( m_coolQuery1.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ), this, SLOT( playlistRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ) );
connect( m_coolQuery1->generator().data(), SIGNAL(generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
connect( m_coolQuery1->generator().data(), SIGNAL(generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
m_coolQuery1->loadRevision( m_coolQuery1->currentrevision() );
}
void
SocialPlaylistWidget::playlistRevisionLoaded( Tomahawk::DynamicPlaylistRevision )
{
m_coolQuery1Model->loadPlaylist( m_coolQuery1 );
m_coolQuery1->resolve();
if ( m_coolQuery1->entries().isEmpty() ) // Generate some
m_coolQuery1->generator()->generate( 30 );
}
void
SocialPlaylistWidget::dynamicPlaylistLoadDone()
{
if ( m_coolQuery1.isNull() ) /// Load failed so we need to create the playlist, doesn't exist yet
{
tLog() << "SocialPlaylistWidget didn't find the magic dynamic playlist, creating!";
createPlaylist();
}
}
void void
SocialPlaylistWidget::createPlaylist() SocialPlaylistWidget::createPlaylist()
{ {
// Ok, lets create our playlist // Ok, lets create our playlist
/**
* select count(*) as counter, track.name, artist.name from (select track from playback_log group by track, source), track, artist where track.id = track and artist.id = track.artist group by track order by counter desc limit 0,20; * select count(*) as counter, track.name, artist.name from (select track from playback_log group by track, source), track, artist where track.id = track and artist.id = track.artist group by track order by counter desc limit 0,20;
s elect count(*) as counter, playback_log.track, track.name, artist.name from playback_log, track, artist where track.id = playback_log.track and artist.id = track.artist group by playback_log.track order by counter desc limit 0,10; * s elect count(*) as counter, playback_log.track, track.name, artist.name from playback_log, track, artist where track.id = playback_log.track and artist.id = track.artist group by playback_log.track order by counter desc limit 0,10; *
select count(*) as counter, track.name, artist.name from (select track from playback_log group by track, source), track, artist where track not in (select track from playback_log where source is null group by track) and track.id = track and artist.id = track.artist group by track order by counter desc limit 0,20; select count(*) as counter, track.name, artist.name from (select track from playback_log group by track, source), track, artist where track not in (select track from playback_log where source is null group by track) and track.id = track and artist.id = track.artist group by track order by counter desc limit 0,20;
select count(*) as counter, track.name, artist.name from (select track from playback_log where source > 0 group by track, source), track, artist where track.id = track and artist.id = track.artist group by track order by counter desc limit 0,20; select count(*) as counter, track.name, artist.name from (select track from playback_log where source > 0 group by track, source), track, artist where track.id = track and artist.id = track.artist group by track order by counter desc limit 0,20;
*/
m_coolQuery1 = DynamicPlaylist::create( SourceList::instance()->getLocal(), COOLPLAYLIST_GUID, "Cool Playlist!", QString(), QString(), Static, false, "database", false ); m_coolQuery1 = DynamicPlaylist::create( SourceList::instance()->getLocal(), COOLPLAYLIST_GUID, "Cool Playlist!", QString(), QString(), Static, false, "database", false );
connect( m_coolQuery1.data(), SIGNAL( created() ), this, SLOT( playlist1Created() ) ); connect( m_coolQuery1.data(), SIGNAL( created() ), this, SLOT( playlist1Created() ) );
}*/
void
SocialPlaylistWidget::popularAlbumsFetched( QList< album_ptr > albums )
{
m_popularNewAlbumsModel->clear();
m_popularNewAlbumsModel->addAlbums( albums );
} }
void void
SocialPlaylistWidget::playlist1Created() SocialPlaylistWidget::topForeignTracksFetched( QList< query_ptr > tracks )
{ {
Q_ASSERT( m_coolQuery1->generator().dynamicCast< DatabaseGenerator >() ); m_topForeignTracksModel->clear();
foreach( const query_ptr& q, tracks )
QString sql = "select track.name, artist.name, count(*) as counter from (select track from playback_log group by track, source), track, artist where track.id = track and artist.id = track.artist group by track order by counter desc"; m_topForeignTracksModel->append( q );
dyncontrol_ptr control = m_coolQuery1->generator().dynamicCast< DatabaseGenerator >()->createControl( sql, DatabaseCommand_GenericSelect::Track, "This is a cool playlist!" );
m_coolQuery1->createNewRevision( uuid() );
connect( m_coolQuery1.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ), this, SLOT( playlistRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ) );
connect( m_coolQuery1->generator().data(), SIGNAL(generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
}
void
SocialPlaylistWidget::tracksGenerated( QList< query_ptr > queries )
{
if ( sender() == m_coolQuery1->generator().data() )
{
tDebug() << "Got generated tracks from playlist, adding" << queries.size() << "tracks";
m_coolQuery1Model->clear();
m_coolQuery1->addEntries( queries, m_coolQuery1->currentrevision() );
}
} }

View File

@@ -38,6 +38,7 @@
#include "playlist/dynamic/DynamicPlaylist.h" #include "playlist/dynamic/DynamicPlaylist.h"
#include "source.h" #include "source.h"
class AlbumModel;
class PlaylistModel; class PlaylistModel;
class TreeModel; class TreeModel;
@@ -72,26 +73,25 @@ signals:
void pixmapChanged( const QPixmap& pixmap ); void pixmapChanged( const QPixmap& pixmap );
private slots: private slots:
void dynamicPlaylistLoaded( const Tomahawk::dynplaylist_ptr& ptr ); void popularAlbumsFetched( QList<Tomahawk::album_ptr> );
void playlistRevisionLoaded ( Tomahawk::DynamicPlaylistRevision ); void topForeignTracksFetched( QList<Tomahawk::query_ptr> );
void tracksGenerated ( QList<Tomahawk::query_ptr> );
void dynamicPlaylistLoadDone();
void playlist1Created();
private: private:
void load(); void fetchFromDB();
void createPlaylist();
Ui_SocialPlaylistWidget *ui; Ui_SocialPlaylistWidget *ui;
PlaylistModel* m_topForeignTracksModel;
AlbumModel* m_popularNewAlbumsModel;
Tomahawk::dynplaylist_ptr m_coolQuery1;
PlaylistModel* m_coolQuery1Model;
QString m_title; QString m_title;
QString m_description; QString m_description;
QString m_longDescription; QString m_longDescription;
QPixmap m_pixmap; QPixmap m_pixmap;
static QString s_popularAlbumsQuery;
static QString s_mostPlayedPlaylistsQuery;
static QString s_topForeignTracksQuery;
}; };
} }

View File

@@ -6,27 +6,72 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>875</width>
<height>300</height> <height>513</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <layout class="QVBoxLayout" name="verticalLayout_4">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>4</number>
</property>
<item> <item>
<widget class="HeaderLabel" name="socialLabel"> <widget class="QSplitter" name="splitter_2">
<property name="text"> <property name="orientation">
<string>Social Stuff!</string> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWidget" name="layoutWidget1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="HeaderLabel" name="label_4">
<property name="text">
<string>Popular New Albums From Your Friends</string>
</property>
</widget>
</item>
<item>
<widget class="AlbumView" name="newAlbumsView"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="HeaderLabel" name="label_2">
<property name="text">
<string>Most Played Playlists</string>
</property>
</widget>
</item>
<item>
<widget class="PlaylistWidget" name="mostPlayedPlaylists"/>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="HeaderLabel" name="label_3">
<property name="text">
<string>Most Played Tracks You Don't Have</string>
</property>
</widget>
</item>
<item>
<widget class="PlaylistView" name="newTracksView">
<property name="minimumSize">
<size>
<width>320</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item>
<widget class="PlaylistView" name="playlistView"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
@@ -40,6 +85,16 @@
<extends>QLabel</extends> <extends>QLabel</extends>
<header location="global">widgets/HeaderLabel.h</header> <header location="global">widgets/HeaderLabel.h</header>
</customwidget> </customwidget>
<customwidget>
<class>AlbumView</class>
<extends>QListView</extends>
<header location="global">playlist/albumview.h</header>
</customwidget>
<customwidget>
<class>PlaylistWidget</class>
<extends>QListWidget</extends>
<header>widgets/welcomewidget.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>