VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

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