diff options
Diffstat (limited to 'framework/domain/composercontroller.cpp')
-rw-r--r-- | framework/domain/composercontroller.cpp | 88 |
1 files changed, 48 insertions, 40 deletions
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 7129e342..57d386c6 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -47,35 +47,65 @@ ComposerController::ComposerController(QObject *parent) : QObject(parent) | |||
47 | QQmlEngine::setObjectOwnership(&mContext, QQmlEngine::CppOwnership); | 47 | QQmlEngine::setObjectOwnership(&mContext, QQmlEngine::CppOwnership); |
48 | } | 48 | } |
49 | 49 | ||
50 | QString ComposerController::recepientSearchString() const | ||
51 | { | ||
52 | return QString(); | ||
53 | } | ||
54 | 50 | ||
55 | Kube::Context* ComposerController::mailContext() | 51 | Kube::Context* ComposerController::mailContext() |
56 | { | 52 | { |
57 | return &mContext; | 53 | return &mContext; |
58 | } | 54 | } |
59 | 55 | ||
60 | void ComposerController::setRecepientSearchString(const QString &s) | 56 | class RecipientCompleter : public Completer { |
61 | { | 57 | public: |
62 | if (auto model = static_cast<RecipientAutocompletionModel*>(recepientAutocompletionModel())) { | 58 | RecipientCompleter() : Completer(new RecipientAutocompletionModel) |
63 | model->setFilter(s); | 59 | { |
64 | } | 60 | } |
65 | } | ||
66 | 61 | ||
67 | QAbstractItemModel *ComposerController::identityModel() const | 62 | void setSearchString(const QString &s) { |
63 | static_cast<RecipientAutocompletionModel*>(model())->setFilter(s); | ||
64 | Completer::setSearchString(s); | ||
65 | } | ||
66 | }; | ||
67 | |||
68 | Completer *ComposerController::recipientCompleter() const | ||
68 | { | 69 | { |
69 | static auto model = new IdentitiesModel(); | 70 | static auto selector = new RecipientCompleter(); |
70 | QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership); | 71 | QQmlEngine::setObjectOwnership(selector, QQmlEngine::CppOwnership); |
71 | return model; | 72 | return selector; |
72 | } | 73 | } |
73 | 74 | ||
74 | QAbstractItemModel *ComposerController::recepientAutocompletionModel() const | 75 | class IdentitySelector : public Selector { |
76 | public: | ||
77 | IdentitySelector(ComposerContext &context) : Selector(new IdentitiesModel), mContext(context) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | void setCurrent(const QModelIndex &index) Q_DECL_OVERRIDE | ||
82 | { | ||
83 | if (index.isValid()) { | ||
84 | auto currentAccountId = index.data(IdentitiesModel::AccountId).toByteArray(); | ||
85 | |||
86 | KMime::Types::Mailbox mb; | ||
87 | mb.setName(index.data(IdentitiesModel::Username).toString()); | ||
88 | mb.setAddress(index.data(IdentitiesModel::Address).toString().toUtf8()); | ||
89 | SinkLog() << "Setting current identity: " << mb.prettyAddress() << "Account: " << currentAccountId; | ||
90 | |||
91 | mContext.setProperty("identity", QVariant::fromValue(mb)); | ||
92 | mContext.setProperty("accountId", QVariant::fromValue(currentAccountId)); | ||
93 | } else { | ||
94 | SinkWarning() << "No valid identity for index: " << index; | ||
95 | mContext.setProperty("identity", QVariant{}); | ||
96 | mContext.setProperty("accountId", QVariant{}); | ||
97 | } | ||
98 | |||
99 | } | ||
100 | private: | ||
101 | ComposerContext &mContext; | ||
102 | }; | ||
103 | |||
104 | Selector *ComposerController::identitySelector() const | ||
75 | { | 105 | { |
76 | static auto model = new RecipientAutocompletionModel(); | 106 | static auto selector = new IdentitySelector(*const_cast<ComposerContext*>(&mContext)); |
77 | QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership); | 107 | QQmlEngine::setObjectOwnership(selector, QQmlEngine::CppOwnership); |
78 | return model; | 108 | return selector; |
79 | } | 109 | } |
80 | 110 | ||
81 | void ComposerController::setMessage(const KMime::Message::Ptr &msg) | 111 | void ComposerController::setMessage(const KMime::Message::Ptr &msg) |
@@ -113,7 +143,7 @@ void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) | |||
113 | 143 | ||
114 | void ComposerController::recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName) | 144 | void ComposerController::recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName) |
115 | { | 145 | { |
116 | if (auto model = static_cast<RecipientAutocompletionModel*>(recepientAutocompletionModel())) { | 146 | if (auto model = static_cast<RecipientAutocompletionModel*>(recipientCompleter()->model())) { |
117 | model->addEntry(addrSpec, displayName); | 147 | model->addEntry(addrSpec, displayName); |
118 | } | 148 | } |
119 | } | 149 | } |
@@ -194,25 +224,3 @@ Kube::Action* ComposerController::sendAction() | |||
194 | })); | 224 | })); |
195 | return action; | 225 | return action; |
196 | } | 226 | } |
197 | |||
198 | void ComposerController::setCurrentIdentityIndex(int index) | ||
199 | { | ||
200 | m_currentAccountIndex = index; | ||
201 | auto currentIndex = identityModel()->index(m_currentAccountIndex, 0); | ||
202 | if (currentIndex.isValid()) { | ||
203 | auto currentAccountId = currentIndex.data(IdentitiesModel::AccountId).toByteArray(); | ||
204 | KMime::Types::Mailbox mb; | ||
205 | mb.setName(currentIndex.data(IdentitiesModel::Username).toString()); | ||
206 | mb.setAddress(currentIndex.data(IdentitiesModel::Address).toString().toUtf8()); | ||
207 | SinkLog() << "Setting current identity: " << mb.prettyAddress() << "Account: " << currentAccountId; | ||
208 | mContext.setProperty("identity", QVariant::fromValue(mb)); | ||
209 | mContext.setProperty("accountId", QVariant::fromValue(currentAccountId)); | ||
210 | } else { | ||
211 | SinkWarning() << "No valid identity for index: " << index << " out of available in model: " << identityModel()->rowCount(); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | int ComposerController::currentIdentityIndex() const | ||
216 | { | ||
217 | return m_currentAccountIndex; | ||
218 | } | ||