FrameworkIntegration

frameworkintegrationplugin.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2012 David Faure <faure+bluesystems@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "frameworkintegrationplugin.h"
9#include <KConfigGroup>
10#include <KNotification>
11#include <KSharedConfig>
12
13#include <QDebug>
14#include <qplugin.h>
15
16bool KMessageBoxDontAskAgainConfigStorage::shouldBeShownTwoActions(const QString &dontShowAgainName, KMessageBox::ButtonCode &result)
17{
18 KConfigGroup cg(KMessageBox_againConfig ? KMessageBox_againConfig : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
19 const QString dontAsk = cg.readEntry(dontShowAgainName, QString()).toLower();
20 if (dontAsk == QLatin1String("yes") || dontAsk == QLatin1String("true")) {
22 return false;
23 }
24 if (dontAsk == QLatin1String("no") || dontAsk == QLatin1String("false")) {
26 return false;
27 }
28 return true;
29}
30
31bool KMessageBoxDontAskAgainConfigStorage::shouldBeShownContinue(const QString &dontShowAgainName)
32{
33 KConfigGroup cg(KMessageBox_againConfig ? KMessageBox_againConfig : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
34 return cg.readEntry(dontShowAgainName, true);
35}
36
37void KMessageBoxDontAskAgainConfigStorage::saveDontShowAgainTwoActions(const QString &dontShowAgainName, KMessageBox::ButtonCode result)
38{
40 if (dontShowAgainName[0] == QLatin1Char(':')) {
41 flags |= KConfigGroup::Global;
42 }
43 KConfigGroup cg(KMessageBox_againConfig ? KMessageBox_againConfig : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
44 cg.writeEntry(dontShowAgainName, result == KMessageBox::PrimaryAction, flags);
45 cg.sync();
46}
47
48void KMessageBoxDontAskAgainConfigStorage::saveDontShowAgainContinue(const QString &dontShowAgainName)
49{
51 if (dontShowAgainName[0] == QLatin1Char(':')) {
52 flags |= KConfigGroup::Global;
53 }
54 KConfigGroup cg(KMessageBox_againConfig ? KMessageBox_againConfig : KSharedConfig::openConfig().data(), QStringLiteral("Notification Messages"));
55 cg.writeEntry(dontShowAgainName, false, flags);
56 cg.sync();
57}
58
59void KMessageBoxDontAskAgainConfigStorage::enableAllMessages()
60{
61 KConfig *config = KMessageBox_againConfig ? KMessageBox_againConfig : KSharedConfig::openConfig().data();
62 if (!config->hasGroup(QStringLiteral("Notification Messages"))) {
63 return;
64 }
65
66 KConfigGroup cg(config, QStringLiteral("Notification Messages"));
67
68 typedef QMap<QString, QString> configMap;
69
70 const configMap map = cg.entryMap();
71
72 configMap::ConstIterator it;
73 for (it = map.begin(); it != map.end(); ++it) {
74 cg.deleteEntry(it.key());
75 }
76}
77
78void KMessageBoxDontAskAgainConfigStorage::enableMessage(const QString &dontShowAgainName)
79{
80 KConfig *config = KMessageBox_againConfig ? KMessageBox_againConfig : KSharedConfig::openConfig().data();
81 if (!config->hasGroup(QStringLiteral("Notification Messages"))) {
82 return;
83 }
84
85 KConfigGroup cg(config, QStringLiteral("Notification Messages"));
86
87 cg.deleteEntry(dontShowAgainName);
88 config->sync();
89}
90
91void KMessageBoxNotify::sendNotification(QMessageBox::Icon notificationType, const QString &message, QWidget * /*parent*/)
92{
93 QString messageType;
94 switch (notificationType) {
96 messageType = QStringLiteral("messageWarning");
97 break;
99 messageType = QStringLiteral("messageCritical");
100 break;
102 messageType = QStringLiteral("messageQuestion");
103 break;
104 default:
105 messageType = QStringLiteral("messageInformation");
106 break;
107 }
108
110}
111
112KFrameworkIntegrationPlugin::KFrameworkIntegrationPlugin()
113 : QObject()
114{
115 setProperty(KMESSAGEBOXDONTASKAGAIN_PROPERTY, QVariant::fromValue<KMessageBoxDontAskAgainInterface *>(&m_dontAskAgainConfigStorage));
116 setProperty(KMESSAGEBOXNOTIFY_PROPERTY, QVariant::fromValue<KMessageBoxNotifyInterface *>(&m_notify));
117}
118
119void KFrameworkIntegrationPlugin::reparseConfiguration()
120{
121 KSharedConfig::openConfig()->reparseConfiguration();
122}
123
124#include "moc_frameworkintegrationplugin.cpp"
bool hasGroup(const QString &group) const
bool sync() override
static KNotification * event(const QString &eventId, const QString &text=QString(), const QPixmap &pixmap=QPixmap(), const NotificationFlags &flags=CloseOnTimeout, const QString &componentName=QString())
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QCA_EXPORT void setProperty(const QString &name, const QVariant &value)
QString toLower() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.