1 | /* $Id: UIGlobalSettingsGeneral.cpp 101511 2023-10-19 14:38:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIGlobalSettingsGeneral class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 | /* Qt includes: */
|
---|
29 | #include <QVBoxLayout>
|
---|
30 |
|
---|
31 | /* GUI includes: */
|
---|
32 | #include "UICommon.h"
|
---|
33 | #include "UIDefaultMachineFolderEditor.h"
|
---|
34 | #include "UIErrorString.h"
|
---|
35 | #include "UIGlobalSettingsGeneral.h"
|
---|
36 | #include "UIVRDEAuthLibraryEditor.h"
|
---|
37 |
|
---|
38 |
|
---|
39 | /** Global settings: General page data structure. */
|
---|
40 | struct UIDataSettingsGlobalGeneral
|
---|
41 | {
|
---|
42 | /** Constructs data. */
|
---|
43 | UIDataSettingsGlobalGeneral()
|
---|
44 | : m_strDefaultMachineFolder(QString())
|
---|
45 | , m_strVRDEAuthLibrary(QString())
|
---|
46 | {}
|
---|
47 |
|
---|
48 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
49 | bool equal(const UIDataSettingsGlobalGeneral &other) const
|
---|
50 | {
|
---|
51 | return true
|
---|
52 | && (m_strDefaultMachineFolder == other.m_strDefaultMachineFolder)
|
---|
53 | && (m_strVRDEAuthLibrary == other.m_strVRDEAuthLibrary)
|
---|
54 | ;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
58 | bool operator==(const UIDataSettingsGlobalGeneral &other) const { return equal(other); }
|
---|
59 | /** Returns whether the @a other passed data is different from this one. */
|
---|
60 | bool operator!=(const UIDataSettingsGlobalGeneral &other) const { return !equal(other); }
|
---|
61 |
|
---|
62 | /** Holds the 'default machine folder' path. */
|
---|
63 | QString m_strDefaultMachineFolder;
|
---|
64 | /** Holds the 'VRDE auth library' name. */
|
---|
65 | QString m_strVRDEAuthLibrary;
|
---|
66 | };
|
---|
67 |
|
---|
68 |
|
---|
69 | /*********************************************************************************************************************************
|
---|
70 | * Class UIGlobalSettingsGeneral implementation. *
|
---|
71 | *********************************************************************************************************************************/
|
---|
72 |
|
---|
73 | UIGlobalSettingsGeneral::UIGlobalSettingsGeneral()
|
---|
74 | : m_pCache(0)
|
---|
75 | , m_pEditorDefaultMachineFolder(0)
|
---|
76 | , m_pEditorVRDEAuthLibrary(0)
|
---|
77 | {
|
---|
78 | prepare();
|
---|
79 | }
|
---|
80 |
|
---|
81 | UIGlobalSettingsGeneral::~UIGlobalSettingsGeneral()
|
---|
82 | {
|
---|
83 | cleanup();
|
---|
84 | }
|
---|
85 |
|
---|
86 | bool UIGlobalSettingsGeneral::changed() const
|
---|
87 | {
|
---|
88 | return m_pCache ? m_pCache->wasChanged() : false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void UIGlobalSettingsGeneral::loadToCacheFrom(QVariant &data)
|
---|
92 | {
|
---|
93 | /* Sanity check: */
|
---|
94 | if (!m_pCache)
|
---|
95 | return;
|
---|
96 |
|
---|
97 | /* Fetch data to properties: */
|
---|
98 | UISettingsPageGlobal::fetchData(data);
|
---|
99 |
|
---|
100 | /* Clear cache initially: */
|
---|
101 | m_pCache->clear();
|
---|
102 |
|
---|
103 | /* Cache old data: */
|
---|
104 | UIDataSettingsGlobalGeneral oldData;
|
---|
105 | oldData.m_strDefaultMachineFolder = m_properties.GetDefaultMachineFolder();
|
---|
106 | oldData.m_strVRDEAuthLibrary = m_properties.GetVRDEAuthLibrary();
|
---|
107 | m_pCache->cacheInitialData(oldData);
|
---|
108 |
|
---|
109 | /* Upload properties to data: */
|
---|
110 | UISettingsPageGlobal::uploadData(data);
|
---|
111 | }
|
---|
112 |
|
---|
113 | void UIGlobalSettingsGeneral::getFromCache()
|
---|
114 | {
|
---|
115 | /* Sanity check: */
|
---|
116 | if (!m_pCache)
|
---|
117 | return;
|
---|
118 |
|
---|
119 | /* Load old data from cache: */
|
---|
120 | const UIDataSettingsGlobalGeneral &oldData = m_pCache->base();
|
---|
121 | if (m_pEditorDefaultMachineFolder)
|
---|
122 | m_pEditorDefaultMachineFolder->setValue(oldData.m_strDefaultMachineFolder);
|
---|
123 | if (m_pEditorVRDEAuthLibrary)
|
---|
124 | m_pEditorVRDEAuthLibrary->setValue(oldData.m_strVRDEAuthLibrary);
|
---|
125 | }
|
---|
126 |
|
---|
127 | void UIGlobalSettingsGeneral::putToCache()
|
---|
128 | {
|
---|
129 | /* Sanity check: */
|
---|
130 | if (!m_pCache)
|
---|
131 | return;
|
---|
132 |
|
---|
133 | /* Prepare new data: */
|
---|
134 | UIDataSettingsGlobalGeneral newData = m_pCache->base();
|
---|
135 |
|
---|
136 | /* Cache new data: */
|
---|
137 | if (m_pEditorDefaultMachineFolder)
|
---|
138 | newData.m_strDefaultMachineFolder = m_pEditorDefaultMachineFolder->value();
|
---|
139 | if (m_pEditorVRDEAuthLibrary)
|
---|
140 | newData.m_strVRDEAuthLibrary = m_pEditorVRDEAuthLibrary->value();
|
---|
141 | m_pCache->cacheCurrentData(newData);
|
---|
142 | }
|
---|
143 |
|
---|
144 | void UIGlobalSettingsGeneral::saveFromCacheTo(QVariant &data)
|
---|
145 | {
|
---|
146 | /* Fetch data to properties: */
|
---|
147 | UISettingsPageGlobal::fetchData(data);
|
---|
148 |
|
---|
149 | /* Update data and failing state: */
|
---|
150 | setFailed(!saveData());
|
---|
151 |
|
---|
152 | /* Upload properties to data: */
|
---|
153 | UISettingsPageGlobal::uploadData(data);
|
---|
154 | }
|
---|
155 |
|
---|
156 | void UIGlobalSettingsGeneral::filterOut(bool fExpertMode, const QString &strFilter)
|
---|
157 | {
|
---|
158 | /* Call to base-class: */
|
---|
159 | UIEditor::filterOut(fExpertMode, strFilter);
|
---|
160 |
|
---|
161 | updateMinimumLayoutHint();
|
---|
162 | }
|
---|
163 |
|
---|
164 | void UIGlobalSettingsGeneral::retranslateUi()
|
---|
165 | {
|
---|
166 | updateMinimumLayoutHint();
|
---|
167 | }
|
---|
168 |
|
---|
169 | void UIGlobalSettingsGeneral::prepare()
|
---|
170 | {
|
---|
171 | /* Prepare cache: */
|
---|
172 | m_pCache = new UISettingsCacheGlobalGeneral;
|
---|
173 | AssertPtrReturnVoid(m_pCache);
|
---|
174 |
|
---|
175 | /* Prepare everything: */
|
---|
176 | prepareWidgets();
|
---|
177 |
|
---|
178 | /* Apply language settings: */
|
---|
179 | retranslateUi();
|
---|
180 | }
|
---|
181 |
|
---|
182 | void UIGlobalSettingsGeneral::prepareWidgets()
|
---|
183 | {
|
---|
184 | /* Prepare main layout: */
|
---|
185 | QVBoxLayout *pLayout = new QVBoxLayout(this);
|
---|
186 | if (pLayout)
|
---|
187 | {
|
---|
188 | /* Prepare 'default machine folder' editor: */
|
---|
189 | m_pEditorDefaultMachineFolder = new UIDefaultMachineFolderEditor(this);
|
---|
190 | if (m_pEditorDefaultMachineFolder)
|
---|
191 | {
|
---|
192 | addEditor(m_pEditorDefaultMachineFolder);
|
---|
193 | pLayout->addWidget(m_pEditorDefaultMachineFolder);
|
---|
194 | }
|
---|
195 |
|
---|
196 | /* Prepare 'VRDE auth library' editor: */
|
---|
197 | m_pEditorVRDEAuthLibrary = new UIVRDEAuthLibraryEditor(this);
|
---|
198 | if (m_pEditorVRDEAuthLibrary)
|
---|
199 | {
|
---|
200 | addEditor(m_pEditorVRDEAuthLibrary);
|
---|
201 | pLayout->addWidget(m_pEditorVRDEAuthLibrary);
|
---|
202 | }
|
---|
203 |
|
---|
204 | /* Add stretch to the end: */
|
---|
205 | pLayout->addStretch();
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | void UIGlobalSettingsGeneral::cleanup()
|
---|
210 | {
|
---|
211 | /* Cleanup cache: */
|
---|
212 | delete m_pCache;
|
---|
213 | m_pCache = 0;
|
---|
214 | }
|
---|
215 |
|
---|
216 | bool UIGlobalSettingsGeneral::saveData()
|
---|
217 | {
|
---|
218 | /* Sanity check: */
|
---|
219 | if (!m_pCache)
|
---|
220 | return false;
|
---|
221 |
|
---|
222 | /* Prepare result: */
|
---|
223 | bool fSuccess = true;
|
---|
224 | /* Save settings from cache: */
|
---|
225 | if ( fSuccess
|
---|
226 | && m_pCache->wasChanged())
|
---|
227 | {
|
---|
228 | /* Get old data from cache: */
|
---|
229 | const UIDataSettingsGlobalGeneral &oldData = m_pCache->base();
|
---|
230 | /* Get new data from cache: */
|
---|
231 | const UIDataSettingsGlobalGeneral &newData = m_pCache->data();
|
---|
232 |
|
---|
233 | /* Save 'default machine folder': */
|
---|
234 | if ( fSuccess
|
---|
235 | && newData.m_strDefaultMachineFolder != oldData.m_strDefaultMachineFolder)
|
---|
236 | {
|
---|
237 | m_properties.SetDefaultMachineFolder(newData.m_strDefaultMachineFolder);
|
---|
238 | fSuccess = m_properties.isOk();
|
---|
239 | }
|
---|
240 | /* Save 'VRDE auth library': */
|
---|
241 | if ( fSuccess
|
---|
242 | && newData.m_strVRDEAuthLibrary != oldData.m_strVRDEAuthLibrary)
|
---|
243 | {
|
---|
244 | m_properties.SetVRDEAuthLibrary(newData.m_strVRDEAuthLibrary);
|
---|
245 | fSuccess = m_properties.isOk();
|
---|
246 | }
|
---|
247 |
|
---|
248 | /* Show error message if necessary: */
|
---|
249 | if (!fSuccess)
|
---|
250 | notifyOperationProgressError(UIErrorString::formatErrorInfo(m_properties));
|
---|
251 | }
|
---|
252 | /* Return result: */
|
---|
253 | return fSuccess;
|
---|
254 | }
|
---|
255 |
|
---|
256 | void UIGlobalSettingsGeneral::updateMinimumLayoutHint()
|
---|
257 | {
|
---|
258 | /* These editors have own labels, but we want them to be properly layouted according to each other: */
|
---|
259 | int iMinimumLayoutHint = 0;
|
---|
260 | if (m_pEditorDefaultMachineFolder && !m_pEditorDefaultMachineFolder->isHidden())
|
---|
261 | iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pEditorDefaultMachineFolder->minimumLabelHorizontalHint());
|
---|
262 | if (m_pEditorVRDEAuthLibrary && !m_pEditorVRDEAuthLibrary->isHidden())
|
---|
263 | iMinimumLayoutHint = qMax(iMinimumLayoutHint, m_pEditorVRDEAuthLibrary->minimumLabelHorizontalHint());
|
---|
264 | if (m_pEditorDefaultMachineFolder)
|
---|
265 | m_pEditorDefaultMachineFolder->setMinimumLayoutIndent(iMinimumLayoutHint);
|
---|
266 | if (m_pEditorVRDEAuthLibrary)
|
---|
267 | m_pEditorVRDEAuthLibrary->setMinimumLayoutIndent(iMinimumLayoutHint);
|
---|
268 | }
|
---|