VirtualBox

Changeset 45313 in vbox for trunk/src


Ignore:
Timestamp:
Apr 3, 2013 5:12:10 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Message-center cleanup (part 20): Global and selector stuff.

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

Legend:

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

    r45308 r45313  
    412412}
    413413
    414 void UIMessageCenter::cannotOpenSession(const CMachine &machine, const CProgress &progress /* = CProgress() */) const
    415 {
    416     /* Format error-info: */
    417     Assert(!machine.isOk() || !progress.isNull());
    418     QString strErrorInfo = !machine.isOk() ? formatErrorInfo(machine) :
    419                            !progress.isOk() ? formatErrorInfo(progress) :
    420                            formatErrorInfo(progress.GetErrorInfo());
    421     /* Compose machine name: */
    422     QString strName = machine.GetName();
    423     if (strName.isEmpty())
    424         strName = QFileInfo(machine.GetSettingsFilePath()).baseName();
     414void UIMessageCenter::cannotOpenSession(const CMachine &machine) const
     415{
     416    /* Preserve error-info: */
     417    QString strErrorInfo = formatErrorInfo(machine);
    425418    /* Show the message: */
    426419    message(mainWindowShown(), MessageType_Error,
    427420            tr("Failed to open a session for the virtual machine <b>%1</b>.")
    428                .arg(strName),
     421               .arg(machine.GetName()),
    429422            strErrorInfo);
     423}
     424
     425void UIMessageCenter::cannotOpenSession(const CProgress &progress, const QString &strMachineName) const
     426{
     427    message(mainWindowShown(), MessageType_Error,
     428            tr("Failed to open a session for the virtual machine <b>%1</b>.")
     429               .arg(strMachineName),
     430            !progress.isOk() ? formatErrorInfo(progress) : formatErrorInfo(progress.GetErrorInfo()));
    430431}
    431432
     
    603604            tr("Failed to remove the virtual machine <b>%1</b>.")
    604605               .arg(machine.GetName()),
    605             formatErrorInfo(progress.GetErrorInfo()));
     606            !progress.isOk() ? formatErrorInfo(progress) : formatErrorInfo(progress.GetErrorInfo()));
    606607}
    607608
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r45296 r45313  
    208208    void cannotFindMachineById(const CVirtualBox &vbox, const QString &strId) const;
    209209    void cannotOpenSession(const CSession &session) const;
    210     void cannotOpenSession(const CMachine &machine, const CProgress &progress = CProgress()) const;
     210    void cannotOpenSession(const CMachine &machine) const;
     211    void cannotOpenSession(const CProgress &progress, const QString &strMachineName) const;
    211212    void cannotGetMediaAccessibility(const UIMedium &medium) const;
    212213    void cannotOpenURL(const QString &strUrl) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r45292 r45313  
    17271727CSession VBoxGlobal::openSession(const QString &strId, KLockType lockType /* = KLockType_Shared */)
    17281728{
    1729     /* Create empty session instance: */
     1729    /* Prepare session: */
    17301730    CSession session;
    1731     session.createInstance(CLSID_Session);
    1732     if (session.isNull())
    1733     {
    1734         msgCenter().cannotOpenSession(session);
    1735         return session;
    1736     }
    1737 
    1738     /* Search for the corresponding machine: */
    1739     CMachine machine = mVBox.FindMachine(strId);
    1740     if (machine.isNull())
    1741     {
    1742         msgCenter().cannotFindMachineById(mVBox, strId);
    1743         return session;
    1744     }
    1745 
    1746     /* Lock found machine to session: */
    1747     machine.LockMachine(session, lockType);
    1748     if (!machine.isOk())
    1749     {
    1750         msgCenter().cannotOpenSession(machine);
     1731
     1732    /* Simulate try-catch block: */
     1733    bool fSuccess = false;
     1734    do
     1735    {
     1736        /* Create empty session instance: */
     1737        session.createInstance(CLSID_Session);
     1738        if (session.isNull())
     1739        {
     1740            msgCenter().cannotOpenSession(session);
     1741            break;
     1742        }
     1743
     1744        /* Search for the corresponding machine: */
     1745        CMachine machine = mVBox.FindMachine(strId);
     1746        if (machine.isNull())
     1747        {
     1748            msgCenter().cannotFindMachineById(mVBox, strId);
     1749            break;
     1750        }
     1751
     1752        /* Lock found machine to session: */
     1753        machine.LockMachine(session, lockType);
     1754        if (!machine.isOk())
     1755        {
     1756            msgCenter().cannotOpenSession(machine);
     1757            break;
     1758        }
     1759
     1760        /* Pass the language ID as the property to the guest: */
     1761        if (session.GetType() == KSessionType_Shared)
     1762        {
     1763            CMachine startedMachine = session.GetMachine();
     1764            /* Make sure that the language is in two letter code.
     1765             * Note: if languageId() returns an empty string lang.name() will
     1766             * return "C" which is an valid language code. */
     1767            QLocale lang(VBoxGlobal::languageId());
     1768            startedMachine.SetGuestPropertyValue("/VirtualBox/HostInfo/GUI/LanguageID", lang.name());
     1769        }
     1770
     1771        /* Success finally: */
     1772        fSuccess = true;
     1773    }
     1774    while (0);
     1775    /* Cleanup try-catch block: */
     1776    if (!fSuccess)
    17511777        session.detach();
    1752         return session;
    1753     }
    1754 
    1755     /* Pass the language ID as the property to the guest: */
    1756     if (session.GetType() == KSessionType_Shared)
    1757     {
    1758         CMachine startedMachine = session.GetMachine();
    1759         /* Make sure that the language is in two letter code.
    1760          * Note: if languageId() returns an empty string lang.name() will
    1761          * return "C" which is an valid language code. */
    1762         QLocale lang(VBoxGlobal::languageId());
    1763         startedMachine.SetGuestPropertyValue("/VirtualBox/HostInfo/GUI/LanguageID", lang.name());
    1764     }
    1765 
    1766     /* Return resulting session: */
     1778
     1779    /* Return session: */
    17671780    return session;
    17681781}
     
    49604973    int iSpawningDuration = 60000;
    49614974    msgCenter().showModalProgressDialog(progress, machine.GetName(), "", mainWindow(), iSpawningDuration);
    4962     if (progress.GetResultCode() != 0)
    4963         msgCenter().cannotOpenSession(machine, progress);
     4975    if (!progress.isOk() || progress.GetResultCode() != 0)
     4976        msgCenter().cannotOpenSession(progress, machine.GetName());
    49644977
    49654978    /* Unlock machine, close session: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r45296 r45313  
    14841484            /* And show cleanup progress finally: */
    14851485            msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_delete_90px.png");
    1486             if (progress.GetResultCode() != 0)
     1486            if (!progress.isOk() || progress.GetResultCode() != 0)
    14871487            {
    14881488                msgCenter().cannotRemoveMachine(machine, progress);
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