Libksieve

custommanagesievewidget.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "custommanagesievewidget.h"
19 #include "widgets/managesievetreeview.h"
20 #include "util/util_p.h"
21 
22 #include <KLocalizedString>
23 #include <QIcon>
24 #include <QTreeWidgetItem>
25 #include <kmanagesieve/sievejob.h>
26 #include <widgets/sievetreewidgetitem.h>
27 
28 using namespace KSieveUi;
29 
30 CustomManageSieveWidget::CustomManageSieveWidget(SieveImapPasswordProvider *passwordProvider, QWidget *parent)
31  : KSieveUi::ManageSieveWidget(parent)
32  , mPasswordProvider(passwordProvider)
33 {
34 }
35 
36 CustomManageSieveWidget::~CustomManageSieveWidget()
37 {
38 }
39 
40 bool CustomManageSieveWidget::refreshList()
41 {
42  bool noImapFound = true;
43  SieveTreeWidgetItem *last = nullptr;
44  const QVector<KSieveUi::SieveImapInstance> lst = KSieveUi::Util::sieveImapInstances();
45  for (const KSieveUi::SieveImapInstance &type : lst) {
46  if (type.status() == KSieveUi::SieveImapInstance::Broken) {
47  continue;
48  }
49 
50  QString serverName = type.name();
51  last = new SieveTreeWidgetItem(treeView(), last);
52  last->setIcon(0, QIcon::fromTheme(QStringLiteral("network-server")));
53 
54  const KSieveUi::Util::AccountInfo info = KSieveUi::Util::fullAccountInfo(type.identifier(), mPasswordProvider, false);
55  const QUrl u = info.sieveUrl;
56  if (u.isEmpty()) {
57  QTreeWidgetItem *item = new QTreeWidgetItem(last);
58  item->setText(0, i18n("No Sieve URL configured"));
59  item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
60  treeView()->expandItem(last);
61  } else {
62  serverName += QStringLiteral(" (%1)").arg(u.userName());
64  //qDebug() << " SETTINGS " << info;
65  job->setProperty("sieveimapaccountsettings", QVariant::fromValue(info.sieveImapAccountSettings));
66  connect(job, &KManageSieve::SieveJob::gotList, this, &CustomManageSieveWidget::slotGotList);
67  mJobs.insert(job, last);
68  mUrls.insert(last, u);
69  last->startAnimation();
70  }
71  last->setText(0, serverName);
72  noImapFound = false;
73  }
74  return noImapFound;
75 }
The agent instance encountered an error state.
void setIcon(int column, const QIcon &icon)
The ManageSieveWidget class.
The SieveImapPasswordProvider class.
The SieveImapInstance class.
void setFlags(Qt::ItemFlags flags)
Type type(const QSqlDatabase &db)
The SieveTreeWidgetItem class.
QVariant fromValue(const T &value)
void gotList(KManageSieve::SieveJob *job, bool success, const QStringList &scriptList, const QString &activeScript)
This signal is emitted when a list job has finished.
QString i18n(const char *text, const TYPE &arg...)
Qt::ItemFlags flags() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void setText(int column, const QString &text)
QIcon fromTheme(const QString &name)
bool setProperty(const char *name, const QVariant &value)
static SieveJob * list(const QUrl &url)
Lists all available scripts at the given sieve url.
Definition: sievejob.cpp:324
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
A job to manage sieve scripts.
Definition: sievejob.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:09:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.