/src/libtomahawk/playlist/dynamic/DynamicControl.h

http://github.com/tomahawk-player/tomahawk · C Header · 126 lines · 55 code · 21 blank · 50 comment · 1 complexity · 5248798e223b67d8f8be44f1b7b4a5ab 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. *
  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. #ifndef DYNAMIC_PLAYLIST_CONTROL
  20. #define DYNAMIC_PLAYLIST_CONTROL
  21. #include "DllMacro.h"
  22. #include "Typedefs.h"
  23. #include <QObject>
  24. #include <QSharedPointer>
  25. #include <QStringList>
  26. #include <QWidget>
  27. namespace Tomahawk
  28. {
  29. /**
  30. * A Dynamic Control is a single constraint that limits a dynamic playlist. Each generator creates controls specific to that generator.
  31. * Each control has 3 pieces:
  32. * - Type (string selector for what this control is matching)
  33. * - Match selector (how to match the type to the input)
  34. * - Input field (the user input field).
  35. *
  36. * Each control also has a list of TypeSelectors that comes from the generator, and only one is selected at once.
  37. *
  38. */
  39. class DLLEXPORT DynamicControl : public QObject
  40. {
  41. Q_OBJECT
  42. Q_PROPERTY( QString type READ type WRITE setType ) // the generator type associated with this control
  43. Q_PROPERTY( QString id READ id WRITE setId )
  44. Q_PROPERTY( QString selectedType READ selectedType WRITE setSelectedType )
  45. Q_PROPERTY( QString match READ match WRITE setMatch )
  46. Q_PROPERTY( QString input READ input WRITE setInput )
  47. Q_PROPERTY( QString summary READ summary ) // a summary of the control in phrase form
  48. public:
  49. DynamicControl( const QStringList& typeSelectors = QStringList() );
  50. virtual ~DynamicControl();
  51. /// The current type of this control
  52. QString selectedType() const { return m_selectedType; }
  53. /**
  54. * The match selector widget based on this control's type
  55. *
  56. * The control manages the lifetime of the widget.
  57. */
  58. virtual QWidget* matchSelector() { Q_ASSERT( false ); return 0; }
  59. /**
  60. * The input field widget that is associated with this type
  61. *
  62. * The control manages the lifetime of the widget.
  63. */
  64. virtual QWidget* inputField() { Q_ASSERT( false ); return 0; }
  65. /// The user-readable match value, for showing in read-only playlists
  66. virtual QString matchString() const { Q_ASSERT( false ); return QString(); }
  67. /// the serializable value of the match
  68. virtual QString match() const { Q_ASSERT( false ); return QString(); }
  69. /// the serializable value of the input
  70. virtual QString input() const { Q_ASSERT( false ); return QString(); }
  71. /// the user-readable summary phrase
  72. virtual QString summary() const { Q_ASSERT( false ); return QString(); }
  73. // used by JSON serialization
  74. virtual void setMatch( const QString& /*match*/ ) { Q_ASSERT( false ); }
  75. virtual void setInput( const QString& /*input*/ ) { Q_ASSERT( false ); }
  76. /// All the potential type selectors for this control
  77. QStringList typeSelectors() const { return m_typeSelectors; }
  78. QString id() {
  79. if( m_id.isEmpty() )
  80. m_id = uuid();
  81. return m_id;
  82. };
  83. void setId( const QString& id ) { m_id = id; }
  84. void setType( const QString& type ) { m_type = type; }
  85. QString type() const { return m_type; }
  86. signals:
  87. void changed();
  88. public slots:
  89. /**
  90. * Sets the type to the newly specified one. Note that this will update the matchSelector
  91. * and inputField widgets, so you should fetch the new widgets for use immediately.
  92. */
  93. virtual void setSelectedType( const QString& selectedType ) { m_selectedType = selectedType; }
  94. protected:
  95. // Private constructor, you can't make one. Get it from your Generator.
  96. explicit DynamicControl( const QString& selectedType, const QStringList& typeSelectors, QObject* parent = 0 );
  97. private:
  98. QString m_type;
  99. QString m_selectedType;
  100. QStringList m_typeSelectors;
  101. QString m_id;
  102. };
  103. }
  104. Q_DECLARE_METATYPE( Tomahawk::dyncontrol_ptr )
  105. #endif