diff --git a/applets/clipboard/contents/ui/ClipboardPage.qml b/applets/clipboard/contents/ui/ClipboardPage.qml index 626a89497..c423110c3 100644 --- a/applets/clipboard/contents/ui/ClipboardPage.qml +++ b/applets/clipboard/contents/ui/ClipboardPage.qml @@ -1,126 +1,126 @@ /******************************************************************** This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin Copyright (C) 2014 Kai Uwe Broulik This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.4 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras ColumnLayout { Keys.onPressed: { switch(event.key) { case Qt.Key_Up: { clipboardMenu.view.decrementCurrentIndex(); event.accepted = true; break; } case Qt.Key_Down: { clipboardMenu.view.incrementCurrentIndex(); event.accepted = true; break; } case Qt.Key_Enter: case Qt.Key_Return: { if (clipboardMenu.view.currentIndex >= 0) { var uuid = clipboardMenu.model.get(clipboardMenu.view.currentIndex).UuidRole if (uuid) { clipboardSource.service(uuid, "select") clipboardMenu.view.currentIndex = 0 } } break; } case Qt.Key_Escape: { if (filter.text != "") { filter.text = ""; event.accepted = true; } break; } default: { // forward key to filter // filter.text += event.text wil break if the key is backspace if (event.key == Qt.Key_Backspace && filter.text == "") { return; } if (event.text != "" && !filter.activeFocus) { clipboardMenu.view.currentIndex = -1 if (event.matches(StandardKey.Paste)) { filter.paste(); } else { filter.text = ""; filter.text += event.text; } filter.forceActiveFocus(); event.accepted = true; } } } } PlasmaExtras.Heading { id: emptyHint Layout.fillWidth: true level: 3 opacity: 0.6 visible: clipboardMenu.model.count === 0 && filter.length === 0 text: i18n("Clipboard history is empty.") } RowLayout { Layout.fillWidth: true visible: !emptyHint.visible PlasmaComponents.TextField { id: filter placeholderText: i18n("Search") clearButtonShown: true Layout.fillWidth: true } PlasmaComponents.ToolButton { - iconSource: "edit-delete" + iconSource: "edit-clear-history" tooltip: i18n("Clear history") onClicked: clipboardSource.service("", "clearHistory") } } Menu { id: clipboardMenu model: PlasmaCore.SortFilterModel { sourceModel: clipboardSource.models.clipboard filterRole: "DisplayRole" filterRegExp: filter.text } supportsBarcodes: clipboardSource.data["clipboard"]["supportsBarcodes"] Layout.fillWidth: true Layout.fillHeight: true onItemSelected: clipboardSource.service(uuid, "select") onRemove: clipboardSource.service(uuid, "remove") onEdit: clipboardSource.edit(uuid) onBarcode: { var page = stack.push(barcodePage); page.show(uuid); } onAction: { clipboardSource.service(uuid, "action") clipboardMenu.view.currentIndex = 0 } } } diff --git a/applets/notifications/package/contents/ui/Notifications.qml b/applets/notifications/package/contents/ui/Notifications.qml index 2ebf61778..e3f46d78c 100644 --- a/applets/notifications/package/contents/ui/Notifications.qml +++ b/applets/notifications/package/contents/ui/Notifications.qml @@ -1,322 +1,322 @@ /* * Copyright 2012 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program 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 Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.0 import QtQuick.Layouts 1.2 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.private.notifications 1.0 Column { id: notificationsRoot anchors { left: parent.left right: parent.right } property alias count: notificationsRepeater.count readonly property int historyCount: historyList.count property bool showHistory: plasmoid.configuration.showHistory signal popupShown(var popup) onShowHistoryChanged: { if(!showHistory) clearHistory() } Component.onCompleted: { // Create the popup components and pass them to the C++ plugin for (var i = 0; i < 3; i++) { var popup = notificationPopupComponent.createObject(); notificationPositioner.addNotificationPopup(popup); } } function addNotification(notification) { // Do not show duplicated notifications for (var i = 0; i < notificationsModel.count; ++i) { if (notificationsModel.get(i).source == notification.source && notificationsModel.get(i).appName == notification.appName && notificationsModel.get(i).summary == notification.summary && notificationsModel.get(i).body == notification.body) { return } } for (var i = 0; i < notificationsModel.count; ++i) { if (notificationsModel.get(i).source == notification.source || (notificationsModel.get(i).appName == notification.appName && notificationsModel.get(i).summary == notification.summary && notificationsModel.get(i).body == notification.body)) { notificationsModel.remove(i) break } } if (notificationsModel.count > 20) { notificationsModel.remove(notificationsModel.count-1) } if (notification.isPersistent) { notification.created = new Date(); notificationsModel.inserting = true; notificationsModel.insert(0, notification); notificationsModel.inserting = false; } else if (showHistory) { notificationsHistoryModel.inserting = true; //create a copy of the notification. //Disable actions in this copy as they will stop working once the original notification is closed. notificationsHistoryModel.insert(0, { "compact" : notification.compact, "icon" : notification.icon, "image" : notification.image, "summary" : notification.summary, "body" : notification.body, "configurable" : false, "created" : new Date(), "urls" : notification.urls, "maximumTextHeight" : notification.maximumTextHeight, "actions" : null, "hasDefaultAction" : false, "hasConfigureAction" : false, }); notificationsHistoryModel.inserting = false; } notificationPositioner.displayNotification(notification); } function executeAction(source, id) { //try to use the service if (id.indexOf("jobUrl#") === -1) { var service = notificationsSource.serviceForSource(source) var op = service.operationDescription("invokeAction") op["actionId"] = id service.startOperationCall(op) //try to open the id as url } else if (id.indexOf("jobUrl#") !== -1) { Qt.openUrlExternally(id.slice(7)); } notificationPositioner.closePopup(source); } function configureNotification(appRealName, eventId) { var service = notificationsSource.serviceForSource("notification") var op = service.operationDescription("configureNotification") op.appRealName = appRealName op.eventId = eventId service.startOperationCall(op) } function createNotification(data) { var service = notificationsSource.serviceForSource("notification"); var op = service.operationDescription("createNotification"); // add everything from "data" to "op" for (var attrname in data) { op[attrname] = data[attrname]; } service.startOperationCall(op); } function closeNotification(source) { var service = notificationsSource.serviceForSource(source) var op = service.operationDescription("userClosed") service.startOperationCall(op) } function expireNotification(source) { var service = notificationsSource.serviceForSource(source) var op = service.operationDescription("expireNotification") service.startOperationCall(op) } function clearNotifications() { for (var i = 0, length = notificationsSource.sources.length; i < length; ++i) { var source = notificationsSource.sources[i]; closeNotification(source) notificationPositioner.closePopup(source); } notificationsModel.clear() clearHistory() } function clearHistory() { notificationsHistoryModel.clear() } Component { id: notificationPopupComponent NotificationPopup { } } ListModel { id: notificationsModel property bool inserting: false } ListModel { id: notificationsHistoryModel property bool inserting: false } PlasmaCore.DataSource { id: idleTimeSource property bool idle: data["UserActivity"]["IdleTime"] > 300000 engine: "powermanagement" interval: 30000 connectedSources: ["UserActivity"] //Idle with more than 5 minutes of user inactivity } PlasmaCore.DataSource { id: notificationsSource engine: "notifications" interval: 0 onSourceAdded: { connectSource(source); } onSourceRemoved: { notificationPositioner.closePopup(source); for (var i = 0; i < notificationsModel.count; ++i) { if (notificationsModel.get(i).source == source) { notificationsModel.remove(i) break } } } onNewData: { var _data = data; // Temp copy to avoid lots of context switching var actions = [] _data["hasDefaultAction"] = false _data["hasConfigureAction"] = false; if (data["actions"] && data["actions"].length % 2 == 0) { for (var i = 0; i < data["actions"].length; i += 2) { var action = data["actions"][i] if (action == "default") { // The default action is not shown, but we want to know it's there _data["hasDefaultAction"] = true } else if (action == "settings") { // configure icon in the notification for custom notification settings _data["hasConfigureAction"] = true; _data["configurable"] = true; } else { actions.push({ id: data["actions"][i], text: data["actions"][i+1] }) } } } _data["source"] = sourceName _data["actions"] = actions notificationsRoot.addNotification(_data) } } Connections { target: plasmoid.nativeInterface onAvailableScreenRectChanged: { notificationPositioner.setPlasmoidScreenGeometry(availableScreenRect); } } NotificationsHelper { id: notificationPositioner popupLocation: plasmoid.nativeInterface.screenPosition Component.onCompleted: { notificationPositioner.setPlasmoidScreenGeometry(plasmoid.nativeInterface.availableScreenRect); } onPopupShown: notificationsRoot.popupShown(popup) } Repeater { id: notificationsRepeater model: notificationsModel delegate: NotificationDelegate { listModel: notificationsModel } } RowLayout { Layout.fillWidth: true spacing: units.smallSpacing visible: historyCount > 0 width: parent.width PlasmaExtras.Heading { Layout.fillWidth: true level: 3 opacity: 0.6 text: i18n("History") } PlasmaComponents.ToolButton { Layout.rightMargin: spacerSvgFrame.margins.right - iconSource: "edit-delete" + iconSource: "edit-clear-history" tooltip: i18n("Clear History") onClicked: clearHistory() } } // This hack is unfortunately needed to have the buttons align, // the ones in the list contain have a margin due to a frame for being a list item. PlasmaCore.FrameSvgItem { id : spacerSvgFrame imagePath: "widgets/listitem" prefix: "normal" visible: false } // History stuff // The history is shown outside in a ListView Binding { target: historyList property: "model" value: notificationsHistoryModel when: showHistory } Binding { target: historyList property: "delegate" value: notificationsHistoryDelegate when: showHistory } Component { id: notificationsHistoryDelegate NotificationDelegate { listModel: notificationsHistoryModel } } } diff --git a/applets/notifications/package/contents/ui/main.qml b/applets/notifications/package/contents/ui/main.qml index 356034333..ad449df31 100644 --- a/applets/notifications/package/contents/ui/main.qml +++ b/applets/notifications/package/contents/ui/main.qml @@ -1,160 +1,160 @@ /*************************************************************************** * Copyright 2011 Davide Bettio * * Copyright 2011 Marco Martin * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.private.notifications 1.0 import "uiproperties.js" as UiProperties MouseEventListener { id: notificationsApplet //width: units.gridUnit.width * 10 //height: units.gridUnit.width * 15 //Layout.minimumWidth: mainScrollArea.implicitWidth //Layout.minimumHeight: mainScrollArea.implicitHeight Layout.minimumWidth: 256 // FIXME: use above Layout.minimumHeight: 256 LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft LayoutMirroring.childrenInherit: true property int layoutSpacing: UiProperties.layoutSpacing property real globalProgress: 0 property Item notifications: historyList.headerItem ? historyList.headerItem.notifications : null property Item jobs: historyList.headerItem ? historyList.headerItem.jobs : null //notifications + jobs property int activeItemsCount: (notifications ? notifications.count : 0) + (jobs ? jobs.count : 0) property int totalCount: activeItemsCount + (notifications ? notifications.historyCount : 0) Plasmoid.switchWidth: units.gridUnit * 20 Plasmoid.switchHeight: units.gridUnit * 30 Plasmoid.status: activeItemsCount > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus Plasmoid.toolTipSubText: { if (activeItemsCount == 0) { return i18n("No notifications or jobs") } else if (!notifications || !notifications.count) { return i18np("%1 running job", "%1 running jobs", jobs.count) } else if (!jobs || !jobs.count) { return i18np("%1 notification", "%1 notifications", notifications.count) } else { return i18np("%1 running job", "%1 running jobs", jobs.count) + "\n" + i18np("%1 notification", "%1 notifications", notifications.count) } } Plasmoid.compactRepresentation: NotificationIcon { } // Always scroll to the top when opening as that's where the important stuff goes on Plasmoid.onExpandedChanged: { if (Plasmoid.expanded) { // contentY doesn't really work with ListView (creates and destroys delegates on demand and positions them randomly) // so first use its "move to the top" method and then move it further up to reveal all of its "header" contents historyList.positionViewAtBeginning(); historyList.contentY = historyList.originY; } } hoverEnabled: !UiProperties.touchInput onActiveItemsCountChanged: { if (!activeItemsCount) { plasmoid.expanded = false; } } PlasmaExtras.Heading { width: parent.width level: 3 opacity: 0.6 visible: notificationsApplet.totalCount == 0 text: i18n("No new notifications.") } PlasmaExtras.ScrollArea { id: mainScrollArea anchors.fill: parent // HACK The history of notifications can become quite large. In order to avoid a memory leak // show them in a ListView which creates delegate instances only on demand. // The ListView's header functionality is abused to provide the jobs and regular notifications // which are few and might store some state inside the delegate (e.g. expanded state) and // thus are created all at once by a Repeater. ListView { id: historyList // The history stuff is quite entangled with regular notifications, so // model and delegate are set by Bindings {} inside Notifications.qml header: Column { property alias jobs: jobsLoader.item property alias notifications: notificationsLoader.item width: historyList.width Loader { id: jobsLoader width: parent.width source: "Jobs.qml" active: plasmoid.configuration.showJobs } Loader { id: notificationsLoader width: parent.width source: "Notifications.qml" active: plasmoid.configuration.showNotifications } } } } function action_clearNotifications() { notifications.clearNotifications(); notifications.clearHistory(); } function action_notificationskcm() { KCMShell.open("kcmnotify"); } Component.onCompleted: { - plasmoid.setAction("clearNotifications", i18n("Clear Notifications"), "edit-clear") + plasmoid.setAction("clearNotifications", i18n("Clear Notifications"), "edit-clear-history") var clearAction = plasmoid.action("clearNotifications"); clearAction.visible = Qt.binding(function() { return notificationsApplet.notifications && (notificationsApplet.notifications.count > 0 || notificationsApplet.notifications.historyCount > 0); }) if (KCMShell.authorize("kcmnotify.desktop").length > 0) { plasmoid.setAction("notificationskcm", i18n("&Configure Event Notifications and Actions..."), "preferences-desktop-notification") } } }