Debian Codegraph @

Dekko/backend/accounts/Identity.cpp

raw symbols SCIP
1 #include "Identity.h"
2 #include <QDebug>
3
4 namespace {
5 static const QString accountId = QStringLiteral("id");
6 static const QString parentId = QStringLiteral("parentId");
7 static const QString name = QStringLiteral("name");
8 static const QString email = QStringLiteral("email");
9 static const QString replyTo = QStringLiteral("replyTo");
10 static const QString signature = QStringLiteral("signature");
11 }
12
13 Identity::Identity(QObject *parent) : QObject(parent),
14 m_accountId(0), m_parentId(0), m_isDefault(false)
15 {
16 }
17
18 Identity *Identity::fromMap(QObject *p, const QVariantMap &map)
19 {
20 if (map.isEmpty()) {
21 return Q_NULLPTR;
22 }
23 Identity *identity = new Identity(p);
24 if (map.contains(accountId)) {
25 identity->set_accountId(map.value(accountId).toUInt());
26 }
27 if (map.contains(parentId)) {
28 identity->set_parentId(map.value(parentId).toUInt());
29 }
30 if (map.contains(name)) {
31 identity->set_name(map.value(name).toString());
32 }
33 if (map.contains(email)) {
34 identity->set_email(map.value(email).toString());
35 }
36 if (map.contains(replyTo)) {
37 identity->set_replyTo(map.value(replyTo).toString());
38 }
39 if (map.contains(signature)) {
40 identity->set_signature(map.value(signature).toString());
41 }
42 if (map.contains(QStringLiteral("default"))) {
43 identity->set_isDefault(map.value(QStringLiteral("default")).toBool());
44 }
45 return identity;
46 }
47
48 QString Identity::initials()
49 {
50 QString name = this->get_name();
51 if (name.isEmpty() || !name.at(0).isLetter()) {
52 // Name is empty so return first character of address. :-/
53 return QString(this->get_email().at(0).toUpper());
54 }
55 // Intitials string
56 QString initials;
57 // Now break up the name, we have to set the encoding here as QT_NO_CAST_FROM/TO_ASCII is set
58 QStringList parts = name.split(QStringLiteral(" "));
59 if (parts.first().at(0).isLetter()) {
60 initials += parts.first().at(0).toUpper();
61 }
62 if (parts.size() > 1) {
63 if (parts.last().at(0).isLetter()) {
64 initials += parts.last().at(0).toUpper();
65 }
66 }
67 return initials;
68 }
69
70 QMailAddress Identity::fromAddress()
71 {
72 if (m_name.isEmpty()) {
73 return QMailAddress(m_email);
74 }
75 return QMailAddress(m_name, m_email);
76 }
77
78 QVariantMap Identity::toMap()
79 {
80 QVariantMap map;
81 map[accountId] = get_accountId();
82 map[parentId] = get_parentId();
83 map[name] = get_name();
84 map[email] = get_email();
85 map[replyTo] = get_replyTo();
86 map[signature] = get_signature();
87 map[QStringLiteral("default")] = get_isDefault();
88 return map;
89 }