Merge pull request #1129 from jmarshallnz/remove_smb_auth_details_in_add_source
[vuplus_xbmc] / xbmc / Application.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2008 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, write to
19  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20  *  http://www.gnu.org/copyleft/gpl.html
21  *
22  */
23
24 #include "system.h" // for HAS_DVD_DRIVE et. al.
25 #include "XBApplicationEx.h"
26
27 #include "guilib/IMsgTargetCallback.h"
28 #include "threads/Condition.h"
29
30 #include <map>
31
32 class CFileItem;
33 class CFileItemList;
34 namespace ADDON
35 {
36   class CSkinInfo;
37   class IAddon;
38   typedef boost::shared_ptr<IAddon> AddonPtr;
39 }
40
41 namespace MEDIA_DETECT
42 {
43   class CAutorun;
44 }
45
46 #include "cores/IPlayer.h"
47 #include "cores/playercorefactory/PlayerCoreFactory.h"
48 #include "PlayListPlayer.h"
49 #if !defined(_WIN32) && defined(HAS_DVD_DRIVE)
50 #include "storage/DetectDVDType.h"
51 #endif
52 #ifdef _WIN32
53 #include "win32/WIN32Util.h"
54 #endif
55 #include "utils/Stopwatch.h"
56 #include "ApplicationMessenger.h"
57 #include "network/Network.h"
58 #include "utils/CharsetConverter.h"
59 #ifdef HAS_PERFORMANCE_SAMPLE
60 #include "utils/PerformanceStats.h"
61 #endif
62 #include "windowing/XBMC_events.h"
63 #include "threads/Thread.h"
64
65 class CKaraokeLyricsManager;
66 class CInertialScrollingHandler;
67 class CApplicationMessenger;
68 class DPMSSupport;
69 class CSplash;
70 class CBookmark;
71 class CWebServer;
72 #ifdef HAS_WEB_SERVER
73 class CWebServer;
74 class CHTTPImageHandler;
75 class CHTTPVfsHandler;
76 #ifdef HAS_JSONRPC
77 class CHTTPJsonRpcHandler;
78 #endif
79 #ifdef HAS_HTTPAPI
80 class CHTTPApiHandler;
81 #endif
82 #ifdef HAS_WEB_INTERFACE
83 class CHTTPWebinterfaceHandler;
84 class CHTTPWebinterfaceAddonsHandler;
85 #endif
86 #endif
87 namespace VIDEO
88 {
89   class CVideoInfoScanner;
90 }
91
92 namespace MUSIC_INFO
93 {
94   class CMusicInfoScanner;
95 }
96
97 class CBackgroundPlayer : public CThread
98 {
99 public:
100   CBackgroundPlayer(const CFileItem &item, int iPlayList);
101   virtual ~CBackgroundPlayer();
102   virtual void Process();
103 protected:
104   CFileItem *m_item;
105   int       m_iPlayList;
106 };
107
108 class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMsgTargetCallback
109 {
110 public:
111   CApplication(void);
112   virtual ~CApplication(void);
113   virtual bool Initialize();
114   virtual void FrameMove(bool processEvents, bool processGUI = true);
115   virtual void Render();
116   virtual bool RenderNoPresent();
117   virtual void Preflight();
118   virtual bool Create();
119   virtual bool Cleanup();
120
121   bool CreateGUI();
122   bool InitWindow();
123   bool DestroyWindow();
124   void StartServices();
125   void StopServices();
126   bool StartWebServer();
127   void StopWebServer();
128   void StartAirplayServer();  
129   void StopAirplayServer(bool bWait);   
130   bool StartJSONRPCServer();
131   void StopJSONRPCServer(bool bWait);
132   void StartUPnP();
133   void StopUPnP(bool bWait);
134   void StartUPnPRenderer();
135   void StopUPnPRenderer();
136   void StartUPnPServer();
137   void StopUPnPServer();
138   bool StartEventServer();
139   bool StopEventServer(bool bWait, bool promptuser);
140   void RefreshEventServer();
141   void StartZeroconf();
142   void StopZeroconf();
143   void DimLCDOnPlayback(bool dim);
144   bool IsCurrentThread() const;
145   void Stop(int exitCode);
146   void RestartApp();
147   void UnloadSkin(bool forReload = false);
148   bool LoadUserWindows();
149   void ReloadSkin();
150   const CStdString& CurrentFile();
151   CFileItem& CurrentFileItem();
152   virtual bool OnMessage(CGUIMessage& message);
153   PLAYERCOREID GetCurrentPlayer();
154   virtual void OnPlayBackEnded();
155   virtual void OnPlayBackStarted();
156   virtual void OnPlayBackPaused();
157   virtual void OnPlayBackResumed();
158   virtual void OnPlayBackStopped();
159   virtual void OnQueueNextItem();
160   virtual void OnPlayBackSeek(int iTime, int seekOffset);
161   virtual void OnPlayBackSeekChapter(int iChapter);
162   virtual void OnPlayBackSpeedChanged(int iSpeed);
163   bool PlayMedia(const CFileItem& item, int iPlaylist = PLAYLIST_MUSIC);
164   bool PlayMediaSync(const CFileItem& item, int iPlaylist = PLAYLIST_MUSIC);
165   bool ProcessAndStartPlaylist(const CStdString& strPlayList, PLAYLIST::CPlayList& playlist, int iPlaylist, int track=0);
166   bool PlayFile(const CFileItem& item, bool bRestart = false);
167   void SaveFileState(bool bForeground = false);
168   void UpdateFileState();
169   void StopPlaying();
170   void Restart(bool bSamePosition = true);
171   void DelayedPlayerRestart();
172   void CheckDelayedPlayerRestart();
173   bool IsPlaying() const;
174   bool IsPaused() const;
175   bool IsPlayingAudio() const;
176   bool IsPlayingVideo() const;
177   bool IsPlayingFullScreenVideo() const;
178   bool IsStartingPlayback() const { return m_bPlaybackStarting; }
179   bool IsFullScreen();
180   bool OnKey(const CKey& key);
181   bool OnAppCommand(const CAction &action);
182   bool OnAction(const CAction &action);
183   void CheckShutdown();
184   // Checks whether the screensaver and / or DPMS should become active.
185   void CheckScreenSaverAndDPMS();
186   void CheckPlayingProgress();
187   void CheckAudioScrobblerStatus();
188   void CheckForTitleChange();
189   void ActivateScreenSaver(bool forceType = false);
190
191   virtual void Process();
192   void ProcessSlow();
193   void ResetScreenSaver();
194   int GetVolume() const;
195   void SetVolume(float iValue, bool isPercentage = true);
196   bool IsMuted() const;
197   void ToggleMute(void);
198   void ShowVolumeBar(const CAction *action = NULL);
199   int GetPlaySpeed() const;
200   int GetSubtitleDelay() const;
201   int GetAudioDelay() const;
202   void SetPlaySpeed(int iSpeed);
203   void ResetSystemIdleTimer();
204   void ResetScreenSaverTimer();
205   void StopScreenSaverTimer();
206   // Wakes up from the screensaver and / or DPMS. Returns true if woken up.
207   bool WakeUpScreenSaverAndDPMS(bool bPowerOffKeyPressed = false);
208   bool WakeUpScreenSaver(bool bPowerOffKeyPressed = false);
209   double GetTotalTime() const;
210   double GetTime() const;
211   float GetPercentage() const;
212
213   // Get the percentage of data currently cached/buffered (aq/vq + FileCache) from the input stream if applicable.
214   float GetCachePercentage() const;
215
216   void SeekPercentage(float percent);
217   void SeekTime( double dTime = 0.0 );
218
219   void StopShutdownTimer();
220   void ResetShutdownTimers();
221
222   void SaveMusicScanSettings();
223   void RestoreMusicScanSettings();
224
225   void StopVideoScan();
226   void StopMusicScan();
227   bool IsMusicScanning() const;
228   bool IsVideoScanning() const;
229
230   void StartVideoCleanup();
231
232   void StartVideoScan(const CStdString &path, bool scanAll = false);
233   void StartMusicScan(const CStdString &path, int flags = 0);
234   void StartMusicAlbumScan(const CStdString& strDirectory, bool refresh=false);
235   void StartMusicArtistScan(const CStdString& strDirectory, bool refresh=false);
236
237   void UpdateLibraries();
238   void CheckMusicPlaylist();
239
240   bool ExecuteXBMCAction(std::string action);
241
242   static bool OnEvent(XBMC_Event& newEvent);
243
244   CApplicationMessenger& getApplicationMessenger();
245 #if defined(HAS_LINUX_NETWORK)
246   CNetworkLinux& getNetwork();
247 #elif defined(HAS_WIN32_NETWORK)
248   CNetworkWin32& getNetwork();
249 #else
250   CNetwork& getNetwork();
251 #endif
252 #ifdef HAS_PERFORMANCE_SAMPLE
253   CPerformanceStats &GetPerformanceStats();
254 #endif
255
256 #ifdef HAS_DVD_DRIVE
257   MEDIA_DETECT::CAutorun* m_Autorun;
258 #endif
259
260 #if !defined(_WIN32) && defined(HAS_DVD_DRIVE)
261   MEDIA_DETECT::CDetectDVDMedia m_DetectDVDType;
262 #endif
263
264   IPlayer* m_pPlayer;
265
266 #ifdef HAS_WEB_SERVER
267   CWebServer& m_WebServer;
268   CHTTPImageHandler& m_httpImageHandler;
269   CHTTPVfsHandler& m_httpVfsHandler;
270 #ifdef HAS_JSONRPC
271   CHTTPJsonRpcHandler& m_httpJsonRpcHandler;
272 #endif
273 #ifdef HAS_HTTPAPI
274   CHTTPApiHandler& m_httpApiHandler;
275 #endif
276 #ifdef HAS_WEB_INTERFACE
277   CHTTPWebinterfaceHandler& m_httpWebinterfaceHandler;
278   CHTTPWebinterfaceAddonsHandler& m_httpWebinterfaceAddonsHandler;
279 #endif
280 #endif
281
282   inline bool IsInScreenSaver() { return m_bScreenSave; };
283   int m_iScreenSaveLock; // spiff: are we checking for a lock? if so, ignore the screensaver state, if -1 we have failed to input locks
284
285   bool m_bIsPaused;
286   bool m_bPlaybackStarting;
287
288   CKaraokeLyricsManager* m_pKaraokeMgr;
289
290   PLAYERCOREID m_eForcedNextPlayer;
291   CStdString m_strPlayListFile;
292
293   int GlobalIdleTime();
294   void NewFrame();
295   bool WaitFrame(unsigned int timeout);
296
297   void EnablePlatformDirectories(bool enable=true)
298   {
299     m_bPlatformDirectories = enable;
300   }
301
302   bool PlatformDirectoriesEnabled()
303   {
304     return m_bPlatformDirectories;
305   }
306
307   void SetStandAlone(bool value);
308
309   bool IsStandAlone()
310   {
311     return m_bStandalone;
312   }
313
314   void SetEnableLegacyRes(bool value)
315   {
316     m_bEnableLegacyRes = value;
317   }
318
319   bool IsEnableLegacyRes()
320   {
321     return m_bEnableLegacyRes;
322   }
323
324   void SetEnableTestMode(bool value)
325   {
326     m_bTestMode = value;
327   }
328
329   bool IsEnableTestMode()
330   {
331     return m_bTestMode;
332   }
333
334   bool IsPresentFrame();
335
336   void Minimize();
337   bool ToggleDPMS(bool manual);
338
339   float GetDimScreenSaverLevel() const;
340 protected:
341   bool LoadSkin(const CStdString& skinID);
342   void LoadSkin(const boost::shared_ptr<ADDON::CSkinInfo>& skin);
343
344   bool m_skinReloading; // if true we disallow LoadSkin until ReloadSkin is called
345
346   friend class CApplicationMessenger;
347 #if defined(TARGET_DARWIN_IOS)
348   friend class CWinEventsIOS;
349 #endif
350   // screensaver
351   bool m_bScreenSave;
352   ADDON::AddonPtr m_screenSaver;
353
354   // timer information
355 #ifdef _WIN32
356   CWinIdleTimer m_idleTimer;
357 #else
358   CStopWatch m_idleTimer;
359 #endif
360   CStopWatch m_restartPlayerTimer;
361   CStopWatch m_frameTime;
362   CStopWatch m_navigationTimer;
363   CStopWatch m_slowTimer;
364   CStopWatch m_screenSaverTimer;
365   CStopWatch m_shutdownTimer;
366
367   DPMSSupport* m_dpms;
368   bool m_dpmsIsActive;
369   bool m_dpmsIsManual;
370
371   CFileItemPtr m_itemCurrentFile;
372   CFileItemList* m_currentStack;
373   CFileItemPtr m_stackFileItemToUpdate;
374
375   CStdString m_prevMedia;
376   CSplash* m_splash;
377   ThreadIdentifier m_threadID;       // application thread ID.  Used in applicationMessanger to know where we are firing a thread with delay from.
378   PLAYERCOREID m_eCurrentPlayer;
379   bool m_bSettingsLoaded;
380   bool m_bAllSettingsLoaded;
381   bool m_bInitializing;
382   bool m_bPlatformDirectories;
383
384   CBookmark& m_progressTrackingVideoResumeBookmark;
385   CFileItemPtr m_progressTrackingItem;
386   bool m_progressTrackingPlayCountUpdate;
387
388   int m_iPlaySpeed;
389   int m_currentStackPosition;
390   int m_nextPlaylistItem;
391
392   bool m_bPresentFrame;
393   unsigned int m_lastFrameTime;
394   unsigned int m_lastRenderTime;
395
396   bool m_bStandalone;
397   bool m_bEnableLegacyRes;
398   bool m_bTestMode;
399   bool m_bSystemScreenSaverEnable;
400   
401   int        m_frameCount;
402   CCriticalSection m_frameMutex;
403   XbmcThreads::ConditionVariable  m_frameCond;
404
405   VIDEO::CVideoInfoScanner *m_videoInfoScanner;
406   MUSIC_INFO::CMusicInfoScanner *m_musicInfoScanner;
407
408   void Mute();
409   void UnMute();
410
411   void SetHardwareVolume(float hardwareVolume);
412   void UpdateLCD();
413   void FatalErrorHandler(bool WindowSystemInitialized, bool MapDrives, bool InitNetwork);
414
415   void VolumeChanged() const;
416
417   bool PlayStack(const CFileItem& item, bool bRestart);
418   bool SwitchToFullScreen();
419   bool ProcessMouse();
420   bool ProcessRemote(float frameTime);
421   bool ProcessGamepad(float frameTime);
422   bool ProcessEventServer(float frameTime);
423   bool ProcessPeripherals(float frameTime);
424   bool ProcessHTTPApiButtons();
425   bool ProcessJsonRpcButtons();
426   bool ProcessJoystickEvent(const std::string& joystickName, int button, bool isAxis, float fAmount, unsigned int holdTime = 0);
427   int  GetActiveWindowID(void);
428
429   float NavigationIdleTime();
430   static bool AlwaysProcess(const CAction& action);
431
432   void SaveCurrentFileSettings();
433
434   bool InitDirectoriesLinux();
435   bool InitDirectoriesOSX();
436   bool InitDirectoriesWin32();
437   void CreateUserDirs();
438
439   CInertialScrollingHandler *m_pInertialScrollingHandler;
440   CApplicationMessenger m_applicationMessenger;
441 #if defined(HAS_LINUX_NETWORK)
442   CNetworkLinux m_network;
443 #elif defined(HAS_WIN32_NETWORK)
444   CNetworkWin32 m_network;
445 #else
446   CNetwork    m_network;
447 #endif
448 #ifdef HAS_PERFORMANCE_SAMPLE
449   CPerformanceStats m_perfStats;
450 #endif
451
452 #ifdef HAS_EVENT_SERVER
453   std::map<std::string, std::map<int, float> > m_lastAxisMap;
454 #endif
455
456 };
457
458 extern CApplication g_application;