VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use