dynamicplaylist.h 3.5 KB
Newer Older
1 2
/***************************************************************************
    begin                : Mon May 5 2003
3
    copyright            : (C) 2003 - 2004 by Scott Wheeler
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    email                : 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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DYNAMICPLAYLIST_H
#define DYNAMICPLAYLIST_H

#include "playlist.h"
Laurent Montel's avatar
Laurent Montel committed
20 21 22 23
//Added by qt3to4:
#include <QShowEvent>
#include <Q3ValueList>
#include <QPaintEvent>
24 25 26 27 28 29 30 31 32 33 34 35

/**
 * 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.
     */
36 37 38
    DynamicPlaylist(const PlaylistList &lists,
                    PlaylistCollection *collection,
                    const QString &name = QString::null,
39
                    const QString &iconName = "midi",
40
                    bool setupPlaylist = true,
41
                    bool synchronizePlaying = false);
42

43 44
    virtual ~DynamicPlaylist();

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

47 48
    void setPlaylists(const PlaylistList &playlists);

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

57 58 59 60 61 62 63
    /**
     * 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);

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

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

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

84 85
    virtual void paintEvent(QPaintEvent *e);

86 87 88 89 90 91 92
    /**
     * 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();

93 94
    bool synchronizePlaying() const;

95 96 97 98 99 100 101 102
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();

103 104 105
private slots:
    void slotUpdateItems();

106
private:
Laurent Montel's avatar
Laurent Montel committed
107
    Q3ValueList<PlaylistObserver *> m_observers;
108
    PlaylistItemList m_siblings;
109 110
    PlaylistList m_playlists;
    bool m_dirty;
111
    bool m_synchronizePlaying;
112 113 114
};

#endif