| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef MESSAGE_H |
| 19 |
#define MESSAGE_H |
| 20 |
|
| 21 |
#include <QObject> |
| 22 |
#include <QUrl> |
| 23 |
#include <qmailmessage.h> |
| 24 |
#include <QmlObjectListModel.h> |
| 25 |
#include "MailAddress.h" |
| 26 |
#include <QtConcurrent/QtConcurrent> |
| 27 |
#include <QFuture> |
| 28 |
#include <QFutureWatcher> |
| 29 |
#include "Attachments.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class MinimalMessage : public QObject |
| 37 |
{ |
| 38 |
Q_OBJECT |
| 39 |
Q_PROPERTY(int messageId READ messageId WRITE setMessageId NOTIFY minMessageChanged) |
| 40 |
Q_PROPERTY(int parentAccountId READ parentAccountId NOTIFY minMessageChanged) |
| 41 |
Q_PROPERTY(MailAddress *from READ from NOTIFY minMessageChanged) |
| 42 |
Q_PROPERTY(QString subject READ subject NOTIFY minMessageChanged) |
| 43 |
Q_PROPERTY(QString preview READ preview NOTIFY minMessageChanged) |
| 44 |
Q_PROPERTY(bool hasAttachments READ hasAttachments NOTIFY minMessageChanged) |
| 45 |
Q_PROPERTY(bool isRead READ isRead NOTIFY minMessageChanged) |
| 46 |
Q_PROPERTY(bool isImportant READ isFlagged NOTIFY minMessageChanged) |
| 47 |
Q_PROPERTY(bool isTodo READ isTodo WRITE setIsTodo NOTIFY minMessageChanged) |
| 48 |
Q_PROPERTY(bool isDone READ isDone NOTIFY minMessageChanged) |
| 49 |
Q_PROPERTY(bool isJunk READ isJunk NOTIFY minMessageChanged) |
| 50 |
Q_PROPERTY(bool canBeRestored READ canBeRestored NOTIFY minMessageChanged) |
| 51 |
Q_PROPERTY(bool isListPost READ isListPost NOTIFY minMessageChanged) |
| 52 |
Q_PROPERTY(bool isDraft READ isDraft NOTIFY minMessageChanged) |
| 53 |
Q_PROPERTY(QString previousFolderName READ previousFolderName NOTIFY minMessageChanged) |
| 54 |
Q_PROPERTY(QDateTime date READ date NOTIFY minMessageChanged) |
| 55 |
Q_PROPERTY(QString prettyDate READ prettyDate NOTIFY minMessageChanged) |
| 56 |
Q_PROPERTY(QString prettyLongDate READ prettyLongDate NOTIFY minMessageChanged) |
| 57 |
Q_PROPERTY(Qt::CheckState checked READ checked WRITE setChecked NOTIFY checkedChanged) |
| 58 |
Q_PROPERTY(QVariant senderMsgKey READ senderMsgKey NOTIFY minMessageChanged) |
| 59 |
|
| 60 |
public: |
| 61 |
explicit MinimalMessage(QObject *parent = 0); |
| 62 |
int messageId() const { return m_id.toULongLong(); } |
| 63 |
int parentAccountId() const { return QMailMessageMetaData(m_id).parentAccountId().toULongLong(); } |
| 64 |
MailAddress *from() const; |
| 65 |
QString subject() const; |
| 66 |
QString preview() const; |
| 67 |
bool hasAttachments() const; |
| 68 |
bool isRead() const; |
| 69 |
bool isFlagged() const; |
| 70 |
bool isTodo() const; |
| 71 |
bool canBeRestored() const; |
| 72 |
bool isDone() const; |
| 73 |
bool isJunk() const; |
| 74 |
bool isListPost() const; |
| 75 |
bool isDraft() const; |
| 76 |
QString previousFolderName() const; |
| 77 |
QDateTime date() const; |
| 78 |
QString prettyDate(); |
| 79 |
QString prettyLongDate(); |
| 80 |
Qt::CheckState checked() const; |
| 81 |
QVariant senderMsgKey() const; |
| 82 |
|
| 83 |
signals: |
| 84 |
void internalMessageChanged(); |
| 85 |
void minMessageChanged(); |
| 86 |
void checkedChanged(); |
| 87 |
|
| 88 |
public slots: |
| 89 |
void setMessageId(const quint64 &id); |
| 90 |
void setMessageId(const QMailMessageId &id); |
| 91 |
void emitMinMessageChanged() { emit minMessageChanged(); } |
| 92 |
void selectionEnded() { setChecked(Qt::Unchecked); } |
| 93 |
void selectionStarted() { setChecked(Qt::Unchecked); } |
| 94 |
void setChecked(const Qt::CheckState &checked); |
| 95 |
void setIsTodo(const bool todo); |
| 96 |
|
| 97 |
protected: |
| 98 |
QMailMessageId m_id; |
| 99 |
|
| 100 |
private: |
| 101 |
MailAddress *m_from; |
| 102 |
Qt::CheckState m_checked; |
| 103 |
}; |
| 104 |
|
| 105 |
class Message : public MinimalMessage |
| 106 |
{ |
| 107 |
Q_OBJECT |
| 108 |
Q_PROPERTY(QObject *to READ to NOTIFY messageChanged) |
| 109 |
Q_PROPERTY(QObject *cc READ cc NOTIFY messageChanged) |
| 110 |
Q_PROPERTY(QObject *bcc READ bcc NOTIFY messageChanged) |
| 111 |
Q_PROPERTY(QUrl body READ body NOTIFY bodyChanged) |
| 112 |
|
| 113 |
|
| 114 |
Q_PROPERTY(QString toRecipientsString READ toRecipientsString NOTIFY messageChanged) |
| 115 |
Q_PROPERTY(bool preferPlainText READ preferPlainText WRITE setPreferPlainText NOTIFY plainTextChanged) |
| 116 |
Q_PROPERTY(QObject *attachments READ attachments NOTIFY messageChanged) |
| 117 |
public: |
| 118 |
explicit Message(QObject *parent = 0); |
| 119 |
QObject *to() const { return m_to; } |
| 120 |
QObject *cc() const { return m_cc; } |
| 121 |
QObject *bcc() const { return m_bcc; } |
| 122 |
QObject *attachments() const { return m_attachments; } |
| 123 |
QString toRecipientsString(); |
| 124 |
|
| 125 |
QUrl body() const; |
| 126 |
static QUrl findInterestingBodyPart(const QMailMessageId &id, const bool preferPlainText); |
| 127 |
|
| 128 |
bool preferPlainText() const; |
| 129 |
|
| 130 |
public slots: |
| 131 |
void setPreferPlainText(const bool preferPlainText); |
| 132 |
|
| 133 |
signals: |
| 134 |
void messageChanged(); |
| 135 |
void bodyChanged(); |
| 136 |
|
| 137 |
void plainTextChanged(); |
| 138 |
|
| 139 |
private slots: |
| 140 |
void initMessage(); |
| 141 |
void handleUpdatedMessages(const QMailMessageIdList &list); |
| 142 |
|
| 143 |
private: |
| 144 |
QQmlObjectListModel<MailAddress> *m_to; |
| 145 |
QQmlObjectListModel<MailAddress> *m_cc; |
| 146 |
QQmlObjectListModel<MailAddress> *m_bcc; |
| 147 |
Attachments *m_attachments; |
| 148 |
QUrl m_body; |
| 149 |
bool m_preferPlainText; |
| 150 |
}; |
| 151 |
|
| 152 |
#endif |