VirtualBox

Changeset 45439 in vbox for trunk/src/VBox/Frontends


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

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

File:
1 edited

Legend:

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

    r45435 r45439  
    299299}
    300300
    301 extern "C" DECLEXPORT(int) TrustedMain (int argc, char **argv, char ** /*envp*/)
     301extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char ** /*envp*/)
    302302{
     303    /* Start logging: */
    303304    LogFlowFuncEnter();
    304 # if defined(RT_OS_DARWIN)
     305
     306# ifdef RT_OS_DARWIN
    305307    ShutUpAppKit();
    306 # endif
    307 
     308# endif /* RT_OS_DARWIN */
     309
     310    /* Console help preprocessing: */
    308311    for (int i=0; i<argc; i++)
    309312        if (   !strcmp(argv[i], "-h")
     
    317320
    318321#if defined(DEBUG) && defined(Q_WS_X11) && defined(RT_OS_LINUX)
    319     /* install our signal handler to backtrace the call stack */
     322    /* Install our signal handler to backtrace the call stack: */
    320323    struct sigaction sa;
    321324    sa.sa_sigaction = bt_sighandler;
    322     sigemptyset (&sa.sa_mask);
     325    sigemptyset(&sa.sa_mask);
    323326    sa.sa_flags = SA_RESTART | SA_SIGINFO;
    324     sigaction (SIGSEGV, &sa, NULL);
    325     sigaction (SIGBUS, &sa, NULL);
    326     sigaction (SIGUSR1, &sa, NULL);
     327    sigaction(SIGSEGV, &sa, NULL);
     328    sigaction(SIGBUS, &sa, NULL);
     329    sigaction(SIGUSR1, &sa, NULL);
    327330#endif
    328331
     
    331334     * forces NSApplication to be instantiated. */
    332335    UICocoaApplication::instance();
    333 #endif
    334 
    335     qInstallMsgHandler (QtMessageOutput);
     336#endif /* QT_MAC_USE_COCOA */
     337
     338    qInstallMsgHandler(QtMessageOutput);
    336339
    337340    int rc = 1; /* failure */
    338341
    339     /* scope the QApplication variable */
     342    /* Scope the QApplication variable: */
    340343    {
    341344#ifdef Q_WS_X11
    342345        /* Qt has a complex algorithm for selecting the right visual which
    343          * doesn't always seem to work.  So we naively choose a visual - the
    344          * default one - ourselves and pass that to Qt.  This means that we
     346         * doesn't always seem to work. So we naively choose a visual - the
     347         * default one - ourselves and pass that to Qt. This means that we
    345348         * also have to open the display ourselves.
    346349         * We check the Qt parameter list and handle Qt's -display argument
    347          * ourselves, since we open the display connection.  We also check the
     350         * ourselves, since we open the display connection. We also check the
    348351         * to see if the user has passed Qt's -visual parameter, and if so we
    349352         * assume that the user wants Qt to handle visual selection after all,
     
    354357        {
    355358            if (!::strcmp(argv[i], "-display") && (i + 1 < argc))
    356             /* What if it isn't?  Rely on QApplication to complain? */
     359            /* What if it isn't? Rely on QApplication to complain? */
    357360            {
    358361                pszDisplay = argv[i + 1];
     
    373376                          ? DefaultVisual(pDisplay, DefaultScreen(pDisplay))
    374377                          : NULL;
    375         /* Now create the application object */
    376         QApplication a (pDisplay, argc, argv, (Qt::HANDLE) pVisual);
     378        /* Now create the application object: */
     379        QApplication a(pDisplay, argc, argv, (Qt::HANDLE)pVisual);
    377380#else /* Q_WS_X11 */
    378         QApplication a (argc, argv);
     381        QApplication a(argc, argv);
    379382#endif /* Q_WS_X11 */
    380383
    381         UIModalWindowManager::create();
    382 
    383         /* Qt4.3 version has the QProcess bug which freezing the application
    384          * for 30 seconds. This bug is internally used at initialization of
    385          * Cleanlooks style. So we have to change this style to another one.
    386          * See http://trolltech.com/developer/task-tracker/index_html?id=179200&method=entry
    387          * for details. */
    388         if (VBoxGlobal::qtRTVersionString().startsWith ("4.3") &&
    389             qobject_cast <QCleanlooksStyle*> (QApplication::style()))
    390             QApplication::setStyle (new QPlastiqueStyle);
    391 
    392384#ifdef Q_OS_SOLARIS
    393         /* Use plastique look 'n feel for Solaris instead of the default motif (Qt 4.7.x) */
    394         QApplication::setStyle (new QPlastiqueStyle);
    395 #endif
     385        /* Use plastique look&feel for Solaris instead of the default motif (Qt 4.7.x): */
     386        QApplication::setStyle(new QPlastiqueStyle);
     387#endif /* Q_OS_SOLARIS */
    396388
    397389#ifdef Q_WS_X11
    398390        /* This patch is not used for now on Solaris & OpenSolaris because
    399391         * there is no anti-aliasing enabled by default, Qt4 to be rebuilt. */
    400 #ifndef Q_OS_SOLARIS
     392# ifndef Q_OS_SOLARIS
    401393        /* Cause Qt4 has the conflict with fontconfig application as a result
    402394         * sometimes substituting some fonts with non scaleable-anti-aliased
     
    405397        QFontDatabase fontDataBase;
    406398
    407         QString currentFamily (QApplication::font().family());
    408         bool isCurrentScaleable = fontDataBase.isScalable (currentFamily);
    409 
    410         /*
    411         LogFlowFunc (("Font: Current family is '%s'. It is %s.\n",
    412             currentFamily.toLatin1().constData(),
    413             isCurrentScaleable ? "scalable" : "not scalable"));
    414         QStringList subFamilies (QFont::substitutes (currentFamily));
    415         foreach (QString sub, subFamilies)
    416         {
    417             bool isSubScalable = fontDataBase.isScalable (sub);
    418             LogFlowFunc (("Font: Substitute family is '%s'. It is %s.\n",
    419                 sub.toLatin1().constData(),
    420                 isSubScalable ? "scalable" : "not scalable"));
    421         }
    422         */
     399        QString currentFamily(QApplication::font().family());
     400        bool isCurrentScaleable = fontDataBase.isScalable(currentFamily);
    423401
    424402        QString subFamily (QFont::substitute (currentFamily));
     
    427405        if (isCurrentScaleable && !isSubScaleable)
    428406            QFont::removeSubstitution (currentFamily);
    429 #endif /* Q_OS_SOLARIS */
    430 #endif
     407# endif /* Q_OS_SOLARIS */
     408#endif /* Q_WS_X11 */
    431409
    432410#ifdef Q_WS_WIN
     
    437415         * load and slows down the load process that happens on the main GUI
    438416         * thread to several seconds). */
    439         PlaySound (NULL, NULL, 0);
    440 #endif
     417        PlaySound(NULL, NULL, 0);
     418#endif /* Q_WS_WIN */
    441419
    442420#ifdef Q_WS_MAC
     421        /* Disable menu icons on MacOS X host: */
    443422        ::darwinDisableIconsInMenus();
    444423#endif /* Q_WS_MAC */
    445424
    446425#ifdef Q_WS_X11
    447         /* version check (major.minor are sensitive, fix number is ignored) */
     426        /* Qt version check (major.minor are sensitive, fix number is ignored): */
    448427        if (VBoxGlobal::qtRTVersion() < (VBoxGlobal::qtCTVersion() & 0xFFFF00))
    449428        {
    450             QString msg =
    451                 QApplication::tr ("Executable <b>%1</b> requires Qt %2.x, found Qt %3.")
    452                                   .arg (qAppName())
    453                                   .arg (VBoxGlobal::qtCTVersionString().section ('.', 0, 1))
    454                                   .arg (VBoxGlobal::qtRTVersionString());
    455             QMessageBox::critical (
    456                 0, QApplication::tr ("Incompatible Qt Library Error"),
    457                 msg, QMessageBox::Abort, 0);
    458             qFatal ("%s", msg.toAscii().constData());
     429            QString strMsg = QApplication::tr("Executable <b>%1</b> requires Qt %2.x, found Qt %3.")
     430                                              .arg(qAppName())
     431                                              .arg(VBoxGlobal::qtCTVersionString().section('.', 0, 1))
     432                                              .arg(VBoxGlobal::qtRTVersionString());
     433            QMessageBox::critical(0, QApplication::tr("Incompatible Qt Library Error"),
     434                                  strMsg, QMessageBox::Abort, 0);
     435            qFatal("%s", strMsg.toAscii().constData());
    459436        }
    460 #endif
    461 
    462         /* load a translation based on the current locale */
     437#endif /* Q_WS_X11 */
     438
     439        /* Create modal-window manager: */
     440        UIModalWindowManager::create();
     441
     442        /* Load a translation based on the current locale: */
    463443        VBoxGlobal::loadLanguage();
    464444
     445        /* Simulate try-catch block: */
    465446        do
    466447        {
     448            /* Exit if VBoxGlobal is not valid: */
    467449            if (!vboxGlobal().isValid())
    468450                break;
    469451
    470 
     452            /* Exit if VBoxGlobal unable to process arguments: */
    471453            if (vboxGlobal().processArgs())
    472454                return 0;
     
    477459#endif /* RT_OS_LINUX */
    478460
     461            /* Load application settings: */
    479462            VBoxGlobalSettings settings = vboxGlobal().settings();
    480             /* Process known keys */
    481             bool noSelector = settings.isFeatureActive ("noSelector");
    482 
     463
     464            /* VM console process: */
    483465            if (vboxGlobal().isVMConsoleProcess())
    484466            {
    485                 if (vboxGlobal().startMachine(vboxGlobal().managedVMUuid()))
    486                     rc = a.exec();
    487             }
    488             else if (noSelector)
    489             {
    490                 msgCenter().cannotStartSelector();
     467                /* Make sure VM is started: */
     468                if (!vboxGlobal().startMachine(vboxGlobal().managedVMUuid()))
     469                    break;
     470
     471                /* Start application: */
     472                rc = a.exec();
    491473            }
    492474            else
    493475            {
     476                /* Make sure VM selector is permitted: */
     477                if (settings.isFeatureActive("noSelector"))
     478                {
     479                    msgCenter().cannotStartSelector();
     480                    break;
     481                }
     482
    494483#ifdef VBOX_BLEEDING_EDGE
    495484                msgCenter().showBEBWarning();
    496485#else /* VBOX_BLEEDING_EDGE */
    497486# ifndef DEBUG
    498                 /* Check for BETA version */
    499                 QString vboxVersion (vboxGlobal().virtualBox().GetVersion());
    500                 if (vboxVersion.contains ("BETA"))
     487                /* Check for BETA version: */
     488                QString vboxVersion(vboxGlobal().virtualBox().GetVersion());
     489                if (vboxVersion.contains("BETA"))
    501490                {
    502                     /* Allow to prevent this message */
    503                     QString str = vboxGlobal().virtualBox().
    504                         GetExtraData(GUI_PreventBetaWarning);
     491                    /* Allow to prevent this message: */
     492                    QString str = vboxGlobal().virtualBox().GetExtraData(GUI_PreventBetaWarning);
    505493                    if (str != vboxVersion)
    506494                        msgCenter().showBETAWarning();
     
    508496# endif /* !DEBUG */
    509497#endif /* !VBOX_BLEEDING_EDGE*/
     498
     499                /* Create/show selector window: */
    510500                vboxGlobal().selectorWnd().show();
     501
     502                /* Start application: */
    511503                rc = a.exec();
    512504            }
     
    514506        while (0);
    515507
     508        /* Create modal-window manager: */
    516509        UIModalWindowManager::destroy();
    517510    }
    518511
    519     LogFlowFunc (("rc=%d\n", rc));
     512    /* Finish logging: */
     513    LogFlowFunc(("rc=%d\n", rc));
    520514    LogFlowFuncLeave();
    521515
     516    /* Return result: */
    522517    return rc;
    523518}
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