Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port to qt6 #158

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf

[CMakeLists.txt]
indent_style = space
indent_size = 4

[*.{cpp,h,ts}]
indent_style = space
indent_size = 4
8 changes: 4 additions & 4 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Copyright: UnionTech Software Technology Co., Ltd.
License: CC-BY-4.0

# Project file
Files: *.pro *.qrc *.pri *CMakeLists.txt *.cmake *.desktop *.service *.in .clang-format
Files: *.pro *.qrc *.pri *CMakeLists.txt *.cmake *.desktop *.service *.in .clang-format .editorconfig
Copyright: None
License: CC0-1.0

Expand All @@ -43,9 +43,9 @@ Files: dde-clipboard/dbus/* dbus/*.xml dde-clipboard/org.deepin.dde.Clipboard1.x
Copyright: The Qt Company Ltd.
License: CC0-1.0

# xml
Files: dde-clipboard/com.deepin.dde.Clipboard.xml
Copyright: UnionTech Software Technology Co., Ltd.
# wayland
Files: misc/wlr-data-control-unstable-v1.xml
Copyright: wlroots developer.
License: GPL-3.0-or-later

# test file
Expand Down
211 changes: 17 additions & 194 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,137 +2,38 @@ cmake_minimum_required(VERSION 3.16)

set(BIN_NAME dde-clipboard)

project(${BIN_NAME})
project(dde-clipboard)

#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -O0")
endif()

if (DEFINED ENABLE_MIEEE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mieee")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Install settings
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
endif ()

include(GNUInstallDirs)

if (NOT (${CMAKE_BUILD_TYPE} MATCHES "Debug"))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast")

# generate qm
execute_process(COMMAND bash "translate_generation.sh"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -O0")
endif()

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Dtk COMPONENTS Widget Core REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Widgets DBus Test Concurrent REQUIRED)

find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
find_package(DWayland REQUIRED)

pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-qt)

if (NOT DEFINED SYSTEMD_USER_UNIT_DIR)
pkg_get_variable(SYSTEMD_USER_UNIT_DIR systemd systemduserunitdir)
endif()

find_package(DtkTools REQUIRED)
function(generation_dbus_adaptor xml class_name class_file option)
execute_process(COMMAND qdbusxml2cpp ${option} -a ${class_file} -c ${class_name} ${xml}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endfunction(generation_dbus_adaptor)

set(DBUS_INTERFACE ${PROJECT_SOURCE_DIR}/dbus/interface)
function(generation_dbus_interface xml class_name class_file)
execute_process(COMMAND ${DTK_XML2CPP} -c ${class_name} -p ${class_file} ${xml}
WORKING_DIRECTORY ${DBUS_INTERFACE})
endfunction(generation_dbus_interface)

include_directories(
dde-clipboard
dde-clipboard/dbus
dde-clipboard/displaymanager
dde-clipboardloader
)

#----------------------------dde-clipboard------------------------------
generation_dbus_adaptor(
${CMAKE_SOURCE_DIR}/dde-clipboard/org.deepin.dde.Clipboard1.xml
ClipboardAdaptor
${CMAKE_CURRENT_BINARY_DIR}/clipboard_adaptor
-N
)

generation_dbus_interface(
${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.Display1.Monitor.xml
Monitor
${DBUS_INTERFACE}/monitor_interface
)

generation_dbus_interface(
${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.Display1.xml
Display1
${DBUS_INTERFACE}/display_interface
)

generation_dbus_interface(
${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.daemon.Dock1.xml
Dock1
${DBUS_INTERFACE}/dock_interface
)

include_directories(
${PROJECT_SOURCE_DIR}/dbus/interface
${PROJECT_SOURCE_DIR}/dbus/types
${PROJECT_SOURCE_DIR}/dbus
)

aux_source_directory(dbus/types DBUS_TYPES)
aux_source_directory(dbus/interface DBUS_INTERFACES)

set(Clipboard_DBUS_SCRS
${CMAKE_CURRENT_BINARY_DIR}/clipboard_adaptor.h
${CMAKE_CURRENT_BINARY_DIR}/clipboard_adaptor.cpp
)

file(GLOB_RECURSE Clipboard_SCRS
"dde-clipboard/*.h"
"dde-clipboard/*.cpp"
)
list(REMOVE_ITEM Clipboard_SCRS "${CMAKE_SOURCE_DIR}/dde-clipboard/main.cpp")

add_executable(${BIN_NAME}
${Clipboard_SCRS}
${Clipboard_DBUS_SCRS}
dde-clipboard/main.cpp
${DBUS_INTERFACES}
${DBUS_TYPES}
)
include(GNUInstallDirs)

target_link_libraries(${BIN_NAME} PRIVATE
Dtk::Widget
Dtk::Core
PkgConfig::GIO
Qt5::Core
Qt5::Widgets
Qt5::GuiPrivate
Qt5::Gui
Qt5::DBus
)
add_subdirectory(dde-clipboard)
add_subdirectory(dde-clipboard-daemon)
add_subdirectory(tests)

macro(install_symlink filepath wantsdir)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/link/${wantsdir}/)
Expand All @@ -141,7 +42,12 @@ macro(install_symlink filepath wantsdir)
endmacro(install_symlink)

## qm files
file(GLOB QM_FILES "translations/*.qm")
find_package(Qt6LinguistTools REQUIRED)

file(GLOB TS_FILES "translations/*.ts")

qt6_add_translation(QM_FILES ${TS_FILES})

install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/${BIN_NAME}/translations)

configure_file(
Expand All @@ -163,86 +69,3 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dde-clipboard.service DESTINATION ${SY

install_symlink(dde-clipboard.service dde-session-initialized.target.wants)

## bin
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})

#----------------------------dde-clipboard-daemon------------------------------
set(BIN_NAME dde-clipboard-daemon)

file(GLOB_RECURSE dde-clipboard-daemon_SCRS
"dde-clipboard-daemon/*.h"
"dde-clipboard-daemon/*.cpp"
)

add_executable(${BIN_NAME}
${dde-clipboard-daemon_SCRS}
)

target_link_libraries(${BIN_NAME} PRIVATE
Qt5::Gui
Qt5::DBus
Qt5::Widgets
Dtk::Core
Qt5::Concurrent
DWaylandClient
)

install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})

configure_file(
misc/org.deepin.dde.ClipboardLoader1.service.in
org.deepin.dde.ClipboardLoader1.service
@ONLY
)

configure_file(
misc/org.deepin.dde.daemon.Clipboard1.service.in
org.deepin.dde.daemon.Clipboard1.service
@ONLY
)
configure_file(
misc/dde-clipboard-daemon.service.in
dde-clipboard-daemon.service
@ONLY
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.deepin.dde.ClipboardLoader1.service
DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.deepin.dde.daemon.Clipboard1.service
DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dde-clipboard-daemon.service DESTINATION ${SYSTEMD_USER_UNIT_DIR})

#----------------------------ut-dde-clipboard------------------------------
set(UT_BIN_NAME ut-dde-clipboard)

file(GLOB_RECURSE ut_Clipboard_SCRS
"tests/dde-clipboard/*.h"
"tests/dde-clipboard/*.cpp"
"tests/dde-clipboard/*.qrc"
)

add_executable(${UT_BIN_NAME}
${Clipboard_SCRS}
${Clipboard_DBUS_SCRS}
${ut_Clipboard_SCRS}
${DBUS_INTERFACES}
${DBUS_TYPES}
)
# 用于测试覆盖率的编译条件
target_compile_options(${UT_BIN_NAME} PRIVATE -fprofile-arcs -ftest-coverage)

target_link_libraries(${UT_BIN_NAME} PRIVATE
Dtk::Widget
PkgConfig::GIO
Qt5::Core
Qt5::Widgets
Qt5::DBus
Qt5::Test
Qt5::GuiPrivate
-lpthread
-lgcov
-lgtest
)
19 changes: 14 additions & 5 deletions dbus/types/dockrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dockrect.h"

#include <QDebug>

DockRect::DockRect()
Expand All @@ -11,15 +12,11 @@ DockRect::DockRect()
, w(0)
, h(0)
{

}

QDebug operator<<(QDebug debug, const DockRect &rect)
{
debug << QString("DockRect(%1, %2, %3, %4)").arg(rect.x)
.arg(rect.y)
.arg(rect.w)
.arg(rect.h);
debug << QString("DockRect(%1, %2, %3, %4)").arg(rect.x).arg(rect.y).arg(rect.w).arg(rect.h);

return debug;
}
Expand Down Expand Up @@ -52,3 +49,15 @@ void registerDockRectMetaType()
qRegisterMetaType<DockRect>("DockRect");
qDBusRegisterMetaType<DockRect>();
}

bool operator==(const DockRect &infoa, const DockRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return re;
}

bool operator!=(const DockRect &infoa, const DockRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return !re;
}
2 changes: 2 additions & 0 deletions dbus/types/dockrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct DockRect
friend QDebug operator<<(QDebug debug, const DockRect &rect);
friend const QDBusArgument &operator>>(const QDBusArgument &arg, DockRect &rect);
friend QDBusArgument &operator<<(QDBusArgument &arg, const DockRect &rect);
friend bool operator==(const DockRect &a, const DockRect &b);
friend bool operator!=(const DockRect &a, const DockRect &b);

private:
int x;
Expand Down
26 changes: 17 additions & 9 deletions dbus/types/screenrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
#include "screenrect.h"

ScreenRect::ScreenRect()
: x(0),
y(0),
w(0),
h(0)
: x(0)
, y(0)
, w(0)
, h(0)
{

}

QDebug operator<<(QDebug debug, const ScreenRect &rect)
{
debug << QString("ScreenRect(%1, %2, %3, %4)").arg(rect.x)
.arg(rect.y)
.arg(rect.w)
.arg(rect.h);
debug << QString("ScreenRect(%1, %2, %3, %4)").arg(rect.x).arg(rect.y).arg(rect.w).arg(rect.h);

return debug;
}
Expand All @@ -38,6 +34,18 @@ QDBusArgument &operator<<(QDBusArgument &arg, const ScreenRect &rect)
return arg;
}

bool operator==(const ScreenRect &infoa, const ScreenRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return re;
}

bool operator!=(const ScreenRect &infoa, const ScreenRect &rect)
{
bool re = infoa.x == rect.x && infoa.y == rect.y && infoa.h == rect.h && infoa.w == rect.w;
return !re;
}

const QDBusArgument &operator>>(const QDBusArgument &arg, ScreenRect &rect)
{
arg.beginStructure();
Expand Down
3 changes: 2 additions & 1 deletion dbus/types/screenrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ struct ScreenRect
friend QDebug operator<<(QDebug debug, const ScreenRect &rect);
friend const QDBusArgument &operator>>(const QDBusArgument &arg, ScreenRect &rect);
friend QDBusArgument &operator<<(QDBusArgument &arg, const ScreenRect &rect);

friend bool operator ==(const ScreenRect &infoa, const ScreenRect& info);
friend bool operator !=(const ScreenRect &infoa, const ScreenRect& info);
private:
qint16 x;
qint16 y;
Expand Down
Loading
Loading