| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef ACCOUNT_H |
| 19 |
#define ACCOUNT_H |
| 20 |
|
| 21 |
#include <QLoggingCategory> |
| 22 |
#include <QObject> |
| 23 |
#include <QPointer> |
| 24 |
#include <qmailaccount.h> |
| 25 |
#include <qmailaccountconfiguration.h> |
| 26 |
#include "AccountConfiguration.h" |
| 27 |
|
| 28 |
Q_DECLARE_LOGGING_CATEGORY(D_ACCOUNT) |
| 29 |
|
| 30 |
|
| 31 |
class Account : public QObject |
| 32 |
{ |
| 33 |
Q_OBJECT |
| 34 |
|
| 35 |
Q_PROPERTY(int id READ id WRITE setId NOTIFY accountChanged) |
| 36 |
Q_PROPERTY(int accountId READ id WRITE setId NOTIFY accountChanged) |
| 37 |
Q_PROPERTY(QString name READ name WRITE setName NOTIFY accountChanged) |
| 38 |
Q_PROPERTY(QStringList messageSources READ messageSources NOTIFY accountChanged) |
| 39 |
Q_PROPERTY(QStringList messageSinks READ messageSinks NOTIFY accountChanged) |
| 40 |
Q_PROPERTY(QObject *incoming READ incoming NOTIFY accountChanged) |
| 41 |
Q_PROPERTY(QObject *outgoing READ outgoing NOTIFY accountChanged) |
| 42 |
Q_PROPERTY(bool enabled READ enabled NOTIFY accountChanged) |
| 43 |
Q_PROPERTY(bool isValid READ isValid CONSTANT) |
| 44 |
|
| 45 |
Q_ENUMS(SpecialUseFolder) |
| 46 |
Q_ENUMS(Error) |
| 47 |
|
| 48 |
public: |
| 49 |
explicit Account(QObject *parent = 0); |
| 50 |
|
| 51 |
~Account() { |
| 52 |
delete m_account; |
| 53 |
delete m_accountConfig; |
| 54 |
m_incoming->deleteLater(); |
| 55 |
m_outgoing->deleteLater(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
enum SpecialUseFolder { |
| 60 |
InboxFolder = 1, |
| 61 |
OutboxFolder, |
| 62 |
DraftsFolder, |
| 63 |
SentFolder, |
| 64 |
TrashFolder, |
| 65 |
JunkFolder |
| 66 |
}; |
| 67 |
|
| 68 |
enum Error { |
| 69 |
EmptyName, |
| 70 |
InvalidAccountId, |
| 71 |
InvalidFolderId |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
int id() const { return m_account->id().toULongLong(); } |
| 76 |
QMailAccountId accountId() const { return m_account->id(); } |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
QString name() const { return m_account->name(); } |
| 83 |
|
| 84 |
|
| 85 |
QStringList messageSources() const { return m_account->messageSources(); } |
| 86 |
|
| 87 |
|
| 88 |
QStringList messageSinks() const { return m_account->messageSinks(); } |
| 89 |
|
| 90 |
|
| 91 |
QObject *incoming() { return m_incoming; } |
| 92 |
|
| 93 |
|
| 94 |
QObject *outgoing() { return m_outgoing; } |
| 95 |
|
| 96 |
|
| 97 |
bool enabled() const { return m_account->status() & QMailAccount::Enabled; } |
| 98 |
|
| 99 |
|
| 100 |
bool isPreferredSender() const { return m_account->status() & QMailAccount::PreferredSender; } |
| 101 |
|
| 102 |
|
| 103 |
Q_INVOKABLE quint64 specialUseFolder(SpecialUseFolder folder) |
| 104 |
{ |
| 105 |
return m_account->standardFolder((QMailFolder::StandardFolder)folder).toULongLong(); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
Q_INVOKABLE void setSpecialUseFolder(SpecialUseFolder folder, const quint64 &folderId); |
| 112 |
Q_INVOKABLE void setSpecialUseFolder(SpecialUseFolder folder, const QString &path); |
| 113 |
Q_INVOKABLE QString specialUseFolderPath(SpecialUseFolder folder); |
| 114 |
|
| 115 |
QMailAccount *qMailAccount() const { return m_account; } |
| 116 |
|
| 117 |
static const QString imapServiceType, popServiceType, qmfStorage, smtpServiceType; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
void emitAccountChanged() { |
| 123 |
emit accountChanged(id()); |
| 124 |
} |
| 125 |
|
| 126 |
bool isValid() const { return m_account->id().isValid(); } |
| 127 |
|
| 128 |
signals: |
| 129 |
void accountChanged(const int &id); |
| 130 |
void error(Error error, const int &accountId); |
| 131 |
|
| 132 |
public slots: |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
void setId(const int &id); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
void setName(const QString &name); |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
bool save(); |
| 148 |
|
| 149 |
QString customValue(const QString &ns, const QString &key); |
| 150 |
void setCustomValue(const QString &ns, const QString &key, const QString &value); |
| 151 |
protected: |
| 152 |
QMailAccount *m_account; |
| 153 |
QMailAccountConfiguration *m_accountConfig; |
| 154 |
AccountConfiguration *m_incoming; |
| 155 |
AccountConfiguration *m_outgoing; |
| 156 |
|
| 157 |
void initialize(); |
| 158 |
|
| 159 |
private slots: |
| 160 |
void reload(const QMailAccountIdList &ids); |
| 161 |
|
| 162 |
}; |
| 163 |
|
| 164 |
|
| 165 |
class NewAccount : public Account |
| 166 |
{ |
| 167 |
Q_OBJECT |
| 168 |
AccountConfiguration::ServiceType m_type; |
| 169 |
public: |
| 170 |
explicit NewAccount(QObject *parent = 0); |
| 171 |
|
| 172 |
Q_INVOKABLE void setSourceType(const int &srcType); |
| 173 |
}; |
| 174 |
|
| 175 |
#endif |