-
Notifications
You must be signed in to change notification settings - Fork 92
/
ICalManager.qml
94 lines (80 loc) · 2.32 KB
/
ICalManager.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
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import "../lib"
CalendarManager {
id: icalManager
calendarManagerId: "ical"
ExecUtil { id: executable }
// property var eventsData: { "items": [] }
property var calendarList: [
{
url: "/home/chris/Code/icsjson/basic.ics",
backgroundColor: '#ff0',
isTasklist: false,
}
]
function getCalendar(calendarId) {
for (var i = 0; i < calendarList.length; i++) {
var calendarData = calendarList[i]
if (calendarData.url == calendarId) {
return calendarData
}
}
return null
}
function fetchEvents(calendarData, startTime, endTime, callback) {
logger.debug('ical.fetchEvents', calendarData.url)
var cmd = 'python3 ' + plasmoid.file("", "scripts/icsjson.py")
cmd += ' --url "' + calendarData.url + '"' // TODO proper argument wrapping
cmd += ' query'
cmd += ' ' + startTime.getFullYear() + '-' + (startTime.getMonth()+1) + '-' + startTime.getDate()
cmd += ' ' + endTime.getFullYear() + '-' + (endTime.getMonth()+1) + '-' + endTime.getDate()
executable.exec(cmd, function(cmd, exitCode, exitStatus, stdout, stderr) {
if (exitCode) {
logger.log('ical.stderr', stderr)
return callback(stderr)
}
var data = JSON.parse(stdout)
// console.log(cmd)
// console.log(str)
callback(null, data)
})
}
function fetchCalendar(calendarData) {
icalManager.asyncRequests += 0
fetchEvents(calendarData, dateMin, dateMax, function(err, data) {
parseEventList(calendarData, data.items)
setCalendarData(calendarData.url, data)
icalManager.asyncRequestsDone += 1
})
}
onFetchAllCalendars: {
for (var i = 0; i < calendarList.length; i++) {
var calendarData = calendarList[i]
fetchCalendar(calendarData)
}
}
onCalendarParsing: {
var calendar = getCalendar(calendarId)
parseEventList(calendar, data.items)
}
function parseEvent(calendar, event) {
event.backgroundColor = calendar.backgroundColor
event.canEdit = false
}
function parseEventList(calendar, eventList) {
eventList.forEach(function(event) {
parseEvent(calendar, event)
})
}
// onCalendarFetched: {
// console.log(calendarId, data)
// }
// Component.onCompleted: {
// var startTime = new Date(2017, 07-1, 01)
// var endTime = new Date(2017, 07-1, 31)
// dateMin = startTime
// dateMax = endTime
// fetchAllCalendars()
// }
}