Libksieve

custommanagesievewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only
5*/
6
7#include "custommanagesievewidget.h"
8#include "util/findaccountinfojob.h"
9#include "widgets/managesievetreeview.h"
10
11#include "kmanagesieve/sievejob.h"
12#include "widgets/sievetreewidgetitem.h"
13#include <KLocalizedString>
14#include <QIcon>
15#include <QTreeWidgetItem>
16
17using namespace KSieveUi;
18
19CustomManageSieveWidget::CustomManageSieveWidget(KSieveCore::SieveImapPasswordProvider *passwordProvider, QWidget *parent)
20 : KSieveUi::ManageSieveWidget(parent)
21 , mPasswordProvider(passwordProvider)
22{
23}
24
25CustomManageSieveWidget::~CustomManageSieveWidget() = default;
26
27void CustomManageSieveWidget::updateSieveSettings()
28{
29 mSieveImapInstances = KSieveCore::Util::sieveImapInstances();
30 Q_EMIT updateSieveSettingsDone();
31}
32
33bool CustomManageSieveWidget::refreshList()
34{
35 if (mRefreshInProgress) {
36 return false;
37 }
38 mRefreshInProgress = true;
39 bool noImapFound = true;
40 mLastSieveTreeWidgetItem = nullptr;
41 mServerSieveInfos.clear();
42 for (const KSieveCore::SieveImapInstance &type : std::as_const(mSieveImapInstances)) {
44 continue;
45 }
46 mServerSieveInfos.insert(type.name(), type.identifier());
47 }
48 noImapFound = mServerSieveInfos.isEmpty();
49 searchSieveScript();
50 return noImapFound;
51}
52
53void CustomManageSieveWidget::searchSieveScript()
54{
55 mSieveServerMapIterator = mServerSieveInfos.constBegin();
56 if (mSieveServerMapIterator != mServerSieveInfos.constEnd()) {
57 slotSearchSieveScript(mSieveServerMapIterator.key(), mSieveServerMapIterator.value());
58 }
59}
60
61void CustomManageSieveWidget::searchNextServerSieve()
62{
63 ++mSieveServerMapIterator;
64 if (mSieveServerMapIterator != mServerSieveInfos.constEnd()) {
65 slotSearchSieveScript(mSieveServerMapIterator.key(), mSieveServerMapIterator.value());
66 } else {
67 mLastSieveTreeWidgetItem = nullptr;
68 mRefreshInProgress = false;
69 }
70}
71
72void CustomManageSieveWidget::slotSearchSieveScript(const QString &name, const QString &identifier)
73{
74 mLastSieveTreeWidgetItem = new SieveTreeWidgetItem(treeView(), mLastSieveTreeWidgetItem);
75 mLastSieveTreeWidgetItem->setIcon(0, QIcon::fromTheme(QStringLiteral("network-server")));
76
77 auto job = new KSieveCore::FindAccountInfoJob(this);
78 connect(job, &KSieveCore::FindAccountInfoJob::findAccountInfoFinished, this, &CustomManageSieveWidget::slotFindAccountInfoFinished);
79 job->setIdentifier(identifier);
80 job->setProperty("serverName", name);
81 job->setProvider(mPasswordProvider);
82 job->start();
83}
84
85void CustomManageSieveWidget::slotFindAccountInfoFinished(const KSieveCore::Util::AccountInfo &info)
86{
87 QString serverName = sender()->property("serverName").toString();
88 const QUrl u = info.sieveUrl;
89 if (u.isEmpty()) {
90 auto item = new QTreeWidgetItem(mLastSieveTreeWidgetItem);
91 item->setText(0, i18n("No Sieve URL configured"));
92 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
93 treeView()->expandItem(mLastSieveTreeWidgetItem);
94 } else {
95 serverName += QStringLiteral(" (%1)").arg(u.userName());
97 // qDebug() << " SETTINGS " << info;
98 job->setProperty("sieveimapaccountsettings", QVariant::fromValue(info.sieveImapAccountSettings));
99 connect(job, &KManageSieve::SieveJob::gotList, this, &CustomManageSieveWidget::slotGotList);
100 mJobs.insert(job, mLastSieveTreeWidgetItem);
101 mUrls.insert(mLastSieveTreeWidgetItem, u);
102 mLastSieveTreeWidgetItem->startAnimation();
103 }
104 mLastSieveTreeWidgetItem->setText(0, serverName);
105 searchNextServerSieve();
106}
107
108#include "moc_custommanagesievewidget.cpp"
A job to manage sieve scripts.
Definition sievejob.h:31
static SieveJob * list(const QUrl &url)
Lists all available scripts at the given sieve url.
Definition sievejob.cpp:314
void gotList(KManageSieve::SieveJob *job, bool success, const QStringList &scriptList, const QString &activeScript)
This signal is emitted when a list job has finished.
The SieveImapInstance class.
@ Broken
The agent instance encountered an error state.
The SieveImapPasswordProvider class.
The ManageSieveWidget class.
The SieveTreeWidgetItem class.
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
KSIEVECORE_EXPORT QList< KSieveCore::SieveImapInstance > sieveImapInstances()
Returns the list of configured IMAP agent instances.
Definition util.cpp:32
QIcon fromTheme(const QString &name)
void clear()
const_iterator constBegin() const const
const_iterator constEnd() const const
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
Key key(const T &value, const Key &defaultKey) const const
T value(const Key &key, const T &defaultValue) const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QVariant property(const char *name) const const
QObject * sender() const const
bool setProperty(const char *name, QVariant &&value)
QString arg(Args &&... args) const const
ItemIsEnabled
void expandItem(const QTreeWidgetItem *item)
void setIcon(int column, const QIcon &icon)
void setText(int column, const QString &text)
bool isEmpty() const const
QString userName(ComponentFormattingOptions options) const const
QVariant fromValue(T &&value)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.