diff --git a/applet/contents/ui/PopupDialog.qml b/applet/contents/ui/PopupDialog.qml index 329cfbed..ac1c564b 100644 --- a/applet/contents/ui/PopupDialog.qml +++ b/applet/contents/ui/PopupDialog.qml @@ -1,105 +1,102 @@ /* Copyright 2013-2017 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ 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 PlasmaNM.AvailableDevices { id: availableDevices } PlasmaNM.NetworkModel { id: connectionModel } PlasmaNM.AppletProxyModel { id: appletProxyModel sourceModel: connectionModel } - Toolbar { - id: toolbar + ColumnLayout { + anchors.fill: parent - anchors { - left: parent.left - right: parent.right - top: parent.top - } - } - - PlasmaExtras.ScrollArea { - id: scrollView - - anchors { - bottom: parent.bottom - left: parent.left - right: parent.right - top: toolbar.bottom + Toolbar { + id: toolbar + Layout.fillWidth: true } - ListView { - id: connectionView - - property bool availableConnectionsVisible: false - property int currentVisibleButtonIndex: -1 - - anchors.fill: parent - clip: true - model: appletProxyModel - currentIndex: -1 - boundsBehavior: Flickable.StopAtBounds - section.property: showSections ? "Section" : "" - section.delegate: Header { text: section } - delegate: ConnectionItem { } + PlasmaExtras.ScrollArea { + id: scrollView + Layout.fillWidth: true + Layout.fillHeight: true + + ListView { + id: connectionView + + property bool availableConnectionsVisible: false + property int currentVisibleButtonIndex: -1 + + anchors.fill: parent + clip: true + model: appletProxyModel + currentIndex: -1 + boundsBehavior: Flickable.StopAtBounds + section.property: showSections ? "Section" : "" + section.delegate: Header { text: section } + delegate: ConnectionItem { } + } } } Connections { target: plasmoid onExpandedChanged: { connectionView.currentVisibleButtonIndex = -1; if (expanded) { var service = notificationsEngine.serviceForSource("notifications"); var operation = service.operationDescription("inhibit"); operation.hint = "x-kde-appname"; operation.value = "networkmanagement"; var job = service.startOperationCall(operation); job.finished.connect(function(job) { if (expanded) { notificationInhibitorLock = job.result; } }); } else { notificationInhibitorLock = undefined; + toolbar.closeSearch() } } } PlasmaCore.DataSource { id: notificationsEngine engine: "notifications" } } diff --git a/applet/contents/ui/Toolbar.qml b/applet/contents/ui/Toolbar.qml index b1a21513..fb8ae3d2 100644 --- a/applet/contents/ui/Toolbar.qml +++ b/applet/contents/ui/Toolbar.qml @@ -1,131 +1,164 @@ /* Copyright 2013-2017 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ 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.networkmanagement 0.2 as PlasmaNM import org.kde.kquickcontrolsaddons 2.0 -Item { +GridLayout { id: toolbar - height: wifiSwitchButton.height + function closeSearch() { + searchToggleButton.checked = false + } + + rows: 2 + columns: 2 PlasmaCore.Svg { id: lineSvg imagePath: "widgets/line" } PlasmaNM.EnabledConnections { id: enabledConnections onWirelessEnabledChanged: { wifiSwitchButton.checked = wifiSwitchButton.enabled && enabled } onWirelessHwEnabledChanged: { wifiSwitchButton.enabled = enabled && availableDevices.wirelessDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled } onWwanEnabledChanged: { wwanSwitchButton.checked = wwanSwitchButton.enabled && enabled } onWwanHwEnabledChanged: { wwanSwitchButton.enabled = enabled && availableDevices.modemDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled } } Row { - anchors { - bottom: parent.bottom - left: parent.left - top: parent.top - } + Layout.fillWidth: true SwitchButton { id: wifiSwitchButton checked: enabled && enabledConnections.wirelessEnabled enabled: enabledConnections.wirelessHwEnabled && availableDevices.wirelessDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled tooltip: i18n("Enable wireless") icon: enabled ? "network-wireless-on" : "network-wireless-off" visible: availableDevices.wirelessDeviceAvailable onClicked: { handler.enableWireless(checked); } } SwitchButton { id: wwanSwitchButton checked: enabled && enabledConnections.wwanEnabled enabled: enabledConnections.wwanHwEnabled && availableDevices.modemDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled tooltip: i18n("Enable mobile network") icon: enabled ? "network-mobile-on" : "network-mobile-off" visible: availableDevices.modemDeviceAvailable onClicked: { handler.enableWwan(checked); } } SwitchButton { id: planeModeSwitchButton property bool airplaneModeEnabled: false checked: airplaneModeEnabled tooltip: i18n("Enable airplane mode") icon: airplaneModeEnabled ? "network-flightmode-on" : "network-flightmode-off" onClicked: { handler.enableAirplaneMode(checked); airplaneModeEnabled = !airplaneModeEnabled; } Binding { target: connectionIconProvider property: "airplaneMode" value: planeModeSwitchButton.airplaneModeEnabled } } } - PlasmaComponents.ToolButton { - id: openEditorButton + Row { + Layout.column: 1 + + PlasmaComponents.ToolButton { + id: searchToggleButton + iconSource: "search" + tooltip: i18ndc("plasma-nm", "button tooltip", "Search the connections") + checkable: true + } + + PlasmaComponents.ToolButton { + id: openEditorButton + iconSource: "configure" + tooltip: i18n("Configure network connections...") + visible: mainWindow.kcmAuthorized - anchors { - right: parent.right - rightMargin: Math.round(units.gridUnit / 2) - verticalCenter: parent.verticalCenter + onClicked: { + KCMShell.open(mainWindow.kcm) + } } + } + + PlasmaComponents.TextField { + id: searchTextField - iconSource: "configure" - tooltip: i18n("Configure network connections...") - visible: mainWindow.kcmAuthorized + Layout.row: 1 + Layout.columnSpan: 2 + Layout.fillWidth: true + Layout.leftMargin: units.smallSpacing + Layout.rightMargin: units.smallSpacing + Layout.bottomMargin: units.smallSpacing - onClicked: { - KCMShell.open(mainWindow.kcm) + focus: true + clearButtonShown: true + placeholderText: i18ndc("plasma-nm", "text field placeholder text", "Search...") + + visible: searchToggleButton.checked + onVisibleChanged: if (!visible) text = "" + Keys.onEscapePressed: searchToggleButton.checked = false + + onTextChanged: { + // Show search field when starting to type directly + if (text.length && !searchToggleButton.checked) { + searchToggleButton.checked = true + } + appletProxyModel.setFilterRegExp(text) } } } diff --git a/libs/models/appletproxymodel.cpp b/libs/models/appletproxymodel.cpp index 4944b6c8..2b89388a 100644 --- a/libs/models/appletproxymodel.cpp +++ b/libs/models/appletproxymodel.cpp @@ -1,128 +1,133 @@ /* Copyright 2013-2014 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "appletproxymodel.h" #include "networkmodel.h" #include "uiutils.h" AppletProxyModel::AppletProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { setDynamicSortFilter(true); + setFilterCaseSensitivity(Qt::CaseInsensitive); sort(0, Qt::DescendingOrder); } AppletProxyModel::~AppletProxyModel() { } bool AppletProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { 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; } const NetworkManager::ConnectionSettings::ConnectionType type = (NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(index, NetworkModel::TypeRole).toUInt(); if (!UiUtils::isConnectionTypeSupported(type)) { return false; } 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 { const bool leftAvailable = (NetworkModelItem::ItemType)sourceModel()->data(left, NetworkModel::ItemTypeRole).toUInt() != NetworkModelItem::UnavailableConnection; const bool leftConnected = sourceModel()->data(left, NetworkModel::ConnectionStateRole).toUInt() == NetworkManager::ActiveConnection::Activated; const int leftConnectionState = sourceModel()->data(left, NetworkModel::ConnectionStateRole).toUInt(); const QString leftName = sourceModel()->data(left, NetworkModel::NameRole).toString(); const UiUtils::SortedConnectionType leftType = UiUtils::connectionTypeToSortedType((NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(left, NetworkModel::TypeRole).toUInt()); const QString leftUuid = sourceModel()->data(left, NetworkModel::UuidRole).toString(); const int leftSignal = sourceModel()->data(left, NetworkModel::SignalRole).toInt(); const QDateTime leftDate = sourceModel()->data(left, NetworkModel::TimeStampRole).toDateTime(); const bool rightAvailable = (NetworkModelItem::ItemType)sourceModel()->data(right, NetworkModel::ItemTypeRole).toUInt() != NetworkModelItem::UnavailableConnection; const bool rightConnected = sourceModel()->data(right, NetworkModel::ConnectionStateRole).toUInt() == NetworkManager::ActiveConnection::Activated; const int rightConnectionState = sourceModel()->data(right, NetworkModel::ConnectionStateRole).toUInt(); const QString rightName = sourceModel()->data(right, NetworkModel::NameRole).toString(); const UiUtils::SortedConnectionType rightType = UiUtils::connectionTypeToSortedType((NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(right, NetworkModel::TypeRole).toUInt()); const QString rightUuid = sourceModel()->data(right, NetworkModel::UuidRole).toString(); const int rightSignal = sourceModel()->data(right, NetworkModel::SignalRole).toInt(); const QDateTime rightDate = sourceModel()->data(right, NetworkModel::TimeStampRole).toDateTime(); if (leftAvailable < rightAvailable) { return true; } else if (leftAvailable > rightAvailable) { return false; } if (leftConnected < rightConnected) { return true; } else if (leftConnected > rightConnected) { return false; } if (leftConnectionState > rightConnectionState) { return true; } else if (leftConnectionState < rightConnectionState) { return false; } if (leftUuid.isEmpty() && !rightUuid.isEmpty()) { return true; } else if (!leftUuid.isEmpty() && rightUuid.isEmpty()) { return false; } if (leftType < rightType) { return false; } else if (leftType > rightType) { return true; } if (leftDate > rightDate) { return false; } else if (leftDate < rightDate) { return true; } if (leftSignal < rightSignal) { return true; } else if (leftSignal > rightSignal) { return false; } if (QString::localeAwareCompare(leftName, rightName) > 0) { return true; } else { return false; } }