Revert previous commit, was incorrect
[amarok.git] / src / engineobserver.cpp
blobb55dab6d229343d5692baed1837c0dec74dfa727
1 /***************************************************************************
2 engineobserver.cpp - Observer pattern for engine
3 -------------------
4 begin : Mar 14 2003
5 copyright : (C) 2003 by Frederik Holljen
6 email : fh@ez.no
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
18 #include "engineobserver.h"
20 #include "debug.h"
21 #include "collectiondb.h"
22 #include "podcastbundle.h"
25 //////////////////////////////////////////////////////////////////////////////////////////
26 /// CLASS EngineObserver
27 //////////////////////////////////////////////////////////////////////////////////////////
29 EngineObserver::EngineObserver()
30 : m_subject( 0 )
33 EngineObserver::EngineObserver( EngineSubject *s )
34 : m_subject( s )
36 m_subject->attach( this );
39 EngineObserver::~EngineObserver()
41 if ( m_subject )
42 m_subject->detach( this );
45 void
46 EngineObserver::engineStateChanged( Engine::State currentState, Engine::State oldState )
48 Q_UNUSED( oldState );
49 Q_UNUSED( currentState );
52 void
53 EngineObserver::engineTrackEnded( int finalPosition, int trackLength, const QString &reason )
55 Q_UNUSED( finalPosition );
56 Q_UNUSED( trackLength );
57 Q_UNUSED( reason );
60 void
61 EngineObserver::engineNewTrackPlaying()
65 void
66 EngineObserver::engineNewMetaData( const QHash<qint64, QString> &newMetaData, bool trackChanged )
68 Q_UNUSED( newMetaData );
69 Q_UNUSED( trackChanged );
72 void
73 EngineObserver::engineVolumeChanged( int percent )
75 Q_UNUSED( percent );
78 void
79 EngineObserver::engineTrackPositionChanged( long position , bool userSeek )
81 Q_UNUSED( position );
82 Q_UNUSED( userSeek );
85 void
86 EngineObserver::engineTrackLengthChanged( long seconds )
88 Q_UNUSED( 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 );
121 void
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 );
154 void
155 EngineSubject::newTrackPlaying() const
157 foreach( EngineObserver *observer, Observers )
158 observer->engineNewTrackPlaying();
162 void EngineSubject::attach( EngineObserver *observer )
164 if( !observer )
165 return;
166 Observers.insert( observer );
170 void EngineSubject::detach( EngineObserver *observer )
172 Observers.remove( observer );