mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
Add "Hot Playlists" to NetworkActivity
This commit is contained in:
@@ -30,7 +30,9 @@
|
|||||||
#include "utils/TomahawkStyle.h"
|
#include "utils/TomahawkStyle.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "widgets/OverlayWidget.h"
|
#include "widgets/OverlayWidget.h"
|
||||||
|
#include "widgets/PlaylistsModel.h"
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
|
#include "PlaylistDelegate.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
@@ -111,8 +113,6 @@ NetworkActivityWidget::NetworkActivityWidget( QWidget* parent )
|
|||||||
// Trending Tracks
|
// Trending Tracks
|
||||||
{
|
{
|
||||||
d->trendingTracksModel = new PlaylistModel( d->ui->trendingTracksView );
|
d->trendingTracksModel = new PlaylistModel( d->ui->trendingTracksView );
|
||||||
// TODO:
|
|
||||||
// m_tracksModel = new RecentlyPlayedModel( ui->tracksView, HISTORY_TRACK_ITEMS );
|
|
||||||
d->ui->trendingTracksView->proxyModel()->setStyle( PlayableProxyModel::Short );
|
d->ui->trendingTracksView->proxyModel()->setStyle( PlayableProxyModel::Short );
|
||||||
d->ui->trendingTracksView->overlay()->setEnabled( false );
|
d->ui->trendingTracksView->overlay()->setEnabled( false );
|
||||||
d->ui->trendingTracksView->setPlaylistModel( d->trendingTracksModel );
|
d->ui->trendingTracksView->setPlaylistModel( d->trendingTracksModel );
|
||||||
@@ -146,7 +146,7 @@ NetworkActivityWidget::NetworkActivityWidget( QWidget* parent )
|
|||||||
|
|
||||||
// Hot Playlists
|
// Hot Playlists
|
||||||
{
|
{
|
||||||
TomahawkStyle::stylePageFrame( d->ui->hotPlaylistsFrame );
|
TomahawkStyle::stylePageFrame( d->ui->playlistsFrame );
|
||||||
|
|
||||||
QFont f = d->ui->hotPlaylistsLabel->font();
|
QFont f = d->ui->hotPlaylistsLabel->font();
|
||||||
f.setFamily( "Pathway Gothic One" );
|
f.setFamily( "Pathway Gothic One" );
|
||||||
@@ -158,6 +158,31 @@ NetworkActivityWidget::NetworkActivityWidget( QWidget* parent )
|
|||||||
d->ui->hotPlaylistsLabel->setPalette( p );
|
d->ui->hotPlaylistsLabel->setPalette( p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
d->ui->playlistView->setFrameShape( QFrame::NoFrame );
|
||||||
|
d->ui->playlistView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
||||||
|
d->ui->playlistView->setItemDelegate( new PlaylistDelegate() );
|
||||||
|
d->ui->playlistView->overlay()->resize( 380, 86 );
|
||||||
|
d->ui->playlistView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
||||||
|
|
||||||
|
QPalette p = d->ui->playlistView->palette();
|
||||||
|
p.setColor( QPalette::Text, TomahawkStyle::HEADER_TEXT );
|
||||||
|
p.setColor( QPalette::BrightText, TomahawkStyle::HEADER_TEXT );
|
||||||
|
p.setColor( QPalette::Foreground, TomahawkStyle::HEADER_TEXT );
|
||||||
|
p.setColor( QPalette::Highlight, TomahawkStyle::HEADER_TEXT );
|
||||||
|
p.setColor( QPalette::HighlightedText, TomahawkStyle::HEADER_BACKGROUND );
|
||||||
|
|
||||||
|
d->ui->playlistView->setPalette( p );
|
||||||
|
d->ui->playlistView->setMinimumHeight( 400 );
|
||||||
|
d->ui->playlistView->setStyleSheet( "QListView { background-color: transparent; }" );
|
||||||
|
TomahawkStyle::styleScrollBar( d->ui->playlistView->verticalScrollBar() );
|
||||||
|
TomahawkStyle::stylePageFrame( d->ui->playlistsFrame );
|
||||||
|
|
||||||
|
// updatePlaylists();
|
||||||
|
// connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
|
||||||
|
// connect( model, SIGNAL( emptinessChanged( bool ) ), this, SLOT( updatePlaylists() ) );
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
QScrollArea* area = new QScrollArea();
|
QScrollArea* area = new QScrollArea();
|
||||||
area->setWidgetResizable( true );
|
area->setWidgetResizable( true );
|
||||||
@@ -171,18 +196,27 @@ NetworkActivityWidget::NetworkActivityWidget( QWidget* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load data in separate thread
|
// Load data in separate thread
|
||||||
d->worker = new NetworkActivityWorker();
|
d->workerThread = new QThread();
|
||||||
d->worker->moveToThread( d->worker );
|
d->workerThread->start();
|
||||||
|
d->worker = new NetworkActivityWorker( );
|
||||||
|
d->worker->moveToThread( d->workerThread );
|
||||||
connect( d->worker, SIGNAL( trendingTracks( QList<Tomahawk::track_ptr> ) ),
|
connect( d->worker, SIGNAL( trendingTracks( QList<Tomahawk::track_ptr> ) ),
|
||||||
SLOT( trendingTracks( QList<Tomahawk::track_ptr> ) ), Qt::QueuedConnection);
|
SLOT( trendingTracks( QList<Tomahawk::track_ptr> ) ),
|
||||||
connect( d->worker, SIGNAL( finished() ), d->worker, SLOT( deleteLater() ) );
|
Qt::QueuedConnection);
|
||||||
d->worker->start();
|
connect( d->worker, SIGNAL( hotPlaylists(QList<Tomahawk::playlist_ptr>) ),
|
||||||
|
SLOT(hotPlaylists(QList<Tomahawk::playlist_ptr>)),
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
connect( d->worker, SIGNAL( finished() ),
|
||||||
|
d->workerThread, SLOT( quit() ),
|
||||||
|
Qt::QueuedConnection );
|
||||||
|
// connect( d->workerThread, SIGNAL( finished() ), d->workerThread, SLOT( deleteLater() ), Qt::QueuedConnection );
|
||||||
|
// connect( d->workerThread, SIGNAL( destroyed() ), d->worker, SLOT( deleteLater() ), Qt::QueuedConnection );
|
||||||
|
QMetaObject::invokeMethod( d->worker, "run", Qt::QueuedConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NetworkActivityWidget::~NetworkActivityWidget()
|
NetworkActivityWidget::~NetworkActivityWidget()
|
||||||
{
|
{
|
||||||
delete d_ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -279,6 +313,13 @@ NetworkActivityWidget::overallCharts( const QList<track_ptr>& tracks )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWidget::hotPlaylists( const QList<playlist_ptr>& playlists )
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWidget );
|
||||||
|
d->ui->playlistView->setModel( new PlaylistsModel( playlists, this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NetworkActivityWidget::trendingTracks( const QList<track_ptr>& tracks )
|
NetworkActivityWidget::trendingTracks( const QList<track_ptr>& tracks )
|
||||||
@@ -326,7 +367,7 @@ NetworkActivityWidget::fetchYearCharts()
|
|||||||
QDateTime to = QDateTime::currentDateTime();
|
QDateTime to = QDateTime::currentDateTime();
|
||||||
QDateTime yearAgo = to.addYears( -1 );
|
QDateTime yearAgo = to.addYears( -1 );
|
||||||
DatabaseCommand_NetworkCharts* yearCharts = new DatabaseCommand_NetworkCharts( yearAgo, to );
|
DatabaseCommand_NetworkCharts* yearCharts = new DatabaseCommand_NetworkCharts( yearAgo, to );
|
||||||
yearCharts->setLimit( NETWORKCHARTS_NUM_TRACKS );
|
yearCharts->setLimit( numberOfNetworkChartEntries );
|
||||||
connect( yearCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( yearlyCharts( QList<Tomahawk::track_ptr> ) ) );
|
connect( yearCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( yearlyCharts( QList<Tomahawk::track_ptr> ) ) );
|
||||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( yearCharts ) );
|
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( yearCharts ) );
|
||||||
}
|
}
|
||||||
@@ -336,7 +377,7 @@ void
|
|||||||
NetworkActivityWidget::fetchOverallCharts()
|
NetworkActivityWidget::fetchOverallCharts()
|
||||||
{
|
{
|
||||||
DatabaseCommand_NetworkCharts* overallCharts = new DatabaseCommand_NetworkCharts();
|
DatabaseCommand_NetworkCharts* overallCharts = new DatabaseCommand_NetworkCharts();
|
||||||
overallCharts->setLimit( NETWORKCHARTS_NUM_TRACKS );
|
overallCharts->setLimit( numberOfNetworkChartEntries );
|
||||||
connect( overallCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( overallCharts( QList<Tomahawk::track_ptr> ) ) );
|
connect( overallCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( overallCharts( QList<Tomahawk::track_ptr> ) ) );
|
||||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( overallCharts ) );
|
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( overallCharts ) );
|
||||||
}
|
}
|
||||||
@@ -348,7 +389,7 @@ NetworkActivityWidget::fetchWeekCharts()
|
|||||||
QDateTime to = QDateTime::currentDateTime();
|
QDateTime to = QDateTime::currentDateTime();
|
||||||
QDateTime weekAgo = to.addDays( -7 );
|
QDateTime weekAgo = to.addDays( -7 );
|
||||||
DatabaseCommand_NetworkCharts* weekCharts = new DatabaseCommand_NetworkCharts( weekAgo, to );
|
DatabaseCommand_NetworkCharts* weekCharts = new DatabaseCommand_NetworkCharts( weekAgo, to );
|
||||||
weekCharts->setLimit( NETWORKCHARTS_NUM_TRACKS );
|
weekCharts->setLimit( numberOfNetworkChartEntries );
|
||||||
connect( weekCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( weeklyCharts( QList<Tomahawk::track_ptr> ) ) );
|
connect( weekCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( weeklyCharts( QList<Tomahawk::track_ptr> ) ) );
|
||||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( weekCharts ) );
|
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( weekCharts ) );
|
||||||
}
|
}
|
||||||
@@ -360,7 +401,7 @@ NetworkActivityWidget::fetchMonthCharts()
|
|||||||
QDateTime to = QDateTime::currentDateTime();
|
QDateTime to = QDateTime::currentDateTime();
|
||||||
QDateTime monthAgo = to.addMonths( -1 );
|
QDateTime monthAgo = to.addMonths( -1 );
|
||||||
DatabaseCommand_NetworkCharts* monthCharts = new DatabaseCommand_NetworkCharts( monthAgo, to );
|
DatabaseCommand_NetworkCharts* monthCharts = new DatabaseCommand_NetworkCharts( monthAgo, to );
|
||||||
monthCharts->setLimit( NETWORKCHARTS_NUM_TRACKS );
|
monthCharts->setLimit( numberOfNetworkChartEntries );
|
||||||
connect( monthCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( monthlyCharts( QList<Tomahawk::track_ptr> ) ) );
|
connect( monthCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( monthlyCharts( QList<Tomahawk::track_ptr> ) ) );
|
||||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( monthCharts ) );
|
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( monthCharts ) );
|
||||||
}
|
}
|
||||||
|
@@ -19,9 +19,6 @@
|
|||||||
#ifndef NETWORKACTIVITYWIDGET_H
|
#ifndef NETWORKACTIVITYWIDGET_H
|
||||||
#define NETWORKACTIVITYWIDGET_H
|
#define NETWORKACTIVITYWIDGET_H
|
||||||
|
|
||||||
#define NETWORKCHARTS_NUM_TRACKS 20
|
|
||||||
#define TRENDING_TRACKS_NUM 3
|
|
||||||
|
|
||||||
#include "ViewPage.h"
|
#include "ViewPage.h"
|
||||||
|
|
||||||
#include "WidgetsDllMacro.h"
|
#include "WidgetsDllMacro.h"
|
||||||
@@ -61,7 +58,13 @@ public:
|
|||||||
virtual bool isBeingPlayed() const;
|
virtual bool isBeingPlayed() const;
|
||||||
|
|
||||||
virtual bool jumpToCurrentTrack();
|
virtual bool jumpToCurrentTrack();
|
||||||
signals:
|
|
||||||
|
static const uint numberOfHotPlaylists = 3;
|
||||||
|
static const uint numberOfTrendingTracks = 3;
|
||||||
|
static const uint numberOfNetworkChartEntries = 20;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QScopedPointer<NetworkActivityWidgetPrivate> d_ptr;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void weeklyCharts( const QList<Tomahawk::track_ptr>& );
|
void weeklyCharts( const QList<Tomahawk::track_ptr>& );
|
||||||
@@ -69,6 +72,7 @@ private slots:
|
|||||||
void yearlyCharts( const QList<Tomahawk::track_ptr>& );
|
void yearlyCharts( const QList<Tomahawk::track_ptr>& );
|
||||||
void overallCharts( const QList<Tomahawk::track_ptr>& );
|
void overallCharts( const QList<Tomahawk::track_ptr>& );
|
||||||
|
|
||||||
|
void hotPlaylists( const QList<Tomahawk::playlist_ptr>& playlists );
|
||||||
void trendingTracks( const QList< Tomahawk::track_ptr >& tracks );
|
void trendingTracks( const QList< Tomahawk::track_ptr >& tracks );
|
||||||
|
|
||||||
void leftCrumbIndexChanged( const QModelIndex& );
|
void leftCrumbIndexChanged( const QModelIndex& );
|
||||||
@@ -85,11 +89,10 @@ private:
|
|||||||
void showOverallCharts();
|
void showOverallCharts();
|
||||||
|
|
||||||
Q_DECLARE_PRIVATE( NetworkActivityWidget )
|
Q_DECLARE_PRIVATE( NetworkActivityWidget )
|
||||||
NetworkActivityWidgetPrivate* d_ptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // Widgets
|
} // Widgets
|
||||||
|
|
||||||
}; // Tomahawk
|
} // Tomahawk
|
||||||
|
|
||||||
#endif // NETWORKACTIVITYWIDGET_H
|
#endif // NETWORKACTIVITYWIDGET_H
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>875</width>
|
<width>875</width>
|
||||||
<height>520</height>
|
<height>526</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QFrame" name="hotPlaylistsFrame">
|
<widget class="QFrame" name="trendingTracksFrame">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="trendingTracksLabel">
|
<widget class="QLabel" name="trendingTracksLabel">
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QFrame" name="trendingTracksFrame">
|
<widget class="QFrame" name="playlistsFrame">
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::StyledPanel</enum>
|
<enum>QFrame::StyledPanel</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -31,6 +31,7 @@ public:
|
|||||||
: q_ptr ( q )
|
: q_ptr ( q )
|
||||||
, ui( new Ui::NetworkActivityWidget )
|
, ui( new Ui::NetworkActivityWidget )
|
||||||
, sortedProxy( 0 )
|
, sortedProxy( 0 )
|
||||||
|
, workerThread( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ private:
|
|||||||
|
|
||||||
Tomahawk::Widgets::NetworkActivityWidget::ViewType activeView;
|
Tomahawk::Widgets::NetworkActivityWidget::ViewType activeView;
|
||||||
Tomahawk::NetworkActivityWorker* worker;
|
Tomahawk::NetworkActivityWorker* worker;
|
||||||
|
QThread* workerThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETWORKACTIVITYWIDGET_P_H
|
#endif // NETWORKACTIVITYWIDGET_P_H
|
||||||
|
@@ -19,15 +19,19 @@
|
|||||||
#include "NetworkActivityWorker_p.h"
|
#include "NetworkActivityWorker_p.h"
|
||||||
|
|
||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
|
#include "database/DatabaseCommand_CalculatePlaytime.h"
|
||||||
|
#include "database/DatabaseCommand_LoadAllPlaylists.h"
|
||||||
|
#include "database/DatabaseCommand_LoadAllSources.h"
|
||||||
#include "database/DatabaseCommand_TrendingTracks.h"
|
#include "database/DatabaseCommand_TrendingTracks.h"
|
||||||
#include "database/DatabaseImpl.h"
|
#include "database/DatabaseImpl.h"
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "NetworkActivityWidget.h"
|
#include "NetworkActivityWidget.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
|
|
||||||
NetworkActivityWorker::NetworkActivityWorker( QObject* parent )
|
NetworkActivityWorker::NetworkActivityWorker( QObject* parent )
|
||||||
: QThread( parent )
|
: QObject( parent )
|
||||||
, d_ptr( new NetworkActivityWorkerPrivate( this ) )
|
, d_ptr( new NetworkActivityWorkerPrivate( this ) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -41,19 +45,85 @@ NetworkActivityWorker::~NetworkActivityWorker()
|
|||||||
void
|
void
|
||||||
NetworkActivityWorker::run()
|
NetworkActivityWorker::run()
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO;
|
|
||||||
{
|
{
|
||||||
// Load trending tracks
|
// Load trending tracks
|
||||||
qRegisterMetaType< QList< QPair< double,Tomahawk::track_ptr > > >("QList< QPair< double,Tomahawk::track_ptr > >");
|
qRegisterMetaType< QList< QPair< double,Tomahawk::track_ptr > > >("QList< QPair< double,Tomahawk::track_ptr > >");
|
||||||
DatabaseCommand_TrendingTracks* dbcmd = new DatabaseCommand_TrendingTracks();
|
DatabaseCommand_TrendingTracks* dbcmd = new DatabaseCommand_TrendingTracks();
|
||||||
dbcmd->setLimit( TRENDING_TRACKS_NUM );
|
dbcmd->setLimit( Tomahawk::Widgets::NetworkActivityWidget::numberOfTrendingTracks );
|
||||||
connect( dbcmd, SIGNAL( done( QList< QPair< double,Tomahawk::track_ptr > >) ),
|
connect( dbcmd, SIGNAL( done( QList< QPair< double,Tomahawk::track_ptr > >) ),
|
||||||
SLOT( trendingTracksReceived( QList< QPair< double,Tomahawk::track_ptr > > ) ), Qt::QueuedConnection );
|
SLOT( trendingTracksReceived( QList< QPair< double,Tomahawk::track_ptr > > ) ),
|
||||||
|
Qt::QueuedConnection );
|
||||||
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
DatabaseCommand_LoadAllSources* dbcmd = new DatabaseCommand_LoadAllSources();
|
||||||
|
connect( dbcmd, SIGNAL( done( QList<Tomahawk::source_ptr> ) ),
|
||||||
|
SLOT( allSourcesReceived( QList<Tomahawk::source_ptr> ) ),
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start the event loop
|
|
||||||
exec();
|
void
|
||||||
|
NetworkActivityWorker::allPlaylistsReceived( const QList<playlist_ptr>& playlists )
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
d->sourcesToLoad--;
|
||||||
|
d->playlists.append( playlists );
|
||||||
|
|
||||||
|
if ( d->sourcesToLoad == 0 )
|
||||||
|
{
|
||||||
|
// Load all playlist entries
|
||||||
|
foreach( playlist_ptr playlist, d->playlists )
|
||||||
|
{
|
||||||
|
if ( !playlist->loaded() )
|
||||||
|
{
|
||||||
|
d->playlistsRevisionToLoad++;
|
||||||
|
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ),
|
||||||
|
SLOT( revisionLoaded( Tomahawk::PlaylistRevision ) ),
|
||||||
|
Qt::QueuedConnection );
|
||||||
|
playlist->loadRevision();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkRevisionLoadedDone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::allSourcesReceived( const QList<source_ptr>& sources )
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
d->sourcesToLoad = sources.count();
|
||||||
|
|
||||||
|
foreach ( const source_ptr& source, sources)
|
||||||
|
{
|
||||||
|
DatabaseCommand_LoadAllPlaylists* dbcmd = new DatabaseCommand_LoadAllPlaylists( source );
|
||||||
|
connect( dbcmd, SIGNAL( done( QList<Tomahawk::playlist_ptr> ) ),
|
||||||
|
SLOT( allPlaylistsReceived ( QList<Tomahawk::playlist_ptr> ) ),
|
||||||
|
Qt::QueuedConnection );
|
||||||
|
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::playtime( uint playtime )
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
d->playlistCount.insert( playtime, d->playlistStack.pop() );
|
||||||
|
calculateNextPlaylist();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::revisionLoaded(PlaylistRevision revision)
|
||||||
|
{
|
||||||
|
Q_UNUSED( revision );
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
d->playlistsRevisionToLoad--;
|
||||||
|
checkRevisionLoadedDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,13 +145,54 @@ NetworkActivityWorker::trendingTracksReceived( const QList<QPair<double, Tomahaw
|
|||||||
checkDone();
|
checkDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::calculateNextPlaylist()
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
if ( !d->playlistStack.isEmpty() )
|
||||||
|
{
|
||||||
|
DatabaseCommand_CalculatePlaytime* dbcmd = new DatabaseCommand_CalculatePlaytime( d->playlistStack.top(), QDateTime::currentDateTime().addDays( -7 ), QDateTime::currentDateTime() );
|
||||||
|
connect( dbcmd, SIGNAL( done( uint ) ), SLOT( playtime( uint ) ), Qt::QueuedConnection );
|
||||||
|
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d->playlistCount.remove( 0 );
|
||||||
|
QList<playlist_ptr> playlists;
|
||||||
|
QMapIterator<uint, playlist_ptr> iter (d->playlistCount);
|
||||||
|
iter.toBack();
|
||||||
|
while (iter.hasPrevious() && (uint)playlists.size() < Widgets::NetworkActivityWidget::numberOfHotPlaylists )
|
||||||
|
{
|
||||||
|
iter.previous();
|
||||||
|
playlists << iter.value();
|
||||||
|
}
|
||||||
|
emit hotPlaylists( playlists );
|
||||||
|
d->hotPlaylistsDone = true;
|
||||||
|
checkDone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::checkRevisionLoadedDone()
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
if ( d->playlistsRevisionToLoad == 0 )
|
||||||
|
{
|
||||||
|
foreach (playlist_ptr playlist, d->playlists) {
|
||||||
|
d->playlistStack.push( playlist );
|
||||||
|
}
|
||||||
|
calculateNextPlaylist();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NetworkActivityWorker::checkDone()
|
NetworkActivityWorker::checkDone()
|
||||||
{
|
{
|
||||||
Q_D( NetworkActivityWorker );
|
Q_D( NetworkActivityWorker );
|
||||||
if ( d->trendingTracksDone )
|
if ( d->trendingTracksDone && d->hotPlaylistsDone )
|
||||||
{
|
{
|
||||||
quit();
|
emit finished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#ifndef TOMAHAWK_NETWORKACTIVITYWORKER_H
|
#ifndef TOMAHAWK_NETWORKACTIVITYWORKER_H
|
||||||
#define TOMAHAWK_NETWORKACTIVITYWORKER_H
|
#define TOMAHAWK_NETWORKACTIVITYWORKER_H
|
||||||
|
|
||||||
|
#include "Playlist.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -28,27 +29,36 @@ namespace Tomahawk {
|
|||||||
|
|
||||||
class NetworkActivityWorkerPrivate;
|
class NetworkActivityWorkerPrivate;
|
||||||
|
|
||||||
class NetworkActivityWorker : public QThread
|
class NetworkActivityWorker : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit NetworkActivityWorker( QObject *parent = 0 );
|
explicit NetworkActivityWorker( QObject *parent = 0 );
|
||||||
virtual ~NetworkActivityWorker();
|
virtual ~NetworkActivityWorker();
|
||||||
|
|
||||||
|
public slots:
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void trendingTracks( const QList<Tomahawk::track_ptr>& tracks );
|
void trendingTracks( const QList<Tomahawk::track_ptr>& tracks );
|
||||||
|
void hotPlaylists( const QList<Tomahawk::playlist_ptr>& playlists );
|
||||||
|
void finished();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QScopedPointer<NetworkActivityWorkerPrivate> d_ptr;
|
QScopedPointer<NetworkActivityWorkerPrivate> d_ptr;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void allPlaylistsReceived( const QList<Tomahawk::playlist_ptr>& playlists );
|
||||||
|
void allSourcesReceived( const QList< Tomahawk::source_ptr >& sources );
|
||||||
|
void playtime( uint playtime );
|
||||||
|
void revisionLoaded( Tomahawk::PlaylistRevision revision );
|
||||||
void trendingTracksReceived( const QList< QPair< double,Tomahawk::track_ptr > >& tracks );
|
void trendingTracksReceived( const QList< QPair< double,Tomahawk::track_ptr > >& tracks );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE( NetworkActivityWorker )
|
Q_DECLARE_PRIVATE( NetworkActivityWorker )
|
||||||
|
|
||||||
|
void calculateNextPlaylist();
|
||||||
|
void checkRevisionLoadedDone();
|
||||||
void checkDone();
|
void checkDone();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "NetworkActivityWorker.h"
|
#include "NetworkActivityWorker.h"
|
||||||
|
|
||||||
|
#include <QStack>
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -31,6 +33,9 @@ public:
|
|||||||
NetworkActivityWorkerPrivate( NetworkActivityWorker* q )
|
NetworkActivityWorkerPrivate( NetworkActivityWorker* q )
|
||||||
: q_ptr( q )
|
: q_ptr( q )
|
||||||
, trendingTracksDone( false )
|
, trendingTracksDone( false )
|
||||||
|
, hotPlaylistsDone( false )
|
||||||
|
, playlistsRevisionToLoad( 0 )
|
||||||
|
, trackStatsToLoad( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +43,14 @@ public:
|
|||||||
Q_DECLARE_PUBLIC( NetworkActivityWorker )
|
Q_DECLARE_PUBLIC( NetworkActivityWorker )
|
||||||
private:
|
private:
|
||||||
bool trendingTracksDone;
|
bool trendingTracksDone;
|
||||||
|
|
||||||
|
bool hotPlaylistsDone;
|
||||||
|
QList<Tomahawk::playlist_ptr> playlists;
|
||||||
|
uint playlistsRevisionToLoad;
|
||||||
|
uint sourcesToLoad;
|
||||||
|
uint trackStatsToLoad;
|
||||||
|
QStack<playlist_ptr> playlistStack;
|
||||||
|
QMultiMap<uint, playlist_ptr> playlistCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Tomahawk
|
} // Tomahawk
|
||||||
|
@@ -128,36 +128,37 @@ set( libGuiSources
|
|||||||
utils/NetworkAccessManager.cpp
|
utils/NetworkAccessManager.cpp
|
||||||
|
|
||||||
widgets/AnimatedCounterLabel.cpp
|
widgets/AnimatedCounterLabel.cpp
|
||||||
|
widgets/AnimatedSplitter.cpp
|
||||||
widgets/BasicHeader.cpp
|
widgets/BasicHeader.cpp
|
||||||
widgets/FilterHeader.cpp
|
|
||||||
widgets/ScriptCollectionHeader.cpp
|
|
||||||
widgets/Breadcrumb.cpp
|
widgets/Breadcrumb.cpp
|
||||||
widgets/BreadcrumbButton.cpp
|
widgets/BreadcrumbButton.cpp
|
||||||
widgets/CheckDirTree.cpp
|
|
||||||
widgets/QueryLabel.cpp
|
|
||||||
widgets/ImageButton.cpp
|
|
||||||
widgets/StatsGauge.cpp
|
|
||||||
widgets/AnimatedSplitter.cpp
|
|
||||||
widgets/ElidedLabel.cpp
|
|
||||||
widgets/NewPlaylistWidget.cpp
|
|
||||||
widgets/SearchWidget.cpp
|
|
||||||
widgets/SeekSlider.cpp
|
|
||||||
widgets/PlaylistTypeSelectorDialog.cpp
|
|
||||||
widgets/HistoryWidget.cpp
|
|
||||||
widgets/WhatsHotWidget.cpp
|
|
||||||
widgets/NewReleasesWidget.cpp
|
|
||||||
widgets/ChartDataLoader.cpp
|
widgets/ChartDataLoader.cpp
|
||||||
widgets/RecentlyPlayedPlaylistsModel.cpp
|
widgets/CheckDirTree.cpp
|
||||||
widgets/RecentPlaylistsModel.cpp
|
widgets/ComboBox.cpp
|
||||||
widgets/OverlayButton.cpp
|
widgets/ElidedLabel.cpp
|
||||||
widgets/OverlayWidget.cpp
|
widgets/FadingPixmap.cpp
|
||||||
|
widgets/FilterHeader.cpp
|
||||||
widgets/HeaderLabel.cpp
|
widgets/HeaderLabel.cpp
|
||||||
widgets/HeaderWidget.cpp
|
widgets/HeaderWidget.cpp
|
||||||
widgets/ComboBox.cpp
|
widgets/HistoryWidget.cpp
|
||||||
widgets/ToggleButton.cpp
|
widgets/ImageButton.cpp
|
||||||
widgets/FadingPixmap.cpp
|
widgets/NewPlaylistWidget.cpp
|
||||||
|
widgets/NewReleasesWidget.cpp
|
||||||
|
widgets/OverlayButton.cpp
|
||||||
|
widgets/OverlayWidget.cpp
|
||||||
widgets/PlayableCover.cpp
|
widgets/PlayableCover.cpp
|
||||||
|
widgets/PlaylistsModel.cpp
|
||||||
|
widgets/PlaylistTypeSelectorDialog.cpp
|
||||||
|
widgets/QueryLabel.cpp
|
||||||
|
widgets/RecentPlaylistsModel.cpp
|
||||||
|
widgets/RecentlyPlayedPlaylistsModel.cpp
|
||||||
|
widgets/ScriptCollectionHeader.cpp
|
||||||
|
widgets/SearchWidget.cpp
|
||||||
|
widgets/SeekSlider.cpp
|
||||||
widgets/SourceTreePopupDialog.cpp
|
widgets/SourceTreePopupDialog.cpp
|
||||||
|
widgets/StatsGauge.cpp
|
||||||
|
widgets/ToggleButton.cpp
|
||||||
|
widgets/WhatsHotWidget.cpp
|
||||||
widgets/infowidgets/SourceInfoWidget.cpp
|
widgets/infowidgets/SourceInfoWidget.cpp
|
||||||
widgets/infowidgets/ArtistInfoWidget.cpp
|
widgets/infowidgets/ArtistInfoWidget.cpp
|
||||||
widgets/infowidgets/AlbumInfoWidget.cpp
|
widgets/infowidgets/AlbumInfoWidget.cpp
|
||||||
@@ -245,6 +246,7 @@ list(APPEND libSources
|
|||||||
database/DatabaseCommand_AllArtists.cpp
|
database/DatabaseCommand_AllArtists.cpp
|
||||||
database/DatabaseCommand_AllTracks.cpp
|
database/DatabaseCommand_AllTracks.cpp
|
||||||
database/DatabaseCommand_ArtistStats.cpp
|
database/DatabaseCommand_ArtistStats.cpp
|
||||||
|
database/DatabaseCommand_CalculatePlaytime.cpp
|
||||||
database/DatabaseCommand_ClientAuthValid.cpp
|
database/DatabaseCommand_ClientAuthValid.cpp
|
||||||
database/DatabaseCommand_CollectionAttributes.cpp
|
database/DatabaseCommand_CollectionAttributes.cpp
|
||||||
database/DatabaseCommand_CollectionStats.cpp
|
database/DatabaseCommand_CollectionStats.cpp
|
||||||
|
107
src/libtomahawk/database/DatabaseCommand_CalculatePlaytime.cpp
Normal file
107
src/libtomahawk/database/DatabaseCommand_CalculatePlaytime.cpp
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DatabaseCommand_CalculatePlaytime_p.h"
|
||||||
|
|
||||||
|
#include "database/DatabaseImpl.h"
|
||||||
|
#include "Source.h"
|
||||||
|
#include "Track.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
DatabaseCommand_CalculatePlaytime::DatabaseCommand_CalculatePlaytime( const playlist_ptr& playlist, QDateTime from, QDateTime to, QObject* parent )
|
||||||
|
: DatabaseCommand( parent, new DatabaseCommand_CalculatePlaytimePrivate( this , from, to ) )
|
||||||
|
{
|
||||||
|
Q_D( DatabaseCommand_CalculatePlaytime );
|
||||||
|
foreach( plentry_ptr entry, playlist->entries() )
|
||||||
|
{
|
||||||
|
d->tracks.append( entry->query()->track() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DatabaseCommand_CalculatePlaytime::DatabaseCommand_CalculatePlaytime( const track_ptr& track, QDateTime from, QDateTime to, QObject* parent )
|
||||||
|
: DatabaseCommand( parent, new DatabaseCommand_CalculatePlaytimePrivate( this , from, to ) )
|
||||||
|
{
|
||||||
|
Q_D( DatabaseCommand_CalculatePlaytime );
|
||||||
|
d->tracks.append( track );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DatabaseCommand_CalculatePlaytime::DatabaseCommand_CalculatePlaytime( const QList<track_ptr>& tracks, QDateTime from, QDateTime to, QObject* parent )
|
||||||
|
: DatabaseCommand( parent, new DatabaseCommand_CalculatePlaytimePrivate( this , from, to ) )
|
||||||
|
{
|
||||||
|
Q_D( DatabaseCommand_CalculatePlaytime );
|
||||||
|
d->tracks = tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DatabaseCommand_CalculatePlaytime::DatabaseCommand_CalculatePlaytime( const query_ptr& query, QDateTime from, QDateTime to, QObject* parent)
|
||||||
|
: DatabaseCommand( parent, new DatabaseCommand_CalculatePlaytimePrivate( this , from, to ) )
|
||||||
|
{
|
||||||
|
Q_D( DatabaseCommand_CalculatePlaytime );
|
||||||
|
d->tracks.append( query->track() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DatabaseCommand_CalculatePlaytime::DatabaseCommand_CalculatePlaytime( const QList<query_ptr>& queries, QDateTime from, QDateTime to, QObject* parent)
|
||||||
|
: DatabaseCommand( parent, new DatabaseCommand_CalculatePlaytimePrivate( this , from, to ) )
|
||||||
|
{
|
||||||
|
Q_D( DatabaseCommand_CalculatePlaytime );
|
||||||
|
foreach ( query_ptr query, queries )
|
||||||
|
{
|
||||||
|
d->tracks.append( query->track() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DatabaseCommand_CalculatePlaytime::~DatabaseCommand_CalculatePlaytime()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DatabaseCommand_CalculatePlaytime::exec( DatabaseImpl *dbi )
|
||||||
|
{
|
||||||
|
Q_D( DatabaseCommand_CalculatePlaytime );
|
||||||
|
|
||||||
|
// Get all trackIds
|
||||||
|
QStringList trackIds;
|
||||||
|
foreach ( track_ptr track, d->tracks )
|
||||||
|
{
|
||||||
|
trackIds.append( QString::number( track->trackId() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sql = QString(
|
||||||
|
" SELECT SUM(secs_played) "
|
||||||
|
" FROM playback_log "
|
||||||
|
" WHERE track in ( %1 ) AND playtime >= %2 AND playtime <= %3 "
|
||||||
|
).arg( trackIds.join(", ") ).arg( d->from.toTime_t() ).arg( d->to.toTime_t() );
|
||||||
|
|
||||||
|
TomahawkSqlQuery query = dbi->newquery();
|
||||||
|
query.prepare( sql );
|
||||||
|
query.exec();
|
||||||
|
|
||||||
|
uint playtime;
|
||||||
|
while ( query.next() )
|
||||||
|
{
|
||||||
|
playtime = query.value( 0 ).toUInt();
|
||||||
|
}
|
||||||
|
emit done( playtime );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
55
src/libtomahawk/database/DatabaseCommand_CalculatePlaytime.h
Normal file
55
src/libtomahawk/database/DatabaseCommand_CalculatePlaytime.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef TOMAHAWK_DATABASECOMMAND_CALCULATEPLAYTIME_H
|
||||||
|
#define TOMAHAWK_DATABASECOMMAND_CALCULATEPLAYTIME_H
|
||||||
|
|
||||||
|
#include "database/DatabaseCommand.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
class DatabaseCommand_CalculatePlaytimePrivate;
|
||||||
|
|
||||||
|
class DLLEXPORT DatabaseCommand_CalculatePlaytime : public Tomahawk::DatabaseCommand
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DatabaseCommand_CalculatePlaytime( const playlist_ptr& playlist, QDateTime from, QDateTime to, QObject* parent = 0 );
|
||||||
|
explicit DatabaseCommand_CalculatePlaytime( const track_ptr& track, QDateTime from, QDateTime to, QObject* parent = 0 );
|
||||||
|
explicit DatabaseCommand_CalculatePlaytime( const QList<track_ptr>& tracks, QDateTime from, QDateTime to, QObject* parent = 0 );
|
||||||
|
explicit DatabaseCommand_CalculatePlaytime( const query_ptr& query, QDateTime from, QDateTime to, QObject* parent = 0 );
|
||||||
|
explicit DatabaseCommand_CalculatePlaytime( const QList<query_ptr>& queries, QDateTime from, QDateTime to, QObject* parent = 0 );
|
||||||
|
virtual ~DatabaseCommand_CalculatePlaytime();
|
||||||
|
|
||||||
|
virtual void exec( DatabaseImpl* dbi );
|
||||||
|
|
||||||
|
virtual bool doesMutates() const { return false; }
|
||||||
|
virtual QString commandname() const { return "calculateplaytime"; }
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void done( uint playtime );
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DECLARE_PRIVATE( DatabaseCommand_CalculatePlaytime )
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_DATABASECOMMAND_CALCULATEPLAYTIME_H
|
@@ -0,0 +1,50 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef DATABASECOMMAND_CALCULATEPLAYTIME_P_H
|
||||||
|
#define DATABASECOMMAND_CALCULATEPLAYTIME_P_H
|
||||||
|
|
||||||
|
#include "database/DatabaseCommand_p.h"
|
||||||
|
#include "database/DatabaseCommand_CalculatePlaytime.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
class DatabaseCommand_CalculatePlaytimePrivate : public DatabaseCommandPrivate
|
||||||
|
{
|
||||||
|
DatabaseCommand_CalculatePlaytimePrivate( DatabaseCommand_CalculatePlaytime* q, QDateTime _from, QDateTime _to )
|
||||||
|
: DatabaseCommandPrivate( q )
|
||||||
|
, from( _from )
|
||||||
|
, to( _to )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_PUBLIC( DatabaseCommand_CalculatePlaytime )
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDateTime from;
|
||||||
|
QDateTime to;
|
||||||
|
QList<track_ptr> tracks;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DATABASECOMMAND_CALCULATEPLAYTIME_P_H
|
121
src/libtomahawk/widgets/PlaylistsModel.cpp
Normal file
121
src/libtomahawk/widgets/PlaylistsModel.cpp
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PlaylistsModel_p.h"
|
||||||
|
|
||||||
|
#include "widgets/RecentlyPlayedPlaylistsModel.h"
|
||||||
|
#include "Track.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
|
||||||
|
PlaylistsModel::PlaylistsModel( const QList<playlist_ptr>& playlists, QObject* parent )
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
, d_ptr( new PlaylistsModelPrivate( this, playlists ) )
|
||||||
|
{
|
||||||
|
updateArtists();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PlaylistsModel::~PlaylistsModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
PlaylistsModel::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
Q_D( const PlaylistsModel );
|
||||||
|
|
||||||
|
if ( !index.isValid() || !hasIndex( index.row(), index.column(), index.parent() ) )
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
playlist_ptr pl = d->playlists.value( index.row() );
|
||||||
|
switch( role )
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return pl->title();
|
||||||
|
case RecentlyPlayedPlaylistsModel::PlaylistRole:
|
||||||
|
return QVariant::fromValue< Tomahawk::playlist_ptr >( pl );
|
||||||
|
case RecentlyPlayedPlaylistsModel::ArtistRole:
|
||||||
|
{
|
||||||
|
return d->artists[pl];
|
||||||
|
}
|
||||||
|
case RecentlyPlayedPlaylistsModel::PlaylistTypeRole:
|
||||||
|
{
|
||||||
|
if ( !pl.dynamicCast< Tomahawk::DynamicPlaylist >().isNull() )
|
||||||
|
{
|
||||||
|
dynplaylist_ptr dynp = pl.dynamicCast< Tomahawk::DynamicPlaylist >();
|
||||||
|
if ( dynp->mode() == Static )
|
||||||
|
return RecentlyPlayedPlaylistsModel::AutoPlaylist;
|
||||||
|
else if ( dynp->mode() == OnDemand )
|
||||||
|
return RecentlyPlayedPlaylistsModel::Station;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecentlyPlayedPlaylistsModel::StaticPlaylist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case RecentlyPlayedPlaylistsModel::DynamicPlaylistRole:
|
||||||
|
{
|
||||||
|
dynplaylist_ptr dynp = pl.dynamicCast< Tomahawk::DynamicPlaylist >();
|
||||||
|
return QVariant::fromValue< Tomahawk::dynplaylist_ptr >( dynp );
|
||||||
|
}
|
||||||
|
case RecentlyPlayedPlaylistsModel::TrackCountRole:
|
||||||
|
{
|
||||||
|
if ( !pl.dynamicCast< Tomahawk::DynamicPlaylist >().isNull() && pl.dynamicCast< Tomahawk::DynamicPlaylist >()->mode() == OnDemand )
|
||||||
|
return QString( QChar( 0x221E ) );
|
||||||
|
else
|
||||||
|
return pl->entries().count();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
PlaylistsModel::rowCount( const QModelIndex& ) const
|
||||||
|
{
|
||||||
|
Q_D( const PlaylistsModel );
|
||||||
|
return d->playlists.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistsModel::updateArtists()
|
||||||
|
{
|
||||||
|
Q_D( PlaylistsModel );
|
||||||
|
d->artists.clear();
|
||||||
|
|
||||||
|
foreach ( playlist_ptr playlist, d->playlists )
|
||||||
|
{
|
||||||
|
QStringList artists;
|
||||||
|
|
||||||
|
foreach ( const Tomahawk::plentry_ptr& entry, playlist->entries() )
|
||||||
|
{
|
||||||
|
if ( !artists.contains( entry->query()->track()->artist() ) )
|
||||||
|
artists << entry->query()->track()->artist();
|
||||||
|
}
|
||||||
|
|
||||||
|
d->artists[ playlist ] = artists.join( ", " );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
54
src/libtomahawk/widgets/PlaylistsModel.h
Normal file
54
src/libtomahawk/widgets/PlaylistsModel.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef TOMAHAWK_PLAYLISTSMODEL_H
|
||||||
|
#define TOMAHAWK_PLAYLISTSMODEL_H
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
#include "Typedefs.h"
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
class PlaylistsModelPrivate;
|
||||||
|
|
||||||
|
class DLLEXPORT PlaylistsModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit PlaylistsModel( const QList<playlist_ptr>& playlists, QObject* parent = 0 );
|
||||||
|
virtual ~PlaylistsModel();
|
||||||
|
|
||||||
|
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
|
||||||
|
virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QScopedPointer<PlaylistsModelPrivate> d_ptr;
|
||||||
|
|
||||||
|
void updateArtists();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DECLARE_PRIVATE( PlaylistsModel )
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_PLAYLISTSMODEL_H
|
47
src/libtomahawk/widgets/PlaylistsModel_p.h
Normal file
47
src/libtomahawk/widgets/PlaylistsModel_p.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef PLAYLISTSMODEL_P_H
|
||||||
|
#define PLAYLISTSMODEL_P_H
|
||||||
|
|
||||||
|
#include "PlaylistsModel.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
class PlaylistsModelPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PlaylistsModelPrivate( PlaylistsModel* q, const QList<playlist_ptr>& _playlists )
|
||||||
|
: q_ptr( q )
|
||||||
|
, playlists( _playlists )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~PlaylistsModelPrivate() {}
|
||||||
|
|
||||||
|
PlaylistsModel* q_ptr;
|
||||||
|
Q_DECLARE_PUBLIC( PlaylistsModel )
|
||||||
|
private:
|
||||||
|
QList<playlist_ptr> playlists;
|
||||||
|
QMap<playlist_ptr, QString> artists;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PLAYLISTSMODEL_P_H
|
Reference in New Issue
Block a user