changed: Add logic to properly handle subtitles for stacked files
[vuplus_xbmc] / xbmc / peripherals / devices / Peripheral.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
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, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <set>
23 #include "utils/StdString.h"
24 #include "peripherals/PeripheralTypes.h"
25
26 class TiXmlDocument;
27
28 class CSetting;
29
30 namespace PERIPHERALS
31 {
32   class CGUIDialogPeripheralSettings;
33
34   typedef enum
35   {
36     STATE_SWITCH_TOGGLE,
37     STATE_ACTIVATE_SOURCE,
38     STATE_STANDBY
39   } CecStateChange;
40
41   class CPeripheral
42   {
43     friend class CGUIDialogPeripheralSettings;
44
45   public:
46     CPeripheral(const PeripheralScanResult& scanResult);
47     virtual ~CPeripheral(void);
48
49     bool operator ==(const CPeripheral &right) const;
50     bool operator !=(const CPeripheral &right) const;
51     bool operator ==(const PeripheralScanResult& right) const;
52     bool operator !=(const PeripheralScanResult& right) const;
53
54     const CStdString &FileLocation(void) const     { return m_strFileLocation; }
55     const CStdString &Location(void) const         { return m_strLocation; }
56     int VendorId(void) const                       { return m_iVendorId; }
57     const char *VendorIdAsString(void) const       { return m_strVendorId.c_str(); }
58     int ProductId(void) const                      { return m_iProductId; }
59     const char *ProductIdAsString(void) const      { return m_strProductId.c_str(); }
60     const PeripheralType Type(void) const          { return m_type; }
61     const PeripheralBusType GetBusType(void) const { return m_busType; };
62     const CStdString &DeviceName(void) const       { return m_strDeviceName; }
63     bool IsHidden(void) const                      { return m_bHidden; }
64     void SetHidden(bool bSetTo = true)             { m_bHidden = bSetTo; }
65     const CStdString &GetVersionInfo(void) const   { return m_strVersionInfo; }
66
67     /*!
68      * @brief Check whether this device has the given feature.
69      * @param feature The feature to check for.
70      * @return True when the device has the feature, false otherwise.
71      */
72     bool HasFeature(const PeripheralFeature feature) const;
73
74     /*!
75      * @brief Get all features that are supported by this device.
76      * @param features The features.
77      */
78     void GetFeatures(std::vector<PeripheralFeature> &features) const;
79
80     /*!
81      * @brief Initialises the peripheral.
82      * @return True when the peripheral has been initialised succesfully, false otherwise.
83      */
84     bool Initialise(void);
85
86     /*!
87      * @brief Initialise one of the features of this peripheral.
88      * @param feature The feature to initialise.
89      * @return True when the feature has been initialised succesfully, false otherwise.
90      */
91     virtual bool InitialiseFeature(const PeripheralFeature feature) { return true; }
92
93     /*!
94      * @brief Called when a setting changed.
95      * @param strChangedSetting The changed setting.
96      */
97     virtual void OnSettingChanged(const CStdString &strChangedSetting) {};
98
99     /*!
100      * @brief Called when this device is removed, before calling the destructor.
101      */
102     virtual void OnDeviceRemoved(void) {}
103
104     /*!
105      * @brief Get all subdevices if this device is multifunctional.
106      * @param subDevices The subdevices.
107      */
108     virtual void GetSubdevices(std::vector<CPeripheral *> &subDevices) const;
109
110     /*!
111      * @return True when this device is multifunctional, false otherwise.
112      */
113     virtual bool IsMultiFunctional(void) const;
114
115     /*!
116      * @brief Add a setting to this peripheral. This will overwrite a previous setting with the same key.
117      * @param strKey The key of the setting.
118      * @param setting The setting.
119      */
120     virtual void AddSetting(const CStdString &strKey, const CSetting *setting);
121
122     /*!
123      * @brief Check whether a setting is known with the given key.
124      * @param strKey The key to search.
125      * @return True when found, false otherwise.
126      */
127     virtual bool HasSetting(const CStdString &strKey) const;
128
129     /*!
130      * @return True when this device has any settings, false otherwise.
131      */
132     virtual bool HasSettings(void) const;
133
134     /*!
135      * @return True when this device has any configurable settings, false otherwise.
136      */
137     virtual bool HasConfigurableSettings(void) const;
138
139     /*!
140      * @brief Get the value of a setting.
141      * @param strKey The key to search.
142      * @return The value or an empty string if it wasn't found.
143      */
144     virtual const CStdString GetSettingString(const CStdString &strKey) const;
145     virtual bool SetSetting(const CStdString &strKey, const CStdString &strValue);
146     virtual void SetSettingVisible(const CStdString &strKey, bool bSetTo);
147     virtual bool IsSettingVisible(const CStdString &strKey) const;
148
149     virtual int GetSettingInt(const CStdString &strKey) const;
150     virtual bool SetSetting(const CStdString &strKey, int iValue);
151
152     virtual bool GetSettingBool(const CStdString &strKey) const;
153     virtual bool SetSetting(const CStdString &strKey, bool bValue);
154
155     virtual float GetSettingFloat(const CStdString &strKey) const;
156     virtual bool SetSetting(const CStdString &strKey, float fValue);
157
158     virtual void PersistSettings(bool bExiting = false);
159     virtual void LoadPersistedSettings(void);
160     virtual void ResetDefaultSettings(void);
161
162     virtual std::vector<CSetting *> GetSettings(void) const;
163
164     virtual bool ErrorOccured(void) const { return m_bError; }
165
166   protected:
167     virtual void ClearSettings(void);
168
169     PeripheralType                   m_type;
170     PeripheralBusType                m_busType;
171     PeripheralBusType                m_mappedBusType;
172     CStdString                       m_strLocation;
173     CStdString                       m_strDeviceName;
174     CStdString                       m_strSettingsFile;
175     CStdString                       m_strFileLocation;
176     int                              m_iVendorId;
177     CStdString                       m_strVendorId;
178     int                              m_iProductId;
179     CStdString                       m_strProductId;
180     CStdString                       m_strVersionInfo;
181     bool                             m_bInitialised;
182     bool                             m_bHidden;
183     bool                             m_bError;
184     std::vector<PeripheralFeature>   m_features;
185     std::vector<CPeripheral *>       m_subDevices;
186     std::map<CStdString, CSetting *> m_settings;
187     std::set<CStdString>             m_changedSettings;
188   };
189 }