diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 22f985fc4..907963a22 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -246,6 +246,7 @@ list(APPEND libSources database/DatabaseCommand_CollectionStats.cpp database/DatabaseCommand_TrackStats.cpp database/DatabaseCommand_LoadPlaylistEntries.cpp + database/DatabaseCommand_LoadInboxEntries.cpp database/DatabaseCommand_ModifyPlaylist.cpp database/DatabaseCommand_PlaybackHistory.cpp database/DatabaseCommand_SetPlaylistRevision.cpp diff --git a/src/libtomahawk/Track.cpp b/src/libtomahawk/Track.cpp index eefceef74..cb5611c80 100644 --- a/src/libtomahawk/Track.cpp +++ b/src/libtomahawk/Track.cpp @@ -227,6 +227,13 @@ Track::updateSortNames() } +void +Track::setAllSocialActions( const QList< SocialAction >& socialActions ) +{ + m_trackData->setAllSocialActions( socialActions ); +} + + bool Track::equals( const Tomahawk::track_ptr& other, bool ignoreCase ) const { diff --git a/src/libtomahawk/Track.h b/src/libtomahawk/Track.h index 5e9d59e97..d6801ff5e 100644 --- a/src/libtomahawk/Track.h +++ b/src/libtomahawk/Track.h @@ -29,6 +29,7 @@ #include "DllMacro.h" +class DatabaseCommand_LoadInboxEntries; namespace Tomahawk { @@ -38,6 +39,7 @@ class DLLEXPORT Track : public QObject Q_OBJECT friend class Pipeline; +friend class ::DatabaseCommand_LoadInboxEntries; // for setAllSocialActions public: enum DescriptionMode @@ -134,6 +136,8 @@ private: void updateSortNames(); + void setAllSocialActions( const QList< SocialAction >& socialActions ); + QString m_composer; QString m_album; QString m_composerSortname; diff --git a/src/libtomahawk/database/DatabaseCommand_LoadInboxEntries.cpp b/src/libtomahawk/database/DatabaseCommand_LoadInboxEntries.cpp new file mode 100644 index 000000000..04d67cfbf --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_LoadInboxEntries.cpp @@ -0,0 +1,75 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + + +#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 ); +} diff --git a/src/libtomahawk/database/DatabaseCommand_LoadInboxEntries.h b/src/libtomahawk/database/DatabaseCommand_LoadInboxEntries.h new file mode 100644 index 000000000..0ee116fa8 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_LoadInboxEntries.h @@ -0,0 +1,38 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#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 diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp index 4deec1030..872a5c94f 100644 --- a/src/libtomahawk/playlist/InboxModel.cpp +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -19,7 +19,7 @@ #include "InboxModel.h" #include "database/Database.h" -#include "database/DatabaseCommand_GenericSelect.h" +#include "database/DatabaseCommand_LoadInboxEntries.h" #include "database/DatabaseCommand_DeleteInboxEntry.h" #include "database/DatabaseCommand_ModifyInboxEntry.h" #include "SourceList.h" @@ -190,13 +190,7 @@ 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' " - "ORDER BY social_attributes.timestamp" ); - - DatabaseCommand_GenericSelect* cmd = new DatabaseCommand_GenericSelect( sql, DatabaseCommand_GenericSelect::Track, -1, 0 ); + DatabaseCommand_LoadInboxEntries* cmd = new DatabaseCommand_LoadInboxEntries(); connect( cmd, SIGNAL( tracks( QList ) ), this, SLOT( tracksLoaded( QList ) ) ); Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -223,19 +217,7 @@ InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > incoming ) 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->setProperty( "data", QVariant() ); //clear } bool changed = false;