1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
4
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
6
* Tomahawk is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Tomahawk is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
20
#include "SocialPlaylistWidget.h"
21
#include "ui_SocialPlaylistWidget.h"
23
#include "database/DatabaseCommand_LoadDynamicPlaylist.h"
24
#include "database/Database.h"
25
#include "SourceList.h"
26
#include "playlist/PlayableModel.h"
27
#include "playlist/dynamic/GeneratorInterface.h"
28
#include "playlist/dynamic/database/DatabaseGenerator.h"
29
#include "utils/Logger.h"
30
#include "database/DatabaseCommand_GenericSelect.h"
31
#include "widgets/OverlayWidget.h"
33
using namespace Tomahawk;
35
QString SocialPlaylistWidget::s_popularAlbumsQuery = "SELECT * from album";
36
QString SocialPlaylistWidget::s_mostPlayedPlaylistsQuery = "asd";
37
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";
39
SocialPlaylistWidget::SocialPlaylistWidget ( QWidget* parent )
41
, ui( new Ui_SocialPlaylistWidget )
42
, m_topForeignTracksModel( 0 )
43
, m_popularNewAlbumsModel( 0 )
47
ui->splitter_2->setStretchFactor( 0, 2 );
48
ui->splitter_2->setStretchFactor( 0, 1 );
51
WelcomePlaylistModel* model = new WelcomePlaylistModel( this );
52
model->setMaxPlaylists( HISTORY_PLAYLIST_ITEMS );
55
ui->mostPlayedPlaylists->setFrameShape( QFrame::NoFrame );
56
ui->mostPlayedPlaylists->setAttribute( Qt::WA_MacShowFocusRect, 0 );
58
TomahawkUtils::unmarginLayout( layout() );
59
TomahawkUtils::unmarginLayout( ui->verticalLayout->layout() );
60
TomahawkUtils::unmarginLayout( ui->verticalLayout_2->layout() );
61
TomahawkUtils::unmarginLayout( ui->verticalLayout_3->layout() );
62
TomahawkUtils::unmarginLayout( ui->verticalLayout_4->layout() );
64
// ui->mostPlayedPlaylists->setItemDelegate( new PlaylistDelegate() );
65
// ui->mostPlayedPlaylists->setModel( model );
66
// ui->mostPlayedPlaylists->overlay()->resize( 380, 86 );
68
// connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) );
70
m_topForeignTracksModel = new PlaylistModel( ui->newTracksView );
71
ui->newTracksView->setPlaylistModel( m_topForeignTracksModel );
72
ui->newTracksView->proxyModel()->setStyle( PlayableProxyModel::Short );
73
ui->newTracksView->overlay()->setEnabled( false );
75
m_popularNewAlbumsModel = new PlayableModel( ui->newAlbumsView );
76
ui->newAlbumsView->setPlayableModel( m_popularNewAlbumsModel );
77
// TODO run the genericselect command
78
// m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime );
80
m_timer = new QTimer( this );
81
connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) );
83
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( updateRecentTracks() ) );
84
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
85
connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
86
connect( AudioEngine::instance() ,SIGNAL( playlistChanged( Tomahawk::playlistinterface_ptr ) ), this, SLOT( updatePlaylists() ), Qt::QueuedConnection );
92
SocialPlaylistWidget::~SocialPlaylistWidget()
98
SocialPlaylistWidget::fetchFromDB()
100
// Load the pre-baked custom playlists that we are going to show.
101
QSharedPointer<DatabaseCommand_GenericSelect> albumsCmd = QSharedPointer<DatabaseCommand_GenericSelect>( new DatabaseCommand_GenericSelect( s_popularAlbumsQuery, DatabaseCommand_GenericSelect::Album, 30, 0 ) );
102
connect( albumsCmd.data(), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ), this, SLOT( popularAlbumsFetched( QList<Tomahawk::album_ptr> ) ) );
103
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( albumsCmd ) );
105
// QSharedPointer<DatabaseCommand_GenericSelect> plCmd = QSharedPointer<DatabaseCommand_GenericSelect>( new DatabaseCommand_GenericSelect( s_mostPlayedPlaylistsQuery, DatabaseCommand_GenericSelect::, 30, 0 ) );
106
// connect( albumsCmd.data(), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ), this, SLOT( popularAlbumsFetched( QList<Tomahawk::album_ptr> ) ) );
107
// Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( albumsCmd ) );
109
QSharedPointer<DatabaseCommand_GenericSelect> trackCmd = QSharedPointer<DatabaseCommand_GenericSelect>( new DatabaseCommand_GenericSelect( s_topForeignTracksQuery, DatabaseCommand_GenericSelect::Track, 50, 0 ) );
110
connect( trackCmd.data(), SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( topForeignTracksFetched( QList<Tomahawk::query_ptr> ) ) );
111
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( trackCmd ) );
115
Tomahawk::playlistinterface_ptr
116
SocialPlaylistWidget::playlistInterface() const
118
return Tomahawk::playlistinterface_ptr();
124
SocialPlaylistWidget::createPlaylist()
126
// Ok, lets create our playlist
128
* 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;
129
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; *
130
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;
131
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;
133
m_coolQuery1 = DynamicPlaylist::create( SourceList::instance()->getLocal(), COOLPLAYLIST_GUID, "Cool Playlist!", QString(), QString(), Static, false, "database", false );
134
connect( m_coolQuery1.data(), SIGNAL( created() ), this, SLOT( playlist1Created() ) );
139
SocialPlaylistWidget::popularAlbumsFetched( QList< album_ptr > albums )
141
m_popularNewAlbumsModel->clear();
143
m_popularNewAlbumsModel->appendAlbums( albums );
148
SocialPlaylistWidget::topForeignTracksFetched( QList< query_ptr > tracks )
150
m_topForeignTracksModel->clear();
152
m_topForeignTracksModel->appendQueries( tracks );