Changeset 71367 in vbox
- Timestamp:
- Mar 16, 2018 1:51:58 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 121319
- 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 187 187 188 188 /* static */ 189 bool VBoxGlobal::m_sfCleanupInProgress = false;190 VBoxGlobal* VBoxGlobal::m_spInstance = 0;191 VBoxGlobal* VBoxGlobal::instance() { return m_spInstance; } 189 VBoxGlobal *VBoxGlobal::s_pInstance = 0; 190 bool VBoxGlobal::s_fCleanupInProgress = false; 191 QString VBoxGlobal::s_strLoadedLanguageId = vboxBuiltInLanguageName(); 192 192 193 193 /* static */ … … 195 195 { 196 196 /* Make sure instance is NOT created yet: */ 197 if ( m_spInstance)197 if (s_pInstance) 198 198 { 199 199 AssertMsgFailed(("VBoxGlobal instance is already created!")); … … 204 204 new VBoxGlobal; 205 205 /* Prepare instance: */ 206 m_spInstance->prepare();206 s_pInstance->prepare(); 207 207 } 208 208 … … 211 211 { 212 212 /* Make sure instance is NOT destroyed yet: */ 213 if (! m_spInstance)213 if (!s_pInstance) 214 214 { 215 215 AssertMsgFailed(("VBoxGlobal instance is already destroyed!")); … … 221 221 * 2. But if QApplication was not started at all and we perform 222 222 * 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(); 225 225 /* Destroy instance: */ 226 delete m_spInstance;226 delete s_pInstance; 227 227 } 228 228 … … 260 260 { 261 261 /* Assign instance: */ 262 m_spInstance = this;262 s_pInstance = this; 263 263 } 264 264 … … 266 266 { 267 267 /* Unassign instance: */ 268 m_spInstance = 0;268 s_pInstance = 0; 269 269 } 270 270 … … 1274 1274 1275 1275 /* Ignore the request during VBoxGlobal cleanup: */ 1276 if ( m_sfCleanupInProgress)1276 if (s_fCleanupInProgress) 1277 1277 return; 1278 1278 … … 1748 1748 } 1749 1749 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 1756 1750 class VBoxTranslator : public QTranslator 1757 1751 { … … 1776 1770 1777 1771 static VBoxTranslator *sTranslator = 0; 1778 static QString sLoadedLangId = gVBoxBuiltInLangName; 1772 1773 /* static */ 1774 QString VBoxGlobal::vboxLanguageSubDirectory() 1775 { 1776 return "/nls"; 1777 } 1778 1779 /* static */ 1780 QString VBoxGlobal::vboxLanguageFileBase() 1781 { 1782 return "VirtualBox_"; 1783 } 1784 1785 /* static */ 1786 QString VBoxGlobal::vboxLanguageFileExtension() 1787 { 1788 return ".qm"; 1789 } 1790 1791 /* static */ 1792 QString VBoxGlobal::vboxLanguageIdRegExp() 1793 { 1794 return "(([a-z]{2})(?:_([A-Z]{2}))?)|(C)"; 1795 } 1796 1797 /* static */ 1798 QString VBoxGlobal::vboxBuiltInLanguageName() 1799 { 1800 return "C"; 1801 } 1779 1802 1780 1803 /** … … 1793 1816 QString VBoxGlobal::languageId() 1794 1817 { 1795 return s LoadedLangId;1818 return s_strLoadedLanguageId; 1796 1819 } 1797 1820 … … 1808 1831 VBoxGlobal::systemLanguageId() : aLangId; 1809 1832 QString languageFileName; 1810 QString selectedLangId = gVBoxBuiltInLangName;1833 QString selectedLangId = vboxBuiltInLanguageName(); 1811 1834 1812 1835 /* If C is selected we change it temporary to en. This makes sure any extra … … 1826 1849 AssertRC (rc); 1827 1850 1828 QString nlsPath = QString(szNlsPath) + gVBoxLangSubDir;1851 QString nlsPath = QString(szNlsPath) + vboxLanguageSubDirectory(); 1829 1852 QDir nlsDir (nlsPath); 1830 1853 1831 1854 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()); 1835 1858 int pos = regExp.indexIn (langId); 1836 1859 /* the language ID should match the regexp completely */ … … 1839 1862 QString lang = regExp.cap (2); 1840 1863 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()); 1845 1868 selectedLangId = langId; 1846 1869 } 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()); 1851 1874 selectedLangId = lang; 1852 1875 } … … 1859 1882 msgCenter().cannotFindLanguage (langId, nlsPath); 1860 1883 /* selectedLangId remains built-in here */ 1861 AssertReturnVoid (selectedLangId == gVBoxBuiltInLangName);1884 AssertReturnVoid (selectedLangId == vboxBuiltInLanguageName()); 1862 1885 } 1863 1886 } … … 1878 1901 if (sTranslator) 1879 1902 { 1880 if (selectedLangId != gVBoxBuiltInLangName)1903 if (selectedLangId != vboxBuiltInLanguageName()) 1881 1904 { 1882 1905 Assert (!languageFileName.isNull()); … … 1892 1915 1893 1916 if (loadOk) 1894 s LoadedLangId = selectedLangId;1917 s_strLoadedLanguageId = selectedLangId; 1895 1918 else 1896 1919 { 1897 1920 msgCenter().cannotLoadLanguage (languageFileName); 1898 s LoadedLangId = gVBoxBuiltInLangName;1921 s_strLoadedLanguageId = vboxBuiltInLanguageName(); 1899 1922 } 1900 1923 1901 1924 /* Try to load the corresponding Qt translation */ 1902 if ( sLoadedLangId != gVBoxBuiltInLangName && sLoadedLangId!= "en")1925 if (languageId() != vboxBuiltInLanguageName() && languageId() != "en") 1903 1926 { 1904 1927 #ifdef Q_OS_UNIX … … 1906 1929 * to load the Qt translation from the system location. */ 1907 1930 languageFileName = QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + 1908 sLoadedLangId + gVBoxLangFileExt;1931 languageId() + vboxLanguageFileExtension(); 1909 1932 QTranslator *qtSysTr = new QTranslator (sTranslator); 1910 1933 Assert (qtSysTr); … … 1921 1944 #endif 1922 1945 languageFileName = nlsDir.absoluteFilePath (QString ("qt_") + 1923 sLoadedLangId+1924 gVBoxLangFileExt);1946 languageId() + 1947 vboxLanguageFileExtension()); 1925 1948 QTranslator *qtTr = new QTranslator (sTranslator); 1926 1949 Assert (qtTr); … … 1935 1958 } 1936 1959 if (fResetToC) 1937 s LoadedLangId = "C";1960 s_strLoadedLanguageId = vboxBuiltInLanguageName(); 1938 1961 #ifdef VBOX_WS_MAC 1939 1962 /* Qt doesn't translate the items in the Application menu initially. … … 4044 4067 /* Remember that the cleanup is in progress preventing any unwanted 4045 4068 * stuff which could be called from the other threads: */ 4046 m_sfCleanupInProgress = true;4069 s_fCleanupInProgress = true; 4047 4070 4048 4071 #ifdef VBOX_GUI_WITH_NETWORK_MANAGER -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r71360 r71367 82 82 83 83 /* Static API: Create/destroy stuff: */ 84 static VBoxGlobal * instance();84 static VBoxGlobal *instance() { return s_pInstance; } 85 85 static void create(); 86 86 static void destroy(); 87 87 88 88 bool isValid() { return mValid; } 89 bool isCleaningUp() { return m_sfCleanupInProgress; }89 bool isCleaningUp() { return s_fCleanupInProgress; } 90 90 91 91 static QString qtRTVersionString(); … … 339 339 static bool isDOSType (const QString &aOSTypeId); 340 340 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(); 341 351 static QString languageId(); 342 352 static void loadLanguage (const QString &aLangId = QString::null); … … 634 644 UIThreadPool *m_pThreadPool; 635 645 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(); 640 655 }; 641 656 642 /* Shortcut to the static VBoxGlobal::instance() method:*/643 inline VBoxGlobal &vboxGlobal() { return *VBoxGlobal::instance(); }657 /** Singleton VBoxGlobal 'official' name. */ 658 inline VBoxGlobal &vboxGlobal() { return *VBoxGlobal::instance(); } 644 659 645 660 #endif /* !___VBoxGlobal_h___ */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsLanguage.cpp
r71027 r71367 43 43 44 44 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 52 45 /** Global settings: Language page data structure. */ 53 46 struct UIDataSettingsGlobalLanguage … … 395 388 int rc = RTPathAppPrivateNoArch(szNlsPath, sizeof(szNlsPath)); 396 389 AssertRC(rc); 397 QString strNlsPath = QString(szNlsPath) + gVBoxLangSubDir;390 QString strNlsPath = QString(szNlsPath) + VBoxGlobal::vboxLanguageSubDirectory(); 398 391 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); 400 395 401 396 QTranslator translator; … … 403 398 new UILanguageItem(m_pLanguageTree); 404 399 /* 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 */); 406 401 /* Add all existing languages */ 407 402 for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) 408 403 { 409 404 QString strFileName = *it; 410 QRegExp regExp( QString(gVBoxLangFileBase) + gVBoxLangIDRegExp);405 QRegExp regExp(VBoxGlobal::vboxLanguageFileBase() + VBoxGlobal::vboxLanguageIdRegExp()); 411 406 int iPos = regExp.indexIn(strFileName); 412 407 if (iPos == -1)
Note:
See TracChangeset
for help on using the changeset viewer.