diff --git a/applet/contents/ui/PopupDialog.qml b/applet/contents/ui/PopupDialog.qml --- a/applet/contents/ui/PopupDialog.qml +++ b/applet/contents/ui/PopupDialog.qml @@ -19,12 +19,15 @@ */ import QtQuick 2.2 +import QtQuick.Layouts 1.2 +import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.networkmanagement 0.2 as PlasmaNM FocusScope { property var notificationInhibitorLock: undefined + property bool isConnectionsListLong: false PlasmaNM.AvailableDevices { id: availableDevices @@ -54,7 +57,7 @@ id: scrollView anchors { - bottom: parent.bottom + bottom: searchBarLayout.top left: parent.left right: parent.right top: toolbar.bottom @@ -74,6 +77,30 @@ section.property: showSections ? "Section" : "" section.delegate: Header { text: section } delegate: ConnectionItem { } + + onContentHeightChanged: isConnectionsListLong = height < contentHeight + } + } + + RowLayout { + id: searchBarLayout + visible: searchTextField.text != "" || isConnectionsListLong + + anchors { + bottom: parent.bottom + left: parent.left + right: parent.right + } + + PlasmaComponents.Label { + text: i18n("Search:") + } + + PlasmaComponents.TextField { + Layout.fillWidth: true + id: searchTextField + focus: true + onTextChanged: appletProxyModel.setFilterRegExp(text) } } @@ -94,6 +121,7 @@ }); } else { notificationInhibitorLock = undefined; + searchTextField.text = "" } } } diff --git a/libs/models/appletproxymodel.cpp b/libs/models/appletproxymodel.cpp --- a/libs/models/appletproxymodel.cpp +++ b/libs/models/appletproxymodel.cpp @@ -26,6 +26,7 @@ : QSortFilterProxyModel(parent) { setDynamicSortFilter(true); + setFilterCaseSensitivity(Qt::CaseInsensitive); sort(0, Qt::DescendingOrder); } @@ -37,9 +38,9 @@ { const QModelIndex index = sourceModel()->index(source_row, 0, source_parent); - // slaves are always filtered-out + // slaves are filtered-out when not searching for a connection (makes the state of search results clear) const bool isSlave = sourceModel()->data(index, NetworkModel::SlaveRole).toBool(); - if (isSlave) { + if (isSlave && filterRegExp().isEmpty()) { return false; } @@ -50,12 +51,16 @@ NetworkModelItem::ItemType itemType = (NetworkModelItem::ItemType)sourceModel()->data(index, NetworkModel::ItemTypeRole).toUInt(); - if (itemType == NetworkModelItem::AvailableConnection || - itemType == NetworkModelItem::AvailableAccessPoint) { + if (itemType != NetworkModelItem::AvailableConnection && + itemType != NetworkModelItem::AvailableAccessPoint) { + return false; + } + + if (filterRegExp().isEmpty()) { return true; } - return false; + return sourceModel()->data(index, NetworkModel::ItemUniqueNameRole).toString().contains(filterRegExp()); } bool AppletProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const