VirtualBox

Changeset 45275 in vbox for trunk/src


Ignore:
Timestamp:
Apr 2, 2013 6:04:05 AM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Message-center cleanup (part 12), reworking VBox global startup VM code a little.

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

Legend:

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

    r45274 r45275  
    409409}
    410410
    411 void UIMessageCenter::cannotOpenSession(const CVirtualBox &vbox, const CMachine &machine,
     411void UIMessageCenter::cannotOpenSession(const CMachine &machine,
    412412                                        const CProgress &progress /* = CProgress() */)
    413413{
    414     Assert(!vbox.isOk() || progress.isOk());
     414    /* Format error-info: */
     415    Assert(!machine.isOk() || !progress.isNull());
     416    QString strErrorInfo = !machine.isOk() ? formatErrorInfo(machine) :
     417                           !progress.isOk() ? formatErrorInfo(progress) :
     418                           formatErrorInfo(progress.GetErrorInfo());
    415419    /* Compose machine name: */
    416420    QString strName = machine.GetName();
     
    420424    message(mainWindowShown(), MessageType_Error,
    421425            tr("Failed to open a session for the virtual machine <b>%1</b>.").arg(strName),
    422             !vbox.isOk() ? formatErrorInfo(vbox) : formatErrorInfo(progress.GetErrorInfo()));
    423 }
    424 
    425 void UIMessageCenter::cannotOpenSession(const CMachine &machine)
    426 {
    427     /* Preserve error-info: */
    428     COMResult res(machine);
    429     /* Compose machine name: */
    430     QString strName = machine.GetName();
    431     if (strName.isEmpty())
    432         strName = QFileInfo(machine.GetSettingsFilePath()).baseName();
    433     /* Show the message: */
    434     message(mainWindowShown(), MessageType_Error,
    435             tr("Failed to open a session for the virtual machine <b>%1</b>.").arg(strName),
    436             formatErrorInfo(res));
     426            strErrorInfo);
    437427}
    438428
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r45271 r45275  
    205205    void cannotFindMachineById(const CVirtualBox &vbox, const QString &strId);
    206206    void cannotOpenSession(const CSession &session);
    207     void cannotOpenSession(const CVirtualBox &vbox, const CMachine &machine, const CProgress &progress = CProgress());
    208     void cannotOpenSession(const CMachine &machine);
     207    void cannotOpenSession(const CMachine &machine, const CProgress &progress = CProgress());
    209208    void cannotGetMediaAccessibility(const UIMedium &medium);
    210209    void cannotOpenURL(const QString &strUrl);
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r45272 r45275  
    17491749    {
    17501750        msgCenter().cannotOpenSession(machine);
    1751         session.detach();
    1752         return session;
    1753     }
    1754     else if (!mVBox.isOk())
    1755     {
    1756         msgCenter().cannotOpenSession(mVBox, machine);
    17571751        session.detach();
    17581752        return session;
     
    49154909bool VBoxGlobal::launchMachine(CMachine &machine, bool fHeadless /* = false */)
    49164910{
     4911    /* Switch to machine window(s) if possible: */
    49174912    if (machine.CanShowConsoleWindow())
    49184913        return VBoxGlobal::switchToMachine(machine);
    49194914
     4915    /* Make sure machine-state is one of required: */
    49204916    KMachineState state = machine.GetState(); NOREF(state);
    49214917    AssertMsg(   state == KMachineState_PoweredOff
     
    49234919              || state == KMachineState_Teleported
    49244920              || state == KMachineState_Aborted
    4925               , ("Machine must be PoweredOff/Saved/Aborted (%d)", state));
    4926 
    4927     CVirtualBox vbox = vboxGlobal().virtualBox();
     4921              , ("Machine must be PoweredOff/Saved/Teleported/Aborted (%d)", state));
     4922
     4923    /* Create empty session instance: */
    49284924    CSession session;
    49294925    session.createInstance(CLSID_Session);
     
    49344930    }
    49354931
    4936 #if defined(Q_OS_WIN32)
    4937     /* allow the started VM process to make itself the foreground window */
     4932    /* Configure environment: */
     4933    QString strEnv;
     4934#ifdef Q_OS_WIN
     4935    /* Allow started VM process to be foreground window: */
    49384936    AllowSetForegroundWindow(ASFW_ANY);
    4939 #endif
    4940 
    4941     QString env;
    4942 #if defined(Q_WS_X11)
    4943     /* make sure the VM process will start on the same display as the Selector */
    4944     const char *display = RTEnvGet("DISPLAY");
    4945     if (display)
    4946         env.append(QString("DISPLAY=%1\n").arg(display));
    4947     const char *xauth = RTEnvGet("XAUTHORITY");
    4948     if (xauth)
    4949         env.append(QString("XAUTHORITY=%1\n").arg(xauth));
    4950 #endif
     4937#endif /* Q_OS_WIN */
     4938#ifdef Q_WS_X11
     4939    /* Make sure VM process will start on the same display as the VM selector: */
     4940    const char *pDisplay = RTEnvGet("DISPLAY");
     4941    if (pDisplay)
     4942        strEnv.append(QString("DISPLAY=%1\n").arg(pDisplay));
     4943    const char *pXauth = RTEnvGet("XAUTHORITY");
     4944    if (pXauth)
     4945        strEnv.append(QString("XAUTHORITY=%1\n").arg(pXauth));
     4946#endif /* Q_WS_X11 */
    49514947    const QString strType = fHeadless ? "headless" : "";
    49524948
    4953     CProgress progress = machine.LaunchVMProcess(session, strType, env);
    4954     if (   !vbox.isOk()
    4955         || progress.isNull())
    4956     {
    4957         msgCenter().cannotOpenSession(vbox, machine);
     4949    /* Prepare "VM spawning" progress: */
     4950    CProgress progress = machine.LaunchVMProcess(session, strType, strEnv);
     4951    if (!machine.isOk())
     4952    {
     4953        msgCenter().cannotOpenSession(machine);
    49584954        return false;
    49594955    }
    49604956
    4961     /* Hide the "VM spawning" progress dialog */
    4962     /* I hope 1 minute will be enough to spawn any running VM silently, isn't it? */
     4957    /* Postpone showing "VM spawning" progress.
     4958     * Hope 1 minute will be enough to spawn any running VM silently,
     4959     * otherwise we better show the progress... */
    49634960    int iSpawningDuration = 60000;
    49644961    msgCenter().showModalProgressDialog(progress, machine.GetName(), "", mainWindow(), iSpawningDuration);
    49654962    if (progress.GetResultCode() != 0)
    4966         msgCenter().cannotOpenSession(vbox, machine, progress);
    4967 
     4963        msgCenter().cannotOpenSession(machine, progress);
     4964
     4965    /* Unlock machine, close session: */
    49684966    session.UnlockMachine();
    49694967
     4968    /* True finally: */
    49704969    return true;
    49714970}
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