Changeset 91656 in vbox
- Timestamp:
- Oct 11, 2021 8:44:14 AM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
- 2 copied
-
Makefile.kmk (modified) (2 diffs)
-
src/runtime/UIBootTimeErrorDialog.cpp (copied) (copied from trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp ) (4 diffs)
-
src/runtime/UIBootTimeErrorDialog.h (copied) (copied from trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h ) (6 diffs)
-
src/runtime/UIMachineLogic.cpp (modified) (5 diffs)
-
src/runtime/UIMachineLogic.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r91416 r91656 695 695 VirtualBoxVM_QT_MOCHDRS = \ 696 696 src/globals/UIStarter.h \ 697 src/runtime/UIBootTimeErrorDialog.h \ 697 698 src/runtime/UIConsoleEventHandler.h \ 698 699 src/runtime/UIFrameBuffer.h \ … … 1219 1220 src/main.cpp \ 1220 1221 src/globals/UIStarter.cpp \ 1222 src/runtime/UIBootTimeErrorDialog.cpp \ 1221 1223 src/runtime/UIConsoleEventHandler.cpp \ 1222 1224 src/runtime/UIFrameBuffer.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIBootTimeErrorDialog.cpp
r91606 r91656 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI MediumSelectorclass implementation.3 * VBox Qt GUI - UIBootTimeErrorDialog class implementation. 4 4 */ 5 5 … … 19 19 #include <QAction> 20 20 #include <QHeaderView> 21 #include <QLabel> 21 22 #include <QMenuBar> 22 23 #include <QVBoxLayout> … … 25 26 /* GUI includes: */ 26 27 #include "QIDialogButtonBox.h" 27 #include "QIFileDialog.h"28 #include "QIMessageBox.h"29 #include "QITabWidget.h"30 28 #include "QIToolButton.h" 29 #include "QIRichTextLabel.h" 30 31 31 #include "UICommon.h" 32 32 #include "UIDesktopWidgetWatchdog.h" 33 #include "UIExtraDataManager.h" 34 #include "UIMediumSearchWidget.h" 35 #include "UIMediumSelector.h" 33 34 #include "UIFilePathSelector.h" 35 #include "UIBootTimeErrorDialog.h" 36 37 #include "UIIconPool.h" 38 #include "UIModalWindowManager.h" 36 39 #include "UIMessageCenter.h" 37 #include "UIIconPool.h" 38 #include "UIMedium.h" 39 #include "UIMediumItem.h" 40 #include "QIToolBar.h" 41 42 /* COM includes: */ 43 #include "COMEnums.h" 44 #include "CMachine.h" 40 41 45 42 #include "CMediumAttachment.h" 46 #include "CMediumFormat.h"47 43 #include "CStorageController.h" 48 #include "CSystemProperties.h" 49 50 #ifdef VBOX_WS_MAC 51 # include "UIWindowMenuManager.h" 52 #endif /* VBOX_WS_MAC */ 53 54 55 UIMediumSelector::UIMediumSelector(const QUuid &uCurrentMediumId, UIMediumDeviceType enmMediumType, const QString &machineName, 56 const QString &machineSettingsFilePath, const QString &strMachineGuestOSTypeId, 57 const QUuid &uMachineID, QWidget *pParent) 44 45 UIBootTimeErrorDialog::UIBootTimeErrorDialog(QWidget *pParent, const CMachine &comMachine) 58 46 :QIWithRetranslateUI<QIMainDialog>(pParent) 47 , m_pParent(pParent) 59 48 , m_pCentralWidget(0) 60 49 , m_pMainLayout(0) 61 , m_pTreeWidget(0)62 , m_enmMediumType(enmMediumType)63 50 , m_pButtonBox(0) 64 , m_pCancelButton(0) 65 , m_pChooseButton(0) 66 , m_pLeaveEmptyButton(0) 67 , m_pMainMenu(0) 68 , m_pToolBar(0) 69 , m_pActionAdd(0) 70 , m_pActionCreate(0) 71 , m_pActionRefresh(0) 72 , m_pAttachedSubTreeRoot(0) 73 , m_pNotAttachedSubTreeRoot(0) 74 , m_pParent(pParent) 75 , m_pSearchWidget(0) 76 , m_iCurrentShownIndex(0) 77 , m_strMachineFolder(machineSettingsFilePath) 78 , m_strMachineName(machineName) 79 , m_strMachineGuestOSTypeId(strMachineGuestOSTypeId) 80 , m_uMachineID(uMachineID) 81 { 82 /* Start full medium-enumeration (if necessary): */ 83 if (!uiCommon().isFullMediumEnumerationRequested()) 84 uiCommon().enumerateMedia(); 51 , m_pCloseButton(0) 52 , m_pResetButton(0) 53 , m_pLabel(0) 54 , m_pBootImageSelector(0) 55 , m_pBootImageLabel(0) 56 , m_comMachine(comMachine) 57 { 85 58 configure(); 86 finalize(); 87 selectMedium(uCurrentMediumId); 88 } 89 90 void UIMediumSelector::setEnableCreateAction(bool fEnable) 91 { 92 if (!m_pActionCreate) 93 return; 94 m_pActionCreate->setEnabled(fEnable); 95 m_pActionCreate->setVisible(fEnable); 96 } 97 98 QList<QUuid> UIMediumSelector::selectedMediumIds() const 99 { 100 QList<QUuid> selectedIds; 101 if (!m_pTreeWidget) 102 return selectedIds; 103 QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems(); 104 for (int i = 0; i < selectedItems.size(); ++i) 105 { 106 UIMediumItem *item = dynamic_cast<UIMediumItem*>(selectedItems.at(i)); 107 if (item) 108 selectedIds.push_back(item->medium().id()); 109 } 110 return selectedIds; 111 } 112 113 void UIMediumSelector::retranslateUi() 114 { 115 if (m_pMainMenu) 116 m_pMainMenu->setTitle(tr("&Medium")); 117 118 if (m_pActionAdd) 119 { 120 m_pActionAdd->setText(tr("&Add...")); 121 m_pActionAdd->setToolTip(tr("Add Disk Image")); 122 m_pActionAdd->setStatusTip(tr("Add existing disk image file")); 123 } 124 125 if (m_pActionCreate) 126 { 127 m_pActionCreate->setText(tr("&Create...")); 128 m_pActionCreate->setToolTip(tr("Create Disk Image")); 129 m_pActionCreate->setStatusTip(tr("Create new disk image file")); 130 } 131 132 if (m_pActionRefresh) 133 { 134 m_pActionRefresh->setText(tr("&Refresh")); 135 m_pActionRefresh->setToolTip(tr("Refresh Disk Image Files (%1)").arg(m_pActionRefresh->shortcut().toString())); 136 m_pActionRefresh->setStatusTip(tr("Refresh the list of disk image files")); 137 } 138 139 if (m_pCancelButton) 140 m_pCancelButton->setText(tr("&Cancel")); 141 if (m_pLeaveEmptyButton) 142 m_pLeaveEmptyButton->setText(tr("Leave &Empty")); 143 if (m_pChooseButton) 144 m_pChooseButton->setText(tr("C&hoose")); 145 146 if (m_pTreeWidget) 147 { 148 m_pTreeWidget->headerItem()->setText(0, tr("Name")); 149 m_pTreeWidget->headerItem()->setText(1, tr("Virtual Size")); 150 m_pTreeWidget->headerItem()->setText(2, tr("Actual Size")); 151 } 152 } 153 154 void UIMediumSelector::configure() 155 { 156 /* Apply window icons: */ 59 } 60 61 QString UIBootTimeErrorDialog::bootMediumPath() const 62 { 63 if (!m_pBootImageSelector) 64 return QString(); 65 return m_pBootImageSelector->path(); 66 } 67 68 void UIBootTimeErrorDialog::retranslateUi() 69 { 70 if (m_pCloseButton) 71 m_pCloseButton->setText(tr("&Close")); 72 if (m_pResetButton) 73 m_pResetButton->setText(tr("&Reset")); 74 75 if (m_pLabel) 76 m_pLabel->setText(tr("The virtual machine failed to boot. That might be caused by a missing operating system " 77 "or misconfigured boot order. Mounting an operation install DVD might solve this problem. " 78 "Selecting an ISO file will attemt to mount it immediately to the guest machine.")); 79 if (m_pBootImageLabel) 80 m_pBootImageLabel->setText(tr("Boot DVD:")); 81 } 82 83 void UIBootTimeErrorDialog::configure() 84 { 157 85 setWindowIcon(UIIconPool::iconSetFull(":/media_manager_32px.png", ":/media_manager_16px.png")); 158 86 setTitle(); 159 87 prepareWidgets(); 160 prepareActions();161 prepareMenuAndToolBar();162 88 prepareConnections(); 163 89 } 164 90 165 void UIMediumSelector::prepareActions() 166 { 167 QString strPrefix("hd"); 168 switch (m_enmMediumType) 169 { 170 case UIMediumDeviceType_DVD: 171 strPrefix = "cd"; 172 break; 173 case UIMediumDeviceType_Floppy: 174 strPrefix = "fd"; 175 break; 176 case UIMediumDeviceType_HardDisk: 177 case UIMediumDeviceType_All: 178 case UIMediumDeviceType_Invalid: 179 default: 180 strPrefix = "hd"; 181 break; 182 } 183 184 m_pActionAdd = new QAction(this); 185 if (m_pActionAdd) 186 { 187 /* Configure add-action: */ 188 m_pActionAdd->setShortcut(QKeySequence("")); 189 190 m_pActionAdd->setIcon(UIIconPool::iconSetFull(QString(":/%1_add_32px.png").arg(strPrefix), 191 QString(":/%1_add_16px.png").arg(strPrefix), 192 QString(":/%1_add_disabled_32px.png").arg(strPrefix), 193 QString(":/%1_add_disabled_16px.png").arg(strPrefix))); 194 } 195 196 m_pActionCreate = new QAction(this); 197 if (m_pActionCreate) 198 { 199 m_pActionCreate->setShortcut(QKeySequence("")); 200 m_pActionCreate->setIcon(UIIconPool::iconSetFull(QString(":/%1_create_32px.png").arg(strPrefix), 201 QString(":/%1_create_16px.png").arg(strPrefix), 202 QString(":/%1_create_disabled_32px.png").arg(strPrefix), 203 QString(":/%1_create_disabled_16px.png").arg(strPrefix))); 204 } 205 206 m_pActionRefresh = new QAction(this); 207 if (m_pActionRefresh) 208 { 209 m_pActionRefresh->setShortcut(QKeySequence()); 210 if (m_pActionRefresh && m_pActionRefresh->icon().isNull()) 211 m_pActionRefresh->setIcon(UIIconPool::iconSetFull(":/refresh_32px.png", ":/refresh_16px.png", 212 ":/refresh_disabled_32px.png", ":/refresh_disabled_16px.png")); 213 } 214 } 215 216 void UIMediumSelector::prepareMenuAndToolBar() 217 { 218 if (!m_pMainMenu || !m_pToolBar) 219 return; 220 221 m_pMainMenu->addAction(m_pActionAdd); 222 m_pMainMenu->addAction(m_pActionCreate); 223 m_pMainMenu->addSeparator(); 224 m_pMainMenu->addAction(m_pActionRefresh); 225 226 m_pToolBar->addAction(m_pActionAdd); 227 if (!(gEDataManager->restrictedDialogTypes(m_uMachineID) & UIExtraDataMetaDefs::DialogType_VISOCreator)) 228 m_pToolBar->addAction(m_pActionCreate); 229 m_pToolBar->addSeparator(); 230 m_pToolBar->addAction(m_pActionRefresh); 231 } 232 233 void UIMediumSelector::prepareConnections() 234 { 235 /* Configure medium-enumeration connections: */ 236 connect(&uiCommon(), &UICommon::sigMediumCreated, 237 this, &UIMediumSelector::sltHandleMediumCreated); 238 connect(&uiCommon(), &UICommon::sigMediumEnumerationStarted, 239 this, &UIMediumSelector::sltHandleMediumEnumerationStart); 240 connect(&uiCommon(), &UICommon::sigMediumEnumerated, 241 this, &UIMediumSelector::sltHandleMediumEnumerated); 242 connect(&uiCommon(), &UICommon::sigMediumEnumerationFinished, 243 this, &UIMediumSelector::sltHandleMediumEnumerationFinish); 244 if (m_pActionAdd) 245 connect(m_pActionAdd, &QAction::triggered, this, &UIMediumSelector::sltAddMedium); 246 if (m_pActionCreate) 247 connect(m_pActionCreate, &QAction::triggered, this, &UIMediumSelector::sltCreateMedium); 248 if (m_pActionRefresh) 249 connect(m_pActionRefresh, &QAction::triggered, this, &UIMediumSelector::sltHandleRefresh); 250 251 if (m_pTreeWidget) 252 { 253 connect(m_pTreeWidget, &QITreeWidget::itemSelectionChanged, this, &UIMediumSelector::sltHandleItemSelectionChanged); 254 connect(m_pTreeWidget, &QITreeWidget::itemDoubleClicked, this, &UIMediumSelector::sltHandleTreeWidgetDoubleClick); 255 connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested, this, &UIMediumSelector::sltHandleTreeContextMenuRequest); 256 } 257 258 if (m_pCancelButton) 259 connect(m_pCancelButton, &QPushButton::clicked, this, &UIMediumSelector::sltButtonCancel); 260 if (m_pChooseButton) 261 connect(m_pChooseButton, &QPushButton::clicked, this, &UIMediumSelector::sltButtonChoose); 262 if (m_pLeaveEmptyButton) 263 connect(m_pLeaveEmptyButton, &QPushButton::clicked, this, &UIMediumSelector::sltButtonLeaveEmpty); 264 265 if (m_pSearchWidget) 266 { 267 connect(m_pSearchWidget, &UIMediumSearchWidget::sigPerformSearch, 268 this, &UIMediumSelector::sltHandlePerformSearch); 269 } 270 } 271 272 UIMediumItem* UIMediumSelector::addTreeItem(const UIMedium &medium, QITreeWidgetItem *pParent) 273 { 274 if (!pParent) 275 return 0; 276 switch (m_enmMediumType) 277 { 278 case UIMediumDeviceType_DVD: 279 return new UIMediumItemCD(medium, pParent); 280 break; 281 case UIMediumDeviceType_Floppy: 282 return new UIMediumItemFD(medium, pParent); 283 break; 284 case UIMediumDeviceType_HardDisk: 285 case UIMediumDeviceType_All: 286 case UIMediumDeviceType_Invalid: 287 default: 288 return createHardDiskItem(medium, pParent); 289 break; 290 } 291 } 292 293 UIMediumItem* UIMediumSelector::createHardDiskItem(const UIMedium &medium, QITreeWidgetItem *pParent) 294 { 295 if (medium.medium().isNull()) 296 return 0; 297 if (!m_pTreeWidget) 298 return 0; 299 /* Search the tree to see if we already have the item: */ 300 UIMediumItem *pMediumItem = searchItem(0, medium.id()); 301 if (pMediumItem) 302 return pMediumItem; 303 /* Check if the corresponding medium has a parent */ 304 if (medium.parentID() != UIMedium::nullID()) 305 { 306 UIMediumItem *pParentMediumItem = searchItem(0, medium.parentID()); 307 /* If parent medium-item was not found we create it: */ 308 if (!pParentMediumItem) 309 { 310 /* Make sure corresponding parent medium is already cached! */ 311 UIMedium parentMedium = uiCommon().medium(medium.parentID()); 312 if (parentMedium.isNull()) 313 AssertMsgFailed(("Parent medium with ID={%s} was not found!\n", medium.parentID().toString().toUtf8().constData())); 314 /* Try to create parent medium-item: */ 315 else 316 pParentMediumItem = createHardDiskItem(parentMedium, pParent); 317 } 318 if (pParentMediumItem) 319 { 320 pMediumItem = new UIMediumItemHD(medium, pParentMediumItem); 321 LogRel2(("UIMediumManager: Child hard-disk medium-item with ID={%s} created.\n", medium.id().toString().toUtf8().constData())); 322 } 323 else 324 AssertMsgFailed(("Parent medium with ID={%s} could not be created!\n", medium.parentID().toString().toUtf8().constData())); 325 } 326 327 /* No parents, thus just create item as top-level one: */ 328 else 329 { 330 pMediumItem = new UIMediumItemHD(medium, pParent); 331 LogRel2(("UIMediumManager: Root hard-disk medium-item with ID={%s} created.\n", medium.id().toString().toUtf8().constData())); 332 } 333 return pMediumItem; 334 } 335 336 void UIMediumSelector::restoreSelection(const QList<QUuid> &selectedMediums, QVector<UIMediumItem*> &mediumList) 337 { 338 if (!m_pTreeWidget) 339 return; 340 if (selectedMediums.isEmpty()) 341 { 342 m_pTreeWidget->setCurrentItem(0); 343 return; 344 } 345 bool selected = false; 346 for (int i = 0; i < mediumList.size(); ++i) 347 { 348 if (!mediumList[i]) 349 continue; 350 if (selectedMediums.contains(mediumList[i]->medium().id())) 351 { 352 mediumList[i]->setSelected(true); 353 selected = true; 354 } 355 } 356 357 if (!selected) 358 m_pTreeWidget->setCurrentItem(0); 359 } 360 361 void UIMediumSelector::prepareWidgets() 91 void UIBootTimeErrorDialog::prepareConnections() 92 { 93 if (m_pCloseButton) 94 connect(m_pCloseButton, &QPushButton::clicked, this, &UIBootTimeErrorDialog::sltCancel); 95 if (m_pResetButton) 96 connect(m_pResetButton, &QPushButton::clicked, this, &UIBootTimeErrorDialog::sltReset); 97 } 98 99 void UIBootTimeErrorDialog::prepareWidgets() 362 100 { 363 101 m_pCentralWidget = new QWidget; … … 372 110 return; 373 111 374 m_pMainMenu = menuBar()->addMenu(tr("&Medium")); 375 376 m_pToolBar = new QIToolBar; 377 if (m_pToolBar) 378 { 379 /* Configure toolbar: */ 380 const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize)); 381 m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric)); 382 m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 383 m_pMainLayout->addWidget(m_pToolBar); 384 } 385 386 m_pTreeWidget = new QITreeWidget; 387 if (m_pTreeWidget) 388 { 389 m_pTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); 390 m_pMainLayout->addWidget(m_pTreeWidget); 391 m_pTreeWidget->setAlternatingRowColors(true); 392 int iColumnCount = (m_enmMediumType == UIMediumDeviceType_HardDisk) ? 3 : 2; 393 m_pTreeWidget->setColumnCount(iColumnCount); 394 m_pTreeWidget->setSortingEnabled(true); 395 m_pTreeWidget->sortItems(0, Qt::AscendingOrder); 396 m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); 397 } 398 399 m_pSearchWidget = new UIMediumSearchWidget; 400 if (m_pSearchWidget) 401 { 402 m_pMainLayout->addWidget(m_pSearchWidget); 403 } 404 112 m_pLabel = new QIRichTextLabel; 113 if (m_pLabel) 114 m_pMainLayout->addWidget(m_pLabel); 115 116 QHBoxLayout *pSelectorLayout = new QHBoxLayout; 117 pSelectorLayout->setContentsMargins(0, 0, 0, 0); 118 m_pBootImageLabel = new QLabel; 119 120 if (m_pBootImageLabel) 121 pSelectorLayout->addWidget(m_pBootImageLabel); 122 123 m_pBootImageSelector = new UIFilePathSelector; 124 if (m_pBootImageSelector) 125 { 126 m_pBootImageSelector->setMode(UIFilePathSelector::Mode_File_Open); 127 m_pBootImageSelector->setFileDialogFilters("ISO Images(*.iso *.ISO)"); 128 m_pBootImageSelector->setInitialPath(uiCommon().defaultFolderPathForType(UIMediumDeviceType_DVD)); 129 m_pBootImageSelector->setRecentMediaListType(UIMediumDeviceType_DVD); 130 if (m_pBootImageLabel) 131 m_pBootImageLabel->setBuddy(m_pBootImageSelector); 132 pSelectorLayout->addWidget(m_pBootImageSelector); 133 connect(m_pBootImageSelector, &UIFilePathSelector::pathChanged, 134 this, &UIBootTimeErrorDialog::sltFileSelectorPathChanged); 135 } 136 m_pMainLayout->addLayout(pSelectorLayout); 405 137 m_pButtonBox = new QIDialogButtonBox; 406 138 if (m_pButtonBox) 407 139 { 408 /* Configure button-box: */ 409 m_pCancelButton = m_pButtonBox->addButton(tr("Cancel"), QDialogButtonBox::RejectRole); 410 411 /* Only DVDs and Floppies can be left empty: */ 412 if (m_enmMediumType == UIMediumDeviceType_DVD || m_enmMediumType == UIMediumDeviceType_Floppy) 413 m_pLeaveEmptyButton = m_pButtonBox->addButton(tr("Leave Empty"), QDialogButtonBox::ActionRole); 414 415 m_pChooseButton = m_pButtonBox->addButton(tr("Choose"), QDialogButtonBox::AcceptRole); 416 m_pCancelButton->setShortcut(Qt::Key_Escape); 417 418 /* Add button-box into main layout: */ 140 m_pCloseButton = m_pButtonBox->addButton(QString(), QDialogButtonBox::RejectRole); 141 m_pResetButton = m_pButtonBox->addButton(QString(), QDialogButtonBox::ActionRole); 142 m_pCloseButton->setShortcut(Qt::Key_Escape); 143 419 144 m_pMainLayout->addWidget(m_pButtonBox); 420 145 } 421 422 repopulateTreeWidget(); 423 } 424 425 void UIMediumSelector::sltButtonChoose() 426 { 427 done(static_cast<int>(ReturnCode_Accepted)); 428 } 429 430 void UIMediumSelector::sltButtonCancel() 431 { 432 done(static_cast<int>(ReturnCode_Rejected)); 433 } 434 435 void UIMediumSelector::sltButtonLeaveEmpty() 436 { 437 done(static_cast<int>(ReturnCode_LeftEmpty)); 438 } 439 440 void UIMediumSelector::sltAddMedium() 441 { 442 QUuid uMediumID = uiCommon().openMediumWithFileOpenDialog(m_enmMediumType, this, m_strMachineFolder, true /* fUseLastFolder */); 443 if (uMediumID.isNull()) 444 return; 445 repopulateTreeWidget(); 446 selectMedium(uMediumID); 447 } 448 449 void UIMediumSelector::sltCreateMedium() 450 { 451 QUuid uMediumId = uiCommon().openMediumCreatorDialog(this, m_enmMediumType, m_strMachineFolder, 452 m_strMachineName, m_strMachineGuestOSTypeId); 453 /* Make sure that the data structure is updated and newly created medium is selected and visible: */ 454 sltHandleMediumCreated(uMediumId); 455 } 456 457 void UIMediumSelector::sltHandleItemSelectionChanged() 458 { 459 updateChooseButton(); 460 } 461 462 void UIMediumSelector::sltHandleTreeWidgetDoubleClick(QTreeWidgetItem * item, int column) 463 { 464 Q_UNUSED(column); 465 if (!dynamic_cast<UIMediumItem*>(item)) 466 return; 467 accept(); 468 } 469 470 void UIMediumSelector::sltHandleMediumCreated(const QUuid &uMediumId) 471 { 472 if (uMediumId.isNull()) 473 return; 474 /* Update the tree widget making sure we show the new item: */ 475 repopulateTreeWidget(); 476 /* Select the new item: */ 477 selectMedium(uMediumId); 478 /* Update the search: */ 479 m_pSearchWidget->search(m_pTreeWidget); 480 } 481 482 void UIMediumSelector::sltHandleMediumEnumerationStart() 483 { 484 /* Disable controls. Left Alone button box 'Ok' button. it is handle by tree population: */ 485 if (m_pActionRefresh) 486 m_pActionRefresh->setEnabled(false); 487 } 488 489 void UIMediumSelector::sltHandleMediumEnumerated() 490 { 491 } 492 493 void UIMediumSelector::sltHandleMediumEnumerationFinish() 494 { 495 repopulateTreeWidget(); 496 if (m_pActionRefresh) 497 m_pActionRefresh->setEnabled(true); 498 } 499 500 void UIMediumSelector::sltHandleRefresh() 501 { 502 /* Restart full medium-enumeration: */ 503 uiCommon().enumerateMedia(); 504 /* Update the search: */ 505 m_pSearchWidget->search(m_pTreeWidget); 506 } 507 508 void UIMediumSelector::sltHandlePerformSearch() 509 { 510 if (!m_pSearchWidget) 511 return; 512 m_pSearchWidget->search(m_pTreeWidget); 513 } 514 515 void UIMediumSelector::sltHandleTreeContextMenuRequest(const QPoint &point) 516 { 517 QWidget *pSender = qobject_cast<QWidget*>(sender()); 518 if (!pSender) 519 return; 520 521 QMenu menu; 522 QAction *pExpandAll = menu.addAction(tr("Expand All")); 523 QAction *pCollapseAll = menu.addAction(tr("Collapse All")); 524 if (!pExpandAll || !pCollapseAll) 525 return; 526 527 pExpandAll->setIcon(UIIconPool::iconSet(":/expand_all_16px.png")); 528 pCollapseAll->setIcon(UIIconPool::iconSet(":/collapse_all_16px.png")); 529 530 connect(pExpandAll, &QAction::triggered, this, &UIMediumSelector::sltHandleTreeExpandAllSignal); 531 connect(pCollapseAll, &QAction::triggered, this, &UIMediumSelector::sltHandleTreeCollapseAllSignal); 532 533 menu.exec(pSender->mapToGlobal(point)); 534 } 535 536 void UIMediumSelector::sltHandleTreeExpandAllSignal() 537 { 538 if (m_pTreeWidget) 539 m_pTreeWidget->expandAll(); 540 } 541 542 void UIMediumSelector::sltHandleTreeCollapseAllSignal() 543 { 544 if (m_pTreeWidget) 545 m_pTreeWidget->collapseAll(); 546 547 if (m_pAttachedSubTreeRoot) 548 m_pTreeWidget->setExpanded(m_pTreeWidget->itemIndex(m_pAttachedSubTreeRoot), true); 549 if (m_pNotAttachedSubTreeRoot) 550 m_pTreeWidget->setExpanded(m_pTreeWidget->itemIndex(m_pNotAttachedSubTreeRoot), true); 551 } 552 553 void UIMediumSelector::selectMedium(const QUuid &uMediumID) 554 { 555 if (!m_pTreeWidget || uMediumID.isNull()) 556 return; 557 UIMediumItem *pMediumItem = searchItem(0, uMediumID); 558 if (pMediumItem) 559 { 560 m_pTreeWidget->setCurrentItem(pMediumItem); 561 QModelIndex itemIndex = m_pTreeWidget->itemIndex(pMediumItem); 562 if (itemIndex.isValid()) 563 m_pTreeWidget->scrollTo(itemIndex, QAbstractItemView::EnsureVisible); 564 } 565 } 566 567 void UIMediumSelector::updateChooseButton() 568 { 569 if (!m_pTreeWidget || !m_pChooseButton) 570 return; 571 QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems(); 572 if (selectedItems.isEmpty()) 573 { 574 m_pChooseButton->setEnabled(false); 575 return; 576 } 577 578 /* check if at least one of the selected items is a UIMediumItem */ 579 bool mediumItemSelected = false; 580 for (int i = 0; i < selectedItems.size() && !mediumItemSelected; ++i) 581 { 582 if (dynamic_cast<UIMediumItem*>(selectedItems.at(i))) 583 mediumItemSelected = true; 584 } 585 if (mediumItemSelected) 586 m_pChooseButton->setEnabled(true); 587 else 588 m_pChooseButton->setEnabled(false); 589 } 590 591 void UIMediumSelector::finalize() 592 { 593 /* Apply language settings: */ 146 m_pMainLayout->addStretch(); 594 147 retranslateUi(); 595 148 } 596 149 597 void UIMediumSelector::showEvent(QShowEvent *pEvent) 150 void UIBootTimeErrorDialog::sltCancel() 151 { 152 done(static_cast<int>(ReturnCode_Close)); 153 } 154 155 void UIBootTimeErrorDialog::sltReset() 156 { 157 done(static_cast<int>(ReturnCode_Reset)); 158 } 159 160 void UIBootTimeErrorDialog::showEvent(QShowEvent *pEvent) 598 161 { 599 162 Q_UNUSED(pEvent); 600 163 601 164 /* Try to determine the initial size: */ 602 QSize proposedSize;603 int iHostScreen = 0;604 if (m_pParent)605 iHostScreen = gpDesktop->screenNumber(m_pParent);606 else607 iHostScreen = gpDesktop->screenNumber(this);608 if (iHostScreen >= 0 && iHostScreen < gpDesktop->screenCount())609 {610 /* On the basis of current host-screen geometry if possible: */611 const QRect screenGeometry = gpDesktop->screenGeometry(iHostScreen);612 if (screenGeometry.isValid())613 proposedSize = screenGeometry.size() * 5 / 15;614 }615 / * Fallback to default size if we failed: */616 if (proposedSize.isNull())617 proposedSize = QSize(800, 600);618 / * Resize to initial size: */619 resize(proposedSize);165 // QSize proposedSize; 166 // int iHostScreen = 0; 167 // if (m_pParent) 168 // iHostScreen = gpDesktop->screenNumber(m_pParent); 169 // else 170 // iHostScreen = gpDesktop->screenNumber(this); 171 // if (iHostScreen >= 0 && iHostScreen < gpDesktop->screenCount()) 172 // { 173 // /* On the basis of current host-screen geometry if possible: */ 174 // const QRect screenGeometry = gpDesktop->screenGeometry(iHostScreen); 175 // if (screenGeometry.isValid()) 176 // proposedSize = screenGeometry.size() * 5 / 15; 177 // } 178 // /* Fallback to default size if we failed: */ 179 // if (proposedSize.isNull()) 180 // proposedSize = QSize(800, 600); 181 // /* Resize to initial size: */ 182 // resize(proposedSize); 620 183 621 184 if (m_pParent) 622 185 UIDesktopWidgetWatchdog::centerWidget(this, m_pParent, false); 623 186 624 if (m_pTreeWidget) 625 m_pTreeWidget->setFocus(); 626 } 627 628 void UIMediumSelector::repopulateTreeWidget() 629 { 630 if (!m_pTreeWidget) 631 return; 632 /* Cache the currently selected items: */ 633 QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems(); 634 QList<QUuid> selectedMedia = selectedMediumIds(); 635 /* uuid list of selected items: */ 636 /* Reset the related data structure: */ 637 m_mediumItemList.clear(); 638 m_pTreeWidget->clear(); 639 m_pAttachedSubTreeRoot = 0; 640 m_pNotAttachedSubTreeRoot = 0; 641 QVector<UIMediumItem*> menuItemVector; 642 foreach (const QUuid &uMediumID, uiCommon().mediumIDs()) 643 { 644 UIMedium medium = uiCommon().medium(uMediumID); 645 if (medium.type() == m_enmMediumType) 187 } 188 189 void UIBootTimeErrorDialog::setTitle() 190 { 191 } 192 193 bool UIBootTimeErrorDialog::insertBootMedium(const QUuid &uMediumId) 194 { 195 AssertReturn(!uMediumId.isNull(), false); 196 197 CVirtualBox comVBox = uiCommon().virtualBox(); 198 const CGuestOSType &comOsType = comVBox.GetGuestOSType(m_comMachine.GetOSTypeId()); 199 /* Get recommended controller bus & type: */ 200 const KStorageBus enmRecommendedDvdBus = comOsType.GetRecommendedDVDStorageBus(); 201 const KStorageControllerType enmRecommendedDvdType = comOsType.GetRecommendedDVDStorageController(); 202 203 CMediumAttachment comAttachment; 204 /* Search for an attachment of required bus & type: */ 205 foreach (const CMediumAttachment &comCurrentAttachment, m_comMachine.GetMediumAttachments()) 206 { 207 /* Determine current attachment's controller: */ 208 const CStorageController &comCurrentController = m_comMachine.GetStorageControllerByName(comCurrentAttachment.GetController()); 209 210 if ( comCurrentController.GetBus() == enmRecommendedDvdBus 211 && comCurrentController.GetControllerType() == enmRecommendedDvdType 212 && comCurrentAttachment.GetType() == KDeviceType_DVD) 646 213 { 647 bool isMediumAttached = !(medium.medium().GetMachineIds().isEmpty()); 648 QITreeWidgetItem *pParent = 0; 649 if (isMediumAttached) 650 { 651 if (!m_pAttachedSubTreeRoot) 652 { 653 QStringList strList; 654 strList << "Attached"; 655 m_pAttachedSubTreeRoot = new QITreeWidgetItem(m_pTreeWidget, strList); 656 } 657 pParent = m_pAttachedSubTreeRoot; 658 659 } 660 else 661 { 662 if (!m_pNotAttachedSubTreeRoot) 663 { 664 QStringList strList; 665 strList << "Not Attached"; 666 m_pNotAttachedSubTreeRoot = new QITreeWidgetItem(m_pTreeWidget, strList); 667 } 668 pParent = m_pNotAttachedSubTreeRoot; 669 } 670 UIMediumItem *treeItem = addTreeItem(medium, pParent); 671 m_mediumItemList.append(treeItem); 672 menuItemVector.push_back(treeItem); 214 comAttachment = comCurrentAttachment; 215 break; 673 216 } 674 217 } 675 restoreSelection(selectedMedia, menuItemVector); 676 saveDefaultForeground(); 677 updateChooseButton(); 678 if (m_pAttachedSubTreeRoot) 679 m_pTreeWidget->expandItem(m_pAttachedSubTreeRoot); 680 if (m_pNotAttachedSubTreeRoot) 681 m_pTreeWidget->expandItem(m_pNotAttachedSubTreeRoot); 682 m_pTreeWidget->resizeColumnToContents(0); 683 } 684 685 void UIMediumSelector::saveDefaultForeground() 686 { 687 if (!m_pTreeWidget) 688 return; 689 if (m_defaultItemForeground == QBrush() && m_pTreeWidget->topLevelItemCount() >= 1) 690 { 691 QTreeWidgetItem *item = m_pTreeWidget->topLevelItem(0); 692 if (item) 693 { 694 QVariant data = item->data(0, Qt::ForegroundRole); 695 if (data.canConvert<QBrush>()) 696 { 697 m_defaultItemForeground = data.value<QBrush>(); 698 } 699 } 700 } 701 } 702 703 UIMediumItem* UIMediumSelector::searchItem(const QTreeWidgetItem *pParent, const QUuid &mediumId) 704 { 705 if (!m_pTreeWidget) 706 return 0; 707 if (!pParent) 708 pParent = m_pTreeWidget->invisibleRootItem(); 709 if (!pParent) 710 return 0; 711 712 for (int i = 0; i < pParent->childCount(); ++i) 713 { 714 QTreeWidgetItem *pChild = pParent->child(i); 715 if (!pChild) 716 continue; 717 UIMediumItem *mediumItem = dynamic_cast<UIMediumItem*>(pChild); 718 if (mediumItem) 719 { 720 if (mediumItem->id() == mediumId) 721 return mediumItem; 722 } 723 UIMediumItem *pResult = searchItem(pChild, mediumId); 724 if (pResult) 725 return pResult; 726 } 727 return 0; 728 } 729 730 void UIMediumSelector::setTitle() 731 { 732 switch (m_enmMediumType) 733 { 734 case UIMediumDeviceType_DVD: 735 if (!m_strMachineName.isEmpty()) 736 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Optical Disk Selector"))); 737 else 738 setWindowTitle(QString("%1").arg(tr("Optical Disk Selector"))); 739 break; 740 case UIMediumDeviceType_Floppy: 741 if (!m_strMachineName.isEmpty()) 742 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Floppy Disk Selector"))); 743 else 744 setWindowTitle(QString("%1").arg(tr("Floppy Disk Selector"))); 745 break; 746 case UIMediumDeviceType_HardDisk: 747 if (!m_strMachineName.isEmpty()) 748 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Hard Disk Selector"))); 749 else 750 setWindowTitle(QString("%1").arg(tr("Hard Disk Selector"))); 751 break; 752 case UIMediumDeviceType_All: 753 case UIMediumDeviceType_Invalid: 754 default: 755 if (!m_strMachineName.isEmpty()) 756 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Virtual Medium Selector"))); 757 else 758 setWindowTitle(QString("%1").arg(tr("Virtual Medium Selector"))); 759 break; 760 } 761 } 218 AssertMsgReturn(!comAttachment.isNull(), ("Storage Controller is NOT properly configured!\n"), false); 219 220 const UIMedium guiMedium = uiCommon().medium(uMediumId); 221 const CMedium comMedium = guiMedium.medium(); 222 223 /* Mount medium to the predefined port/device: */ 224 m_comMachine.MountMedium(comAttachment.GetController(), comAttachment.GetPort(), comAttachment.GetDevice(), comMedium, false /* force */); 225 bool fSuccess = m_comMachine.isOk(); 226 227 QWidget *pParent = windowManager().realParentWindow(this); 228 229 /* Show error message if necessary: */ 230 if (!fSuccess) 231 msgCenter().cannotRemountMedium(m_comMachine, guiMedium, true /* mount? */, false /* retry? */, pParent); 232 else 233 { 234 /* Save machine settings: */ 235 m_comMachine.SaveSettings(); 236 fSuccess = m_comMachine.isOk(); 237 238 /* Show error message if necessary: */ 239 if (!fSuccess) 240 msgCenter().cannotSaveMachineSettings(m_comMachine, pParent); 241 } 242 return fSuccess; 243 } 244 245 void UIBootTimeErrorDialog::sltFileSelectorPathChanged(const QString &strPath) 246 { 247 insertBootMedium(uiCommon().openMedium(UIMediumDeviceType_DVD, strPath)); 248 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIBootTimeErrorDialog.h
r91606 r91656 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI MediumSelectorclass declaration.3 * VBox Qt GUI - UIBootTimeErrorDialog class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef FEQT_INCLUDED_SRC_medium_UI MediumSelector_h19 #define FEQT_INCLUDED_SRC_medium_UI MediumSelector_h18 #ifndef FEQT_INCLUDED_SRC_medium_UIBootTimeErrorDialog_h 19 #define FEQT_INCLUDED_SRC_medium_UIBootTimeErrorDialog_h 20 20 #ifndef RT_WITHOUT_PRAGMA_ONCE 21 21 # pragma once … … 30 30 31 31 /* Forward declarations: */ 32 class QAction; 33 class QTreeWidgetItem; 34 class QITreeWidget; 35 class QITreeWidgetItem; 32 class QLabel; 36 33 class QVBoxLayout; 37 34 class QIDialogButtonBox; 38 class UIMediumItem; 39 class UIMediumSearchWidget; 40 class QIToolBar; 35 class QIRichTextLabel; 36 class UIFilePathSelector; 41 37 38 /* COM includes: */ 39 #include "COMEnums.h" 40 #include "CMachine.h" 42 41 43 42 /** QIDialog extension providing GUI with a dialog to select an existing medium. */ 44 class SHARED_LIBRARY_STUFF UI MediumSelector: public QIWithRetranslateUI<QIMainDialog>43 class SHARED_LIBRARY_STUFF UIBootTimeErrorDialog : public QIWithRetranslateUI<QIMainDialog> 45 44 { 46 45 … … 51 50 public: 52 51 53 UIMediumSelector(const QUuid &uCurrentMediumId, UIMediumDeviceType enmMediumType, const QString &machineName,54 const QString &machineSettingsFilePath, const QString &strMachineGuestOSTypeId,55 const QUuid &uMachineID, QWidget *pParent);56 /** Disables/enables the create action and controls its visibility. */57 void setEnableCreateAction(bool fEnable);58 QList<QUuid> selectedMediumIds() const;59 60 52 enum ReturnCode 61 53 { 62 ReturnCode_Rejected = 0, 63 ReturnCode_Accepted, 64 ReturnCode_LeftEmpty, 54 ReturnCode_Close = 0, 55 ReturnCode_Reset, 65 56 ReturnCode_Max 66 57 }; 58 59 UIBootTimeErrorDialog(QWidget *pParent, const CMachine &comMachine); 60 QString bootMediumPath() const; 67 61 68 62 protected: … … 73 67 private slots: 74 68 75 void sltButtonLeaveEmpty(); 76 void sltButtonCancel(); 77 void sltButtonChoose(); 78 void sltAddMedium(); 79 void sltCreateMedium(); 80 void sltHandleItemSelectionChanged(); 81 void sltHandleTreeWidgetDoubleClick(QTreeWidgetItem * item, int column); 82 void sltHandleMediumCreated(const QUuid &uMediumId); 83 void sltHandleMediumEnumerationStart(); 84 void sltHandleMediumEnumerated(); 85 void sltHandleMediumEnumerationFinish(); 86 void sltHandleRefresh(); 87 void sltHandlePerformSearch(); 88 void sltHandleTreeContextMenuRequest(const QPoint &point); 89 void sltHandleTreeExpandAllSignal(); 90 void sltHandleTreeCollapseAllSignal(); 69 void sltCancel(); 70 void sltReset(); 71 void sltFileSelectorPathChanged(const QString &strPath); 91 72 92 73 private: 93 74 75 bool insertBootMedium(const QUuid &uMediumId); 94 76 95 77 /** @name Event-handling stuff. … … 104 86 void configure(); 105 87 void prepareWidgets(); 106 void prepareActions();107 void prepareMenuAndToolBar();108 88 void prepareConnections(); 109 /** Perform final preparations. */110 void finalize();111 89 /** @} */ 112 90 113 void repopulateTreeWidget();114 /** Disable/enable 'ok' button on the basis of having a selected item */115 void updateChooseButton();116 UIMediumItem* addTreeItem(const UIMedium &medium, QITreeWidgetItem *pParent);117 void restoreSelection(const QList<QUuid> &selectedMediums, QVector<UIMediumItem*> &mediumList);118 /** Recursively create the hard disk hierarchy under the tree widget */119 UIMediumItem* createHardDiskItem(const UIMedium &medium, QITreeWidgetItem *pParent);120 UIMediumItem* searchItem(const QTreeWidgetItem *pParent, const QUuid &mediumId);121 /** Remember the default foreground brush of the tree so that we can reset tree items' foreground later */122 void saveDefaultForeground();123 void selectMedium(const QUuid &uMediumID);124 91 void setTitle(); 92 QWidget *m_pParent; 93 125 94 QWidget *m_pCentralWidget; 126 95 QVBoxLayout *m_pMainLayout; 127 QITreeWidget *m_pTreeWidget;128 UIMediumDeviceType m_enmMediumType;129 96 QIDialogButtonBox *m_pButtonBox; 130 QPushButton *m_pCancelButton; 131 QPushButton *m_pChooseButton; 132 QPushButton *m_pLeaveEmptyButton; 133 QMenu *m_pMainMenu; 134 QIToolBar *m_pToolBar; 135 QAction *m_pActionAdd; 136 QAction *m_pActionCreate; 137 QAction *m_pActionRefresh; 138 /** All the known media that are already attached to some vm are added under the following top level tree item */ 139 QITreeWidgetItem *m_pAttachedSubTreeRoot; 140 /** All the known media that are not attached to any vm are added under the following top level tree item */ 141 QITreeWidgetItem *m_pNotAttachedSubTreeRoot; 142 QWidget *m_pParent; 143 UIMediumSearchWidget *m_pSearchWidget; 144 /** The list all items added to tree. kept in sync. with tree to make searching easier (faster). */ 145 QList<UIMediumItem*> m_mediumItemList; 146 /** List of items that are matching to the search. */ 147 QList<UIMediumItem*> m_mathingItemList; 148 /** Index of the currently shown (scrolled) item in the m_mathingItemList. */ 149 int m_iCurrentShownIndex; 150 QBrush m_defaultItemForeground; 151 QString m_strMachineFolder; 152 QString m_strMachineName; 153 QString m_strMachineGuestOSTypeId; 154 QUuid m_uMachineID; 155 QUuid m_uCurrentMediumId; 97 QPushButton *m_pCloseButton; 98 QPushButton *m_pResetButton; 99 QIRichTextLabel *m_pLabel; 100 UIFilePathSelector *m_pBootImageSelector; 101 QLabel *m_pBootImageLabel; 102 CMachine m_comMachine; 156 103 }; 157 104 158 #endif /* !FEQT_INCLUDED_SRC_medium_UI MediumSelector_h */105 #endif /* !FEQT_INCLUDED_SRC_medium_UIBootTimeErrorDialog_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
r91363 r91656 34 34 #include "UIActionPoolRuntime.h" 35 35 #include "UIAddDiskEncryptionPasswordDialog.h" 36 #include "UIBootTimeErrorDialog.h" 36 37 #include "UICommon.h" 37 38 #include "UIConverter.h" … … 665 666 if (strErrorId == "DrvVD_DEKMISSING") 666 667 return askUserForTheDiskEncryptionPasswords(); 668 else if (strErrorId == "VMBootFail") 669 return showBootFailureDialog(); 667 670 668 671 /* Show runtime error: */ … … 1543 1546 return; 1544 1547 1545 /* Create the soft keyboard only once: */1546 1548 if (!m_pSoftKeyboardDialog) 1547 1549 { … … 1797 1799 } 1798 1800 1799 void UIMachineLogic::sltReset() 1800 { 1801 /* Confirm/Reset current console: */ 1802 if (msgCenter().confirmResetMachine(machineName())) 1801 void UIMachineLogic::sltReset(bool fShowConfirmation /* = true */) 1802 { 1803 if (fShowConfirmation) 1804 { 1805 /* Confirm/Reset current console: */ 1806 if (msgCenter().confirmResetMachine(machineName())) 1807 console().Reset(); 1808 } 1809 else 1803 1810 console().Reset(); 1804 1811 … … 3249 3256 } 3250 3257 3258 void UIMachineLogic::showBootFailureDialog() 3259 { 3260 QWidget *pParent = windowManager().realParentWindow(activeMachineWindow()); 3261 UIBootTimeErrorDialog *pBootFailureDialog = new UIBootTimeErrorDialog(pParent, machine()); 3262 AssertPtrReturnVoid(pBootFailureDialog); 3263 connect(actionPool()->action(UIActionIndexRT_M_Machine_S_Reset), &UIAction::triggered, 3264 this, &UIMachineLogic::sltReset); 3265 3266 int iResult = pBootFailureDialog->exec(false); 3267 3268 3269 delete pBootFailureDialog; 3270 3271 if (iResult == static_cast<int>(UIBootTimeErrorDialog::ReturnCode_Reset)) 3272 sltReset(false); 3273 } 3274 3251 3275 #ifdef VBOX_WITH_DEBUGGER_GUI 3252 3276 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
r90893 r91656 272 272 void sltShowFileManagerDialog(); 273 273 void sltCloseFileManagerDialog(); 274 void sltReset( );274 void sltReset(bool fShowConfirmation = true); 275 275 void sltPause(bool fOn); 276 276 void sltDetach(); … … 386 386 * closing vm windows re-activates screen saver automatically. On Windows explicit re-activation is needed. */ 387 387 void activateScreenSaver(); 388 /* Shows the boot failure dialog through which user can mount a boot DVD and reset the vm. */ 389 void showBootFailureDialog(); 388 390 389 391 /* Private variables: */
Note:
See TracChangeset
for help on using the changeset viewer.

