From 0365646737a1894ca6de94e8a9ad9dd6f28e0493 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 12 Feb 2018 21:34:40 +0100 Subject: A basic but working searchview --- framework/qml/ConversationView.qml | 15 --------- framework/qml/MailListView.qml | 32 +++++++------------ framework/src/domain/maillistmodel.cpp | 27 ++++++++++++++-- views/conversation/qml/View.qml | 27 ++++++++++++++++ views/search/metadata.json | 4 +-- views/search/qml/View.qml | 57 ++++++++++++++++++++++++++++++---- 6 files changed, 116 insertions(+), 46 deletions(-) diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml index f3011f65..2dab92ba 100644 --- a/framework/qml/ConversationView.qml +++ b/framework/qml/ConversationView.qml @@ -32,21 +32,6 @@ FocusScope { property bool hideTrash: true; property bool hideNonTrash: false; - Kube.Listener { - filter: Kube.Messages.mailSelection - onMessageReceived: { - root.mail = message.mail - } - } - - Kube.Listener { - filter: Kube.Messages.folderSelection - onMessageReceived: { - root.hideTrash = !message.trash - root.hideNonTrash = message.trash - } - } - Rectangle { anchors.fill: parent color: Kube.Colors.backgroundColor diff --git a/framework/qml/MailListView.qml b/framework/qml/MailListView.qml index 8fed8c9d..69b7d871 100644 --- a/framework/qml/MailListView.qml +++ b/framework/qml/MailListView.qml @@ -32,27 +32,18 @@ FocusScope { property bool isTrash : false property bool isUnread : false property variant currentMail: null + property bool showFilter: false + property string filter: null onCurrentMailChanged: { Kube.Fabric.postMessage(Kube.Messages.markAsRead, {"mail": currentMail}) - Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail": currentMail}) } - - Kube.Listener { - filter: Kube.Messages.folderSelection - onMessageReceived: { - parentFolder = message.folder - currentMail = null - filterField.clearSearch() - } + onParentFolderChanged: { + currentMail = null + filterField.clearSearch() } - - Kube.Listener { - filter: Kube.Messages.search - onMessageReceived: { - filterField.visible = true - find.forceActiveFocus() - } + onShowFilterChanged: { + find.forceActiveFocus() } Shortcut { @@ -78,12 +69,12 @@ FocusScope { Layout.fillWidth: true height: Kube.Units.gridUnit * 2 color: Kube.Colors.buttonColor - visible: false + visible: root.showFilter function clearSearch() { - filterField.visible = false + root.showFilter = false find.text = "" - mailListModel.filter = "" + root.filter = "" } RowLayout { @@ -104,7 +95,7 @@ FocusScope { id: find Layout.fillWidth: true placeholderText: qsTr("Filter...") - onTextChanged: mailListModel.filter = text + onTextChanged: root.filter = text activeFocusOnTab: visible focus: visible Keys.onEscapePressed: filterField.clearSearch() @@ -150,6 +141,7 @@ FocusScope { model: Kube.MailListModel { id: mailListModel parentFolder: root.parentFolder + filter: root.filter } delegate: Kube.ListDelegate { diff --git a/framework/src/domain/maillistmodel.cpp b/framework/src/domain/maillistmodel.cpp index e3ef04d6..dcebedbc 100644 --- a/framework/src/domain/maillistmodel.cpp +++ b/framework/src/domain/maillistmodel.cpp @@ -48,6 +48,21 @@ void MailListModel::setFilter(const QString &filter) f = "\"" + filter + "\""; } f.append('*'); + if (mCurrentQueryItem.isEmpty()) { + using namespace Sink::ApplicationDomain; + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + query.request(); + } query.filter(Sink::QueryBase::Comparator(f, Sink::QueryBase::Comparator::Fulltext)); } runQuery(query); @@ -202,9 +217,15 @@ bool MailListModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePar void MailListModel::runQuery(const Sink::Query &query) { - mQuery = query; - m_model = Sink::Store::loadModel(query); - setSourceModel(m_model.data()); + if (query.getBaseFilters().isEmpty() && query.ids().isEmpty()) { + mQuery = {}; + m_model.clear(); + setSourceModel(nullptr); + } else { + mQuery = query; + m_model = Sink::Store::loadModel(query); + setSourceModel(m_model.data()); + } } bool MailListModel::isThreaded() const diff --git a/views/conversation/qml/View.qml b/views/conversation/qml/View.qml index 7f1c78bb..5f0d362d 100644 --- a/views/conversation/qml/View.qml +++ b/views/conversation/qml/View.qml @@ -109,6 +109,18 @@ FocusScope { anchors.fill: parent activeFocusOnTab: true Layout.minimumWidth: Kube.Units.gridUnit * 10 + Kube.Listener { + filter: Kube.Messages.folderSelection + onMessageReceived: mailListView.parentFolder = message.folder + } + + Kube.Listener { + filter: Kube.Messages.search + onMessageReceived: mailListView.showFilter = true + } + onCurrentMailChanged: { + Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail": currentMail}) + } } } @@ -118,6 +130,21 @@ FocusScope { Layout.fillWidth: true Layout.fillHeight: parent.height activeFocusOnTab: true + Kube.Listener { + filter: Kube.Messages.mailSelection + onMessageReceived: { + mailView.mail = message.mail + } + } + + Kube.Listener { + filter: Kube.Messages.folderSelection + onMessageReceived: { + mailView.hideTrash = !message.trash + mailView.hideNonTrash = message.trash + } + } + } } } diff --git a/views/search/metadata.json b/views/search/metadata.json index 870ff2aa..a3f6d4a5 100644 --- a/views/search/metadata.json +++ b/views/search/metadata.json @@ -1,4 +1,4 @@ { - "icon": "mail-message-inverted", - "tooltip": "Follow conversations." + "icon": "edit-find-inverted", + "tooltip": "Search" } diff --git a/views/search/qml/View.qml b/views/search/qml/View.qml index d2c8ae65..437b0ba2 100644 --- a/views/search/qml/View.qml +++ b/views/search/qml/View.qml @@ -26,14 +26,59 @@ import QtQuick.Layouts 1.1 import org.kube.framework 1.0 as Kube FocusScope { - Rectangle { + SplitView { anchors.fill: parent - Kube.MailListView { - id: mailListView - anchors.fill: parent - activeFocusOnTab: true + ColumnLayout { + width: Kube.Units.gridUnit * 18 Layout.minimumWidth: Kube.Units.gridUnit * 10 + Rectangle { + id: filterField + Layout.fillWidth: true + height: Kube.Units.gridUnit * 2 + color: Kube.Colors.textColor + + function clearSearch() { + find.text = "" + mailListView.filter = "" + } + + RowLayout { + anchors { + verticalCenter: parent.verticalCenter + } + + width: parent.width - Kube.Units.smallSpacing + spacing: 0 + + Kube.IconButton { + iconName: Kube.Icons.remove + onClicked: filterField.clearSearch() + } + + Kube.TextField { + id: find + Layout.fillWidth: true + placeholderText: qsTr("Search...") + onTextChanged: mailListView.filter = text + focus: true + Keys.onEscapePressed: filterField.clearSearch() + } + } + } + Kube.MailListView { + id: mailListView + showFilter: false + Layout.fillWidth: true + Layout.fillHeight: true + } + } + Kube.ConversationView { + id: mailView + objectName: "mailView" + Layout.fillWidth: true + Layout.fillHeight: parent.height + activeFocusOnTab: true + mail: mailListView.currentMail } - } } } -- cgit v1.2.3