sieveeditormanagesievewidget.cpp 2.39 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
2
   SPDX-FileCopyrightText: 2014-2021 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3

4
   SPDX-License-Identifier: GPL-2.0-or-later
Laurent Montel's avatar
Laurent Montel committed
5
6
7
*/

#include "sieveeditormanagesievewidget.h"
Laurent Montel's avatar
Laurent Montel committed
8
#include "readserversieveconfigjob.h"
Laurent Montel's avatar
Laurent Montel committed
9
#include <KSieveUi/ManageSieveTreeView>
Laurent Montel's avatar
Laurent Montel committed
10
#include <KSieveUi/SieveTreeWidgetItem>
Laurent Montel's avatar
Laurent Montel committed
11

12
#include <KManageSieve/SieveJob>
Laurent Montel's avatar
Laurent Montel committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include <KLocalizedString>

using namespace KSieveUi;

SieveEditorManageSieveWidget::SieveEditorManageSieveWidget(QWidget *parent)
    : KSieveUi::ManageSieveWidget(parent)
{
}

SieveEditorManageSieveWidget::~SieveEditorManageSieveWidget()
{
}

bool SieveEditorManageSieveWidget::refreshList()
{
    bool noImapFound = true;
Laurent Montel's avatar
Laurent Montel committed
30
    SieveTreeWidgetItem *last = nullptr;
Laurent Montel's avatar
Laurent Montel committed
31
    for (const SieveEditorUtil::SieveServerConfig &conf : mSieveServerSettings) {
Laurent Montel's avatar
Laurent Montel committed
32
        last = new SieveTreeWidgetItem(treeView(), last);
Laurent Montel's avatar
Laurent Montel committed
33
        last->setText(0, conf.sieveSettings.serverName + QStringLiteral(" (%1)").arg(conf.sieveSettings.userName));
34
        last->setIcon(0, QIcon::fromTheme(QStringLiteral("network-server")));
Laurent Montel's avatar
Laurent Montel committed
35

Laurent Montel's avatar
Laurent Montel committed
36
        const QUrl u = conf.url();
Laurent Montel's avatar
Laurent Montel committed
37
        if (u.isEmpty()) {
38
            auto item = new QTreeWidgetItem(last);
Laurent Montel's avatar
Laurent Montel committed
39
40
41
            item->setText(0, i18n("No Sieve URL configured"));
            item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
            treeView()->expandItem(last);
Laurent Montel's avatar
Laurent Montel committed
42
        } else if (!conf.enabled) {
43
44
            last->setFlags(last->flags() & ~Qt::ItemIsEnabled);
            last->setText(0, i18n("(Disabled) %1", last->text(0)));
Laurent Montel's avatar
Laurent Montel committed
45
        } else {
Laurent Montel's avatar
Laurent Montel committed
46
            KManageSieve::SieveJob *job = KManageSieve::SieveJob::list(u);
Laurent Montel's avatar
Laurent Montel committed
47
            job->setProperty("sieveimapaccountsettings", QVariant::fromValue(conf.sieveImapAccountSettings));
Laurent Montel's avatar
Laurent Montel committed
48
            connect(job, &KManageSieve::SieveJob::gotList, this, &SieveEditorManageSieveWidget::slotGotList);
Laurent Montel's avatar
Laurent Montel committed
49
50
            mJobs.insert(job, last);
            mUrls.insert(last, u);
Laurent Montel's avatar
Laurent Montel committed
51
52
53
54
55
56
            last->startAnimation();
        }
        noImapFound = false;
    }
    return noImapFound;
}
Laurent Montel's avatar
Laurent Montel committed
57
58
59

void SieveEditorManageSieveWidget::updateSieveSettings()
{
60
61
62
63
64
65
66
67
    ReadServerSieveConfigJob *job = new ReadServerSieveConfigJob(this);
    connect(job, &ReadServerSieveConfigJob::finished, this, &SieveEditorManageSieveWidget::slotReadServerSieveConfigDone);
    job->start();
}

void SieveEditorManageSieveWidget::slotReadServerSieveConfigDone(const QVector<SieveEditorUtil::SieveServerConfig> &lstConfig)
{
    mSieveServerSettings = lstConfig;
Laurent Montel's avatar
Laurent Montel committed
68
69
    Q_EMIT updateSieveSettingsDone();
}