playlistinterface.h 2.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 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

#ifndef PLAYLISTINTERFACE_H
#define PLAYLISTINTERFACE_H

20
#include <QList>
21

22
class FileHandle;
23 24
class PlaylistObserver;

Scott Wheeler's avatar
Scott Wheeler committed
25 26 27 28 29 30
/**
 * An interface implemented by PlaylistInterface to make it possible to watch
 * for changes in the PlaylistInterface.  This is a semi-standard observer
 * pattern from i.e. Design Patterns.
 */

31 32 33 34 35
class Watched
{
public:
    void addObserver(PlaylistObserver *observer);
    void removeObserver(PlaylistObserver *observer);
Scott Wheeler's avatar
Scott Wheeler committed
36

37 38 39 40 41 42
    /**
     * Call this to remove all objects observing this class unconditionally (for example, when
     * you're being destructed).
     */
    void clearObservers();

Scott Wheeler's avatar
Scott Wheeler committed
43 44 45
    /**
     * This is triggered when the currently playing item has been changed.
     */
46
    virtual void currentPlayingItemChanged();
Scott Wheeler's avatar
Scott Wheeler committed
47 48 49 50 51

    /**
     * This is triggered when the data in the playlist -- i.e. the tag content
     * changes.
     */
52
    virtual void playlistItemsChanged();
53 54 55 56 57

protected:
    virtual ~Watched();

private:
58
    QList<PlaylistObserver *> m_observers;
59
};
Scott Wheeler's avatar
Scott Wheeler committed
60

61 62 63 64 65
/**
 * This is a simple interface that should be used by things that implement a
 * playlist-like API.
 */

66
class PlaylistInterface : public Watched
67 68
{
public:
69
    virtual QString name() const = 0;
70
    virtual FileHandle currentFile() const = 0;
71 72
    virtual int time() const = 0;
    virtual int count() const = 0;
73 74 75 76

    virtual void playNext() = 0;
    virtual void playPrevious() = 0;
    virtual void stop() = 0;
77 78 79 80 81 82 83 84

    virtual bool playing() const = 0;
};

class PlaylistObserver
{
public:
    virtual ~PlaylistObserver();
Scott Wheeler's avatar
Scott Wheeler committed
85 86

    /**
87 88 89
     * This method is called when the item which is currently playing
     * in the given playlist changes.
     * @todo TODO: Move to PlayerManager...
Scott Wheeler's avatar
Scott Wheeler committed
90
     */
91 92
    virtual void playingItemHasChanged()
    { ; }
Scott Wheeler's avatar
Scott Wheeler committed
93 94

    /**
95 96
     * This method is called when the data of a PlaylistItem in the playlist
     * being watched changes.
Scott Wheeler's avatar
Scott Wheeler committed
97
     */
98 99
    virtual void playlistItemDataHasChanged()
    { ; }
100

101
    void clearWatched() { m_playlist = nullptr; }
102 103 104 105 106 107 108

protected:
    PlaylistObserver(PlaylistInterface *playlist);
    const PlaylistInterface *playlist() const;

private:
    PlaylistInterface *m_playlist;
109 110 111
};

#endif
112 113

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