Skip to content

Commit

Permalink
feat: add deepinfiledialog theme
Browse files Browse the repository at this point in the history
compiling deepin file dialog theme without dtk depends
  • Loading branch information
kegechen committed Aug 24, 2023
1 parent ccf82d7 commit 59f880a
Show file tree
Hide file tree
Showing 87 changed files with 221 additions and 16 deletions.
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 @@
/*
* 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)

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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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"
#endif

#include <DGuiApplicationHelper>
Expand Down
File renamed without changes.
File renamed without changes.
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)
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

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
)

0 comments on commit 59f880a

Please sign in to comment.