Changeset 42766 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Aug 10, 2012 8:54:11 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
r42748 r42766 1348 1348 } 1349 1349 1350 bool UIMessageCenter::confirmDiscardSavedState(const CMachine &machine)1350 bool UIMessageCenter::confirmDiscardSavedState(const QString &strNames) 1351 1351 { 1352 1352 return messageOkCancel(&vboxGlobal().selectorWnd(), Question, 1353 1353 tr("<p>Are you sure you want to discard the saved state of " 1354 "the virtual machine <b>%1</b>?</p>" 1355 "<p>This operation is equivalent to resetting or powering off " 1356 "the machine without doing a proper shutdown of the " 1357 "guest OS.</p>") 1358 .arg(machine.GetName()), 1354 "the following virtual machines?</p><p><b>%1</b></p>" 1355 "<p>This operation is equivalent to resetting or powering off " 1356 "the machine without doing a proper shutdown of the guest OS.</p>") 1357 .arg(strNames), 1359 1358 0 /* pcszAutoConfirmId */, 1360 1359 tr("Discard", "saved state")); … … 2288 2287 * @return @c true if the user has selected to reset the machine. 2289 2288 */ 2290 bool UIMessageCenter::confirmVMReset(QWidget *pParent /* = 0 */) 2291 { 2292 return messageOkCancel(pParent ? pParent : mainMachineWindowShown(), Question, 2293 tr("<p>Do you really want to reset the virtual machine?</p>" 2294 "<p>This will cause any unsaved data in applications running inside " 2295 "it to be lost.</p>"), 2289 bool UIMessageCenter::confirmVMReset(const QString &strNames) 2290 { 2291 return messageOkCancel(mainMachineWindowShown(), Question, 2292 tr("<p>Do you really want to reset the following virtual machines?</p>" 2293 "<p><b>%1</b></p><p>This will cause any unsaved data " 2294 "in applications running inside it to be lost.</p>") 2295 .arg(strNames), 2296 2296 "confirmVMReset" /* pcszAutoConfirmId */, 2297 2297 tr("Reset", "machine")); 2298 2298 } 2299 2299 2300 bool UIMessageCenter::confirmVMACPIShutdown(QWidget *pParent /* = 0 */) 2301 { 2302 return messageOkCancel(pParent ? pParent : mainMachineWindowShown(), Question, 2303 tr("<p>Do you really want to send an ACPI shutdown signal to the virtual machine?</p>"), 2300 bool UIMessageCenter::confirmVMACPIShutdown(const QString &strNames) 2301 { 2302 return messageOkCancel(mainMachineWindowShown(), Question, 2303 tr("<p>Do you really want to send an ACPI shutdown signal " 2304 "to the following virtual machines?</p><p><b>%1</b></p>") 2305 .arg(strNames), 2304 2306 "confirmVMACPIShutdown" /* pcszAutoConfirmId */, 2305 2307 tr("ACPI Shutdown", "machine")); 2306 2308 } 2307 2309 2308 bool UIMessageCenter::confirmVMPowerOff(QWidget *pParent /* = 0 */) 2309 { 2310 return messageOkCancel(pParent ? pParent : mainMachineWindowShown(), Question, 2311 tr("<p>Do you really want to power off the virtual machine?</p>" 2312 "<p>This will cause any unsaved data in applications running inside " 2313 "it to be lost.</p>"), 2310 bool UIMessageCenter::confirmVMPowerOff(const QString &strNames) 2311 { 2312 return messageOkCancel(mainMachineWindowShown(), Question, 2313 tr("<p>Do you really want to power off the following virtual machines?</p>" 2314 "<p><b>%1</b></p><p>This will cause any unsaved data in applications " 2315 "running inside it to be lost.</p>") 2316 .arg(strNames), 2314 2317 "confirmVMPowerOff" /* pcszAutoConfirmId */, 2315 2318 tr("Power Off", "machine")); -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
r42748 r42766 257 257 int confirmMachineItemRemoval(const QStringList &names); 258 258 int confirmMachineDeletion(const QList<CMachine> &machines); 259 bool confirmDiscardSavedState(const CMachine &machine);259 bool confirmDiscardSavedState(const QString &strNames); 260 260 261 261 void cannotChangeMediumType(QWidget *pParent, const CMedium &medium, KMediumType oldMediumType, KMediumType newMediumType); … … 352 352 const QString &strLogFolder); 353 353 354 bool confirmVMReset( QWidget *pParent = 0);355 bool confirmVMACPIShutdown( QWidget *pParent = 0);356 bool confirmVMPowerOff( QWidget *pParent = 0);354 bool confirmVMReset(const QString &strNames); 355 bool confirmVMACPIShutdown(const QString &strNames); 356 bool confirmVMPowerOff(const QString &strNames); 357 357 358 358 void warnAboutCannotRemoveMachineFolder(QWidget *pParent, const QString &strFolderName); -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
r42760 r42766 134 134 } 135 135 136 void UISelectorWindow::sltStateChanged(QString strId)136 void UISelectorWindow::sltStateChanged(QString) 137 137 { 138 138 /* Get current item: */ … … 143 143 return; 144 144 145 /* If signal is for the current item: */ 146 if (pItem->id() == strId) 147 updateActionsAppearance(); 145 /* Update actions: */ 146 updateActionsAppearance(); 148 147 } 149 148 … … 428 427 429 428 /* For every selected item: */ 430 for (int i = 0; i < items.size(); ++i)429 foreach (UIVMItem *pItem, items) 431 430 { 432 431 /* Check if current item could be started/showed: */ 433 if (!isActionEnabled(UIActionIndexSelector_State_Common_StartOrShow, items))432 if (!isActionEnabled(UIActionIndexSelector_State_Common_StartOrShow, QList<UIVMItem*>() << pItem)) 434 433 continue; 435 434 436 /* Get iterated VM: */ 437 CMachine machine = items[i]->machine(); 438 /* Launch/show iterated VM: */ 435 /* Launch/show current VM: */ 436 CMachine machine = pItem->machine(); 439 437 vboxGlobal().launchMachine(machine, qApp->keyboardModifiers() == Qt::ShiftModifier); 440 438 } … … 442 440 443 441 void UISelectorWindow::sltPerformDiscardAction() 444 {445 /* Get current item: */446 UIVMItem *pItem = currentItem();447 AssertMsgReturnVoid(pItem, ("Current item should be selected!\n"));448 449 /* Confirm discarding current VM saved state: */450 if (!msgCenter().confirmDiscardSavedState(pItem->machine()))451 return;452 453 /* Open a session to modify VM: */454 CSession session = vboxGlobal().openSession(pItem->id());455 if (session.isNull())456 {457 msgCenter().cannotOpenSession(session);458 return;459 }460 461 /* Get session console: */462 CConsole console = session.GetConsole();463 console.DiscardSavedState(true /* delete file */);464 if (!console.isOk())465 msgCenter().cannotDiscardSavedState(console);466 467 /* Unlock machine finally: */468 session.UnlockMachine();469 }470 471 void UISelectorWindow::sltPerformPauseResumeAction(bool fPause)472 442 { 473 443 /* Get selected items: */ … … 475 445 AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n")); 476 446 447 /* Prepare the list of the machines to be discarded: */ 448 QStringList machineNames; 449 QList<UIVMItem*> itemsToDiscard; 450 foreach (UIVMItem *pItem, items) 451 if (isActionEnabled(UIActionIndexSelector_Simple_Common_Discard, QList<UIVMItem*>() << pItem)) 452 { 453 machineNames << pItem->name(); 454 itemsToDiscard << pItem; 455 } 456 AssertMsg(!machineNames.isEmpty(), ("This action should not be allowed!")); 457 458 /* Confirm discarding saved VM state: */ 459 if (!msgCenter().confirmDiscardSavedState(machineNames.join(", "))) 460 return; 461 462 /* For every confirmed item: */ 463 foreach (UIVMItem *pItem, itemsToDiscard) 464 { 465 /* Open a session to modify VM: */ 466 CSession session = vboxGlobal().openSession(pItem->id()); 467 if (session.isNull()) 468 { 469 msgCenter().cannotOpenSession(session); 470 return; 471 } 472 473 /* Get session console: */ 474 CConsole console = session.GetConsole(); 475 console.DiscardSavedState(true); 476 if (!console.isOk()) 477 msgCenter().cannotDiscardSavedState(console); 478 479 /* Unlock machine finally: */ 480 session.UnlockMachine(); 481 } 482 } 483 484 void UISelectorWindow::sltPerformPauseResumeAction(bool fPause) 485 { 486 /* Get selected items: */ 487 QList<UIVMItem*> items = currentItems(); 488 AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n")); 489 477 490 /* For every selected item: */ 478 for (int i = 0; i < items.size(); ++i) 479 { 480 /* Get iterated item: */ 481 UIVMItem *pItem = items[i]; 491 foreach (UIVMItem *pItem, items) 492 { 482 493 /* Get item state: */ 483 494 KMachineState state = pItem->machineState(); 484 495 485 496 /* Check if current item could be paused/resumed: */ 486 if (!isActionEnabled(UIActionIndexSelector_Toggle_Common_PauseAndResume, items))497 if (!isActionEnabled(UIActionIndexSelector_Toggle_Common_PauseAndResume, QList<UIVMItem*>() << pItem)) 487 498 continue; 488 499 489 500 /* Check if current item already paused: */ 490 501 if (fPause && 491 (state == KMachineState_Paused || state == KMachineState_TeleportingPausedVM)) 502 (state == KMachineState_Paused || 503 state == KMachineState_TeleportingPausedVM)) 492 504 continue; 493 505 494 506 /* Check if current item already resumed: */ 495 507 if (!fPause && 496 (state == KMachineState_Running || state == KMachineState_Teleporting || state == KMachineState_LiveSnapshotting)) 508 (state == KMachineState_Running || 509 state == KMachineState_Teleporting || 510 state == KMachineState_LiveSnapshotting)) 497 511 continue; 498 512 … … 528 542 void UISelectorWindow::sltPerformResetAction() 529 543 { 530 /* Confirm reseting VM: */531 if (!msgCenter().confirmVMReset(this))532 return;533 534 544 /* Get selected items: */ 535 545 QList<UIVMItem*> items = currentItems(); 536 546 AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n")); 537 547 548 /* Prepare the list of the machines to be reseted: */ 549 QStringList machineNames; 550 QList<UIVMItem*> itemsToReset; 551 foreach (UIVMItem *pItem, items) 552 if (isActionEnabled(UIActionIndexSelector_Simple_Common_Reset, QList<UIVMItem*>() << pItem)) 553 { 554 machineNames << pItem->name(); 555 itemsToReset << pItem; 556 } 557 AssertMsg(!machineNames.isEmpty(), ("This action should not be allowed!")); 558 559 /* Confirm reseting VM: */ 560 if (!msgCenter().confirmVMReset(machineNames.join(", "))) 561 return; 562 538 563 /* For each selected item: */ 539 for (int i = 0; i < items.size(); ++i) 540 { 541 /* Get iterated item: */ 542 UIVMItem *pItem = items[i]; 543 544 /* Check if current item could be reseted: */ 545 if (!isActionEnabled(UIActionIndexSelector_Simple_Common_Reset, items)) 546 continue; 547 564 foreach (UIVMItem *pItem, itemsToReset) 565 { 548 566 /* Open a session to modify VM state: */ 549 567 CSession session = vboxGlobal().openExistingSession(pItem->id()); … … 570 588 AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n")); 571 589 572 /* Check if all the items could be saved: */573 if (!isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_Save, items))574 return;575 576 590 /* For each selected item: */ 577 591 foreach (UIVMItem *pItem, items) 578 592 { 593 /* Check if current item could be saved: */ 594 if (!isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_Save, QList<UIVMItem*>() << pItem)) 595 continue; 596 579 597 /* Open a session to modify VM state: */ 580 598 CSession session = vboxGlobal().openExistingSession(pItem->id()); … … 593 611 else 594 612 { 595 /* Get machine: */613 /* Show the "VM saving" progress dialog: */ 596 614 CMachine machine = session.GetMachine(); 597 /* Show the "VM saving" progress dialog: */598 615 msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_state_save_90px.png", 0, true); 599 616 if (progress.GetResultCode() != 0) … … 608 625 void UISelectorWindow::sltPerformACPIShutdownAction() 609 626 { 610 /* Confirm ACPI shutdown current VM: */611 if (!msgCenter().confirmVMACPIShutdown(this))612 return;613 614 627 /* Get selected items: */ 615 628 QList<UIVMItem*> items = currentItems(); 616 629 AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n")); 617 630 631 /* Prepare the list of the machines to be shutdowned: */ 632 QStringList machineNames; 633 QList<UIVMItem*> itemsToShutdown; 634 foreach (UIVMItem *pItem, items) 635 if (isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown, QList<UIVMItem*>() << pItem)) 636 { 637 machineNames << pItem->name(); 638 itemsToShutdown << pItem; 639 } 640 AssertMsg(!machineNames.isEmpty(), ("This action should not be allowed!")); 641 642 /* Confirm ACPI shutdown current VM: */ 643 if (!msgCenter().confirmVMACPIShutdown(machineNames.join(", "))) 644 return; 645 618 646 /* For each selected item: */ 619 for (int i = 0; i < items.size(); ++i) 620 { 621 /* Get iterated item: */ 622 UIVMItem *pItem = items[i]; 623 624 /* Check if current item could be shutdowned: */ 625 if (!isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown, items)) 626 continue; 627 647 foreach (UIVMItem *pItem, itemsToShutdown) 648 { 628 649 /* Open a session to modify VM state: */ 629 650 CSession session = vboxGlobal().openExistingSession(pItem->id()); … … 646 667 void UISelectorWindow::sltPerformPowerOffAction() 647 668 { 648 /* Confirm Power Off current VM: */649 if (!msgCenter().confirmVMPowerOff(this))650 return;651 652 669 /* Get selected items: */ 653 670 QList<UIVMItem*> items = currentItems(); 654 671 AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n")); 655 672 673 /* Prepare the list of the machines to be powered off: */ 674 QStringList machineNames; 675 QList<UIVMItem*> itemsToPowerOff; 676 foreach (UIVMItem *pItem, items) 677 if (isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_PowerOff, QList<UIVMItem*>() << pItem)) 678 { 679 machineNames << pItem->name(); 680 itemsToPowerOff << pItem; 681 } 682 AssertMsg(!machineNames.isEmpty(), ("This action should not be allowed!")); 683 684 /* Confirm Power Off current VM: */ 685 if (!msgCenter().confirmVMPowerOff(machineNames.join(", "))) 686 return; 687 656 688 /* For each selected item: */ 657 for (int i = 0; i < items.size(); ++i) 658 { 659 /* Get iterated item: */ 660 UIVMItem *pItem = items[i]; 661 662 /* Check if current item could be powered off: */ 663 if (!isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_PowerOff, items)) 664 continue; 665 689 foreach (UIVMItem *pItem, itemsToPowerOff) 690 { 666 691 /* Open a session to modify VM state: */ 667 692 CSession session = vboxGlobal().openExistingSession(pItem->id()); … … 701 726 702 727 /* For each selected item: */ 703 for (int i = 0; i < items.size(); ++i) 704 { 705 /* Get iterated item: */ 706 UIVMItem *pItem = items[i]; 707 728 foreach (UIVMItem *pItem, items) 729 { 708 730 /* Check if log could be show for the current item: */ 709 if (!isActionEnabled(UIActionIndex_Simple_LogDialog, items))731 if (!isActionEnabled(UIActionIndex_Simple_LogDialog, QList<UIVMItem*>() << pItem)) 710 732 continue; 711 733 … … 722 744 723 745 /* For each selected item: */ 724 for (int i = 0; i < items.size(); ++i) 725 { 726 /* Get iterated item: */ 727 UIVMItem *pItem = items[i]; 728 746 foreach (UIVMItem *pItem, items) 747 { 729 748 /* Check if that item could be shown in file-browser: */ 730 if (!isActionEnabled(UIActionIndexSelector_Simple_Common_ShowInFileManager, items))749 if (!isActionEnabled(UIActionIndexSelector_Simple_Common_ShowInFileManager, QList<UIVMItem*>() << pItem)) 731 750 continue; 732 751 … … 743 762 744 763 /* For each selected item: */ 745 for (int i = 0; i < items.size(); ++i) 746 { 747 /* Get iterated item: */ 748 UIVMItem *pItem = items[i]; 749 764 foreach (UIVMItem *pItem, items) 765 { 750 766 /* Check if shortcuts could be created for this item: */ 751 if (!isActionEnabled(UIActionIndexSelector_Simple_Common_CreateShortcut, items))767 if (!isActionEnabled(UIActionIndexSelector_Simple_Common_CreateShortcut, QList<UIVMItem*>() << pItem)) 752 768 continue; 753 769 … … 762 778 void UISelectorWindow::sltMachineCloseMenuAboutToShow() 763 779 { 764 /* Get current item: */765 UIVMItem *pItem = currentItem();766 780 /* Get selected items: */ 767 781 QList<UIVMItem*> items = currentItems(); 768 AssertMsgReturnVoid( pItem, ("Currentitem should be selected!\n"));782 AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n")); 769 783 770 784 m_pACPIShutdownAction->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown, items)); … … 1539 1553 QList<UIVMItem*> items = currentItems(); 1540 1554 1555 /* Enable/disable group actions: */ 1556 m_pAction_Group_Rename->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Rename, items)); 1557 m_pAction_Group_Remove->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Remove, items)); 1558 m_pAction_Group_Sort->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Sort, items)); 1559 1560 /* Enable/disable machine actions: */ 1561 m_pAction_Machine_Settings->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Settings, items)); 1562 m_pAction_Machine_Clone->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Clone, items)); 1563 m_pAction_Machine_Remove->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Remove, items)); 1564 m_pAction_Machine_AddGroup->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_AddGroup, items)); 1565 1541 1566 /* Enable/disable common actions: */ 1542 1567 m_pAction_Common_StartOrShow->setEnabled(isActionEnabled(UIActionIndexSelector_State_Common_StartOrShow, items)); … … 1550 1575 m_pAction_Common_SortParent->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Common_SortParent, items)); 1551 1576 1552 /* Enable/disable group actions: */1553 m_pAction_Group_Rename->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Rename, items));1554 m_pAction_Group_Remove->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Remove, items));1555 m_pAction_Group_Sort->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Sort, items));1556 1557 /* Enable/disable machine actions: */1558 m_pAction_Machine_Settings->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Settings, items));1559 m_pAction_Machine_Clone->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Clone, items));1560 m_pAction_Machine_Remove->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Remove, items));1561 m_pAction_Machine_AddGroup->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_AddGroup, items));1562 1563 1577 /* Enable/disable machine-close actions: */ 1564 1578 m_pMachineCloseMenuAction->setEnabled(isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items)); … … 1567 1581 m_pPowerOffAction->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_PowerOff, items)); 1568 1582 1569 /* If item present: */1583 /* Start/Show action is deremined by 1st item: */ 1570 1584 if (pItem && pItem->accessible()) 1571 { 1572 /* Get state: */ 1573 KMachineState state = pItem->machineState(); 1574 1575 /* Update the Start button action appearance: */ 1576 if (state == KMachineState_PoweredOff || 1577 state == KMachineState_Saved || 1578 state == KMachineState_Teleported || 1579 state == KMachineState_Aborted) 1580 { 1581 m_pAction_Common_StartOrShow->setState(1); 1585 m_pAction_Common_StartOrShow->setState(isItemPoweredOff(pItem) ? 1 : 2); 1586 else 1587 m_pAction_Common_StartOrShow->setState(1); 1588 1589 /* Pause/Resume action is deremined by 1st started item: */ 1590 UIVMItem *pFirstStartedAction = 0; 1591 foreach (UIVMItem *pSelectedItem, items) 1592 if (isItemStarted(pSelectedItem)) 1593 pFirstStartedAction = pSelectedItem; 1594 /* Update the Pause/Resume action appearance: */ 1595 m_pAction_Common_PauseAndResume->blockSignals(true); 1596 m_pAction_Common_PauseAndResume->setChecked(pFirstStartedAction && isItemPaused(pFirstStartedAction)); 1597 m_pAction_Common_PauseAndResume->updateAppearance(); 1598 m_pAction_Common_PauseAndResume->blockSignals(false); 1599 1582 1600 #ifdef QT_MAC_USE_COCOA 1583 1584 1585 1586 1587 1601 /* There is a bug in Qt Cocoa which result in showing a "more arrow" when 1602 the necessary size of the toolbar is increased. Also for some languages 1603 the with doesn't match if the text increase. So manually adjust the size 1604 after changing the text. */ 1605 mVMToolBar->updateLayout(); 1588 1606 #endif /* QT_MAC_USE_COCOA */ 1589 }1590 else1591 {1592 m_pAction_Common_StartOrShow->setState(2);1593 #ifdef QT_MAC_USE_COCOA1594 /* There is a bug in Qt Cocoa which result in showing a "more arrow" when1595 the necessary size of the toolbar is increased. Also for some languages1596 the with doesn't match if the text increase. So manually adjust the size1597 after changing the text. */1598 mVMToolBar->updateLayout();1599 #endif /* QT_MAC_USE_COCOA */1600 }1601 1602 /* Update the Pause/Resume action appearance: */1603 if (state == KMachineState_Paused ||1604 state == KMachineState_TeleportingPausedVM)1605 {1606 m_pAction_Common_PauseAndResume->blockSignals(true);1607 m_pAction_Common_PauseAndResume->setChecked(true);1608 m_pAction_Common_PauseAndResume->blockSignals(false);1609 }1610 else1611 {1612 m_pAction_Common_PauseAndResume->blockSignals(true);1613 m_pAction_Common_PauseAndResume->setChecked(false);1614 m_pAction_Common_PauseAndResume->blockSignals(false);1615 }1616 m_pAction_Common_PauseAndResume->updateAppearance();1617 }1618 else1619 {1620 /* Update the Start button action appearance: */1621 m_pAction_Common_StartOrShow->setState(1);1622 }1623 1607 } 1624 1608 … … 1635 1619 switch (iActionIndex) 1636 1620 { 1621 case UIActionIndexSelector_Simple_Group_Rename: 1622 case UIActionIndexSelector_Simple_Group_Remove: 1623 { 1624 return !m_pChooser->isGroupSavingInProgress() && 1625 isItemsPoweredOff(items); 1626 } 1627 case UIActionIndexSelector_Simple_Group_Sort: 1628 { 1629 return !m_pChooser->isGroupSavingInProgress() && 1630 m_pChooser->singleGroupSelected(); 1631 } 1637 1632 case UIActionIndexSelector_Simple_Machine_Settings: 1638 1633 { 1639 /* Check that we are not saving groups,1640 * there is only one item, its accessible1641 * and machine is not in 'stuck' state. */1642 1634 return !m_pChooser->isGroupSavingInProgress() && 1643 1635 items.size() == 1 && 1644 1636 pItem->accessible() && 1645 pItem->machineState() != KMachineState_Stuck;1637 !isItemStuck(pItem); 1646 1638 } 1647 1639 case UIActionIndexSelector_Simple_Machine_Clone: 1648 1640 { 1649 /* Check that there is only one item, its accessible 1650 * and session state is unlocked. */ 1651 return items.size() == 1 && 1652 pItem->accessible() && 1653 pItem->sessionState() == KSessionState_Unlocked; 1654 } 1655 case UIActionIndexSelector_Simple_Group_Rename: 1656 case UIActionIndexSelector_Simple_Group_Remove: 1657 { 1658 /* Make sure we are not saving groups: */ 1659 if (m_pChooser->isGroupSavingInProgress()) 1660 return false; 1661 1662 /* Group can be always removed/renamed: */ 1663 return true; 1641 return !m_pChooser->isGroupSavingInProgress() && 1642 items.size() == 1 && 1643 isItemEditable(pItem); 1664 1644 } 1665 1645 case UIActionIndexSelector_Simple_Machine_Remove: 1666 1646 { 1667 /* Make sure we are not saving groups: */ 1668 if (m_pChooser->isGroupSavingInProgress()) 1669 return false; 1670 1671 /* Check that all machines are NOT accessible 1672 * or session states of all machines are unlocked. */ 1673 return isItemsInaccessible(items) || isItemsHasUnlockedSession(items); 1647 return !m_pChooser->isGroupSavingInProgress() && 1648 isAtLeastOneItemRemovable(items); 1674 1649 } 1675 1650 case UIActionIndexSelector_Simple_Machine_AddGroup: 1676 1651 { 1677 /* Check that there is more than one item, 1678 * all items are accessible and in 'powered off' states: */ 1679 return items.size() > 1 && 1680 isItemsAccessible(items) && 1681 isItemsPoweredOff(items); 1652 return !m_pChooser->isGroupSavingInProgress() && 1653 items.size() > 1 && isItemsPoweredOff(items); 1682 1654 } 1683 1655 case UIActionIndexSelector_State_Common_StartOrShow: 1684 1656 { 1685 /* Make sure all items are accessible: */ 1686 if (!isItemsAccessible(items)) 1687 return false; 1688 1689 /* Make sure we are not saving groups: */ 1690 if (m_pChooser->isGroupSavingInProgress()) 1691 return false; 1692 1693 /* If machine is in one of 'powered-off' states:*/ 1694 if (pItem->machineState() == KMachineState_PoweredOff || 1695 pItem->machineState() == KMachineState_Saved || 1696 pItem->machineState() == KMachineState_Teleported || 1697 pItem->machineState() == KMachineState_Aborted) 1698 { 1699 /* It depends on session state: */ 1700 return pItem->sessionState() == KSessionState_Unlocked; 1701 } 1702 1703 /* Otherwise we are in running mode and 1704 * should allow to switch to VM if its possible: */ 1705 return pItem->canSwitchTo(); 1657 return !m_pChooser->isGroupSavingInProgress() && 1658 isAtLeastOneItemCanBeStartedOrShowed(items); 1706 1659 } 1707 1660 case UIActionIndexSelector_Simple_Common_Discard: 1708 1661 { 1709 /* Check that there is only one item, its accessible 1710 * and machine is in 'saved' state and session state is unlocked. */ 1711 return items.size() == 1 && 1712 pItem->accessible() && 1713 pItem->machineState() == KMachineState_Saved && 1714 pItem->sessionState() == KSessionState_Unlocked; 1662 return !m_pChooser->isGroupSavingInProgress() && 1663 isAtLeastOneItemDiscardable(items); 1715 1664 } 1716 1665 case UIActionIndexSelector_Toggle_Common_PauseAndResume: 1717 1666 { 1718 /* Make sure all items are accessible: */ 1719 if (!isItemsAccessible(items)) 1720 return false; 1721 1722 /* True if machine is in one of next 'running' or 'paused' states: */ 1723 return pItem->machineState() == KMachineState_Running || 1724 pItem->machineState() == KMachineState_Teleporting || 1725 pItem->machineState() == KMachineState_LiveSnapshotting || 1726 pItem->machineState() == KMachineState_Paused || 1727 pItem->machineState() == KMachineState_TeleportingPausedVM; 1667 return isAtLeastOneItemStarted(items); 1728 1668 } 1729 1669 case UIActionIndexSelector_Simple_Common_Reset: 1730 1670 { 1731 /* Make sure all items are accessible: */ 1732 if (!isItemsAccessible(items)) 1733 return false; 1734 1735 /* True if machine is in one of 'running' states: */ 1736 return pItem->machineState() == KMachineState_Running || 1737 pItem->machineState() == KMachineState_Teleporting || 1738 pItem->machineState() == KMachineState_LiveSnapshotting; 1739 } 1740 case UIActionIndexSelector_Menu_Machine_Close: 1741 { 1742 /* Make sure all items are accessible: */ 1743 if (!isItemsAccessible(items)) 1744 return false; 1745 1746 /* True if machine is in one of next 'running' or 'paused' states: */ 1747 return pItem->machineState() == KMachineState_Running || 1748 pItem->machineState() == KMachineState_Paused; 1749 } 1750 case UIActionIndexSelector_Simple_Machine_Close_Save: 1751 { 1752 /* The same as 'Machine/Close' menu is enabled: */ 1753 return isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items); 1754 } 1755 case UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown: 1756 { 1757 /* Check that 'Machine/Close' menu is enabled: */ 1758 if (!isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items)) 1759 return false; 1760 1761 /* Check if we are entered ACPI mode already. 1762 * Only then it make sense to send the ACPI shutdown sequence: */ 1763 bool fEnteredACPIMode = false; 1764 CSession session = vboxGlobal().openExistingSession(pItem->id()); 1765 if (!session.isNull()) 1766 { 1767 CConsole console = session.GetConsole(); 1768 if (!console.isNull()) 1769 fEnteredACPIMode = console.GetGuestEnteredACPIMode(); 1770 session.UnlockMachine(); 1771 } 1772 else 1773 msgCenter().cannotOpenSession(session); 1774 return fEnteredACPIMode; 1775 } 1776 case UIActionIndexSelector_Simple_Machine_Close_PowerOff: 1777 { 1778 /* The same as 'Machine/Close' menu is enabled: */ 1779 return isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items); 1671 return isAtLeastOneItemRunning(items); 1780 1672 } 1781 1673 case UIActionIndexSelector_Simple_Common_Refresh: 1782 1674 { 1783 /* Make sure all items are NOT accessible: */ 1784 return isItemsInaccessible(items); 1675 return isAtLeastOneItemInaccessible(items); 1785 1676 } 1786 1677 case UIActionIndex_Simple_LogDialog: 1787 1678 case UIActionIndexSelector_Simple_Common_ShowInFileManager: 1679 { 1680 return isAtLeastOneItemAccessible(items); 1681 } 1788 1682 case UIActionIndexSelector_Simple_Common_SortParent: 1789 case UIActionIndexSelector_Simple_Group_Sort: 1790 { 1791 /* Make sure all items are accessible: */ 1792 return items.size() > 0 && isItemsAccessible(items); 1683 { 1684 return !m_pChooser->isGroupSavingInProgress(); 1793 1685 } 1794 1686 case UIActionIndexSelector_Simple_Common_CreateShortcut: 1795 1687 { 1796 /* Make sure all items supports shortcuts: */ 1797 return isItemsSupportsShortcuts(items); 1688 return isAtLeastOneItemSupportsShortcuts(items); 1689 } 1690 case UIActionIndexSelector_Menu_Machine_Close: 1691 { 1692 return isAtLeastOneItemStarted(items); 1693 } 1694 case UIActionIndexSelector_Simple_Machine_Close_Save: 1695 { 1696 return isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items); 1697 } 1698 case UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown: 1699 { 1700 return isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items) && 1701 isAtLeastOneItemAbleToShutdown(items); 1702 } 1703 case UIActionIndexSelector_Simple_Machine_Close_PowerOff: 1704 { 1705 return isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items); 1798 1706 } 1799 1707 default: … … 1806 1714 1807 1715 /* static */ 1808 bool UISelectorWindow::isItems Accessible(const QList<UIVMItem*> &items)1809 { 1810 foreach (UIVMItem *pItem, items) 1811 if (! pItem->accessible())1716 bool UISelectorWindow::isItemsPoweredOff(const QList<UIVMItem*> &items) 1717 { 1718 foreach (UIVMItem *pItem, items) 1719 if (!isItemPoweredOff(pItem)) 1812 1720 return false; 1813 1721 return true; … … 1815 1723 1816 1724 /* static */ 1817 bool UISelectorWindow::isItemsInaccessible(const QList<UIVMItem*> &items) 1725 bool UISelectorWindow::isAtLeastOneItemAbleToShutdown(const QList<UIVMItem*> &items) 1726 { 1727 foreach (UIVMItem *pItem, items) 1728 { 1729 if (!isItemRunning(pItem)) 1730 continue; 1731 1732 CSession session = vboxGlobal().openExistingSession(pItem->id()); 1733 if (session.isNull()) 1734 { 1735 msgCenter().cannotOpenSession(session); 1736 return false; 1737 } 1738 CConsole console = session.GetConsole(); 1739 if (console.isNull()) 1740 { 1741 session.UnlockMachine(); 1742 return false; 1743 } 1744 session.UnlockMachine(); 1745 1746 return console.GetGuestEnteredACPIMode(); 1747 } 1748 return false; 1749 } 1750 1751 /* static */ 1752 bool UISelectorWindow::isAtLeastOneItemSupportsShortcuts(const QList<UIVMItem*> &items) 1753 { 1754 foreach (UIVMItem *pItem, items) 1755 if (pItem->accessible() 1756 #ifdef Q_WS_MAC 1757 /* On Mac OS X this are real alias files, which don't work with the old 1758 * legacy xml files. On the other OS's some kind of start up script is used. */ 1759 && !pItem->settingsFile().endsWith(".vbox", Qt::CaseInsensitive) 1760 #endif /* Q_WS_MAC */ 1761 ) 1762 return true; 1763 return false; 1764 } 1765 1766 /* static */ 1767 bool UISelectorWindow::isAtLeastOneItemAccessible(const QList<UIVMItem*> &items) 1818 1768 { 1819 1769 foreach (UIVMItem *pItem, items) 1820 1770 if (pItem->accessible()) 1821 return false;1822 return true;1771 return true; 1772 return false; 1823 1773 } 1824 1774 1825 1775 /* static */ 1826 bool UISelectorWindow::is ItemsHasUnlockedSession(const QList<UIVMItem*> &items)1827 { 1828 foreach (UIVMItem *pItem, items) 1829 if ( pItem->sessionState() != KSessionState_Unlocked)1830 return false;1831 return true;1776 bool UISelectorWindow::isAtLeastOneItemInaccessible(const QList<UIVMItem*> &items) 1777 { 1778 foreach (UIVMItem *pItem, items) 1779 if (!pItem->accessible()) 1780 return true; 1781 return false; 1832 1782 } 1833 1783 1834 1784 /* static */ 1835 bool UISelectorWindow::isItemsSupportsShortcuts(const QList<UIVMItem*> &items) 1836 { 1837 /* Make sure all items are accessible: */ 1838 if (!isItemsAccessible(items)) 1839 return false; 1840 1841 #ifdef Q_WS_MAC 1842 /* On Mac OS X this are real alias files, which don't work with the old 1843 * legacy xml files. On the other OS's some kind of start up script is used. */ 1844 foreach (UIVMItem *pItem, items) 1845 if (!pItem->settingsFile().endsWith(".vbox", Qt::CaseInsensitive)) 1846 return false; 1847 #endif /* Q_WS_MAC */ 1848 1849 /* True by default: */ 1850 return true; 1785 bool UISelectorWindow::isAtLeastOneItemRemovable(const QList<UIVMItem*> &items) 1786 { 1787 foreach (UIVMItem *pItem, items) 1788 if (!pItem->accessible() || isItemEditable(pItem)) 1789 return true; 1790 return false; 1851 1791 } 1852 1792 1853 1793 /* static */ 1854 bool UISelectorWindow::isItemsPoweredOff(const QList<UIVMItem*> &items) 1855 { 1856 foreach (UIVMItem *pItem, items) 1857 if (!(pItem->machineState() == KMachineState_PoweredOff || 1858 pItem->machineState() == KMachineState_Saved || 1859 pItem->machineState() == KMachineState_Teleported || 1860 pItem->machineState() == KMachineState_Aborted)) 1861 return false; 1862 return true; 1863 } 1864 1794 bool UISelectorWindow::isAtLeastOneItemCanBeStartedOrShowed(const QList<UIVMItem*> &items) 1795 { 1796 foreach (UIVMItem *pItem, items) 1797 { 1798 if ((isItemPoweredOff(pItem) && isItemEditable(pItem)) || 1799 (isItemStarted(pItem) && pItem->canSwitchTo())) 1800 return true; 1801 } 1802 return false; 1803 } 1804 1805 /* static */ 1806 bool UISelectorWindow::isAtLeastOneItemDiscardable(const QList<UIVMItem*> &items) 1807 { 1808 foreach (UIVMItem *pItem, items) 1809 if (isItemSaved(pItem) && isItemEditable(pItem)) 1810 return true; 1811 return false; 1812 } 1813 1814 /* static */ 1815 bool UISelectorWindow::isAtLeastOneItemStarted(const QList<UIVMItem*> &items) 1816 { 1817 foreach (UIVMItem *pItem, items) 1818 if (isItemStarted(pItem)) 1819 return true; 1820 return false; 1821 } 1822 1823 /* static */ 1824 bool UISelectorWindow::isAtLeastOneItemRunning(const QList<UIVMItem*> &items) 1825 { 1826 foreach (UIVMItem *pItem, items) 1827 if (isItemRunning(pItem)) 1828 return true; 1829 return false; 1830 } 1831 1832 /* static */ 1833 bool UISelectorWindow::isItemEditable(UIVMItem *pItem) 1834 { 1835 return pItem->accessible() && 1836 pItem->sessionState() == KSessionState_Unlocked; 1837 } 1838 1839 /* static */ 1840 bool UISelectorWindow::isItemSaved(UIVMItem *pItem) 1841 { 1842 if (pItem->accessible() && 1843 pItem->machineState() == KMachineState_Saved) 1844 return true; 1845 return false; 1846 } 1847 1848 /* static */ 1849 bool UISelectorWindow::isItemPoweredOff(UIVMItem *pItem) 1850 { 1851 if (pItem->accessible() && 1852 (pItem->machineState() == KMachineState_PoweredOff || 1853 pItem->machineState() == KMachineState_Saved || 1854 pItem->machineState() == KMachineState_Teleported || 1855 pItem->machineState() == KMachineState_Aborted)) 1856 return true; 1857 return false; 1858 } 1859 1860 /* static */ 1861 bool UISelectorWindow::isItemStarted(UIVMItem *pItem) 1862 { 1863 return isItemRunning(pItem) || isItemPaused(pItem); 1864 } 1865 1866 /* static */ 1867 bool UISelectorWindow::isItemRunning(UIVMItem *pItem) 1868 { 1869 if (pItem->accessible() && 1870 (pItem->machineState() == KMachineState_Running || 1871 pItem->machineState() == KMachineState_Teleporting || 1872 pItem->machineState() == KMachineState_LiveSnapshotting)) 1873 return true; 1874 return false; 1875 } 1876 1877 /* static */ 1878 bool UISelectorWindow::isItemPaused(UIVMItem *pItem) 1879 { 1880 if (pItem->accessible() && 1881 (pItem->machineState() == KMachineState_Paused || 1882 pItem->machineState() == KMachineState_TeleportingPausedVM)) 1883 return true; 1884 return false; 1885 1886 } 1887 1888 /* static */ 1889 bool UISelectorWindow::isItemStuck(UIVMItem *pItem) 1890 { 1891 if (pItem->accessible() && 1892 pItem->machineState() == KMachineState_Stuck) 1893 return true; 1894 return false; 1895 } 1896 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h
r42760 r42766 147 147 /* Helpers: Action stuff: */ 148 148 bool isActionEnabled(int iActionIndex, const QList<UIVMItem*> &items); 149 static bool isItemsAccessible(const QList<UIVMItem*> &items);150 static bool isItemsInaccessible(const QList<UIVMItem*> &items);151 static bool isItemsHasUnlockedSession(const QList<UIVMItem*> &items);152 static bool isItemsSupportsShortcuts(const QList<UIVMItem*> &items);153 149 static bool isItemsPoweredOff(const QList<UIVMItem*> &items); 150 static bool isAtLeastOneItemAbleToShutdown(const QList<UIVMItem*> &items); 151 static bool isAtLeastOneItemSupportsShortcuts(const QList<UIVMItem*> &items); 152 static bool isAtLeastOneItemAccessible(const QList<UIVMItem*> &items); 153 static bool isAtLeastOneItemInaccessible(const QList<UIVMItem*> &items); 154 static bool isAtLeastOneItemRemovable(const QList<UIVMItem*> &items); 155 static bool isAtLeastOneItemCanBeStartedOrShowed(const QList<UIVMItem*> &items); 156 static bool isAtLeastOneItemDiscardable(const QList<UIVMItem*> &items); 157 static bool isAtLeastOneItemStarted(const QList<UIVMItem*> &items); 158 static bool isAtLeastOneItemRunning(const QList<UIVMItem*> &items); 159 static bool isItemEditable(UIVMItem *pItem); 160 static bool isItemSaved(UIVMItem *pItem); 161 static bool isItemPoweredOff(UIVMItem *pItem); 162 static bool isItemStarted(UIVMItem *pItem); 163 static bool isItemRunning(UIVMItem *pItem); 164 static bool isItemPaused(UIVMItem *pItem); 165 static bool isItemStuck(UIVMItem *pItem); 154 166 155 167 /* Central splitter window: */
Note:
See TracChangeset
for help on using the changeset viewer.