mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 09:04:33 +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
|
||||
Dashboard.cpp
|
||||
NetworkActivityWidget.cpp
|
||||
NetworkActivityWorker.cpp
|
||||
SocialPlaylistWidget.cpp
|
||||
)
|
||||
|
||||
|
@@ -18,13 +18,11 @@
|
||||
|
||||
#include "NetworkActivityWidget_p.h"
|
||||
|
||||
#include "Pipeline.h"
|
||||
#include "audio/AudioEngine.h"
|
||||
#include "database/Database.h"
|
||||
#include "database/DatabaseCommand_NetworkCharts.h"
|
||||
#include "database/DatabaseCommand_TrendingTracks.h"
|
||||
#include "playlist/AlbumItemDelegate.h"
|
||||
// #include "playlist/PlaylistChartItemDelegate.h"
|
||||
#include "playlist/ViewHeader.h"
|
||||
#include "utils/AnimatedSpinner.h"
|
||||
#include "utils/ImageRegistry.h"
|
||||
@@ -32,15 +30,13 @@
|
||||
#include "utils/TomahawkStyle.h"
|
||||
#include "utils/TomahawkUtilsGui.h"
|
||||
#include "widgets/OverlayWidget.h"
|
||||
#include "Pipeline.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QStandardItemModel>
|
||||
#include <QScrollArea>
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
#define NETWORKCHARTS_NUM_TRACKS 20
|
||||
#define TRENDING_TRACKS_NUM 3
|
||||
|
||||
using namespace Tomahawk;
|
||||
using namespace Tomahawk::Widgets;
|
||||
|
||||
@@ -174,15 +170,13 @@ NetworkActivityWidget::NetworkActivityWidget( QWidget* parent )
|
||||
TomahawkUtils::unmarginLayout( layout );
|
||||
}
|
||||
|
||||
{
|
||||
// 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( trendingTracks( QList< QPair< double,Tomahawk::track_ptr > > ) ) );
|
||||
Database::instance()->enqueue( dbcmd_ptr( dbcmd ) );
|
||||
}
|
||||
// Load data in separate thread
|
||||
d->worker = new NetworkActivityWorker();
|
||||
d->worker->moveToThread( d->worker );
|
||||
connect( d->worker, SIGNAL( trendingTracks( QList<Tomahawk::track_ptr> ) ),
|
||||
SLOT( trendingTracks( QList<Tomahawk::track_ptr> ) ), Qt::QueuedConnection);
|
||||
connect( d->worker, SIGNAL( finished() ), d->worker, SLOT( deleteLater() ) );
|
||||
d->worker->start();
|
||||
}
|
||||
|
||||
|
||||
@@ -287,19 +281,11 @@ NetworkActivityWidget::overallCharts( const QList<track_ptr>& tracks )
|
||||
|
||||
|
||||
void
|
||||
NetworkActivityWidget::trendingTracks( const QList<QPair<double, track_ptr> >& _tracks )
|
||||
NetworkActivityWidget::trendingTracks( const QList<track_ptr>& tracks )
|
||||
{
|
||||
Q_D( NetworkActivityWidget );
|
||||
|
||||
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->finishLoading();
|
||||
}
|
||||
|
@@ -19,6 +19,9 @@
|
||||
#ifndef NETWORKACTIVITYWIDGET_H
|
||||
#define NETWORKACTIVITYWIDGET_H
|
||||
|
||||
#define NETWORKCHARTS_NUM_TRACKS 20
|
||||
#define TRENDING_TRACKS_NUM 3
|
||||
|
||||
#include "ViewPage.h"
|
||||
|
||||
#include "WidgetsDllMacro.h"
|
||||
@@ -66,7 +69,7 @@ private slots:
|
||||
void yearlyCharts( 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& );
|
||||
|
||||
|
@@ -22,6 +22,8 @@
|
||||
#include "NetworkActivityWidget.h"
|
||||
#include "ui_NetworkActivityWidget.h"
|
||||
|
||||
#include "NetworkActivityWorker.h"
|
||||
|
||||
class NetworkActivityWidgetPrivate
|
||||
{
|
||||
public:
|
||||
@@ -31,6 +33,7 @@ public:
|
||||
, sortedProxy( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
Tomahawk::Widgets::NetworkActivityWidget* q_ptr;
|
||||
Q_DECLARE_PUBLIC ( Tomahawk::Widgets::NetworkActivityWidget )
|
||||
|
||||
@@ -48,6 +51,7 @@ private:
|
||||
QPointer<PlaylistModel> trendingTracksModel;
|
||||
|
||||
Tomahawk::Widgets::NetworkActivityWidget::ViewType activeView;
|
||||
Tomahawk::NetworkActivityWorker* worker;
|
||||
};
|
||||
|
||||
#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