accountinfosource.cpp 3.26 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   SPDX-FileCopyrightText: 2020-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 "accountinfosource.h"
Laurent Montel's avatar
Laurent Montel committed
8
#include <AkonadiCore/AgentInstance>
Laurent Montel's avatar
Laurent Montel committed
9
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
10
#include <KUserFeedback/Provider>
11
#include <MailCommon/MailUtil>
Laurent Montel's avatar
Laurent Montel committed
12
#include <MailTransport/TransportManager>
Laurent Montel's avatar
Laurent Montel committed
13
#include <QVariant>
Laurent Montel's avatar
Laurent Montel committed
14
15

AccountInfoSource::AccountInfoSource()
16
    : KUserFeedback::AbstractDataSource(QStringLiteral("accounts"), KUserFeedback::Provider::DetailedSystemInformation)
Laurent Montel's avatar
Laurent Montel committed
17
18
19
20
21
{
}

QString AccountInfoSource::name() const
{
Laurent Montel's avatar
Laurent Montel committed
22
    return i18n("Account information");
Laurent Montel's avatar
Laurent Montel committed
23
24
25
26
}

QString AccountInfoSource::description() const
{
27
    return i18n("Number and type of accounts configured in KMail (receiver and sender).");
Laurent Montel's avatar
Laurent Montel committed
28
29
30
31
}

QVariant AccountInfoSource::data()
{
32
33
34
35
36
    const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances();
    int numberOfImap = 0;
    int numberOfPop3 = 0;
    int numberOfKolab = 0;
    int numberOfEws = 0;
Laurent Montel's avatar
Laurent Montel committed
37
    int numberOfMaildir = 0;
Laurent Montel's avatar
Laurent Montel committed
38
    int numberOfMbox = 0;
Laurent Montel's avatar
Laurent Montel committed
39
    for (const Akonadi::AgentInstance &type : lst) {
40
41
42
43
44
45
46
47
48
        const QString identifier = type.identifier();
        if (identifier.startsWith(QLatin1String("akonadi_pop3_resource"))) {
            numberOfPop3++;
        } else if (identifier.startsWith(QLatin1String("akonadi_imap_resource"))) {
            numberOfImap++;
        } else if (identifier.startsWith(QLatin1String("akonadi_kolab_resource"))) {
            numberOfKolab++;
        } else if (identifier.startsWith(QLatin1String("akonadi_ews_resource"))) {
            numberOfEws++;
Laurent Montel's avatar
Laurent Montel committed
49
50
        } else if (identifier.startsWith(QLatin1String("akonadi_maildir_resource"))) {
            numberOfMaildir++;
Laurent Montel's avatar
Laurent Montel committed
51
52
        } else if (identifier.startsWith(QLatin1String("akonadi_mbox_resource"))) {
            numberOfMbox++;
53
        }
Laurent Montel's avatar
Laurent Montel committed
54
        // TODO add more
55
56
57
    }
    QVariantList l;
    if (numberOfImap > 0) {
Laurent Montel's avatar
Minor    
Laurent Montel committed
58
        QVariantMap m;
59
60
61
62
63
        m.insert(QStringLiteral("name"), QStringLiteral("imap"));
        m.insert(QStringLiteral("number"), numberOfImap);
        l.push_back(m);
    }
    if (numberOfPop3 > 0) {
Laurent Montel's avatar
Minor    
Laurent Montel committed
64
        QVariantMap m;
65
66
67
68
69
        m.insert(QStringLiteral("name"), QStringLiteral("pop3"));
        m.insert(QStringLiteral("number"), numberOfPop3);
        l.push_back(m);
    }
    if (numberOfKolab > 0) {
Laurent Montel's avatar
Minor    
Laurent Montel committed
70
        QVariantMap m;
71
72
73
74
75
        m.insert(QStringLiteral("name"), QStringLiteral("kolab"));
        m.insert(QStringLiteral("number"), numberOfKolab);
        l.push_back(m);
    }
    if (numberOfEws > 0) {
Laurent Montel's avatar
Minor    
Laurent Montel committed
76
        QVariantMap m;
77
78
79
80
        m.insert(QStringLiteral("name"), QStringLiteral("ews"));
        m.insert(QStringLiteral("number"), numberOfEws);
        l.push_back(m);
    }
Laurent Montel's avatar
Laurent Montel committed
81
82
83
84
85
86
    if (numberOfMaildir > 0) {
        QVariantMap m;
        m.insert(QStringLiteral("name"), QStringLiteral("maildir"));
        m.insert(QStringLiteral("number"), numberOfMaildir);
        l.push_back(m);
    }
Laurent Montel's avatar
Laurent Montel committed
87
88
89
90
91
92
    if (numberOfMbox > 0) {
        QVariantMap m;
        m.insert(QStringLiteral("name"), QStringLiteral("mbox"));
        m.insert(QStringLiteral("number"), numberOfMbox);
        l.push_back(m);
    }
93

Laurent Montel's avatar
Laurent Montel committed
94
    // Mail Transport
Laurent Montel's avatar
Laurent Montel committed
95
96
97
98
99
    QVariantMap m;
    m.insert(QStringLiteral("name"), QStringLiteral("sender"));
    m.insert(QStringLiteral("number"), MailTransport::TransportManager::self()->transports().count());
    l.push_back(m);

100
    return l;
Laurent Montel's avatar
Laurent Montel committed
101
}