VirtualBox

Ignore:
Timestamp:
Aug 10, 2012 8:54:11 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: VM Selector: Action pool refactoring/cleanup (part 2); More freedom for selector actions.

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  
    13481348}
    13491349
    1350 bool UIMessageCenter::confirmDiscardSavedState(const CMachine &machine)
     1350bool UIMessageCenter::confirmDiscardSavedState(const QString &strNames)
    13511351{
    13521352    return messageOkCancel(&vboxGlobal().selectorWnd(), Question,
    13531353        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),
    13591358        0 /* pcszAutoConfirmId */,
    13601359        tr("Discard", "saved state"));
     
    22882287 *  @return @c true if the user has selected to reset the machine.
    22892288 */
    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>"),
     2289bool 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),
    22962296        "confirmVMReset" /* pcszAutoConfirmId */,
    22972297        tr("Reset", "machine"));
    22982298}
    22992299
    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>"),
     2300bool 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),
    23042306        "confirmVMACPIShutdown" /* pcszAutoConfirmId */,
    23052307        tr("ACPI Shutdown", "machine"));
    23062308}
    23072309
    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>"),
     2310bool 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),
    23142317        "confirmVMPowerOff" /* pcszAutoConfirmId */,
    23152318        tr("Power Off", "machine"));
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r42748 r42766  
    257257    int confirmMachineItemRemoval(const QStringList &names);
    258258    int confirmMachineDeletion(const QList<CMachine> &machines);
    259     bool confirmDiscardSavedState(const CMachine &machine);
     259    bool confirmDiscardSavedState(const QString &strNames);
    260260
    261261    void cannotChangeMediumType(QWidget *pParent, const CMedium &medium, KMediumType oldMediumType, KMediumType newMediumType);
     
    352352                                   const QString &strLogFolder);
    353353
    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);
    357357
    358358    void warnAboutCannotRemoveMachineFolder(QWidget *pParent, const QString &strFolderName);
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r42760 r42766  
    134134}
    135135
    136 void UISelectorWindow::sltStateChanged(QString strId)
     136void UISelectorWindow::sltStateChanged(QString)
    137137{
    138138    /* Get current item: */
     
    143143        return;
    144144
    145     /* If signal is for the current item: */
    146     if (pItem->id() == strId)
    147         updateActionsAppearance();
     145    /* Update actions: */
     146    updateActionsAppearance();
    148147}
    149148
     
    428427
    429428    /* For every selected item: */
    430     for (int i = 0; i < items.size(); ++i)
     429    foreach (UIVMItem *pItem, items)
    431430    {
    432431        /* 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))
    434433            continue;
    435434
    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();
    439437        vboxGlobal().launchMachine(machine, qApp->keyboardModifiers() == Qt::ShiftModifier);
    440438    }
     
    442440
    443441void 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)
    472442{
    473443    /* Get selected items: */
     
    475445    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    476446
     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
     484void 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
    477490    /* 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    {
    482493        /* Get item state: */
    483494        KMachineState state = pItem->machineState();
    484495
    485496        /* 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))
    487498            continue;
    488499
    489500        /* Check if current item already paused: */
    490501        if (fPause &&
    491             (state == KMachineState_Paused || state == KMachineState_TeleportingPausedVM))
     502            (state == KMachineState_Paused ||
     503             state == KMachineState_TeleportingPausedVM))
    492504            continue;
    493505
    494506        /* Check if current item already resumed: */
    495507        if (!fPause &&
    496             (state == KMachineState_Running || state == KMachineState_Teleporting || state == KMachineState_LiveSnapshotting))
     508            (state == KMachineState_Running ||
     509             state == KMachineState_Teleporting ||
     510             state == KMachineState_LiveSnapshotting))
    497511            continue;
    498512
     
    528542void UISelectorWindow::sltPerformResetAction()
    529543{
    530     /* Confirm reseting VM: */
    531     if (!msgCenter().confirmVMReset(this))
    532         return;
    533 
    534544    /* Get selected items: */
    535545    QList<UIVMItem*> items = currentItems();
    536546    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    537547
     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
    538563    /* 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    {
    548566        /* Open a session to modify VM state: */
    549567        CSession session = vboxGlobal().openExistingSession(pItem->id());
     
    570588    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    571589
    572     /* Check if all the items could be saved: */
    573     if (!isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_Save, items))
    574         return;
    575 
    576590    /* For each selected item: */
    577591    foreach (UIVMItem *pItem, items)
    578592    {
     593        /* Check if current item could be saved: */
     594        if (!isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_Save, QList<UIVMItem*>() << pItem))
     595            continue;
     596
    579597        /* Open a session to modify VM state: */
    580598        CSession session = vboxGlobal().openExistingSession(pItem->id());
     
    593611        else
    594612        {
    595             /* Get machine: */
     613            /* Show the "VM saving" progress dialog: */
    596614            CMachine machine = session.GetMachine();
    597             /* Show the "VM saving" progress dialog: */
    598615            msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_state_save_90px.png", 0, true);
    599616            if (progress.GetResultCode() != 0)
     
    608625void UISelectorWindow::sltPerformACPIShutdownAction()
    609626{
    610     /* Confirm ACPI shutdown current VM: */
    611     if (!msgCenter().confirmVMACPIShutdown(this))
    612         return;
    613 
    614627    /* Get selected items: */
    615628    QList<UIVMItem*> items = currentItems();
    616629    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    617630
     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
    618646    /* 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    {
    628649        /* Open a session to modify VM state: */
    629650        CSession session = vboxGlobal().openExistingSession(pItem->id());
     
    646667void UISelectorWindow::sltPerformPowerOffAction()
    647668{
    648     /* Confirm Power Off current VM: */
    649     if (!msgCenter().confirmVMPowerOff(this))
    650         return;
    651 
    652669    /* Get selected items: */
    653670    QList<UIVMItem*> items = currentItems();
    654671    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    655672
     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
    656688    /* 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    {
    666691        /* Open a session to modify VM state: */
    667692        CSession session = vboxGlobal().openExistingSession(pItem->id());
     
    701726
    702727    /* 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    {
    708730        /* 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))
    710732            continue;
    711733
     
    722744
    723745    /* 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    {
    729748        /* 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))
    731750            continue;
    732751
     
    743762
    744763    /* 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    {
    750766        /* 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))
    752768            continue;
    753769
     
    762778void UISelectorWindow::sltMachineCloseMenuAboutToShow()
    763779{
    764     /* Get current item: */
    765     UIVMItem *pItem = currentItem();
    766780    /* Get selected items: */
    767781    QList<UIVMItem*> items = currentItems();
    768     AssertMsgReturnVoid(pItem, ("Current item should be selected!\n"));
     782    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    769783
    770784    m_pACPIShutdownAction->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_ACPIShutdown, items));
     
    15391553    QList<UIVMItem*> items = currentItems();
    15401554
     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
    15411566    /* Enable/disable common actions: */
    15421567    m_pAction_Common_StartOrShow->setEnabled(isActionEnabled(UIActionIndexSelector_State_Common_StartOrShow, items));
     
    15501575    m_pAction_Common_SortParent->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Common_SortParent, items));
    15511576
    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 
    15631577    /* Enable/disable machine-close actions: */
    15641578    m_pMachineCloseMenuAction->setEnabled(isActionEnabled(UIActionIndexSelector_Menu_Machine_Close, items));
     
    15671581    m_pPowerOffAction->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Close_PowerOff, items));
    15681582
    1569     /* If item present: */
     1583    /* Start/Show action is deremined by 1st item: */
    15701584    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
    15821600#ifdef QT_MAC_USE_COCOA
    1583             /* There is a bug in Qt Cocoa which result in showing a "more arrow" when
    1584                the necessary size of the toolbar is increased. Also for some languages
    1585                the with doesn't match if the text increase. So manually adjust the size
    1586                after changing the text. */
    1587             mVMToolBar->updateLayout();
     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();
    15881606#endif /* QT_MAC_USE_COCOA */
    1589         }
    1590         else
    1591         {
    1592             m_pAction_Common_StartOrShow->setState(2);
    1593 #ifdef QT_MAC_USE_COCOA
    1594             /* There is a bug in Qt Cocoa which result in showing a "more arrow" when
    1595                the necessary size of the toolbar is increased. Also for some languages
    1596                the with doesn't match if the text increase. So manually adjust the size
    1597                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         else
    1611         {
    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     else
    1619     {
    1620         /* Update the Start button action appearance: */
    1621         m_pAction_Common_StartOrShow->setState(1);
    1622     }
    16231607}
    16241608
     
    16351619    switch (iActionIndex)
    16361620    {
     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        }
    16371632        case UIActionIndexSelector_Simple_Machine_Settings:
    16381633        {
    1639             /* Check that we are not saving groups,
    1640              * there is only one item, its accessible
    1641              * and machine is not in 'stuck' state. */
    16421634            return !m_pChooser->isGroupSavingInProgress() &&
    16431635                   items.size() == 1 &&
    16441636                   pItem->accessible() &&
    1645                    pItem->machineState() != KMachineState_Stuck;
     1637                   !isItemStuck(pItem);
    16461638        }
    16471639        case UIActionIndexSelector_Simple_Machine_Clone:
    16481640        {
    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);
    16641644        }
    16651645        case UIActionIndexSelector_Simple_Machine_Remove:
    16661646        {
    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);
    16741649        }
    16751650        case UIActionIndexSelector_Simple_Machine_AddGroup:
    16761651        {
    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);
    16821654        }
    16831655        case UIActionIndexSelector_State_Common_StartOrShow:
    16841656        {
    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);
    17061659        }
    17071660        case UIActionIndexSelector_Simple_Common_Discard:
    17081661        {
    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);
    17151664        }
    17161665        case UIActionIndexSelector_Toggle_Common_PauseAndResume:
    17171666        {
    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);
    17281668        }
    17291669        case UIActionIndexSelector_Simple_Common_Reset:
    17301670        {
    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);
    17801672        }
    17811673        case UIActionIndexSelector_Simple_Common_Refresh:
    17821674        {
    1783             /* Make sure all items are NOT accessible: */
    1784             return isItemsInaccessible(items);
     1675            return isAtLeastOneItemInaccessible(items);
    17851676        }
    17861677        case UIActionIndex_Simple_LogDialog:
    17871678        case UIActionIndexSelector_Simple_Common_ShowInFileManager:
     1679        {
     1680            return isAtLeastOneItemAccessible(items);
     1681        }
    17881682        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();
    17931685        }
    17941686        case UIActionIndexSelector_Simple_Common_CreateShortcut:
    17951687        {
    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);
    17981706        }
    17991707        default:
     
    18061714
    18071715/* static */
    1808 bool UISelectorWindow::isItemsAccessible(const QList<UIVMItem*> &items)
    1809 {
    1810     foreach (UIVMItem *pItem, items)
    1811         if (!pItem->accessible())
     1716bool UISelectorWindow::isItemsPoweredOff(const QList<UIVMItem*> &items)
     1717{
     1718    foreach (UIVMItem *pItem, items)
     1719        if (!isItemPoweredOff(pItem))
    18121720            return false;
    18131721    return true;
     
    18151723
    18161724/* static */
    1817 bool UISelectorWindow::isItemsInaccessible(const QList<UIVMItem*> &items)
     1725bool 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 */
     1752bool 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 */
     1767bool UISelectorWindow::isAtLeastOneItemAccessible(const QList<UIVMItem*> &items)
    18181768{
    18191769    foreach (UIVMItem *pItem, items)
    18201770        if (pItem->accessible())
    1821             return false;
    1822     return true;
     1771            return true;
     1772    return false;
    18231773}
    18241774
    18251775/* static */
    1826 bool UISelectorWindow::isItemsHasUnlockedSession(const QList<UIVMItem*> &items)
    1827 {
    1828     foreach (UIVMItem *pItem, items)
    1829         if (pItem->sessionState() != KSessionState_Unlocked)
    1830             return false;
    1831     return true;
     1776bool UISelectorWindow::isAtLeastOneItemInaccessible(const QList<UIVMItem*> &items)
     1777{
     1778    foreach (UIVMItem *pItem, items)
     1779        if (!pItem->accessible())
     1780            return true;
     1781    return false;
    18321782}
    18331783
    18341784/* 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;
     1785bool UISelectorWindow::isAtLeastOneItemRemovable(const QList<UIVMItem*> &items)
     1786{
     1787    foreach (UIVMItem *pItem, items)
     1788        if (!pItem->accessible() || isItemEditable(pItem))
     1789            return true;
     1790    return false;
    18511791}
    18521792
    18531793/* 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 
     1794bool 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 */
     1806bool 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 */
     1815bool 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 */
     1824bool 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 */
     1833bool UISelectorWindow::isItemEditable(UIVMItem *pItem)
     1834{
     1835    return pItem->accessible() &&
     1836           pItem->sessionState() == KSessionState_Unlocked;
     1837}
     1838
     1839/* static */
     1840bool UISelectorWindow::isItemSaved(UIVMItem *pItem)
     1841{
     1842    if (pItem->accessible() &&
     1843        pItem->machineState() == KMachineState_Saved)
     1844        return true;
     1845    return false;
     1846}
     1847
     1848/* static */
     1849bool 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 */
     1861bool UISelectorWindow::isItemStarted(UIVMItem *pItem)
     1862{
     1863    return isItemRunning(pItem) || isItemPaused(pItem);
     1864}
     1865
     1866/* static */
     1867bool 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 */
     1878bool 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 */
     1889bool 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  
    147147    /* Helpers: Action stuff: */
    148148    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);
    153149    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);
    154166
    155167    /* Central splitter window: */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette