diff options
Diffstat (limited to 'framework/domain/composercontroller.h')
-rw-r--r-- | framework/domain/composercontroller.h | 118 |
1 files changed, 41 insertions, 77 deletions
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index 3e701ed1..c5046306 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -23,110 +23,74 @@ | |||
23 | #include <QString> | 23 | #include <QString> |
24 | #include <QStringList> | 24 | #include <QStringList> |
25 | #include <QVariant> | 25 | #include <QVariant> |
26 | #include <QQmlEngine> | ||
27 | #include <QAbstractItemModel> | ||
28 | #include <sink/applicationdomaintype.h> | 26 | #include <sink/applicationdomaintype.h> |
27 | #include <KMime/Message> | ||
29 | 28 | ||
30 | #include <actions/context.h> | 29 | #include "completer.h" |
31 | #include <actions/action.h> | 30 | #include "selector.h" |
31 | #include "controller.h" | ||
32 | 32 | ||
33 | namespace KMime { | 33 | inline bool operator !=(const KMime::Types::Mailbox &l, const KMime::Types::Mailbox &r) |
34 | class Message; | 34 | { |
35 | return !(l.prettyAddress() == r.prettyAddress()); | ||
35 | } | 36 | } |
36 | 37 | ||
37 | class ComposerContext : public Kube::Context { | 38 | Q_DECLARE_METATYPE(KMime::Types::Mailbox); |
38 | Q_OBJECT | ||
39 | KUBE_CONTEXT_PROPERTY(QString, To, to) | ||
40 | KUBE_CONTEXT_PROPERTY(QString, Cc, cc) | ||
41 | KUBE_CONTEXT_PROPERTY(QString, Bcc, bcc) | ||
42 | KUBE_CONTEXT_PROPERTY(QString, From, from) | ||
43 | KUBE_CONTEXT_PROPERTY(QString, Subject, subject) | ||
44 | KUBE_CONTEXT_PROPERTY(QString, Body, body) | ||
45 | }; | ||
46 | |||
47 | class Completer : public QObject { | ||
48 | Q_OBJECT | ||
49 | Q_PROPERTY (QAbstractItemModel* model READ model CONSTANT) | ||
50 | Q_PROPERTY (QString searchString WRITE setSearchString READ searchString) | ||
51 | 39 | ||
52 | public: | 40 | namespace KMime { |
53 | Completer(QAbstractItemModel *model) : mModel{model} | 41 | class Message; |
54 | { | 42 | } |
55 | QQmlEngine::setObjectOwnership(mModel, QQmlEngine::CppOwnership); | ||
56 | } | ||
57 | QAbstractItemModel *model() { return mModel; } | ||
58 | virtual void setSearchString(const QString &s) { mSearchString = s; } | ||
59 | QString searchString() const { return mSearchString; } | ||
60 | |||
61 | private: | ||
62 | QAbstractItemModel *mModel = nullptr; | ||
63 | QString mSearchString; | ||
64 | }; | ||
65 | 43 | ||
66 | /** | 44 | class ComposerController : public Kube::Controller |
67 | * Exposes a model and maintains a current index selection. | 45 | { |
68 | */ | ||
69 | class Selector : public QObject { | ||
70 | Q_OBJECT | 46 | Q_OBJECT |
71 | Q_PROPERTY (int currentIndex READ currentIndex WRITE setCurrentIndex) | ||
72 | Q_PROPERTY (QAbstractItemModel* model READ model CONSTANT) | ||
73 | |||
74 | public: | ||
75 | Selector(QAbstractItemModel *model) : mModel{model} | ||
76 | { | ||
77 | QQmlEngine::setObjectOwnership(mModel, QQmlEngine::CppOwnership); | ||
78 | } | ||
79 | |||
80 | virtual QAbstractItemModel *model() { return mModel; } | ||
81 | |||
82 | void setCurrentIndex(int i) { | ||
83 | mCurrentIndex = i; | ||
84 | Q_ASSERT(mModel); | ||
85 | setCurrent(mModel->index(mCurrentIndex, 0)); | ||
86 | } | ||
87 | 47 | ||
88 | int currentIndex() { return mCurrentIndex; } | 48 | //Interface properties |
49 | KUBE_CONTROLLER_PROPERTY(QString, To, to) | ||
50 | KUBE_CONTROLLER_PROPERTY(QString, Cc, cc) | ||
51 | KUBE_CONTROLLER_PROPERTY(QString, Bcc, bcc) | ||
52 | KUBE_CONTROLLER_PROPERTY(QString, Subject, subject) | ||
53 | KUBE_CONTROLLER_PROPERTY(QString, Body, body) | ||
89 | 54 | ||
90 | virtual void setCurrent(const QModelIndex &) = 0; | 55 | //Set by identitySelector |
91 | private: | 56 | KUBE_CONTROLLER_PROPERTY(KMime::Types::Mailbox, Identity, identity) |
92 | QAbstractItemModel *mModel = nullptr; | 57 | KUBE_CONTROLLER_PROPERTY(QByteArray, AccountId, accountId) |
93 | int mCurrentIndex = 0; | ||
94 | }; | ||
95 | 58 | ||
96 | class ComposerController : public QObject | 59 | //Set by loadMessage |
97 | { | 60 | KUBE_CONTROLLER_PROPERTY(KMime::Message::Ptr, ExistingMessage, existingMessage) |
98 | Q_OBJECT | 61 | KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail, ExistingMail, existingMail) |
99 | Q_PROPERTY (Kube::Context* mailContext READ mailContext CONSTANT) | ||
100 | 62 | ||
101 | Q_PROPERTY (Completer* recipientCompleter READ recipientCompleter CONSTANT) | 63 | Q_PROPERTY (Completer* recipientCompleter READ recipientCompleter CONSTANT) |
102 | Q_PROPERTY (Selector* identitySelector READ identitySelector CONSTANT) | 64 | Q_PROPERTY (Selector* identitySelector READ identitySelector CONSTANT) |
65 | //Q_PROPERTY (QValidator* subjectValidator READ subjectValidator CONSTANT) | ||
103 | 66 | ||
104 | Q_PROPERTY (Kube::Action* sendAction READ sendAction) | 67 | Q_PROPERTY (Kube::ControllerAction* sendAction READ sendAction CONSTANT) |
105 | Q_PROPERTY (Kube::Action* saveAsDraftAction READ saveAsDraftAction) | 68 | Q_PROPERTY (Kube::ControllerAction* saveAsDraftAction READ saveAsDraftAction CONSTANT) |
106 | 69 | ||
107 | public: | 70 | public: |
108 | explicit ComposerController(QObject *parent = Q_NULLPTR); | 71 | explicit ComposerController(); |
109 | |||
110 | Kube::Context* mailContext(); | ||
111 | 72 | ||
112 | Completer *recipientCompleter() const; | 73 | Completer *recipientCompleter() const; |
113 | Selector *identitySelector() const; | 74 | Selector *identitySelector() const; |
114 | 75 | ||
115 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); | 76 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); |
116 | 77 | ||
117 | Kube::Action* sendAction(); | 78 | Kube::ControllerAction* sendAction(); |
118 | Kube::Action* saveAsDraftAction(); | 79 | Kube::ControllerAction* saveAsDraftAction(); |
119 | |||
120 | public slots: | ||
121 | void clear(); | ||
122 | 80 | ||
123 | signals: | 81 | private slots: |
124 | void done(); | 82 | void updateSendAction(); |
83 | void send(); | ||
84 | void updateSaveAsDraftAction(); | ||
85 | void saveAsDraft(); | ||
125 | 86 | ||
126 | private: | 87 | private: |
127 | Kube::ActionHandler *messageHandler(); | ||
128 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); | 88 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); |
129 | void setMessage(const QSharedPointer<KMime::Message> &msg); | 89 | void setMessage(const QSharedPointer<KMime::Message> &msg); |
90 | KMime::Message::Ptr assembleMessage(); | ||
130 | 91 | ||
131 | ComposerContext mContext; | 92 | QScopedPointer<Kube::ControllerAction> mSendAction; |
93 | QScopedPointer<Kube::ControllerAction> mSaveAsDraftAction; | ||
94 | QScopedPointer<Completer> mRecipientCompleter; | ||
95 | QScopedPointer<Selector> mIdentitySelector; | ||
132 | }; | 96 | }; |