summaryrefslogtreecommitdiffstats
path: root/amarok/src/engineobserver.h
blob: 858e8f56a294eeee1faf56ad912178b7a4aa5f14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/***************************************************************************
                      engineobserver.h  -  Observer pattern for engine
                         -------------------
begin                : Mar 14 2003
copyright            : (C) 2003 by Frederik Holljen
email                : fh@ez.no
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 AMAROK_ENGINEOBSERVER_H
#define AMAROK_ENGINEOBSERVER_H

#include "engine_fwd.h"

class EngineSubject;
class MetaBundle;
class TQString;

/**
 * if you want to observe the engine, inherit from this class and attach yourself to
 * the engine with attach
 * Note that all positional information and times are in milliseconds
 */
class EngineObserver
{
public:
    EngineObserver();
    EngineObserver( EngineSubject* );
    virtual ~EngineObserver();
    virtual void engineStateChanged( Engine::State /*state*/, Engine::State /*oldState*/ = Engine::Empty ) {}
    virtual void engineNewMetaData( const MetaBundle &/*bundle*/, bool /*trackChanged*/ ) {}
    virtual void engineTrackEnded( int /*finalPosition*/, int /*trackLength*/, const TQString &/*reason*/ ) {}
    virtual void engineVolumeChanged( int /*percent*/ ) {}
    virtual void engineTrackPositionChanged( long /*position*/ , bool /*userSeek*/ ) {}
    virtual void engineTrackLengthChanged( long /*length*/ ) {}

private:
    EngineSubject *m_subject;
};

#include <tqptrlist.h>
/**
 * Inherited by EngineController.
 * Notify observer functionality is captured in this class.
 */
class EngineSubject
{
public:
    void attach( EngineObserver *observer );
    void detach( EngineObserver *observer );

protected:
    EngineSubject();
    virtual ~EngineSubject();
    void stateChangedNotify( Engine::State /*state*/ );
    void newMetaDataNotify( const MetaBundle &/*bundle*/, bool /*trackChanged*/ );
    void trackEnded( int /*finalPosition*/, int /*trackLength*/, const TQString &reason );
    void volumeChangedNotify( int /*percent*/ );
    /* userSeek means the position didn't change due to normal playback */
    void trackPositionChangedNotify( long /*position*/ , bool userSeek=false );
    void trackLengthChangedNotify( long /*length*/ );

private:
    TQPtrList<EngineObserver> Observers;
    Engine::State m_oldEngineState;
};

#endif // AMAROK_ENGINEOBSERVER_H