VirtualBox

Ignore:
Timestamp:
Apr 9, 2013 2:05:22 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Main.cpp cleanup (part 1).

File:
1 edited

Legend:

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

    r45377 r45435  
    525525#ifndef VBOX_WITH_HARDENING
    526526
    527 int main (int argc, char **argv, char **envp)
     527int main(int argc, char **argv, char **envp)
    528528{
    529     /* Initialize VBox Runtime. Initialize the SUPLib as well only if we
    530      * are really about to start a VM. Don't do this if we are only starting
    531      * the selector window. */
     529    /* Initialize VBox Runtime.
     530     * Initialize the SUPLib as well only if we are really about to start a VM.
     531     * Don't do this if we are only starting the selector window. */
    532532    bool fInitSUPLib = false;
    533     for (int i = 1; i < argc; i++)
     533    for (int i = 1; i < argc; ++i)
    534534    {
    535535        /* NOTE: the check here must match the corresponding check for the
     
    543543        }
    544544    }
    545 
    546545    int rc = RTR3InitExe(argc, &argv, fInitSUPLib ? RTR3INIT_FLAGS_SUPLIB : 0);
     546
     547    /* Initialization failed: */
    547548    if (RT_FAILURE(rc))
    548549    {
    549         QApplication a (argc, &argv[0]);
     550        /* We have to create QApplication anyway
     551         * just to show the only one error-message: */
     552        QApplication a(argc, &argv[0]);
    550553#ifdef Q_OS_SOLARIS
    551         /* Use plastique look 'n feel for Solaris instead of the default motif (Qt 4.7.x) */
    552         QApplication::setStyle (new QPlastiqueStyle);
    553 #endif
    554         QString msgTitle = QApplication::tr ("VirtualBox - Runtime Error");
    555         QString msgText = "<html>";
    556 
     554        /* Use plastique look&feel for Solaris instead of the default motif (Qt 4.7.x): */
     555        QApplication::setStyle(new QPlastiqueStyle);
     556#endif /* Q_OS_SOLARIS */
     557
     558        /* Prepare the error-message: */
     559        QString strTitle = QApplication::tr("VirtualBox - Runtime Error");
     560        QString strText = "<html>";
    557561        switch (rc)
    558562        {
    559563            case VERR_VM_DRIVER_NOT_INSTALLED:
    560564            case VERR_VM_DRIVER_LOAD_ERROR:
    561                 msgText += QApplication::tr (
    562                         "<b>Cannot access the kernel driver!</b><br/><br/>");
     565                strText += QApplication::tr("<b>Cannot access the kernel driver!</b><br/><br/>");
    563566# ifdef RT_OS_LINUX
    564                 msgText += g_QStrHintLinuxNoDriver;
    565 # else
    566                 msgText += g_QStrHintOtherNoDriver;
    567 # endif
     567                strText += g_QStrHintLinuxNoDriver;
     568# else /* RT_OS_LINUX */
     569                strText += g_QStrHintOtherNoDriver;
     570# endif /* !RT_OS_LINUX */
    568571                break;
    569572# ifdef RT_OS_LINUX
    570573            case VERR_NO_MEMORY:
    571                 msgText += g_QStrHintLinuxNoMemory;
     574                strText += g_QStrHintLinuxNoMemory;
    572575                break;
    573 # endif
     576# endif /* RT_OS_LINUX */
    574577            case VERR_VM_DRIVER_NOT_ACCESSIBLE:
    575                 msgText += QApplication::tr ("Kernel driver not accessible");
     578                strText += QApplication::tr("Kernel driver not accessible");
    576579                break;
    577580            case VERR_VM_DRIVER_VERSION_MISMATCH:
    578581# ifdef RT_OS_LINUX
    579                 msgText += g_QStrHintLinuxWrongDriverVersion;
    580 # else
    581                 msgText += g_QStrHintOtherWrongDriverVersion;
    582 # endif
     582                strText += g_QStrHintLinuxWrongDriverVersion;
     583# else /* RT_OS_LINUX */
     584                strText += g_QStrHintOtherWrongDriverVersion;
     585# endif /* !RT_OS_LINUX */
    583586                break;
    584587            default:
    585                 msgText += QApplication::tr (
    586                         "Unknown error %2 during initialization of the Runtime"
    587                         ).arg (rc);
     588                strText += QApplication::tr("Unknown error %2 during initialization of the Runtime").arg(rc);
    588589                break;
    589590        }
    590         msgText += "</html>";
    591         QMessageBox::critical (
    592                                0,                      /* parent */
    593                                msgTitle,
    594                                msgText,
    595                                QMessageBox::Abort,     /* button0 */
    596                                0);                     /* button1 */
     591        strText += "</html>";
     592
     593        /* Show the error-message: */
     594        QMessageBox::critical(0 /* parent */, strTitle, strText,
     595                              QMessageBox::Abort /* 1st button */, 0 /* 2nd button */);
     596
     597        /* Default error-result: */
    597598        return 1;
    598599    }
    599600
    600     return TrustedMain (argc, argv, envp);
     601    /* Actual main function: */
     602    return TrustedMain(argc, argv, envp);
    601603}
    602604
    603605#else  /* VBOX_WITH_HARDENING */
    604606
    605 /**
    606  * Hardened main failed, report the error without any unnecessary fuzz.
    607  *
    608  * @remarks Do not call IPRT here unless really required, it might not be
    609  *          initialized.
    610  */
    611 extern "C" DECLEXPORT(void) TrustedError (const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va)
     607extern "C" DECLEXPORT(void) TrustedError(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va)
    612608{
    613 # if defined(RT_OS_DARWIN)
     609# ifdef RT_OS_DARWIN
    614610    ShutUpAppKit();
    615 # endif
    616 
    617     /*
    618      * Init the Qt application object. This is a bit hackish as we
    619      * don't have the argument vector handy.
    620      */
     611# endif /* RT_OS_DARWIN */
     612
     613    /* We have to create QApplication anyway just to show the only one error-message.
     614     * This is a bit hackish as we don't have the argument vector handy. */
    621615    int argc = 0;
    622616    char *argv[2] = { NULL, NULL };
    623     QApplication a (argc, &argv[0]);
    624 
    625     /*
    626      * Compose and show the error message.
    627      */
    628     QString msgTitle = QApplication::tr ("VirtualBox - Error In %1").arg (pszWhere);
    629 
     617    QApplication a(argc, &argv[0]);
     618
     619    /* Prepare the error-message: */
     620    QString strTitle = QApplication::tr("VirtualBox - Error In %1").arg(pszWhere);
    630621    char msgBuf[1024];
    631     vsprintf (msgBuf, pszMsgFmt, va);
    632 
    633     QString msgText = QApplication::tr (
    634             "<html><b>%1 (rc=%2)</b><br/><br/>").arg (msgBuf).arg (rc);
     622    vsprintf(msgBuf, pszMsgFmt, va);
     623    QString strText = QApplication::tr("<html><b>%1 (rc=%2)</b><br/><br/>").arg(msgBuf).arg(rc);
    635624    switch (enmWhat)
    636625    {
    637626        case kSupInitOp_Driver:
    638627# ifdef RT_OS_LINUX
    639             msgText += g_QStrHintLinuxNoDriver;
    640 # else
    641             msgText += g_QStrHintOtherNoDriver;
    642 # endif
     628            strText += g_QStrHintLinuxNoDriver;
     629# else /* RT_OS_LINUX */
     630            strText += g_QStrHintOtherNoDriver;
     631# endif /* !RT_OS_LINUX */
    643632            break;
    644633# ifdef RT_OS_LINUX
    645634        case kSupInitOp_IPRT:
    646635            if (rc == VERR_NO_MEMORY)
    647                 msgText += g_QStrHintLinuxNoMemory;
     636                strText += g_QStrHintLinuxNoMemory;
    648637            else
    649 # endif
     638# endif /* RT_OS_LINUX */
    650639            if (rc == VERR_VM_DRIVER_VERSION_MISMATCH)
    651640# ifdef RT_OS_LINUX
    652                 msgText += g_QStrHintLinuxWrongDriverVersion;
    653 # else
    654                 msgText += g_QStrHintOtherWrongDriverVersion;
    655 # endif
     641                strText += g_QStrHintLinuxWrongDriverVersion;
     642# else /* RT_OS_LINUX */
     643                strText += g_QStrHintOtherWrongDriverVersion;
     644# endif /* !RT_OS_LINUX */
    656645            else
    657                 msgText += g_QStrHintReinstall;
     646                strText += g_QStrHintReinstall;
    658647            break;
    659648        case kSupInitOp_Integrity:
    660649        case kSupInitOp_RootCheck:
    661             msgText += g_QStrHintReinstall;
     650            strText += g_QStrHintReinstall;
    662651            break;
    663652        default:
     
    665654            break;
    666655    }
    667     msgText += "</html>";
     656    strText += "</html>";
    668657
    669658# ifdef RT_OS_LINUX
     659    /* We have to to make sure that we display the error-message
     660     * after the parent displayed its own message. */
    670661    sleep(2);
    671 # endif
    672     QMessageBox::critical (
    673         0,                      /* parent */
    674         msgTitle,               /* title */
    675         msgText,                /* text */
    676         QMessageBox::Abort,     /* button0 */
    677         0);                     /* button1 */
    678     qFatal ("%s", msgText.toAscii().constData());
     662# endif /* RT_OS_LINUX */
     663
     664    QMessageBox::critical(0 /* parent */, strTitle, strText,
     665                          QMessageBox::Abort /* 1st button */, 0 /* 2nd button */);
     666    qFatal("%s", strText.toAscii().constData());
    679667}
    680668
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