Commit c0179b08 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add a helper for decorating a button according to compliance

GnuPG-bug-id: 6073
parent 24578a0c
......@@ -852,21 +852,12 @@ public:
}
}
DeVSCompliance::decorate(mOkButton, de_vs);
if (de_vs) {
mOkButton->setIcon(QIcon::fromTheme(QStringLiteral("security-high")));
if (!SystemInfo::isHighContrastModeActive()) {
mOkButton->setStyleSheet(QStringLiteral("background-color: ")
+ KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::PositiveBackground).color().name());
}
mComplianceLbl->setText(i18nc("%1 is a placeholder for the name of a compliance mode. E.g. NATO RESTRICTED compliant or VS-NfD compliant",
"%1 communication possible.",
Formatting::deVsString()));
} else {
mOkButton->setIcon(QIcon::fromTheme(QStringLiteral("security-medium")));
if (!SystemInfo::isHighContrastModeActive()) {
mOkButton->setStyleSheet(QStringLiteral("background-color: ")
+ KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::NegativeBackground).color().name());
}
mComplianceLbl->setText(i18nc("%1 is a placeholder for the name of a compliance mode. E.g. NATO RESTRICTED compliant or VS-NfD compliant",
"%1 communication not possible.",
Formatting::deVsString()));
......
......@@ -14,6 +14,11 @@
#include "cryptoconfig.h"
#include "gnupg.h"
#include "systeminfo.h"
#include <KColorScheme>
#include <QPushButton>
bool Kleo::DeVSCompliance::isActive()
{
......@@ -36,3 +41,28 @@ bool Kleo::DeVSCompliance::isCompliant()
}
return getCryptoConfigIntValue("gpg", "compliance_de_vs", 0) != 0;
}
void Kleo::DeVSCompliance::decorate(QPushButton *button)
{
decorate(button, isCompliant());
}
void Kleo::DeVSCompliance::decorate(QPushButton *button, bool compliant)
{
if (!button) {
return;
}
if (compliant) {
button->setIcon(QIcon::fromTheme(QStringLiteral("security-high")));
if (!SystemInfo::isHighContrastModeActive()) {
const auto bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::PositiveBackground).color().name();
button->setStyleSheet(QStringLiteral("QPushButton { background-color: %1; };").arg(bgColor));
}
} else {
button->setIcon(QIcon::fromTheme(QStringLiteral("security-medium")));
if (!SystemInfo::isHighContrastModeActive()) {
const auto bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::NegativeBackground).color().name();
button->setStyleSheet(QStringLiteral("QPushButton { background-color: %1; };").arg(bgColor));
}
}
}
......@@ -12,6 +12,8 @@
#include "kleo_export.h"
class QPushButton;
namespace Kleo::DeVSCompliance
{
......@@ -28,4 +30,20 @@ KLEO_EXPORT bool isActive();
*/
KLEO_EXPORT bool isCompliant();
/**
* \overload
*
* Sets the appropriate icon and, unless high-contrast mode is active, the
* appropriate background color of \p button depending on the state of
* compliance.
*/
KLEO_EXPORT void decorate(QPushButton *button);
/**
* Sets the appropriate icon and, unless high-contrast mode is active, the
* appropriate background color of \p button depending on the value of
* \p compliant.
*/
KLEO_EXPORT void decorate(QPushButton *button, bool compliant);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment