1 | /* $Id: UISettingsDefs.h 103803 2024-03-12 11:15:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Header with definitions and functions related to settings configuration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_settings_UISettingsDefs_h
|
---|
29 | #define FEQT_INCLUDED_SRC_settings_UISettingsDefs_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QMap>
|
---|
36 | #include <QPair>
|
---|
37 | #include <QString>
|
---|
38 |
|
---|
39 | /* GUI includes: */
|
---|
40 | #include "UILibraryDefs.h"
|
---|
41 |
|
---|
42 | /* COM includes: */
|
---|
43 | #include "KSessionState.h"
|
---|
44 | #include "KMachineState.h"
|
---|
45 |
|
---|
46 | /** Settings configuration namespace. */
|
---|
47 | namespace UISettingsDefs
|
---|
48 | {
|
---|
49 | /** Configuration access levels. */
|
---|
50 | enum ConfigurationAccessLevel
|
---|
51 | {
|
---|
52 | /** Configuration is not accessible. */
|
---|
53 | ConfigurationAccessLevel_Null,
|
---|
54 | /** Configuration is accessible fully. */
|
---|
55 | ConfigurationAccessLevel_Full,
|
---|
56 | /** Configuration is accessible partially, machine is in @a powered_off state. */
|
---|
57 | ConfigurationAccessLevel_Partial_PoweredOff,
|
---|
58 | /** Configuration is accessible partially, machine is in @a saved state. */
|
---|
59 | ConfigurationAccessLevel_Partial_Saved,
|
---|
60 | /** Configuration is accessible partially, machine is in @a running state. */
|
---|
61 | ConfigurationAccessLevel_Partial_Running,
|
---|
62 | };
|
---|
63 |
|
---|
64 | /** Recording mode enum is used in Display setting page to determine the recording mode. */
|
---|
65 | enum RecordingMode
|
---|
66 | {
|
---|
67 | RecordingMode_None = 0,
|
---|
68 | RecordingMode_VideoAudio = 1,
|
---|
69 | RecordingMode_VideoOnly = 2,
|
---|
70 | RecordingMode_AudioOnly = 3,
|
---|
71 | RecordingMode_Max = 4
|
---|
72 | };
|
---|
73 |
|
---|
74 | /** Determines configuration access level for passed @a enmSessionState and @a enmMachineState. */
|
---|
75 | SHARED_LIBRARY_STUFF ConfigurationAccessLevel configurationAccessLevel(KSessionState enmSessionState,
|
---|
76 | KMachineState enmMachineState);
|
---|
77 | }
|
---|
78 |
|
---|
79 | Q_DECLARE_METATYPE(UISettingsDefs::RecordingMode);
|
---|
80 |
|
---|
81 |
|
---|
82 | /** Template organizing settings object cache: */
|
---|
83 | template <class CacheData> class UISettingsCache
|
---|
84 | {
|
---|
85 | public:
|
---|
86 |
|
---|
87 | /** Constructs empty object cache. */
|
---|
88 | UISettingsCache() { m_value = qMakePair(CacheData(), CacheData()); }
|
---|
89 |
|
---|
90 | /** Destructs cache object. */
|
---|
91 | virtual ~UISettingsCache() { /* Makes MSC happy */ }
|
---|
92 |
|
---|
93 | /** Returns the NON-modifiable REFERENCE to the initial cached data. */
|
---|
94 | const CacheData &base() const { return m_value.first; }
|
---|
95 | /** Returns the NON-modifiable REFERENCE to the current cached data. */
|
---|
96 | const CacheData &data() const { return m_value.second; }
|
---|
97 | /** Returns the modifiable REFERENCE to the initial cached data. */
|
---|
98 | CacheData &base() { return m_value.first; }
|
---|
99 | /** Returns the modifiable REFERENCE to the current cached data. */
|
---|
100 | CacheData &data() { return m_value.second; }
|
---|
101 |
|
---|
102 | /** Returns whether the cached object was removed.
|
---|
103 | * We assume that cached object was removed if
|
---|
104 | * initial data was set but current data was NOT set. */
|
---|
105 | virtual bool wasRemoved() const { return base() != CacheData() && data() == CacheData(); }
|
---|
106 |
|
---|
107 | /** Returns whether the cached object was created.
|
---|
108 | * We assume that cached object was created if
|
---|
109 | * initial data was NOT set but current data was set. */
|
---|
110 | virtual bool wasCreated() const { return base() == CacheData() && data() != CacheData(); }
|
---|
111 |
|
---|
112 | /** Returns whether the cached object was updated.
|
---|
113 | * We assume that cached object was updated if
|
---|
114 | * current and initial data were both set and not equal to each other. */
|
---|
115 | virtual bool wasUpdated() const { return base() != CacheData() && data() != CacheData() && data() != base(); }
|
---|
116 |
|
---|
117 | /** Returns whether the cached object was changed.
|
---|
118 | * We assume that cached object was changed if
|
---|
119 | * it was 1. removed, 2. created or 3. updated. */
|
---|
120 | virtual bool wasChanged() const { return wasRemoved() || wasCreated() || wasUpdated(); }
|
---|
121 |
|
---|
122 | /** Defines initial cached object data. */
|
---|
123 | void cacheInitialData(const CacheData &initialData) { m_value.first = initialData; }
|
---|
124 | /** Defines current cached object data: */
|
---|
125 | void cacheCurrentData(const CacheData ¤tData) { m_value.second = currentData; }
|
---|
126 |
|
---|
127 | /** Resets the initial and the current object data to be both empty. */
|
---|
128 | void clear() { m_value.first = CacheData(); m_value.second = CacheData(); }
|
---|
129 |
|
---|
130 | private:
|
---|
131 |
|
---|
132 | /** Holds the cached object data. */
|
---|
133 | QPair<CacheData, CacheData> m_value;
|
---|
134 | };
|
---|
135 |
|
---|
136 |
|
---|
137 | /** Template organizing settings object cache with children. */
|
---|
138 | template <class ParentCacheData, class ChildCacheData> class UISettingsCachePool : public UISettingsCache<ParentCacheData>
|
---|
139 | {
|
---|
140 | public:
|
---|
141 |
|
---|
142 | /** Children map. */
|
---|
143 | typedef QMap<QString, ChildCacheData> UISettingsCacheChildMap;
|
---|
144 | /** Children map iterator. */
|
---|
145 | typedef QMapIterator<QString, ChildCacheData> UISettingsCacheChildIterator;
|
---|
146 |
|
---|
147 | /** Constructs empty object cache. */
|
---|
148 | UISettingsCachePool() : UISettingsCache<ParentCacheData>() {}
|
---|
149 |
|
---|
150 | /** Returns children count. */
|
---|
151 | int childCount() const { return m_children.size(); }
|
---|
152 | /** Returns the modifiable REFERENCE to the child cached data. */
|
---|
153 | ChildCacheData &child(const QString &strChildKey) { return m_children[strChildKey]; }
|
---|
154 | /** Wraps method above to return the modifiable REFERENCE to the child cached data. */
|
---|
155 | ChildCacheData &child(int iIndex) { return child(indexToKey(iIndex)); }
|
---|
156 | /** Returns the NON-modifiable COPY to the child cached data. */
|
---|
157 | const ChildCacheData child(const QString &strChildKey) const { return m_children[strChildKey]; }
|
---|
158 | /** Wraps method above to return the NON-modifiable COPY to the child cached data. */
|
---|
159 | const ChildCacheData child(int iIndex) const { return child(indexToKey(iIndex)); }
|
---|
160 |
|
---|
161 | /** Returns whether the cache was updated.
|
---|
162 | * We assume that cache object was updated if current and
|
---|
163 | * initial data were both set and not equal to each other.
|
---|
164 | * Takes into account all the children. */
|
---|
165 | bool wasUpdated() const
|
---|
166 | {
|
---|
167 | /* First of all, cache object is considered to be updated if parent data was updated: */
|
---|
168 | bool fWasUpdated = UISettingsCache<ParentCacheData>::wasUpdated();
|
---|
169 | /* If parent data was NOT updated but also was NOT created or removed too
|
---|
170 | * (e.j. was NOT changed at all), we have to check children too: */
|
---|
171 | if (!fWasUpdated && !UISettingsCache<ParentCacheData>::wasRemoved() && !UISettingsCache<ParentCacheData>::wasCreated())
|
---|
172 | {
|
---|
173 | for (int iChildIndex = 0; !fWasUpdated && iChildIndex < childCount(); ++iChildIndex)
|
---|
174 | if (child(iChildIndex).wasChanged())
|
---|
175 | fWasUpdated = true;
|
---|
176 | }
|
---|
177 | return fWasUpdated;
|
---|
178 | }
|
---|
179 |
|
---|
180 | /** Resets the initial and the current one data to be both empty.
|
---|
181 | * Removes all the children. */
|
---|
182 | void clear()
|
---|
183 | {
|
---|
184 | UISettingsCache<ParentCacheData>::clear();
|
---|
185 | m_children.clear();
|
---|
186 | }
|
---|
187 |
|
---|
188 | private:
|
---|
189 |
|
---|
190 | /** Returns QString representation of passed @a iIndex. */
|
---|
191 | QString indexToKey(int iIndex) const
|
---|
192 | {
|
---|
193 | UISettingsCacheChildIterator childIterator(m_children);
|
---|
194 | for (int iChildIndex = 0; childIterator.hasNext(); ++iChildIndex)
|
---|
195 | {
|
---|
196 | childIterator.next();
|
---|
197 | if (iChildIndex == iIndex)
|
---|
198 | return childIterator.key();
|
---|
199 | }
|
---|
200 | return QString("%1").arg(iIndex, 8 /* up to 8 digits */, 10 /* base */, QChar('0') /* filler */);
|
---|
201 | }
|
---|
202 |
|
---|
203 | /** Holds the children. */
|
---|
204 | UISettingsCacheChildMap m_children;
|
---|
205 | };
|
---|
206 |
|
---|
207 |
|
---|
208 | /** Template organizing settings object cache with 2 groups of children. */
|
---|
209 | template <class ParentCacheData, class ChildCacheData1, class ChildCacheData2> class UISettingsCachePoolOfTwo : public UISettingsCache<ParentCacheData>
|
---|
210 | {
|
---|
211 | public:
|
---|
212 |
|
---|
213 | /** Group 1 children map. */
|
---|
214 | typedef QMap<QString, ChildCacheData1> UISettingsCacheChildMap1;
|
---|
215 | /** Group 2 children map. */
|
---|
216 | typedef QMap<QString, ChildCacheData2> UISettingsCacheChildMap2;
|
---|
217 | /** Group 1 children map iterator. */
|
---|
218 | typedef QMapIterator<QString, ChildCacheData1> UISettingsCacheChildIterator1;
|
---|
219 | /** Group 2 children map iterator. */
|
---|
220 | typedef QMapIterator<QString, ChildCacheData2> UISettingsCacheChildIterator2;
|
---|
221 |
|
---|
222 | /** Constructs empty cache object. */
|
---|
223 | UISettingsCachePoolOfTwo() : UISettingsCache<ParentCacheData>() {}
|
---|
224 |
|
---|
225 | /** Returns group 1 children count. */
|
---|
226 | int childCount1() const { return m_children1.size(); }
|
---|
227 | /** Returns the modifiable REFERENCE to the group 1 child cached data. */
|
---|
228 | ChildCacheData1 &child1(const QString &strChildKey) { return m_children1[strChildKey]; }
|
---|
229 | /** Wraps method above to return the modifiable REFERENCE to the group 1 child cached data. */
|
---|
230 | ChildCacheData1 &child1(int iIndex) { return child1(indexToKey1(iIndex)); }
|
---|
231 | /** Returns the NON-modifiable COPY to the group 1 child cached data. */
|
---|
232 | const ChildCacheData1 child1(const QString &strChildKey) const { return m_children1[strChildKey]; }
|
---|
233 | /** Wraps method above to return the NON-modifiable COPY to the group 1 child cached data. */
|
---|
234 | const ChildCacheData1 child1(int iIndex) const { return child1(indexToKey1(iIndex)); }
|
---|
235 |
|
---|
236 | /** Returns group 2 children count. */
|
---|
237 | int childCount2() const { return m_children2.size(); }
|
---|
238 | /** Returns the modifiable REFERENCE to the group 2 child cached data. */
|
---|
239 | ChildCacheData2 &child2(const QString &strChildKey) { return m_children2[strChildKey]; }
|
---|
240 | /** Wraps method above to return the modifiable REFERENCE to the group 2 child cached data. */
|
---|
241 | ChildCacheData2 &child2(int iIndex) { return child2(indexToKey2(iIndex)); }
|
---|
242 | /** Returns the NON-modifiable COPY to the group 2 child cached data. */
|
---|
243 | const ChildCacheData2 child2(const QString &strChildKey) const { return m_children2[strChildKey]; }
|
---|
244 | /** Wraps method above to return the NON-modifiable COPY to the group 2 child cached data. */
|
---|
245 | const ChildCacheData2 child2(int iIndex) const { return child2(indexToKey2(iIndex)); }
|
---|
246 |
|
---|
247 | /** Returns whether the cache was updated.
|
---|
248 | * We assume that cache object was updated if current and
|
---|
249 | * initial data were both set and not equal to each other.
|
---|
250 | * Takes into account all the children of both groups. */
|
---|
251 | bool wasUpdated() const
|
---|
252 | {
|
---|
253 | /* First of all, cache object is considered to be updated if parent data was updated: */
|
---|
254 | bool fWasUpdated = UISettingsCache<ParentCacheData>::wasUpdated();
|
---|
255 | /* If parent data was NOT updated but also was NOT created or removed too
|
---|
256 | * (e.j. was NOT changed at all), we have to check children too: */
|
---|
257 | if (!fWasUpdated && !UISettingsCache<ParentCacheData>::wasRemoved() && !UISettingsCache<ParentCacheData>::wasCreated())
|
---|
258 | {
|
---|
259 | for (int iChildIndex = 0; !fWasUpdated && iChildIndex < childCount1(); ++iChildIndex)
|
---|
260 | if (child1(iChildIndex).wasChanged())
|
---|
261 | fWasUpdated = true;
|
---|
262 | for (int iChildIndex = 0; !fWasUpdated && iChildIndex < childCount2(); ++iChildIndex)
|
---|
263 | if (child2(iChildIndex).wasChanged())
|
---|
264 | fWasUpdated = true;
|
---|
265 | }
|
---|
266 | return fWasUpdated;
|
---|
267 | }
|
---|
268 |
|
---|
269 | /** Resets the initial and the current one data to be both empty.
|
---|
270 | * Removes all the children from both groups. */
|
---|
271 | void clear()
|
---|
272 | {
|
---|
273 | UISettingsCache<ParentCacheData>::clear();
|
---|
274 | m_children1.clear();
|
---|
275 | m_children2.clear();
|
---|
276 | }
|
---|
277 |
|
---|
278 | private:
|
---|
279 |
|
---|
280 | /** Returns QString representation of passed @a iIndex inside group 1. */
|
---|
281 | QString indexToKey1(int iIndex) const
|
---|
282 | {
|
---|
283 | UISettingsCacheChildIterator1 childIterator(m_children1);
|
---|
284 | for (int iChildIndex = 0; childIterator.hasNext(); ++iChildIndex)
|
---|
285 | {
|
---|
286 | childIterator.next();
|
---|
287 | if (iChildIndex == iIndex)
|
---|
288 | return childIterator.key();
|
---|
289 | }
|
---|
290 | return QString("%1").arg(iIndex, 8 /* up to 8 digits */, 10 /* base */, QChar('0') /* filler */);
|
---|
291 | }
|
---|
292 |
|
---|
293 | /** Returns QString representation of passed @a iIndex inside group 2. */
|
---|
294 | QString indexToKey2(int iIndex) const
|
---|
295 | {
|
---|
296 | UISettingsCacheChildIterator2 childIterator(m_children2);
|
---|
297 | for (int iChildIndex = 0; childIterator.hasNext(); ++iChildIndex)
|
---|
298 | {
|
---|
299 | childIterator.next();
|
---|
300 | if (iChildIndex == iIndex)
|
---|
301 | return childIterator.key();
|
---|
302 | }
|
---|
303 | return QString("%1").arg(iIndex, 8 /* up to 8 digits */, 10 /* base */, QChar('0') /* filler */);
|
---|
304 | }
|
---|
305 |
|
---|
306 | /** Holds the children of group 1. */
|
---|
307 | UISettingsCacheChildMap1 m_children1;
|
---|
308 | /** Holds the children of group 2. */
|
---|
309 | UISettingsCacheChildMap2 m_children2;
|
---|
310 | };
|
---|
311 |
|
---|
312 |
|
---|
313 | #endif /* !FEQT_INCLUDED_SRC_settings_UISettingsDefs_h */
|
---|