mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-22 13:43:11 +02:00
Add persistence to Inbox.
This commit is contained in:
@@ -18,10 +18,57 @@
|
|||||||
|
|
||||||
#include "InboxModel.h"
|
#include "InboxModel.h"
|
||||||
|
|
||||||
|
#include "database/Database.h"
|
||||||
|
#include "database/DatabaseCommand_GenericSelect.h"
|
||||||
|
|
||||||
|
|
||||||
InboxModel::InboxModel( QObject* parent )
|
InboxModel::InboxModel( QObject* parent )
|
||||||
: PlaylistModel( parent )
|
: PlaylistModel( parent )
|
||||||
{
|
{
|
||||||
|
loadTracks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InboxModel::~InboxModel()
|
InboxModel::~InboxModel()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InboxModel::loadTracks()
|
||||||
|
{
|
||||||
|
startLoading();
|
||||||
|
|
||||||
|
//extra fields end up in Tomahawk query objects as qt properties
|
||||||
|
QString sql = QString( "SELECT track.name as title, artist.name as artist, source, v as unlistened, social_attributes.timestamp "
|
||||||
|
"FROM social_attributes, track, artist "
|
||||||
|
"WHERE social_attributes.id = track.id AND artist.id = track.artist AND social_attributes.k = 'Inbox' "
|
||||||
|
"GROUP BY track.id "
|
||||||
|
"ORDER BY social_attributes.timestamp DESC" );
|
||||||
|
|
||||||
|
DatabaseCommand_GenericSelect* cmd = new DatabaseCommand_GenericSelect( sql, DatabaseCommand_GenericSelect::Track, -1, 0 );
|
||||||
|
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > newTracks )
|
||||||
|
{
|
||||||
|
finishLoading();
|
||||||
|
|
||||||
|
QList< Tomahawk::query_ptr > tracks;
|
||||||
|
|
||||||
|
foreach ( const Tomahawk::plentry_ptr ple, playlistEntries() )
|
||||||
|
tracks << ple->query();
|
||||||
|
|
||||||
|
bool changed = false;
|
||||||
|
QList< Tomahawk::query_ptr > mergedTracks = TomahawkUtils::mergePlaylistChanges( tracks, newTracks, changed );
|
||||||
|
|
||||||
|
if ( changed )
|
||||||
|
{
|
||||||
|
QList< Tomahawk::plentry_ptr > el = playlist()->entriesFromQueries( mergedTracks, true );
|
||||||
|
|
||||||
|
clear();
|
||||||
|
appendEntries( el );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -30,8 +30,13 @@ public:
|
|||||||
explicit InboxModel( QObject* parent = 0 );
|
explicit InboxModel( QObject* parent = 0 );
|
||||||
virtual ~InboxModel();
|
virtual ~InboxModel();
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
|
void loadTracks();
|
||||||
|
|
||||||
|
void tracksLoaded( QList< Tomahawk::query_ptr > );
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer* m_smoothingTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INBOXMODEL_H
|
#endif // INBOXMODEL_H
|
||||||
|
Reference in New Issue
Block a user