From dfcdc09cee5f5d1d1075f42aab1baff4bb635382 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 16 May 2013 11:29:40 +0200 Subject: [PATCH] * Added DbCmd_LoadTrackAttributes. --- .../DatabaseCommand_LoadTrackAttributes.cpp | 55 ++++++++++++ .../DatabaseCommand_LoadTrackAttributes.h | 83 +++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.cpp create mode 100644 src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.h diff --git a/src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.cpp b/src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.cpp new file mode 100644 index 000000000..84b861e75 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.cpp @@ -0,0 +1,55 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Christian Muehlhaeuser + * + * 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_LoadTrackAttributes.h" + +#include + +#include "database/Database.h" +#include "DatabaseImpl.h" +#include "network/Servent.h" +#include "Result.h" +#include "utils/Logger.h" + +using namespace Tomahawk; + + +void +DatabaseCommand_LoadTrackAttributes::exec( DatabaseImpl* dbi ) +{ + Q_ASSERT( m_track ); + if ( m_track->trackId() == 0 ) + return; + + TomahawkSqlQuery query = dbi->newquery(); + + query.prepare( "SELECT k, v FROM track_attributes WHERE id = ?" ); + query.bindValue( 0, m_track->trackId() ); + query.exec(); + + QVariantMap attr; + while ( query.next() ) + { + attr[ query.value( 0 ).toString() ] = query.value( 1 ).toString(); + } + + m_track->setAttributes( attr ); + + emit done(); +} + diff --git a/src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.h b/src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.h new file mode 100644 index 000000000..9e7098db2 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_LoadTrackAttributes.h @@ -0,0 +1,83 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Christian Muehlhaeuser + * + * 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_LOADTRACKATTRIBUTES_H +#define DATABASECOMMAND_LOADTRACKATTRIBUTES_H + +#include +#include +#include "database/DatabaseCommand.h" + +#include "SourceList.h" +#include "Typedefs.h" + +#include "DllMacro.h" + +/** + * \class DatabaseCommand_LoadTrackAttributes + * \brief Database command used to load track attributes from the database. + * + * This Database command allows Tomahawk to load track attributes from + * the local database. + * + */ +class DLLEXPORT DatabaseCommand_LoadTrackAttributes : public DatabaseCommand +{ +Q_OBJECT + +public: + /** + * \brief Overloaded constructor for DatabaseCommand_LoadTrackAttributes. + * \param result A Tomahawk Query object. + * \param parent Parent class. + * + * Constructor which creates a new database command for loading all track attributes. + */ + explicit DatabaseCommand_LoadTrackAttributes( const Tomahawk::trackdata_ptr& track, QObject* parent = 0 ) + : DatabaseCommand( parent ), m_track( track ) + { + setSource( SourceList::instance()->getLocal() ); + } + + /** + * \brief Returns the name of this database command. + * \return QString containing the database command name 'loadtrackattributes'. + */ + virtual QString commandname() const { return "loadtrackattributes"; } + + /** + * \brief Executes the database command. + * \param dbi Database instance. + * + * This method executes an sql query to load the track attributes + * from the database and sets it on a Track object. + * + * \see Track::setTrackAttributes() + */ + virtual void exec( DatabaseImpl* ); + + virtual bool doesMutates() const { return false; } + +signals: + void done(); + +private: + Tomahawk::trackdata_ptr m_track; +}; + +#endif // DATABASECOMMAND_LOADTRACKATTRIBUTES_H