mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
Add RecentlyLovedTracksModel
This commit is contained in:
@@ -72,6 +72,7 @@ set( libGuiSources
|
|||||||
playlist/TreeWidget.cpp
|
playlist/TreeWidget.cpp
|
||||||
playlist/ViewHeader.cpp
|
playlist/ViewHeader.cpp
|
||||||
playlist/LovedTracksModel.cpp
|
playlist/LovedTracksModel.cpp
|
||||||
|
playlist/RecentlyLovedTracksModel.cpp
|
||||||
playlist/TopLovedTracksModel.cpp
|
playlist/TopLovedTracksModel.cpp
|
||||||
playlist/RecentlyAddedModel.cpp
|
playlist/RecentlyAddedModel.cpp
|
||||||
playlist/RecentlyPlayedModel.cpp
|
playlist/RecentlyPlayedModel.cpp
|
||||||
|
@@ -21,8 +21,9 @@
|
|||||||
|
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
|
|
||||||
LovedTracksModel::LovedTracksModel( QObject *parent )
|
|
||||||
: PlaylistModel( parent, new LovedTracksModelPrivate( this ) )
|
void
|
||||||
|
LovedTracksModel::init()
|
||||||
{
|
{
|
||||||
Q_D( LovedTracksModel );
|
Q_D( LovedTracksModel );
|
||||||
d->smoothingTimer.setInterval( 300 );
|
d->smoothingTimer.setInterval( 300 );
|
||||||
@@ -32,6 +33,20 @@ LovedTracksModel::LovedTracksModel( QObject *parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LovedTracksModel::LovedTracksModel( QObject *parent )
|
||||||
|
: PlaylistModel( parent, new LovedTracksModelPrivate( this ) )
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LovedTracksModel::LovedTracksModel(QObject *parent, LovedTracksModelPrivate *d)
|
||||||
|
: PlaylistModel( parent, d )
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LovedTracksModel::~LovedTracksModel()
|
LovedTracksModel::~LovedTracksModel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,6 @@ class DLLEXPORT LovedTracksModel : public PlaylistModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LovedTracksModel( QObject* parent = 0 );
|
|
||||||
virtual ~LovedTracksModel();
|
virtual ~LovedTracksModel();
|
||||||
|
|
||||||
unsigned int limit() const;
|
unsigned int limit() const;
|
||||||
@@ -41,9 +40,14 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void setSource( const Tomahawk::source_ptr& source );
|
void setSource( const Tomahawk::source_ptr& source );
|
||||||
|
|
||||||
private slots:
|
protected slots:
|
||||||
virtual void loadTracks();
|
virtual void loadTracks();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit LovedTracksModel( QObject* parent = 0 );
|
||||||
|
explicit LovedTracksModel( QObject* parent, LovedTracksModelPrivate* d );
|
||||||
|
|
||||||
|
private slots:
|
||||||
void onSourcesReady();
|
void onSourcesReady();
|
||||||
void onSourceAdded( const Tomahawk::source_ptr& source );
|
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||||
void onTrackLoved();
|
void onTrackLoved();
|
||||||
@@ -52,6 +56,9 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE( LovedTracksModel )
|
Q_DECLARE_PRIVATE( LovedTracksModel )
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOVEDTRACKSMODEL_H
|
#endif // LOVEDTRACKSMODEL_H
|
||||||
|
66
src/libtomahawk/playlist/RecentlyLovedTracksModel.cpp
Normal file
66
src/libtomahawk/playlist/RecentlyLovedTracksModel.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/* === 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 "RecentlyLovedTracksModel_p.h"
|
||||||
|
|
||||||
|
#include "database/Database.h"
|
||||||
|
#include "database/DatabaseCommand_GenericSelect.h"
|
||||||
|
#include "Source.h"
|
||||||
|
|
||||||
|
RecentlyLovedTracksModel::RecentlyLovedTracksModel( QObject* parent )
|
||||||
|
: LovedTracksModel( parent, new RecentlyLovedTracksModelPrivate( this ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RecentlyLovedTracksModel::~RecentlyLovedTracksModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
RecentlyLovedTracksModel::loadTracks()
|
||||||
|
{
|
||||||
|
Q_D( RecentlyLovedTracksModel );
|
||||||
|
startLoading();
|
||||||
|
|
||||||
|
QString sql;
|
||||||
|
if ( d->source.isNull() )
|
||||||
|
{
|
||||||
|
sql = QString( "SELECT track.name, artist.name, source "
|
||||||
|
"FROM social_attributes, track, artist "
|
||||||
|
"WHERE social_attributes.id = track.id AND artist.id = track.artist AND social_attributes.k = 'Love' AND social_attributes.v = 'true' "
|
||||||
|
"GROUP BY track.id "
|
||||||
|
"ORDER BY social_attributes.timestamp DESC LIMIT %1" )
|
||||||
|
.arg( d->limit );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql = QString( "SELECT track.name, artist.name "
|
||||||
|
"FROM social_attributes, track, artist "
|
||||||
|
"WHERE social_attributes.id = track.id AND artist.id = track.artist AND social_attributes.k = 'Love' AND social_attributes.v = 'true' AND social_attributes.source %1 "
|
||||||
|
"GROUP BY track.id "
|
||||||
|
"ORDER BY social_attributes.timestamp DESC "
|
||||||
|
)
|
||||||
|
.arg( d->source->isLocal() ? "IS NULL" : QString( "= %1" ).arg( d->source->id() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
Tomahawk::DatabaseCommand_GenericSelect* cmd = new Tomahawk::DatabaseCommand_GenericSelect( sql, Tomahawk::DatabaseCommand_GenericSelect::Track, -1, 0 );
|
||||||
|
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||||
|
}
|
41
src/libtomahawk/playlist/RecentlyLovedTracksModel.h
Normal file
41
src/libtomahawk/playlist/RecentlyLovedTracksModel.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/* === 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 RECENTLYLOVEDTRACKSMODEL_H
|
||||||
|
#define RECENTLYLOVEDTRACKSMODEL_H
|
||||||
|
|
||||||
|
#include "LovedTracksModel.h"
|
||||||
|
|
||||||
|
class RecentlyLovedTracksModelPrivate;
|
||||||
|
|
||||||
|
class RecentlyLovedTracksModel : public LovedTracksModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit RecentlyLovedTracksModel(QObject *parent = 0);
|
||||||
|
virtual ~RecentlyLovedTracksModel();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
virtual void loadTracks();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DECLARE_PRIVATE( RecentlyLovedTracksModel )
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RECENTLYLOVEDTRACKSMODEL_H
|
36
src/libtomahawk/playlist/RecentlyLovedTracksModel_p.h
Normal file
36
src/libtomahawk/playlist/RecentlyLovedTracksModel_p.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/* === 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 RECENTLYLOVEDTRACKSMODEL_P_H
|
||||||
|
#define RECENTLYLOVEDTRACKSMODEL_P_H
|
||||||
|
|
||||||
|
#include "RecentlyLovedTracksModel.h"
|
||||||
|
#include "LovedTracksModel_p.h"
|
||||||
|
|
||||||
|
class RecentlyLovedTracksModelPrivate : public LovedTracksModelPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RecentlyLovedTracksModelPrivate( RecentlyLovedTracksModel* q )
|
||||||
|
: LovedTracksModelPrivate( q )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_PUBLIC( RecentlyLovedTracksModel )
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RECENTLYLOVEDTRACKSMODEL_P_H
|
@@ -33,7 +33,7 @@ public:
|
|||||||
explicit TopLovedTracksModel( QObject* parent = 0 );
|
explicit TopLovedTracksModel( QObject* parent = 0 );
|
||||||
virtual ~TopLovedTracksModel();
|
virtual ~TopLovedTracksModel();
|
||||||
|
|
||||||
private slots:
|
protected slots:
|
||||||
void loadTracks();
|
void loadTracks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user