VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIBootFailureDialog.cpp@ 104158

Last change on this file since 104158 was 100896, checked in by vboxsync, 16 months ago

FE/Qt: bugref:10506: Suitable HiDPI icon sets for all dialogs using QWidget::setWindowIcon.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/* $Id: UIBootFailureDialog.cpp 100896 2023-08-17 12:18:19Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIBootTimeErrorDialog 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 <QAction>
30#include <QCheckBox>
31#include <QHeaderView>
32#include <QLabel>
33#include <QMenuBar>
34#include <QVBoxLayout>
35#include <QPushButton>
36
37/* GUI includes: */
38#include "QIDialogButtonBox.h"
39#include "QIToolButton.h"
40#include "QIRichTextLabel.h"
41#include "UIBootFailureDialog.h"
42#include "UICommon.h"
43#include "UIConverter.h"
44#include "UIDesktopWidgetWatchdog.h"
45#include "UIExtraDataManager.h"
46#include "UIFilePathSelector.h"
47#include "UIIconPool.h"
48#include "UIMessageCenter.h"
49#include "UIModalWindowManager.h"
50
51/* COM includes: */
52#include "CMediumAttachment.h"
53#include "CStorageController.h"
54
55UIBootFailureDialog::UIBootFailureDialog(QWidget *pParent)
56 : QIWithRetranslateUI<QIMainDialog>(pParent)
57 , m_pParent(pParent)
58 , m_pCentralWidget(0)
59 , m_pMainLayout(0)
60 , m_pButtonBox(0)
61 , m_pCloseButton(0)
62 , m_pResetButton(0)
63 , m_pLabel(0)
64 , m_pBootImageSelector(0)
65 , m_pBootImageLabel(0)
66 , m_pIconLabel(0)
67 , m_pSuppressDialogCheckBox(0)
68{
69 configure();
70}
71
72UIBootFailureDialog::~UIBootFailureDialog()
73{
74 if (m_pSuppressDialogCheckBox && m_pSuppressDialogCheckBox->isChecked())
75 {
76 QStringList suppressedMessageList = gEDataManager->suppressedMessages();
77 suppressedMessageList << gpConverter->toInternalString(UIExtraDataMetaDefs::DialogType_BootFailure);
78 gEDataManager->setSuppressedMessages(suppressedMessageList);
79 }
80}
81
82QString UIBootFailureDialog::bootMediumPath() const
83{
84 if (!m_pBootImageSelector)
85 return QString();
86 return m_pBootImageSelector->path();
87}
88
89void UIBootFailureDialog::retranslateUi()
90{
91 if (m_pCloseButton)
92 {
93 m_pCloseButton->setText(tr("&Cancel"));
94 m_pCloseButton->setToolTip(tr("Closes this dialog without resetting the guest or mounting a medium"));
95 }
96 if (m_pResetButton)
97 {
98 m_pResetButton->setText(tr("&Mount and Retry Boot"));
99 m_pResetButton->setToolTip(tr("Mounts the selected ISO if any and reboots the vm"));
100 }
101
102 if (m_pLabel)
103 m_pLabel->setText(tr("The virtual machine failed to boot. That might be caused by a missing operating system "
104 "or misconfigured boot order. Mounting an operating system install DVD might solve this problem. "
105 "Selecting an ISO file will attempt to mount it after the dialog is closed."));
106
107 if (m_pBootImageLabel)
108 m_pBootImageLabel->setText(tr("DVD:"));
109 if (m_pSuppressDialogCheckBox)
110 {
111 m_pSuppressDialogCheckBox->setText(tr("Do not show this dialog again"));
112 m_pSuppressDialogCheckBox->setToolTip(tr("When checked this dialog will not be shown again."));
113 }
114 if (m_pBootImageSelector)
115 m_pBootImageSelector->setToolTip(tr("Holds the path of the ISO to be attached to machine as boot medium."));
116
117}
118
119void UIBootFailureDialog::configure()
120{
121#ifndef VBOX_WS_MAC
122 /* Assign window icon: */
123 setWindowIcon(UIIconPool::iconSetFull(":/media_manager_32px.png", ":/media_manager_16px.png"));
124#endif
125
126 setTitle();
127 prepareWidgets();
128 prepareConnections();
129}
130
131void UIBootFailureDialog::prepareConnections()
132{
133 if (m_pCloseButton)
134 connect(m_pCloseButton, &QPushButton::clicked, this, &UIBootFailureDialog::sltCancel);
135 if (m_pResetButton)
136 connect(m_pResetButton, &QPushButton::clicked, this, &UIBootFailureDialog::sltReset);
137}
138
139void UIBootFailureDialog::prepareWidgets()
140{
141 m_pCentralWidget = new QWidget;
142 if (!m_pCentralWidget)
143 return;
144 setCentralWidget(m_pCentralWidget);
145
146 m_pMainLayout = new QVBoxLayout;
147 m_pCentralWidget->setLayout(m_pMainLayout);
148
149 if (!m_pMainLayout || !menuBar())
150 return;
151
152 QHBoxLayout *pTopLayout = new QHBoxLayout;
153 pTopLayout->setContentsMargins(0, 0, 0, 0);
154
155 m_pIconLabel = new QLabel;
156 if (m_pIconLabel)
157 {
158 m_pIconLabel->setPixmap(iconPixmap());
159 m_pIconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
160 pTopLayout->addWidget(m_pIconLabel, Qt::AlignTop | Qt::AlignCenter);
161 }
162
163 m_pLabel = new QIRichTextLabel;
164 if (m_pLabel)
165 pTopLayout->addWidget(m_pLabel);
166
167 QHBoxLayout *pSelectorLayout = new QHBoxLayout;
168 pSelectorLayout->setContentsMargins(0, 0, 0, 0);
169 m_pBootImageLabel = new QLabel;
170
171 if (m_pBootImageLabel)
172 {
173 pSelectorLayout->addWidget(m_pBootImageLabel);
174 m_pBootImageLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
175
176 }
177
178 m_pBootImageSelector = new UIFilePathSelector;
179 if (m_pBootImageSelector)
180 {
181 m_pBootImageSelector->setMode(UIFilePathSelector::Mode_File_Open);
182 m_pBootImageSelector->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
183 m_pBootImageSelector->setFileDialogFilters("ISO Images(*.iso *.ISO)");
184 m_pBootImageSelector->setResetEnabled(false);
185 m_pBootImageSelector->setInitialPath(uiCommon().defaultFolderPathForType(UIMediumDeviceType_DVD));
186 m_pBootImageSelector->setRecentMediaListType(UIMediumDeviceType_DVD);
187 if (m_pBootImageLabel)
188 m_pBootImageLabel->setBuddy(m_pBootImageSelector);
189 pSelectorLayout->addWidget(m_pBootImageSelector);
190 connect(m_pBootImageSelector, &UIFilePathSelector::pathChanged,
191 this, &UIBootFailureDialog::sltFileSelectorPathChanged);
192 }
193
194 m_pMainLayout->addLayout(pTopLayout);
195 m_pMainLayout->addLayout(pSelectorLayout);
196
197 m_pSuppressDialogCheckBox = new QCheckBox;
198 if (m_pSuppressDialogCheckBox)
199 m_pMainLayout->addWidget(m_pSuppressDialogCheckBox);
200
201 m_pButtonBox = new QIDialogButtonBox;
202 if (m_pButtonBox)
203 {
204 m_pCloseButton = m_pButtonBox->addButton(QString(), QDialogButtonBox::RejectRole);
205 m_pResetButton = m_pButtonBox->addButton(QString(), QDialogButtonBox::ActionRole);
206 m_pCloseButton->setShortcut(Qt::Key_Escape);
207
208 m_pMainLayout->addWidget(m_pButtonBox);
209 }
210
211 m_pMainLayout->addStretch();
212 retranslateUi();
213}
214
215void UIBootFailureDialog::sltCancel()
216{
217 done(static_cast<int>(ReturnCode_Close));
218}
219
220void UIBootFailureDialog::sltReset()
221{
222 done(static_cast<int>(ReturnCode_Reset));
223}
224
225void UIBootFailureDialog::showEvent(QShowEvent *pEvent)
226{
227 if (m_pParent)
228 gpDesktop->centerWidget(this, m_pParent, false);
229 QIWithRetranslateUI<QIMainDialog>::showEvent(pEvent);
230
231}
232
233void UIBootFailureDialog::setTitle()
234{
235}
236
237void UIBootFailureDialog::sltFileSelectorPathChanged(const QString &strPath)
238{
239 Q_UNUSED(strPath);
240 bool fISOValid = checkISOImage();
241 if (m_pBootImageSelector)
242 {
243 m_pBootImageSelector->mark(!fISOValid, tr("The selected path is invalid."));
244 }
245 if (m_pResetButton)
246 m_pResetButton->setEnabled(fISOValid);
247}
248
249QPixmap UIBootFailureDialog::iconPixmap()
250{
251 QIcon icon = UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_MessageBoxWarning);
252 if (icon.isNull())
253 return QPixmap();
254 int iSize = QApplication::style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, 0);
255 return icon.pixmap(iSize, iSize);
256}
257
258bool UIBootFailureDialog::checkISOImage() const
259{
260 AssertReturn(m_pBootImageSelector, true);
261 if (m_pBootImageSelector->path().isEmpty())
262 return true;
263 QFileInfo fileInfo(m_pBootImageSelector->path());
264 if (!fileInfo.exists() || !fileInfo.isReadable())
265 return false;
266 return true;
267}
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