/src/libtomahawk/database/DatabaseCommand.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 174 lines · 115 code · 41 blank · 18 comment · 1 complexity · 2902ebea0d0417e1dc2945810f11ad3b 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 2013, Uwe L. Korn <uwelk@xhochy.com>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "DatabaseCommand_p.h"
  20. #include "utils/Logger.h"
  21. #include "Source.h"
  22. namespace Tomahawk
  23. {
  24. DatabaseCommand::DatabaseCommand( QObject* parent )
  25. : QObject( parent )
  26. , d_ptr( new DatabaseCommandPrivate( this ) )
  27. {
  28. }
  29. DatabaseCommand::DatabaseCommand( const Tomahawk::source_ptr& src, QObject* parent )
  30. : QObject( parent )
  31. , d_ptr( new DatabaseCommandPrivate( this, src ) )
  32. {
  33. }
  34. DatabaseCommand::DatabaseCommand( const DatabaseCommand& other )
  35. : QObject( other.parent() )
  36. , d_ptr( new DatabaseCommandPrivate( this ) )
  37. {
  38. }
  39. DatabaseCommand::~DatabaseCommand()
  40. {
  41. }
  42. DatabaseCommand::State
  43. DatabaseCommand::state() const
  44. {
  45. Q_D( const DatabaseCommand );
  46. return d->state;
  47. }
  48. void
  49. DatabaseCommand::_exec( DatabaseImpl* lib )
  50. {
  51. Q_D( DatabaseCommand );
  52. d->state = RUNNING;
  53. emitRunning();
  54. exec( lib );
  55. d->state = FINISHED;
  56. }
  57. void
  58. DatabaseCommand::setSource( const Tomahawk::source_ptr& s )
  59. {
  60. Q_D( DatabaseCommand );
  61. d->source = s;
  62. }
  63. const Tomahawk::source_ptr&
  64. DatabaseCommand::source() const
  65. {
  66. Q_D( const DatabaseCommand );
  67. return d->source;
  68. }
  69. QVariant
  70. DatabaseCommand::data() const
  71. {
  72. Q_D( const DatabaseCommand );
  73. return d->data;
  74. }
  75. void
  76. DatabaseCommand::setData( const QVariant& data )
  77. {
  78. Q_D( DatabaseCommand );
  79. d->data = data;
  80. }
  81. QString
  82. DatabaseCommand::guid() const
  83. {
  84. Q_D( const DatabaseCommand );
  85. if( d->guid.isEmpty() )
  86. d->guid = uuid();
  87. return d->guid;
  88. }
  89. void
  90. DatabaseCommand::setGuid( const QString& g)
  91. {
  92. Q_D( DatabaseCommand );
  93. d->guid = g;
  94. }
  95. void
  96. DatabaseCommand::emitFinished()
  97. {
  98. Q_D( DatabaseCommand );
  99. emit finished( d->ownRef.toStrongRef() );
  100. emit finished();
  101. }
  102. void
  103. DatabaseCommand::emitCommitted()
  104. {
  105. Q_D( DatabaseCommand );
  106. emit committed( d->ownRef.toStrongRef() );
  107. emit committed();
  108. }
  109. void
  110. DatabaseCommand::emitRunning()
  111. {
  112. Q_D( DatabaseCommand );
  113. emit running( d->ownRef.toStrongRef() );
  114. emit running();
  115. }
  116. QWeakPointer< DatabaseCommand >
  117. DatabaseCommand::weakRef() const
  118. {
  119. Q_D( const DatabaseCommand );
  120. return d->ownRef;
  121. }
  122. void
  123. DatabaseCommand::setWeakRef( QWeakPointer< DatabaseCommand > weakRef )
  124. {
  125. Q_D( DatabaseCommand );
  126. d->ownRef = weakRef;
  127. }
  128. DatabaseCommand::DatabaseCommand( QObject* parent, DatabaseCommandPrivate* d)
  129. : QObject( parent )
  130. , d_ptr( d )
  131. {
  132. }
  133. }