mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-04 01:42:44 +00:00
Add support for server-side notifications
This commit is contained in:
parent
357ac89330
commit
60bc90c5fa
14 changed files with 179 additions and 14 deletions
|
@ -18,5 +18,7 @@
|
|||
<file>qml/pages/DetailPage.qml</file>
|
||||
<file>qml/ApiClient.qml</file>
|
||||
<file>qml/qmldir</file>
|
||||
<file>qml/components/NotificationList.qml</file>
|
||||
<file>qml/components/Notification.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
28
qtquick/qml/components/Notification.qml
Normal file
28
qtquick/qml/components/Notification.qml
Normal file
|
@ -0,0 +1,28 @@
|
|||
import QtQuick 2.6
|
||||
import QtQuick.Controls 2.6
|
||||
|
||||
Rectangle {
|
||||
property alias title: titleText.text
|
||||
property alias content: contentText.text
|
||||
color: "black"
|
||||
implicitHeight: column.height
|
||||
implicitWidth: column.width
|
||||
|
||||
Column {
|
||||
id: column
|
||||
width: parent.width
|
||||
|
||||
Text {
|
||||
id: titleText
|
||||
width: parent.width
|
||||
font.pointSize: 24
|
||||
color: "white"
|
||||
}
|
||||
|
||||
Text {
|
||||
id: contentText
|
||||
width: parent.width
|
||||
color: "white"
|
||||
}
|
||||
}
|
||||
}
|
49
qtquick/qml/components/NotificationList.qml
Normal file
49
qtquick/qml/components/NotificationList.qml
Normal file
|
@ -0,0 +1,49 @@
|
|||
import QtQuick 2.6
|
||||
|
||||
Column {
|
||||
id: notifList
|
||||
ListModel {
|
||||
id: notificationModel
|
||||
ListElement {
|
||||
title: "Test notification"
|
||||
text: "Foo bar\n2000"
|
||||
timeout: 10000
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: notificationModel
|
||||
Notification {
|
||||
id: notify
|
||||
title: model.title
|
||||
content: model.text
|
||||
width: notifList.width
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: model.timeout
|
||||
onTriggered: notificationModel.remove(index, 1)
|
||||
}
|
||||
Component.onCompleted: timer.start()
|
||||
}
|
||||
}
|
||||
|
||||
add: Transition {
|
||||
NumberAnimation { targets: ViewTransition.targetItems; properties: "opacity"; from: 0.0; to: 1.0; }
|
||||
}
|
||||
move: Transition {
|
||||
NumberAnimation {
|
||||
targets: ViewTransition.targetItems;
|
||||
properties: "x";
|
||||
}
|
||||
NumberAnimation {
|
||||
targets: ViewTransition.targetItems;
|
||||
properties: "y";
|
||||
}
|
||||
}
|
||||
|
||||
function addNotification(title, text, timeout) {
|
||||
var realTimeout = Number(timeout) >= 0 ? Number(timeout) : 5000
|
||||
notificationModel.append({"title": title, "text": text, "timeout": realTimeout});
|
||||
}
|
||||
}
|
|
@ -53,6 +53,24 @@ ApplicationWindow {
|
|||
Keys.onEscapePressed: pop()
|
||||
}
|
||||
|
||||
NotificationList {
|
||||
id: notifList
|
||||
anchors {
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
width: Math.min(parent.width, 400)
|
||||
height: parent.height
|
||||
|
||||
Connections {
|
||||
target: ApiClient.eventbus
|
||||
onDisplayMessage: {
|
||||
console.log("Displaying message: ", header, ": ", message)
|
||||
notifList.addNotification(header, message, timeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: ApiClient
|
||||
onSetupRequired: { pageStack.replace(Qt.resolvedUrl("pages/setup/ServerSelectPage.qml")); }
|
||||
|
|
|
@ -18,6 +18,8 @@ int main(int argc, char** argv) {
|
|||
app.setOrganizationDomain("nl.netsoj.chris");
|
||||
app.setOrganizationName("Chris Josten");
|
||||
|
||||
qSetMessagePattern("[%{time yyyyMMdd h:mm:ss.zzz} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{if-category}<%{category}> %{endif} %{message}");
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
// Disable Qt nagging about "implicitly defined onFoo properties in connections are deprecated",
|
||||
// as we cannot yet move towards a newer version.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue