From ef8a9f2f1d9f91358541b83fab63603aa3001bff Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 16 Apr 2017 17:47:48 +0200 Subject: Don't thread drafts and sent To do this we: * Expose from the model wether or not the model is threaded * Set the relevant properties from the model on the controller (so we can switch between aggregate and non-aggregate versions) * Keep the controller in the view it belongs to. While this works it highlights a couple of issues: * Controllers are view specific and should be kept within the view. * The actions we execute in the controller are closely related to the model. The model is essentially what the user sees, and therefore what he operatees on. * Sink should perhaps expose aggregates better. We have to pass around the values from the model because the model dispatches between aggregate and non-aggregate property depending on the threaded state. Similary the controller operates on the thread or not depending on the threaded state. Perhaps it would be more useful if sink actually returned the aggregate somehow, with the regular properties. That way the controller could use the regular properties from the entity it gets (which would simply either be the aggregate or non-aggregate depending on the executed query). If the aggregate already contains all matched ids, then we would also not have to execute an additional query to get the thread again, the modification would simply be applied to all ids originally returned. --- components/kube/contents/ui/Kube.qml | 22 --------------- framework/qml/ConversationView.qml | 1 + framework/qml/MailListView.qml | 35 ++++++++++++++++++++++++ framework/src/domain/mailcontroller.cpp | 32 +++++++++++----------- framework/src/domain/mailcontroller.h | 8 +++++- framework/src/domain/maillistmodel.cpp | 47 ++++++++++++++++++++++++++++++--- framework/src/domain/maillistmodel.h | 7 +++++ 7 files changed, 109 insertions(+), 43 deletions(-) diff --git a/components/kube/contents/ui/Kube.qml b/components/kube/contents/ui/Kube.qml index 41e970c6..979f7bd5 100644 --- a/components/kube/contents/ui/Kube.qml +++ b/components/kube/contents/ui/Kube.qml @@ -89,15 +89,6 @@ Controls2.ApplicationWindow { //END ActionHandler //Controller - Kube.MailController { - id: mailController - Binding on threadLeader { - //!! checks for the availability of the type - when: !!mailListView.currentMail - value: mailListView.currentMail - } - } - Kube.FolderController { id: folderController Binding on folder { @@ -119,19 +110,6 @@ Controls2.ApplicationWindow { onActivated: folderController.synchronizeAction.execute() enabled: folderController.synchronizeAction.enabled } - Shortcut { - sequence: StandardKey.Delete - onActivated: mailController.moveToTrashAction.execute() - enabled: mailController.moveToTrashAction.enabled - } - Shortcut { - sequence: StandardKey.MoveToNextLine - onActivated: mailListView.currentIndex++ - } - Shortcut { - sequence: StandardKey.MoveToPreviousLine - onActivated: mailListView.currentIndex-- - } //END Shortcuts //BEGIN background diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml index 8c6e2d38..83771925 100644 --- a/framework/qml/ConversationView.qml +++ b/framework/qml/ConversationView.qml @@ -149,6 +149,7 @@ Rectangle { when: !!root.currentMail value: root.currentMail } + operateOnThreads: false } Timer { diff --git a/framework/qml/MailListView.qml b/framework/qml/MailListView.qml index 1e0123cc..27fae7c2 100644 --- a/framework/qml/MailListView.qml +++ b/framework/qml/MailListView.qml @@ -28,6 +28,9 @@ Item { property variant parentFolder property variant currentMail: null property bool isDraft : false + property bool isImportant : false + property bool isTrash : false + property bool isUnread : false property int currentIndex property string filterString: searchBar.text; @@ -35,6 +38,34 @@ Item { currentMail = null } + Kube.MailController { + id: mailController + Binding on mail { + //!! checks for the availability of the type + when: !!root.currentMail + value: root.currentMail + } + unread: root.isUnread + trash: root.isUnread + important: root.isUnread + draft: root.isUnread + operateOnThreads: mailListModel.isThreaded + } + + Shortcut { + sequence: StandardKey.Delete + onActivated: mailController.moveToTrashAction.execute() + enabled: mailController.moveToTrashAction.enabled + } + Shortcut { + sequence: StandardKey.MoveToNextLine + onActivated: root.currentIndex++ + } + Shortcut { + sequence: StandardKey.MoveToPreviousLine + onActivated: root.currentIndex-- + } + ToolBar { id: toolbar @@ -142,9 +173,13 @@ Item { onCurrentItemChanged: { root.currentMail = currentItem.currentData.domainObject; root.isDraft = currentItem.currentData.draft; + root.isTrash = currentItem.currentData.trash; + root.isImportant = currentItem.currentData.important; + root.isUnread = currentItem.currentData.unread; } model: Kube.MailListModel { + id: mailListModel parentFolder: root.parentFolder filter: root.filterString } diff --git a/framework/src/domain/mailcontroller.cpp b/framework/src/domain/mailcontroller.cpp index fe02afc3..a6c5c555 100644 --- a/framework/src/domain/mailcontroller.cpp +++ b/framework/src/domain/mailcontroller.cpp @@ -39,7 +39,10 @@ MailController::MailController() action_moveToFolder{new Kube::ControllerAction{this, &MailController::moveToFolder}} { QObject::connect(this, &MailController::mailChanged, &MailController::updateActions); - QObject::connect(this, &MailController::threadLeaderChanged, &MailController::updateActions); + QObject::connect(this, &MailController::importantChanged, &MailController::updateActions); + QObject::connect(this, &MailController::draftChanged, &MailController::updateActions); + QObject::connect(this, &MailController::trashChanged, &MailController::updateActions); + QObject::connect(this, &MailController::unreadChanged, &MailController::updateActions); updateActions(); } @@ -47,24 +50,21 @@ void MailController::runModification(const std::functionsetEnabled(!mail->getTrash()); - action_restoreFromTrash->setEnabled(mail->getTrash()); - action_markAsRead->setEnabled(mail->getUnread()); - action_markAsUnread->setEnabled(!mail->getUnread()); + if (auto mail = getMail()) { + action_moveToTrash->setEnabled(!getTrash()); + action_restoreFromTrash->setEnabled(getTrash()); + action_markAsRead->setEnabled(getUnread()); + action_markAsUnread->setEnabled(getUnread()); } else { action_moveToTrash->setEnabled(false); action_restoreFromTrash->setEnabled(false); @@ -99,8 +99,8 @@ void MailController::markAsImportant() void MailController::toggleImportant() { - runModification([] (ApplicationDomain::Mail &mail) { - mail.setImportant(!mail.getImportant()); + runModification([this] (ApplicationDomain::Mail &mail) { + mail.setImportant(!getImportant()); SinkLog() << "Toggle important " << mail.identifier() << mail.getImportant(); }); } diff --git a/framework/src/domain/mailcontroller.h b/framework/src/domain/mailcontroller.h index f6613558..0bc000f1 100644 --- a/framework/src/domain/mailcontroller.h +++ b/framework/src/domain/mailcontroller.h @@ -25,9 +25,15 @@ class MailController : public Kube::Controller { Q_OBJECT + //Use this instead of mail property to get overall status of thread. + KUBE_CONTROLLER_PROPERTY(bool, Unread, unread) + KUBE_CONTROLLER_PROPERTY(bool, Important, important) + KUBE_CONTROLLER_PROPERTY(bool, Trash, trash) + KUBE_CONTROLLER_PROPERTY(bool, Draft, draft) + KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail::Ptr, Mail, mail) - KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail::Ptr, ThreadLeader, threadLeader) KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, TargetFolder, targetFolder) + KUBE_CONTROLLER_PROPERTY(bool, OperateOnThreads, operateOnThreads) KUBE_CONTROLLER_ACTION(markAsRead) KUBE_CONTROLLER_ACTION(markAsUnread) KUBE_CONTROLLER_ACTION(markAsImportant) diff --git a/framework/src/domain/maillistmodel.cpp b/framework/src/domain/maillistmodel.cpp index 83340f69..0f477624 100644 --- a/framework/src/domain/maillistmodel.cpp +++ b/framework/src/domain/maillistmodel.cpp @@ -114,9 +114,17 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const case Date: return mail->getDate(); case Unread: - return mail->getProperty("unreadCollected").toList().contains(true); + if (mIsThreaded) { + return mail->getProperty("unreadCollected").toList().contains(true); + } else { + return mail->getUnread(); + } case Important: - return mail->getProperty("importantCollected").toList().contains(true); + if (mIsThreaded) { + return mail->getProperty("importantCollected").toList().contains(true); + } else { + return mail->getImportant(); + } case Draft: return mail->getDraft(); case Sent: @@ -133,7 +141,11 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const } return mail->getMimeMessage(); case ThreadSize: - return mail->getProperty("count").toInt(); + if (mIsThreaded) { + return mail->getProperty("count").toInt(); + } else { + return 1; + } case Mail: return QVariant::fromValue(mail); case Incomplete: @@ -176,6 +188,11 @@ void MailListModel::runQuery(const Sink::Query &query) setSourceModel(m_model.data()); } +bool MailListModel::isThreaded() const +{ + return mIsThreaded; +} + void MailListModel::setParentFolder(const QVariant &parentFolder) { using namespace Sink::ApplicationDomain; @@ -189,11 +206,33 @@ void MailListModel::setParentFolder(const QVariant &parentFolder) return; } mCurrentQueryItem = folder->identifier(); - Sink::Query query = Sink::StandardQueries::threadLeaders(*folder); + if (folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::drafts) || + folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::sent)) { + mIsThreaded = false; + } else { + mIsThreaded = true; + } + emit isThreadedChanged(); + + Sink::Query query = [&] { + if (mIsThreaded) { + return Sink::StandardQueries::threadLeaders(*folder); + } else { + Sink::Query query; + query.setId("threadleaders-unthreaded"); + if (!folder->resourceInstanceIdentifier().isEmpty()) { + query.resourceFilter(folder->resourceInstanceIdentifier()); + } + query.filter(*folder); + query.sort(); + return query; + } + }(); if (!folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::trash)) { //Filter trash if this is not a trash folder query.filter(false); } + query.setFlags(Sink::Query::LiveQuery); query.limit(100); query.request(); diff --git a/framework/src/domain/maillistmodel.h b/framework/src/domain/maillistmodel.h index 44347661..5ed081f4 100644 --- a/framework/src/domain/maillistmodel.h +++ b/framework/src/domain/maillistmodel.h @@ -32,6 +32,7 @@ class MailListModel : public QSortFilterProxyModel Q_PROPERTY (QVariant parentFolder READ parentFolder WRITE setParentFolder) Q_PROPERTY (QVariant mail READ mail WRITE setMail) Q_PROPERTY (QString filter READ filter WRITE setFilter) + Q_PROPERTY (bool isThreaded READ isThreaded NOTIFY isThreadedChanged) public: enum Status { @@ -49,6 +50,8 @@ public: bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE; + bool isThreaded() const; + enum Roles { Subject = Qt::UserRole + 1, Sender, @@ -84,6 +87,9 @@ public: void setFilter(const QString &mail); QString filter() const; +signals: + void isThreadedChanged(); + private: void fetchMail(Sink::ApplicationDomain::Mail::Ptr mail); @@ -91,4 +97,5 @@ private: bool mFetchMails = false; QSet mFetchedMails; QByteArray mCurrentQueryItem; + bool mIsThreaded = true; }; -- cgit v1.2.3