1 /***************************************************************************
2 engineobserver.cpp - 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 #include "engineobserver.h"
21 #include "collectiondb.h"
22 #include "podcastbundle.h"
25 //////////////////////////////////////////////////////////////////////////////////////////
26 /// CLASS EngineObserver
27 //////////////////////////////////////////////////////////////////////////////////////////
29 EngineObserver::EngineObserver()
33 EngineObserver::EngineObserver( EngineSubject
*s
)
36 m_subject
->attach( this );
39 EngineObserver::~EngineObserver()
42 m_subject
->detach( this );
46 EngineObserver::engineStateChanged( Engine::State currentState
, Engine::State oldState
)
49 Q_UNUSED( currentState
);
53 EngineObserver::engineTrackEnded( int finalPosition
, int trackLength
, const QString
&reason
)
55 Q_UNUSED( finalPosition
);
56 Q_UNUSED( trackLength
);
61 EngineObserver::engineNewTrackPlaying()
66 EngineObserver::engineNewMetaData( const QHash
<qint64
, QString
> &newMetaData
, bool trackChanged
)
68 Q_UNUSED( newMetaData
);
69 Q_UNUSED( trackChanged
);
73 EngineObserver::engineVolumeChanged( int percent
)
79 EngineObserver::engineTrackPositionChanged( long position
, bool userSeek
)
86 EngineObserver::engineTrackLengthChanged( long seconds
)
91 //////////////////////////////////////////////////////////////////////////////////////////
92 /// CLASS EngineSubject
93 //////////////////////////////////////////////////////////////////////////////////////////
95 EngineSubject::EngineSubject()
96 : m_oldEngineState( Engine::Empty
)
99 EngineSubject::~EngineSubject()
101 //do not delete the observers, we don't ahve ownership of them!
105 void EngineSubject::stateChangedNotify( Engine::State state
)
107 foreach( EngineObserver
*observer
, Observers
)
109 observer
->engineStateChanged( state
, m_oldEngineState
);
112 m_oldEngineState
= state
;
115 void EngineSubject::trackEnded( int finalPosition
, int trackLength
, const QString
&reason
)
117 foreach( EngineObserver
*observer
, Observers
)
118 observer
->engineTrackEnded( finalPosition
, trackLength
, reason
);
122 EngineSubject::newMetaDataNotify( const QHash
<qint64
, QString
> &newMetaData
, bool trackChanged
) const
124 foreach( EngineObserver
*observer
, Observers
)
125 observer
->engineNewMetaData( newMetaData
, trackChanged
);
128 void EngineSubject::volumeChangedNotify( int percent
)
130 foreach( EngineObserver
*observer
, Observers
)
132 observer
->engineVolumeChanged( percent
);
137 void EngineSubject::trackPositionChangedNotify( long position
, bool userSeek
)
139 foreach( EngineObserver
*observer
, Observers
)
141 observer
->engineTrackPositionChanged( position
, userSeek
);
146 void EngineSubject::trackLengthChangedNotify( long seconds
)
148 foreach( EngineObserver
*observer
, Observers
)
150 observer
->engineTrackLengthChanged( seconds
);
155 EngineSubject::newTrackPlaying() const
157 foreach( EngineObserver
*observer
, Observers
)
158 observer
->engineNewTrackPlaying();
162 void EngineSubject::attach( EngineObserver
*observer
)
166 Observers
.insert( observer
);
170 void EngineSubject::detach( EngineObserver
*observer
)
172 Observers
.remove( observer
);