VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsUpdate.cpp

Last change on this file was 104313, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the settings related GUI classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: UIGlobalSettingsUpdate.cpp 104313 2024-04-12 13:10:30Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIGlobalSettingsUpdate 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 "UIExtraDataManager.h"
33#include "UIGlobalSettingsUpdate.h"
34#include "UIUpdateSettingsEditor.h"
35
36
37/** Global settings: Update page data structure. */
38struct UIDataSettingsGlobalUpdate
39{
40 /** Constructs data. */
41 UIDataSettingsGlobalUpdate()
42 : m_guiUpdateData(VBoxUpdateData())
43 {}
44
45 /** Returns whether the @a other passed data is equal to this one. */
46 bool equal(const UIDataSettingsGlobalUpdate &other) const
47 {
48 return true
49 && (m_guiUpdateData == other.m_guiUpdateData)
50 ;
51 }
52
53 /** Returns whether the @a other passed data is equal to this one. */
54 bool operator==(const UIDataSettingsGlobalUpdate &other) const { return equal(other); }
55 /** Returns whether the @a other passed data is different from this one. */
56 bool operator!=(const UIDataSettingsGlobalUpdate &other) const { return !equal(other); }
57
58 /** Holds VBox update data. */
59 VBoxUpdateData m_guiUpdateData;
60};
61
62
63/*********************************************************************************************************************************
64* Class UIGlobalSettingsUpdate implementation. *
65*********************************************************************************************************************************/
66
67UIGlobalSettingsUpdate::UIGlobalSettingsUpdate()
68 : m_pCache(0)
69 , m_pEditorUpdateSettings(0)
70{
71 prepare();
72}
73
74UIGlobalSettingsUpdate::~UIGlobalSettingsUpdate()
75{
76 cleanup();
77}
78
79bool UIGlobalSettingsUpdate::changed() const
80{
81 return m_pCache ? m_pCache->wasChanged() : false;
82}
83
84void UIGlobalSettingsUpdate::loadToCacheFrom(QVariant &data)
85{
86 /* Sanity check: */
87 if (!m_pCache)
88 return;
89
90 /* Fetch data to properties: */
91 UISettingsPageGlobal::fetchData(data);
92
93 /* Clear cache initially: */
94 m_pCache->clear();
95
96 /* Cache old data: */
97 UIDataSettingsGlobalUpdate oldData;
98 VBoxUpdateData guiUpdateData;
99 /* Load old data from host: */
100 guiUpdateData.load(m_host);
101 oldData.m_guiUpdateData = guiUpdateData;
102 m_pCache->cacheInitialData(oldData);
103
104 /* Upload properties to data: */
105 UISettingsPageGlobal::uploadData(data);
106}
107
108void UIGlobalSettingsUpdate::getFromCache()
109{
110 /* Sanity check: */
111 if (!m_pCache)
112 return;
113
114 /* Load old data from cache: */
115 const UIDataSettingsGlobalUpdate &oldData = m_pCache->base();
116 if (m_pEditorUpdateSettings)
117 m_pEditorUpdateSettings->setValue(oldData.m_guiUpdateData);
118}
119
120void UIGlobalSettingsUpdate::putToCache()
121{
122 /* Sanity check: */
123 if (!m_pCache)
124 return;
125
126 /* Prepare new data: */
127 UIDataSettingsGlobalUpdate newData = m_pCache->base();
128
129 /* Cache new data: */
130 if (m_pEditorUpdateSettings)
131 newData.m_guiUpdateData = m_pEditorUpdateSettings->value();
132 m_pCache->cacheCurrentData(newData);
133}
134
135void UIGlobalSettingsUpdate::saveFromCacheTo(QVariant &data)
136{
137 /* Fetch data to properties: */
138 UISettingsPageGlobal::fetchData(data);
139
140 /* Update data and failing state: */
141 setFailed(!saveData());
142
143 /* Upload properties to data: */
144 UISettingsPageGlobal::uploadData(data);
145}
146
147void UIGlobalSettingsUpdate::sltRetranslateUI()
148{
149}
150
151void UIGlobalSettingsUpdate::prepare()
152{
153 /* Prepare cache: */
154 m_pCache = new UISettingsCacheGlobalUpdate;
155 AssertPtrReturnVoid(m_pCache);
156
157 /* Prepare everything: */
158 prepareWidgets();
159
160 /* Apply language settings: */
161 sltRetranslateUI();
162}
163
164void UIGlobalSettingsUpdate::prepareWidgets()
165{
166 /* Prepare main layout: */
167 QVBoxLayout *pLayout = new QVBoxLayout(this);
168 if (pLayout)
169 {
170 /* Prepare 'update settings' editor: */
171 m_pEditorUpdateSettings = new UIUpdateSettingsEditor(this);
172 if (m_pEditorUpdateSettings)
173 {
174 addEditor(m_pEditorUpdateSettings);
175 pLayout->addWidget(m_pEditorUpdateSettings);
176 }
177
178 /* Add stretch to the end: */
179 pLayout->addStretch();
180 }
181}
182
183void UIGlobalSettingsUpdate::cleanup()
184{
185 /* Cleanup cache: */
186 delete m_pCache;
187 m_pCache = 0;
188}
189
190bool UIGlobalSettingsUpdate::saveData()
191{
192 /* Sanity check: */
193 if (!m_pCache)
194 return false;
195
196 /* Prepare result: */
197 bool fSuccess = true;
198 /* Save update settings from cache: */
199 if ( fSuccess
200 && m_pCache->wasChanged())
201 {
202 /* Get old data from cache: */
203 const UIDataSettingsGlobalUpdate &oldData = m_pCache->base();
204 /* Get new data from cache: */
205 const UIDataSettingsGlobalUpdate &newData = m_pCache->data();
206
207 /* Save new data from cache: */
208 if ( fSuccess
209 && newData != oldData)
210 {
211 /* We still prefer data to be saved to extra-data as well, for backward compartibility: */
212 /* fSuccess = */ gEDataManager->setApplicationUpdateData(newData.m_guiUpdateData.data());
213 /* Save new data to host finally: */
214 const VBoxUpdateData guiUpdateData = newData.m_guiUpdateData;
215 fSuccess = guiUpdateData.save(m_host);
216 }
217 }
218 /* Return result: */
219 return fSuccess;
220}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use