mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Add NetworkCharts Database Command
This commit is contained in:
@@ -280,6 +280,7 @@ list(APPEND libSources
|
|||||||
database/DatabaseCommand_ShareTrack.cpp
|
database/DatabaseCommand_ShareTrack.cpp
|
||||||
database/DatabaseCommand_DeleteInboxEntry.cpp
|
database/DatabaseCommand_DeleteInboxEntry.cpp
|
||||||
database/DatabaseCommand_ModifyInboxEntry.cpp
|
database/DatabaseCommand_ModifyInboxEntry.cpp
|
||||||
|
database/DatabaseCommand_NetworkCharts.cpp
|
||||||
database/Database.cpp
|
database/Database.cpp
|
||||||
database/TomahawkSqlQuery.cpp
|
database/TomahawkSqlQuery.cpp
|
||||||
database/IdThreadWorker.cpp
|
database/IdThreadWorker.cpp
|
||||||
|
74
src/libtomahawk/database/DatabaseCommand_NetworkCharts.cpp
Normal file
74
src/libtomahawk/database/DatabaseCommand_NetworkCharts.cpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/* === 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_NetworkCharts.h"
|
||||||
|
|
||||||
|
#include "Track.h"
|
||||||
|
#include "DatabaseImpl.h"
|
||||||
|
#include "TomahawkSqlQuery.h"
|
||||||
|
|
||||||
|
DatabaseCommand_NetworkCharts::DatabaseCommand_NetworkCharts( const QDateTime &from, const QDateTime &to, QObject *parent )
|
||||||
|
: DatabaseCommand( parent )
|
||||||
|
, m_amount( 0 )
|
||||||
|
, m_from( from )
|
||||||
|
, m_to( to )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DatabaseCommand_NetworkCharts::~DatabaseCommand_NetworkCharts()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DatabaseCommand_NetworkCharts::exec( DatabaseImpl * dbi )
|
||||||
|
{
|
||||||
|
TomahawkSqlQuery query = dbi->newquery();
|
||||||
|
|
||||||
|
QString limit;
|
||||||
|
if ( m_amount > 0 )
|
||||||
|
{
|
||||||
|
limit = QString( "LIMIT 0, %1" ).arg( m_amount );
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sql = QString(
|
||||||
|
"SELECT COUNT(*) as counter, track.name, artist.name "
|
||||||
|
" FROM playback_log, track, artist "
|
||||||
|
" WHERE track.id = playback_log.track AND artist.id = track.artist "
|
||||||
|
" AND playback_log.playtime >= %1 AND playback_log.playtime <= %2 " // incorportrate timespan
|
||||||
|
" AND playback_log.source IS NOT NULL " // exclude self
|
||||||
|
" GROUP BY playback_log.track "
|
||||||
|
" ORDER BY counter DESC "
|
||||||
|
" %3"
|
||||||
|
).arg( m_from.toTime_t() ).arg( m_to.toTime_t() ).arg( limit );
|
||||||
|
|
||||||
|
query.prepare( sql );
|
||||||
|
query.exec();
|
||||||
|
|
||||||
|
QList<Tomahawk::track_ptr> tracks;
|
||||||
|
while ( query.next() )
|
||||||
|
{
|
||||||
|
Tomahawk::track_ptr track = Tomahawk::Track::get( query.value( 2 ).toString(), query.value( 1 ).toString() );
|
||||||
|
if ( !track )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
tracks << track;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit done( tracks );
|
||||||
|
}
|
||||||
|
|
53
src/libtomahawk/database/DatabaseCommand_NetworkCharts.h
Normal file
53
src/libtomahawk/database/DatabaseCommand_NetworkCharts.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* === 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DATABASECOMMAND_NETWORKCHARTS_H
|
||||||
|
#define DATABASECOMMAND_NETWORKCHARTS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
#include "Typedefs.h"
|
||||||
|
#include "DatabaseCommand.h"
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
class DLLEXPORT DatabaseCommand_NetworkCharts : public DatabaseCommand
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DatabaseCommand_NetworkCharts( const QDateTime& from, const QDateTime& to, QObject* parent = 0 );
|
||||||
|
virtual ~DatabaseCommand_NetworkCharts();
|
||||||
|
|
||||||
|
virtual void exec( DatabaseImpl* );
|
||||||
|
|
||||||
|
virtual bool doesMutates() const { return false; }
|
||||||
|
virtual QString commandname() const { return "networkcharts"; }
|
||||||
|
|
||||||
|
void setLimit( unsigned int amount ) { m_amount = amount; }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void done( const QList<Tomahawk::track_ptr>& tracks );
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int m_amount;
|
||||||
|
QDateTime m_from;
|
||||||
|
QDateTime m_to;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATABASECOMMAND_NETWORKCHARTS_H
|
Reference in New Issue
Block a user