|
13 | 13 |
|
14 | 14 | #include <QApplication> |
15 | 15 | #include <QDBusConnection> |
| 16 | +#include <QDBusConnectionInterface> |
16 | 17 | #include <QDBusInterface> |
17 | 18 | #include <QDBusMessage> |
| 19 | +#include <QDBusServiceWatcher> |
18 | 20 | #include <QTime> |
19 | 21 | #include <QWidget> |
20 | 22 |
|
21 | 23 | #define NETWORK_KEY "network-item-key" |
22 | 24 |
|
| 25 | +static QString networkService = "org.deepin.service.SystemNetwork"; |
| 26 | +static QString networkPath = "/org/deepin/service/SystemNetwork"; |
| 27 | +static QString networkInterface = "org.deepin.service.SystemNetwork"; |
| 28 | + |
23 | 29 | const int CONTENT_SPACING = 10; |
24 | 30 |
|
25 | 31 | static Q_LOGGING_CATEGORY(DNC, "org.deepin.dde.session-shell.network"); |
@@ -279,5 +285,49 @@ void NetworkPlugin::setMessage(bool visible) |
279 | 285 | qCInfo(DNC) << "Set message:" << doc.toJson(); |
280 | 286 | } |
281 | 287 |
|
| 288 | +QString NetworkPlugin::message(const QString &msgData) |
| 289 | +{ |
| 290 | + qDebug() << "message" << msgData; |
| 291 | + QJsonDocument json = QJsonDocument::fromJson(msgData.toLatin1()); |
| 292 | + QJsonObject jsonObject = json.object(); |
| 293 | + if (!jsonObject.contains("data")) { |
| 294 | + qWarning() << "msgData don't containt data" << msgData; |
| 295 | + QJsonDocument jsonResult; |
| 296 | + QJsonObject resultObject; |
| 297 | + resultObject.insert("data", QString("msgData don't containt data %1").arg(msgData)); |
| 298 | + jsonResult.setObject(resultObject); |
| 299 | + return jsonResult.toJson(); |
| 300 | + } |
| 301 | + QJsonObject dataObject = jsonObject.value("data").toObject(); |
| 302 | + QString locale = dataObject.value("locale").toString(); |
| 303 | + qDebug() << "read locale" << locale; |
| 304 | + m_network->installTranslator(locale); |
| 305 | + // 同时更新网络服务的语言 |
| 306 | + if (QDBusConnection::systemBus().interface()->isServiceRegistered(networkService)) { |
| 307 | + qDebug() << "update SystemNetworm Language" << locale; |
| 308 | + QDBusInterface dbusInter(networkService, networkPath, networkInterface, QDBusConnection::systemBus()); |
| 309 | + QDBusPendingCall reply = dbusInter.asyncCall("UpdateLanguage", locale); |
| 310 | + reply.waitForFinished(); |
| 311 | + } else { |
| 312 | + qWarning() << networkService << "don't start, wait for it start"; |
| 313 | + QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(this); |
| 314 | + serviceWatcher->setConnection(QDBusConnection::systemBus()); |
| 315 | + serviceWatcher->addWatchedService(networkService); |
| 316 | + connect(serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [locale](const QString &service) { |
| 317 | + if (service == networkService) { |
| 318 | + QDBusInterface dbusInter(networkService, networkPath, networkInterface, QDBusConnection::systemBus()); |
| 319 | + QDBusPendingCall reply = dbusInter.asyncCall("UpdateLanguage", locale); |
| 320 | + reply.waitForFinished(); |
| 321 | + } |
| 322 | + }); |
| 323 | + } |
| 324 | + |
| 325 | + QJsonDocument jsonResult; |
| 326 | + QJsonObject resultObject; |
| 327 | + resultObject.insert("data", "success"); |
| 328 | + jsonResult.setObject(resultObject); |
| 329 | + return jsonResult.toJson(); |
| 330 | +} |
| 331 | + |
282 | 332 | } // namespace network |
283 | 333 | } // namespace dde |
0 commit comments