diff --git a/CHANGELOG.md b/CHANGELOG.md index 4052647..7b1d75a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,15 @@ ## Squawk 0.2.1 (UNRELEASED) ### Bug fixes +- build in release mode now no longer spams warnings +- build now correctly installs all build plugin libs ### Improvements ### New features +- the settings are here! You con config different stuff from there +- now it's possible to set up different qt styles from settings +- if you have KConfig nad KConfigWidgets packages installed - you can chose from global color schemes ## Squawk 0.2.0 (Jan 10, 2022) ### Bug fixes diff --git a/README.md b/README.md index 0af201f..486d4fe 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ - qxmpp 1.1.0 or higher - KDE Frameworks: kwallet (optional) - KDE Frameworks: KIO (optional) +- KDE Frameworks: KConfig (optional) +- KDE Frameworks: KConfigWidgets (optional) - Boost (just one little hpp from there) - Imagemagick (for compilation, to rasterize an SVG logo) @@ -92,6 +94,7 @@ Here is the list of keys you can pass to configuration phase of `cmake ..`. - `SYSTEM_QXMPP` - `True` tries to link against `qxmpp` installed in the system, `False` builds bundled `qxmpp` library (default is `True`) - `WITH_KWALLET` - `True` builds the `KWallet` capability module if `KWallet` is installed and if not goes to `False`. `False` disables `KWallet` support (default is `True`) - `WITH_KIO` - `True` builds the `KIO` capability module if `KIO` is installed and if not goes to `False`. `False` disables `KIO` support (default is `True`) +- `WITH_KCONFIG` - `True` builds the `KConfig` and `KConfigWidgets` capability module if such packages are installed and if not goes to `False`. `False` disables `KConfig` and `KConfigWidgets` support (default is `True`) ## License diff --git a/core/main.cpp b/core/main.cpp index 03de307..cdfca7e 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -90,13 +90,24 @@ int main(int argc, char *argv[]) new Shared::Global(); //translates enums QSettings settings; - QVariant vtheme = settings.value("theme"); - if (vtheme.isValid()) { - QString theme = vtheme.toString().toLower(); - if (theme != "system") { - QApplication::setStyle(theme); + QVariant vs = settings.value("style"); + if (vs.isValid()) { + QString style = vs.toString().toLower(); + if (style != "system") { + Shared::Global::setStyle(style); } } + if (Shared::Global::supported("colorSchemeTools")) { + QVariant vt = settings.value("theme"); + if (vt.isValid()) { + QString theme = vt.toString(); + if (theme.toLower() != "system") { + Shared::Global::setTheme(theme); + } + } + } + + Squawk w; w.show(); diff --git a/core/passwordStorageEngines/wrappers/CMakeLists.txt b/core/passwordStorageEngines/wrappers/CMakeLists.txt index 6d486c0..e8420da 100644 --- a/core/passwordStorageEngines/wrappers/CMakeLists.txt +++ b/core/passwordStorageEngines/wrappers/CMakeLists.txt @@ -1,2 +1,4 @@ add_library(kwalletWrapper SHARED kwallet.cpp) target_link_libraries(kwalletWrapper PRIVATE KF5::Wallet) + +install(TARGETS kwalletWrapper LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/packaging/Archlinux/PKGBUILD b/packaging/Archlinux/PKGBUILD index 0d2aaaa..a8da388 100644 --- a/packaging/Archlinux/PKGBUILD +++ b/packaging/Archlinux/PKGBUILD @@ -8,7 +8,10 @@ url="https://git.macaw.me/blue/squawk" license=('GPL3') depends=('hicolor-icon-theme' 'desktop-file-utils' 'lmdb' 'qxmpp>=1.1.0') makedepends=('cmake>=3.3' 'imagemagick' 'qt5-tools' 'boost') -optdepends=('kwallet: secure password storage (requires rebuild)' 'kio: better show in folder action (requires rebuild)') +optdepends=('kwallet: secure password storage (requires rebuild)' + 'kconfig: system themes support (requires rebuild)' + 'kconfigwidgets: system themes support (requires rebuild)' + 'kio: better show in folder action (requires rebuild)') source=("$pkgname-$pkgver.tar.gz") sha256sums=('8e93d3dbe1fc35cfecb7783af409c6a264244d11609b2241d4fe77d43d068419') diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 5a5a41d..388c258 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,10 +1,14 @@ if (WITH_KIO) add_library(openFileManagerWindowJob SHARED openfilemanagerwindowjob.cpp) target_link_libraries(openFileManagerWindowJob PRIVATE KF5::KIOWidgets) + + install(TARGETS openFileManagerWindowJob LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif () if (WITH_KCONFIG) add_library(colorSchemeTools SHARED colorschemetools.cpp) target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigCore) target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigWidgets) + + install(TARGETS colorSchemeTools LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() diff --git a/plugins/colorschemetools.cpp b/plugins/colorschemetools.cpp index 0ad8e24..0288b28 100644 --- a/plugins/colorschemetools.cpp +++ b/plugins/colorschemetools.cpp @@ -1,7 +1,9 @@ #include #include +#include #include +#include #include QPixmap createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection); @@ -24,6 +26,17 @@ extern "C" void deletePreview(QIcon* icon) { delete icon; } +extern "C" void colorSchemeName(const QString& path, QString& answer) { + KSharedConfigPtr config = KSharedConfig::openConfig(path); + KConfigGroup group(config, QStringLiteral("General")); + answer = group.readEntry("Name", QFileInfo(path).baseName()); +} + +extern "C" void createPalette(const QString& path, QPalette& answer) { + KSharedConfigPtr config = KSharedConfig::openConfig(path); + answer = KColorScheme::createApplicationPalette(config); +} + QPixmap createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection) { QPixmap pix(size, size); pix.fill(Qt::black); diff --git a/shared/global.cpp b/shared/global.cpp index 7dafed6..122bc79 100644 --- a/shared/global.cpp +++ b/shared/global.cpp @@ -32,6 +32,8 @@ Shared::Global::HighlightInFileManager Shared::Global::hfm = 0; QLibrary Shared::Global::colorSchemeTools("colorSchemeTools"); Shared::Global::CreatePreview Shared::Global::createPreview = 0; Shared::Global::DeletePreview Shared::Global::deletePreview = 0; +Shared::Global::ColorSchemeName Shared::Global::colorSchemeName = 0; +Shared::Global::CreatePalette Shared::Global::createPalette = 0; #endif Shared::Global::Global(): @@ -91,6 +93,7 @@ Shared::Global::Global(): tr("Your password is going to be stored in KDE wallet storage (KWallet). You're going to be queried for permissions", "AccountPasswordDescription") }), defaultSystemStyle(QApplication::style()->objectName()), + defaultSystemPalette(QApplication::palette()), pluginSupport({ {"KWallet", false}, {"openFileManagerWindowJob", false}, @@ -124,7 +127,9 @@ Shared::Global::Global(): if (colorSchemeTools.isLoaded()) { createPreview = (CreatePreview) colorSchemeTools.resolve("createPreview"); deletePreview = (DeletePreview) colorSchemeTools.resolve("deletePreview"); - if (createPreview && deletePreview) { + colorSchemeName = (ColorSchemeName) colorSchemeTools.resolve("colorSchemeName"); + createPalette = (CreatePalette) colorSchemeTools.resolve("createPalette"); + if (createPreview && deletePreview && colorSchemeName && createPalette) { setSupported("colorSchemeTools", true); qDebug() << "Color Schemes support enabled"; } else { @@ -311,6 +316,38 @@ QIcon Shared::Global::createThemePreview(const QString& path) } } +QString Shared::Global::getColorSchemeName(const QString& path) +{ + if (supported("colorSchemeTools")) { + QString res; + colorSchemeName(path, res); + return res; + } else { + return ""; + } +} + +void Shared::Global::setTheme(const QString& path) +{ + if (supported("colorSchemeTools")) { + if (path.toLower() == "system") { + QApplication::setPalette(getInstance()->defaultSystemPalette); + } else { + QPalette pallete; + createPalette(path, pallete); + QApplication::setPalette(pallete); + } + } +} + +void Shared::Global::setStyle(const QString& style) +{ + if (style.toLower() == "system") { + QApplication::setStyle(getInstance()->defaultSystemStyle); + } else { + QApplication::setStyle(style); + } +} #define FROM_INT_INPL(Enum) \ template<> \ diff --git a/shared/global.h b/shared/global.h index bd3c9a6..2056639 100644 --- a/shared/global.h +++ b/shared/global.h @@ -87,6 +87,7 @@ namespace Shared { const std::deque accountPasswordDescription; const QString defaultSystemStyle; + const QPalette defaultSystemPalette; static bool supported(const QString& pluginName); static void setSupported(const QString& pluginName, bool support); @@ -96,6 +97,9 @@ namespace Shared { static FileInfo getFileInfo(const QString& path); static void highlightInFileManager(const QString& path); static QIcon createThemePreview(const QString& path); + static QString getColorSchemeName(const QString& path); + static void setTheme(const QString& path); + static void setStyle(const QString& style); template static T fromInt(int src); @@ -135,9 +139,13 @@ namespace Shared { typedef QIcon* (*CreatePreview)(const QString&); typedef void (*DeletePreview)(QIcon*); + typedef void (*ColorSchemeName)(const QString&, QString&); + typedef void (*CreatePalette)(const QString&, QPalette&); static CreatePreview createPreview; static DeletePreview deletePreview; + static ColorSchemeName colorSchemeName; + static CreatePalette createPalette; #endif }; } diff --git a/ui/widgets/settings/pageappearance.cpp b/ui/widgets/settings/pageappearance.cpp index 57da7aa..f2bf53e 100644 --- a/ui/widgets/settings/pageappearance.cpp +++ b/ui/widgets/settings/pageappearance.cpp @@ -10,41 +10,59 @@ static const QStringList filters = {"*.colors"}; PageAppearance::PageAppearance(QWidget* parent): QWidget(parent), m_ui(new Ui::PageAppearance()), - styles() + styles(), + themes() { m_ui->setupUi(this); - m_ui->themeInput->addItem(tr("System")); + m_ui->styleInput->addItem(tr("System")); styles.push_back("system"); - QStringList themes = QStyleFactory::keys(); - for (const QString& key : themes) { - m_ui->themeInput->addItem(key); + QStringList systemStyles = QStyleFactory::keys(); + for (const QString& key : systemStyles) { + m_ui->styleInput->addItem(key); styles.push_back(key); } QSettings settings; - QVariant vtheme = settings.value("theme"); - if (vtheme.isValid()) { - QString theme = vtheme.toString(); - m_ui->themeInput->setCurrentText(theme); + QVariant vs = settings.value("style"); + if (vs.isValid()) { + m_ui->styleInput->setCurrentText(vs.toString()); } else { - m_ui->themeInput->setCurrentText("System"); + m_ui->styleInput->setCurrentText(tr("System")); } - connect(m_ui->themeInput, qOverload(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged); + connect(m_ui->styleInput, qOverload(&QComboBox::currentIndexChanged), this, &PageAppearance::onStyleChanged); if (Shared::Global::supported("colorSchemeTools")) { - m_ui->colorInput->addItem(tr("System")); + themes.push_back("system"); + m_ui->themeInput->addItem(tr("System")); const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "color-schemes", QStandardPaths::LocateDirectory); QStringList schemeFiles; + QString currentTheme(tr("System")); + QString requestedTheme(""); + QVariant vtheme = settings.value("theme"); + if (vtheme.isValid()) { + requestedTheme = vtheme.toString(); + } for (const QString &dir : dirs) { const QStringList fileNames = QDir(dir).entryList(filters); for (const QString &file : fileNames) { - m_ui->colorInput->addItem(Shared::Global::createThemePreview(dir + QDir::separator() + file), file); + QString path = dir + QDir::separator() + file; + themes.push_back(path); + QString themeName = Shared::Global::getColorSchemeName(path); + m_ui->themeInput->addItem(Shared::Global::createThemePreview(path), themeName); + + if (path == requestedTheme) { + currentTheme = themeName; + } } } + + m_ui->themeInput->setCurrentText(currentTheme); + + connect(m_ui->themeInput, qOverload(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged); } else { - m_ui->colorInput->setEnabled(false); + m_ui->themeInput->setEnabled(false); } } @@ -55,8 +73,14 @@ PageAppearance::~PageAppearance() void PageAppearance::onThemeChanged(int index) { if (index >= 0) { - emit variableModified("theme", styles[index]); + emit variableModified("theme", themes[index]); } } +void PageAppearance::onStyleChanged(int index) +{ + if (index >= 0) { + emit variableModified("style", styles[index]); + } +} diff --git a/ui/widgets/settings/pageappearance.h b/ui/widgets/settings/pageappearance.h index b31f3c1..80efd85 100644 --- a/ui/widgets/settings/pageappearance.h +++ b/ui/widgets/settings/pageappearance.h @@ -29,11 +29,13 @@ signals: void variableModified(const QString& key, const QVariant& value); protected slots: + void onStyleChanged(int index); void onThemeChanged(int index); private: QScopedPointer m_ui; std::vector styles; + std::vector themes; }; #endif // PAGEAPPEARANCE_H diff --git a/ui/widgets/settings/pageappearance.ui b/ui/widgets/settings/pageappearance.ui index afcb3a8..570eefa 100644 --- a/ui/widgets/settings/pageappearance.ui +++ b/ui/widgets/settings/pageappearance.ui @@ -12,20 +12,20 @@ - + Theme - + - + - + Color scheme diff --git a/ui/widgets/settings/settings.cpp b/ui/widgets/settings/settings.cpp index 75a7780..3ab38bb 100644 --- a/ui/widgets/settings/settings.cpp +++ b/ui/widgets/settings/settings.cpp @@ -40,13 +40,10 @@ void Settings::apply() { QSettings settings; for (const std::pair& pair: modifiedSettings) { - if (pair.first == "theme") { - QString theme = pair.second.toString(); - if (theme.toLower() == "system") { - QApplication::setStyle(Shared::Global::getInstance()->defaultSystemStyle); - } else { - QApplication::setStyle(theme); - } + if (pair.first == "style") { + Shared::Global::setStyle(pair.second.toString()); + } else if (pair.first == "theme") { + Shared::Global::setTheme(pair.second.toString()); } settings.setValue(pair.first, pair.second);