VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UITranslator.h@ 104158

Last change on this file since 104158 was 103320, checked in by vboxsync, 10 months ago

FE/Qt: UITranslator: Get rid of UIDefs.h dependency; Moving SizeSuffix to appropriate place; Had to rework few places to simplify the dependencies.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/* $Id: UITranslator.h 103320 2024-02-12 16:40:52Z 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 "UILibraryDefs.h"
39
40/** Size suffixes. */
41enum SizeSuffix
42{
43 SizeSuffix_Byte = 0,
44 SizeSuffix_KiloByte,
45 SizeSuffix_MegaByte,
46 SizeSuffix_GigaByte,
47 SizeSuffix_TeraByte,
48 SizeSuffix_PetaByte,
49 SizeSuffix_Max
50};
51
52/** QTranslator subclass for VBox needs. */
53class SHARED_LIBRARY_STUFF UITranslator : public QTranslator
54{
55 Q_OBJECT;
56
57public:
58
59 /** Size formatting types. */
60 enum FormatSize
61 {
62 FormatSize_Round,
63 FormatSize_RoundDown,
64 FormatSize_RoundUp
65 };
66
67 /** Loads the language by language ID.
68 * @param strLangId Brings the language ID in in form of xx_YY.
69 * QString() means the system default language. */
70 static void loadLanguage(const QString &strLangId = QString());
71
72 /** Returns VBox language sub-directory. */
73 static QString vboxLanguageSubDirectory();
74 /** Returns VBox language file-base. */
75 static QString vboxLanguageFileBase();
76 /** Returns VBox language file-extension. */
77 static QString vboxLanguageFileExtension();
78 /** Returns VBox language ID reg-exp. */
79 static QString vboxLanguageIdRegExp();
80 /** Returns built in language name. */
81 static QString vboxBuiltInLanguageName();
82
83 /** Returns the loaded (active) language ID. */
84 static QString languageId();
85
86 /** Returns tr("%n year(s)"). */
87 static QString yearsToString(uint32_t cVal);
88 /** Returns tr("%n month(s)"). */
89 static QString monthsToString(uint32_t cVal);
90 /** Returns tr("%n day(s)"). */
91 static QString daysToString(uint32_t cVal);
92 /** Returns tr("%n hour(s)"). */
93 static QString hoursToString(uint32_t cVal);
94 /** Returns tr("%n minute(s)"). */
95 static QString minutesToString(uint32_t cVal);
96 /** Returns tr("%n second(s)"). */
97 static QString secondsToString(uint32_t cVal);
98
99 /** Returns tr("%n year(s) ago"). */
100 static QString yearsToStringAgo(uint32_t cVal);
101 /** Returns tr("%n month(s) ago"). */
102 static QString monthsToStringAgo(uint32_t cVal);
103 /** Returns tr("%n day(s) ago"). */
104 static QString daysToStringAgo(uint32_t cVal);
105 /** Returns tr("%n hour(s) ago"). */
106 static QString hoursToStringAgo(uint32_t cVal);
107 /** Returns tr("%n minute(s) ago"). */
108 static QString minutesToStringAgo(uint32_t cVal);
109 /** Returns tr("%n second(s) ago"). */
110 static QString secondsToStringAgo(uint32_t cVal);
111
112 /** Returns the decimal separator for the current locale. */
113 static QString decimalSep();
114 /** Returns the regexp string that defines the format of the human-readable size representation. */
115 static QString sizeRegexp();
116 /** Parses the given size strText and returns the size value in bytes. */
117 static quint64 parseSize(const QString &strText);
118 /** Parses the given size strText and returns the size suffix. */
119 static SizeSuffix parseSizeSuffix(const QString &strText);
120 /** Parses the given string @a strText and returns true if it includes a size suffix. */
121 static bool hasSizeSuffix(const QString &strText);
122 /** Formats the given @a uSize value in bytes to a human readable string.
123 * @param uSize Brings the size value in bytes.
124 * @param enmMode Brings the conversion mode.
125 * @param cDecimal Brings the number of decimal digits in result. */
126 static QString formatSize(quint64 uSize, uint cDecimal = 2, FormatSize enmMode = FormatSize_Round);
127 /** Formats the given @a uNumber to that 'k' is added for thousand, 'M' for million and so on. */
128 static QString addMetricSuffixToNumber(quint64 uNumber);
129
130 /** Returns the list of the standard COM port names (i.e. "COMx"). */
131 static QStringList COMPortNames();
132 /** Returns the name of the standard COM port corresponding to the given parameters,
133 * or "User-defined" (which is also returned when both @a uIRQ and @a uIOBase are 0). */
134 static QString toCOMPortName(ulong uIRQ, ulong uIOBase);
135 /** Returns port parameters corresponding to the given standard COM name.
136 * Returns @c true on success, or @c false if the given port name is not one of the standard names (i.e. "COMx"). */
137 static bool toCOMPortNumbers(const QString &strName, ulong &uIRQ, ulong &uIOBase);
138
139 /** Reformats the input @a strText to highlight it. */
140 static QString highlight(QString strText, bool fToolTip = false);
141 /** Reformats the input @a strText to emphasize it. */
142 static QString emphasize(QString strText);
143 /** Removes the first occurrence of the accelerator mark (the ampersand symbol) from the given @a strText. */
144 static QString removeAccelMark(QString strText);
145 /** Inserts a passed @a strKey into action @a strText. */
146 static QString insertKeyToActionText(const QString &strText, const QString &strKey);
147
148 /** Returns whether we are performing translation currently. */
149 static bool isTranslationInProgress();
150
151 /* Converts bytes string to megabytes string. */
152 static QString byteStringToMegaByteString(const QString &strByteString);
153 /* Converts megabytes string to bytes string. */
154 static QString megabyteStringToByteString(const QString &strMegaByteString);
155
156private:
157
158 /** Constructs translator passing @a pParent to the base-class. */
159 UITranslator(QObject *pParent = 0);
160
161 /** Loads language file with gained @a strFileName. */
162 bool loadFile(const QString &strFileName);
163
164 /** Native language name of the currently installed translation. */
165 static QString languageName();
166 /** Native language country name of the currently installed translation. */
167 static QString languageCountry();
168 /** Language name of the currently installed translation, in English. */
169 static QString languageNameEnglish();
170 /** Language country name of the currently installed translation, in English. */
171 static QString languageCountryEnglish();
172 /** Comma-separated list of authors of the currently installed translation. */
173 static QString languageTranslators();
174
175 /** Returns the system language ID. */
176 static QString systemLanguageId();
177
178 /** Holds the singleton instance. */
179 static UITranslator *s_pTranslator;
180
181 /** Holds whether we are performing translation currently. */
182 static bool s_fTranslationInProgress;
183
184 /** Holds the currently loaded language ID. */
185 static QString s_strLoadedLanguageId;
186
187 /** Holds the loaded data. */
188 QByteArray m_data;
189};
190
191#endif /* !FEQT_INCLUDED_SRC_globals_UITranslator_h */
192
Note: See TracBrowser for help on using the repository browser.

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