diff --git a/src/libtomahawk/database/databasecommand_loadfiles.cpp b/src/libtomahawk/database/databasecommand_loadfiles.cpp new file mode 100644 index 000000000..4cf7a1add --- /dev/null +++ b/src/libtomahawk/database/databasecommand_loadfiles.cpp @@ -0,0 +1,58 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, 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_loadfiles.h" + +#include "databaseimpl.h" +#include "collection.h" +#include "utils/logger.h" + + +DatabaseCommand_LoadFiles::DatabaseCommand_LoadFiles( unsigned int id, QObject* parent ) + : DatabaseCommand( parent ) + , m_single( true ) +{ + m_ids << id; +} + +DatabaseCommand_LoadFiles::DatabaseCommand_LoadFiles( const QList& ids, QObject* parent ) + : DatabaseCommand( parent ) + , m_single( false ) + , m_ids( ids ) +{ +} + + +void +DatabaseCommand_LoadFiles::exec( DatabaseImpl* dbi ) +{ + QList resultList; + // file ids internally are really ints, at least for now: + foreach ( unsigned int id, m_ids ) + { + qDebug() << "Loading file from db with id:" << id; + resultList << dbi->file( id ); + } + + Q_ASSERT( !m_single || resultList.size() <= 1 ); + + if ( m_single && !resultList.isEmpty() ) + emit result( resultList.first() ); + else + emit results( resultList ); +} diff --git a/src/libtomahawk/database/databasecommand_loadfiles.h b/src/libtomahawk/database/databasecommand_loadfiles.h new file mode 100644 index 000000000..cfbabe68b --- /dev/null +++ b/src/libtomahawk/database/databasecommand_loadfiles.h @@ -0,0 +1,57 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, 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_LOADFILES_H +#define DATABASECOMMAND_LOADFILES_H + +#include +#include +#include +#include + +#include "databasecommand.h" +#include "result.h" +#include "dllmacro.h" + +/** + Loads a result_ptr from the database from a track dbid. + + If use use the QStringList constructor, isten to results() instead of result() + */ +class DLLEXPORT DatabaseCommand_LoadFiles : public DatabaseCommand +{ +Q_OBJECT + +public: + explicit DatabaseCommand_LoadFiles( unsigned int id, QObject* parent = 0 ); + explicit DatabaseCommand_LoadFiles( const QList& ids, QObject* parent = 0 ); + + virtual void exec( DatabaseImpl* ); + virtual bool doesMutates() const { return false; } + virtual QString commandname() const { return "loadfiles"; } + +signals: + void result( const Tomahawk::result_ptr& result ); + void results( const QList& results ); + +private: + bool m_single; + QList m_ids; +}; + +#endif // DATABASECOMMAND_LOADFILE_H