1 | /* $Id: UIGlobalSettingsGeneral.cpp 86020 2020-09-03 13:10:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIGlobalSettingsGeneral class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QCheckBox>
|
---|
20 | #include <QDir>
|
---|
21 | #include <QGridLayout>
|
---|
22 | #include <QLabel>
|
---|
23 |
|
---|
24 | /* GUI includes: */
|
---|
25 | #include "UICommon.h"
|
---|
26 | #include "UIErrorString.h"
|
---|
27 | #include "UIExtraDataManager.h"
|
---|
28 | #include "UIFilePathSelector.h"
|
---|
29 | #include "UIGlobalSettingsGeneral.h"
|
---|
30 |
|
---|
31 |
|
---|
32 | /** Global settings: General page data structure. */
|
---|
33 | struct UIDataSettingsGlobalGeneral
|
---|
34 | {
|
---|
35 | /** Constructs data. */
|
---|
36 | UIDataSettingsGlobalGeneral()
|
---|
37 | : m_strDefaultMachineFolder(QString())
|
---|
38 | , m_strVRDEAuthLibrary(QString())
|
---|
39 | , m_fHostScreenSaverDisabled(false)
|
---|
40 | {}
|
---|
41 |
|
---|
42 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
43 | bool equal(const UIDataSettingsGlobalGeneral &other) const
|
---|
44 | {
|
---|
45 | return true
|
---|
46 | && (m_strDefaultMachineFolder == other.m_strDefaultMachineFolder)
|
---|
47 | && (m_strVRDEAuthLibrary == other.m_strVRDEAuthLibrary)
|
---|
48 | && (m_fHostScreenSaverDisabled == other.m_fHostScreenSaverDisabled)
|
---|
49 | ;
|
---|
50 | }
|
---|
51 |
|
---|
52 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
53 | bool operator==(const UIDataSettingsGlobalGeneral &other) const { return equal(other); }
|
---|
54 | /** Returns whether the @a other passed data is different from this one. */
|
---|
55 | bool operator!=(const UIDataSettingsGlobalGeneral &other) const { return !equal(other); }
|
---|
56 |
|
---|
57 | /** Holds the default machine folder path. */
|
---|
58 | QString m_strDefaultMachineFolder;
|
---|
59 | /** Holds the VRDE authentication library name. */
|
---|
60 | QString m_strVRDEAuthLibrary;
|
---|
61 | /** Holds whether host screen-saver should be disabled. */
|
---|
62 | bool m_fHostScreenSaverDisabled;
|
---|
63 | };
|
---|
64 |
|
---|
65 |
|
---|
66 | UIGlobalSettingsGeneral::UIGlobalSettingsGeneral()
|
---|
67 | : m_pCache(0)
|
---|
68 | , m_pLabelMachineFolder(0)
|
---|
69 | , m_pSelectorMachineFolder(0)
|
---|
70 | , m_pLabelVRDPLibraryName(0)
|
---|
71 | , m_pSelectorVRDPLibraryName(0)
|
---|
72 | , m_pLabelHostScreenSaver(0)
|
---|
73 | , m_pCheckBoxHostScreenSaver(0)
|
---|
74 | {
|
---|
75 | /* Prepare: */
|
---|
76 | prepare();
|
---|
77 | }
|
---|
78 |
|
---|
79 | UIGlobalSettingsGeneral::~UIGlobalSettingsGeneral()
|
---|
80 | {
|
---|
81 | /* Cleanup: */
|
---|
82 | cleanup();
|
---|
83 | }
|
---|
84 |
|
---|
85 | void UIGlobalSettingsGeneral::loadToCacheFrom(QVariant &data)
|
---|
86 | {
|
---|
87 | /* Fetch data to properties: */
|
---|
88 | UISettingsPageGlobal::fetchData(data);
|
---|
89 |
|
---|
90 | /* Clear cache initially: */
|
---|
91 | m_pCache->clear();
|
---|
92 |
|
---|
93 | /* Prepare old general data: */
|
---|
94 | UIDataSettingsGlobalGeneral oldGeneralData;
|
---|
95 |
|
---|
96 | /* Gather old general data: */
|
---|
97 | oldGeneralData.m_strDefaultMachineFolder = m_properties.GetDefaultMachineFolder();
|
---|
98 | oldGeneralData.m_strVRDEAuthLibrary = m_properties.GetVRDEAuthLibrary();
|
---|
99 | oldGeneralData.m_fHostScreenSaverDisabled = gEDataManager->hostScreenSaverDisabled();
|
---|
100 |
|
---|
101 | /* Cache old general data: */
|
---|
102 | m_pCache->cacheInitialData(oldGeneralData);
|
---|
103 |
|
---|
104 | /* Upload properties to data: */
|
---|
105 | UISettingsPageGlobal::uploadData(data);
|
---|
106 | }
|
---|
107 |
|
---|
108 | void UIGlobalSettingsGeneral::getFromCache()
|
---|
109 | {
|
---|
110 | /* Get old general data from the cache: */
|
---|
111 | const UIDataSettingsGlobalGeneral &oldGeneralData = m_pCache->base();
|
---|
112 |
|
---|
113 | /* Load old general data from the cache: */
|
---|
114 | m_pSelectorMachineFolder->setPath(oldGeneralData.m_strDefaultMachineFolder);
|
---|
115 | m_pSelectorVRDPLibraryName->setPath(oldGeneralData.m_strVRDEAuthLibrary);
|
---|
116 | m_pCheckBoxHostScreenSaver->setChecked(oldGeneralData.m_fHostScreenSaverDisabled);
|
---|
117 | }
|
---|
118 |
|
---|
119 | void UIGlobalSettingsGeneral::putToCache()
|
---|
120 | {
|
---|
121 | /* Prepare new general data: */
|
---|
122 | UIDataSettingsGlobalGeneral newGeneralData = m_pCache->base();
|
---|
123 |
|
---|
124 | /* Gather new general data: */
|
---|
125 | newGeneralData.m_strDefaultMachineFolder = m_pSelectorMachineFolder->path();
|
---|
126 | newGeneralData.m_strVRDEAuthLibrary = m_pSelectorVRDPLibraryName->path();
|
---|
127 | newGeneralData.m_fHostScreenSaverDisabled = m_pCheckBoxHostScreenSaver->isChecked();
|
---|
128 |
|
---|
129 | /* Cache new general data: */
|
---|
130 | m_pCache->cacheCurrentData(newGeneralData);
|
---|
131 | }
|
---|
132 |
|
---|
133 | void UIGlobalSettingsGeneral::saveFromCacheTo(QVariant &data)
|
---|
134 | {
|
---|
135 | /* Fetch data to properties: */
|
---|
136 | UISettingsPageGlobal::fetchData(data);
|
---|
137 |
|
---|
138 | /* Update general data and failing state: */
|
---|
139 | setFailed(!saveGeneralData());
|
---|
140 |
|
---|
141 | /* Upload properties to data: */
|
---|
142 | UISettingsPageGlobal::uploadData(data);
|
---|
143 | }
|
---|
144 |
|
---|
145 | void UIGlobalSettingsGeneral::retranslateUi()
|
---|
146 | {
|
---|
147 | m_pLabelMachineFolder->setText(tr("Default &Machine Folder:"));
|
---|
148 | m_pSelectorMachineFolder->setWhatsThis(tr("Holds the path to the default virtual machine folder. This folder is used, "
|
---|
149 | "if not explicitly specified otherwise, when creating new virtual machines."));
|
---|
150 | m_pLabelVRDPLibraryName->setText(tr("V&RDP Authentication Library:"));
|
---|
151 | m_pSelectorVRDPLibraryName->setWhatsThis(tr("Holds the path to the library that provides authentication for Remote Display (VRDP) clients."));
|
---|
152 | m_pLabelHostScreenSaver->setText(tr("Host Screensaver:"));
|
---|
153 | m_pCheckBoxHostScreenSaver->setWhatsThis(tr("When checked, the host screensaver will be disabled whenever a virtual machine is running."));
|
---|
154 | m_pCheckBoxHostScreenSaver->setText(tr("&Disable When Running Virtual Machines"));
|
---|
155 | }
|
---|
156 |
|
---|
157 | void UIGlobalSettingsGeneral::prepare()
|
---|
158 | {
|
---|
159 | /* Prepare cache: */
|
---|
160 | m_pCache = new UISettingsCacheGlobalGeneral;
|
---|
161 | AssertPtrReturnVoid(m_pCache);
|
---|
162 |
|
---|
163 | /* Prepare everything: */
|
---|
164 | prepareWidgets();
|
---|
165 |
|
---|
166 | /* Apply language settings: */
|
---|
167 | retranslateUi();
|
---|
168 | }
|
---|
169 |
|
---|
170 | void UIGlobalSettingsGeneral::prepareWidgets()
|
---|
171 | {
|
---|
172 | /* Prepare main layout: */
|
---|
173 | QGridLayout *pLayoutMain = new QGridLayout(this);
|
---|
174 | if (pLayoutMain)
|
---|
175 | {
|
---|
176 | pLayoutMain->setColumnStretch(1, 1);
|
---|
177 | pLayoutMain->setRowStretch(3, 1);
|
---|
178 |
|
---|
179 | /* Prepare machine folder label: */
|
---|
180 | m_pLabelMachineFolder = new QLabel(this);
|
---|
181 | if (m_pLabelMachineFolder)
|
---|
182 | {
|
---|
183 | m_pLabelMachineFolder->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
---|
184 | pLayoutMain->addWidget(m_pLabelMachineFolder, 0, 0);
|
---|
185 | }
|
---|
186 | /* Prepare machine folder selector: */
|
---|
187 | m_pSelectorMachineFolder = new UIFilePathSelector(this);
|
---|
188 | if (m_pSelectorMachineFolder)
|
---|
189 | {
|
---|
190 | if (m_pLabelMachineFolder)
|
---|
191 | m_pLabelMachineFolder->setBuddy(m_pSelectorMachineFolder);
|
---|
192 | m_pSelectorMachineFolder->setHomeDir(uiCommon().homeFolder());
|
---|
193 |
|
---|
194 | pLayoutMain->addWidget(m_pSelectorMachineFolder, 0, 1, 1, 2);
|
---|
195 | }
|
---|
196 |
|
---|
197 | /* Prepare VRDP library name label: */
|
---|
198 | m_pLabelVRDPLibraryName = new QLabel(this);
|
---|
199 | if (m_pLabelVRDPLibraryName)
|
---|
200 | {
|
---|
201 | m_pLabelVRDPLibraryName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
---|
202 | pLayoutMain->addWidget(m_pLabelVRDPLibraryName, 1, 0);
|
---|
203 | }
|
---|
204 | /* Prepare VRDP library name selector: */
|
---|
205 | m_pSelectorVRDPLibraryName = new UIFilePathSelector(this);
|
---|
206 | if (m_pSelectorVRDPLibraryName)
|
---|
207 | {
|
---|
208 | if (m_pLabelVRDPLibraryName)
|
---|
209 | m_pLabelVRDPLibraryName->setBuddy(m_pSelectorVRDPLibraryName);
|
---|
210 | m_pSelectorVRDPLibraryName->setHomeDir(uiCommon().homeFolder());
|
---|
211 | m_pSelectorVRDPLibraryName->setMode(UIFilePathSelector::Mode_File_Open);
|
---|
212 |
|
---|
213 | pLayoutMain->addWidget(m_pSelectorVRDPLibraryName, 1, 1, 1, 2);
|
---|
214 | }
|
---|
215 |
|
---|
216 | /* Prepare screen-saver label: */
|
---|
217 | m_pLabelHostScreenSaver = new QLabel(this);
|
---|
218 | if (m_pLabelHostScreenSaver)
|
---|
219 | {
|
---|
220 | m_pLabelHostScreenSaver->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
---|
221 | m_pLabelHostScreenSaver->hide();
|
---|
222 | pLayoutMain->addWidget(m_pLabelHostScreenSaver, 2, 0);
|
---|
223 | }
|
---|
224 | /* Prepare screen-saver check-box: */
|
---|
225 | m_pCheckBoxHostScreenSaver = new QCheckBox(this);
|
---|
226 | if (m_pCheckBoxHostScreenSaver)
|
---|
227 | {
|
---|
228 | if (m_pLabelHostScreenSaver)
|
---|
229 | m_pLabelHostScreenSaver->setBuddy(m_pCheckBoxHostScreenSaver);
|
---|
230 | m_pCheckBoxHostScreenSaver->hide();
|
---|
231 | pLayoutMain->addWidget(m_pCheckBoxHostScreenSaver, 2, 1);
|
---|
232 | }
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | void UIGlobalSettingsGeneral::cleanup()
|
---|
237 | {
|
---|
238 | /* Cleanup cache: */
|
---|
239 | delete m_pCache;
|
---|
240 | m_pCache = 0;
|
---|
241 | }
|
---|
242 |
|
---|
243 | bool UIGlobalSettingsGeneral::saveGeneralData()
|
---|
244 | {
|
---|
245 | /* Prepare result: */
|
---|
246 | bool fSuccess = true;
|
---|
247 | /* Save general settings from the cache: */
|
---|
248 | if (fSuccess && m_pCache->wasChanged())
|
---|
249 | {
|
---|
250 | /* Get old general data from the cache: */
|
---|
251 | const UIDataSettingsGlobalGeneral &oldGeneralData = m_pCache->base();
|
---|
252 | /* Get new general data from the cache: */
|
---|
253 | const UIDataSettingsGlobalGeneral &newGeneralData = m_pCache->data();
|
---|
254 |
|
---|
255 | /* Save default machine folder: */
|
---|
256 | if ( fSuccess
|
---|
257 | && newGeneralData.m_strDefaultMachineFolder != oldGeneralData.m_strDefaultMachineFolder)
|
---|
258 | {
|
---|
259 | m_properties.SetDefaultMachineFolder(newGeneralData.m_strDefaultMachineFolder);
|
---|
260 | fSuccess = m_properties.isOk();
|
---|
261 | }
|
---|
262 | /* Save VRDE auth library: */
|
---|
263 | if ( fSuccess
|
---|
264 | && newGeneralData.m_strVRDEAuthLibrary != oldGeneralData.m_strVRDEAuthLibrary)
|
---|
265 | {
|
---|
266 | m_properties.SetVRDEAuthLibrary(newGeneralData.m_strVRDEAuthLibrary);
|
---|
267 | fSuccess = m_properties.isOk();
|
---|
268 | }
|
---|
269 |
|
---|
270 | /* Show error message if necessary: */
|
---|
271 | if (!fSuccess)
|
---|
272 | notifyOperationProgressError(UIErrorString::formatErrorInfo(m_properties));
|
---|
273 |
|
---|
274 | /* Save new general data from the cache: */
|
---|
275 | if (newGeneralData.m_fHostScreenSaverDisabled != oldGeneralData.m_fHostScreenSaverDisabled)
|
---|
276 | gEDataManager->setHostScreenSaverDisabled(newGeneralData.m_fHostScreenSaverDisabled);
|
---|
277 | }
|
---|
278 | /* Return result: */
|
---|
279 | return fSuccess;
|
---|
280 | }
|
---|