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

chore: option to use KIconThemes instead of Qt5XdgIconLoader #135

Closed
wants to merge 1 commit 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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ project(DtkGui
set(LIB_NAME dtkgui)

include(GNUInstallDirs)
include(FeatureSummary)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 11)
Expand All @@ -19,7 +21,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set build option
option(DTK_DISABLE_LIBXDG "Disable libxdg" OFF)
option(DTK_DISABLE_ICON_ENGINE_PROXY "Disable icon engine, use QIcon::fromTheme() as possible fallback" OFF)
Copy link
Member

Choose a reason for hiding this comment

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

同步更新一下readme?

cmake_dependent_option(DTK_DISABLE_LIBXDG "If icon engine proxy is used, prefer KIconEngine instead of using libqxdg" OFF "NOT DTK_DISABLE_ICON_ENGINE_PROXY" OFF)
option(DTK_DISABLE_LIBRSVG "Disable librsvg" OFF)
option(DTK_DISABLE_EX_IMAGE_FORMAT "Disable libraw and freeimage" OFF)
set(BUILD_DOCS ON CACHE BOOL "Generate doxygen-based documentation")
Expand Down Expand Up @@ -132,3 +135,5 @@ add_subdirectory(examples)
if (BUILD_DOCS)
add_subdirectory(docs)
endif ()

feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ if(NOT DTK_DISABLE_EX_IMAGE_FORMAT AND EX_IMAGE_FORMAT_LIBS_FOUND)
)
endif()

if(NOT DTK_DISABLE_LIBXDG)
target_link_libraries(${LIB_NAME} PRIVATE
Qt5XdgIconLoader
)
if(NOT DTK_DISABLE_ICON_ENGINE_PROXY)
if(DTK_DISABLE_LIBXDG)
target_link_libraries(${LIB_NAME} PRIVATE KF5::IconThemes)
asterwyx marked this conversation as resolved.
Show resolved Hide resolved
else()
target_link_libraries(${LIB_NAME} PRIVATE Qt5XdgIconLoader)
endif()
endif()

set_target_properties(${LIB_NAME} PROPERTIES
Expand Down
25 changes: 19 additions & 6 deletions src/util/dicontheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

#include "dicontheme.h"
#include "private/dbuiltiniconengine_p.h"
#ifndef DTK_DISABLE_LIBXDG
#include "private/xdgiconproxyengine_p.h"
#ifndef DTK_DISABLE_ICON_ENGINE_PROXY
#ifndef DTK_DISABLE_LIBXDG
#include "private/xdgiconproxyengine_p.h"
#else
#include <KIconEngine>
#include <KIconLoader>
#endif
#endif

#include <DStandardPaths>
Expand Down Expand Up @@ -87,10 +92,14 @@ static inline QIconEngine *createBuiltinIconEngine(const QString &iconName)
return new DBuiltinIconEngine(iconName);
}

#ifndef DTK_DISABLE_LIBXDG
#ifndef DTK_DISABLE_ICON_ENGINE_PROXY
static inline QIconEngine *createXdgProxyIconEngine(const QString &iconName)
Copy link
Member

Choose a reason for hiding this comment

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

函数名改改

{
#ifndef DTK_DISABLE_LIBXDG
return new XdgIconProxyEngine(new XdgIconLoaderEngine(iconName));
#else
return new KIconEngine(iconName, KIconLoader::global());
#endif
}
#endif

Expand All @@ -116,7 +125,7 @@ QIcon DIconTheme::findQIcon(const QString &iconName, Options options)
}
}

#ifdef DTK_DISABLE_LIBXDG
#ifdef DTK_DISABLE_ICON_ENGINE_PROXY
if (options.testFlag(DontFallbackToQIconFromTheme))
return QIcon();
return QIcon::fromTheme(iconName);
Expand All @@ -135,12 +144,16 @@ bool DIconTheme::isBuiltinIcon(const QIcon &icon)

bool DIconTheme::isXdgIcon(const QIcon &icon)
{
#ifdef DTK_DISABLE_LIBXDG
#ifdef DTK_DISABLE_ICON_ENGINE_PROXY
return false;
#else
if (icon.isNull())
return false;
return typeid(*const_cast<QIcon&>(icon).data_ptr()->engine) == typeid(XdgIconProxyEngine);
#ifndef DTK_DISABLE_LIBXDG
return typeid(*const_cast<QIcon&>(icon).data_ptr()->engine) == typeid(XdgIconProxyEngine);
#else
return typeid(*const_cast<QIcon&>(icon).data_ptr()->engine) == typeid(KIconEngine);
#endif
#endif
}

Expand Down
38 changes: 23 additions & 15 deletions src/util/util.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
if(NOT DTK_DISABLE_LIBXDG)
find_package(qt5xdgiconloader)
set(UTIL_PRIVATE
${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine_p.h
${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine.cpp
${CMAKE_CURRENT_LIST_DIR}/private/dimagehandlerlibs_p.h
)

if(NOT DTK_DISABLE_ICON_ENGINE_PROXY)
if(NOT DTK_DISABLE_LIBXDG)
find_package(qt5xdgiconloader REQUIRED)
add_definitions(-DXDG_ICON_VERSION_MAR=${qt5xdgiconloader_VERSION_MAJOR})
set(UTIL_PRIVATE
${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine_p.h
${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine.cpp
${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine_p.h
${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine.cpp
${CMAKE_CURRENT_LIST_DIR}/private/dimagehandlerlibs_p.h
)
else()
add_definitions(-DDTK_DISABLE_LIBXDG)
set(UTIL_PRIVATE
${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine_p.h
${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine.cpp
${CMAKE_CURRENT_LIST_DIR}/private/dimagehandlerlibs_p.h
list(APPEND UTIL_PRIVATE
${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine_p.h
${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine.cpp
)
else()
find_package(KF5IconThemes REQUIRED)
endif()
endif()

if(DTK_DISABLE_ICON_ENGINE_PROXY)
add_definitions(-DDTK_DISABLE_ICON_ENGINE_PROXY)
endif()

if(DTK_DISABLE_LIBXDG)
add_definitions(-DDTK_DISABLE_LIBXDG)
endif()

if(DTK_DISABLE_EX_IMAGE_FORMAT OR NOT EX_IMAGE_FORMAT_LIBS_FOUND)
Expand Down