1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 19:30:21 +02:00

* Added DbCmd_LoadTrackAttributes.

This commit is contained in:
Christian Muehlhaeuser
2013-05-16 11:29:40 +02:00
parent 06a46daa0b
commit dfcdc09cee
2 changed files with 138 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.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_LoadTrackAttributes.h"
#include <QSqlQuery>
#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();
}

View File

@@ -0,0 +1,83 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.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_LOADTRACKATTRIBUTES_H
#define DATABASECOMMAND_LOADTRACKATTRIBUTES_H
#include <QDateTime>
#include <QList>
#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