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

feat: add deepinfiledialog theme #188

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Copyright: None
License: CC0-1.0

# png svg dci
Files: platformthemeplugin/icons/* styleplugins/chameleon/*.svg styles/images/*.png
Files: platformthemeplugins/deepintheme/icons/* styleplugins/chameleon/*.svg styles/images/*.png
tests/*/icons/*/*.svg tests/*/*.svg tests/*/icons/*/*.dci
tests/imageformats/dci/*.dci tests/platformtheme/qt-theme.ini
Copyright: None
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ set(PLUGIN_INSTALL_BASE_DIR ${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/plugin

add_subdirectory(iconengineplugins)
add_subdirectory(imageformatplugins)
add_subdirectory(platformthemeplugin)
add_subdirectory(platformthemeplugins)
add_subdirectory(styleplugins)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL debug)
add_subdirectory(styles)
Expand Down
6 changes: 6 additions & 0 deletions platformthemeplugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

add_subdirectory(deepintheme)
add_subdirectory(deepinfiledialogtheme)
41 changes: 41 additions & 0 deletions platformthemeplugins/deepinfiledialogtheme/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus Widgets)
set(QT_LIBS Qt${QT_VERSION_MAJOR}::DBus Qt${QT_VERSION_MAJOR}::Widgets)
if(QT_VERSION_MAJOR EQUAL 5)
find_package(Qt5X11Extras REQUIRED)
list(APPEND QT_LIBS Qt5::X11Extras)
if(QT_VERSION_MINOR GREATER_EQUAL 8) # Qt5.8
find_package(Qt5ThemeSupport REQUIRED)
list(APPEND QT_LIBS Qt5::ThemeSupportPrivate)
else()
list(APPEND QT_LIBS Qt5::PlatformSupportPrivate)
endif()
else()
list(APPEND QT_LIBS Qt6::GuiPrivate)
endif()

include(../filedialog/filedialog.cmake)

dtk_add_plugin(
NAME
qdeepinfiledialog
OUTPUT_DIR
${PLUGIN_OUTPUT_BASE_DIR}/platformthemes
INCLUDE_DIRS
${CMAKE_CURRENT_LIST_DIR}/../filedialog
SOURCES
${DFM_DLG_SOURCES}
qdeepintheme.cpp
main.cpp
${DBUS_INTERFACES}
HEADERS
${DFM_DLG_HEADERS}
qdeepintheme.h
DEPENDENCIES
${QT_LIBS}
DEFINITIONS
${DEFS}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Keys" : [ "deepinfiledialog", "deepin", "DDE" ]
}
30 changes: 30 additions & 0 deletions platformthemeplugins/deepinfiledialogtheme/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <qpa/qplatformthemeplugin.h>
#include "qdeepintheme.h"

QT_BEGIN_NAMESPACE
class QDeepinFileDialogThemePlugin : public QPlatformThemePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QPlatformThemeFactoryInterface_iid FILE "deepinfiledialog.json")

public:
QPlatformTheme *create(const QString &key, const QStringList &params) Q_DECL_OVERRIDE;
};

QPlatformTheme *QDeepinFileDialogThemePlugin::create(const QString &key, const QStringList &params)
{
Q_UNUSED(params);
const QStringList &keys = {"deepinfiledialog", QLatin1String(QDeepinTheme::name), QLatin1String("DDE")};
if (keys.contains(key, Qt::CaseInsensitive))
return new QDeepinTheme;

return nullptr;
}

QT_END_NAMESPACE

#include "main.moc"
69 changes: 69 additions & 0 deletions platformthemeplugins/deepinfiledialogtheme/qdeepintheme.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个文件名最好修改一下。

* SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "qdeepintheme.h"
#include "qdeepinfiledialoghelper.h"
#include "filedialogmanager_interface.h"

#include <QGuiApplication>
#include <QIconEnginePlugin>

#include <private/qguiapplication_p.h>
#include <qpa/qwindowsysteminterface_p.h>
#include <qpa/qplatformscreen.h>
#include <qpa/qplatformcursor.h>

#undef signals
#include <X11/Xlib.h>


QT_BEGIN_NAMESPACE

const char *QDeepinTheme::name = "deepin";
bool QDeepinTheme::m_usePlatformNativeDialog = true;

QDeepinTheme::QDeepinTheme()
{
}

QDeepinTheme::~QDeepinTheme()
{
if (QDeepinFileDialogHelper::manager) {
QDeepinFileDialogHelper::manager->deleteLater();
QDeepinFileDialogHelper::manager = Q_NULLPTR;
}
}

bool QDeepinTheme::usePlatformNativeDialog(DialogType type) const
{
if (type == FileDialog) {
if (qgetenv("_d_disableDBusFileDialog") == "true")
return false;

static bool dbusDialogManagerInitialized = false;

if (!dbusDialogManagerInitialized) {
dbusDialogManagerInitialized = true;
QDeepinFileDialogHelper::initDBusFileDialogManager();
}

return m_usePlatformNativeDialog
&& QDeepinFileDialogHelper::manager
&& QDeepinFileDialogHelper::manager->isUseFileChooserDialog();
}

return QGenericUnixTheme::usePlatformNativeDialog(type);
}

QPlatformDialogHelper *QDeepinTheme::createPlatformDialogHelper(DialogType type) const
{
if (type == FileDialog && usePlatformNativeDialog(type))
return new QDeepinFileDialogHelper();

return QGenericUnixTheme::createPlatformDialogHelper(type);
}

QT_END_NAMESPACE

#include "qdeepintheme.moc"
32 changes: 32 additions & 0 deletions platformthemeplugins/deepinfiledialogtheme/qdeepintheme.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2017-2023 UnionTech Software Technology Co., Ltd.
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef QDEEPINTHEME_H
#define QDEEPINTHEME_H

#include <QMimeDatabase>

#include <private/qgenericunixthemes_p.h>
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformnativeinterface.h>

class DThemeSettings;
class QDeepinTheme : public QGenericUnixTheme
{
public:
QDeepinTheme();
~QDeepinTheme();

bool usePlatformNativeDialog(DialogType type) const Q_DECL_OVERRIDE;
QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const Q_DECL_OVERRIDE;

static const char *name;

private:
static bool m_usePlatformNativeDialog;

friend class QDeepinFileDialogHelper;
};

#endif // QDEEPINTHEME_H
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,28 @@ pkg_check_modules(Deps REQUIRED IMPORTED_TARGET mtdev)
if(ENABLE_QT_XDG_ICON_LOADER)
set(DEFS -DXDG_ICON_VERSION_MAR=${XDG_ICON_VERSION_MAJOR})
endif()
if(QT_VERSION_MAJOR EQUAL 5)
qt5_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialog.xml filedialog_interface)
qt5_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialogmanager.xml filedialogmanager_interface)
else()
qt6_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialog.xml filedialog_interface)
qt6_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialogmanager.xml filedialogmanager_interface)
endif()

include(../filedialog/filedialog.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里如果是为了源码共享,可以使用OBJECT或者INTERFACE的TARGET类型共享

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同下


dtk_add_plugin(
NAME
qdeepin
OUTPUT_DIR
${PLUGIN_OUTPUT_BASE_DIR}/platformthemes
INSTALL_DIR
${PLUGIN_INSTALL_BASE_DIR}/platformthemes
INCLUDE_DIRS
${CMAKE_CURRENT_LIST_DIR}/../filedialog
SOURCES
dthemesettings.cpp
qdeepinfiledialoghelper.cpp
${DFM_DLG_SOURCES}
qdeepintheme.cpp
${3RD_PARTY_SOURCES}
main.cpp
${DBUS_INTERFACES}
HEADERS
dthemesettings.h
qdeepinfiledialoghelper.h
${DFM_DLG_HEADERS}
qdeepintheme.h
${3RD_PARTY_HEADERS}
RESOURCES
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "filedialogmanager_interface.h"
#include "dthemesettings.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include "../3rdparty/qdbustrayicon_p.h"
#include "../../3rdparty/qdbustrayicon_p.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免在源码中使用相对目录,使用target_include_directories

#endif

#include <DGuiApplicationHelper>
Expand Down
14 changes: 14 additions & 0 deletions platformthemeplugins/filedialog/filedialog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

if(QT_VERSION_MAJOR EQUAL 5)
qt5_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialog.xml filedialog_interface)
qt5_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialogmanager.xml filedialogmanager_interface)
else()
qt6_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialog.xml filedialog_interface)
qt6_add_dbus_interface(DBUS_INTERFACES ${CMAKE_CURRENT_LIST_DIR}/xmls/com.deepin.filemanager.filedialogmanager.xml filedialogmanager_interface)
endif()

set(DFM_DLG_HEADERS ${CMAKE_CURRENT_LIST_DIR}/qdeepinfiledialoghelper.h)
set(DFM_DLG_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qdeepinfiledialoghelper.cpp)
Comment on lines +1 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议使用target的方式共享

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target 就把俩plugin关联在一起了。 现在这种方式可以只编译一个。没有dtk的依赖。换成target是不是需要带入另外一个theme的编译依赖呢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要,是这个文件夹里面的内容单独做一个target,两个theme都依赖这一个target。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

仅仅是使用target的方式共享需要共享的源码,本质上和你这里的cmake一样,但是以target的方式,会更加灵活,不需要依赖于目录。

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

#include <X11/Xlib.h>

#include <DPlatformHandle>
DGUI_USE_NAMESPACE
Comment on lines -30 to -31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么不使用dtkgui的内容呢

Copy link
Contributor Author

@kegechen kegechen Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就是想要纯粹的文管的filedialog服务,不想引入dtk依赖, 比如一个安装在opt目录下的自带qt 某一个版本的应用(很多,如网易云音乐,有道词典等)需要用我们的文管对话框,这个时候就可以简单的编译deepin-file-dialog的theme来实现

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是我记得qdeepinfiledialog本身有dtkwidget的依赖吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有。仅仅有的dtkgui的都移除了。
风格插件有dtkwidget的依赖

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们这整个项目都有dtkwidget的依赖,如果想要单独编出这个插件,还要做一些修改


QT_BEGIN_NAMESPACE
#ifndef DIALOG_SERVICE
Expand Down Expand Up @@ -117,6 +115,20 @@ static inline void setTransientForHint(WId wid, WId propWid)
XSetTransientForHint(DISPLAY, wid, propWid);
}

static inline bool isDXcbPlatform()
{
if (!qApp)
return false;

#define DXCB_PLUGIN_KEY "dxcb"
#define DXCB_PLUGIN_SYMBOLIC_PROPERTY "_d_isDxcb"

static bool _is_dxcb = qApp->platformName() == DXCB_PLUGIN_KEY ||
qApp->property(DXCB_PLUGIN_SYMBOLIC_PROPERTY).toBool();

return _is_dxcb;
}

void QDeepinFileDialogHelper::onWindowActiveChanged()
{
if (!filedlgInterface)
Expand All @@ -131,7 +143,7 @@ void QDeepinFileDialogHelper::onWindowActiveChanged()
setTransientForHint(fileDlgWId, parentWId);
}

if (DPlatformHandle::isDXcbPlatform()) {
if (isDXcbPlatform()) {
QWindow *focus_window = qApp->focusWindow();
if (!focus_window)
return;
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ target_include_directories(unit-tests PRIVATE
${CMAKE_SOURCE_DIR}/imageformatplugins/svg
${CMAKE_SOURCE_DIR}/imageformatplugins/dci
${CMAKE_SOURCE_DIR}/styleplugins/chameleon
${CMAKE_SOURCE_DIR}/platformthemeplugin
${CMAKE_SOURCE_DIR}/platformthemeplugins/deepintheme
)
Loading