VirtualBox

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

Last change on this file since 100064 was 99946, checked in by vboxsync, 13 months ago

FE/Qt: bugref:10451. Refactoring the code which kicks of the help browser and navigates to the selected keyword in case it is there.

  • 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 99946 2023-05-24 06:53:04Z 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
39/* GUI includes: */
40#include "QIDialogButtonBox.h"
41#include "UICommon.h"
42#include "UIConverter.h"
43#include "UIExtraDataManager.h"
44#include "UIHelpBrowserDialog.h"
45#include "UIIconPool.h"
46#include "UIMachine.h"
47#include "UIMessageCenter.h"
48#include "UIVMCloseDialog.h"
49
50
51UIVMCloseDialog::UIVMCloseDialog(QWidget *pParent, UIMachine *pMachine,
52 bool fIsACPIEnabled, MachineCloseAction restictedCloseActions)
53 : QIWithRetranslateUI<QIDialog>(pParent)
54 , m_pMachine(pMachine)
55 , m_fIsACPIEnabled(fIsACPIEnabled)
56 , m_restictedCloseActions(restictedCloseActions)
57 , m_fValid(false)
58 , m_pMainLayout(0)
59 , m_pTopLayout(0)
60 , m_pTopLeftLayout(0)
61 , m_pTopRightLayout(0)
62 , m_pChoiceLayout(0)
63 , m_pLabelIcon(0), m_pLabelText(0)
64 , m_pLabelIconDetach(0), m_pRadioButtonDetach(0)
65 , m_pLabelIconSave(0), m_pRadioButtonSave(0)
66 , m_pLabelIconShutdown(0), m_pRadioButtonShutdown(0)
67 , m_pLabelIconPowerOff(0), m_pRadioButtonPowerOff(0)
68 , m_pCheckBoxDiscard(0)
69 , m_enmLastCloseAction(MachineCloseAction_Invalid)
70{
71 prepare();
72}
73
74void UIVMCloseDialog::setIcon(const QIcon &icon)
75{
76 /* Make sure icon is valid: */
77 if (icon.isNull())
78 return;
79
80 /* Remember it: */
81 m_icon = icon;
82 /* Update pixmaps: */
83 updatePixmaps();
84}
85
86bool UIVMCloseDialog::eventFilter(QObject *pObject, QEvent *pEvent)
87{
88 /* Handle events realted to our radio-buttons only: */
89 if ( pObject != m_pRadioButtonDetach
90 && pObject != m_pRadioButtonSave
91 && pObject != m_pRadioButtonShutdown
92 && pObject != m_pRadioButtonPowerOff)
93 return QIWithRetranslateUI<QIDialog>::eventFilter(pObject, pEvent);
94
95 /* For now we are interested in double-click events only: */
96 if (pEvent->type() == QEvent::MouseButtonDblClick)
97 {
98 /* Make sure it's one of the radio-buttons
99 * which has this event-filter installed: */
100 if (qobject_cast<QRadioButton*>(pObject))
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
108 /* Call to base-class: */
109 return QIWithRetranslateUI<QIDialog>::eventFilter(pObject, pEvent);
110}
111
112bool UIVMCloseDialog::event(QEvent *pEvent)
113{
114 /* Pre-process in base-class: */
115 const bool fResult = QIWithRetranslateUI<QIDialog>::event(pEvent);
116
117 /* Post-process know event types: */
118 switch (pEvent->type())
119 {
120 case QEvent::ScreenChangeInternal:
121 {
122 /* Update pixmaps: */
123 updatePixmaps();
124 break;
125 }
126 default:
127 break;
128 }
129
130 /* Return pre-processed result: */
131 return fResult;
132}
133
134void UIVMCloseDialog::showEvent(QShowEvent *pEvent)
135{
136 /* Update pixmaps: */
137 updatePixmaps();
138
139 /* Call to base-class: */
140 QIWithRetranslateUI<QIDialog>::showEvent(pEvent);
141}
142
143void UIVMCloseDialog::retranslateUi()
144{
145 /* Translate title: */
146 setWindowTitle(tr("Close Virtual Machine"));
147
148 /* Translate text label: */
149 m_pLabelText->setText(tr("You want to:"));
150
151 /* Translate radio-buttons: */
152 m_pRadioButtonDetach->setText(tr("&Continue running in the background"));
153 m_pRadioButtonDetach->setWhatsThis(tr("<p>Close the virtual machine windows but keep the virtual machine running.</p>"
154 "<p>You can use the VirtualBox Manager to return to running the virtual machine "
155 "in a window.</p>"));
156 m_pRadioButtonSave->setText(tr("&Save the machine state"));
157 m_pRadioButtonSave->setWhatsThis(tr("<p>Saves the current execution state of the virtual machine to the physical hard disk "
158 "of the host PC.</p>"
159 "<p>Next time this machine is started, it will be restored from the saved state and "
160 "continue execution from the same place you saved it at, which will let you continue "
161 "your work immediately.</p>"
162 "<p>Note that saving the machine state may take a long time, depending on the guest "
163 "operating system type and the amount of memory you assigned to the virtual "
164 "machine.</p>"));
165 m_pRadioButtonShutdown->setText(tr("S&end the shutdown signal"));
166 m_pRadioButtonShutdown->setWhatsThis(tr("<p>Sends the ACPI Power Button press event to the virtual machine.</p>"
167 "<p>Normally, the guest operating system running inside the virtual machine will "
168 "detect this event and perform a clean shutdown procedure. This is a recommended "
169 "way to turn off the virtual machine because all applications running inside it "
170 "will get a chance to save their data and state.</p>"
171 "<p>If the machine doesn't respond to this action then the guest operating system "
172 "may be misconfigured or doesn't understand ACPI Power Button events at all. In "
173 "this case you should select the <b>Power off the machine</b> action to stop "
174 "virtual machine execution.</p>"));
175 m_pRadioButtonPowerOff->setText(tr("&Power off the machine"));
176 m_pRadioButtonPowerOff->setWhatsThis(tr("<p>Turns off the virtual machine.</p>"
177 "<p>Note that this action will stop machine execution immediately so that the guest "
178 "operating system running inside it will not be able to perform a clean shutdown "
179 "procedure which may result in <i>data loss</i> inside the virtual machine. "
180 "Selecting this action is recommended only if the virtual machine does not respond "
181 "to the <b>Send the shutdown signal</b> action.</p>"));
182
183 /* Translate check-box: */
184 m_pCheckBoxDiscard->setText(tr("&Restore current snapshot '%1'").arg(m_strDiscardCheckBoxText));
185 m_pCheckBoxDiscard->setWhatsThis(tr("<p>When checked, the machine will be returned to the state stored in the current "
186 "snapshot after it is turned off. This is useful if you are sure that you want to "
187 "discard the results of your last sessions and start again at that snapshot.</p>"));
188}
189
190void UIVMCloseDialog::sltUpdateWidgetAvailability()
191{
192 /* Discard option should be enabled only on power-off action: */
193 m_pCheckBoxDiscard->setEnabled(m_pRadioButtonPowerOff->isChecked());
194}
195
196void UIVMCloseDialog::accept()
197{
198 /* Calculate result: */
199 if (m_pRadioButtonDetach->isChecked())
200 setResult(MachineCloseAction_Detach);
201 else if (m_pRadioButtonSave->isChecked())
202 setResult(MachineCloseAction_SaveState);
203 else if (m_pRadioButtonShutdown->isChecked())
204 setResult(MachineCloseAction_Shutdown);
205 else if (m_pRadioButtonPowerOff->isChecked())
206 {
207 if (!m_pCheckBoxDiscard->isChecked() || !m_pCheckBoxDiscard->isVisible())
208 setResult(MachineCloseAction_PowerOff);
209 else
210 setResult(MachineCloseAction_PowerOff_RestoringSnapshot);
211 }
212
213 /* Memorize the last user's choice for the given VM: */
214 MachineCloseAction newCloseAction = static_cast<MachineCloseAction>(result());
215 /* But make sure 'Shutdown' is preserved if temporary unavailable: */
216 if (newCloseAction == MachineCloseAction_PowerOff &&
217 m_enmLastCloseAction == MachineCloseAction_Shutdown && !m_fIsACPIEnabled)
218 newCloseAction = MachineCloseAction_Shutdown;
219 gEDataManager->setLastMachineCloseAction(newCloseAction, uiCommon().managedVMUuid());
220
221 /* Hide the dialog: */
222 hide();
223}
224
225void UIVMCloseDialog::setButtonEnabledDetach(bool fEnabled)
226{
227 m_pLabelIconDetach->setEnabled(fEnabled);
228 m_pRadioButtonDetach->setEnabled(fEnabled);
229}
230
231void UIVMCloseDialog::setButtonVisibleDetach(bool fVisible)
232{
233 m_pLabelIconDetach->setVisible(fVisible);
234 m_pRadioButtonDetach->setVisible(fVisible);
235}
236
237void UIVMCloseDialog::setButtonEnabledSave(bool fEnabled)
238{
239 m_pLabelIconSave->setEnabled(fEnabled);
240 m_pRadioButtonSave->setEnabled(fEnabled);
241}
242
243void UIVMCloseDialog::setButtonVisibleSave(bool fVisible)
244{
245 m_pLabelIconSave->setVisible(fVisible);
246 m_pRadioButtonSave->setVisible(fVisible);
247}
248
249void UIVMCloseDialog::setButtonEnabledShutdown(bool fEnabled)
250{
251 m_pLabelIconShutdown->setEnabled(fEnabled);
252 m_pRadioButtonShutdown->setEnabled(fEnabled);
253}
254
255void UIVMCloseDialog::setButtonVisibleShutdown(bool fVisible)
256{
257 m_pLabelIconShutdown->setVisible(fVisible);
258 m_pRadioButtonShutdown->setVisible(fVisible);
259}
260
261void UIVMCloseDialog::setButtonEnabledPowerOff(bool fEnabled)
262{
263 m_pLabelIconPowerOff->setEnabled(fEnabled);
264 m_pRadioButtonPowerOff->setEnabled(fEnabled);
265}
266
267void UIVMCloseDialog::setButtonVisiblePowerOff(bool fVisible)
268{
269 m_pLabelIconPowerOff->setVisible(fVisible);
270 m_pRadioButtonPowerOff->setVisible(fVisible);
271}
272
273void UIVMCloseDialog::setCheckBoxVisibleDiscard(bool fVisible)
274{
275 m_pCheckBoxDiscard->setVisible(fVisible);
276}
277
278void UIVMCloseDialog::prepare()
279{
280 /* Choose default dialog icon: */
281 m_icon = UIIconPool::iconSet(":/os_unknown.png");
282
283 /* Prepare size-grip token: */
284 setSizeGripEnabled(false);
285
286 /* Prepare main layout: */
287 prepareMainLayout();
288
289 /* Update pixmaps: */
290 updatePixmaps();
291
292 /* Configure: */
293 configure();
294
295 /* Apply language settings: */
296 retranslateUi();
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 {
418 connect(pButtonGroup, static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked),
419 this, &UIVMCloseDialog::sltUpdateWidgetAvailability);
420 }
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
515void 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(QKeySequence::HelpContents);
532
533 /* Add into layout: */
534 m_pMainLayout->addWidget(pButtonBox);
535 }
536}
537
538void 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
628void 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 m_pLabelIcon->setPixmap(m_icon.pixmap(windowHandle(), QSize(iMetricLarge, iMetricLarge)));
636
637 QIcon icon;
638 icon = UIIconPool::iconSet(":/vm_create_shortcut_16px.png");
639 m_pLabelIconDetach->setPixmap(icon.pixmap(windowHandle(), QSize(iMetricSmall, iMetricSmall)));
640 icon = UIIconPool::iconSet(":/vm_save_state_16px.png");
641 m_pLabelIconSave->setPixmap(icon.pixmap(windowHandle(), QSize(iMetricSmall, iMetricSmall)));
642 icon = UIIconPool::iconSet(":/vm_shutdown_16px.png");
643 m_pLabelIconShutdown->setPixmap(icon.pixmap(windowHandle(), QSize(iMetricSmall, iMetricSmall)));
644 icon = UIIconPool::iconSet(":/vm_poweroff_16px.png");
645 m_pLabelIconPowerOff->setPixmap(icon.pixmap(windowHandle(), QSize(iMetricSmall, iMetricSmall)));
646}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use