-
Notifications
You must be signed in to change notification settings - Fork 17
/
sailfishos-chum-gui.qml
107 lines (93 loc) · 3.2 KB
/
sailfishos-chum-gui.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import QtQuick 2.0
import Sailfish.Silica 1.0
import Nemo.Configuration 1.0
import Nemo.Notifications 1.0
import org.chum 1.0
import "pages"
ApplicationWindow {
property int _updatesCount: 0
readonly property string chumDisplayName: "Chum"
readonly property string configGroup: "/apps/sailfishos-chum-gui/"
function _packageOperationNotification(operation) {
switch (operation) {
case Chum.PackageInstallation:
//: %1 - package name, %2 - package version
//% "%1 %2 installed"
return QT_TRID_NOOP("chum-package-installed")
case Chum.PackageRemove:
//: %1 - package name, %2 - package version
//% "%1 %2 removed"
return QT_TRID_NOOP("chum-package-uninstalled")
case Chum.PackageUpdate:
//: %1 - package name, %2 - package version
//% "%1 %2 updated"
return QT_TRID_NOOP("chum-package-updated")
default:
return null
}
}
initialPage: Component { MainPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
allowedOrientations: defaultAllowedOrientations
ConfigurationValue {
id: updatesNotificationId
key: configGroup + "updates-notification-id"
defaultValue: 0
}
Notification {
function showPopup(title, message, icn) {
replacesId = 0
previewSummary = title
previewBody = message
icon = icn || Qt.application.name
publish()
}
function show(message, icn) {
showPopup("", message, icn)
}
id: notification
appName: chumDisplayName
expireTimeout: 3000
}
Notification {
id: updatesNotification
appName: chumDisplayName
appIcon: Qt.application.name
//% "%n update(s) available"
summary: qsTrId("chum-updates-available", _updatesCount)
}
Connections {
target: Chum
onError: notification.show(errorTxt)
onErrorFatal: {
pageStack.replaceAbove(null,
Qt.resolvedUrl("pages/MessagePage.qml"), {
title: errorTitle,
text: errorTxt
});
}
onRepositoryRefreshed: {
//% "Repository refreshed"
notification.show(qsTrId("chum-repo-refreshed"))
}
onUpdatesCountChanged: {
if (_updatesCount !== Chum.updatesCount) {
_updatesCount = Chum.updatesCount
if (_updatesCount > 0) {
updatesNotification.replacesId = updatesNotificationId.value
updatesNotification.publish()
updatesNotificationId.value = updatesNotification.replacesId
} else {
updatesNotification.close()
updatesNotificationId.value = 0
}
}
}
onPackageOperationFinished: {
var trid = _packageOperationNotification(operation)
if (trid) {
notification.show(qsTrId(trid).arg(name).arg(version))
}
}
}
}