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