code format
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#include "qad_locations.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QTranslator>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
# include <QStandardPaths>
|
||||
#else
|
||||
@@ -17,10 +18,11 @@
|
||||
|
||||
class __QADTranslators__ {
|
||||
public:
|
||||
static QList<QTranslator * > & translators() {
|
||||
static QList<QTranslator * > ret;
|
||||
static QList<QTranslator *> & translators() {
|
||||
static QList<QTranslator *> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -29,25 +31,24 @@ QString QAD::userPath(QAD::LocationType loc, QString name) {
|
||||
QString dir, ext;
|
||||
switch (loc) {
|
||||
case ltConfig: ext = ".conf"; break;
|
||||
case ltCache : ext = ".cache"; break;
|
||||
case ltCache: ext = ".cache"; break;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QStandardPaths::StandardLocation l = QStandardPaths::AppConfigLocation;
|
||||
switch (loc) {
|
||||
case ltConfig: l = QStandardPaths::AppConfigLocation; break;
|
||||
case ltCache : l = QStandardPaths::CacheLocation; break;
|
||||
case ltCache: l = QStandardPaths::CacheLocation; break;
|
||||
}
|
||||
dir = QStandardPaths::writableLocation(l);
|
||||
#else
|
||||
QDesktopServices::StandardLocation l = QDesktopServices::DataLocation;
|
||||
switch (loc) {
|
||||
case ltConfig: l = QDesktopServices::DataLocation; break;
|
||||
case ltCache : l = QDesktopServices::CacheLocation; break;
|
||||
case ltCache: l = QDesktopServices::CacheLocation; break;
|
||||
}
|
||||
dir = QDesktopServices::storageLocation(l);
|
||||
#endif
|
||||
if (!QDir(dir).exists())
|
||||
QDir().mkpath(dir);
|
||||
if (!QDir(dir).exists()) QDir().mkpath(dir);
|
||||
return dir + "/" + name + ext;
|
||||
}
|
||||
|
||||
@@ -70,22 +71,20 @@ QStringList QAD::resourcePaths(QString type) {
|
||||
|
||||
void QAD::loadTranslations(QString lang) {
|
||||
unloadTranslations();
|
||||
if (lang.isEmpty())
|
||||
lang = QLocale().bcp47Name();
|
||||
if (lang.isEmpty()) lang = QLocale().bcp47Name();
|
||||
QString short_lang = lang.left(2);
|
||||
QStringList dirs = resourcePaths("lang");
|
||||
QStringList dirs = resourcePaths("lang");
|
||||
for (const QString & d: dirs) {
|
||||
QDirIterator dit(d);
|
||||
while (dit.hasNext()) {
|
||||
dit.next();
|
||||
if (!dit.filePath().endsWith(".qm")) continue;
|
||||
if (!dit.fileInfo().baseName().endsWith(lang) &&
|
||||
!dit.fileInfo().baseName().endsWith(short_lang)) continue;
|
||||
if (!dit.fileInfo().baseName().endsWith(lang) && !dit.fileInfo().baseName().endsWith(short_lang)) continue;
|
||||
QTranslator * tr = new QTranslator();
|
||||
if (tr->load(dit.filePath())) {
|
||||
qApp->installTranslator(tr);
|
||||
__QADTranslators__::translators() << tr;
|
||||
//qDebug() << "Add tr" << dit.fileName();
|
||||
// qDebug() << "Add tr" << dit.fileName();
|
||||
} else {
|
||||
qDebug() << "Can`t load translation" << dit.fileName();
|
||||
delete tr;
|
||||
@@ -96,14 +95,13 @@ void QAD::loadTranslations(QString lang) {
|
||||
|
||||
|
||||
void QAD::unloadTranslations() {
|
||||
//qDebug() << "removeTranslator ...";
|
||||
// qDebug() << "removeTranslator ...";
|
||||
for (QTranslator * t: __QADTranslators__::translators()) {
|
||||
qApp->removeTranslator(t);
|
||||
delete t;
|
||||
}
|
||||
__QADTranslators__::translators().clear();
|
||||
//qDebug() << "removeTranslator done";
|
||||
|
||||
// qDebug() << "removeTranslator done";
|
||||
}
|
||||
|
||||
|
||||
@@ -129,8 +127,7 @@ QStringList QAD::availableTranslations() {
|
||||
}
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
QLocale loc(lang[i]);
|
||||
if (loc.language() != QLocale::C)
|
||||
ret << lang[i];
|
||||
if (loc.language() != QLocale::C) ret << lang[i];
|
||||
}
|
||||
}
|
||||
delete tr;
|
||||
|
||||
Reference in New Issue
Block a user