mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: split uiLanguage() in two functions
The uiLanguage() function was used for two purposes: to initialize the language related preferences and to read the current language. To make things more easy to follow, split this function in two: one for initializing, one for getting the current language. Moreover, don't return the current locale in an out-parameter as there is already a function to do that [getLocale()]. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2dca7d0ce5
commit
eb55ffde16
8 changed files with 19 additions and 20 deletions
core
desktop-widgets
map-widget
|
@ -39,7 +39,7 @@ void reverseGeoLookup(degrees_t latitude, degrees_t longitude, taxonomy_data *ta
|
||||||
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
|
|
||||||
// first check the findNearbyPlaces API from geonames - that should give us country, state, city
|
// first check the findNearbyPlaces API from geonames - that should give us country, state, city
|
||||||
request.setUrl(geonamesURL.arg(uiLanguage(NULL).section(QRegExp("[-_ ]"), 0, 0)).arg(latitude.udeg / 1000000.0).arg(longitude.udeg / 1000000.0));
|
request.setUrl(geonamesURL.arg(getUiLanguage().section(QRegExp("[-_ ]"), 0, 0)).arg(latitude.udeg / 1000000.0).arg(longitude.udeg / 1000000.0));
|
||||||
|
|
||||||
// By using a std::unique_ptr<>, we can exit from the function at any point
|
// By using a std::unique_ptr<>, we can exit from the function at any point
|
||||||
// and the reply will be freed. Likewise, when overwriting the pointer with
|
// and the reply will be freed. Likewise, when overwriting the pointer with
|
||||||
|
@ -119,7 +119,7 @@ void reverseGeoLookup(degrees_t latitude, degrees_t longitude, taxonomy_data *ta
|
||||||
reply->abort();
|
reply->abort();
|
||||||
}
|
}
|
||||||
// next check the oceans API to figure out the body of water
|
// next check the oceans API to figure out the body of water
|
||||||
request.setUrl(geonamesOceanURL.arg(uiLanguage(NULL).section(QRegExp("[-_ ]"), 0, 0)).arg(latitude.udeg / 1000000.0).arg(longitude.udeg / 1000000.0));
|
request.setUrl(geonamesOceanURL.arg(getUiLanguage().section(QRegExp("[-_ ]"), 0, 0)).arg(latitude.udeg / 1000000.0).arg(longitude.udeg / 1000000.0));
|
||||||
reply.reset(rgl.get(request)); // Note: frees old reply.
|
reply.reset(rgl.get(request)); // Note: frees old reply.
|
||||||
QObject::connect(&*reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
QObject::connect(&*reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
timer.start(5000); // 5 secs. timeout
|
timer.start(5000); // 5 secs. timeout
|
||||||
|
|
|
@ -70,7 +70,9 @@ void init_qt_late()
|
||||||
loc.setDefault(QLocale("es_ES"));
|
loc.setDefault(QLocale("es_ES"));
|
||||||
loc = QLocale();
|
loc = QLocale();
|
||||||
}
|
}
|
||||||
QString uiLang = uiLanguage(&loc);
|
initUiLanguage();
|
||||||
|
QString uiLang = getUiLanguage();
|
||||||
|
loc = getLocale();
|
||||||
QLocale::setDefault(loc);
|
QLocale::setDefault(loc);
|
||||||
|
|
||||||
qtTranslator = new QTranslator;
|
qtTranslator = new QTranslator;
|
||||||
|
|
|
@ -426,7 +426,7 @@ QString getUserAgent()
|
||||||
userAgent.append(arch);
|
userAgent.append(arch);
|
||||||
if (arch == "i386")
|
if (arch == "i386")
|
||||||
userAgent.append("/" + SubsurfaceSysInfo::currentCpuArchitecture());
|
userAgent.append("/" + SubsurfaceSysInfo::currentCpuArchitecture());
|
||||||
userAgent.append(":" + uiLanguage(NULL));
|
userAgent.append(":" + getUiLanguage());
|
||||||
return userAgent;
|
return userAgent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -438,21 +438,20 @@ extern "C" const char *subsurface_user_agent()
|
||||||
return copy_qstring(uA);
|
return copy_qstring(uA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getUiLanguage()
|
||||||
|
{
|
||||||
|
return prefs.locale.lang_locale;
|
||||||
|
}
|
||||||
|
|
||||||
/* TOOD: Move this to SettingsObjectWrapper, and also fix this complexity.
|
/* TOOD: Move this to SettingsObjectWrapper, and also fix this complexity.
|
||||||
* gezus.
|
* gezus.
|
||||||
*/
|
*/
|
||||||
QString uiLanguage(QLocale *callerLoc)
|
void initUiLanguage()
|
||||||
{
|
{
|
||||||
QString shortDateFormat;
|
QString shortDateFormat;
|
||||||
QString dateFormat;
|
QString dateFormat;
|
||||||
QString timeFormat;
|
QString timeFormat;
|
||||||
|
|
||||||
// Language settings are already loaded, see qPref::load()
|
|
||||||
// so no need to reload them
|
|
||||||
|
|
||||||
// remark this method used "useSystemLanguage", which is not set
|
|
||||||
// instead use_system_language is loaded from disk
|
|
||||||
|
|
||||||
// set loc as system language or selected language
|
// set loc as system language or selected language
|
||||||
if (!qPrefLanguage::use_system_language()) {
|
if (!qPrefLanguage::use_system_language()) {
|
||||||
loc = QLocale(qPrefLanguage::lang_locale());
|
loc = QLocale(qPrefLanguage::lang_locale());
|
||||||
|
@ -483,8 +482,6 @@ QString uiLanguage(QLocale *callerLoc)
|
||||||
else if (languages.count() > 2 && languages[2].contains('-'))
|
else if (languages.count() > 2 && languages[2].contains('-'))
|
||||||
uiLang = languages[2];
|
uiLang = languages[2];
|
||||||
}
|
}
|
||||||
if (callerLoc)
|
|
||||||
*callerLoc = loc;
|
|
||||||
|
|
||||||
prefs.locale.lang_locale = copy_qstring(uiLang);
|
prefs.locale.lang_locale = copy_qstring(uiLang);
|
||||||
|
|
||||||
|
@ -515,7 +512,6 @@ QString uiLanguage(QLocale *callerLoc)
|
||||||
free((void *)prefs.time_format);
|
free((void *)prefs.time_format);
|
||||||
prefs.time_format = copy_qstring(timeFormat);
|
prefs.time_format = copy_qstring(timeFormat);
|
||||||
}
|
}
|
||||||
return uiLang;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QLocale getLocale()
|
QLocale getLocale()
|
||||||
|
|
|
@ -77,7 +77,8 @@ QString get_first_dive_date_string();
|
||||||
QString get_last_dive_date_string();
|
QString get_last_dive_date_string();
|
||||||
QString get_short_dive_date_string(timestamp_t when);
|
QString get_short_dive_date_string(timestamp_t when);
|
||||||
QString get_trip_date_string(timestamp_t when, int nr, bool getday);
|
QString get_trip_date_string(timestamp_t when, int nr, bool getday);
|
||||||
QString uiLanguage(QLocale *callerLoc);
|
QString getUiLanguage();
|
||||||
|
void initUiLanguage();
|
||||||
QLocale getLocale();
|
QLocale getLocale();
|
||||||
QVector<QPair<QString, int>> selectedDivesGasUsed();
|
QVector<QPair<QString, int>> selectedDivesGasUsed();
|
||||||
QString getUserAgent();
|
QString getUserAgent();
|
||||||
|
|
|
@ -89,7 +89,7 @@ void PreferencesLanguage::syncSettings()
|
||||||
qPrefLanguage::set_time_format(ui->timeFormatEntry->currentText());
|
qPrefLanguage::set_time_format(ui->timeFormatEntry->currentText());
|
||||||
qPrefLanguage::set_date_format(ui->dateFormatEntry->currentText());
|
qPrefLanguage::set_date_format(ui->dateFormatEntry->currentText());
|
||||||
qPrefLanguage::set_date_format_short(ui->shortDateFormatEntry->text());
|
qPrefLanguage::set_date_format_short(ui->shortDateFormatEntry->text());
|
||||||
uiLanguage(NULL);
|
initUiLanguage();
|
||||||
|
|
||||||
QString qDateTimeWeb = tr("These will be used as is. This might not be what you intended.\nSee http://doc.qt.io/qt-5/qdatetime.html#toString");
|
QString qDateTimeWeb = tr("These will be used as is. This might not be what you intended.\nSee http://doc.qt.io/qt-5/qdatetime.html#toString");
|
||||||
QRegExp tfillegalchars("[^hHmszaApPt\\s:;\\.,]");
|
QRegExp tfillegalchars("[^hHmszaApPt\\s:;\\.,]");
|
||||||
|
|
|
@ -64,7 +64,7 @@ UserManual::UserManual(QWidget *parent) : QDialog(parent)
|
||||||
QString searchPath = getSubsurfaceDataPath("Documentation");
|
QString searchPath = getSubsurfaceDataPath("Documentation");
|
||||||
if (searchPath.size()) {
|
if (searchPath.size()) {
|
||||||
// look for localized versions of the manual first
|
// look for localized versions of the manual first
|
||||||
QString lang = uiLanguage(NULL);
|
QString lang = getUiLanguage();
|
||||||
QString prefix = searchPath.append("/user-manual");
|
QString prefix = searchPath.append("/user-manual");
|
||||||
QFile manual(prefix + "_" + lang + ".html");
|
QFile manual(prefix + "_" + lang + ".html");
|
||||||
if (!manual.exists())
|
if (!manual.exists())
|
||||||
|
|
|
@ -31,7 +31,7 @@ UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent),
|
||||||
QString osArch = SubsurfaceSysInfo::currentCpuArchitecture();
|
QString osArch = SubsurfaceSysInfo::currentCpuArchitecture();
|
||||||
os.append(QString("&osCpuArch=%1").arg(osArch));
|
os.append(QString("&osCpuArch=%1").arg(osArch));
|
||||||
}
|
}
|
||||||
os.append(QString("&uiLang=%1").arg(uiLanguage(NULL)));
|
os.append(QString("&uiLang=%1").arg(getUiLanguage()));
|
||||||
os.append(QString("&uuid=%1").arg(getUUID()));
|
os.append(QString("&uuid=%1").arg(getUUID()));
|
||||||
ui->system->setPlainText(getVersion());
|
ui->system->setPlainText(getVersion());
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ QString UserSurvey::getVersion()
|
||||||
sysInfo.append(tr("\nCPU architecture: %1").arg(arch));
|
sysInfo.append(tr("\nCPU architecture: %1").arg(arch));
|
||||||
if (arch == "i386")
|
if (arch == "i386")
|
||||||
sysInfo.append(tr("\nOS CPU architecture: %1").arg(SubsurfaceSysInfo::currentCpuArchitecture()));
|
sysInfo.append(tr("\nOS CPU architecture: %1").arg(SubsurfaceSysInfo::currentCpuArchitecture()));
|
||||||
sysInfo.append(tr("\nLanguage: %1").arg(uiLanguage(NULL)));
|
sysInfo.append(tr("\nLanguage: %1").arg(getUiLanguage()));
|
||||||
return sysInfo;
|
return sysInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ bool MapWidgetHelper::editMode() const
|
||||||
|
|
||||||
QString MapWidgetHelper::pluginObject()
|
QString MapWidgetHelper::pluginObject()
|
||||||
{
|
{
|
||||||
QString lang = uiLanguage(NULL).replace('_', '-');
|
QString lang = getUiLanguage().replace('_', '-');
|
||||||
QString cacheFolder = QString(system_default_directory()).append("/googlemaps").replace("\\", "/");
|
QString cacheFolder = QString(system_default_directory()).append("/googlemaps").replace("\\", "/");
|
||||||
return QStringLiteral("import QtQuick 2.0;"
|
return QStringLiteral("import QtQuick 2.0;"
|
||||||
"import QtLocation 5.3;"
|
"import QtLocation 5.3;"
|
||||||
|
|
Loading…
Add table
Reference in a new issue