mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
Switch to using direct GenericSelect command
This commit is contained in:
@@ -244,7 +244,7 @@ AlbumModel::addCollection( const collection_ptr& collection )
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
|
||||
|
||||
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 ) );
|
||||
|
||||
@@ -266,7 +266,7 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in
|
||||
cmd->setSortDescending( true );
|
||||
|
||||
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 ) );
|
||||
|
||||
@@ -278,7 +278,7 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in
|
||||
|
||||
|
||||
void
|
||||
AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums )
|
||||
AlbumModel::addAlbums( const QList<Tomahawk::album_ptr>& albums )
|
||||
{
|
||||
if ( !albums.count() )
|
||||
return;
|
||||
@@ -303,6 +303,15 @@ AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums )
|
||||
qDebug() << rowCount( QModelIndex() );
|
||||
}
|
||||
|
||||
void
|
||||
AlbumModel::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
delete m_rootItem;
|
||||
m_rootItem = new AlbumItem( 0, this );
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||
|
@@ -66,6 +66,8 @@ public:
|
||||
void addCollection( const Tomahawk::collection_ptr& collection );
|
||||
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 description() const { return m_description; }
|
||||
virtual void setTitle( const QString& title ) { m_title = title; }
|
||||
@@ -85,6 +87,8 @@ public slots:
|
||||
virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
|
||||
virtual void setShuffled( bool /*shuffled*/ ) {}
|
||||
|
||||
void addAlbums( const QList<Tomahawk::album_ptr>& albums );
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||
void shuffleModeChanged( bool enabled );
|
||||
@@ -94,7 +98,6 @@ signals:
|
||||
protected:
|
||||
|
||||
private slots:
|
||||
void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums );
|
||||
void onDataChanged();
|
||||
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
|
@@ -26,21 +26,70 @@
|
||||
#include "dynamic/database/DatabaseGenerator.h"
|
||||
#include "utils/logger.h"
|
||||
#include "database/databasecommand_genericselect.h"
|
||||
|
||||
#define COOLPLAYLIST_GUID "TOMAHAWK_COOLPLAYLISTOHAI_GUID"
|
||||
#include "widgets/overlaywidget.h"
|
||||
|
||||
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 )
|
||||
: QWidget ( parent )
|
||||
, ui( new Ui_SocialPlaylistWidget )
|
||||
, m_coolQuery1Model( new PlaylistModel( this ) )
|
||||
, m_topForeignTracksModel( 0 )
|
||||
, m_popularNewAlbumsModel( 0 )
|
||||
{
|
||||
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()
|
||||
@@ -49,91 +98,55 @@ SocialPlaylistWidget::~SocialPlaylistWidget()
|
||||
}
|
||||
|
||||
void
|
||||
SocialPlaylistWidget::load()
|
||||
SocialPlaylistWidget::fetchFromDB()
|
||||
{
|
||||
// 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.
|
||||
DatabaseCommand_LoadDynamicPlaylist* cmd = new DatabaseCommand_LoadDynamicPlaylist( SourceList::instance()->getLocal(), COOLPLAYLIST_GUID, 0 );
|
||||
connect( cmd, SIGNAL( dynamicPlaylistLoaded( Tomahawk::dynplaylist_ptr ) ), this, SLOT( dynamicPlaylistLoaded( Tomahawk::dynplaylist_ptr ) ) );
|
||||
connect( cmd, SIGNAL( done() ), this, SLOT( dynamicPlaylistLoadDone() ) );
|
||||
QSharedPointer<DatabaseCommand_GenericSelect> albumsCmd = QSharedPointer<DatabaseCommand_GenericSelect>( new DatabaseCommand_GenericSelect( s_popularAlbumsQuery, DatabaseCommand_GenericSelect::Album, 30, 0 ) );
|
||||
connect( albumsCmd.data(), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ), this, SLOT( popularAlbumsFetched( QList<Tomahawk::album_ptr> ) ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( albumsCmd ) );
|
||||
|
||||
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*
|
||||
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
|
||||
SocialPlaylistWidget::createPlaylist()
|
||||
{
|
||||
// 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;
|
||||
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 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 );
|
||||
connect( m_coolQuery1.data(), SIGNAL( created() ), this, SLOT( playlist1Created() ) );
|
||||
}*/
|
||||
|
||||
void
|
||||
SocialPlaylistWidget::popularAlbumsFetched( QList< album_ptr > albums )
|
||||
{
|
||||
m_popularNewAlbumsModel->clear();
|
||||
|
||||
m_popularNewAlbumsModel->addAlbums( albums );
|
||||
}
|
||||
|
||||
void
|
||||
SocialPlaylistWidget::playlist1Created()
|
||||
SocialPlaylistWidget::topForeignTracksFetched( QList< query_ptr > tracks )
|
||||
{
|
||||
Q_ASSERT( m_coolQuery1->generator().dynamicCast< DatabaseGenerator >() );
|
||||
|
||||
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";
|
||||
|
||||
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() );
|
||||
}
|
||||
m_topForeignTracksModel->clear();
|
||||
foreach( const query_ptr& q, tracks )
|
||||
m_topForeignTracksModel->append( q );
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@
|
||||
#include "playlist/dynamic/DynamicPlaylist.h"
|
||||
#include "source.h"
|
||||
|
||||
class AlbumModel;
|
||||
class PlaylistModel;
|
||||
class TreeModel;
|
||||
|
||||
@@ -72,26 +73,25 @@ signals:
|
||||
void pixmapChanged( const QPixmap& pixmap );
|
||||
|
||||
private slots:
|
||||
void dynamicPlaylistLoaded( const Tomahawk::dynplaylist_ptr& ptr );
|
||||
void playlistRevisionLoaded ( Tomahawk::DynamicPlaylistRevision );
|
||||
void tracksGenerated ( QList<Tomahawk::query_ptr> );
|
||||
void dynamicPlaylistLoadDone();
|
||||
|
||||
void playlist1Created();
|
||||
void popularAlbumsFetched( QList<Tomahawk::album_ptr> );
|
||||
void topForeignTracksFetched( QList<Tomahawk::query_ptr> );
|
||||
|
||||
private:
|
||||
void load();
|
||||
void createPlaylist();
|
||||
void fetchFromDB();
|
||||
|
||||
Ui_SocialPlaylistWidget *ui;
|
||||
PlaylistModel* m_topForeignTracksModel;
|
||||
AlbumModel* m_popularNewAlbumsModel;
|
||||
|
||||
Tomahawk::dynplaylist_ptr m_coolQuery1;
|
||||
PlaylistModel* m_coolQuery1Model;
|
||||
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
QString m_longDescription;
|
||||
QPixmap m_pixmap;
|
||||
|
||||
static QString s_popularAlbumsQuery;
|
||||
static QString s_mostPlayedPlaylistsQuery;
|
||||
static QString s_topForeignTracksQuery;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -6,27 +6,72 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>875</width>
|
||||
<height>513</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="margin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="HeaderLabel" name="socialLabel">
|
||||
<property name="text">
|
||||
<string>Social Stuff!</string>
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</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>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="PlaylistView" name="playlistView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
@@ -40,6 +85,16 @@
|
||||
<extends>QLabel</extends>
|
||||
<header location="global">widgets/HeaderLabel.h</header>
|
||||
</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>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
Reference in New Issue
Block a user