Debian Codegraph @

Dekko/backend/accounts/quick/PresetProviderModel.cpp

raw symbols SCIP
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "PresetProviderModel.h"
19 #include <QSettings>
20 #include <Paths.h>
21
22 Provider::Provider(QObject *parent, const QString &description, const int &type):
23 QObject(parent), m_description(description), m_type((Provider::Type)type)
24 {
25 }
26
27 Provider::Provider(QObject *parent, const QString &providerFilePath, const QString &group) : QObject(parent),
28 m_imapPort(0), m_imapUseSSL(false), m_imapStartTLS(false), m_smtpPort(0), m_smtpUseSSL(false), m_smtpStartTLS(false),
29 m_type(INVALID)
30 {
31 ProviderFile file(providerFilePath, ProviderFile::NativeFormat);
32 file.beginGroup(group);
33 m_description = file.value(QStringLiteral("description")).toString();
34 m_domain = file.value(QStringLiteral("domain")).toString();
35
36 m_imapHost = file.value(QStringLiteral("imap.server")).toString();
37 m_imapPort = file.value(QStringLiteral("imap.port")).toInt();
38 m_imapUseSSL = file.value(QStringLiteral("imap.useSsl")).toBool();
39 m_imapStartTLS = file.value(QStringLiteral("imap.startTls")).toBool();
40
41 m_smtpHost = file.value(QStringLiteral("smtp.server")).toString();
42 m_smtpPort = file.value(QStringLiteral("smtp.port")).toInt();
43 m_smtpUseSSL = file.value(QStringLiteral("imap.useSsl")).toBool();
44 m_smtpStartTLS = file.value(QStringLiteral("imap.startTls")).toBool();
45
46 m_type = Type::PRESET;
47 file.endGroup();
48 }
49
50 QString Provider::icon()
51 {
52 switch (m_type) {
53 case INVALID:
54 case PRESET:
55 return Paths::providerIconForDomain(m_domain);
56 case IMAP:
57 case POP3:
58 return QStringLiteral("qrc:/provider/dekko-app-symbolic.svg");
59 case SMTP:
60 return QStringLiteral("qrc:/actions/send.svg");
61 }
62 Q_UNREACHABLE();
63 }
64
65 PresetProviderModel::PresetProviderModel(QObject *parent) : QObject(parent),
66 m_model(0)
67 {
68 m_model = new QQmlObjectListModel<Provider>(this);
69 emit modelChanged();
70 m_providers = Paths::findProviderFile();
71 init();
72 }
73
74 void PresetProviderModel::init()
75 {
76 ProviderFile p(m_providers, ProviderFile::NativeFormat);
77 #ifdef IMAP_ENABLED
78 Q_FOREACH(const QString &group, p.childGroups()) {
79 Provider *provider = new Provider(0, m_providers, group);
80 m_model->append(provider);
81 }
82 Provider *imapprovider = new Provider(0, "IMAP", Provider::IMAP);
83 m_model->append(imapprovider);
84 #endif
85 #ifdef POP3_ENABLED
86 Provider *pop3provider = new Provider(0, "POP3", Provider::POP3);
87 m_model->append(pop3provider);
88 #endif
89 Provider *smtpprovider = new Provider(0, "SMTP", Provider::SMTP);
90 m_model->append(smtpprovider);
91 }
92
93
94