importimapsettingprogresspage.cpp 3.21 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   Copyright (C) 2016-2020 Laurent Montel <montel@kde.org>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "importimapsettingprogresspage.h"
21
#include "sieveeditor_debug.h"
22
#include "checks/abstractimapsettingscheckjob.h"
Laurent Montel's avatar
Laurent Montel committed
23
24
#include <QVBoxLayout>
#include <KLocalizedString>
25
#include <QTextEdit>
26
27

ImportImapSettingProgressPage::ImportImapSettingProgressPage(QWidget *parent)
Laurent Montel's avatar
Laurent Montel committed
28
    : QWidget(parent)
29
{
30
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
Laurent Montel's avatar
Laurent Montel committed
31
    mainLayout->setObjectName(QStringLiteral("mainlayout"));
32
    mainLayout->setContentsMargins(0, 0, 0, 0);
33
34
35
36
    mProgressTextEdit = new QTextEdit(this);
    mProgressTextEdit->setObjectName(QStringLiteral("textedit"));
    mProgressTextEdit->setReadOnly(true);
    mainLayout->addWidget(mProgressTextEdit);
37
38
39
40
41
}

ImportImapSettingProgressPage::~ImportImapSettingProgressPage()
{
}
42
43
44

void ImportImapSettingProgressPage::addProgressInfo(const QString &str)
{
45
    mProgressTextEdit->append(str);
46
}
Laurent Montel's avatar
Laurent Montel committed
47
48
49

void ImportImapSettingProgressPage::setSelectedPrograms(const QStringList &programs)
{
Laurent Montel's avatar
Laurent Montel committed
50
    mSelectedPrograms = programs;
51
52
53
54
55
56
}

void ImportImapSettingProgressPage::setListCheckJob(const QMap<QString, AbstractImapSettingsCheckJob *> &listCheckJob)
{
    mListCheckJob = listCheckJob;
}
Laurent Montel's avatar
Laurent Montel committed
57

58
59
60
void ImportImapSettingProgressPage::start()
{
    if (mSelectedPrograms.isEmpty()) {
Laurent Montel's avatar
Laurent Montel committed
61
        qCDebug(SIEVEEDITOR_LOG) << "No selected import type.";
62
63
64
65
66
67
        Q_EMIT finished();
        return;
    }
    if (mListCheckJob.isEmpty()) {
        qCWarning(SIEVEEDITOR_LOG) << "It's a bug, list of check job can not be empty";
        Q_EMIT finished();
68
69
70
71
72
        return;
    }
    for (const QString &prg : qAsConst(mSelectedPrograms)) {
        AbstractImapSettingsCheckJob *job = mListCheckJob.value(prg);
        connect(job, &AbstractImapSettingsCheckJob::importSetting, this, &ImportImapSettingProgressPage::slotImportSettingsDone);
73
        connect(job, &AbstractImapSettingsCheckJob::noSettingsImported, this, &ImportImapSettingProgressPage::noSettingsImported);
74
75
        job->start();
    }
76
77
78
    if (!mSettingsFound) {
        addProgressInfo(i18n("No settings found."));
    }
Laurent Montel's avatar
Laurent Montel committed
79
    Q_EMIT finished();
80
81
82
83
}

void ImportImapSettingProgressPage::slotImportSettingsDone(const QString &name, const SieveEditorUtil::SieveServerConfig &settings)
{
Laurent Montel's avatar
Laurent Montel committed
84
85
86
    const QString str{
        i18n("Import settings from %1...", name)
    };
Laurent Montel's avatar
Laurent Montel committed
87
    addProgressInfo(str);
Laurent Montel's avatar
Laurent Montel committed
88
89
90
    const QString summaryStr{
        i18n("Import settings from %1 done", name)
    };
Laurent Montel's avatar
Laurent Montel committed
91
    Q_EMIT addSummaryInfo(summaryStr);
92
    SieveEditorUtil::addServerSieveConfig(settings);
93
    mSettingsFound = true;
Laurent Montel's avatar
Laurent Montel committed
94
}