mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 17:14:00 +02:00
Move "data mining/aggregation" into its own worker thread
This commit is contained in:
@@ -8,6 +8,7 @@ list(APPEND ${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_SOURCES
|
|||||||
# ViewPages
|
# ViewPages
|
||||||
Dashboard.cpp
|
Dashboard.cpp
|
||||||
NetworkActivityWidget.cpp
|
NetworkActivityWidget.cpp
|
||||||
|
NetworkActivityWorker.cpp
|
||||||
SocialPlaylistWidget.cpp
|
SocialPlaylistWidget.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -18,13 +18,11 @@
|
|||||||
|
|
||||||
#include "NetworkActivityWidget_p.h"
|
#include "NetworkActivityWidget_p.h"
|
||||||
|
|
||||||
#include "Pipeline.h"
|
|
||||||
#include "audio/AudioEngine.h"
|
#include "audio/AudioEngine.h"
|
||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
#include "database/DatabaseCommand_NetworkCharts.h"
|
#include "database/DatabaseCommand_NetworkCharts.h"
|
||||||
#include "database/DatabaseCommand_TrendingTracks.h"
|
#include "database/DatabaseCommand_TrendingTracks.h"
|
||||||
#include "playlist/AlbumItemDelegate.h"
|
#include "playlist/AlbumItemDelegate.h"
|
||||||
// #include "playlist/PlaylistChartItemDelegate.h"
|
|
||||||
#include "playlist/ViewHeader.h"
|
#include "playlist/ViewHeader.h"
|
||||||
#include "utils/AnimatedSpinner.h"
|
#include "utils/AnimatedSpinner.h"
|
||||||
#include "utils/ImageRegistry.h"
|
#include "utils/ImageRegistry.h"
|
||||||
@@ -32,15 +30,13 @@
|
|||||||
#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 "Pipeline.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
#define NETWORKCHARTS_NUM_TRACKS 20
|
|
||||||
#define TRENDING_TRACKS_NUM 3
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
using namespace Tomahawk::Widgets;
|
using namespace Tomahawk::Widgets;
|
||||||
|
|
||||||
@@ -174,15 +170,13 @@ NetworkActivityWidget::NetworkActivityWidget( QWidget* parent )
|
|||||||
TomahawkUtils::unmarginLayout( layout );
|
TomahawkUtils::unmarginLayout( layout );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// Load data in separate thread
|
||||||
// Load trending tracks
|
d->worker = new NetworkActivityWorker();
|
||||||
qRegisterMetaType< QList< QPair< double,Tomahawk::track_ptr > > >("QList< QPair< double,Tomahawk::track_ptr > >");
|
d->worker->moveToThread( d->worker );
|
||||||
DatabaseCommand_TrendingTracks* dbcmd = new DatabaseCommand_TrendingTracks();
|
connect( d->worker, SIGNAL( trendingTracks( QList<Tomahawk::track_ptr> ) ),
|
||||||
dbcmd->setLimit( TRENDING_TRACKS_NUM );
|
SLOT( trendingTracks( QList<Tomahawk::track_ptr> ) ), Qt::QueuedConnection);
|
||||||
connect( dbcmd, SIGNAL( done( QList< QPair< double,Tomahawk::track_ptr > >) ),
|
connect( d->worker, SIGNAL( finished() ), d->worker, SLOT( deleteLater() ) );
|
||||||
SLOT( trendingTracks( QList< QPair< double,Tomahawk::track_ptr > > ) ) );
|
d->worker->start();
|
||||||
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -287,19 +281,11 @@ NetworkActivityWidget::overallCharts( const QList<track_ptr>& tracks )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NetworkActivityWidget::trendingTracks( const QList<QPair<double, track_ptr> >& _tracks )
|
NetworkActivityWidget::trendingTracks( const QList<track_ptr>& tracks )
|
||||||
{
|
{
|
||||||
Q_D( NetworkActivityWidget );
|
Q_D( NetworkActivityWidget );
|
||||||
|
|
||||||
d->trendingTracksModel->startLoading();
|
d->trendingTracksModel->startLoading();
|
||||||
QList<track_ptr> tracks;
|
|
||||||
QList< QPair< double, track_ptr > >::const_iterator iter = _tracks.constBegin();
|
|
||||||
const QList< QPair< double, track_ptr > >::const_iterator end = _tracks.constEnd();
|
|
||||||
for(; iter != end; ++iter)
|
|
||||||
{
|
|
||||||
tracks << iter->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
d->trendingTracksModel->appendTracks( tracks );
|
d->trendingTracksModel->appendTracks( tracks );
|
||||||
d->trendingTracksModel->finishLoading();
|
d->trendingTracksModel->finishLoading();
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,9 @@
|
|||||||
#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"
|
||||||
@@ -66,7 +69,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 trendingTracks( const QList< QPair< double,Tomahawk::track_ptr > >& tracks );
|
void trendingTracks( const QList< Tomahawk::track_ptr >& tracks );
|
||||||
|
|
||||||
void leftCrumbIndexChanged( const QModelIndex& );
|
void leftCrumbIndexChanged( const QModelIndex& );
|
||||||
|
|
||||||
|
@@ -22,6 +22,8 @@
|
|||||||
#include "NetworkActivityWidget.h"
|
#include "NetworkActivityWidget.h"
|
||||||
#include "ui_NetworkActivityWidget.h"
|
#include "ui_NetworkActivityWidget.h"
|
||||||
|
|
||||||
|
#include "NetworkActivityWorker.h"
|
||||||
|
|
||||||
class NetworkActivityWidgetPrivate
|
class NetworkActivityWidgetPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -31,6 +33,7 @@ public:
|
|||||||
, sortedProxy( 0 )
|
, sortedProxy( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Tomahawk::Widgets::NetworkActivityWidget* q_ptr;
|
Tomahawk::Widgets::NetworkActivityWidget* q_ptr;
|
||||||
Q_DECLARE_PUBLIC ( Tomahawk::Widgets::NetworkActivityWidget )
|
Q_DECLARE_PUBLIC ( Tomahawk::Widgets::NetworkActivityWidget )
|
||||||
|
|
||||||
@@ -48,6 +51,7 @@ private:
|
|||||||
QPointer<PlaylistModel> trendingTracksModel;
|
QPointer<PlaylistModel> trendingTracksModel;
|
||||||
|
|
||||||
Tomahawk::Widgets::NetworkActivityWidget::ViewType activeView;
|
Tomahawk::Widgets::NetworkActivityWidget::ViewType activeView;
|
||||||
|
Tomahawk::NetworkActivityWorker* worker;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETWORKACTIVITYWIDGET_P_H
|
#endif // NETWORKACTIVITYWIDGET_P_H
|
||||||
|
88
src/libtomahawk-widgets/NetworkActivityWorker.cpp
Normal file
88
src/libtomahawk-widgets/NetworkActivityWorker.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/* === 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 "NetworkActivityWorker_p.h"
|
||||||
|
|
||||||
|
#include "database/Database.h"
|
||||||
|
#include "database/DatabaseCommand_TrendingTracks.h"
|
||||||
|
#include "database/DatabaseImpl.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "NetworkActivityWidget.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
NetworkActivityWorker::NetworkActivityWorker( QObject* parent )
|
||||||
|
: QThread( parent )
|
||||||
|
, d_ptr( new NetworkActivityWorkerPrivate( this ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NetworkActivityWorker::~NetworkActivityWorker()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::run()
|
||||||
|
{
|
||||||
|
tLog() << Q_FUNC_INFO;
|
||||||
|
{
|
||||||
|
// Load trending tracks
|
||||||
|
qRegisterMetaType< QList< QPair< double,Tomahawk::track_ptr > > >("QList< QPair< double,Tomahawk::track_ptr > >");
|
||||||
|
DatabaseCommand_TrendingTracks* dbcmd = new DatabaseCommand_TrendingTracks();
|
||||||
|
dbcmd->setLimit( TRENDING_TRACKS_NUM );
|
||||||
|
connect( dbcmd, SIGNAL( done( QList< QPair< double,Tomahawk::track_ptr > >) ),
|
||||||
|
SLOT( trendingTracksReceived( QList< QPair< double,Tomahawk::track_ptr > > ) ), Qt::QueuedConnection );
|
||||||
|
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the event loop
|
||||||
|
exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::trendingTracksReceived( const QList<QPair<double, Tomahawk::track_ptr> >& _tracks)
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
d->trendingTracksDone = true;
|
||||||
|
|
||||||
|
QList<track_ptr> tracks;
|
||||||
|
QList< QPair< double, track_ptr > >::const_iterator iter = _tracks.constBegin();
|
||||||
|
const QList< QPair< double, track_ptr > >::const_iterator end = _tracks.constEnd();
|
||||||
|
for(; iter != end; ++iter)
|
||||||
|
{
|
||||||
|
tracks << iter->second;
|
||||||
|
}
|
||||||
|
emit trendingTracks( tracks );
|
||||||
|
|
||||||
|
checkDone();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkActivityWorker::checkDone()
|
||||||
|
{
|
||||||
|
Q_D( NetworkActivityWorker );
|
||||||
|
if ( d->trendingTracksDone )
|
||||||
|
{
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
57
src/libtomahawk-widgets/NetworkActivityWorker.h
Normal file
57
src/libtomahawk-widgets/NetworkActivityWorker.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/* === 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_NETWORKACTIVITYWORKER_H
|
||||||
|
#define TOMAHAWK_NETWORKACTIVITYWORKER_H
|
||||||
|
|
||||||
|
#include "Typedefs.h"
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
class NetworkActivityWorkerPrivate;
|
||||||
|
|
||||||
|
class NetworkActivityWorker : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit NetworkActivityWorker( QObject *parent = 0 );
|
||||||
|
virtual ~NetworkActivityWorker();
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void trendingTracks( const QList<Tomahawk::track_ptr>& tracks );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QScopedPointer<NetworkActivityWorkerPrivate> d_ptr;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void trendingTracksReceived( const QList< QPair< double,Tomahawk::track_ptr > >& tracks );
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DECLARE_PRIVATE( NetworkActivityWorker )
|
||||||
|
|
||||||
|
void checkDone();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_NETWORKACTIVITYWORKER_H
|
45
src/libtomahawk-widgets/NetworkActivityWorker_p.h
Normal file
45
src/libtomahawk-widgets/NetworkActivityWorker_p.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* === 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 NETWORKACTIVITYWORKER_P_H
|
||||||
|
#define NETWORKACTIVITYWORKER_P_H
|
||||||
|
|
||||||
|
#include "NetworkActivityWorker.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
class NetworkActivityWorkerPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NetworkActivityWorkerPrivate( NetworkActivityWorker* q )
|
||||||
|
: q_ptr( q )
|
||||||
|
, trendingTracksDone( false )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkActivityWorker* q_ptr;
|
||||||
|
Q_DECLARE_PUBLIC( NetworkActivityWorker )
|
||||||
|
private:
|
||||||
|
bool trendingTracksDone;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Tomahawk
|
||||||
|
|
||||||
|
#endif // NETWORKACTIVITYWORKER_P_H
|
Reference in New Issue
Block a user