1 | /* $Id: UIVMCloseDialog.cpp 103578 2024-02-26 17:29:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMCloseDialog 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 <QButtonGroup>
|
---|
30 | #include <QCheckBox>
|
---|
31 | #include <QGridLayout>
|
---|
32 | #include <QHBoxLayout>
|
---|
33 | #include <QLabel>
|
---|
34 | #include <QPushButton>
|
---|
35 | #include <QRadioButton>
|
---|
36 | #include <QStyle>
|
---|
37 | #include <QVBoxLayout>
|
---|
38 | #include <QWindow>
|
---|
39 |
|
---|
40 | /* GUI includes: */
|
---|
41 | #include "QIDialogButtonBox.h"
|
---|
42 | #include "UICommon.h"
|
---|
43 | #include "UIConverter.h"
|
---|
44 | #include "UIExtraDataManager.h"
|
---|
45 | #include "UIHelpBrowserDialog.h"
|
---|
46 | #include "UIIconPool.h"
|
---|
47 | #include "UIMachine.h"
|
---|
48 | #include "UIMessageCenter.h"
|
---|
49 | #include "UIShortcutPool.h"
|
---|
50 | #include "UIVMCloseDialog.h"
|
---|
51 |
|
---|
52 |
|
---|
53 | UIVMCloseDialog::UIVMCloseDialog(QWidget *pParent, UIMachine *pMachine,
|
---|
54 | bool fIsACPIEnabled, MachineCloseAction restictedCloseActions)
|
---|
55 | : QIWithRetranslateUI<QIDialog>(pParent)
|
---|
56 | , m_pMachine(pMachine)
|
---|
57 | , m_fIsACPIEnabled(fIsACPIEnabled)
|
---|
58 | , m_restictedCloseActions(restictedCloseActions)
|
---|
59 | , m_fValid(false)
|
---|
60 | , m_pMainLayout(0)
|
---|
61 | , m_pTopLayout(0)
|
---|
62 | , m_pTopLeftLayout(0)
|
---|
63 | , m_pTopRightLayout(0)
|
---|
64 | , m_pChoiceLayout(0)
|
---|
65 | , m_pLabelIcon(0), m_pLabelText(0)
|
---|
66 | , m_pLabelIconDetach(0), m_pRadioButtonDetach(0)
|
---|
67 | , m_pLabelIconSave(0), m_pRadioButtonSave(0)
|
---|
68 | , m_pLabelIconShutdown(0), m_pRadioButtonShutdown(0)
|
---|
69 | , m_pLabelIconPowerOff(0), m_pRadioButtonPowerOff(0)
|
---|
70 | , m_pCheckBoxDiscard(0)
|
---|
71 | , m_enmLastCloseAction(MachineCloseAction_Invalid)
|
---|
72 | {
|
---|
73 | prepare();
|
---|
74 | }
|
---|
75 |
|
---|
76 | void UIVMCloseDialog::setIcon(const QIcon &icon)
|
---|
77 | {
|
---|
78 | /* Make sure icon is valid: */
|
---|
79 | if (icon.isNull())
|
---|
80 | return;
|
---|
81 |
|
---|
82 | /* Remember it: */
|
---|
83 | m_icon = icon;
|
---|
84 | /* Update pixmaps: */
|
---|
85 | updatePixmaps();
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool UIVMCloseDialog::eventFilter(QObject *pObject, QEvent *pEvent)
|
---|
89 | {
|
---|
90 | /* Handle events realted to our radio-buttons only: */
|
---|
91 | if ( pObject != m_pRadioButtonDetach
|
---|
92 | && pObject != m_pRadioButtonSave
|
---|
93 | && pObject != m_pRadioButtonShutdown
|
---|
94 | && pObject != m_pRadioButtonPowerOff)
|
---|
95 | return QIWithRetranslateUI<QIDialog>::eventFilter(pObject, pEvent);
|
---|
96 |
|
---|
97 | /* For now we are interested in double-click events only: */
|
---|
98 | if (pEvent->type() == QEvent::MouseButtonDblClick)
|
---|
99 | {
|
---|
100 | /* Make sure it's one of the radio-buttons
|
---|
101 | * which has this event-filter installed: */
|
---|
102 | if (qobject_cast<QRadioButton*>(pObject))
|
---|
103 | {
|
---|
104 | /* Since on double-click the button will be also selected
|
---|
105 | * we are just calling for the *accept* slot: */
|
---|
106 | accept();
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | /* Call to base-class: */
|
---|
111 | return QIWithRetranslateUI<QIDialog>::eventFilter(pObject, pEvent);
|
---|
112 | }
|
---|
113 |
|
---|
114 | bool UIVMCloseDialog::event(QEvent *pEvent)
|
---|
115 | {
|
---|
116 | /* Pre-process in base-class: */
|
---|
117 | const bool fResult = QIWithRetranslateUI<QIDialog>::event(pEvent);
|
---|
118 |
|
---|
119 | /* Post-process know event types: */
|
---|
120 | switch (pEvent->type())
|
---|
121 | {
|
---|
122 | case QEvent::ScreenChangeInternal:
|
---|
123 | {
|
---|
124 | /* Update pixmaps: */
|
---|
125 | updatePixmaps();
|
---|
126 | break;
|
---|
127 | }
|
---|
128 | default:
|
---|
129 | break;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* Return pre-processed result: */
|
---|
133 | return fResult;
|
---|
134 | }
|
---|
135 |
|
---|
136 | void UIVMCloseDialog::showEvent(QShowEvent *pEvent)
|
---|
137 | {
|
---|
138 | /* Update pixmaps: */
|
---|
139 | updatePixmaps();
|
---|
140 |
|
---|
141 | /* Call to base-class: */
|
---|
142 | QIWithRetranslateUI<QIDialog>::showEvent(pEvent);
|
---|
143 | }
|
---|
144 |
|
---|
145 | void UIVMCloseDialog::retranslateUi()
|
---|
146 | {
|
---|
147 | /* Translate title: */
|
---|
148 | setWindowTitle(tr("Close Virtual Machine"));
|
---|
149 |
|
---|
150 | /* Translate text label: */
|
---|
151 | m_pLabelText->setText(tr("You want to:"));
|
---|
152 |
|
---|
153 | /* Translate radio-buttons: */
|
---|
154 | m_pRadioButtonDetach->setText(tr("&Continue running in the background"));
|
---|
155 | m_pRadioButtonDetach->setWhatsThis(tr("<p>Close the virtual machine windows but keep the virtual machine running.</p>"
|
---|
156 | "<p>You can use the VirtualBox Manager to return to running the virtual machine "
|
---|
157 | "in a window.</p>"));
|
---|
158 | m_pRadioButtonSave->setText(tr("&Save the machine state"));
|
---|
159 | m_pRadioButtonSave->setWhatsThis(tr("<p>Saves the current execution state of the virtual machine to the physical hard disk "
|
---|
160 | "of the host PC.</p>"
|
---|
161 | "<p>Next time this machine is started, it will be restored from the saved state and "
|
---|
162 | "continue execution from the same place you saved it at, which will let you continue "
|
---|
163 | "your work immediately.</p>"
|
---|
164 | "<p>Note that saving the machine state may take a long time, depending on the guest "
|
---|
165 | "operating system type and the amount of memory you assigned to the virtual "
|
---|
166 | "machine.</p>"));
|
---|
167 | m_pRadioButtonShutdown->setText(tr("S&end the shutdown signal"));
|
---|
168 | m_pRadioButtonShutdown->setWhatsThis(tr("<p>Sends the ACPI Power Button press event to the virtual machine.</p>"
|
---|
169 | "<p>Normally, the guest operating system running inside the virtual machine will "
|
---|
170 | "detect this event and perform a clean shutdown procedure. This is a recommended "
|
---|
171 | "way to turn off the virtual machine because all applications running inside it "
|
---|
172 | "will get a chance to save their data and state.</p>"
|
---|
173 | "<p>If the machine doesn't respond to this action then the guest operating system "
|
---|
174 | "may be misconfigured or doesn't understand ACPI Power Button events at all. In "
|
---|
175 | "this case you should select the <b>Power off the machine</b> action to stop "
|
---|
176 | "virtual machine execution.</p>"));
|
---|
177 | m_pRadioButtonPowerOff->setText(tr("&Power off the machine"));
|
---|
178 | m_pRadioButtonPowerOff->setWhatsThis(tr("<p>Turns off the virtual machine.</p>"
|
---|
179 | "<p>Note that this action will stop machine execution immediately so that the guest "
|
---|
180 | "operating system running inside it will not be able to perform a clean shutdown "
|
---|
181 | "procedure which may result in <i>data loss</i> inside the virtual machine. "
|
---|
182 | "Selecting this action is recommended only if the virtual machine does not respond "
|
---|
183 | "to the <b>Send the shutdown signal</b> action.</p>"));
|
---|
184 |
|
---|
185 | /* Translate check-box: */
|
---|
186 | m_pCheckBoxDiscard->setText(tr("&Restore current snapshot '%1'").arg(m_strDiscardCheckBoxText));
|
---|
187 | m_pCheckBoxDiscard->setWhatsThis(tr("<p>When checked, the machine will be returned to the state stored in the current "
|
---|
188 | "snapshot after it is turned off. This is useful if you are sure that you want to "
|
---|
189 | "discard the results of your last sessions and start again at that snapshot.</p>"));
|
---|
190 | }
|
---|
191 |
|
---|
192 | void UIVMCloseDialog::sltUpdateWidgetAvailability()
|
---|
193 | {
|
---|
194 | /* Discard option should be enabled only on power-off action: */
|
---|
195 | m_pCheckBoxDiscard->setEnabled(m_pRadioButtonPowerOff->isChecked());
|
---|
196 | }
|
---|
197 |
|
---|
198 | void UIVMCloseDialog::accept()
|
---|
199 | {
|
---|
200 | /* Calculate result: */
|
---|
201 | if (m_pRadioButtonDetach->isChecked())
|
---|
202 | setResult(MachineCloseAction_Detach);
|
---|
203 | else if (m_pRadioButtonSave->isChecked())
|
---|
204 | setResult(MachineCloseAction_SaveState);
|
---|
205 | else if (m_pRadioButtonShutdown->isChecked())
|
---|
206 | setResult(MachineCloseAction_Shutdown);
|
---|
207 | else if (m_pRadioButtonPowerOff->isChecked())
|
---|
208 | {
|
---|
209 | if (!m_pCheckBoxDiscard->isChecked() || !m_pCheckBoxDiscard->isVisible())
|
---|
210 | setResult(MachineCloseAction_PowerOff);
|
---|
211 | else
|
---|
212 | setResult(MachineCloseAction_PowerOff_RestoringSnapshot);
|
---|
213 | }
|
---|
214 |
|
---|
215 | /* Memorize the last user's choice for the given VM: */
|
---|
216 | MachineCloseAction newCloseAction = static_cast<MachineCloseAction>(result());
|
---|
217 | /* But make sure 'Shutdown' is preserved if temporary unavailable: */
|
---|
218 | if (newCloseAction == MachineCloseAction_PowerOff &&
|
---|
219 | m_enmLastCloseAction == MachineCloseAction_Shutdown && !m_fIsACPIEnabled)
|
---|
220 | newCloseAction = MachineCloseAction_Shutdown;
|
---|
221 | gEDataManager->setLastMachineCloseAction(newCloseAction, uiCommon().managedVMUuid());
|
---|
222 |
|
---|
223 | /* Hide the dialog: */
|
---|
224 | hide();
|
---|
225 | }
|
---|
226 |
|
---|
227 | void UIVMCloseDialog::setButtonEnabledDetach(bool fEnabled)
|
---|
228 | {
|
---|
229 | m_pLabelIconDetach->setEnabled(fEnabled);
|
---|
230 | m_pRadioButtonDetach->setEnabled(fEnabled);
|
---|
231 | }
|
---|
232 |
|
---|
233 | void UIVMCloseDialog::setButtonVisibleDetach(bool fVisible)
|
---|
234 | {
|
---|
235 | m_pLabelIconDetach->setVisible(fVisible);
|
---|
236 | m_pRadioButtonDetach->setVisible(fVisible);
|
---|
237 | }
|
---|
238 |
|
---|
239 | void UIVMCloseDialog::setButtonEnabledSave(bool fEnabled)
|
---|
240 | {
|
---|
241 | m_pLabelIconSave->setEnabled(fEnabled);
|
---|
242 | m_pRadioButtonSave->setEnabled(fEnabled);
|
---|
243 | }
|
---|
244 |
|
---|
245 | void UIVMCloseDialog::setButtonVisibleSave(bool fVisible)
|
---|
246 | {
|
---|
247 | m_pLabelIconSave->setVisible(fVisible);
|
---|
248 | m_pRadioButtonSave->setVisible(fVisible);
|
---|
249 | }
|
---|
250 |
|
---|
251 | void UIVMCloseDialog::setButtonEnabledShutdown(bool fEnabled)
|
---|
252 | {
|
---|
253 | m_pLabelIconShutdown->setEnabled(fEnabled);
|
---|
254 | m_pRadioButtonShutdown->setEnabled(fEnabled);
|
---|
255 | }
|
---|
256 |
|
---|
257 | void UIVMCloseDialog::setButtonVisibleShutdown(bool fVisible)
|
---|
258 | {
|
---|
259 | m_pLabelIconShutdown->setVisible(fVisible);
|
---|
260 | m_pRadioButtonShutdown->setVisible(fVisible);
|
---|
261 | }
|
---|
262 |
|
---|
263 | void UIVMCloseDialog::setButtonEnabledPowerOff(bool fEnabled)
|
---|
264 | {
|
---|
265 | m_pLabelIconPowerOff->setEnabled(fEnabled);
|
---|
266 | m_pRadioButtonPowerOff->setEnabled(fEnabled);
|
---|
267 | }
|
---|
268 |
|
---|
269 | void UIVMCloseDialog::setButtonVisiblePowerOff(bool fVisible)
|
---|
270 | {
|
---|
271 | m_pLabelIconPowerOff->setVisible(fVisible);
|
---|
272 | m_pRadioButtonPowerOff->setVisible(fVisible);
|
---|
273 | }
|
---|
274 |
|
---|
275 | void UIVMCloseDialog::setCheckBoxVisibleDiscard(bool fVisible)
|
---|
276 | {
|
---|
277 | m_pCheckBoxDiscard->setVisible(fVisible);
|
---|
278 | }
|
---|
279 |
|
---|
280 | void UIVMCloseDialog::prepare()
|
---|
281 | {
|
---|
282 | /* Choose default dialog icon: */
|
---|
283 | m_icon = UIIconPool::iconSet(":/os_unknown.png");
|
---|
284 |
|
---|
285 | /* Prepare size-grip token: */
|
---|
286 | setSizeGripEnabled(false);
|
---|
287 |
|
---|
288 | /* Prepare main layout: */
|
---|
289 | prepareMainLayout();
|
---|
290 |
|
---|
291 | /* Update pixmaps: */
|
---|
292 | updatePixmaps();
|
---|
293 |
|
---|
294 | /* Configure: */
|
---|
295 | configure();
|
---|
296 |
|
---|
297 | /* Apply language settings: */
|
---|
298 | retranslateUi();
|
---|
299 | }
|
---|
300 |
|
---|
301 | void UIVMCloseDialog::prepareMainLayout()
|
---|
302 | {
|
---|
303 | /* Create main layout: */
|
---|
304 | m_pMainLayout = new QVBoxLayout(this);
|
---|
305 | if (m_pMainLayout)
|
---|
306 | {
|
---|
307 | /* Configure layout: */
|
---|
308 | #ifdef VBOX_WS_MAC
|
---|
309 | m_pMainLayout->setContentsMargins(40, 20, 40, 20);
|
---|
310 | m_pMainLayout->setSpacing(15);
|
---|
311 | #else
|
---|
312 | m_pMainLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) * 2);
|
---|
313 | #endif
|
---|
314 |
|
---|
315 | /* Prepare top layout: */
|
---|
316 | prepareTopLayout();
|
---|
317 |
|
---|
318 | /* Add stretch between top and bottom: */
|
---|
319 | m_pMainLayout->addStretch(1);
|
---|
320 |
|
---|
321 | /* Prepare button-box: */
|
---|
322 | prepareButtonBox();
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|
326 | void UIVMCloseDialog::prepareTopLayout()
|
---|
327 | {
|
---|
328 | /* Create top layout: */
|
---|
329 | m_pTopLayout = new QHBoxLayout;
|
---|
330 | if (m_pTopLayout)
|
---|
331 | {
|
---|
332 | /* Configure layout: */
|
---|
333 | #ifdef VBOX_WS_MAC
|
---|
334 | m_pTopLayout->setSpacing(20);
|
---|
335 | #else
|
---|
336 | m_pTopLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) * 2);
|
---|
337 | #endif
|
---|
338 |
|
---|
339 | /* Prepare top-left layout: */
|
---|
340 | prepareTopLeftLayout();
|
---|
341 | /* Prepare top-right layout: */
|
---|
342 | prepareTopRightLayout();
|
---|
343 |
|
---|
344 | /* Add into layout: */
|
---|
345 | m_pMainLayout->addLayout(m_pTopLayout);
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 | void UIVMCloseDialog::prepareTopLeftLayout()
|
---|
350 | {
|
---|
351 | /* Create top-left layout: */
|
---|
352 | m_pTopLeftLayout = new QVBoxLayout;
|
---|
353 | if (m_pTopLeftLayout)
|
---|
354 | {
|
---|
355 | /* Create icon label: */
|
---|
356 | m_pLabelIcon = new QLabel;
|
---|
357 | if (m_pLabelIcon)
|
---|
358 | {
|
---|
359 | /* Configure label: */
|
---|
360 | m_pLabelIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
361 |
|
---|
362 | /* Add into layout: */
|
---|
363 | m_pTopLeftLayout->addWidget(m_pLabelIcon);
|
---|
364 | }
|
---|
365 |
|
---|
366 | /* Add vertical stretch under icon label: */
|
---|
367 | m_pTopLeftLayout->addStretch();
|
---|
368 |
|
---|
369 | /* Add into layout: */
|
---|
370 | m_pTopLayout->addLayout(m_pTopLeftLayout);
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | void UIVMCloseDialog::prepareTopRightLayout()
|
---|
375 | {
|
---|
376 | /* Create top-right layout: */
|
---|
377 | m_pTopRightLayout = new QVBoxLayout;
|
---|
378 | if (m_pTopRightLayout)
|
---|
379 | {
|
---|
380 | /* Configure layout: */
|
---|
381 | #ifdef VBOX_WS_MAC
|
---|
382 | m_pTopRightLayout->setSpacing(10);
|
---|
383 | #else
|
---|
384 | m_pTopRightLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
|
---|
385 | #endif
|
---|
386 |
|
---|
387 | /* Create text label: */
|
---|
388 | m_pLabelText = new QLabel;
|
---|
389 | if (m_pLabelText)
|
---|
390 | {
|
---|
391 | /* Add into layout: */
|
---|
392 | m_pTopRightLayout->addWidget(m_pLabelText);
|
---|
393 | }
|
---|
394 |
|
---|
395 | /* Prepare choice layout: */
|
---|
396 | prepareChoiceLayout();
|
---|
397 |
|
---|
398 | /* Add into layout: */
|
---|
399 | m_pTopLayout->addLayout(m_pTopRightLayout);
|
---|
400 | }
|
---|
401 | }
|
---|
402 |
|
---|
403 | void UIVMCloseDialog::prepareChoiceLayout()
|
---|
404 | {
|
---|
405 | /* Create 'choice' layout: */
|
---|
406 | m_pChoiceLayout = new QGridLayout;
|
---|
407 | if (m_pChoiceLayout)
|
---|
408 | {
|
---|
409 | /* Configure layout: */
|
---|
410 | #ifdef VBOX_WS_MAC
|
---|
411 | m_pChoiceLayout->setSpacing(10);
|
---|
412 | #else
|
---|
413 | m_pChoiceLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
|
---|
414 | #endif
|
---|
415 |
|
---|
416 | /* Create button-group: */
|
---|
417 | QButtonGroup *pButtonGroup = new QButtonGroup(this);
|
---|
418 | if (pButtonGroup)
|
---|
419 | connect(pButtonGroup, &QButtonGroup::buttonClicked,
|
---|
420 | this, &UIVMCloseDialog::sltUpdateWidgetAvailability);
|
---|
421 |
|
---|
422 | /* Create 'detach' icon label: */
|
---|
423 | m_pLabelIconDetach = new QLabel;
|
---|
424 | if (m_pLabelIconDetach)
|
---|
425 | {
|
---|
426 | /* Configure label: */
|
---|
427 | m_pLabelIconDetach->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
428 | /* Add into layout: */
|
---|
429 | m_pChoiceLayout->addWidget(m_pLabelIconDetach, 0, 0);
|
---|
430 | }
|
---|
431 | /* Create 'detach' radio-button: */
|
---|
432 | m_pRadioButtonDetach = new QRadioButton;
|
---|
433 | if (m_pRadioButtonDetach)
|
---|
434 | {
|
---|
435 | /* Configure button: */
|
---|
436 | m_pRadioButtonDetach->installEventFilter(this);
|
---|
437 | /* Add into group/layout: */
|
---|
438 | pButtonGroup->addButton(m_pRadioButtonDetach);
|
---|
439 | m_pChoiceLayout->addWidget(m_pRadioButtonDetach, 0, 1);
|
---|
440 | }
|
---|
441 |
|
---|
442 | /* Create 'save' icon label: */
|
---|
443 | m_pLabelIconSave = new QLabel;
|
---|
444 | if (m_pLabelIconSave)
|
---|
445 | {
|
---|
446 | /* Configure label: */
|
---|
447 | m_pLabelIconSave->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
448 | /* Add into layout: */
|
---|
449 | m_pChoiceLayout->addWidget(m_pLabelIconSave, 1, 0);
|
---|
450 | }
|
---|
451 | /* Create 'save' radio-button: */
|
---|
452 | m_pRadioButtonSave = new QRadioButton;
|
---|
453 | if (m_pRadioButtonSave)
|
---|
454 | {
|
---|
455 | /* Configure button: */
|
---|
456 | m_pRadioButtonSave->installEventFilter(this);
|
---|
457 | /* Add into group/layout: */
|
---|
458 | pButtonGroup->addButton(m_pRadioButtonSave);
|
---|
459 | m_pChoiceLayout->addWidget(m_pRadioButtonSave, 1, 1);
|
---|
460 | }
|
---|
461 |
|
---|
462 | /* Create 'shutdown' icon label: */
|
---|
463 | m_pLabelIconShutdown = new QLabel;
|
---|
464 | if (m_pLabelIconShutdown)
|
---|
465 | {
|
---|
466 | /* Configure label: */
|
---|
467 | m_pLabelIconShutdown->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
468 | /* Add into layout: */
|
---|
469 | m_pChoiceLayout->addWidget(m_pLabelIconShutdown, 2, 0);
|
---|
470 | }
|
---|
471 | /* Create 'shutdown' radio-button: */
|
---|
472 | m_pRadioButtonShutdown = new QRadioButton;
|
---|
473 | if (m_pRadioButtonShutdown)
|
---|
474 | {
|
---|
475 | /* Configure button: */
|
---|
476 | m_pRadioButtonShutdown->installEventFilter(this);
|
---|
477 | /* Add into group/layout: */
|
---|
478 | pButtonGroup->addButton(m_pRadioButtonShutdown);
|
---|
479 | m_pChoiceLayout->addWidget(m_pRadioButtonShutdown, 2, 1);
|
---|
480 | }
|
---|
481 |
|
---|
482 | /* Create 'power-off' icon label: */
|
---|
483 | m_pLabelIconPowerOff = new QLabel;
|
---|
484 | if (m_pLabelIconPowerOff)
|
---|
485 | {
|
---|
486 | /* Configure label: */
|
---|
487 | m_pLabelIconPowerOff->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
488 | /* Add into layout: */
|
---|
489 | m_pChoiceLayout->addWidget(m_pLabelIconPowerOff, 3, 0);
|
---|
490 | }
|
---|
491 | /* Create 'shutdown' radio-button: */
|
---|
492 | m_pRadioButtonPowerOff = new QRadioButton;
|
---|
493 | if (m_pRadioButtonPowerOff)
|
---|
494 | {
|
---|
495 | /* Configure button: */
|
---|
496 | m_pRadioButtonPowerOff->installEventFilter(this);
|
---|
497 | /* Add into group/layout: */
|
---|
498 | pButtonGroup->addButton(m_pRadioButtonPowerOff);
|
---|
499 | m_pChoiceLayout->addWidget(m_pRadioButtonPowerOff, 3, 1);
|
---|
500 | }
|
---|
501 |
|
---|
502 | /* Create 'discard' check-box: */
|
---|
503 | m_pCheckBoxDiscard = new QCheckBox;
|
---|
504 | if (m_pCheckBoxDiscard)
|
---|
505 | {
|
---|
506 | /* Add into layout: */
|
---|
507 | m_pChoiceLayout->addWidget(m_pCheckBoxDiscard, 4, 1);
|
---|
508 | }
|
---|
509 |
|
---|
510 | /* Add into layout: */
|
---|
511 | m_pTopRightLayout->addLayout(m_pChoiceLayout);
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | void UIVMCloseDialog::prepareButtonBox()
|
---|
516 | {
|
---|
517 | /* Create button-box: */
|
---|
518 | QIDialogButtonBox *pButtonBox = new QIDialogButtonBox;
|
---|
519 | if (pButtonBox)
|
---|
520 | {
|
---|
521 | /* Configure button-box: */
|
---|
522 | pButtonBox->setStandardButtons( QDialogButtonBox::Cancel
|
---|
523 | | QDialogButtonBox::Help
|
---|
524 | | QDialogButtonBox::NoButton
|
---|
525 | | QDialogButtonBox::Ok);
|
---|
526 | connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIVMCloseDialog::accept);
|
---|
527 | connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIVMCloseDialog::reject);
|
---|
528 | uiCommon().setHelpKeyword(pButtonBox->button(QIDialogButtonBox::Help), "intro-save-machine-state");
|
---|
529 | connect(pButtonBox->button(QIDialogButtonBox::Help), &QPushButton::pressed,
|
---|
530 | pButtonBox, &QIDialogButtonBox::sltHandleHelpRequest);
|
---|
531 | pButtonBox->button(QIDialogButtonBox::Help)->setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
|
---|
532 |
|
---|
533 | /* Add into layout: */
|
---|
534 | m_pMainLayout->addWidget(pButtonBox);
|
---|
535 | }
|
---|
536 | }
|
---|
537 |
|
---|
538 | void UIVMCloseDialog::configure()
|
---|
539 | {
|
---|
540 | /* Get actual machine-state: */
|
---|
541 | KMachineState enmActualState = KMachineState_Null;
|
---|
542 | m_pMachine->acquireLiveMachineState(enmActualState);
|
---|
543 |
|
---|
544 | /* Check which close-actions are resticted: */
|
---|
545 | bool fIsDetachAllowed = uiCommon().isSeparateProcess() && !(m_restictedCloseActions & MachineCloseAction_Detach);
|
---|
546 | bool fIsStateSavingAllowed = !(m_restictedCloseActions & MachineCloseAction_SaveState);
|
---|
547 | bool fIsACPIShutdownAllowed = !(m_restictedCloseActions & MachineCloseAction_Shutdown);
|
---|
548 | bool fIsPowerOffAllowed = !(m_restictedCloseActions & MachineCloseAction_PowerOff);
|
---|
549 | bool fIsPowerOffAndRestoreAllowed = fIsPowerOffAllowed && !(m_restictedCloseActions & MachineCloseAction_PowerOff_RestoringSnapshot);
|
---|
550 |
|
---|
551 | /* Make 'Detach' button visible/hidden depending on restriction: */
|
---|
552 | setButtonVisibleDetach(fIsDetachAllowed);
|
---|
553 | /* Make 'Detach' button enabled/disabled depending on machine-state: */
|
---|
554 | setButtonEnabledDetach(enmActualState != KMachineState_Stuck);
|
---|
555 |
|
---|
556 | /* Make 'Save state' button visible/hidden depending on restriction: */
|
---|
557 | setButtonVisibleSave(fIsStateSavingAllowed);
|
---|
558 | /* Make 'Save state' button enabled/disabled depending on machine-state: */
|
---|
559 | setButtonEnabledSave(enmActualState != KMachineState_Stuck);
|
---|
560 |
|
---|
561 | /* Make 'Shutdown' button visible/hidden depending on restriction: */
|
---|
562 | setButtonVisibleShutdown(fIsACPIShutdownAllowed);
|
---|
563 | /* Make 'Shutdown' button enabled/disabled depending on console and machine-state: */
|
---|
564 | setButtonEnabledShutdown(m_fIsACPIEnabled && enmActualState != KMachineState_Stuck);
|
---|
565 |
|
---|
566 | /* Make 'Power off' button visible/hidden depending on restriction: */
|
---|
567 | setButtonVisiblePowerOff(fIsPowerOffAllowed);
|
---|
568 | /* Make the Restore Snapshot checkbox visible/hidden depending on snapshot count & restrictions: */
|
---|
569 | ulong uSnapshotCount = 0;
|
---|
570 | m_pMachine->acquireSnapshotCount(uSnapshotCount);
|
---|
571 | setCheckBoxVisibleDiscard(fIsPowerOffAndRestoreAllowed && uSnapshotCount > 0);
|
---|
572 | /* Assign Restore Snapshot checkbox text: */
|
---|
573 | if (uSnapshotCount > 0)
|
---|
574 | {
|
---|
575 | QString strCurrentSnapshotName;
|
---|
576 | m_pMachine->acquireCurrentSnapshotName(strCurrentSnapshotName);
|
---|
577 | m_strDiscardCheckBoxText = strCurrentSnapshotName;
|
---|
578 | }
|
---|
579 |
|
---|
580 | /* Check which radio-button should be initially chosen: */
|
---|
581 | QRadioButton *pRadioButtonToChoose = 0;
|
---|
582 | /* If choosing 'last choice' is possible: */
|
---|
583 | m_enmLastCloseAction = gEDataManager->lastMachineCloseAction(uiCommon().managedVMUuid());
|
---|
584 | if (m_enmLastCloseAction == MachineCloseAction_Detach && fIsDetachAllowed)
|
---|
585 | {
|
---|
586 | pRadioButtonToChoose = m_pRadioButtonDetach;
|
---|
587 | }
|
---|
588 | else if (m_enmLastCloseAction == MachineCloseAction_SaveState && fIsStateSavingAllowed)
|
---|
589 | {
|
---|
590 | pRadioButtonToChoose = m_pRadioButtonSave;
|
---|
591 | }
|
---|
592 | else if (m_enmLastCloseAction == MachineCloseAction_Shutdown && fIsACPIShutdownAllowed && m_fIsACPIEnabled)
|
---|
593 | {
|
---|
594 | pRadioButtonToChoose = m_pRadioButtonShutdown;
|
---|
595 | }
|
---|
596 | else if (m_enmLastCloseAction == MachineCloseAction_PowerOff && fIsPowerOffAllowed)
|
---|
597 | {
|
---|
598 | pRadioButtonToChoose = m_pRadioButtonPowerOff;
|
---|
599 | }
|
---|
600 | else if (m_enmLastCloseAction == MachineCloseAction_PowerOff_RestoringSnapshot && fIsPowerOffAndRestoreAllowed)
|
---|
601 | {
|
---|
602 | pRadioButtonToChoose = m_pRadioButtonPowerOff;
|
---|
603 | }
|
---|
604 | /* Else 'default choice' will be used: */
|
---|
605 | else
|
---|
606 | {
|
---|
607 | if (fIsDetachAllowed)
|
---|
608 | pRadioButtonToChoose = m_pRadioButtonDetach;
|
---|
609 | else if (fIsStateSavingAllowed)
|
---|
610 | pRadioButtonToChoose = m_pRadioButtonSave;
|
---|
611 | else if (fIsACPIShutdownAllowed && m_fIsACPIEnabled)
|
---|
612 | pRadioButtonToChoose = m_pRadioButtonShutdown;
|
---|
613 | else if (fIsPowerOffAllowed)
|
---|
614 | pRadioButtonToChoose = m_pRadioButtonPowerOff;
|
---|
615 | }
|
---|
616 |
|
---|
617 | /* If some radio-button chosen: */
|
---|
618 | if (pRadioButtonToChoose)
|
---|
619 | {
|
---|
620 | /* Check and focus it: */
|
---|
621 | pRadioButtonToChoose->setChecked(true);
|
---|
622 | pRadioButtonToChoose->setFocus();
|
---|
623 | sltUpdateWidgetAvailability();
|
---|
624 | m_fValid = true;
|
---|
625 | }
|
---|
626 | }
|
---|
627 |
|
---|
628 | void UIVMCloseDialog::updatePixmaps()
|
---|
629 | {
|
---|
630 | /* Acquire hints: */
|
---|
631 | const int iMetricSmall = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
---|
632 | const int iMetricLarge = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
|
---|
633 |
|
---|
634 | /* Re-apply pixmap: */
|
---|
635 | const qreal fDevicePixelRatio = windowHandle() ? windowHandle()->devicePixelRatio() : 1;
|
---|
636 | m_pLabelIcon->setPixmap(m_icon.pixmap(QSize(iMetricLarge, iMetricLarge), fDevicePixelRatio));
|
---|
637 |
|
---|
638 | QIcon icon;
|
---|
639 | icon = UIIconPool::iconSet(":/vm_create_shortcut_16px.png");
|
---|
640 | m_pLabelIconDetach->setPixmap(icon.pixmap(QSize(iMetricSmall, iMetricSmall), fDevicePixelRatio));
|
---|
641 | icon = UIIconPool::iconSet(":/vm_save_state_16px.png");
|
---|
642 | m_pLabelIconSave->setPixmap(icon.pixmap(QSize(iMetricSmall, iMetricSmall), fDevicePixelRatio));
|
---|
643 | icon = UIIconPool::iconSet(":/vm_shutdown_16px.png");
|
---|
644 | m_pLabelIconShutdown->setPixmap(icon.pixmap(QSize(iMetricSmall, iMetricSmall), fDevicePixelRatio));
|
---|
645 | icon = UIIconPool::iconSet(":/vm_poweroff_16px.png");
|
---|
646 | m_pLabelIconPowerOff->setPixmap(icon.pixmap(QSize(iMetricSmall, iMetricSmall), fDevicePixelRatio));
|
---|
647 | }
|
---|