VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.cpp

Last change on this file was 106061, checked in by vboxsync, 4 weeks ago

Copyright year updates by scm.

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