diff options
Diffstat (limited to 'framework/domain/composercontroller.h')
-rw-r--r-- | framework/domain/composercontroller.h | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index 11da517e..3e701ed1 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <QString> | 23 | #include <QString> |
24 | #include <QStringList> | 24 | #include <QStringList> |
25 | #include <QVariant> | 25 | #include <QVariant> |
26 | #include <QQmlEngine> | ||
26 | #include <QAbstractItemModel> | 27 | #include <QAbstractItemModel> |
27 | #include <sink/applicationdomaintype.h> | 28 | #include <sink/applicationdomaintype.h> |
28 | 29 | ||
@@ -43,15 +44,62 @@ class ComposerContext : public Kube::Context { | |||
43 | KUBE_CONTEXT_PROPERTY(QString, Body, body) | 44 | KUBE_CONTEXT_PROPERTY(QString, Body, body) |
44 | }; | 45 | }; |
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 | |||
52 | public: | ||
53 | Completer(QAbstractItemModel *model) : mModel{model} | ||
54 | { | ||
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 | |||
66 | /** | ||
67 | * Exposes a model and maintains a current index selection. | ||
68 | */ | ||
69 | class Selector : public QObject { | ||
70 | 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 | |||
88 | int currentIndex() { return mCurrentIndex; } | ||
89 | |||
90 | virtual void setCurrent(const QModelIndex &) = 0; | ||
91 | private: | ||
92 | QAbstractItemModel *mModel = nullptr; | ||
93 | int mCurrentIndex = 0; | ||
94 | }; | ||
95 | |||
46 | class ComposerController : public QObject | 96 | class ComposerController : public QObject |
47 | { | 97 | { |
48 | Q_OBJECT | 98 | Q_OBJECT |
49 | Q_PROPERTY (Kube::Context* mailContext READ mailContext CONSTANT) | 99 | Q_PROPERTY (Kube::Context* mailContext READ mailContext CONSTANT) |
50 | Q_PROPERTY (int currentIdentityIndex READ currentIdentityIndex WRITE setCurrentIdentityIndex) | ||
51 | 100 | ||
52 | Q_PROPERTY (QString recepientSearchString READ recepientSearchString WRITE setRecepientSearchString) | 101 | Q_PROPERTY (Completer* recipientCompleter READ recipientCompleter CONSTANT) |
53 | Q_PROPERTY (QAbstractItemModel* recepientAutocompletionModel READ recepientAutocompletionModel CONSTANT) | 102 | Q_PROPERTY (Selector* identitySelector READ identitySelector CONSTANT) |
54 | Q_PROPERTY (QAbstractItemModel* identityModel READ identityModel CONSTANT) | ||
55 | 103 | ||
56 | Q_PROPERTY (Kube::Action* sendAction READ sendAction) | 104 | Q_PROPERTY (Kube::Action* sendAction READ sendAction) |
57 | Q_PROPERTY (Kube::Action* saveAsDraftAction READ saveAsDraftAction) | 105 | Q_PROPERTY (Kube::Action* saveAsDraftAction READ saveAsDraftAction) |
@@ -61,20 +109,14 @@ public: | |||
61 | 109 | ||
62 | Kube::Context* mailContext(); | 110 | Kube::Context* mailContext(); |
63 | 111 | ||
64 | QString recepientSearchString() const; | 112 | Completer *recipientCompleter() const; |
65 | void setRecepientSearchString(const QString &body); | 113 | Selector *identitySelector() const; |
66 | |||
67 | QAbstractItemModel *identityModel() const; | ||
68 | QAbstractItemModel *recepientAutocompletionModel() const; | ||
69 | 114 | ||
70 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); | 115 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); |
71 | 116 | ||
72 | Kube::Action* sendAction(); | 117 | Kube::Action* sendAction(); |
73 | Kube::Action* saveAsDraftAction(); | 118 | Kube::Action* saveAsDraftAction(); |
74 | 119 | ||
75 | void setCurrentIdentityIndex(int index); | ||
76 | int currentIdentityIndex() const; | ||
77 | |||
78 | public slots: | 120 | public slots: |
79 | void clear(); | 121 | void clear(); |
80 | 122 | ||
@@ -86,6 +128,5 @@ private: | |||
86 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); | 128 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); |
87 | void setMessage(const QSharedPointer<KMime::Message> &msg); | 129 | void setMessage(const QSharedPointer<KMime::Message> &msg); |
88 | 130 | ||
89 | int m_currentAccountIndex = -1; | ||
90 | ComposerContext mContext; | 131 | ComposerContext mContext; |
91 | }; | 132 | }; |