VirtualBox

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

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

FE/Qt. Build fix.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use