PageRenderTime 62ms CodeModel.GetById 31ms app.highlight 8ms RepoModel.GetById 12ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand.h

http://github.com/tomahawk-player/tomahawk
C Header | 113 lines | 62 code | 28 blank | 23 comment | 0 complexity | fc74be9cb4297ca33981daa62015af95 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *   Copyright 2013,      Uwe L. Korn <uwelk@xhochy.com>
  6 *
  7 *   Tomahawk is free software: you can redistribute it and/or modify
  8 *   it under the terms of the GNU General Public License as published by
  9 *   the Free Software Foundation, either version 3 of the License, or
 10 *   (at your option) any later version.
 11 *
 12 *   Tomahawk is distributed in the hope that it will be useful,
 13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *   GNU General Public License for more details.
 16 *
 17 *   You should have received a copy of the GNU General Public License
 18 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21#ifndef DATABASECOMMAND_H
 22#define DATABASECOMMAND_H
 23
 24#include <QMetaType>
 25#include <QVariant>
 26
 27#include "DllMacro.h"
 28#include "Typedefs.h"
 29
 30namespace Tomahawk
 31{
 32
 33class DatabaseCommandPrivate;
 34class DatabaseImpl;
 35
 36class DLLEXPORT DatabaseCommand : public QObject
 37{
 38Q_OBJECT
 39Q_PROPERTY( QString guid READ guid WRITE setGuid )
 40
 41public:
 42    enum State {
 43        PENDING = 0,
 44        RUNNING = 1,
 45        FINISHED = 2
 46    };
 47
 48    explicit DatabaseCommand( QObject* parent = nullptr );
 49    explicit DatabaseCommand( const Tomahawk::source_ptr& src, QObject* parent = nullptr );
 50
 51    DatabaseCommand( const DatabaseCommand &other ); //needed for QMetaType
 52
 53    virtual ~DatabaseCommand();
 54
 55    virtual QString commandname() const { return "DatabaseCommand"; }
 56    virtual bool doesMutates() const { return true; }
 57    State state() const;
 58
 59    // if i make this pure virtual, i get compile errors in qmetatype.h.
 60    // we need Q_DECLARE_METATYPE to use in queued sig/slot connections.
 61    virtual void exec( DatabaseImpl* /*lib*/ ) { Q_ASSERT( false ); }
 62
 63    void _exec( DatabaseImpl* lib );
 64
 65    // stuff to do once transaction applied ok.
 66    // Don't change the database from in here, duh.
 67    void postCommit() { postCommitHook(); emitCommitted(); }
 68    virtual void postCommitHook(){}
 69
 70    void setSource( const Tomahawk::source_ptr& s );
 71    const Tomahawk::source_ptr& source() const;
 72
 73    virtual bool loggable() const { return false; }
 74    virtual bool groupable() const { return false; }
 75    virtual bool singletonCmd() const { return false; }
 76    virtual bool localOnly() const { return false; }
 77
 78    virtual QVariant data() const;
 79    virtual void setData( const QVariant& data );
 80
 81    QString guid() const;
 82    void setGuid( const QString& g );
 83
 84    void emitFinished();
 85    void emitCommitted();
 86    void emitRunning();
 87
 88    QWeakPointer< Tomahawk::DatabaseCommand > weakRef() const;
 89    void setWeakRef( QWeakPointer< Tomahawk::DatabaseCommand > weakRef );
 90
 91signals:
 92    void running();
 93    void running( const Tomahawk::dbcmd_ptr& );
 94
 95    void finished();
 96    void finished( const Tomahawk::dbcmd_ptr& );
 97
 98    void committed();
 99    void committed( const Tomahawk::dbcmd_ptr& );
100protected:
101    explicit DatabaseCommand( QObject* parent, DatabaseCommandPrivate* d );
102
103    QScopedPointer<DatabaseCommandPrivate> d_ptr;
104
105private:
106    Q_DECLARE_PRIVATE( DatabaseCommand )
107};
108
109}
110
111Q_DECLARE_METATYPE( Tomahawk::DatabaseCommand )
112
113#endif // DATABASECOMMAND_H