PageRenderTime 73ms CodeModel.GetById 20ms app.highlight 13ms RepoModel.GetById 37ms app.codeStats 0ms

/src/libtomahawk/widgets/SocialPlaylistWidget.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 153 lines | 69 code | 29 blank | 55 comment | 0 complexity | 0075cf68296c84638141d5e89b02bc01 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *
  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.
 10 *
 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.
 15 *
 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/>.
 18 */
 19
 20#include "SocialPlaylistWidget.h"
 21#include "ui_SocialPlaylistWidget.h"
 22
 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"
 32
 33using namespace Tomahawk;
 34
 35QString SocialPlaylistWidget::s_popularAlbumsQuery = "SELECT * from album";
 36QString SocialPlaylistWidget::s_mostPlayedPlaylistsQuery = "asd";
 37QString 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";
 38
 39SocialPlaylistWidget::SocialPlaylistWidget ( QWidget* parent )
 40    : QWidget( parent )
 41    , ui( new Ui_SocialPlaylistWidget )
 42    , m_topForeignTracksModel( 0 )
 43    , m_popularNewAlbumsModel( 0 )
 44{
 45    ui->setupUi( this );
 46
 47    ui->splitter_2->setStretchFactor( 0, 2 );
 48    ui->splitter_2->setStretchFactor( 0, 1 );
 49
 50    /*
 51    WelcomePlaylistModel* model = new WelcomePlaylistModel( this );
 52    model->setMaxPlaylists( HISTORY_PLAYLIST_ITEMS );
 53    */
 54
 55    ui->mostPlayedPlaylists->setFrameShape( QFrame::NoFrame );
 56    ui->mostPlayedPlaylists->setAttribute( Qt::WA_MacShowFocusRect, 0 );
 57
 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() );
 63
 64//     ui->mostPlayedPlaylists->setItemDelegate( new PlaylistDelegate() );
 65//     ui->mostPlayedPlaylists->setModel( model );
 66//     ui->mostPlayedPlaylists->overlay()->resize( 380, 86 );
 67
 68//     connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) );
 69
 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 );
 74
 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 );
 79/*
 80    m_timer = new QTimer( this );
 81    connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) );
 82
 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 );
 87*/
 88    fetchFromDB();
 89}
 90
 91
 92SocialPlaylistWidget::~SocialPlaylistWidget()
 93{
 94}
 95
 96
 97void
 98SocialPlaylistWidget::fetchFromDB()
 99{
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 ) );
104
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 ) );
108
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 ) );
112}
113
114
115Tomahawk::playlistinterface_ptr
116SocialPlaylistWidget::playlistInterface() const
117{
118    return Tomahawk::playlistinterface_ptr();
119}
120
121
122/*
123void
124SocialPlaylistWidget::createPlaylist()
125{
126    // Ok, lets create our playlist
127
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;
132
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() ) );
135}*/
136
137
138void
139SocialPlaylistWidget::popularAlbumsFetched( QList< album_ptr > albums )
140{
141    m_popularNewAlbumsModel->clear();
142
143    m_popularNewAlbumsModel->appendAlbums( albums );
144}
145
146
147void
148SocialPlaylistWidget::topForeignTracksFetched( QList< query_ptr > tracks )
149{
150    m_topForeignTracksModel->clear();
151
152    m_topForeignTracksModel->appendQueries( tracks );
153}