1 /***************************************************************************
2 * Copyright (C) 2004 Frederik Holljen <fh@ez.no> *
3 * (C) 2004,5 Max Howell <max.howell@methylblue.com> *
4 * (C) 2004,5 Mark Kretschmann *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 ***************************************************************************/
13 #ifndef AMAROK_ENGINECONTROLLER_H
14 #define AMAROK_ENGINECONTROLLER_H
16 #include "enginebase.h"
17 #include "engineobserver.h"
18 #include "meta/Meta.h"
28 namespace KIO
{ class Job
; }
31 * This class captures Amarok specific behaviour for some common features.
32 * Accessing the engine directly is perfectly legal but on your own risk.
33 * TODO: Hide proxy stuff!
36 class AMAROK_EXPORT EngineController
: public QObject
, public EngineSubject
41 typedef QMap
<QString
, bool> ExtensionCache
;
43 // plugins have their own static space, so calling instance
44 // from a plugin won't do any good. you'll only get a new
45 // instance with a voidEngine
46 static EngineController
* instance();
47 static EngineBase
* engine() { return instance()->m_engine
; }
48 static bool canDecode( const KUrl
& );
49 static ExtensionCache
& extensionCache() { return s_extensionCache
; }
50 static QString
engineProperty( const QString
& key
) { return engine()->pluginProperty( key
); }
51 static bool hasEngineProperty( const QString
& key
) { return engine()->hasPluginProperty( key
); }
53 uint
trackPosition() const;
55 EngineBase
* loadEngine();
57 Meta::TrackPtr
currentTrack() const;
58 uint
trackLength() const;
59 KUrl
previousURL() const { return m_previousUrl
; }
60 KUrl
playingURL() const;
62 void restoreSession();
65 //xx000, xx100, xx200, so at most will be 200ms delay before time displays are updated
66 static const int MAIN_TIMER
= 150;
68 /*enum Filetype { MP3 };*/ //assuming MP3 for time being
69 /*AMAROK_EXPORT*/ static bool installDistroCodec(const QString
& engine
/*Filetype type*/);
73 // forceNext make we go to next track even if Repeat Track is on
74 //NOTE If the track ended normally, call next(false) !
75 void next( const bool forceNext
= true );
77 void play( const Meta::TrackPtr
&, uint offset
= 0 );
80 void playPause(); //pauses if playing, plays if paused or stopped
83 void seekRelative( int ms
);
84 void seekForward( int ms
= 10000 );
85 void seekBackward( int ms
= 10000 );
87 int increaseVolume( int ticks
= 100/25 );
88 int decreaseVolume( int ticks
= 100/25 );
89 int setVolume( int percent
);
93 void playlistChanged() { m_engine
->playlistChanged(); }
98 void orderNext( const bool );
99 void statusText( const QString
& );
100 void trackFinished();
103 void slotEngineMetaData( const QHash
<qint64
, QString
> &newMetaData
);
104 void slotMainTimer();
105 void slotTrackEnded();
106 void slotStateChanged( Engine::State
);
107 void trackDone() { emit
trackFinished(); next(false); }
113 EngineController( const EngineController
& );
114 EngineController
&operator=( const EngineController
& );
117 static ExtensionCache s_extensionCache
;
119 EngineBase
* loadEngine( const QString
&engineName
);
121 EngineBase
* m_engine
;
122 EngineBase
* m_voidEngine
;
126 bool m_xFadeThisTrack
;
129 uint m_playFailureCount
;
130 // try to correct start time for tracks from last.fm streams
132 uint m_positionOffset
, m_lastPositionOffset
;
133 Meta::TrackPtr m_currentTrack
;