VirtualBox

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

Last change on this file was 106282, checked in by vboxsync, 8 weeks ago

FE/Qt: Help browser: A bit of include cleanups.

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