/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. #ifndef DATABASECOMMAND_H
  21. #define DATABASECOMMAND_H
  22. #include <QMetaType>
  23. #include <QVariant>
  24. #include "DllMacro.h"
  25. #include "Typedefs.h"
  26. namespace Tomahawk
  27. {
  28. class DatabaseCommandPrivate;
  29. class DatabaseImpl;
  30. class DLLEXPORT DatabaseCommand : public QObject
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY( QString guid READ guid WRITE setGuid )
  34. public:
  35. enum State {
  36. PENDING = 0,
  37. RUNNING = 1,
  38. FINISHED = 2
  39. };
  40. explicit DatabaseCommand( QObject* parent = nullptr );
  41. explicit DatabaseCommand( const Tomahawk::source_ptr& src, QObject* parent = nullptr );
  42. DatabaseCommand( const DatabaseCommand &other ); //needed for QMetaType
  43. virtual ~DatabaseCommand();
  44. virtual QString commandname() const { return "DatabaseCommand"; }
  45. virtual bool doesMutates() const { return true; }
  46. State state() const;
  47. // if i make this pure virtual, i get compile errors in qmetatype.h.
  48. // we need Q_DECLARE_METATYPE to use in queued sig/slot connections.
  49. virtual void exec( DatabaseImpl* /*lib*/ ) { Q_ASSERT( false ); }
  50. void _exec( DatabaseImpl* lib );
  51. // stuff to do once transaction applied ok.
  52. // Don't change the database from in here, duh.
  53. void postCommit() { postCommitHook(); emitCommitted(); }
  54. virtual void postCommitHook(){}
  55. void setSource( const Tomahawk::source_ptr& s );
  56. const Tomahawk::source_ptr& source() const;
  57. virtual bool loggable() const { return false; }
  58. virtual bool groupable() const { return false; }
  59. virtual bool singletonCmd() const { return false; }
  60. virtual bool localOnly() const { return false; }
  61. virtual QVariant data() const;
  62. virtual void setData( const QVariant& data );
  63. QString guid() const;
  64. void setGuid( const QString& g );
  65. void emitFinished();
  66. void emitCommitted();
  67. void emitRunning();
  68. QWeakPointer< Tomahawk::DatabaseCommand > weakRef() const;
  69. void setWeakRef( QWeakPointer< Tomahawk::DatabaseCommand > weakRef );
  70. signals:
  71. void running();
  72. void running( const Tomahawk::dbcmd_ptr& );
  73. void finished();
  74. void finished( const Tomahawk::dbcmd_ptr& );
  75. void committed();
  76. void committed( const Tomahawk::dbcmd_ptr& );
  77. protected:
  78. explicit DatabaseCommand( QObject* parent, DatabaseCommandPrivate* d );
  79. QScopedPointer<DatabaseCommandPrivate> d_ptr;
  80. private:
  81. Q_DECLARE_PRIVATE( DatabaseCommand )
  82. };
  83. }
  84. Q_DECLARE_METATYPE( Tomahawk::DatabaseCommand )
  85. #endif // DATABASECOMMAND_H