VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsGeneral.cpp@ 86096

Last change on this file since 86096 was 86096, checked in by vboxsync, 4 years ago

FE/Qt: bugref:9827: Cleanup for Global properties / General page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: UIGlobalSettingsGeneral.cpp 86096 2020-09-11 14:31:56Z 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 <QDir>
20#include <QGridLayout>
21#include <QLabel>
22
23/* GUI includes: */
24#include "UICommon.h"
25#include "UIErrorString.h"
26#include "UIFilePathSelector.h"
27#include "UIGlobalSettingsGeneral.h"
28
29
30/** Global settings: General page data structure. */
31struct UIDataSettingsGlobalGeneral
32{
33 /** Constructs data. */
34 UIDataSettingsGlobalGeneral()
35 : m_strDefaultMachineFolder(QString())
36 , m_strVRDEAuthLibrary(QString())
37 {}
38
39 /** Returns whether the @a other passed data is equal to this one. */
40 bool equal(const UIDataSettingsGlobalGeneral &other) const
41 {
42 return true
43 && (m_strDefaultMachineFolder == other.m_strDefaultMachineFolder)
44 && (m_strVRDEAuthLibrary == other.m_strVRDEAuthLibrary)
45 ;
46 }
47
48 /** Returns whether the @a other passed data is equal to this one. */
49 bool operator==(const UIDataSettingsGlobalGeneral &other) const { return equal(other); }
50 /** Returns whether the @a other passed data is different from this one. */
51 bool operator!=(const UIDataSettingsGlobalGeneral &other) const { return !equal(other); }
52
53 /** Holds the 'default machine folder' path. */
54 QString m_strDefaultMachineFolder;
55 /** Holds the 'VRDE auth library' name. */
56 QString m_strVRDEAuthLibrary;
57};
58
59
60UIGlobalSettingsGeneral::UIGlobalSettingsGeneral()
61 : m_pCache(0)
62 , m_pLabelDefaultMachineFolder(0)
63 , m_pSelectorDefaultMachineFolder(0)
64 , m_pLabelVRDEAuthLibrary(0)
65 , m_pSelectorVRDEAuthLibrary(0)
66{
67 prepare();
68}
69
70UIGlobalSettingsGeneral::~UIGlobalSettingsGeneral()
71{
72 cleanup();
73}
74
75void UIGlobalSettingsGeneral::loadToCacheFrom(QVariant &data)
76{
77 /* Fetch data to properties: */
78 UISettingsPageGlobal::fetchData(data);
79
80 /* Clear cache initially: */
81 m_pCache->clear();
82
83 /* Cache old data: */
84 UIDataSettingsGlobalGeneral oldData;
85 oldData.m_strDefaultMachineFolder = m_properties.GetDefaultMachineFolder();
86 oldData.m_strVRDEAuthLibrary = m_properties.GetVRDEAuthLibrary();
87 m_pCache->cacheInitialData(oldData);
88
89 /* Upload properties to data: */
90 UISettingsPageGlobal::uploadData(data);
91}
92
93void UIGlobalSettingsGeneral::getFromCache()
94{
95 /* Load old data from cache: */
96 const UIDataSettingsGlobalGeneral &oldData = m_pCache->base();
97 m_pSelectorDefaultMachineFolder->setPath(oldData.m_strDefaultMachineFolder);
98 m_pSelectorVRDEAuthLibrary->setPath(oldData.m_strVRDEAuthLibrary);
99}
100
101void UIGlobalSettingsGeneral::putToCache()
102{
103 /* Prepare new data: */
104 UIDataSettingsGlobalGeneral newData = m_pCache->base();
105
106 /* Cache new data: */
107 newData.m_strDefaultMachineFolder = m_pSelectorDefaultMachineFolder->path();
108 newData.m_strVRDEAuthLibrary = m_pSelectorVRDEAuthLibrary->path();
109 m_pCache->cacheCurrentData(newData);
110}
111
112void UIGlobalSettingsGeneral::saveFromCacheTo(QVariant &data)
113{
114 /* Fetch data to properties: */
115 UISettingsPageGlobal::fetchData(data);
116
117 /* Update data and failing state: */
118 setFailed(!saveGeneralData());
119
120 /* Upload properties to data: */
121 UISettingsPageGlobal::uploadData(data);
122}
123
124void UIGlobalSettingsGeneral::retranslateUi()
125{
126 m_pLabelDefaultMachineFolder->setText(tr("Default &Machine Folder:"));
127 m_pSelectorDefaultMachineFolder->setWhatsThis(tr("Holds the path to the default virtual machine folder. This folder is used, "
128 "if not explicitly specified otherwise, when creating new virtual machines."));
129 m_pLabelVRDEAuthLibrary->setText(tr("V&RDP Authentication Library:"));
130 m_pSelectorVRDEAuthLibrary->setWhatsThis(tr("Holds the path to the library that provides "
131 "authentication for Remote Display (VRDP) clients."));
132}
133
134void UIGlobalSettingsGeneral::prepare()
135{
136 /* Prepare cache: */
137 m_pCache = new UISettingsCacheGlobalGeneral;
138 AssertPtrReturnVoid(m_pCache);
139
140 /* Prepare everything: */
141 prepareWidgets();
142
143 /* Apply language settings: */
144 retranslateUi();
145}
146
147void UIGlobalSettingsGeneral::prepareWidgets()
148{
149 /* Prepare main layout: */
150 QGridLayout *pLayoutMain = new QGridLayout(this);
151 if (pLayoutMain)
152 {
153 pLayoutMain->setColumnStretch(1, 1);
154 pLayoutMain->setRowStretch(3, 1);
155
156 /* Prepare 'default machine folder' label: */
157 m_pLabelDefaultMachineFolder = new QLabel(this);
158 if (m_pLabelDefaultMachineFolder)
159 {
160 m_pLabelDefaultMachineFolder->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
161 pLayoutMain->addWidget(m_pLabelDefaultMachineFolder, 0, 0);
162 }
163 /* Prepare 'default machine folder' editor: */
164 m_pSelectorDefaultMachineFolder = new UIFilePathSelector(this);
165 if (m_pSelectorDefaultMachineFolder)
166 {
167 if (m_pLabelDefaultMachineFolder)
168 m_pLabelDefaultMachineFolder->setBuddy(m_pSelectorDefaultMachineFolder);
169 m_pSelectorDefaultMachineFolder->setHomeDir(uiCommon().homeFolder());
170
171 pLayoutMain->addWidget(m_pSelectorDefaultMachineFolder, 0, 1, 1, 2);
172 }
173
174 /* Prepare 'VRDE auth library' label: */
175 m_pLabelVRDEAuthLibrary = new QLabel(this);
176 if (m_pLabelVRDEAuthLibrary)
177 {
178 m_pLabelVRDEAuthLibrary->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
179 pLayoutMain->addWidget(m_pLabelVRDEAuthLibrary, 1, 0);
180 }
181 /* Prepare 'VRDE auth library' editor: */
182 m_pSelectorVRDEAuthLibrary = new UIFilePathSelector(this);
183 if (m_pSelectorVRDEAuthLibrary)
184 {
185 if (m_pLabelVRDEAuthLibrary)
186 m_pLabelVRDEAuthLibrary->setBuddy(m_pSelectorVRDEAuthLibrary);
187 m_pSelectorVRDEAuthLibrary->setHomeDir(uiCommon().homeFolder());
188 m_pSelectorVRDEAuthLibrary->setMode(UIFilePathSelector::Mode_File_Open);
189
190 pLayoutMain->addWidget(m_pSelectorVRDEAuthLibrary, 1, 1, 1, 2);
191 }
192 }
193}
194
195void UIGlobalSettingsGeneral::cleanup()
196{
197 /* Cleanup cache: */
198 delete m_pCache;
199 m_pCache = 0;
200}
201
202bool UIGlobalSettingsGeneral::saveGeneralData()
203{
204 /* Prepare result: */
205 bool fSuccess = true;
206 /* Save settings from cache: */
207 if (fSuccess && m_pCache->wasChanged())
208 {
209 /* Get old data from cache: */
210 const UIDataSettingsGlobalGeneral &oldData = m_pCache->base();
211 /* Get new data from cache: */
212 const UIDataSettingsGlobalGeneral &newData = m_pCache->data();
213
214 /* Save 'default machine folder': */
215 if ( fSuccess
216 && newData.m_strDefaultMachineFolder != oldData.m_strDefaultMachineFolder)
217 {
218 m_properties.SetDefaultMachineFolder(newData.m_strDefaultMachineFolder);
219 fSuccess = m_properties.isOk();
220 }
221 /* Save 'VRDE auth library': */
222 if ( fSuccess
223 && newData.m_strVRDEAuthLibrary != oldData.m_strVRDEAuthLibrary)
224 {
225 m_properties.SetVRDEAuthLibrary(newData.m_strVRDEAuthLibrary);
226 fSuccess = m_properties.isOk();
227 }
228
229 /* Show error message if necessary: */
230 if (!fSuccess)
231 notifyOperationProgressError(UIErrorString::formatErrorInfo(m_properties));
232 }
233 /* Return result: */
234 return fSuccess;
235}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette