Kirigami-addons

messagedialoghelper.cpp
1// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#include "messagedialoghelper.h"
5#include <KConfigGroup>
6
7using namespace Qt::StringLiterals;
8
9MessageDialogHelper::MessageDialogHelper(QObject *parent)
10 : QObject(parent)
11{
12}
13
14QJsonObject MessageDialogHelper::shouldBeShownTwoActions(const QString &dontShowAgainName)
15{
16 KConfigGroup cg(m_config ? m_config : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
17 const QString dontAsk = cg.readEntry(dontShowAgainName, QString()).toLower();
18 if (dontAsk == QLatin1StringView("yes") || dontAsk == QLatin1StringView("true")) {
19 return {
20 { "result"_L1, true },
21 { "show"_L1, false },
22 };
23 }
24 if (dontAsk == QLatin1StringView("no") || dontAsk == QLatin1StringView("false")) {
25 return {
26 { "result"_L1, false },
27 { "show"_L1, false },
28 };
29 }
30
31 return {
32 { "show"_L1, true },
33 };
34}
35
36bool MessageDialogHelper::shouldBeShownContinue(const QString &dontShowAgainName)
37{
38 KConfigGroup cg(m_config ? m_config : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
39 return cg.readEntry(dontShowAgainName, true);
40}
41
42void MessageDialogHelper::saveDontShowAgainTwoActions(const QString &dontShowAgainName, bool result)
43{
45 if (dontShowAgainName[0] == QLatin1Char(':')) {
46 flags |= KConfigGroup::Global;
47 }
48 KConfigGroup cg(m_config ? m_config : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
49 cg.writeEntry(dontShowAgainName, result, flags);
50 cg.sync();
51}
52
53void MessageDialogHelper::saveDontShowAgainContinue(const QString &dontShowAgainName)
54{
56 if (dontShowAgainName[0] == QLatin1Char(':')) {
57 flags |= KConfigGroup::Global;
58 }
59 KConfigGroup cg(m_config ? m_config : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
60 cg.writeEntry(dontShowAgainName, false, flags);
61 cg.sync();
62}
63
64KConfig *MessageDialogHelper::config() const
65{
66 return m_config;
67}
68
69void MessageDialogHelper::setConfig(KConfig *config)
70{
71 if (m_config == config) {
72 return;
73 }
74 m_config = config;
75 Q_EMIT configChanged();
76}
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
Q_EMITQ_EMIT
QString toLower() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.