diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-13 16:24:31 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-16 14:54:14 +0100 |
commit | 630f45719a527f8ee739b03bc62f886badea6df3 (patch) | |
tree | b9d859cbfedb30ad8a9570e3b87a419bf24ba6c7 /framework/domain/composercontroller.h | |
parent | b1a2e2de201985a00980bead5272977cda4ef637 (diff) | |
download | kube-630f45719a527f8ee739b03bc62f886badea6df3.tar.gz kube-630f45719a527f8ee739b03bc62f886badea6df3.zip |
Revamp of composercontroller to use actions more.
Instead of setting all properties individually we directly assign all
properties to a context that we assign to the actions.
This way actions can automatically update themselves as new data becomes
available, and we avoid the setter/getter boilerplate, at the cost of a
less explicit interface (But that could be improved by allowing to
define the required properties of a context in c++).
By relying on prehandler/posthandler to execute certain actions we
simplify the control flow and enable the future extension with handlers
that i.e. do encryption etc.
Diffstat (limited to 'framework/domain/composercontroller.h')
-rw-r--r-- | framework/domain/composercontroller.h | 64 |
1 files changed, 20 insertions, 44 deletions
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index aa2ae0d7..6fad0685 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -26,6 +26,9 @@ | |||
26 | #include <QAbstractItemModel> | 26 | #include <QAbstractItemModel> |
27 | #include <sink/applicationdomaintype.h> | 27 | #include <sink/applicationdomaintype.h> |
28 | 28 | ||
29 | #include <actions/context.h> | ||
30 | #include <actions/action.h> | ||
31 | |||
29 | namespace KMime { | 32 | namespace KMime { |
30 | class Message; | 33 | class Message; |
31 | } | 34 | } |
@@ -33,34 +36,21 @@ class Message; | |||
33 | class ComposerController : public QObject | 36 | class ComposerController : public QObject |
34 | { | 37 | { |
35 | Q_OBJECT | 38 | Q_OBJECT |
36 | Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) | 39 | Q_PROPERTY (Kube::Context* mailContext READ mailContext WRITE setMailContext) |
37 | Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) | 40 | Q_PROPERTY (int currentIdentityIndex READ currentIdentityIndex WRITE setCurrentIdentityIndex) |
38 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) | 41 | |
39 | Q_PROPERTY (QString subject READ subject WRITE setSubject NOTIFY subjectChanged) | ||
40 | Q_PROPERTY (QString body READ body WRITE setBody NOTIFY bodyChanged) | ||
41 | Q_PROPERTY (QString recepientSearchString READ recepientSearchString WRITE setRecepientSearchString) | 42 | Q_PROPERTY (QString recepientSearchString READ recepientSearchString WRITE setRecepientSearchString) |
42 | Q_PROPERTY (QAbstractItemModel* recepientAutocompletionModel READ recepientAutocompletionModel CONSTANT) | 43 | Q_PROPERTY (QAbstractItemModel* recepientAutocompletionModel READ recepientAutocompletionModel CONSTANT) |
43 | Q_PROPERTY (QAbstractItemModel* identityModel READ identityModel CONSTANT) | 44 | Q_PROPERTY (QAbstractItemModel* identityModel READ identityModel CONSTANT) |
44 | Q_PROPERTY (int currentIdentityIndex MEMBER m_currentAccountIndex) | 45 | |
45 | Q_PROPERTY (QStringList attachments READ attachemts NOTIFY attachmentsChanged) | 46 | Q_PROPERTY (Kube::Action* sendAction READ sendAction) |
47 | Q_PROPERTY (Kube::Action* saveAsDraftAction READ saveAsDraftAction) | ||
46 | 48 | ||
47 | public: | 49 | public: |
48 | explicit ComposerController(QObject *parent = Q_NULLPTR); | 50 | explicit ComposerController(QObject *parent = Q_NULLPTR); |
49 | 51 | ||
50 | QString to() const; | 52 | Kube::Context* mailContext() const; |
51 | void setTo(const QString &to); | 53 | void setMailContext(Kube::Context *context); |
52 | |||
53 | QString cc() const; | ||
54 | void setCc(const QString &cc); | ||
55 | |||
56 | QString bcc() const; | ||
57 | void setBcc(const QString &bcc); | ||
58 | |||
59 | QString subject() const; | ||
60 | void setSubject(const QString &subject); | ||
61 | |||
62 | QString body() const; | ||
63 | void setBody(const QString &body); | ||
64 | 54 | ||
65 | QString recepientSearchString() const; | 55 | QString recepientSearchString() const; |
66 | void setRecepientSearchString(const QString &body); | 56 | void setRecepientSearchString(const QString &body); |
@@ -68,36 +58,22 @@ public: | |||
68 | QAbstractItemModel *identityModel() const; | 58 | QAbstractItemModel *identityModel() const; |
69 | QAbstractItemModel *recepientAutocompletionModel() const; | 59 | QAbstractItemModel *recepientAutocompletionModel() const; |
70 | 60 | ||
71 | QStringList attachemts() const; | ||
72 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); | 61 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); |
73 | 62 | ||
74 | signals: | 63 | Kube::Action* sendAction(); |
75 | void subjectChanged(); | 64 | Kube::Action* saveAsDraftAction(); |
76 | void bodyChanged(); | 65 | |
77 | void toChanged(); | 66 | void setCurrentIdentityIndex(int index); |
78 | void ccChanged(); | 67 | int currentIdentityIndex() const; |
79 | void bccChanged(); | ||
80 | void fromIndexChanged(); | ||
81 | void attachmentsChanged(); | ||
82 | 68 | ||
83 | public slots: | 69 | public slots: |
84 | void send(); | ||
85 | void saveAsDraft(); | ||
86 | void clear(); | 70 | void clear(); |
87 | void addAttachment(const QUrl &fileUrl); | ||
88 | 71 | ||
89 | private: | 72 | private: |
90 | bool identityIsSet() const; | 73 | Kube::ActionHandler *messageHandler(); |
91 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); | 74 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); |
92 | void setMessage(const QSharedPointer<KMime::Message> &msg); | 75 | void setMessage(const QSharedPointer<KMime::Message> &msg); |
93 | QSharedPointer<KMime::Message> assembleMessage(); | 76 | |
94 | QString m_to; | 77 | int m_currentAccountIndex = -1; |
95 | QString m_cc; | 78 | Kube::Context *mContext; |
96 | QString m_bcc; | ||
97 | QString m_subject; | ||
98 | QString m_body; | ||
99 | QStringList m_attachments; | ||
100 | Sink::ApplicationDomain::Mail m_existingMail; | ||
101 | QVariant m_msg; | ||
102 | int m_currentAccountIndex; | ||
103 | }; | 79 | }; |