Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / addons / ScreenSaver.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20 #include "ScreenSaver.h"
21 #include "interfaces/generic/ScriptInvocationManager.h"
22 #include "settings/DisplaySettings.h"
23 #include "utils/AlarmClock.h"
24 #include "windowing/WindowingFactory.h"
25
26 // What sound does a python screensaver make?
27 #define SCRIPT_ALARM "sssssscreensaver"
28
29 #define SCRIPT_TIMEOUT 5 // seconds
30
31 namespace ADDON
32 {
33
34   CScreenSaver::CScreenSaver(const char *addonID)
35    : ADDON::CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>(AddonProps(addonID, ADDON_UNKNOWN, "", ""))
36   {
37   }
38
39 AddonPtr CScreenSaver::Clone() const
40 {
41   // Copy constructor is generated by compiler and calls parent copy constructor
42   return AddonPtr(new CScreenSaver(*this));
43 }
44
45 bool CScreenSaver::CreateScreenSaver()
46 {
47   if (CScriptInvocationManager::Get().HasLanguageInvoker(LibPath()))
48   {
49     // Don't allow a previously-scheduled alarm to kill our new screensaver
50     g_alarmClock.Stop(SCRIPT_ALARM, true);
51
52     if (!CScriptInvocationManager::Get().Stop(LibPath()))
53       CScriptInvocationManager::Get().Execute(LibPath(), Clone());
54     return true;
55   }
56  // pass it the screen width,height
57  // and the name of the screensaver
58   int iWidth = g_graphicsContext.GetWidth();
59   int iHeight = g_graphicsContext.GetHeight();
60
61   m_pInfo = new SCR_PROPS;
62 #ifdef HAS_DX
63   m_pInfo->device     = g_Windowing.Get3DDevice();
64 #else
65   m_pInfo->device     = NULL;
66 #endif
67   m_pInfo->x          = 0;
68   m_pInfo->y          = 0;
69   m_pInfo->width      = iWidth;
70   m_pInfo->height     = iHeight;
71   m_pInfo->pixelRatio = g_graphicsContext.GetResInfo().fPixelRatio;
72   m_pInfo->name       = strdup(Name().c_str());
73   m_pInfo->presets    = strdup(CSpecialProtocol::TranslatePath(Path()).c_str());
74   m_pInfo->profile    = strdup(CSpecialProtocol::TranslatePath(Profile()).c_str());
75
76   if (CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Create() == ADDON_STATUS_OK)
77     return true;
78
79   return false;
80 }
81
82 void CScreenSaver::Start()
83 {
84   // notify screen saver that they should start
85   if (Initialized()) m_pStruct->Start();
86 }
87
88 void CScreenSaver::Render()
89 {
90   // ask screensaver to render itself
91   if (Initialized()) m_pStruct->Render();
92 }
93
94 void CScreenSaver::GetInfo(SCR_INFO *info)
95 {
96   // get info from screensaver
97   if (Initialized()) m_pStruct->GetInfo(info);
98 }
99
100 void CScreenSaver::Destroy()
101 {
102 #ifdef HAS_PYTHON
103   if (URIUtils::HasExtension(LibPath(), ".py"))
104   {
105     g_alarmClock.Start(SCRIPT_ALARM, SCRIPT_TIMEOUT, "StopScript(" + LibPath() + ")", true, false);
106     return;
107   }
108 #endif
109   // Release what was allocated in method CScreenSaver::CreateScreenSaver.
110   if (m_pInfo)
111   {
112     free((void *) m_pInfo->name);
113     free((void *) m_pInfo->presets);
114     free((void *) m_pInfo->profile);
115
116     delete m_pInfo;
117     m_pInfo = NULL;
118   }
119
120   CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Destroy();
121 }
122
123 } /*namespace ADDON*/
124