PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 33ms app.codeStats 0ms

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