Changeset 2044 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Apr 12, 2007 1:04:20 PM (18 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h
r2022 r2044 375 375 bool openURL (const QString &aURL); 376 376 377 static const QString& languageID();378 static void loadLanguage (const QString &aLangId = QString::null);379 static bool loadLanguageFile (const QString &);380 381 377 QString languageName() const; 382 378 QString languageCountry() const; … … 391 387 392 388 /* public static stuff */ 389 390 static QString languageId(); 391 static void loadLanguage (const QString &aLangId = QString::null); 393 392 394 393 static QIconSet iconSet (const char *aNormal, … … 413 412 static QString highlight (const QString &aStr, bool aToolTip = false); 414 413 415 static QString systemLanguageI D();414 static QString systemLanguageId(); 416 415 417 416 static QString getExistingDirectory (const QString &aDir, QWidget *aParent, … … 510 509 511 510 QString verString; 512 513 static QString mLoadedLangId;514 511 515 512 QValueVector <CGuestOSType> vm_os_types; -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxProblemReporter.h
r1435 r2044 98 98 void cannotOpenURL (const QString &aURL); 99 99 100 void cannotFindLanguage (const QString &aLangID, const QString &aNlsPath); 101 void cannotLoadLanguage (const QString &aLangFile); 102 100 103 void cannotInitCOM (HRESULT rc); 101 104 void cannotCreateVirtualBox (const CVirtualBox &vbox); -
trunk/src/VBox/Frontends/VirtualBox/nls/VirtualBox_de.ts
r1979 r2044 8 8 </message> 9 9 <message> 10 <source> built-in</source>10 <source>--</source> 11 11 <comment>Native language country name (empty if this language is for all countries)</comment> 12 12 <translation></translation> … … 18 18 </message> 19 19 <message> 20 <source> built-in</source>20 <source>--</source> 21 21 <comment>Language country name, in English (empty if native country name is empty)</comment> 22 22 <translation></translation> -
trunk/src/VBox/Frontends/VirtualBox/nls/VirtualBox_ru.ts
r1927 r2044 8 8 </message> 9 9 <message> 10 <source> built-in</source>10 <source>--</source> 11 11 <comment>Native language country name (empty if this language is for all countries)</comment> 12 12 <translation></translation> … … 18 18 </message> 19 19 <message> 20 <source> built-in</source>20 <source>--</source> 21 21 <comment>Language country name, in English (empty if native country name is empty)</comment> 22 22 <translation></translation> -
trunk/src/VBox/Frontends/VirtualBox/nls/VirtualBox_xx_YY.ts
r1927 r2044 8 8 </message> 9 9 <message> 10 <source> built-in</source>10 <source>--</source> 11 11 <comment>Native language country name (empty if this language is for all countries)</comment> 12 12 <translation type="unfinished"></translation> … … 18 18 </message> 19 19 <message> 20 <source> built-in</source>20 <source>--</source> 21 21 <comment>Language country name, in English (empty if native country name is empty)</comment> 22 22 <translation type="unfinished"></translation> -
trunk/src/VBox/Frontends/VirtualBox/nls/VirtualBox_zh_CN.ts
r1927 r2044 8 8 </message> 9 9 <message> 10 <source> built-in</source>10 <source>--</source> 11 11 <comment>Native language country name (empty if this language is for all countries)</comment> 12 12 <translation type="unfinished">China</translation> … … 18 18 </message> 19 19 <message> 20 <source> built-in</source>20 <source>--</source> 21 21 <comment>Language country name, in English (empty if native country name is empty)</comment> 22 22 <translation type="unfinished">China</translation> … … 25 25 <source>InnoTek</source> 26 26 <comment>Comma-separated list of translators</comment> 27 <translation type="unfinished"> </translation>27 <translation type="unfinished">victor</translation> 28 28 </message> 29 29 </context> -
trunk/src/VBox/Frontends/VirtualBox/nls/VirtualBox_zh_TW.ts
r1927 r2044 8 8 </message> 9 9 <message> 10 <source> built-in</source>10 <source>--</source> 11 11 <comment>Native language country name (empty if this language is for all countries)</comment> 12 12 <translation type="unfinished">Taiwan</translation> … … 18 18 </message> 19 19 <message> 20 <source> built-in</source>20 <source>--</source> 21 21 <comment>Language country name, in English (empty if native country name is empty)</comment> 22 22 <translation type="unfinished">Taiwan</translation> … … 25 25 <source>InnoTek</source> 26 26 <comment>Comma-separated list of translators</comment> 27 <translation type="unfinished"> </translation>27 <translation type="unfinished">bluebat</translation> 28 28 </message> 29 29 </context> -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r2042 r2044 471 471 #endif /* Q_WS_WIN */ 472 472 473 // Helpers for VBoxGlobal::loadLanguage()474 /////////////////////////////////////////////////////////////////////////////475 476 extern const QString transFileName = "VirtualBox_";477 extern const QString langIdRegExp = "(([a-z]{2})(_([A-Z]{2}))?)";478 extern const QString builtInName = "built_in";479 static const QString transFileExt = ".qm";480 class VBoxTranslator : public QTranslator481 {482 public:483 484 VBoxTranslator (QObject *aParent = 0)485 : QTranslator (aParent, "VBoxTranslatorObject") {}486 487 bool loadFile (const QString &aFileName)488 {489 QFile file (aFileName);490 if (!file.open (IO_ReadOnly))491 return false;492 mData = file.readAll();493 return load ((uchar*)mData.data(), mData.size());494 }495 496 private:497 498 QByteArray mData;499 };500 static VBoxTranslator *mTranslator = 0;501 502 473 // VBoxGlobal 503 474 //////////////////////////////////////////////////////////////////////////////// … … 515 486 static void vboxGlobalCleanup() 516 487 { 488 Assert (!vboxGlobal_cleanup); 517 489 vboxGlobal_cleanup = true; 518 490 vboxGlobal().cleanup(); … … 1678 1650 1679 1651 /** 1680 * This variable used for storing loaded language id.1681 */1682 /* static */1683 QString VBoxGlobal::mLoadedLangId = builtInName;1684 1685 /**1686 * This method returns loaded language id.1687 */1688 /* static */1689 const QString& VBoxGlobal::languageID()1690 {1691 return mLoadedLangId;1692 }1693 1694 /**1695 * This method is used to load language by language id.1696 */1697 /* static */1698 void VBoxGlobal::loadLanguage (const QString &aLang)1699 {1700 const QString &langId = aLang.isNull() ?1701 VBoxGlobal::systemLanguageID() : aLang;1702 QString languageFileName = QString::null;1703 QString selectedLangId = builtInName;1704 1705 if (aLang != builtInName)1706 {1707 QRegExp regExp (langIdRegExp);1708 int rule = regExp.search (langId);1709 /* this rule should match the language id completely */1710 Assert (!rule);1711 if (rule == -1) return;1712 1713 QString mId1part = regExp.cap (2);1714 QString mId2part = regExp.cap (4);1715 /* language localization (second part) should not be empty? */1716 // Assert (!mId2part.isEmpty());1717 1718 QString nlsPath = qApp->applicationDirPath() + "/nls";1719 QDir nlsDir (nlsPath);1720 if (nlsDir.exists (transFileName + langId + transFileExt))1721 {1722 languageFileName = nlsDir.absFilePath (transFileName + langId + transFileExt);1723 selectedLangId = langId;1724 }1725 else if (nlsDir.exists (transFileName + mId1part + transFileExt))1726 {1727 languageFileName = nlsDir.absFilePath (transFileName + mId1part + transFileExt);1728 selectedLangId = mId1part;1729 }1730 1731 if (mTranslator && languageFileName.isNull())1732 {1733 /* process downgrade situation */1734 int loadLanguageQuest = vboxProblem().message (1735 0, VBoxProblemReporter::Question,1736 tr ("<p>Correct *.qm language file for language with "1737 "<b>%1</b> id could not be found in the "1738 "%2 location.</p> Do you want to use built-in language "1739 "instead of it?</p>").arg (langId).arg (nlsPath),1740 0, /* autoConfirmId */1741 QIMessageBox::Ok | QIMessageBox::Default,1742 QIMessageBox::Cancel | QIMessageBox::Escape);1743 if (loadLanguageQuest == QIMessageBox::Cancel)1744 return;1745 }1746 }1747 1748 if (loadLanguageFile (languageFileName))1749 {1750 mLoadedLangId = selectedLangId;1751 }1752 else1753 {1754 /* passed file is not loaded */1755 vboxProblem().message (1756 0, VBoxProblemReporter::Warning,1757 tr ("<p>Language file <b>%1</b> could not be loaded. This "1758 "issue could be caused by incorrect file content.</p>")1759 .arg (languageFileName),1760 0, /* autoConfirmId */1761 QIMessageBox::Ok | QIMessageBox::Default);1762 }1763 }1764 1765 /**1766 * This method is used to load language file into translator1767 * and install loaded translator.1768 */1769 /* static */1770 bool VBoxGlobal::loadLanguageFile (const QString &aFileName)1771 {1772 if (mTranslator)1773 qApp->removeTranslator (mTranslator);1774 delete mTranslator;1775 mTranslator = new VBoxTranslator();1776 bool status = true;1777 if (!aFileName.isNull())1778 status = mTranslator->loadFile (aFileName);1779 qApp->installTranslator (mTranslator);1780 return status;1781 }1782 1783 /**1784 1652 * Native language name of the currently installed translation. 1785 * Returns "English [built-in]" if no translation is installed1653 * Returns "English" if no translation is installed 1786 1654 * or if the translation file is invalid. 1787 1655 */ … … 1795 1663 /** 1796 1664 * Native language country name of the currently installed translation. 1797 * Returns " " if no translation is installed or if the translation file is1665 * Returns "--" if no translation is installed or if the translation file is 1798 1666 * invalid, or if the language is independent on the country. 1799 1667 */ 1800 1668 QString VBoxGlobal::languageCountry() const 1801 1669 { 1802 return qApp->translate ("@@@", " built-in",1670 return qApp->translate ("@@@", "--", 1803 1671 "Native language country name " 1804 1672 "(empty if this language is for all countries)"); … … 1807 1675 /** 1808 1676 * Language name of the currently installed translation, in English. 1809 * Returns "English [built-in]" if no translation is installed1677 * Returns "English" if no translation is installed 1810 1678 * or if the translation file is invalid. 1811 1679 */ … … 1819 1687 /** 1820 1688 * Language country name of the currently installed translation, in English. 1821 * Returns " " if no translation is installed or if the translation file is1689 * Returns "--" if no translation is installed or if the translation file is 1822 1690 * invalid, or if the language is independent on the country. 1823 1691 */ 1824 1692 QString VBoxGlobal::languageCountryEnglish() const 1825 1693 { 1826 return qApp->translate ("@@@", " built-in",1694 return qApp->translate ("@@@", "--", 1827 1695 "Language country name, in English " 1828 1696 "(empty if native country name is empty)"); … … 1953 1821 // public static stuff 1954 1822 //////////////////////////////////////////////////////////////////////////////// 1823 1824 extern const char *gVBoxLangSubDir = "/nls"; 1825 extern const char *gVBoxLangFileBase = "VirtualBox_"; 1826 extern const char *gVBoxLangFileExt = ".qm"; 1827 extern const char *gVBoxLangIDRegExp = "(([a-z]{2})(?:_([A-Z]{2}))?)"; 1828 extern const char *gVBoxBuiltInLangName = "built_in"; 1829 1830 class VBoxTranslator : public QTranslator 1831 { 1832 public: 1833 1834 VBoxTranslator (QObject *aParent = 0) 1835 : QTranslator (aParent, "VBoxTranslatorObject") {} 1836 1837 bool loadFile (const QString &aFileName) 1838 { 1839 QFile file (aFileName); 1840 if (!file.open (IO_ReadOnly)) 1841 return false; 1842 mData = file.readAll(); 1843 return load ((uchar*) mData.data(), mData.size()); 1844 } 1845 1846 private: 1847 1848 QByteArray mData; 1849 }; 1850 1851 static VBoxTranslator *sTranslator = 0; 1852 static QString sLoadedLangId = gVBoxBuiltInLangName; 1853 1854 /** 1855 * Returns the loaded (active) language ID. 1856 * Note that it may not match with VMGlobalSettings::languageId() if the 1857 * specified language cannot be loaded. 1858 * If the built-in language is active, this method returns "built_in". 1859 */ 1860 /* static */ 1861 QString VBoxGlobal::languageId() 1862 { 1863 return sLoadedLangId; 1864 } 1865 1866 /** 1867 * Loads the language by language ID. 1868 * @param aLang language ID in in form of xx_YY 1869 */ 1870 /* static */ 1871 void VBoxGlobal::loadLanguage (const QString &aLang) 1872 { 1873 QString langId = aLang.isNull() ? 1874 VBoxGlobal::systemLanguageId() : aLang; 1875 QString languageFileName = QString::null; 1876 QString selectedLangId = gVBoxBuiltInLangName; 1877 1878 if (aLang != gVBoxBuiltInLangName) 1879 { 1880 QRegExp regExp (gVBoxLangIDRegExp); 1881 int rule = regExp.search (langId); 1882 /* this rule should match the language id completely */ 1883 Assert (!rule); 1884 if (rule == -1) return; 1885 1886 QString mId1part = regExp.cap (2); 1887 QString mId2part = regExp.cap (4); 1888 /* language localization (second part) should not be empty? */ 1889 // Assert (!mId2part.isEmpty()); 1890 1891 QString nlsPath = qApp->applicationDirPath() + gVBoxLangSubDir; 1892 QDir nlsDir (nlsPath); 1893 if (nlsDir.exists (gVBoxLangFileBase + langId + gVBoxLangFileExt)) 1894 { 1895 languageFileName = nlsDir.absFilePath (gVBoxLangFileBase + langId + 1896 gVBoxLangFileExt); 1897 selectedLangId = langId; 1898 } 1899 else if (nlsDir.exists (gVBoxLangFileBase + mId1part + gVBoxLangFileExt)) 1900 { 1901 languageFileName = nlsDir.absFilePath (gVBoxLangFileBase + mId1part + 1902 gVBoxLangFileExt); 1903 selectedLangId = mId1part; 1904 } 1905 1906 if (sTranslator && languageFileName.isNull()) 1907 { 1908 vboxProblem().cannotFindLanguage (langId, nlsPath); 1909 return; 1910 } 1911 } 1912 1913 /* load the language file */ 1914 if (sTranslator) 1915 { 1916 qApp->removeTranslator (sTranslator); 1917 delete sTranslator; 1918 } 1919 sTranslator = new VBoxTranslator (qApp); 1920 Assert (sTranslator); 1921 bool loadOk = true; 1922 if (sTranslator) 1923 { 1924 /* an empty file name means built-in English*/ 1925 if (selectedLangId != gVBoxBuiltInLangName) 1926 { 1927 Assert (!languageFileName.isNull()); 1928 loadOk = sTranslator->loadFile (languageFileName); 1929 } 1930 /* we install the translator in any case: on failure, this will 1931 * activate an empty (aka built-in) translator */ 1932 qApp->installTranslator (sTranslator); 1933 } 1934 else 1935 loadOk = false; 1936 1937 if (loadOk) 1938 sLoadedLangId = selectedLangId; 1939 else 1940 { 1941 vboxProblem().cannotLoadLanguage (languageFileName); 1942 sLoadedLangId = gVBoxBuiltInLangName; 1943 } 1944 } 1955 1945 1956 1946 /* static */ … … 2392 2382 */ 2393 2383 /* static */ 2394 QString VBoxGlobal::systemLanguageI D()2384 QString VBoxGlobal::systemLanguageId() 2395 2385 { 2396 2386 #ifdef Q_OS_UNIX … … 2899 2889 2900 2890 /* Load predefined language */ 2901 const QString &languageId = gset.languageId();2891 QString languageId = gset.languageId(); 2902 2892 if (!languageId.isNull()) 2903 2893 loadLanguage (languageId); -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp
r1557 r2044 446 446 } 447 447 448 void VBoxProblemReporter::cannotFindLanguage (const QString &aLangID, 449 const QString &aNlsPath) 450 { 451 message 452 (0, VBoxProblemReporter::Error, 453 tr ("<p>Could not find a language file for the language " 454 "<b>%1</b> in the directory <b><nobr>%2</nobr></b>.</p>" 455 "<p>The language will be temporarily reset to the system " 456 "default language. Please go to the <b>Global Settings</b> " 457 "dialog which you can open from the <b>File</b> menu of the " 458 "main VirtualBox window, and select one of the existing " 459 "languages on the <b>Language</b> page.</p>") 460 .arg (aLangID).arg (aNlsPath)); 461 } 462 463 void VBoxProblemReporter::cannotLoadLanguage (const QString &aLangFile) 464 { 465 message 466 (0, VBoxProblemReporter::Error, 467 tr ("<p>Could not load the language file <b><nobr>%1</nobr></b>. " 468 "<p>The language will be temporarily reset to English (built-in). " 469 "Please go to the <b>Global Settings</b> " 470 "dialog which you can open from the <b>File</b> menu of the " 471 "main VirtualBox window, and select one of the existing " 472 "languages on the <b>Language</b> page.</p>") 473 .arg (aLangFile)); 474 } 475 448 476 void VBoxProblemReporter::cannotInitCOM (HRESULT rc) 449 477 { -
trunk/src/VBox/Frontends/VirtualBox/src/VMGlobalSettings.cpp
r2022 r2044 97 97 { "GUI/Input/AutoCapture", "autoCapture", "true|false" }, 98 98 { "GUI/Customizations", "guiFeatures", "\\S+" }, 99 { "GUI/LanguageID", "languageId", "([a-z]{2,5}(_[a-zA-Z]{2})?)?" }, 99 /* LanguageID regexp must correlate with gVBoxLangIDRegExp in 100 * VBoxGlobal.cpp */ 101 { "GUI/LanguageID", "languageId", "(([a-z]{2})(_([A-Z]{2}))?)|(built_in)" }, 100 102 }; 101 103 -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui
r2022 r2044 782 782 <cstring>unnamed</cstring> 783 783 </property> 784 <property name="spacing"> 785 <number>10</number> 786 </property> 784 787 <widget class="QListView"> 785 788 <column> … … 791 794 </property> 792 795 <property name="resizable"> 793 <bool> false</bool>796 <bool>true</bool> 794 797 </property> 795 798 </column> … … 799 802 <property name="sizePolicy"> 800 803 <sizepolicy> 801 <hsizetype> 0</hsizetype>804 <hsizetype>4</hsizetype> 802 805 <vsizetype>7</vsizetype> 803 806 <horstretch>0</horstretch> … … 806 809 </property> 807 810 <property name="resizeMode"> 808 <enum> AllColumns</enum>811 <enum>NoColumn</enum> 809 812 </property> 810 813 <property name="whatsThis" stdset="0"> 811 <string>The list of languages available for interface translation.</string> 814 <string> 815 Lists all available user interface languages. The effective language 816 is written in <b>bold</b>. 817 </string> 812 818 </property> 813 819 </widget> … … 834 840 <property name="sizePolicy"> 835 841 <sizepolicy> 836 <hsizetype> 7</hsizetype>837 <vsizetype> 5</vsizetype>842 <hsizetype>1</hsizetype> 843 <vsizetype>1</vsizetype> 838 844 <horstretch>0</horstretch> 839 845 <verstretch>0</verstretch> … … 854 860 <sizepolicy> 855 861 <hsizetype>1</hsizetype> 856 <vsizetype> 5</vsizetype>862 <vsizetype>1</vsizetype> 857 863 <horstretch>0</horstretch> 858 864 <verstretch>0</verstretch> … … 873 879 <sizepolicy> 874 880 <hsizetype>1</hsizetype> 875 <vsizetype> 5</vsizetype>881 <vsizetype>1</vsizetype> 876 882 <horstretch>0</horstretch> 877 883 <verstretch>0</verstretch> … … 891 897 <property name="sizePolicy"> 892 898 <sizepolicy> 893 <hsizetype> 7</hsizetype>894 <vsizetype> 5</vsizetype>899 <hsizetype>1</hsizetype> 900 <vsizetype>1</vsizetype> 895 901 <horstretch>0</horstretch> 896 902 <verstretch>0</verstretch> … … 919 925 <size> 920 926 <width>20</width> 921 <height> 121</height>927 <height>0</height> 922 928 </size> 923 929 </property> … … 925 931 </vbox> 926 932 </widget> 933 <spacer> 934 <property name="name"> 935 <cstring>spacer8</cstring> 936 </property> 937 <property name="orientation"> 938 <enum>Horizontal</enum> 939 </property> 940 <property name="sizeType"> 941 <enum>Expanding</enum> 942 </property> 943 <property name="sizeHint"> 944 <size> 945 <width>0</width> 946 <height>20</height> 947 </size> 948 </property> 949 </spacer> 927 950 </hbox> 928 951 </widget> … … 1214 1237 <include location="global" impldecl="in implementation">qmessagebox.h</include> 1215 1238 <include location="global" impldecl="in implementation">qfont.h</include> 1239 <include location="global" impldecl="in implementation">qpainter.h</include> 1216 1240 <include location="global" impldecl="in implementation">qobjectlist.h</include> 1217 1241 <include location="global" impldecl="in implementation">qfiledialog.h</include> -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h
r2022 r2044 31 31 32 32 33 extern const QString transFileName; 34 extern const QString langIdRegExp; 35 extern const QString builtInName; 33 /* defined in VBoxGlobal.cpp */ 34 extern const char *gVBoxLangSubDir; 35 extern const char *gVBoxLangFileBase; 36 extern const char *gVBoxLangFileExt; 37 extern const char *gVBoxLangIDRegExp; 38 extern const char *gVBoxBuiltInLangName; 36 39 37 40 /** … … 83 86 enum { TypeId = 1001 }; 84 87 85 LanguageItem (QListView *aParent, const QString &aName)86 : QListViewItem (aParent, aName)87 {88 /* making separator field */89 if (aName == "-")90 {91 QString sepLine;92 while (listView()->fontMetrics().width (sepLine) < listView()->width())93 sepLine += "-";94 setText (0, sepLine);95 setSelectable (false);96 }97 }98 99 88 LanguageItem (QListView *aParent, const QTranslator &aTranslator, 100 89 const QString &aId, bool aBuiltIn = false) 101 : QListViewItem (aParent) 90 : QListViewItem (aParent), mBuiltIn (aBuiltIn), mInvalid (false) 102 91 { 103 92 QTranslatorMessage transMes; 104 93 105 QString nativeLanguage = translate (aTranslator, 106 "@@@", "English", "Native language name", aBuiltIn); 107 QString nativeCountry = translate (aTranslator, 108 "@@@", "built-in", "Native language country name " 109 "(empty if this language is for all countries)", aBuiltIn); 110 111 QString englishLanguage = translate (aTranslator, 112 "@@@", "English", "Language name, in English", aBuiltIn); 113 QString englishCountry = translate (aTranslator, 114 "@@@", "built-in", "Language country name, in English " 115 "(empty if native country name is empty)", aBuiltIn); 116 117 QString translatorsName = translate (aTranslator, 118 "@@@", "InnoTek", "Comma-separated list of translators", aBuiltIn); 119 if (translatorsName.isNull()) 120 translatorsName = QListView::tr ("--", "no info"); 94 /* Note: context/source/comment arguments below must match strings 95 * used in VBoxGlobal::languageName() and friends (the latter are the 96 * source of information for the lupdate tool that generates 97 * translation files) */ 98 99 QString nativeLanguage = tratra (aTranslator, 100 "@@@", "English", "Native language name"); 101 QString nativeCountry = tratra (aTranslator, 102 "@@@", "--", "Native language country name " 103 "(empty if this language is for all countries)"); 104 105 QString englishLanguage = tratra (aTranslator, 106 "@@@", "English", "Language name, in English"); 107 QString englishCountry = tratra (aTranslator, 108 "@@@", "--", "Language country name, in English " 109 "(empty if native country name is empty)"); 110 111 QString translatorsName = tratra (aTranslator, 112 "@@@", "InnoTek", "Comma-separated list of translators"); 121 113 122 114 QString itemName = nativeLanguage; 123 if (!nativeCountry.isNull())124 itemName += " (" + nativeCountry + ")";125 126 115 QString langName = englishLanguage; 127 if (!englishCountry.isNull()) 128 langName += " (" + englishCountry + ")"; 116 129 117 if (!aBuiltIn) 130 langName = itemName + " / " + langName; 118 { 119 if (nativeCountry != "--") 120 itemName += " (" + nativeCountry + ")"; 121 122 if (englishCountry != "--") 123 langName += " (" + englishCountry + ")"; 124 125 if (itemName != langName) 126 langName = itemName + " / " + langName; 127 } 128 else 129 { 130 itemName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language"); 131 langName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language"); 132 } 131 133 132 134 setText (0, itemName); … … 136 138 } 137 139 140 /* Constructs an item for an invalid language ID (i.e. when a language 141 * file is missing or corrupt). */ 142 LanguageItem (QListView *aParent, const QString &aId) 143 : QListViewItem (aParent), mBuiltIn (false), mInvalid (true) 144 { 145 setText (0, QString ("<%1>").arg (aId)); 146 setText (1, aId); 147 setText (2, VBoxGlobalSettingsDlg::tr ("<unavailabie>", "Language")); 148 setText (3, VBoxGlobalSettingsDlg::tr ("<unknown>", "Author(s)")); 149 } 150 138 151 int rtti() const { return TypeId; } 139 152 … … 142 155 QString thisValue = text (1); 143 156 QString thatValue = aItem->text (1); 144 if (thisValue == builtInName)157 if (thisValue == gVBoxBuiltInLangName) 145 158 return -1; 146 else if (thatValue == builtInName)159 else if (thatValue == gVBoxBuiltInLangName) 147 160 return 1; 148 161 else … … 151 164 152 165 void paintCell (QPainter *aPainter, const QColorGroup &aGroup, 153 int aColumn, int aWidth, int aSlign) 154 { 155 /* adjusting list-view width */ 156 int fullwidth = width (listView()->fontMetrics(), listView(), 0) + 4; 157 if (listView()->width() < fullwidth) 158 listView()->setFixedWidth (fullwidth); 159 /* standard paint procedure */ 160 QListViewItem::paintCell (aPainter, aGroup, aColumn, aWidth, aSlign); 166 int aColumn, int aWidth, int aAlign) 167 { 168 QFont font = aPainter->font(); 169 170 if (mInvalid) 171 font.setItalic (true); 172 /* mark the effectively active language */ 173 if (text (1) == VBoxGlobal::languageId()) 174 font.setBold (true); 175 176 if (aPainter->font() != font) 177 aPainter->setFont (font); 178 179 QListViewItem::paintCell (aPainter, aGroup, aColumn, aWidth, aAlign); 180 181 if (mBuiltIn) 182 { 183 int y = height() - 1; 184 aPainter->setPen (aGroup.mid()); 185 aPainter->drawLine (0, y, aWidth - 1, y); 186 } 187 } 188 189 int width (const QFontMetrics &aFM, const QListView *aLV, int aC) const 190 { 191 QFont font = aLV->font(); 192 193 if (mInvalid) 194 font.setItalic (true); 195 /* mark the effectively active language */ 196 if (text (1) == VBoxGlobal::languageId()) 197 font.setBold (true); 198 199 QFontMetrics fm = aFM; 200 if (aLV->font() != font) 201 fm = QFontMetrics (font); 202 203 return QListViewItem::width (fm, aLV, aC); 204 } 205 206 void setup () 207 { 208 QListViewItem::setup(); 209 if (mBuiltIn) 210 setHeight (height() + 1); 161 211 } 162 212 163 213 private: 164 214 165 QString translate (const QTranslator &aTranslator, const char *aCtxt, 166 const char *aSrc, const char *aCmnt, bool aBuiltIn) 167 { 168 QTranslatorMessage msg = aTranslator.findMessage (aCtxt, aSrc, aCmnt); 169 return msg.translation().isNull() && aBuiltIn ? QString (aSrc) : msg.translation(); 170 } 215 QString tratra (const QTranslator &aTranslator, const char *aCtxt, 216 const char *aSrc, const char *aCmnt) 217 { 218 QString msg = aTranslator.findMessage (aCtxt, aSrc, aCmnt).translation(); 219 /* return the source text if no translation is found */ 220 if (msg.isEmpty()) 221 msg = QString (aSrc); 222 return msg; 223 } 224 225 bool mBuiltIn : 1; 226 bool mInvalid : 1; 171 227 }; 172 228 … … 300 356 lvLanguages->header()->hide(); 301 357 lvLanguages->setSorting (0); 302 QString nlsPath = qApp->applicationDirPath() + "/nls";358 QString nlsPath = qApp->applicationDirPath() + gVBoxLangSubDir; 303 359 QDir nlsDir (nlsPath); 304 QStringList files = nlsDir.entryList (transFileName + "*", QDir::Files); 360 QStringList files = nlsDir.entryList (QString ("%1*%2") 361 .arg (gVBoxLangFileBase, gVBoxLangFileExt), 362 QDir::Files); 305 363 QTranslator translator; 306 new LanguageItem (lvLanguages, translator, builtInName, true /* built-in */); 307 new LanguageItem (lvLanguages, tr ("-")); 308 for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) 309 { 310 const QString &fileName = *it; 311 bool status = translator.load (fileName, nlsPath); 312 if (!status) continue; 313 314 QRegExp regExp (transFileName + langIdRegExp); 364 /* add the built-in language */ 365 new LanguageItem (lvLanguages, translator, gVBoxBuiltInLangName, true /* built-in */); 366 /* add all existing languages */ 367 for (QStringList::Iterator it = files.begin(); it != files.end(); ++ it) 368 { 369 QString fileName = *it; 370 QRegExp regExp (QString (gVBoxLangFileBase) + gVBoxLangIDRegExp); 315 371 int pos = regExp.search (fileName); 316 if (pos == -1) continue; 372 if (pos == -1) 373 continue; 374 375 bool loadOk = translator.load (fileName, nlsPath); 376 if (!loadOk) 377 continue; 317 378 318 379 new LanguageItem (lvLanguages, translator, regExp.cap (1)); 319 380 } 381 lvLanguages->adjustColumn (0); 320 382 321 383 /* … … 502 564 /* language properties */ 503 565 504 QListViewItem *item = lvLanguages->findItem (VBoxGlobal::languageID(), 1); 566 QString langId = gs.languageId(); 567 QListViewItem *item = lvLanguages->findItem (langId, 1); 568 if (!item) 569 { 570 /* add an item for an invalid language to represent it in the list */ 571 item = new LanguageItem (lvLanguages, langId); 572 lvLanguages->adjustColumn (0); 573 } 574 Assert (item); 505 575 if (item) 506 576 { … … 573 643 if (mLanguageChanged && selItem) 574 644 { 575 gs.setLanguageId (selItem->text (1) == VBoxGlobal::systemLanguageI D() ?645 gs.setLanguageId (selItem->text (1) == VBoxGlobal::systemLanguageId() ? 576 646 QString::null : selItem->text (1)); 577 647 VBoxGlobal::loadLanguage (selItem->text (1)); … … 846 916 tlLangData->setText (aItem->text (2)); 847 917 tlAuthorData->setText (aItem->text (3)); 848 if (!mLanguageChanged) 849 mLanguageChanged = true; 850 } 918 mLanguageChanged = true; 919 }
Note:
See TracChangeset
for help on using the changeset viewer.