1 /***************************************************************************
2 engineobserver.h - Observer pattern for engine
5 copyright : (C) 2003 by Frederik Holljen
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #ifndef AMAROK_ENGINEOBSERVER_H
19 #define AMAROK_ENGINEOBSERVER_H
21 #include "amarok_export.h"
22 #include "engine_fwd.h"
31 * if you want to observe the engine, inherit from this class and attach yourself to
32 * the engine with attach
33 * Note that all positional information and times are in milliseconds
35 class AMAROK_EXPORT EngineObserver
39 EngineObserver( EngineSubject
* );
40 virtual ~EngineObserver();
41 virtual void engineStateChanged( Engine::State currentState
, Engine::State oldState
= Engine::Empty
);
42 virtual void engineTrackEnded( int finalPosition
, int trackLength
, const QString
&reason
);
43 virtual void engineNewTrackPlaying();
44 virtual void engineNewMetaData( const QHash
<qint64
, QString
> &newMetaData
, bool trackChanged
);
45 virtual void engineVolumeChanged( int percent
);
46 virtual void engineTrackPositionChanged( long position
, bool userSeek
);
47 virtual void engineTrackLengthChanged( long seconds
);
50 EngineSubject
*m_subject
;
54 * Inherited by EngineController.
55 * Notify observer functionality is captured in this class.
60 void AMAROK_EXPORT
attach( EngineObserver
*observer
);
61 void AMAROK_EXPORT
detach( EngineObserver
*observer
);
65 virtual ~EngineSubject();
66 void stateChangedNotify( Engine::State
/*state*/ );
67 void trackEnded( int /*finalPosition*/, int /*trackLength*/, const QString
&reason
);
68 void newMetaDataNotify( const QHash
<qint64
, QString
> &newMetaData
, bool trackChanged
) const;
69 void volumeChangedNotify( int /*percent*/ );
70 /* userSeek means the position didn't change due to normal playback */
71 void trackPositionChangedNotify( long /*position*/ , bool userSeek
=false );
72 void trackLengthChangedNotify( long /*seconds*/ );
73 void newTrackPlaying() const;
76 QSet
<EngineObserver
*> Observers
;
77 Engine::State m_oldEngineState
;
80 #endif // AMAROK_ENGINEOBSERVER_H