Commit e8284944 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fill rules in treewidget

parent 8993a187
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "confirmbeforedeletingmanager.h"
......@@ -56,6 +56,11 @@ QStringList ConfirmBeforeDeletingManager::ruleGroups(const KSharedConfig::Ptr &c
return config->groupList().filter(QRegularExpression(defaultGroupName() + QStringLiteral(" #\\d+")));
}
const QVector<ConfirmBeforeDeletingRule> &ConfirmBeforeDeletingManager::rules() const
{
return mRules;
}
void ConfirmBeforeDeletingManager::saveRules()
{
const KSharedConfig::Ptr &config = KSharedConfig::openConfig(defaultConfigFileName(), KConfig::NoGlobals);
......
......@@ -27,6 +27,8 @@ public:
Q_REQUIRED_RESULT bool deletingNeedToConfirm(const Akonadi::Item &list) const;
Q_REQUIRED_RESULT const QVector<ConfirmBeforeDeletingRule> &rules() const;
private:
Q_REQUIRED_RESULT QString defaultConfigFileName() const;
Q_REQUIRED_RESULT QStringList ruleGroups(const KSharedConfig::Ptr &config) const;
......
......@@ -51,10 +51,10 @@ bool ConfirmBeforeDeletingRule::isValid() const
void ConfirmBeforeDeletingRule::save(KConfigGroup &group) const
{
group.writeEntry(QStringLiteral("Pattern"), mPattern);
group.writeEntry(QStringLiteral("Type"), ruleTypeToString());
group.writeEntry(QStringLiteral("Type"), ruleTypeToString(mRuleType));
}
ConfirmBeforeDeletingRule::RuleType ConfirmBeforeDeletingRule::stringToRuleType(const QString &str) const
ConfirmBeforeDeletingRule::RuleType ConfirmBeforeDeletingRule::stringToRuleType(const QString &str)
{
if (str == QLatin1String("body")) {
return Body;
......@@ -68,10 +68,10 @@ ConfirmBeforeDeletingRule::RuleType ConfirmBeforeDeletingRule::stringToRuleType(
return Unknown;
}
QString ConfirmBeforeDeletingRule::ruleTypeToString() const
QString ConfirmBeforeDeletingRule::ruleTypeToString(ConfirmBeforeDeletingRule::RuleType r)
{
QString tmp;
switch (mRuleType) {
switch (r) {
case Unknown:
break;
case Body:
......
......@@ -38,10 +38,10 @@ public:
void load(const KConfigGroup &group);
Q_REQUIRED_RESULT bool isValid() const;
static Q_REQUIRED_RESULT QString ruleTypeToString(ConfirmBeforeDeletingRule::RuleType r);
static Q_REQUIRED_RESULT ConfirmBeforeDeletingRule::RuleType stringToRuleType(const QString &str);
private:
Q_REQUIRED_RESULT QString ruleTypeToString() const;
Q_REQUIRED_RESULT ConfirmBeforeDeletingRule::RuleType stringToRuleType(const QString &str) const;
QString mPattern;
RuleType mRuleType = RuleType::Unknown;
};
......
......@@ -6,6 +6,7 @@
#include "confirmbeforedeletingwidget.h"
#include "confirmbeforedeletingcreateruledialog.h"
#include "confirmbeforedeletingmanager.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <QIcon>
......@@ -21,7 +22,6 @@ ConfirmBeforeDeletingWidget::ConfirmBeforeDeletingWidget(QWidget *parent)
auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins({});
mainLayout->setObjectName(QStringLiteral("mainlayout"));
// TODO
mainLayout->addWidget(mTreeWidget);
mTreeWidget->setAlternatingRowColors(true);
mTreeWidget->setRootIsDecorated(false);
......@@ -38,7 +38,10 @@ ConfirmBeforeDeletingWidget::~ConfirmBeforeDeletingWidget()
void ConfirmBeforeDeletingWidget::fillRules()
{
// TODO
const QVector<ConfirmBeforeDeletingRule> rules = ConfirmBeforeDeletingManager::self()->rules();
for (const ConfirmBeforeDeletingRule &r : rules) {
new QTreeWidgetItem({ConfirmBeforeDeletingRule::ruleTypeToString(r.ruleType()), r.pattern()});
}
}
void ConfirmBeforeDeletingWidget::slotEditRule()
......
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