2 Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "sieveeditormanagesievewidget.h"
22 #include "sieveeditorutil.h"
23 #include "ksieveui/sievetreewidgetitem.h"
24 #include "ksieveui/managesievetreeview.h"
26 #include <kmanagesieve/sievejob.h>
28 #include <KLocalizedString>
29 #include <KIconLoader>
31 using namespace KSieveUi
;
33 SieveEditorManageSieveWidget::SieveEditorManageSieveWidget(QWidget
*parent
)
34 : KSieveUi::ManageSieveWidget(parent
)
39 SieveEditorManageSieveWidget::~SieveEditorManageSieveWidget()
44 bool SieveEditorManageSieveWidget::refreshList()
46 bool noImapFound
= true;
47 SieveTreeWidgetItem
*last
= Q_NULLPTR
;
49 const QVector
<SieveEditorUtil::SieveServerConfig
> listConfig
= SieveEditorUtil::readServerSieveConfig();
50 Q_FOREACH (const SieveEditorUtil::SieveServerConfig
&conf
, listConfig
) {
51 last
= new SieveTreeWidgetItem(treeView(), last
);
52 last
->setText(0, conf
.serverName
+ QStringLiteral(" (%1)").arg(conf
.userName
));
53 last
->setIcon(0, QIcon::fromTheme(QStringLiteral("network-server")));
55 const QUrl u
= conf
.url();
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 if (!conf
.enabled
) {
62 last
->setFlags(last
->flags() & ~Qt::ItemIsEnabled
);
63 last
->setText(0, i18n("(Disabled) %1", last
->text(0)));
65 KManageSieve::SieveJob
*job
= KManageSieve::SieveJob::list(u
);
66 connect(job
, &KManageSieve::SieveJob::gotList
, this, &SieveEditorManageSieveWidget::slotGotList
);
67 mJobs
.insert(job
, last
);
68 mUrls
.insert(last
, u
);
69 last
->startAnimation();