PageRenderTime 22ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_LogPlayback.h

http://github.com/tomahawk-player/tomahawk
C Header | 110 lines | 70 code | 23 blank | 17 comment | 1 complexity | 910faa5bc16e55d6401a107c3fa38610 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef DATABASECOMMAND_LOGPLAYBACK_H
  19. #define DATABASECOMMAND_LOGPLAYBACK_H
  20. #include <QObject>
  21. #include <QVariantMap>
  22. #include "database/DatabaseCommandLoggable.h"
  23. #include "SourceList.h"
  24. #include "Typedefs.h"
  25. #include "Artist.h"
  26. #include "Track.h"
  27. #include "DllMacro.h"
  28. namespace Tomahawk
  29. {
  30. class DLLEXPORT DatabaseCommand_LogPlayback : public DatabaseCommandLoggable
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY( QString artist READ artist WRITE setArtist )
  34. Q_PROPERTY( QString track READ track WRITE setTrack )
  35. Q_PROPERTY( unsigned int playtime READ playtime WRITE setPlaytime )
  36. Q_PROPERTY( unsigned int secsPlayed READ secsPlayed WRITE setSecsPlayed )
  37. Q_PROPERTY( unsigned int trackDuration READ trackDuration WRITE setTrackDuration )
  38. Q_PROPERTY( int action READ action WRITE setAction )
  39. public:
  40. enum Action
  41. {
  42. Started = 1,
  43. Finished = 2
  44. };
  45. explicit DatabaseCommand_LogPlayback( QObject* parent = 0 )
  46. : DatabaseCommandLoggable( parent ), m_secsPlayed( 0 ), m_playtime( 0 ), m_trackDuration( 0 )
  47. {}
  48. explicit DatabaseCommand_LogPlayback( const Tomahawk::track_ptr& track, Action action, unsigned int secsPlayed = 0, unsigned int timeStamp = 0, QObject* parent = 0 )
  49. : DatabaseCommandLoggable( parent ), m_secsPlayed( secsPlayed ), m_playtime( timeStamp ), m_action( action )
  50. {
  51. m_trackDuration = track->duration();
  52. setSource( SourceList::instance()->getLocal() );
  53. setArtist( track->artist() );
  54. setTrack( track->track() );
  55. }
  56. virtual QString commandname() const { return "logplayback"; }
  57. virtual void exec( DatabaseImpl* );
  58. virtual void postCommitHook();
  59. virtual bool doesMutates() const { return true; }
  60. virtual bool singletonCmd() const { return ( m_action == Started ); }
  61. virtual bool localOnly() const;
  62. virtual bool groupable() const { return true; }
  63. QString artist() const { return m_artist; }
  64. void setArtist( const QString& s ) { m_artist = s; }
  65. QString track() const { return m_track; }
  66. void setTrack( const QString& s ) { m_track = s; }
  67. unsigned int playtime() const { return m_playtime; }
  68. void setPlaytime( unsigned int i ) { m_playtime = i; }
  69. unsigned int secsPlayed() const { return m_secsPlayed; }
  70. void setSecsPlayed( unsigned int i ) { m_secsPlayed = i; }
  71. unsigned int trackDuration() const { return m_trackDuration; }
  72. void setTrackDuration( unsigned int trackDuration ) { m_trackDuration = trackDuration; }
  73. int action() const { return m_action; }
  74. void setAction( int a ) { m_action = (Action)a; }
  75. signals:
  76. void trackPlaying( const Tomahawk::track_ptr& track, unsigned int duration );
  77. void trackPlayed( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log );
  78. private:
  79. QString m_artist;
  80. QString m_track;
  81. unsigned int m_secsPlayed;
  82. unsigned int m_playtime;
  83. unsigned int m_trackDuration;
  84. Action m_action;
  85. };
  86. }
  87. #endif // DATABASECOMMAND_LOGPLAYBACK_H