VirtualBox

Changeset 45278 in vbox


Ignore:
Timestamp:
Apr 2, 2013 8:54:33 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84672
Message:

FE/Qt: Message-center cleanup (part 13).

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r45277 r45278  
    443443}
    444444
    445 void UIMessageCenter::cannotOpenMachine(QWidget *pParent, const QString &strMachinePath, const CVirtualBox &vbox)
    446 {
    447     message(pParent ? pParent : mainWindowShown(),
    448             MessageType_Error,
    449             tr("Failed to open virtual machine located in %1.")
    450                .arg(strMachinePath),
     445void UIMessageCenter::cannotOpenMachine(const CVirtualBox &vbox, const QString &strMachinePath)
     446{
     447    message(mainWindowShown(), MessageType_Error,
     448            tr("Failed to open virtual machine located in %1.").arg(strMachinePath),
    451449            formatErrorInfo(vbox));
    452450}
    453451
    454 void UIMessageCenter::cannotReregisterMachine(QWidget *pParent, const QString &strMachinePath, const QString &strMachineName)
    455 {
    456     message(pParent ? pParent : mainWindowShown(),
    457             MessageType_Error,
     452void UIMessageCenter::cannotReregisterExistingMachine(const QString &strMachinePath, const QString &strMachineName)
     453{
     454    message(mainWindowShown(), MessageType_Error,
    458455            tr("Failed to add virtual machine <b>%1</b> located in <i>%2</i> because its already present.")
    459456               .arg(strMachineName).arg(strMachinePath));
     
    462459void UIMessageCenter::cannotDeleteMachine(const CMachine &machine)
    463460{
    464     /* preserve the current error info before calling the object again */
     461    /* Preserve error-info: */
    465462    COMResult res(machine);
    466 
     463    /* Show the message: */
    467464    message(mainWindowShown(),
    468465            MessageType_Error,
     
    532529}
    533530
    534 int UIMessageCenter::confirmMachineDeletion(const QList<CMachine> &machines)
    535 {
    536     /* Enumerate VMs: */
    537     int cInacessibleVMCount = 0;
    538     bool fVMWithHDPresent = false;
    539     QString strVMNames;
    540     for (int i = 0; i < machines.size(); ++i)
    541     {
    542         /* Get iterated VM: */
    543         const CMachine &machine = machines[i];
    544         /* Prepare VM name: */
     531int UIMessageCenter::confirmMachineRemoval(const QList<CMachine> &machines)
     532{
     533    /* Enumerate the machines: */
     534    int cInacessibleMachineCount = 0;
     535    bool fMachineWithHardDiskPresent = false;
     536    QString strMachineNames;
     537    foreach (const CMachine &machine, machines)
     538    {
     539        /* Prepare machine name: */
    545540        QString strMachineName;
    546541        if (machine.GetAccessible())
    547542        {
    548             /* Get VM name: */
     543            /* Just get machine name: */
    549544            strMachineName = machine.GetName();
    550             /* Enumerate attachments: */
     545            /* Enumerate the attachments: */
    551546            const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
    552             for (int i = 0; !fVMWithHDPresent && i < attachments.size(); ++i)
     547            foreach (const CMediumAttachment &attachment, attachments)
    553548            {
    554                 /* Get current attachment: */
    555                 const CMediumAttachment &attachment = attachments.at(i);
    556549                /* Check if the medium is a hard disk: */
    557550                if (attachment.GetType() == KDeviceType_HardDisk)
     
    559552                    /* Check if that hard disk isn't shared.
    560553                     * If hard disk is shared, it will *never* be deleted: */
    561                     QVector<QString> ids = attachment.GetMedium().GetMachineIds();
    562                     if (ids.size() == 1)
     554                    QVector<QString> usedMachineList = attachment.GetMedium().GetMachineIds();
     555                    if (usedMachineList.size() == 1)
    563556                    {
    564                         fVMWithHDPresent = true;
     557                        fMachineWithHardDiskPresent = true;
    565558                        break;
    566559                    }
     
    570563        else
    571564        {
    572             /* Get VM name: */
     565            /* Compose machine name: */
    573566            QFileInfo fi(machine.GetSettingsFilePath());
    574567            strMachineName = VBoxGlobal::hasAllowedExtension(fi.completeSuffix(), VBoxFileExts) ? fi.completeBaseName() : fi.fileName();
    575             /* Increment inacessible VM count: */
    576             ++cInacessibleVMCount;
     568            /* Increment inacessible machine count: */
     569            ++cInacessibleMachineCount;
    577570        }
    578 
    579         /* Compose VM name list: */
    580         strVMNames += QString(strVMNames.isEmpty() ? "<b>%1</b>" : ", <b>%1</b>").arg(strMachineName);
     571        /* Append machine name to the full name string: */
     572        strMachineNames += QString(strMachineNames.isEmpty() ? "<b>%1</b>" : ", <b>%1</b>").arg(strMachineName);
    581573    }
    582574
    583575    /* Prepare message text: */
    584     QString strText = cInacessibleVMCount == machines.size() ?
     576    QString strText = cInacessibleMachineCount == machines.size() ?
    585577                      tr("<p>You are about to remove following inaccessible virtual machines from the machine list:</p>"
    586578                         "<p>%1</p>"
    587579                         "<p>Do you wish to proceed?</p>")
    588                          .arg(strVMNames) :
    589                       fVMWithHDPresent ?
     580                         .arg(strMachineNames) :
     581                      fMachineWithHardDiskPresent ?
    590582                      tr("<p>You are about to remove following virtual machines from the machine list:</p>"
    591583                         "<p>%1</p>"
     
    593585                         "Doing this will also remove the files containing the machine's virtual hard disks "
    594586                         "if they are not in use by another machine.</p>")
    595                          .arg(strVMNames) :
     587                         .arg(strMachineNames) :
    596588                      tr("<p>You are about to remove following virtual machines from the machine list:</p>"
    597589                         "<p>%1</p>"
    598590                         "<p>Would you like to delete the files containing the virtual machine from your hard disk as well?</p>")
    599                          .arg(strVMNames);
     591                         .arg(strMachineNames);
    600592
    601593    /* Prepare message itself: */
    602     return cInacessibleVMCount == machines.size() ?
    603            message(&vboxGlobal().selectorWnd(),
     594    return cInacessibleMachineCount == machines.size() ?
     595           message(mainWindowShown(),
    604596                   MessageType_Question,
    605597                   strText,
     
    609601                   0,
    610602                   tr("Remove")) :
    611            message(&vboxGlobal().selectorWnd(),
     603           message(mainWindowShown(),
    612604                   MessageType_Question,
    613605                   strText,
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r45275 r45278  
    210210
    211211    /* API: Selector warnings: */
    212     void cannotOpenMachine(QWidget *pParent, const QString &strMachinePath, const CVirtualBox &vbox);
    213     void cannotReregisterMachine(QWidget *pParent, const QString &strMachinePath, const QString &strMachineName);
     212    void cannotOpenMachine(const CVirtualBox &vbox, const QString &strMachinePath);
     213    void cannotReregisterExistingMachine(const QString &strMachinePath, const QString &strMachineName);
    214214    void cannotDeleteMachine(const CMachine &machine);
    215215    void cannotDeleteMachine(const CMachine &machine, const CProgress &progress);
     
    218218    int askAboutCollisionOnGroupRemoving(const QString &strName, const QString &strGroupName);
    219219    int confirmMachineItemRemoval(const QStringList &names);
    220     int confirmMachineDeletion(const QList<CMachine> &machines);
     220    int confirmMachineRemoval(const QList<CMachine> &machines);
    221221    bool confirmDiscardSavedState(const QString &strNames);
    222222    void cannotSetGroups(const CMachine &machine);
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r45270 r45278  
    355355    if (!vbox.isOk() || newMachine.isNull())
    356356    {
    357         msgCenter().cannotOpenMachine(this, strTmpFile, vbox);
     357        msgCenter().cannotOpenMachine(vbox, strTmpFile);
    358358        return;
    359359    }
     
    363363    if (!oldMachine.isNull())
    364364    {
    365         msgCenter().cannotReregisterMachine(this, strTmpFile, oldMachine.GetName());
     365        msgCenter().cannotReregisterExistingMachine(strTmpFile, oldMachine.GetName());
    366366        return;
    367367    }
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r45273 r45278  
    14571457    }
    14581458
    1459     /* Show machine remove dialog: */
    1460     int rc = msgCenter().confirmMachineDeletion(machines);
    1461     if (rc != QIMessageBox::Cancel)
    1462     {
    1463         /* For every selected item: */
    1464         foreach (CMachine machine, machines)
     1459    /* Confirm machine removal: */
     1460    int iResultCode = msgCenter().confirmMachineRemoval(machines);
     1461    if (iResultCode == QIMessageBox::Cancel)
     1462        return;
     1463
     1464    /* For every selected item: */
     1465    for (int iMachineIndex = 0; iMachineIndex < machines.size(); ++iMachineIndex)
     1466    {
     1467        /* Get iterated machine: */
     1468        CMachine &machine = machines[iMachineIndex];
     1469        if (iResultCode == QIMessageBox::Yes)
    14651470        {
    1466             if (rc == QIMessageBox::Yes)
     1471            /* Unregister machine first: */
     1472            CMediumVector mediums = machine.Unregister(KCleanupMode_DetachAllReturnHardDisksOnly);
     1473            if (!machine.isOk())
    14671474            {
    1468                 /* Unregister and cleanup machine's data & hard-disks: */
    1469                 CMediumVector mediums = machine.Unregister(KCleanupMode_DetachAllReturnHardDisksOnly);
    1470                 if (machine.isOk())
    1471                 {
    1472                     /* Delete machine hard-disks: */
    1473                     CProgress progress = machine.DeleteConfig(mediums);
    1474                     if (machine.isOk())
    1475                     {
    1476                         msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_delete_90px.png", msgCenter().mainWindowShown());
    1477                         if (progress.GetResultCode() != 0)
    1478                             msgCenter().cannotDeleteMachine(machine, progress);
    1479                     }
    1480                 }
    1481                 if (!machine.isOk())
    1482                     msgCenter().cannotDeleteMachine(machine);
     1475                msgCenter().cannotDeleteMachine(machine);
     1476                continue;
    14831477            }
    1484             else
     1478            /* Prepare cleanup progress: */
     1479            CProgress progress = machine.DeleteConfig(mediums);
     1480            if (!machine.isOk())
    14851481            {
    1486                 /* Just unregister machine: */
    1487                 machine.Unregister(KCleanupMode_DetachAllReturnNone);
    1488                 if (!machine.isOk())
    1489                     msgCenter().cannotDeleteMachine(machine);
     1482                msgCenter().cannotDeleteMachine(machine);
     1483                continue;
     1484            }
     1485            /* And show cleanup progress finally: */
     1486            msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_delete_90px.png");
     1487            if (progress.GetResultCode() != 0)
     1488            {
     1489                msgCenter().cannotDeleteMachine(machine, progress);
     1490                continue;
     1491            }
     1492        }
     1493        else
     1494        {
     1495            /* Just unregister machine: */
     1496            machine.Unregister(KCleanupMode_DetachAllReturnNone);
     1497            if (!machine.isOk())
     1498            {
     1499                msgCenter().cannotDeleteMachine(machine);
     1500                continue;
    14901501            }
    14911502        }
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