File indexing completed on 2025-02-02 05:09:07
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "accountinfosource.h" 0008 #include <Akonadi/AgentInstance> 0009 #include <KLocalizedString> 0010 #include <KUserFeedback/Provider> 0011 #include <MailCommon/MailUtil> 0012 #include <MailTransport/TransportManager> 0013 #include <QVariant> 0014 0015 AccountInfoSource::AccountInfoSource() 0016 : KUserFeedback::AbstractDataSource(QStringLiteral("accounts"), KUserFeedback::Provider::DetailedSystemInformation) 0017 { 0018 } 0019 0020 QString AccountInfoSource::name() const 0021 { 0022 return i18n("Account information"); 0023 } 0024 0025 QString AccountInfoSource::description() const 0026 { 0027 return i18n("Number and type of accounts configured in KMail (receiver and sender)."); 0028 } 0029 0030 void AccountInfoSource::updateAccountInfo(const QString &resourceName, int numberOfResource, QVariantList &l) 0031 { 0032 QVariantMap m; 0033 m.insert(QStringLiteral("name"), resourceName); 0034 m.insert(QStringLiteral("number"), numberOfResource); 0035 l.push_back(m); 0036 } 0037 0038 QVariant AccountInfoSource::data() 0039 { 0040 const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(); 0041 int numberOfImap = 0; 0042 int numberOfPop3 = 0; 0043 int numberOfKolab = 0; 0044 int numberOfEws = 0; 0045 int numberOfMaildir = 0; 0046 int numberOfMbox = 0; 0047 for (const Akonadi::AgentInstance &type : lst) { 0048 const QString identifier = type.identifier(); 0049 if (identifier.startsWith(QLatin1StringView("akonadi_pop3_resource"))) { 0050 numberOfPop3++; 0051 } else if (identifier.startsWith(QLatin1StringView("akonadi_imap_resource"))) { 0052 numberOfImap++; 0053 } else if (identifier.startsWith(QLatin1StringView("akonadi_kolab_resource"))) { 0054 numberOfKolab++; 0055 } else if (identifier.startsWith(QLatin1StringView("akonadi_ews_resource"))) { 0056 numberOfEws++; 0057 } else if (identifier.startsWith(QLatin1StringView("akonadi_maildir_resource"))) { 0058 numberOfMaildir++; 0059 } else if (identifier.startsWith(QLatin1StringView("akonadi_mbox_resource"))) { 0060 numberOfMbox++; 0061 } 0062 } 0063 QVariantList l; 0064 if (numberOfImap > 0) { 0065 updateAccountInfo(QStringLiteral("imap"), numberOfImap, l); 0066 } 0067 if (numberOfPop3 > 0) { 0068 updateAccountInfo(QStringLiteral("pop3"), numberOfPop3, l); 0069 } 0070 if (numberOfKolab > 0) { 0071 updateAccountInfo(QStringLiteral("kolab"), numberOfKolab, l); 0072 } 0073 if (numberOfEws > 0) { 0074 updateAccountInfo(QStringLiteral("ews"), numberOfEws, l); 0075 } 0076 if (numberOfMaildir > 0) { 0077 updateAccountInfo(QStringLiteral("maildir"), numberOfMaildir, l); 0078 } 0079 if (numberOfMbox > 0) { 0080 updateAccountInfo(QStringLiteral("mbox"), numberOfMbox, l); 0081 } 0082 0083 // Mail Transport 0084 QVariantMap m; 0085 m.insert(QStringLiteral("name"), QStringLiteral("sender")); 0086 m.insert(QStringLiteral("number"), MailTransport::TransportManager::self()->transports().count()); 0087 l.push_back(m); 0088 0089 return l; 0090 }