new optional KDE Frameworks plugin to support system color schemes

This commit is contained in:
Blue 2022-01-26 23:53:44 +03:00
parent 802e2f11a1
commit 0ff9f12157
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
8 changed files with 130 additions and 10 deletions

View file

@ -28,6 +28,12 @@ QLibrary Shared::Global::openFileManagerWindowJob("openFileManagerWindowJob");
Shared::Global::HighlightInFileManager Shared::Global::hfm = 0;
#endif
#ifdef WITH_KCONFIG
QLibrary Shared::Global::colorSchemeTools("colorSchemeTools");
Shared::Global::CreatePreview Shared::Global::createPreview = 0;
Shared::Global::DeletePreview Shared::Global::deletePreview = 0;
#endif
Shared::Global::Global():
availability({
tr("Online", "Availability"),
@ -87,7 +93,8 @@ Shared::Global::Global():
defaultSystemStyle(QApplication::style()->objectName()),
pluginSupport({
{"KWallet", false},
{"openFileManagerWindowJob", false}
{"openFileManagerWindowJob", false},
{"colorSchemeTools", false}
}),
fileCache()
{
@ -111,6 +118,22 @@ Shared::Global::Global():
qDebug() << "KIO::OpenFileManagerWindow support disabled: couldn't load the library" << openFileManagerWindowJob.errorString();
}
#endif
#ifdef WITH_KCONFIG
colorSchemeTools.load();
if (colorSchemeTools.isLoaded()) {
createPreview = (CreatePreview) colorSchemeTools.resolve("createPreview");
deletePreview = (DeletePreview) colorSchemeTools.resolve("deletePreview");
if (createPreview && deletePreview) {
setSupported("colorSchemeTools", true);
qDebug() << "Color Schemes support enabled";
} else {
qDebug() << "Color Schemes support disabled: couldn't resolve required methods in the library";
}
} else {
qDebug() << "Color Schemes support disabled: couldn't load the library" << colorSchemeTools.errorString();
}
#endif
}
@ -276,6 +299,18 @@ void Shared::Global::highlightInFileManager(const QString& path)
}
}
QIcon Shared::Global::createThemePreview(const QString& path)
{
if (supported("colorSchemeTools")) {
QIcon* icon = createPreview(path);
QIcon localIcon = *icon;
deletePreview(icon);
return localIcon;
} else {
return QIcon();
}
}
#define FROM_INT_INPL(Enum) \
template<> \

View file

@ -95,6 +95,7 @@ namespace Shared {
static FileInfo getFileInfo(const QString& path);
static void highlightInFileManager(const QString& path);
static QIcon createThemePreview(const QString& path);
template<typename T>
static T fromInt(int src);
@ -128,6 +129,16 @@ namespace Shared {
static HighlightInFileManager hfm;
#endif
#ifdef WITH_KCONFIG
static QLibrary colorSchemeTools;
typedef QIcon* (*CreatePreview)(const QString&);
typedef void (*DeletePreview)(QIcon*);
static CreatePreview createPreview;
static DeletePreview deletePreview;
#endif
};
}