Skip to content

Commit

Permalink
chore: refactor unreasonable places
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinshark committed Nov 18, 2024
1 parent 05abc19 commit 727aee9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 118 deletions.
144 changes: 37 additions & 107 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall")
Expand All @@ -32,10 +33,13 @@ if (NOT (${CMAKE_BUILD_TYPE} MATCHES "Debug"))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast")
endif ()

set(QT_VERSION_MAJOR 6)
set(DTK_VERSION_MAJOR 6)

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Dtk6 COMPONENTS Widget Core Tools REQUIRED)
find_package(Qt6 COMPONENTS Core Gui Widgets DBus WaylandClient Test Concurrent LinguistTools REQUIRED)
find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget Core Tools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets DBus WaylandClient Test Concurrent LinguistTools REQUIRED)
find_package(DDEShell REQUIRED)
find_package(DdeTrayLoader REQUIRED)

Expand All @@ -58,9 +62,9 @@ include_directories(
#----------------------------dde-clipboard------------------------------

qt_add_dbus_adaptor(DBUS_INTERFACES ${CMAKE_SOURCE_DIR}/dde-clipboard/org.deepin.dde.Clipboard1.xml mainwindow.h MainWindow)
dtk_add_dbus_interface(DBUS_INTERFACES ${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.Display1.Monitor.xml Monitor)
dtk_add_dbus_interface(DBUS_INTERFACES ${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.Display1.xml Display1)
dtk_add_dbus_interface(DBUS_INTERFACES ${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.daemon.Dock1.xml Dock1)
dtk_add_dbus_interface(DBUS_INTERFACES ${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.Display1.Monitor.xml display1monitorinterface)
dtk_add_dbus_interface(DBUS_INTERFACES ${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.Display1.xml display1interface)
dtk_add_dbus_interface(DBUS_INTERFACES ${CMAKE_SOURCE_DIR}/dbus/org.deepin.dde.daemon.Dock1.xml dock1interface)

include_directories(
${PROJECT_SOURCE_DIR}/dbus/interface
Expand All @@ -85,88 +89,19 @@ add_executable(${BIN_NAME}
)

target_link_libraries(${BIN_NAME} PRIVATE
Dtk6::Widget
Dtk6::Core
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Core
PkgConfig::GIO
Qt6::Core
Qt6::Widgets
Qt6::GuiPrivate
Qt6::Gui
Qt6::DBus
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::DBus
Dde::Shell
)

# generate qm
set(TRANSLATION_FILES
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_af.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_am_ET.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ar.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ast.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_az.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_bg.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_bn.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_bo.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ca.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_cs.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_da.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_de.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_el_GR.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_el.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_en_AU.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_en_GB.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_eo.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_es_419.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_es.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_et.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_fa.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_fi.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_fr.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_gl_ES.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_he.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_hi_IN.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_hi.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_hr.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_hu.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_hy.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_id.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_it.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ja.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_kab.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ko.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ku_IQ.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ku.ts
${PROJECT_SOURCE_DIR}/translations/[email protected]
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_lt.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_lv.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ml.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_mn.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ms.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_nb.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ne.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_nl.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_pa.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_pl.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_pt_BR.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_pt.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ro.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ru.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_si.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_sk.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_sl.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_sq.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_sr.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_sv.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_sw.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ta.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_tr.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_ug.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_uk.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_vi.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_zh_CN.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_zh_HK.ts
${PROJECT_SOURCE_DIR}/translations/dde-clipboard_zh_TW.ts
)
file(GLOB TRANSLATION_FILES "${CMAKE_SOURCE_DIR}/translations/*.ts")

qt_add_translations(${BIN_NAME}
TS_FILES ${TRANSLATION_FILES}
Expand Down Expand Up @@ -209,8 +144,8 @@ install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
set(BIN_NAME dde-clipboard-daemon)

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

add_executable(${BIN_NAME}
Expand All @@ -221,12 +156,12 @@ qt_generate_wayland_protocol_client_sources(${BIN_NAME} FILES
${CMAKE_CURRENT_SOURCE_DIR}/dde-clipboard-daemon/protocol/wlr-data-control-unstable-v1.xml)

target_link_libraries(${BIN_NAME} PRIVATE
Qt6::Gui
Qt6::DBus
Qt6::Concurrent
Qt6::WaylandClient
Qt6::WaylandClientPrivate
Dtk6::Core
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::WaylandClient
Qt${QT_VERSION_MAJOR}::WaylandClientPrivate
Dtk${DTK_VERSION_MAJOR}::Core
)

install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down Expand Up @@ -277,13 +212,13 @@ add_executable(${UT_BIN_NAME}
target_compile_options(${UT_BIN_NAME} PRIVATE -fprofile-arcs -ftest-coverage)

target_link_libraries(${UT_BIN_NAME} PRIVATE
Dtk6::Widget
Dtk${DTK_VERSION_MAJOR}::Widget
PkgConfig::GIO
Qt6::Core
Qt6::Widgets
Qt6::DBus
Qt6::Test
Qt6::GuiPrivate
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Test
Qt${QT_VERSION_MAJOR}::GuiPrivate
Dde::Shell
-lpthread
-lgcov
Expand All @@ -303,22 +238,17 @@ file(GLOB_RECURSE SRCS
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
add_library(${PLUGIN_NAME} SHARED ${SRCS} dock-clipboard-plugin/resources/clipboard.qrc)
target_include_directories(${PLUGIN_NAME} PUBLIC
${DtkWidget_INCLUDE_DIRS}
${DtkCore_INCLUDE_DIRS}
Dtk${DTK_VERSION_MAJOR}::Widget
Qt${QT_VERSION_MAJOR}::Core
${OBJECT_BINARY_DIR}
${DDE_DOCK_INCLUDE_DIR}
${QGSettings_INCLUDE_DIRS}
${DFrameworkDBus_INCLUDE_DIRS}
dock-clipboard-plugin/widget/
)
target_link_libraries(${PLUGIN_NAME} PRIVATE
${DtkWidget_LIBRARIES}
${QGSettings_LIBRARIES}
${DFrameworkDBus_LIBRARIES}
${Qt5DBus_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${Qt5Svg_LIBRARIES}
${DtkCore_LIBRARIES}
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Widgets
)

# 设置执行 make install 时哪个目标应该被 install 到哪个位置
Expand Down
6 changes: 3 additions & 3 deletions dde-clipboard/itemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ QPixmap ItemWidget::getIconPixmap(const QIcon &icon, const QSize &size, qreal pi
// 而且,在有些QIconEngine的实现中,会去调用另一个QIcon::pixmap,导致 pixmapSize 在这种嵌套调用中越来越大
// 最终会获取到一个是期望大小几倍的图片,由于图片太大,会很快将 QPixmapCache 塞满,导致后面再调用QIcon::pixmap
// 读取新的图片时无法缓存,非常影响图片绘制性能。此处在获取图片前禁用 Qt::AA_UseHighDpiPixmaps,自行处理图片大小问题
bool useHighDpiPixmaps = qApp->testAttribute(Qt::AA_UseHighDpiPixmaps);
qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, false);
// bool useHighDpiPixmaps = qApp->testAttribute(Qt::AA_UseHighDpiPixmaps);
// qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, false);

QSize icon_size = icon.actualSize(size, mode, state);

Expand All @@ -498,7 +498,7 @@ QPixmap ItemWidget::getIconPixmap(const QIcon &icon, const QSize &size, qreal pi
QPixmap px = icon.pixmap(pixmapSize, mode, state);

// restore the value
qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, useHighDpiPixmaps);
// qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, useHighDpiPixmaps);

if (px.width() > icon_size.width() * pixelRatio) {
px.setDevicePixelRatio(px.width() * 1.0 / qreal(icon_size.width()));
Expand Down
7 changes: 3 additions & 4 deletions dde-clipboard/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "dbusdockinterface.h"
#include "listview.h"
#include "iconbutton.h"
#include "display1interface.h"
#include "display1monitorinterface.h"
#include "dock1interface.h"

#include <DBlurEffectWidget>
#include <DWindowManagerHelper>
Expand All @@ -22,10 +25,6 @@
#include <DGuiApplicationHelper>
#include <dde-shell/dlayershellwindow.h>

#include "Display1.h"
#include "Monitor.h"
#include "Dock1.h"

DCORE_USE_NAMESPACE
DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE
Expand Down
1 change: 0 additions & 1 deletion dock-clipboard-plugin/clipboarditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "constants.h"
#include "clipboardcontroller.h"

#include <DDBusSender>
#include <DGuiApplicationHelper>

#include <QDBusConnection>
Expand Down
7 changes: 4 additions & 3 deletions dock-clipboard-plugin/clipboardplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ ClipboardPlugin::ClipboardPlugin(QObject *parent)
, m_messageCallback(nullptr)
{
QTranslator *translator = new QTranslator(this);
translator->load(QString("/usr/share/dde-clipboard/translations/dde-clipboard_%1.qm").arg(QLocale::system().name()));
QCoreApplication::installTranslator(translator);
if (translator->load(QString("/usr/share/dde-clipboard/translations/dde-clipboard_%1.qm").arg(QLocale::system().name()))) {
QCoreApplication::installTranslator(translator);
}
}

ClipboardPlugin::~ClipboardPlugin()
Expand Down Expand Up @@ -63,7 +64,7 @@ void ClipboardPlugin::init(PluginProxyInterface *proxyInter)
connect(m_quickPanelWidget, &QuickPanelWidget::requestHideApplet, this, [this] {
m_proxyInter->requestSetAppletVisible(this, CLIPBOARD_KEY, false);
});
QDBusConnection::sessionBus().connect("com.deepin.dde.Clipboard", "/com/deepin/dde/Clipboard", "com.deepin.dde.Clipboard", "clipboardVisibleChanged", this, SLOT(onClipboardVisibleChanged(bool)));
QDBusConnection::sessionBus().connect("org.deepin.dde.Clipboard1", "/org/deepin/dde/Clipboard1", "org.deepin.dde.Clipboard1", "clipboardVisibleChanged", this, SLOT(onClipboardVisibleChanged(bool)));
}

QWidget *ClipboardPlugin::itemWidget(const QString &itemKey)

Check warning on line 70 in dock-clipboard-plugin/clipboardplugin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'itemWidget' is never used.
Expand Down

0 comments on commit 727aee9

Please sign in to comment.