Revert previous commit, was incorrect
[amarok.git] / src / enginecontroller.h
blob9aca5f11d13fb8ed401cfee4515d5a86d86e78f5
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 *
5 * *
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. *
10 * *
11 ***************************************************************************/
13 #ifndef AMAROK_ENGINECONTROLLER_H
14 #define AMAROK_ENGINECONTROLLER_H
16 #include "enginebase.h"
17 #include "engineobserver.h"
18 #include "meta/Meta.h"
20 #include <QHash>
21 #include <QMap>
22 #include <QObject>
25 class QTimer;
28 namespace KIO { class Job; }
30 /**
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
38 Q_OBJECT
40 public:
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();
63 void endSession();
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*/);
71 public slots:
72 void previous();
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 );
76 void play();
77 void play( const Meta::TrackPtr&, uint offset = 0 );
78 void pause();
79 void stop();
80 void playPause(); //pauses if playing, plays if paused or stopped
82 void seek( int ms );
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 );
91 void mute();
93 void playlistChanged() { m_engine->playlistChanged(); }
95 signals:
96 void orderPrevious();
97 void orderCurrent();
98 void orderNext( const bool );
99 void statusText( const QString& );
100 void trackFinished();
102 private slots:
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); }
108 protected:
109 EngineController();
110 ~EngineController();
112 // undefined
113 EngineController( const EngineController& );
114 EngineController &operator=( const EngineController& );
116 private:
117 static ExtensionCache s_extensionCache;
119 EngineBase* loadEngine( const QString &engineName );
121 EngineBase* m_engine;
122 EngineBase* m_voidEngine;
123 KUrl m_previousUrl;
124 long m_delayTime;
125 int m_muteVolume;
126 bool m_xFadeThisTrack;
127 bool m_isTiming;
128 QTimer* m_timer;
129 uint m_playFailureCount;
130 // try to correct start time for tracks from last.fm streams
131 bool m_lastFm;
132 uint m_positionOffset, m_lastPositionOffset;
133 Meta::TrackPtr m_currentTrack;
137 #endif