Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dss-network-plugin/networkmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ void NetworkModule::installTranslator(const QString &locale)
}
localTmp = locale;
QApplication::removeTranslator(&translator);
translator.load(QLocale(locale), "dss-network-plugin", "_", "/usr/share/dss-network-plugin/translations");
QApplication::installTranslator(&translator);
if (translator.load(QLocale(locale), "dss-network-plugin", "_", "/usr/share/dss-network-plugin/translations")) {
QApplication::installTranslator(&translator);
}
m_manager->updateLanguage(localTmp);
}

Expand Down
42 changes: 39 additions & 3 deletions network-service-plugin/system/networkinitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
#include <QDBusMessage>

Check warning on line 20 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusMessage> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusServiceWatcher>

Check warning on line 21 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusServiceWatcher> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QEventLoop>

Check warning on line 22 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QEventLoop> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFile>

Check warning on line 23 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonDocument>

Check warning on line 24 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonDocument> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonObject>

Check warning on line 25 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonParseError>

Check warning on line 26 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonParseError> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMap>

Check warning on line 27 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMap> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMutex>

Check warning on line 28 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMutex> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 29 in network-service-plugin/system/networkinitialization.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTranslator>

using namespace network::systemservice;
Expand Down Expand Up @@ -110,10 +112,12 @@
// 调用checkAccountStatus检查当前用户状态并安装当前用户的语言
qCDebug(DSM) << "check connection status";
checkAccountStatus();
if (!m_initilized)
if (!m_initilized) {
qCWarning(DSM) << "can not found current user, used default lauguage to create connection";
// 不管语言有没有安装上,直接添加新连接,如果语言没有安装上,这个时候肯定不会有当前用户的语言了,此时安装就安装默认的英文
// 如果语言安装上了,此时就使用已经安装的语言来新建连接
// 不管语言有没有安装上,直接添加新连接,如果语言没有安装上,这个时候肯定不会有当前用户的语言了,此时安装就安装默认的
// 如果语言安装上了,此时就使用已经安装的语言来新建连接
installSystemTranslator();
}
addFirstConnection();
});
}
Expand Down Expand Up @@ -371,6 +375,11 @@
return false;
}

return installTranslator(locale);
}

bool NetworkInitialization::installTranslator(const QString &locale)
{
static QString localTmp;

if (localTmp != locale) {
Expand All @@ -388,6 +397,33 @@
return true;
}

bool NetworkInitialization::installSystemTranslator()
{
QFile file("/etc/locale.conf");
if (file.open(QFile::ReadOnly)) {
QMap<QString, QString> localeMap;
QString data = file.readAll();
QStringList lines = data.split('\n');
for (auto &&line : lines) {
QStringList pair = line.split('=');
if (pair.size() == 2) {
localeMap.insert(pair.at(0).trimmed(), pair.at(1).trimmed());
}
}
QString locale;
if (localeMap.contains("LANGUAGE")) {
locale = localeMap.value("LANGUAGE").split('.').first();
} else if (localeMap.contains("LANG")) {
locale = localeMap.value("LANG").split('.').first();
} else {
return false;
}
qCInfo(DSM) << "Install system language:" << locale;
return installTranslator(locale);
}
return false;
}

void NetworkInitialization::hideWirelessDevice(const QSharedPointer<NetworkManager::Device> &device, bool disableNetwork)
{
if (!disableNetwork)
Expand Down
2 changes: 2 additions & 0 deletions network-service-plugin/system/networkinitialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class NetworkInitialization : public QObject
bool hasConnection(const QSharedPointer<NetworkManager::WiredDevice> &device, QList<QSharedPointer<NetworkManager::Connection>> &unSaveDevices);
QString connectionMatchName() const;
bool installUserTranslator(const QString &json);
bool installTranslator(const QString &locale);
bool installSystemTranslator();
void hideWirelessDevice(const QSharedPointer<NetworkManager::Device> &device, bool disableNetwork);
void initDeviceConnection(const QSharedPointer<NetworkManager::WiredDevice> &device);
void checkAccountStatus();
Expand Down