VirtualBox

Changeset 71367 in vbox


Ignore:
Timestamp:
Mar 16, 2018 1:51:58 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121319
Message:

FE/Qt: bugref:9049: Detach VBoxGlobal dependencies from Global settings / Language page.

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

Legend:

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

    r71360 r71367  
    187187
    188188/* static */
    189 bool VBoxGlobal::m_sfCleanupInProgress = false;
    190 VBoxGlobal* VBoxGlobal::m_spInstance = 0;
    191 VBoxGlobal* VBoxGlobal::instance() { return m_spInstance; }
     189VBoxGlobal *VBoxGlobal::s_pInstance = 0;
     190bool        VBoxGlobal::s_fCleanupInProgress = false;
     191QString     VBoxGlobal::s_strLoadedLanguageId = vboxBuiltInLanguageName();
    192192
    193193/* static */
     
    195195{
    196196    /* Make sure instance is NOT created yet: */
    197     if (m_spInstance)
     197    if (s_pInstance)
    198198    {
    199199        AssertMsgFailed(("VBoxGlobal instance is already created!"));
     
    204204    new VBoxGlobal;
    205205    /* Prepare instance: */
    206     m_spInstance->prepare();
     206    s_pInstance->prepare();
    207207}
    208208
     
    211211{
    212212    /* Make sure instance is NOT destroyed yet: */
    213     if (!m_spInstance)
     213    if (!s_pInstance)
    214214    {
    215215        AssertMsgFailed(("VBoxGlobal instance is already destroyed!"));
     
    221221     * 2. But if QApplication was not started at all and we perform
    222222     *    early shutdown, we should do cleanup ourselves. */
    223     if (m_spInstance->isValid())
    224         m_spInstance->cleanup();
     223    if (s_pInstance->isValid())
     224        s_pInstance->cleanup();
    225225    /* Destroy instance: */
    226     delete m_spInstance;
     226    delete s_pInstance;
    227227}
    228228
     
    260260{
    261261    /* Assign instance: */
    262     m_spInstance = this;
     262    s_pInstance = this;
    263263}
    264264
     
    266266{
    267267    /* Unassign instance: */
    268     m_spInstance = 0;
     268    s_pInstance = 0;
    269269}
    270270
     
    12741274
    12751275    /* Ignore the request during VBoxGlobal cleanup: */
    1276     if (m_sfCleanupInProgress)
     1276    if (s_fCleanupInProgress)
    12771277        return;
    12781278
     
    17481748}
    17491749
    1750 const char *gVBoxLangSubDir = "/nls";
    1751 const char *gVBoxLangFileBase = "VirtualBox_";
    1752 const char *gVBoxLangFileExt = ".qm";
    1753 const char *gVBoxLangIDRegExp = "(([a-z]{2})(?:_([A-Z]{2}))?)|(C)";
    1754 const char *gVBoxBuiltInLangName   = "C";
    1755 
    17561750class VBoxTranslator : public QTranslator
    17571751{
     
    17761770
    17771771static VBoxTranslator *sTranslator = 0;
    1778 static QString sLoadedLangId = gVBoxBuiltInLangName;
     1772
     1773/* static */
     1774QString VBoxGlobal::vboxLanguageSubDirectory()
     1775{
     1776    return "/nls";
     1777}
     1778
     1779/* static */
     1780QString VBoxGlobal::vboxLanguageFileBase()
     1781{
     1782    return "VirtualBox_";
     1783}
     1784
     1785/* static */
     1786QString VBoxGlobal::vboxLanguageFileExtension()
     1787{
     1788    return ".qm";
     1789}
     1790
     1791/* static */
     1792QString VBoxGlobal::vboxLanguageIdRegExp()
     1793{
     1794    return "(([a-z]{2})(?:_([A-Z]{2}))?)|(C)";
     1795}
     1796
     1797/* static */
     1798QString VBoxGlobal::vboxBuiltInLanguageName()
     1799{
     1800    return "C";
     1801}
    17791802
    17801803/**
     
    17931816QString VBoxGlobal::languageId()
    17941817{
    1795     return sLoadedLangId;
     1818    return s_strLoadedLanguageId;
    17961819}
    17971820
     
    18081831        VBoxGlobal::systemLanguageId() : aLangId;
    18091832    QString languageFileName;
    1810     QString selectedLangId = gVBoxBuiltInLangName;
     1833    QString selectedLangId = vboxBuiltInLanguageName();
    18111834
    18121835    /* If C is selected we change it temporary to en. This makes sure any extra
     
    18261849    AssertRC (rc);
    18271850
    1828     QString nlsPath = QString(szNlsPath) + gVBoxLangSubDir;
     1851    QString nlsPath = QString(szNlsPath) + vboxLanguageSubDirectory();
    18291852    QDir nlsDir (nlsPath);
    18301853
    18311854    Assert (!langId.isEmpty());
    1832     if (!langId.isEmpty() && langId != gVBoxBuiltInLangName)
    1833     {
    1834         QRegExp regExp (gVBoxLangIDRegExp);
     1855    if (!langId.isEmpty() && langId != vboxBuiltInLanguageName())
     1856    {
     1857        QRegExp regExp (vboxLanguageIdRegExp());
    18351858        int pos = regExp.indexIn (langId);
    18361859        /* the language ID should match the regexp completely */
     
    18391862        QString lang = regExp.cap (2);
    18401863
    1841         if (nlsDir.exists (gVBoxLangFileBase + langId + gVBoxLangFileExt))
    1842         {
    1843             languageFileName = nlsDir.absoluteFilePath (gVBoxLangFileBase + langId +
    1844                                                         gVBoxLangFileExt);
     1864        if (nlsDir.exists (vboxLanguageFileBase() + langId + vboxLanguageFileExtension()))
     1865        {
     1866            languageFileName = nlsDir.absoluteFilePath (vboxLanguageFileBase() + langId +
     1867                                                        vboxLanguageFileExtension());
    18451868            selectedLangId = langId;
    18461869        }
    1847         else if (nlsDir.exists (gVBoxLangFileBase + lang + gVBoxLangFileExt))
    1848         {
    1849             languageFileName = nlsDir.absoluteFilePath (gVBoxLangFileBase + lang +
    1850                                                         gVBoxLangFileExt);
     1870        else if (nlsDir.exists (vboxLanguageFileBase() + lang + vboxLanguageFileExtension()))
     1871        {
     1872            languageFileName = nlsDir.absoluteFilePath (vboxLanguageFileBase() + lang +
     1873                                                        vboxLanguageFileExtension());
    18511874            selectedLangId = lang;
    18521875        }
     
    18591882                msgCenter().cannotFindLanguage (langId, nlsPath);
    18601883            /* selectedLangId remains built-in here */
    1861             AssertReturnVoid (selectedLangId == gVBoxBuiltInLangName);
     1884            AssertReturnVoid (selectedLangId == vboxBuiltInLanguageName());
    18621885        }
    18631886    }
     
    18781901    if (sTranslator)
    18791902    {
    1880         if (selectedLangId != gVBoxBuiltInLangName)
     1903        if (selectedLangId != vboxBuiltInLanguageName())
    18811904        {
    18821905            Assert (!languageFileName.isNull());
     
    18921915
    18931916    if (loadOk)
    1894         sLoadedLangId = selectedLangId;
     1917        s_strLoadedLanguageId = selectedLangId;
    18951918    else
    18961919    {
    18971920        msgCenter().cannotLoadLanguage (languageFileName);
    1898         sLoadedLangId = gVBoxBuiltInLangName;
     1921        s_strLoadedLanguageId = vboxBuiltInLanguageName();
    18991922    }
    19001923
    19011924    /* Try to load the corresponding Qt translation */
    1902     if (sLoadedLangId != gVBoxBuiltInLangName && sLoadedLangId != "en")
     1925    if (languageId() != vboxBuiltInLanguageName() && languageId() != "en")
    19031926    {
    19041927#ifdef Q_OS_UNIX
     
    19061929         * to load the Qt translation from the system location. */
    19071930        languageFileName = QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" +
    1908                            sLoadedLangId + gVBoxLangFileExt;
     1931                           languageId() + vboxLanguageFileExtension();
    19091932        QTranslator *qtSysTr = new QTranslator (sTranslator);
    19101933        Assert (qtSysTr);
     
    19211944#endif
    19221945        languageFileName =  nlsDir.absoluteFilePath (QString ("qt_") +
    1923                                                      sLoadedLangId +
    1924                                                      gVBoxLangFileExt);
     1946                                                     languageId() +
     1947                                                     vboxLanguageFileExtension());
    19251948        QTranslator *qtTr = new QTranslator (sTranslator);
    19261949        Assert (qtTr);
     
    19351958    }
    19361959    if (fResetToC)
    1937         sLoadedLangId = "C";
     1960        s_strLoadedLanguageId = vboxBuiltInLanguageName();
    19381961#ifdef VBOX_WS_MAC
    19391962    /* Qt doesn't translate the items in the Application menu initially.
     
    40444067    /* Remember that the cleanup is in progress preventing any unwanted
    40454068     * stuff which could be called from the other threads: */
    4046     m_sfCleanupInProgress = true;
     4069    s_fCleanupInProgress = true;
    40474070
    40484071#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r71360 r71367  
    8282
    8383    /* Static API: Create/destroy stuff: */
    84     static VBoxGlobal* instance();
     84    static VBoxGlobal *instance() { return s_pInstance; }
    8585    static void create();
    8686    static void destroy();
    8787
    8888    bool isValid() { return mValid; }
    89     bool isCleaningUp() { return m_sfCleanupInProgress; }
     89    bool isCleaningUp() { return s_fCleanupInProgress; }
    9090
    9191    static QString qtRTVersionString();
     
    339339    static bool isDOSType (const QString &aOSTypeId);
    340340
     341    /** Returns VBox language sub-directory. */
     342    static QString vboxLanguageSubDirectory();
     343    /** Returns VBox language file-base. */
     344    static QString vboxLanguageFileBase();
     345    /** Returns VBox language file-extension. */
     346    static QString vboxLanguageFileExtension();
     347    /** Returns VBox language ID reg-exp. */
     348    static QString vboxLanguageIdRegExp();
     349    /** Returns built in language name. */
     350    static QString vboxBuiltInLanguageName();
    341351    static QString languageId();
    342352    static void loadLanguage (const QString &aLangId = QString::null);
     
    634644    UIThreadPool *m_pThreadPool;
    635645
    636     /* API: Instance stuff: */
    637     static bool m_sfCleanupInProgress;
    638     static VBoxGlobal* m_spInstance;
    639     friend VBoxGlobal& vboxGlobal();
     646    /** Holds the singleton VBoxGlobal instance. */
     647    static VBoxGlobal *s_pInstance;
     648    /** Holds whether VBoxGlobal cleanup is in progress. */
     649    static bool        s_fCleanupInProgress;
     650    /** Holds the currently loaded language ID. */
     651    static QString     s_strLoadedLanguageId;
     652
     653    /** Allows for shortcut access. */
     654    friend VBoxGlobal &vboxGlobal();
    640655};
    641656
    642 /* Shortcut to the static VBoxGlobal::instance() method: */
    643 inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
     657/** Singleton VBoxGlobal 'official' name. */
     658inline VBoxGlobal &vboxGlobal() { return *VBoxGlobal::instance(); }
    644659
    645660#endif /* !___VBoxGlobal_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsLanguage.cpp

    r71027 r71367  
    4343
    4444
    45 extern const char *gVBoxLangSubDir;
    46 extern const char *gVBoxLangFileBase;
    47 extern const char *gVBoxLangFileExt;
    48 extern const char *gVBoxLangIDRegExp;
    49 extern const char *gVBoxBuiltInLangName;
    50 
    51 
    5245/** Global settings: Language page data structure. */
    5346struct UIDataSettingsGlobalLanguage
     
    395388    int rc = RTPathAppPrivateNoArch(szNlsPath, sizeof(szNlsPath));
    396389    AssertRC(rc);
    397     QString strNlsPath = QString(szNlsPath) + gVBoxLangSubDir;
     390    QString strNlsPath = QString(szNlsPath) + VBoxGlobal::vboxLanguageSubDirectory();
    398391    QDir nlsDir(strNlsPath);
    399     QStringList files = nlsDir.entryList(QStringList(QString("%1*%2").arg(gVBoxLangFileBase, gVBoxLangFileExt)), QDir::Files);
     392    QStringList files = nlsDir.entryList(QStringList(QString("%1*%2").arg(VBoxGlobal::vboxLanguageFileBase(),
     393                                                                          VBoxGlobal::vboxLanguageFileExtension())),
     394                                         QDir::Files);
    400395
    401396    QTranslator translator;
     
    403398    new UILanguageItem(m_pLanguageTree);
    404399    /* Add the built-in language: */
    405     new UILanguageItem(m_pLanguageTree, translator, gVBoxBuiltInLangName, true /* built-in */);
     400    new UILanguageItem(m_pLanguageTree, translator, VBoxGlobal::vboxBuiltInLanguageName(), true /* built-in */);
    406401    /* Add all existing languages */
    407402    for (QStringList::Iterator it = files.begin(); it != files.end(); ++it)
    408403    {
    409404        QString strFileName = *it;
    410         QRegExp regExp(QString(gVBoxLangFileBase) + gVBoxLangIDRegExp);
     405        QRegExp regExp(VBoxGlobal::vboxLanguageFileBase() + VBoxGlobal::vboxLanguageIdRegExp());
    411406        int iPos = regExp.indexIn(strFileName);
    412407        if (iPos == -1)
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette