VirtualBox

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

Last change on this file since 104158 was 101230, checked in by vboxsync, 17 months ago

FE/Qt: bugref:10513: Update UIEditor with API to register sub-editors; This will be useful to use outside of the editor code.

  • 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 101230 2023-09-21 20:17:24Z 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
31/* GUI includes: */
32#include "UIColorThemeEditor.h"
33#include "UIExtraDataManager.h"
34#include "UIGlobalSettingsInterface.h"
35
36
37/** Global settings: User Interface page data structure. */
38struct UIDataSettingsGlobalInterface
39{
40 /** Constructs data. */
41 UIDataSettingsGlobalInterface()
42 : m_enmColorTheme(UIColorThemeType_Auto)
43 {}
44
45 /** Returns whether the @a other passed data is equal to this one. */
46 bool equal(const UIDataSettingsGlobalInterface &other) const
47 {
48 return true
49 && (m_enmColorTheme == other.m_enmColorTheme)
50 ;
51 }
52
53 /** Returns whether the @a other passed data is equal to this one. */
54 bool operator==(const UIDataSettingsGlobalInterface &other) const { return equal(other); }
55 /** Returns whether the @a other passed data is different from this one. */
56 bool operator!=(const UIDataSettingsGlobalInterface &other) const { return !equal(other); }
57
58 /** Holds the color-theme. */
59 UIColorThemeType m_enmColorTheme;
60};
61
62
63/*********************************************************************************************************************************
64* Class UIGlobalSettingsInterface implementation. *
65*********************************************************************************************************************************/
66
67UIGlobalSettingsInterface::UIGlobalSettingsInterface()
68 : m_pCache(0)
69 , m_pEditorColorTheme(0)
70{
71 prepare();
72}
73
74UIGlobalSettingsInterface::~UIGlobalSettingsInterface()
75{
76 cleanup();
77}
78
79bool UIGlobalSettingsInterface::changed() const
80{
81 return m_pCache ? m_pCache->wasChanged() : false;
82}
83
84void UIGlobalSettingsInterface::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 UIDataSettingsGlobalInterface oldData;
98 oldData.m_enmColorTheme = gEDataManager->colorTheme();
99 m_pCache->cacheInitialData(oldData);
100
101 /* Upload properties to data: */
102 UISettingsPageGlobal::uploadData(data);
103}
104
105void UIGlobalSettingsInterface::getFromCache()
106{
107 /* Sanity check: */
108 if (!m_pCache)
109 return;
110
111 /* Load old data from cache: */
112 const UIDataSettingsGlobalInterface &oldData = m_pCache->base();
113 if (m_pEditorColorTheme)
114 m_pEditorColorTheme->setValue(oldData.m_enmColorTheme);
115
116 /* Revalidate: */
117 revalidate();
118}
119
120void UIGlobalSettingsInterface::putToCache()
121{
122 /* Sanity check: */
123 if (!m_pCache)
124 return;
125
126 /* Prepare new data: */
127 UIDataSettingsGlobalInterface newData;
128
129 /* Cache new data: */
130 if (m_pEditorColorTheme)
131 newData.m_enmColorTheme = m_pEditorColorTheme->value();
132 m_pCache->cacheCurrentData(newData);
133}
134
135void UIGlobalSettingsInterface::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 UIGlobalSettingsInterface::retranslateUi()
148{
149}
150
151void UIGlobalSettingsInterface::prepare()
152{
153 /* Prepare cache: */
154 m_pCache = new UISettingsCacheGlobalInterface;
155 AssertPtrReturnVoid(m_pCache);
156
157 /* Prepare everything: */
158 prepareWidgets();
159
160 /* Apply language settings: */
161 retranslateUi();
162}
163
164void UIGlobalSettingsInterface::prepareWidgets()
165{
166 /* Prepare main layout: */
167 QVBoxLayout *pLayout = new QVBoxLayout(this);
168 if (pLayout)
169 {
170 /* Prepare 'color-theme' editor: */
171 m_pEditorColorTheme = new UIColorThemeEditor(this);
172 if (m_pEditorColorTheme)
173 {
174 addEditor(m_pEditorColorTheme);
175 pLayout->addWidget(m_pEditorColorTheme);
176 }
177
178 /* Add stretch to the end: */
179 pLayout->addStretch();
180 }
181}
182
183void UIGlobalSettingsInterface::cleanup()
184{
185 /* Cleanup cache: */
186 delete m_pCache;
187 m_pCache = 0;
188}
189
190bool UIGlobalSettingsInterface::saveData()
191{
192 /* Sanity check: */
193 if (!m_pCache)
194 return false;
195
196 /* Prepare result: */
197 bool fSuccess = true;
198 /* Save settings from cache: */
199 if ( fSuccess
200 && m_pCache->wasChanged())
201 {
202 /* Get old data from cache: */
203 const UIDataSettingsGlobalInterface &oldData = m_pCache->base();
204 /* Get new data from cache: */
205 const UIDataSettingsGlobalInterface &newData = m_pCache->data();
206
207 /* Save 'color-theme': */
208 if ( fSuccess
209 && newData.m_enmColorTheme != oldData.m_enmColorTheme)
210 /* fSuccess = */ gEDataManager->setColorTheme(newData.m_enmColorTheme);
211 }
212 /* Return result: */
213 return fSuccess;
214}
Note: See TracBrowser for help on using the repository browser.

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