Skip to content

Commit

Permalink
refactor: adapts to Qt 6
Browse files Browse the repository at this point in the history
适配Qt6
  • Loading branch information
myml committed Dec 5, 2024
1 parent 7db142b commit 2a52c61
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 132 deletions.
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(QT_VERSION_MAJOR 6)
set(DTK_VERSION_MAJOR 6)

find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Quick)
find_package(QT NAMES Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)
find_package(DtkDeclarative REQUIRED)
find_package(Dtk${DTK_VERSION_MAJOR}Declarative REQUIRED)

# 旧版本Dtk不支持使用cmake find_package 获取版本号, 使用 PkgConfig 来获取版本号
find_package(PkgConfig REQUIRED)
pkg_check_modules(DtkDeclarativeModule REQUIRED dtkdeclarative)
# DtkDeclarative 在 5.6.3 更改了插件的路径和使用方式 See: https://github.com/linuxdeepin/dtkdeclarative/commit/a9701858155b7118bfb53b6f241e35b9f6c0f15e
if(${DtkDeclarativeModule_VERSION} VERSION_LESS "5.6.3")
set(DTK_OLD_VERSION True)
endif()
pkg_check_modules(Dtk${DTK_VERSION_MAJOR}DeclarativeModule REQUIRED dtk${DTK_VERSION_MAJOR}declarative)

add_definitions(-DAPP_VERSION="${APP_VERSION}")
add_subdirectory(src)
add_subdirectory(3rdparty/apiserver/client)

set(ENV{QT_SELECT} qt5)
execute_process(COMMAND bash "-c" "lrelease translations/**/*"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(COMMAND bash "-c" "/usr/lib/qt${QT_VERSION_MAJOR}/bin/lrelease translations/**/*"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
28 changes: 13 additions & 15 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ Build-Depends:
debhelper-compat (= 12),
cmake,
pkg-config,
qtbase5-dev,
qtdeclarative5-dev,
libdtkcommon-dev,
libdtkcore-dev,
libdtkgui-dev,
libdtkdeclarative-dev,
qttools5-dev-tools,
qml-module-qtquick-controls,
qml-module-qtquick-dialogs,
qml-module-qtquick-controls2,
qml-module-qtquick-layouts,
qt6-base-dev,
qt6-declarative-dev,
libdtk6core-dev,
libdtk6gui-dev,
libdtk6declarative-dev,
qt6-l10n-tools,
qtchooser,
qml6-module-qtquick-controls,
qml6-module-qtquick-dialogs,
qml6-module-qtquick-layouts,
libssl-dev,
Standards-Version: 4.6.0
Rules-Requires-Root: no
Expand All @@ -26,10 +25,9 @@ Architecture: any
Depends:
${shlibs:Depends},
${misc:Depends},
qml-module-qtquick-controls,
qml-module-qtquick-dialogs,
qml-module-qtquick-controls2,
qml-module-qtquick-layouts,
qml6-module-qtquick-controls,
qml6-module-qtquick-dialogs,
qml6-module-qtquick-layouts,
inxi,
Description: deepin home
quick login bbs, bug report.
20 changes: 0 additions & 20 deletions linglong.yaml

This file was deleted.

10 changes: 6 additions & 4 deletions src/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ API::API(QString cacheName, QObject *parent)
{
init();
auto cache = new QNetworkDiskCache(parent);
auto cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation)+"/api_http_cache";
auto cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
+ "/api_http_cache";
cache->setCacheDirectory(cacheDir);
qDebug() << "api cache dir:" << cacheDir << QThread::currentThreadId();
m_http->setCache(cache);
Expand Down Expand Up @@ -54,18 +55,19 @@ T API::waitSignal(const typename QtPrivate::FunctionPointer<Func1>::Object *send
exp.err_msg = QString("http code %1").arg(worker->getHttpResponseCode());
}
auto headers = worker->getResponseHeaders();
if (!headers["Content-Type"].startsWith("application/json")) {
if (!headers["Content-Type"].startsWith("application/json")
&& !headers["content-type"].startsWith("application/json")) {
exp.err_code = 600;
exp.err_type = "http";
exp.err_msg = QString("http content: %1 != application/json")
exp.err_msg = QString("http content type: %1 != application/json")
.arg(headers["Content-Type"]);
}
result = resp;
loop.quit();
});
connect(sender, errSignal, &loop, [this, &loop, &exp](auto *worker, auto err_type, auto err_str) {
exp.err_code = worker->getHttpResponseCode();
exp.err_type = err_type;
exp.err_type = "http";
exp.err_msg = err_str;
if (exp.err_code == 0) {
exp.err_code = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/dbusservice/com.deepin.deepinid.Client.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="com.deepin.deepinid.Client">
<node>
<interface name="com.deepin.deepinid.Client">
<signal name="loadError">
</signal>
Expand Down
2 changes: 1 addition & 1 deletion src/dbusservice/com.deepin.deepinid.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="com.deepin.deepinid">
<node>
<interface name="com.deepin.deepinid">
<method name="Login"></method>
<method name="Logout"></method>
Expand Down
32 changes: 16 additions & 16 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,36 @@ set(DAEMON_SRC
../../translations/deepin-home-daemon.qrc
)

# Find the Qt5Quick library
find_package(Qt5Quick CONFIG REQUIRED)
find_package(Qt5DBus CONFIG REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED)
# Find the Qt Quick library
find_package(Qt${QT_VERSION_MAJOR}Quick CONFIG REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}DBus CONFIG REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Widgets CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)

# 通过 dbus 接口的 xml 描述文件,生成调用dbus的 cpp 代码
set_source_files_properties(../dbusservice/org.freedesktop.DBus.Properties.xml PROPERTIES CLASSNAME PropertiesChangedProxy)
set_source_files_properties(../dbusservice/org.freedesktop.DBus.Properties.xml PROPERTIES NO_NAMESPACE ON)
qt5_add_dbus_interface(DAEMON_SRC ../dbusservice/org.freedesktop.DBus.Properties.xml propertiesChangedProxy)
qt_add_dbus_interface(DAEMON_SRC ../dbusservice/org.freedesktop.DBus.Properties.xml propertiesChangedProxy)

set_source_files_properties(../dbusservice/org.desktopspec.ApplicationManager1.Application.xml PROPERTIES CLASSNAME ApplicationManager1Application)
set_source_files_properties(../dbusservice/org.desktopspec.ApplicationManager1.Application.xml PROPERTIES NO_NAMESPACE ON)
qt5_add_dbus_interface(DAEMON_SRC ../dbusservice/org.desktopspec.ApplicationManager1.Application.xml applicationManager1Application)
qt_add_dbus_interface(DAEMON_SRC ../dbusservice/org.desktopspec.ApplicationManager1.Application.xml applicationManager1Application)

set_source_files_properties(../dbusservice/com.deepin.deepinid.xml PROPERTIES CLASSNAME DeepinidDaemonProxy)
set_source_files_properties(../dbusservice/com.deepin.deepinid.xml PROPERTIES NO_NAMESPACE ON)
qt5_add_dbus_interface(DAEMON_SRC ../dbusservice/com.deepin.deepinid.xml deepinidDaemonProxy)
qt_add_dbus_interface(DAEMON_SRC ../dbusservice/com.deepin.deepinid.xml deepinidDaemonProxy)

set_source_files_properties(../dbusservice/com.deepin.deepinid.Client.xml PROPERTIES CLASSNAME DeepinidClientProxy)
set_source_files_properties(../dbusservice/com.deepin.deepinid.Client.xml PROPERTIES NO_NAMESPACE ON)
qt5_add_dbus_interface(DAEMON_SRC ../dbusservice/com.deepin.deepinid.Client.xml deepinidClientProxy)
qt_add_dbus_interface(DAEMON_SRC ../dbusservice/com.deepin.deepinid.Client.xml deepinidClientProxy)

set_source_files_properties(../dbusservice/com.deepin.Home.Daemon.xml PROPERTIES CLASSNAME HomeDaemonProxy)
qt5_add_dbus_interface(SRC ../dbusservice/com.deepin.Home.Daemon.xml homeDaemonProxy)
qt_add_dbus_interface(SRC ../dbusservice/com.deepin.Home.Daemon.xml homeDaemonProxy)

# 通过 dbus 接口的 xml 描述文件,生成 Adaptor 类,使用 Adaptor 可以选择性的暴露类接口到 dbus
# 可使用 qdbuscpp2xml 生成类的 xml 描述文件,再通过修改 xml 来隐藏部分接口
# daemon 的 xml 描述文件生成: qdbuscpp2xml "src/main/homeDaemon.h" "-o" "src/dbusservice/com.deepin.Home.Daemon.xml"
qt5_add_dbus_adaptor(DAEMON_SRC ../dbusservice/com.deepin.Home.Daemon.xml homeDaemon.h HomeDaemon homeDaemonAdaptor HomeDaemonAdaptor)
qt_add_dbus_adaptor(DAEMON_SRC ../dbusservice/com.deepin.Home.Daemon.xml homeDaemon.h HomeDaemon homeDaemonAdaptor HomeDaemonAdaptor)

# Add Client EXE
add_executable(${APP_NAME} ${SRC})
Expand All @@ -67,15 +67,15 @@ add_executable(${APP_DAEMON_NAME} ${DAEMON_SRC})

# 由于 EXE 只是作为启动程序加载 LIB 使用,一般来说,只需链接 ${LIB_NAME} 既可。
target_link_libraries(${APP_NAME}
Qt5::Quick
Qt5::DBus
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::DBus
${DtkDeclarative_LIBRARIES}
)
target_link_libraries(${APP_DAEMON_NAME}
Qt5::Core
Qt5::Network
Qt5::DBus
Qt5::Widgets
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Widgets
OpenSSL::SSL
API
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Account::Account(QObject *parent, API *api, QString server)
// 跟随deepinid退出登陆
if (!m_deepinidDaemon->isLogin()) {
this->m_isLogin = false;
this->m_token = false;
this->m_token = "";
emit this->userInfoChanged();
return;
}
Expand Down
19 changes: 9 additions & 10 deletions src/maincomponentplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ set(MAINCOMPONENNT_SRC
apiproxy.h
apiproxy.cpp
)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
find_package(Qt5QuickCompiler REQUIRED)
find_package(Qt5DBus CONFIG REQUIRED)
find_package(Qt5Concurrent CONFIG REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets)
find_package(Qt${QT_VERSION_MAJOR}DBus CONFIG REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Concurrent CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)

set_source_files_properties(../dbusservice/com.deepin.Home.Daemon.xml PROPERTIES CLASSNAME HomeDaemonProxy)
qt5_add_dbus_interface(MAINCOMPONENNT_SRC ../dbusservice/com.deepin.Home.Daemon.xml homeDaemonProxy)
qt_add_dbus_interface(MAINCOMPONENNT_SRC ../dbusservice/com.deepin.Home.Daemon.xml homeDaemonProxy)

qtquick_compiler_add_resources(MAINCOMPONENT_RCC_SOURCES maincomponent.qrc)
qt_add_resources(MAINCOMPONENT_RCC_SOURCES maincomponent.qrc)
include_directories(src/maincomponentplugin)
add_library(${MAINCOMPONENT_LIB_NAME} SHARED
${MAINCOMPONENNT_SRC}
Expand All @@ -33,10 +32,10 @@ target_include_directories(${MAINCOMPONENT_LIB_NAME}
${DTKDECLARATIVE_INCLUDE_DIR}
)
target_link_libraries(${MAINCOMPONENT_LIB_NAME}
Qt5::Quick
Qt5::Widgets
Qt5::DBus
Qt5::Concurrent
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Concurrent
OpenSSL::SSL
${DtkDeclarative_LIBRARIES}
API
Expand Down
2 changes: 1 addition & 1 deletion src/maincomponentplugin/apiproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void APIProxy::waitFuture(QFuture<T> future, Func2 receiver)
try {
receiver(watcher->result());
} catch (APIException exp) {
qCDebug(logger) << "api exception" << exp.err_code;
qCDebug(logger) << "api exception" << exp.err_code << exp.err_msg;
emit this->signalAPIError(exp.err_code, exp.err_type, exp.err_msg);
} catch (...) {
qCDebug(logger) << "unknown exception";
Expand Down
1 change: 0 additions & 1 deletion src/maincomponentplugin/article/Article.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import APIProxy 1.0
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.7
import QtGraphicalEffects 1.0
import org.deepin.dtk 1.0
import "../api"
import "../widgets"
Expand Down
20 changes: 9 additions & 11 deletions src/maincomponentplugin/feedback/Submit.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

import "../api"
import "../router"
import APIProxy 1.0
import QtGraphicalEffects 1.0
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Dialogs 1.0
import QtQuick.Layouts 1.7
import org.deepin.dtk 1.0
import APIProxy
import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts
import org.deepin.dtk

Item {
id: root
Expand Down Expand Up @@ -239,8 +238,8 @@ Item {
text: emailText.text
visible: false

validator: RegExpValidator {
regExp: /^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
validator: RegularExpressionValidator {
regularExpression: /^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
}

}
Expand Down Expand Up @@ -339,8 +338,7 @@ Item {
id: fileDialog

title: "Please choose a file"
folder: shortcuts.home
selectMultiple: true
fileMode: FileDialog.OpenFiles
nameFilters: [qsTr("Image files") + " (*.png *.jpg *.gif)"]
onAccepted: {
for (const f of fileDialog.fileUrls) {
Expand Down
13 changes: 2 additions & 11 deletions src/maincomponentplugin/index/Card1.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.7
import QtGraphicalEffects 1.0
import QtQuick.Shapes 1.8
import org.deepin.dtk 1.0

Control {
Expand Down Expand Up @@ -73,16 +73,7 @@ Control {
antialiasing: true
corners: (RoundRectangle.TopRightCorner | RoundRectangle.BottomCorner)

LinearGradient {
source: parent
anchors.fill: parent
start: Qt.point(0, height/3)
end: Qt.point(width, height/3)
gradient: Gradient {
GradientStop { position: 0.12; color: "#ffa469" }
GradientStop { position: 0.76; color: "#fe3232" }
}
}

Text {
id: t
text: qsTr("Coming")
Expand Down
9 changes: 0 additions & 9 deletions src/maincomponentplugin/index/Card2.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.7
import QtGraphicalEffects 1.0
import org.deepin.dtk 1.0

Control {
Expand All @@ -26,14 +25,6 @@ Control {
Behavior on y { PropertyAnimation {} }
radius: 20
clip: true
LinearGradient {
id: g
source: parent
anchors.fill: parent
start: Qt.point(0, 0)
end: Qt.point(width, height)
gradient: root.gradient
}
Text {
id: title
y: 16
Expand Down
1 change: 0 additions & 1 deletion src/maincomponentplugin/index/Card3.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.7
import QtGraphicalEffects 1.0
import org.deepin.dtk 1.0

Control {
Expand Down
3 changes: 1 addition & 2 deletions src/maincomponentplugin/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import "./router"
import "./titlebar"
import QtQuick 2.11
import org.deepin.dtk 1.0
import org.deepin.dtk.impl 1.0 as D

AppLoader {
id: appLoader

Component.onCompleted: {
// TODO 暂不支持暗色主题,固定为亮色主题
D.ApplicationHelper.setPaletteType(D.ApplicationHelper.LightType);
ApplicationHelper.setPaletteType(ApplicationHelper.LightType);
// 设置标题栏
appLoader.window.header = actualTitleBar;
for (let i = 1; i <= 10; i++) {
Expand Down
Loading

0 comments on commit 2a52c61

Please sign in to comment.