1 | /* $Id: UITranslator.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UITranslator class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_globals_UITranslator_h
|
---|
29 | #define FEQT_INCLUDED_SRC_globals_UITranslator_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QTranslator>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UIDefs.h"
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 |
|
---|
41 | /** QTranslator subclass for VBox needs. */
|
---|
42 | class SHARED_LIBRARY_STUFF UITranslator : public QTranslator
|
---|
43 | {
|
---|
44 | Q_OBJECT;
|
---|
45 |
|
---|
46 | public:
|
---|
47 |
|
---|
48 | /** Loads the language by language ID.
|
---|
49 | * @param strLangId Brings the language ID in in form of xx_YY.
|
---|
50 | * QString() means the system default language. */
|
---|
51 | static void loadLanguage(const QString &strLangId = QString());
|
---|
52 |
|
---|
53 | /** Returns VBox language sub-directory. */
|
---|
54 | static QString vboxLanguageSubDirectory();
|
---|
55 | /** Returns VBox language file-base. */
|
---|
56 | static QString vboxLanguageFileBase();
|
---|
57 | /** Returns VBox language file-extension. */
|
---|
58 | static QString vboxLanguageFileExtension();
|
---|
59 | /** Returns VBox language ID reg-exp. */
|
---|
60 | static QString vboxLanguageIdRegExp();
|
---|
61 | /** Returns built in language name. */
|
---|
62 | static QString vboxBuiltInLanguageName();
|
---|
63 |
|
---|
64 | /** Returns the loaded (active) language ID. */
|
---|
65 | static QString languageId();
|
---|
66 |
|
---|
67 | /** Returns tr("%n year(s)"). */
|
---|
68 | static QString yearsToString(uint32_t cVal);
|
---|
69 | /** Returns tr("%n month(s)"). */
|
---|
70 | static QString monthsToString(uint32_t cVal);
|
---|
71 | /** Returns tr("%n day(s)"). */
|
---|
72 | static QString daysToString(uint32_t cVal);
|
---|
73 | /** Returns tr("%n hour(s)"). */
|
---|
74 | static QString hoursToString(uint32_t cVal);
|
---|
75 | /** Returns tr("%n minute(s)"). */
|
---|
76 | static QString minutesToString(uint32_t cVal);
|
---|
77 | /** Returns tr("%n second(s)"). */
|
---|
78 | static QString secondsToString(uint32_t cVal);
|
---|
79 |
|
---|
80 | /** Returns tr("%n year(s) ago"). */
|
---|
81 | static QString yearsToStringAgo(uint32_t cVal);
|
---|
82 | /** Returns tr("%n month(s) ago"). */
|
---|
83 | static QString monthsToStringAgo(uint32_t cVal);
|
---|
84 | /** Returns tr("%n day(s) ago"). */
|
---|
85 | static QString daysToStringAgo(uint32_t cVal);
|
---|
86 | /** Returns tr("%n hour(s) ago"). */
|
---|
87 | static QString hoursToStringAgo(uint32_t cVal);
|
---|
88 | /** Returns tr("%n minute(s) ago"). */
|
---|
89 | static QString minutesToStringAgo(uint32_t cVal);
|
---|
90 | /** Returns tr("%n second(s) ago"). */
|
---|
91 | static QString secondsToStringAgo(uint32_t cVal);
|
---|
92 |
|
---|
93 | /** Returns the decimal separator for the current locale. */
|
---|
94 | static QString decimalSep();
|
---|
95 | /** Returns the regexp string that defines the format of the human-readable size representation. */
|
---|
96 | static QString sizeRegexp();
|
---|
97 | /** Parses the given size strText and returns the size value in bytes. */
|
---|
98 | static quint64 parseSize(const QString &strText);
|
---|
99 | /** Parses the given size strText and returns the size suffix. */
|
---|
100 | static SizeSuffix parseSizeSuffix(const QString &strText);
|
---|
101 | /** Parses the given string @a strText and returns true if it includes a size suffix. */
|
---|
102 | static bool hasSizeSuffix(const QString &strText);
|
---|
103 | /** Formats the given @a uSize value in bytes to a human readable string.
|
---|
104 | * @param uSize Brings the size value in bytes.
|
---|
105 | * @param enmMode Brings the conversion mode.
|
---|
106 | * @param cDecimal Brings the number of decimal digits in result. */
|
---|
107 | static QString formatSize(quint64 uSize, uint cDecimal = 2, FormatSize enmMode = FormatSize_Round);
|
---|
108 | /** Formats the given @a uNumber to that 'k' is added for thousand, 'M' for million and so on. */
|
---|
109 | static QString addMetricSuffixToNumber(quint64 uNumber);
|
---|
110 |
|
---|
111 | /** Returns the list of the standard COM port names (i.e. "COMx"). */
|
---|
112 | static QStringList COMPortNames();
|
---|
113 | /** Returns the name of the standard COM port corresponding to the given parameters,
|
---|
114 | * or "User-defined" (which is also returned when both @a uIRQ and @a uIOBase are 0). */
|
---|
115 | static QString toCOMPortName(ulong uIRQ, ulong uIOBase);
|
---|
116 | /** Returns port parameters corresponding to the given standard COM name.
|
---|
117 | * Returns @c true on success, or @c false if the given port name is not one of the standard names (i.e. "COMx"). */
|
---|
118 | static bool toCOMPortNumbers(const QString &strName, ulong &uIRQ, ulong &uIOBase);
|
---|
119 |
|
---|
120 | /** Reformats the input @a strText to highlight it. */
|
---|
121 | static QString highlight(QString strText, bool fToolTip = false);
|
---|
122 | /** Reformats the input @a strText to emphasize it. */
|
---|
123 | static QString emphasize(QString strText);
|
---|
124 | /** Removes the first occurrence of the accelerator mark (the ampersand symbol) from the given @a strText. */
|
---|
125 | static QString removeAccelMark(QString strText);
|
---|
126 | /** Inserts a passed @a strKey into action @a strText. */
|
---|
127 | static QString insertKeyToActionText(const QString &strText, const QString &strKey);
|
---|
128 |
|
---|
129 | /** Returns whether we are performing translation currently. */
|
---|
130 | static bool isTranslationInProgress();
|
---|
131 |
|
---|
132 | /* Converts bytes string to megabytes string. */
|
---|
133 | static QString byteStringToMegaByteString(const QString &strByteString);
|
---|
134 | /* Converts megabytes string to bytes string. */
|
---|
135 | static QString megabyteStringToByteString(const QString &strMegaByteString);
|
---|
136 |
|
---|
137 | private:
|
---|
138 |
|
---|
139 | /** Constructs translator passing @a pParent to the base-class. */
|
---|
140 | UITranslator(QObject *pParent = 0);
|
---|
141 |
|
---|
142 | /** Loads language file with gained @a strFileName. */
|
---|
143 | bool loadFile(const QString &strFileName);
|
---|
144 |
|
---|
145 | /** Native language name of the currently installed translation. */
|
---|
146 | static QString languageName();
|
---|
147 | /** Native language country name of the currently installed translation. */
|
---|
148 | static QString languageCountry();
|
---|
149 | /** Language name of the currently installed translation, in English. */
|
---|
150 | static QString languageNameEnglish();
|
---|
151 | /** Language country name of the currently installed translation, in English. */
|
---|
152 | static QString languageCountryEnglish();
|
---|
153 | /** Comma-separated list of authors of the currently installed translation. */
|
---|
154 | static QString languageTranslators();
|
---|
155 |
|
---|
156 | /** Returns the system language ID. */
|
---|
157 | static QString systemLanguageId();
|
---|
158 |
|
---|
159 | /** Holds the singleton instance. */
|
---|
160 | static UITranslator *s_pTranslator;
|
---|
161 |
|
---|
162 | /** Holds whether we are performing translation currently. */
|
---|
163 | static bool s_fTranslationInProgress;
|
---|
164 |
|
---|
165 | /** Holds the currently loaded language ID. */
|
---|
166 | static QString s_strLoadedLanguageId;
|
---|
167 |
|
---|
168 | /** Holds the loaded data. */
|
---|
169 | QByteArray m_data;
|
---|
170 | };
|
---|
171 |
|
---|
172 | #endif /* !FEQT_INCLUDED_SRC_globals_UITranslator_h */
|
---|
173 |
|
---|