From 6c6dab5b8c4e31f3c85b59d476bdf8cd60eca85f Mon Sep 17 00:00:00 2001 From: zhoubin Date: Tue, 22 Oct 2024 18:15:13 +0800 Subject: [PATCH] feat: language MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 361631 子 【UKUI4.20】ukui-framework-统一接口开发 / 统一接口开发-其他类-本地信息接口多语言区域接口 Log: https://pm.kylin.com/task-view-361631.html --- dbus/CMakeLists.txt | 1 + dbus/others/CMakeLists.txt | 1 + dbus/others/local/CMakeLists.txt | 31 +++++++ dbus/others/local/src/local.cpp | 115 ++++++++++++++++++++++++++ dbus/others/local/src/local.h | 86 +++++++++++++++++++ dbus/others/local/test/CMakeLists.txt | 40 +++++++++ dbus/others/local/test/test.cpp | 39 +++++++++ 7 files changed, 313 insertions(+) create mode 100644 dbus/others/CMakeLists.txt create mode 100644 dbus/others/local/CMakeLists.txt create mode 100644 dbus/others/local/src/local.cpp create mode 100644 dbus/others/local/src/local.h create mode 100644 dbus/others/local/test/CMakeLists.txt create mode 100644 dbus/others/local/test/test.cpp diff --git a/dbus/CMakeLists.txt b/dbus/CMakeLists.txt index cdc82a9..d2b3596 100644 --- a/dbus/CMakeLists.txt +++ b/dbus/CMakeLists.txt @@ -1,5 +1,6 @@ find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Core DBus) add_subdirectory(devices) +add_subdirectory(others) aux_source_directory(SOURCES devices/README.md) diff --git a/dbus/others/CMakeLists.txt b/dbus/others/CMakeLists.txt new file mode 100644 index 0000000..0c64799 --- /dev/null +++ b/dbus/others/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(local) diff --git a/dbus/others/local/CMakeLists.txt b/dbus/others/local/CMakeLists.txt new file mode 100644 index 0000000..3d766c1 --- /dev/null +++ b/dbus/others/local/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.5) +project(local VERSION 1.0) + +add_subdirectory(test) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt5 COMPONENTS Core DBus REQUIRED) +find_package(PkgConfig) + +include_directories(${GLIB_INCLUDE_DIRS}) +include_directories(${GIO_INCLUDE_DIRS}) +include_directories(${GOBJECT_INCLUDE_DIRS}) + +add_library(${PROJECT_NAME} SHARED + src/local.h + src/local.cpp +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + Qt5::Core + Qt5::DBus +) diff --git a/dbus/others/local/src/local.cpp b/dbus/others/local/src/local.cpp new file mode 100644 index 0000000..f515e94 --- /dev/null +++ b/dbus/others/local/src/local.cpp @@ -0,0 +1,115 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*- + * -*- coding: utf-8 -*- + * + * Copyright (C) 2024 KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "local.h" + +#include +#include +#include + +Local::Local() +{ + +} + +Local::~Local() +{ + +} + +void Local::openDateSettingInterface() +{ + QProcess::startDetached("ukui-control-center -m date"); +} + +void Local::openAreaSettingInterface() +{ + QProcess::startDetached("ukui-control-center -m area"); +} + +void Local::openOSInformationInterface() +{ + QProcess::startDetached("ukui-control-center -m about"); +} + +void Local::kWinEffectEnable(bool enable) +{ + QString filename = QDir::homePath() + "/.config/ukui-kwinrc"; + QSettings kwinSettings(filename, QSettings::IniFormat, this); + + if (!enable) { + kwinSettings.beginGroup("Plugins"); + kwinSettings.setValue("kwin4_effect_maximizeEnabled", false); + kwinSettings.setValue("blurEnabled", false); + kwinSettings.endGroup(); + + for (int i = 0; i < effectList.length(); i++) { + QDBusMessage message = QDBusMessage::createMethodCall("org.ukui.KWin", + "/Effects", + "org.ukui.kwin.Effects", + "unloadEffect"); + message << effectList.at(i); + QDBusConnection::sessionBus().send(message); + } + } else { + kwinSettings.beginGroup("Plugins"); + kwinSettings.setValue("kwin4_effect_maximizeEnabled", true); + kwinSettings.setValue("blurEnabled", true); + + kwinSettings.endGroup(); + + for (int i = 0; i < effectList.length(); i++) { + + QDBusMessage message = QDBusMessage::createMethodCall("org.ukui.KWin", + "/Effects", + "org.ukui.kwin.Effects", + "loadEffect"); + message << effectList.at(i); + QDBusConnection::sessionBus().send(message); + } + + } + kwinSettings.sync(); +} + +void Local::timeZoneSet(const QString &timezone) +{ + QDBusInterface ukccSystemDbus("com.control.center.qt.systemdbus", + "/", + "com.control.center.interface", + QDBusConnection::systemBus()); + ukccSystemDbus.call("setShowTimezone", timezone); + + QDBusInterface timeDateInterface ("org.freedesktop.timedate1", + "/org/freedesktop/timedate1", + "org.freedesktop.timedate1", + QDBusConnection::systemBus()); + timeDateInterface.call("SetTimezone", timezone, true); +} + +void Local::setLanguage(const QString &language) +{ + unsigned int uid = getuid(); + QString objpath = "/org/freedesktop/Accounts/User" + QString::number(uid); + QDBusInterface languageDbus("org.freedesktop.Accounts", + objpath, + "org.freedesktop.Accounts.User", + QDBusConnection::systemBus()); + languageDbus.call("SetLanguage", language); +} diff --git a/dbus/others/local/src/local.h b/dbus/others/local/src/local.h new file mode 100644 index 0000000..e27a4c5 --- /dev/null +++ b/dbus/others/local/src/local.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*- + * -*- coding: utf-8 -*- + * + * Copyright (C) 2024 KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef Language_H +#define Language_H + +#include +#include +#include +#include +#include + + +class Local : public QObject, QDBusContext +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.ukui.imp.local") + +public: + Local(); + ~Local(); + +public Q_SLOTS: + /** + * @brief 打开时间设置界面 + * + * @param 无 + */ + void openDateSettingInterface(); + + /** + * @brief 打开区域语言设置界面 + * + * @param 无 + */ + void openAreaSettingInterface(); + + /** + * @brief 打开关于设置界面 + * + * @param 无 + */ + void openOSInformationInterface(); + + /** + * @brief 设置特效模式 + * + * @param enable 状态 + */ + void kWinEffectEnable(bool enable); + + /** + * @brief 修改时区 + * + * @param enable 状态 + */ + void timeZoneSet(const QString &timezone); + + /** + * @brief 设置语言 + * + * @param language 语言 + */ + void setLanguage(const QString &language); + +private: + const QStringList effectList {"blur", "kwin4_effect_maximize", "zoom"}; +}; + + +#endif // Local_H diff --git a/dbus/others/local/test/CMakeLists.txt b/dbus/others/local/test/CMakeLists.txt new file mode 100644 index 0000000..f375c83 --- /dev/null +++ b/dbus/others/local/test/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.5) +project(local_test VERSION 1.0) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt5 COMPONENTS Core DBus REQUIRED) +find_package(PkgConfig) + + +include_directories(${GLIB_INCLUDE_DIRS}) +include_directories(${GIO_INCLUDE_DIRS}) +include_directories(${GOBJECT_INCLUDE_DIRS}) + +include_directories( + ${QGS_INCLUDE_DIRS} + ../src +) + +add_executable(${PROJECT_NAME} + test.cpp + ../src/local.h + ../src/local.cpp +) + +target_include_directories(${PROJECT_NAME} PRIVATE) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + Qt5::Core + Qt5::DBus +) + + diff --git a/dbus/others/local/test/test.cpp b/dbus/others/local/test/test.cpp new file mode 100644 index 0000000..566232b --- /dev/null +++ b/dbus/others/local/test/test.cpp @@ -0,0 +1,39 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*- + * -*- coding: utf-8 -*- + * + * Copyright (C) 2024 KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "local.h" + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc,argv); + + Local *local = new Local(); + + QDBusConnection localDbus = QDBusConnection::sessionBus(); + if (localDbus.registerService("org.ukui.imp.local")) { + localDbus.registerObject("/local", local, + QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals + ); + } + app.exec(); + return 0; +} -- Gitee