File indexing completed on 2024-05-05 17:43:13

0001 /*
0002  *   SPDX-FileCopyrightText: 2017 Ivan Cukic <ivan.cukic (at) kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "noticewidget.h"
0008 
0009 #include "ui_noticewidget.h"
0010 
0011 #include <KConfigGroup>
0012 #include <KSharedConfig>
0013 
0014 class NoticeWidget::Private
0015 {
0016 public:
0017     Ui::NoticeWidget ui;
0018     KSharedConfig::Ptr config;
0019     bool shouldBeShown;
0020     QString noticeId;
0021 };
0022 
0023 NoticeWidget::NoticeWidget(const QString &noticeId, const QString &message, Mode mode)
0024     : DialogDsl::DialogModule(true)
0025     , d(new Private())
0026 {
0027     d->ui.setupUi(this);
0028     d->ui.textNotice->setHtml(message);
0029     d->ui.checkShouldBeHidden->setVisible(mode == DoNotShowAgainOption);
0030 
0031     d->noticeId = noticeId;
0032 
0033     d->config = KSharedConfig::openConfig(PLASMAVAULT_CONFIG_FILE);
0034 }
0035 
0036 NoticeWidget::~NoticeWidget()
0037 {
0038 }
0039 
0040 PlasmaVault::Vault::Payload NoticeWidget::fields() const
0041 {
0042     return {};
0043 }
0044 
0045 void NoticeWidget::aboutToBeShown()
0046 {
0047     KConfigGroup noticeUi(d->config, "UI-notice");
0048     d->shouldBeShown = !noticeUi.readEntry("SkipNotice-" + d->noticeId, false);
0049     d->ui.checkShouldBeHidden->setChecked(!d->shouldBeShown);
0050 }
0051 
0052 bool NoticeWidget::shouldBeShown() const
0053 {
0054     return d->shouldBeShown;
0055 }
0056 
0057 void NoticeWidget::aboutToBeHidden()
0058 {
0059     KConfigGroup noticeUi(d->config, "UI-notice");
0060     noticeUi.writeEntry("SkipNotice-" + d->noticeId, d->ui.checkShouldBeHidden->isChecked());
0061     d->config->sync();
0062 }