dynamicplaylist.h 3.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2003-2004 Scott Wheeler <wheeler@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
16 17 18 19 20

#ifndef DYNAMICPLAYLIST_H
#define DYNAMICPLAYLIST_H

#include "playlist.h"
21

22
#include <QList>
23 24 25 26 27 28 29 30 31 32 33 34

/**
 * A Playlist that is a union of other playlists that is created dynamically.
 */

class DynamicPlaylist : public Playlist
{
    Q_OBJECT
public:
    /**
     * Creates a dynamic playlist based on lists.
     */
35 36
    DynamicPlaylist(const PlaylistList &lists,
                    PlaylistCollection *collection,
37
                    const QString &name = QString(),
Michael Pyne's avatar
Michael Pyne committed
38
                    const QString &iconName = "audio-midi",
39
                    bool setupPlaylist = true,
40
                    bool synchronizePlaying = false);
41

42 43
    virtual ~DynamicPlaylist();

44 45
    virtual bool canReload() const { return false; }

46 47
    void setPlaylists(const PlaylistList &playlists);

48 49 50 51 52 53
public slots:
    /**
     * Reimplemented so that it will reload all of the playlists that are
     * associated with the dynamic list.
     */
    virtual void slotReload();
54
    void slotSetDirty() { m_dirty = true; }
55

56 57 58 59 60 61 62
    /**
     * This is called when lowering the widget from the widget stack so that
     * it can synchronize the playing item with the one that playlist it was
     * create from.
     */
    void lower(QWidget *top = 0);

63 64 65 66 67
protected:
    /**
     * Returns true if this list's items need to be updated the next time it's
     * shown.
     */
68
    bool dirty() const { return m_dirty; }
69 70

    /**
71
     * Return a list of the items in this playlist.  For example in a search
72 73 74
     * list this should return only the matched items.  By default it returns
     * all of the items in the playlists associated with this dynamic list.
     */
75
    virtual PlaylistItemList items();
76 77 78 79 80 81 82

    /**
     * Reimplemented from QWidget.  Here it updates the list of items (when
     * appropriate) as the widget is shown.
     */
    virtual void showEvent(QShowEvent *e);

83 84
    virtual void paintEvent(QPaintEvent *e);

85 86 87 88 89 90 91
    /**
     * Updates the items (unconditionally).  This should be reimplemented in
     * subclasses to refresh the items in the dynamic list (i.e. running a
     * search).
     */
    virtual void updateItems();

92 93
    bool synchronizePlaying() const;

94 95 96 97 98 99 100 101
private:
    /**
     * Checks to see if the current list of items is "dirty" and if so updates
     * this dynamic playlist's items to be in sync with the lists that it is a
     * wrapper around.
     */
    void checkUpdateItems();

102
private:
103
    QList<PlaylistObserver *> m_observers;
104
    PlaylistItemList m_siblings;
105 106
    PlaylistList m_playlists;
    bool m_dirty;
107
    bool m_synchronizePlaying;
108 109 110
};

#endif
111 112

// vim: set et sw=4 tw=0 sta: