1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 06:36:55 +02:00

Replaced GenericSelect with a proper dbcmd.

Consequences:
* we avoid the use of QObject properties, which are not thread safe
* we get social actions right away, without having to wait for
  every track's loadSocialActions to finish
This commit is contained in:
Teo Mrnjavac
2013-05-29 15:22:16 +02:00
parent 90ba7eae5b
commit 63bd256bc4
6 changed files with 127 additions and 20 deletions

View File

@@ -246,6 +246,7 @@ list(APPEND libSources
database/DatabaseCommand_CollectionStats.cpp database/DatabaseCommand_CollectionStats.cpp
database/DatabaseCommand_TrackStats.cpp database/DatabaseCommand_TrackStats.cpp
database/DatabaseCommand_LoadPlaylistEntries.cpp database/DatabaseCommand_LoadPlaylistEntries.cpp
database/DatabaseCommand_LoadInboxEntries.cpp
database/DatabaseCommand_ModifyPlaylist.cpp database/DatabaseCommand_ModifyPlaylist.cpp
database/DatabaseCommand_PlaybackHistory.cpp database/DatabaseCommand_PlaybackHistory.cpp
database/DatabaseCommand_SetPlaylistRevision.cpp database/DatabaseCommand_SetPlaylistRevision.cpp

View File

@@ -227,6 +227,13 @@ Track::updateSortNames()
} }
void
Track::setAllSocialActions( const QList< SocialAction >& socialActions )
{
m_trackData->setAllSocialActions( socialActions );
}
bool bool
Track::equals( const Tomahawk::track_ptr& other, bool ignoreCase ) const Track::equals( const Tomahawk::track_ptr& other, bool ignoreCase ) const
{ {

View File

@@ -29,6 +29,7 @@
#include "DllMacro.h" #include "DllMacro.h"
class DatabaseCommand_LoadInboxEntries;
namespace Tomahawk namespace Tomahawk
{ {
@@ -38,6 +39,7 @@ class DLLEXPORT Track : public QObject
Q_OBJECT Q_OBJECT
friend class Pipeline; friend class Pipeline;
friend class ::DatabaseCommand_LoadInboxEntries; // for setAllSocialActions
public: public:
enum DescriptionMode enum DescriptionMode
@@ -134,6 +136,8 @@ private:
void updateSortNames(); void updateSortNames();
void setAllSocialActions( const QList< SocialAction >& socialActions );
QString m_composer; QString m_composer;
QString m_album; QString m_album;
QString m_composerSortname; QString m_composerSortname;

View File

@@ -0,0 +1,75 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* 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_LoadInboxEntries.h"
#include "DatabaseImpl.h"
#include "Query.h"
#include "SourceList.h"
#include "TomahawkSqlQuery.h"
DatabaseCommand_LoadInboxEntries::DatabaseCommand_LoadInboxEntries( QObject* parent )
: DatabaseCommand( parent )
{
}
void DatabaseCommand_LoadInboxEntries::exec( DatabaseImpl* dbi )
{
TomahawkSqlQuery sqlQuery = dbi->newquery();
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' "
"ORDER BY social_attributes.timestamp" );
sqlQuery.prepare( sql );
sqlQuery.exec();
QList< Tomahawk::query_ptr > queries;
while ( sqlQuery.next() )
{
QString track, artist;
track = sqlQuery.value( 0 ).toString();
artist = sqlQuery.value( 1 ).toString();
Tomahawk::query_ptr query = Tomahawk::Query::get( artist, track, QString() );
if ( query.isNull() )
continue;
int sourceId = sqlQuery.value( 2 ).toInt();
bool unlistened = sqlQuery.value( 3 ).toBool();
uint timestamp = sqlQuery.value( 4 ).toUInt();
Tomahawk::SocialAction action;
action.action = "Inbox";
action.source = SourceList::instance()->get( sourceId );
action.value = unlistened;
action.timestamp = timestamp;
QList< Tomahawk::SocialAction > actions;
actions << action;
query->queryTrack()->setAllSocialActions( actions );
queries << query;
}
emit tracks( queries );
}

View File

@@ -0,0 +1,38 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* 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_LOADINBOXENTRIES_H
#define DATABASECOMMAND_LOADINBOXENTRIES_H
#include "DatabaseCommand.h"
class DatabaseCommand_LoadInboxEntries : public DatabaseCommand
{
Q_OBJECT
public:
explicit DatabaseCommand_LoadInboxEntries( QObject* parent = 0 );
virtual void exec( DatabaseImpl* );
virtual bool doesMutates() const { return false; }
virtual QString commandname() const { return "loadinboxentries"; }
signals:
void tracks( QList< Tomahawk::query_ptr > );
};
#endif // DATABASECOMMAND_LOADINBOXENTRIES_H

View File

@@ -19,7 +19,7 @@
#include "InboxModel.h" #include "InboxModel.h"
#include "database/Database.h" #include "database/Database.h"
#include "database/DatabaseCommand_GenericSelect.h" #include "database/DatabaseCommand_LoadInboxEntries.h"
#include "database/DatabaseCommand_DeleteInboxEntry.h" #include "database/DatabaseCommand_DeleteInboxEntry.h"
#include "database/DatabaseCommand_ModifyInboxEntry.h" #include "database/DatabaseCommand_ModifyInboxEntry.h"
#include "SourceList.h" #include "SourceList.h"
@@ -190,13 +190,7 @@ InboxModel::loadTracks()
{ {
startLoading(); startLoading();
//extra fields end up in Tomahawk query objects as qt properties DatabaseCommand_LoadInboxEntries* cmd = new DatabaseCommand_LoadInboxEntries();
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' "
"ORDER BY social_attributes.timestamp" );
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> ) ) ); connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksLoaded( QList<Tomahawk::query_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
} }
@@ -223,19 +217,7 @@ InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > incoming )
foreach ( Tomahawk::query_ptr newQuery, newTracks ) foreach ( Tomahawk::query_ptr newQuery, newTracks )
{ {
QVariantList extraData = newQuery->property( "data" ).toList();
Tomahawk::SocialAction action;
action.action = "Inbox";
action.source = SourceList::instance()->get( extraData.at( 0 ).toInt() );
action.value = extraData.at( 1 ).toBool(); //unlistened
action.timestamp = extraData.at( 2 ).toUInt();
QList< Tomahawk::SocialAction > actions;
actions << action;
newQuery->queryTrack()->loadSocialActions(); newQuery->queryTrack()->loadSocialActions();
newQuery->setProperty( "data", QVariant() ); //clear
} }
bool changed = false; bool changed = false;