-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPostnlApp.qml
145 lines (121 loc) · 4.03 KB
/
PostnlApp.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import QtQuick 2.1
import qb.components 1.0
import qb.base 1.0
import FileIO 1.0
App {
id: postnlApp
property url tileUrl : "PostnlTile.qml";
property url thumbnailIcon: "qrc:/tsc/postnl.png";
property url postnlScreenUrl : "PostnlScreen.qml"
property url postnlConfigurationScreenUrl : "PostnlConfigurationScreen.qml"
property url trayUrl : "PostnlTray.qml";
property PostnlConfigurationScreen postnlConfigurationScreen
property PostnlScreen postnlScreen
property string timeStr
property string dateStr
property bool enableSystray
property bool enableUseCustomParcelName : false
property string postnlUserid
property string postnlPassword
property int postnlUpdateFrequencyInMinutes : 120
property int postnlShowHistoryInMonths : 1
property string tileBarcode : "even geduld a.u.b"
property string tileSender
property string tileDate
property string tileTime
property string tileParcelName
// user settings from config file
FileIO {
id: postnlSettingsFile
source: "file:///mnt/data/tsc/postnl.userSettings.json"
}
Component.onCompleted: {
// read user settings
try {
var postnlSettingsJson = JSON.parse(postnlSettingsFile.read());
if (postnlSettingsJson['TrayIcon'] == "Yes") {
enableSystray = true
} else {
enableSystray = false
}
if (postnlSettingsJson['UseCustomParcelName']) {
if (postnlSettingsJson['UseCustomParcelName'] == "Yes") {
enableUseCustomParcelName = true
} else {
enableUseCustomParcelName = false
}
}
postnlUserid = postnlSettingsJson['Userid'];
postnlPassword = postnlSettingsJson['Password'];
if (postnlSettingsJson['UpdateFrequencyInMinutes']) postnlUpdateFrequencyInMinutes = postnlSettingsJson['UpdateFrequencyInMinutes'];
if (postnlSettingsJson['ShowHistoryInMonths']) postnlShowHistoryInMonths = postnlSettingsJson['ShowHistoryInMonths'];
} catch(e) {
}
postnlDataRefreshTimer.start();
postnlTimer.start();
}
// Postnl signals, used to update the listview and filter enabled button
signal postnlUpdated()
function init() {
registry.registerWidget("tile", tileUrl, this, null, {thumbLabel: qsTr("PostNL"), thumbIcon: thumbnailIcon, thumbCategory: "general", thumbWeight: 30, baseTileWeight: 10, thumbIconVAlignment: "center"});
registry.registerWidget("screen", postnlScreenUrl, this, "postnlScreen");
registry.registerWidget("screen", postnlConfigurationScreenUrl, this, "postnlConfigurationScreen");
registry.registerWidget("systrayIcon", trayUrl, this, "postnlTray");
}
function saveSettings() {
// save user settings
var tmpTrayIcon = "";
if (enableSystray == true) {
tmpTrayIcon = "Yes";
} else {
tmpTrayIcon = "No";
}
var tmpCustomParcelName = "";
if (enableUseCustomParcelName) {
tmpCustomParcelName = "Yes";
} else {
tmpCustomParcelName = "No";
}
var tmpUserSettingsJson = {
"Userid" : postnlUserid,
"TrayIcon" : tmpTrayIcon,
"Password" : postnlPassword,
"UpdateFrequencyInMinutes" : postnlUpdateFrequencyInMinutes,
"ShowHistoryInMonths" : postnlShowHistoryInMonths,
"UseCustomParcelName": tmpCustomParcelName
}
var doc3 = new XMLHttpRequest();
doc3.open("PUT", "file:///mnt/data/tsc/postnl.userSettings.json");
doc3.send(JSON.stringify(tmpUserSettingsJson ));
postnlDataRefreshTimer.stop();
postnlDataRefreshTimer.interval = 1000;
postnlDataRefreshTimer.start();
postnlTimer.stop();
postnlTimer.interval = 120000;
postnlTimer.start();
}
Timer {
id: postnlTimer
interval: 180000 // first update after 3 minutes
triggeredOnStart: false
running: false
repeat: true
onTriggered: {
interval = postnlUpdateFrequencyInMinutes * 60000;
postnlScreen.refreshScreen();
}
}
Timer {
id: postnlDataRefreshTimer
interval: 60000 // first update after 1 minutes
triggeredOnStart: false
running: false
repeat: true
onTriggered: { // request tsc script to retrieve postnl inbox
interval = postnlUpdateFrequencyInMinutes * 60000;
var doc4 = new XMLHttpRequest();
doc4.open("PUT", "file:///tmp/tsc.command");
doc4.send("postnl");
}
}
}