1 | /* $Id: UIGlobalSettingsGeneral.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIGlobalSettingsGeneral class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 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 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # include <QDir>
|
---|
24 |
|
---|
25 | /* GUI includes: */
|
---|
26 | # include "UIGlobalSettingsGeneral.h"
|
---|
27 | # include "UIExtraDataManager.h"
|
---|
28 | # include "UIErrorString.h"
|
---|
29 | # include "VBoxGlobal.h"
|
---|
30 |
|
---|
31 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
32 |
|
---|
33 |
|
---|
34 | /** Global settings: General page data structure. */
|
---|
35 | struct UIDataSettingsGlobalGeneral
|
---|
36 | {
|
---|
37 | /** Constructs data. */
|
---|
38 | UIDataSettingsGlobalGeneral()
|
---|
39 | : m_strDefaultMachineFolder(QString())
|
---|
40 | , m_strVRDEAuthLibrary(QString())
|
---|
41 | , m_fHostScreenSaverDisabled(false)
|
---|
42 | {}
|
---|
43 |
|
---|
44 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
45 | bool equal(const UIDataSettingsGlobalGeneral &other) const
|
---|
46 | {
|
---|
47 | return true
|
---|
48 | && (m_strDefaultMachineFolder == other.m_strDefaultMachineFolder)
|
---|
49 | && (m_strVRDEAuthLibrary == other.m_strVRDEAuthLibrary)
|
---|
50 | && (m_fHostScreenSaverDisabled == other.m_fHostScreenSaverDisabled)
|
---|
51 | ;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
55 | bool operator==(const UIDataSettingsGlobalGeneral &other) const { return equal(other); }
|
---|
56 | /** Returns whether the @a other passed data is different from this one. */
|
---|
57 | bool operator!=(const UIDataSettingsGlobalGeneral &other) const { return !equal(other); }
|
---|
58 |
|
---|
59 | /** Holds the default machine folder path. */
|
---|
60 | QString m_strDefaultMachineFolder;
|
---|
61 | /** Holds the VRDE authentication library name. */
|
---|
62 | QString m_strVRDEAuthLibrary;
|
---|
63 | /** Holds whether host screen-saver should be disabled. */
|
---|
64 | bool m_fHostScreenSaverDisabled;
|
---|
65 | };
|
---|
66 |
|
---|
67 |
|
---|
68 | UIGlobalSettingsGeneral::UIGlobalSettingsGeneral()
|
---|
69 | : m_pCache(0)
|
---|
70 | {
|
---|
71 | /* Prepare: */
|
---|
72 | prepare();
|
---|
73 | }
|
---|
74 |
|
---|
75 | UIGlobalSettingsGeneral::~UIGlobalSettingsGeneral()
|
---|
76 | {
|
---|
77 | /* Cleanup: */
|
---|
78 | cleanup();
|
---|
79 | }
|
---|
80 |
|
---|
81 | void UIGlobalSettingsGeneral::loadToCacheFrom(QVariant &data)
|
---|
82 | {
|
---|
83 | /* Fetch data to properties: */
|
---|
84 | UISettingsPageGlobal::fetchData(data);
|
---|
85 |
|
---|
86 | /* Clear cache initially: */
|
---|
87 | m_pCache->clear();
|
---|
88 |
|
---|
89 | /* Prepare old general data: */
|
---|
90 | UIDataSettingsGlobalGeneral oldGeneralData;
|
---|
91 |
|
---|
92 | /* Gather old general data: */
|
---|
93 | oldGeneralData.m_strDefaultMachineFolder = m_properties.GetDefaultMachineFolder();
|
---|
94 | oldGeneralData.m_strVRDEAuthLibrary = m_properties.GetVRDEAuthLibrary();
|
---|
95 | oldGeneralData.m_fHostScreenSaverDisabled = gEDataManager->hostScreenSaverDisabled();
|
---|
96 |
|
---|
97 | /* Cache old general data: */
|
---|
98 | m_pCache->cacheInitialData(oldGeneralData);
|
---|
99 |
|
---|
100 | /* Upload properties to data: */
|
---|
101 | UISettingsPageGlobal::uploadData(data);
|
---|
102 | }
|
---|
103 |
|
---|
104 | void UIGlobalSettingsGeneral::getFromCache()
|
---|
105 | {
|
---|
106 | /* Get old general data from the cache: */
|
---|
107 | const UIDataSettingsGlobalGeneral &oldGeneralData = m_pCache->base();
|
---|
108 |
|
---|
109 | /* Load old general data from the cache: */
|
---|
110 | m_pSelectorMachineFolder->setPath(oldGeneralData.m_strDefaultMachineFolder);
|
---|
111 | m_pSelectorVRDPLibName->setPath(oldGeneralData.m_strVRDEAuthLibrary);
|
---|
112 | m_pCheckBoxHostScreenSaver->setChecked(oldGeneralData.m_fHostScreenSaverDisabled);
|
---|
113 | }
|
---|
114 |
|
---|
115 | void UIGlobalSettingsGeneral::putToCache()
|
---|
116 | {
|
---|
117 | /* Prepare new general data: */
|
---|
118 | UIDataSettingsGlobalGeneral newGeneralData = m_pCache->base();
|
---|
119 |
|
---|
120 | /* Gather new general data: */
|
---|
121 | newGeneralData.m_strDefaultMachineFolder = m_pSelectorMachineFolder->path();
|
---|
122 | newGeneralData.m_strVRDEAuthLibrary = m_pSelectorVRDPLibName->path();
|
---|
123 | newGeneralData.m_fHostScreenSaverDisabled = m_pCheckBoxHostScreenSaver->isChecked();
|
---|
124 |
|
---|
125 | /* Cache new general data: */
|
---|
126 | m_pCache->cacheCurrentData(newGeneralData);
|
---|
127 | }
|
---|
128 |
|
---|
129 | void UIGlobalSettingsGeneral::saveFromCacheTo(QVariant &data)
|
---|
130 | {
|
---|
131 | /* Fetch data to properties: */
|
---|
132 | UISettingsPageGlobal::fetchData(data);
|
---|
133 |
|
---|
134 | /* Update general data and failing state: */
|
---|
135 | setFailed(!saveGeneralData());
|
---|
136 |
|
---|
137 | /* Upload properties to data: */
|
---|
138 | UISettingsPageGlobal::uploadData(data);
|
---|
139 | }
|
---|
140 |
|
---|
141 | void UIGlobalSettingsGeneral::retranslateUi()
|
---|
142 | {
|
---|
143 | /* Translate uic generated strings: */
|
---|
144 | Ui::UIGlobalSettingsGeneral::retranslateUi(this);
|
---|
145 | }
|
---|
146 |
|
---|
147 | void UIGlobalSettingsGeneral::prepare()
|
---|
148 | {
|
---|
149 | /* Apply UI decorations: */
|
---|
150 | Ui::UIGlobalSettingsGeneral::setupUi(this);
|
---|
151 |
|
---|
152 | /* Prepare cache: */
|
---|
153 | m_pCache = new UISettingsCacheGlobalGeneral;
|
---|
154 | AssertPtrReturnVoid(m_pCache);
|
---|
155 |
|
---|
156 | /* Layout/widgets created in the .ui file. */
|
---|
157 | AssertPtrReturnVoid(m_pLabelHostScreenSaver);
|
---|
158 | AssertPtrReturnVoid(m_pCheckBoxHostScreenSaver);
|
---|
159 | AssertPtrReturnVoid(m_pSelectorMachineFolder);
|
---|
160 | AssertPtrReturnVoid(m_pSelectorVRDPLibName);
|
---|
161 | {
|
---|
162 | /* Configure host screen-saver check-box: */
|
---|
163 | // Hide checkbox for now.
|
---|
164 | m_pLabelHostScreenSaver->hide();
|
---|
165 | m_pCheckBoxHostScreenSaver->hide();
|
---|
166 |
|
---|
167 | /* Configure other widgets: */
|
---|
168 | m_pSelectorMachineFolder->setHomeDir(vboxGlobal().homeFolder());
|
---|
169 | m_pSelectorVRDPLibName->setHomeDir(vboxGlobal().homeFolder());
|
---|
170 | m_pSelectorVRDPLibName->setMode(UIFilePathSelector::Mode_File_Open);
|
---|
171 | }
|
---|
172 |
|
---|
173 | /* Apply language settings: */
|
---|
174 | retranslateUi();
|
---|
175 | }
|
---|
176 |
|
---|
177 | void UIGlobalSettingsGeneral::cleanup()
|
---|
178 | {
|
---|
179 | /* Cleanup cache: */
|
---|
180 | delete m_pCache;
|
---|
181 | m_pCache = 0;
|
---|
182 | }
|
---|
183 |
|
---|
184 | bool UIGlobalSettingsGeneral::saveGeneralData()
|
---|
185 | {
|
---|
186 | /* Prepare result: */
|
---|
187 | bool fSuccess = true;
|
---|
188 | /* Save general settings from the cache: */
|
---|
189 | if (fSuccess && m_pCache->wasChanged())
|
---|
190 | {
|
---|
191 | /* Get old general data from the cache: */
|
---|
192 | const UIDataSettingsGlobalGeneral &oldGeneralData = m_pCache->base();
|
---|
193 | /* Get new general data from the cache: */
|
---|
194 | const UIDataSettingsGlobalGeneral &newGeneralData = m_pCache->data();
|
---|
195 |
|
---|
196 | /* Save default machine folder: */
|
---|
197 | if ( fSuccess
|
---|
198 | && newGeneralData.m_strDefaultMachineFolder != oldGeneralData.m_strDefaultMachineFolder)
|
---|
199 | {
|
---|
200 | m_properties.SetDefaultMachineFolder(newGeneralData.m_strDefaultMachineFolder);
|
---|
201 | fSuccess = m_properties.isOk();
|
---|
202 | }
|
---|
203 | /* Save VRDE auth library: */
|
---|
204 | if ( fSuccess
|
---|
205 | && newGeneralData.m_strVRDEAuthLibrary != oldGeneralData.m_strVRDEAuthLibrary)
|
---|
206 | {
|
---|
207 | m_properties.SetVRDEAuthLibrary(newGeneralData.m_strVRDEAuthLibrary);
|
---|
208 | fSuccess = m_properties.isOk();
|
---|
209 | }
|
---|
210 |
|
---|
211 | /* Show error message if necessary: */
|
---|
212 | if (!fSuccess)
|
---|
213 | notifyOperationProgressError(UIErrorString::formatErrorInfo(m_properties));
|
---|
214 |
|
---|
215 | /* Save new general data from the cache: */
|
---|
216 | if (newGeneralData.m_fHostScreenSaverDisabled != oldGeneralData.m_fHostScreenSaverDisabled)
|
---|
217 | gEDataManager->setHostScreenSaverDisabled(newGeneralData.m_fHostScreenSaverDisabled);
|
---|
218 | }
|
---|
219 | /* Return result: */
|
---|
220 | return fSuccess;
|
---|
221 | }
|
---|
222 |
|
---|