Debian Codegraph @

Dekko/backend/mail/SenderIdentities.h

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 #ifndef SENDERIDENTITIES_H
19 #define SENDERIDENTITIES_H
20
21 #include <QObject>
22 #include <QmlObjectListModel.h>
23 #include <Account.h>
24 #include <Identities.h>
25 #include <Helpers.h>
26
27 class IdentityWrapper : public QObject
28 {
29 Q_OBJECT
30 QML_WRITABLE_PROPERTY(Account*, account)
31 QML_WRITABLE_PROPERTY(Identity*, identity)
32 public:
33 explicit IdentityWrapper(QObject *parent = Q_NULLPTR) :
34 QObject(parent), m_account(0), m_identity(0) {}
35 };
36
37 class SenderIdentities : public QObject
38 {
39 Q_OBJECT
40 Q_PROPERTY(QObject *model READ model NOTIFY modelsChanged)
41 // Takes Accounts::model with filter type Accounts::CanSend
42 Q_PROPERTY(QObject *accountsModel READ accountsModel WRITE setAccountsModel NOTIFY modelsChanged)
43 Q_PROPERTY(Identities *accountIdentities READ identities WRITE setIdentities NOTIFY modelsChanged)
44 Q_PROPERTY(QObject *selectedAccount READ selectedAccount NOTIFY selectedIndexChanged)
45 Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged)
46 public:
47 explicit SenderIdentities(QObject *parent = 0);
48
49 QObject *model() const;
50 int selectedIndex() const;
51 QObject *selectedAccount() const;
52 QObject *accountsModel() const;
53 bool isEmpty();
54 bool hasAddress(const QString &address);
55
56 Identities *identities() const;
57
58 int determinePreferredIdentity(const QMailMessage &message);
59
60 signals:
61 void selectedIndexChanged();
62 void modelsChanged();
63
64 public slots:
65 void setSelectedIndex(int selectedIndex);
66 void setAccountsModel(QObject *accountsModel);
67 void setSelectedIndexFromAccountId(quint64 accountId);
68 void reset();
69 void setIdentities(Identities *accountIdentities);
70
71 private slots:
72 void accountsChanged(void);
73
74 private:
75 int findIndexOf(const quint64 &id);
76 IdentityWrapper *createIdentityFromAccount(Account *account);
77 IdentityWrapper *createIdentity(Account *account, const QVariantMap &identity);
78 int m_selectedIndex;
79 QQmlObjectListModel<Account> *m_accountsModel;
80 Identities *m_accountIdentities;
81 QQmlObjectListModel<IdentityWrapper> *m_model;
82 };
83
84 #endif // SENDERIDENTITIES_H