Commit 931613b5 authored by Justus Winter's avatar Justus Winter

Add and use a second set of key filters

The second set is not part of the model (i.e. it will not be displayed
in Kleopatras drop down list in the default view), and will only be
used for styling keys.
Signed-off-by: default avatarJustus Winter <justus@gnupg.org>
parent 09197d18
...@@ -167,17 +167,25 @@ static std::vector<std::shared_ptr<KeyFilter>> defaultFilters() ...@@ -167,17 +167,25 @@ static std::vector<std::shared_ptr<KeyFilter>> defaultFilters()
return result; return result;
} }
static std::vector<std::shared_ptr<KeyFilter>> defaultAppearanceFilters()
{
std::vector<std::shared_ptr<KeyFilter> > result;
return result;
}
class KeyFilterManager::Private class KeyFilterManager::Private
{ {
public: public:
Private() : filters(), model(this) {} Private() : filters(), appearanceFilters(), model(this) {}
void clear() void clear()
{ {
filters.clear(); filters.clear();
appearanceFilters.clear();
model.reset(); model.reset();
} }
std::vector<std::shared_ptr<KeyFilter>> filters; std::vector<std::shared_ptr<KeyFilter>> filters;
std::vector<std::shared_ptr<KeyFilter>> appearanceFilters;
Model model; Model model;
}; };
...@@ -251,6 +259,7 @@ void KeyFilterManager::reload() ...@@ -251,6 +259,7 @@ void KeyFilterManager::reload()
d->clear(); d->clear();
d->filters = defaultFilters(); d->filters = defaultFilters();
d->appearanceFilters = defaultAppearanceFilters();
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("libkleopatrarc")); KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("libkleopatrarc"));
const QStringList groups = config->groupList().filter(QRegularExpression(QStringLiteral("^Key Filter #\\d+$"))); const QStringList groups = config->groupList().filter(QRegularExpression(QStringLiteral("^Key Filter #\\d+$")));
...@@ -339,7 +348,12 @@ static KeyFilter::FontDescription get_fontdescription(const std::vector<std::sha ...@@ -339,7 +348,12 @@ static KeyFilter::FontDescription get_fontdescription(const std::vector<std::sha
QFont KeyFilterManager::font(const Key &key, const QFont &baseFont) const QFont KeyFilterManager::font(const Key &key, const QFont &baseFont) const
{ {
return get_fontdescription(d->filters, key, KeyFilter::FontDescription()).font(baseFont); KeyFilter::FontDescription fd;
fd = get_fontdescription(d->appearanceFilters, key, KeyFilter::FontDescription());
fd = get_fontdescription(d->filters, key, fd);
return fd.font(baseFont);
} }
static QColor get_color(const std::vector<std::shared_ptr<KeyFilter>> &filters, const Key &key, QColor(KeyFilter::*fun)() const) static QColor get_color(const std::vector<std::shared_ptr<KeyFilter>> &filters, const Key &key, QColor(KeyFilter::*fun)() const)
...@@ -372,17 +386,34 @@ static QString get_string(const std::vector<std::shared_ptr<KeyFilter>> &filters ...@@ -372,17 +386,34 @@ static QString get_string(const std::vector<std::shared_ptr<KeyFilter>> &filters
QColor KeyFilterManager::bgColor(const Key &key) const QColor KeyFilterManager::bgColor(const Key &key) const
{ {
return get_color(d->filters, key, &KeyFilter::bgColor); QColor color;
color = get_color(d->appearanceFilters, key, &KeyFilter::bgColor);
if (!color.isValid()) {
color = get_color(d->filters, key, &KeyFilter::bgColor);
}
return color;
} }
QColor KeyFilterManager::fgColor(const Key &key) const QColor KeyFilterManager::fgColor(const Key &key) const
{ {
return get_color(d->filters, key, &KeyFilter::fgColor); QColor color;
color = get_color(d->appearanceFilters, key, &KeyFilter::fgColor);
if (!color.isValid()) {
color = get_color(d->filters, key, &KeyFilter::fgColor);
}
return color;
} }
QIcon KeyFilterManager::icon(const Key &key) const QIcon KeyFilterManager::icon(const Key &key) const
{ {
const QString icon = get_string(d->filters, key, &KeyFilter::icon); QString icon;
icon = get_string(d->appearanceFilters, key, &KeyFilter::icon);
if (icon.isEmpty()) {
icon = get_string(d->filters, key, &KeyFilter::icon);
}
return icon.isEmpty() ? QIcon() : QIcon::fromTheme(icon); return icon.isEmpty() ? QIcon() : QIcon::fromTheme(icon);
} }
Markdown is supported
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