From a218183fa992c1930277714840555424c0ec174e Mon Sep 17 00:00:00 2001 From: "Vlad G." Date: Sun, 20 Oct 2024 22:58:01 +0300 Subject: [PATCH] Cleaner notifications (#49) * Cleaner notifications * Honor sticky; stale import * Update AppSettingsPage.qml clarifying --- qml/components/HydrogenNotifier.qml | 238 ---------------------------- qml/harbour-hydrogen.qml | 52 +++++- qml/pages/AppSettingsPage.qml | 6 +- 3 files changed, 48 insertions(+), 248 deletions(-) delete mode 100644 qml/components/HydrogenNotifier.qml diff --git a/qml/components/HydrogenNotifier.qml b/qml/components/HydrogenNotifier.qml deleted file mode 100644 index a562930..0000000 --- a/qml/components/HydrogenNotifier.qml +++ /dev/null @@ -1,238 +0,0 @@ -import QtQuick 2.2 // not 2.0, because Instantiator -import QtQml 2.2 // for Instantiator -import Sailfish.Silica 1.0 -import Nemo.Notifications 1.0 - -Item { id: root - /*! ListModel to serve as an input to the factory */ - property alias messages: factory.model - - /*! Emitted when a Notification hsa been published */ - signal messagePublished(string msgid) - - /*! - * Creates and publishes a new notification. - * Convenience function to quickly publish a notification. - */ - function quickNotification( message ) { addNotification( undefined, message, undefined, message, undefined, undefined, false ) } - - /*! - * Creates and publishes a new notification. - * Convenience function to quickly publish a notification. - */ - function quickNumberedNotification( message, count ) { addNotification( undefined, message, undefined, message, count, undefined, false ) } - - - /*! - * Creates and publishes a new notification. - * - * At least the shortMessage parameter should be supplied. - * If uid is specified, it can be used in removeNotification later. - * - * Both "title" parameters default to "Notification" if not specified. - * - * The count parameter will be passed as itemCount property to the Notification - * - * If hold is set, the Notification is not published immediately, and must - * be published later by calling publishNotification() - */ - function addNotification( shortTitle, shortMessage, - title, message, - count, - uid, - hold - ) { - // we can't write to uid, so copy it to a local variable - const msgid = (uid) ? uid : Qt.md5([ Date.now(), Math.random(), title, message, shortTitle, shortMessage, count].join()) - - // wait for the instantiator to create the object, set properties through function - var conn = factory.objectAdded.connect(createNewNotification) - - // add new thing to model, this should trigger creation of a new - // notification. - messages.append({"mid": msgid}) - return msgid - - /* Set properties and optionally publish - * need a named function here so we can disconnect() again. - */ - function createNewNotification(idx, obj) { - console.assert(shortMessage, "Warning: we should have at least a message body") - - obj.summary = (title) ? title : qsTr("Notification") - obj.previewSummary = (shortTitle) ? shortTitle : qsTr("Notification") - - if (message) obj.body = message - if (shortMessage) obj.previewBody = shortMessage - if (count) obj.itemCount = count - // store our id for sending back on notification click - obj.internalId = msgid - - if (!hold) { - obj.publish() - messagePublished(msgid) - } - // disconnect ourselves again. - factory.objectAdded.disconnect(createNewNotification) - } - - } - - /*! Publishes a Notification - * uid is the internal uid from the "messages" model - */ - function publishNotification(uid) { - for (var i = 0; i