VirtualBox

Changeset 45271 in vbox


Ignore:
Timestamp:
Apr 1, 2013 12:03:35 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84661
Message:

FE/Qt: Global: Open-session mechanism cleanup/rework.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/globals
Files:
3 edited

Legend:

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

    r45270 r45271  
    386386}
    387387
    388 void UIMessageCenter::cannotFindMachineByName(const CVirtualBox &vbox, const QString &name)
     388void UIMessageCenter::cannotFindMachineByName(const CVirtualBox &vbox, const QString &strName)
    389389{
    390390    message(0, MessageType_Error,
    391             tr("There is no virtual machine named <b>%1</b>.").arg(name),
     391            tr("There is no virtual machine named <b>%1</b>.").arg(strName),
     392            formatErrorInfo(vbox));
     393}
     394
     395void UIMessageCenter::cannotFindMachineById(const CVirtualBox &vbox, const QString &strId)
     396{
     397    message(0, MessageType_Error,
     398            tr("There is no virtual machine with id <b>%1</b>.").arg(strId),
    392399            formatErrorInfo(vbox));
    393400}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r45270 r45271  
    202202    void cannotLoadGlobalConfig(const CVirtualBox &vbox, const QString &strError);
    203203    void cannotSaveGlobalConfig(const CVirtualBox &vbox);
    204     void cannotFindMachineByName(const CVirtualBox &vbox, const QString &name);
     204    void cannotFindMachineByName(const CVirtualBox &vbox, const QString &strName);
     205    void cannotFindMachineById(const CVirtualBox &vbox, const QString &strId);
    205206    void cannotOpenSession(const CSession &session);
    206207    void cannotOpenSession(const CVirtualBox &vbox, const CMachine &machine, const CProgress &progress = CProgress());
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r45269 r45271  
    17251725}
    17261726
    1727 /**
    1728  *  Opens a direct session for a machine with the given ID.
    1729  *  This method does user-friendly error handling (display error messages, etc.).
    1730  *  and returns a null CSession object in case of any error.
    1731  *  If this method succeeds, don't forget to close the returned session when
    1732  *  it is no more necessary.
    1733  *
    1734  *  @param aId          Machine ID.
    1735  *  @param aLockType    @c KLockType_Shared to open an existing session with
    1736  *                      the machine which is already running, @c KLockType_Write
    1737  *                      to open a new direct session, @c KLockType_VM to open
    1738  *                      a new session for running a VM in this process.
    1739  */
    1740 CSession VBoxGlobal::openSession(const QString &aId, KLockType aLockType /* = KLockType_Shared */)
    1741 {
     1727CSession VBoxGlobal::openSession(const QString &strId, KLockType lockType /* = KLockType_Shared */)
     1728{
     1729    /* Create empty session instance: */
    17421730    CSession session;
    17431731    session.createInstance(CLSID_Session);
    17441732    if (session.isNull())
    17451733    {
    1746         msgCenter().cannotOpenSession (session);
     1734        msgCenter().cannotOpenSession(session);
    17471735        return session;
    17481736    }
    17491737
    1750     CMachine foundMachine = CVirtualBox(mVBox).FindMachine(aId);
    1751     if (!foundMachine.isNull())
    1752     {
    1753         foundMachine.LockMachine(session, aLockType);
    1754         if (session.GetType() == KSessionType_Shared)
    1755         {
    1756             CMachine machine = session.GetMachine();
    1757             /* Make sure that the language is in two letter code.
    1758              * Note: if languageId() returns an empty string lang.name() will
    1759              * return "C" which is an valid language code. */
    1760             QLocale lang(VBoxGlobal::languageId());
    1761             machine.SetGuestPropertyValue ("/VirtualBox/HostInfo/GUI/LanguageID", lang.name());
    1762         }
    1763     }
    1764 
    1765     if (!foundMachine.isOk())
    1766     {
    1767         msgCenter().cannotOpenSession(foundMachine);
     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
     1749    /* Pass the language ID as the property to the guest: */
     1750    if (session.GetType() == KSessionType_Shared)
     1751    {
     1752        CMachine startedMachine = session.GetMachine();
     1753        /* Make sure that the language is in two letter code.
     1754         * Note: if languageId() returns an empty string lang.name() will
     1755         * return "C" which is an valid language code. */
     1756        QLocale lang(VBoxGlobal::languageId());
     1757        startedMachine.SetGuestPropertyValue("/VirtualBox/HostInfo/GUI/LanguageID", lang.name());
     1758    }
     1759
     1760    /* Show locking errors if any: */
     1761    if (!machine.isOk())
     1762    {
     1763        msgCenter().cannotOpenSession(machine);
    17681764        session.detach();
    17691765    }
    17701766    else if (!mVBox.isOk())
    17711767    {
    1772         msgCenter().cannotOpenSession(mVBox, foundMachine);
     1768        msgCenter().cannotOpenSession(mVBox, machine);
    17731769        session.detach();
    17741770    }
    17751771
     1772    /* Return resulting session: */
    17761773    return session;
    17771774}
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