-
Notifications
You must be signed in to change notification settings - Fork 19
/
gui.py
225 lines (170 loc) · 8.46 KB
/
gui.py
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import xbmc
import xbmcgui
import xbmcplugin
import sys
from urllib.parse import parse_qsl
from resources.lib.cron import utils, CronManager, CronJob
class CronGUI:
params = {}
context_url = "%s?%s"
plugin_url = 'RunPlugin(%s?%s)'
commandTypes = ["built-in", "json"]
cron = None
def __init__(self, params):
self.params = params
self.cron = CronManager()
def _createJob(self):
newJob = CronJob()
# get the name, command, expression and notification setting
name = xbmcgui.Dialog().input(heading=utils.getString(30002))
if(not name):
return
else:
newJob.name = name
type = xbmcgui.Dialog().select(utils.getString(30067), [utils.getString(30071), utils.getString(30072)], preselect=0)
if(type == -1):
return
else:
newJob.command_type = self.commandTypes[type]
command = xbmcgui.Dialog().input(heading=utils.getString(30003))
if(not command):
return
else:
newJob.command = command
expression = xbmcgui.Dialog().input(utils.getString(30004), "0 0 * * *")
if(not expression):
return
else:
newJob.expression = expression
if(xbmcgui.Dialog().yesno(utils.getString(30005), utils.getString(30010))):
newJob.show_notification = "true"
else:
newJob.show_notification = "false"
if(xbmcgui.Dialog().yesno(utils.getString(30005), utils.getString(30066))):
newJob.run_if_skipped = "true"
else:
newJob.run_if_skipped = "false"
if(not self.cron.addJob(newJob)):
xbmcgui.Dialog().ok(utils.getString(30000), utils.getString(30073))
def run(self):
command = int(self.params['command'])
window = int(self.params['window'])
if(command == 1):
# we want to create a job
self._createJob()
elif(command == 2):
# delete command
aJob = self.cron.getJob(int(self.params['job']))
confirm = xbmcgui.Dialog().yesno(utils.getString(30007), utils.getString(30009) + " " + aJob.name)
if(confirm):
# delete the job
self.cron.deleteJob(aJob.id)
elif(command == 3):
# update the name
aJob = self.cron.getJob(int(self.params['job']))
tempInput = xbmcgui.Dialog().input(utils.getString(30006) + " " + utils.getString(30002), aJob.name)
if(tempInput):
aJob.name = tempInput
self.cron.addJob(aJob)
elif(command == 4):
# udpate the command
aJob = self.cron.getJob(int(self.params['job']))
tempInput = xbmcgui.Dialog().input(utils.getString(30006) + " " + utils.getString(30003), aJob.command)
if(tempInput):
aJob.command = tempInput
self.cron.addJob(aJob)
elif(command == 5):
# update the expression
aJob = self.cron.getJob(int(self.params['job']))
tempInput = xbmcgui.Dialog().input(utils.getString(30006) + " " + utils.getString(30004), aJob.expression)
if(tempInput):
aJob.expression = tempInput
if(not self.cron.addJob(aJob)):
xbmcgui.Dialog().ok(utils.getString(30000), utils.getString(30073))
elif(command == 6):
# update the notification setting
aJob = self.cron.getJob(int(self.params['job']))
if(xbmcgui.Dialog().yesno(utils.getString(30005), utils.getString(30010))):
aJob.show_notification = "true"
else:
aJob.show_notification = "false"
self.cron.addJob(aJob)
elif(command == 7):
# update the notification setting
aJob = self.cron.getJob(int(self.params['job']))
if(xbmcgui.Dialog().yesno(utils.getString(30005), utils.getString(30066))):
aJob.run_if_skipped = "true"
else:
aJob.run_if_skipped = "false"
self.cron.addJob(aJob)
elif(command == 8):
aJob = self.cron.getJob(int(self.params['job']))
# update the command type
type = xbmcgui.Dialog().select(utils.getString(
30067), ["Built-In Function", "JSON Command"], preselect=self.commandTypes.index(aJob.command_type))
if(type >= 0):
aJob.command_type = self.commandTypes[type]
self.cron.addJob(aJob)
if(command != 0):
# always refresh after command
xbmc.executebuiltin('Container.Refresh')
show_all = utils.getSetting('show_all') == 'true'
jobs = self.cron.getJobs(show_all)
if(window == 0):
# create the default window
addItem = xbmcgui.ListItem(utils.getString(30001))
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=1&window=0'), listitem=addItem, isFolder=False)
for j in jobs:
# list each job
cronItem = xbmcgui.ListItem(j.name + " - " + utils.getString(30011) + ": " + self.cron.nextRun(j))
cronItem.addContextMenuItems([(utils.getString(30008), self.plugin_url % (sys.argv[0], 'command=0&window=1&job=' + str(
j.id))), (utils.getString(30007), self.plugin_url % (sys.argv[0], 'command=2&window=0&job=' + str(j.id)))])
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=0&window=1&job=' + str(j.id)), listitem=cronItem, isFolder=True)
elif(window == 1):
# list the details of this job
aJob = self.cron.getJob(int(self.params['job']))
name = xbmcgui.ListItem(utils.getString(30002) + ": " + aJob.name)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=3&window=1&job=' + str(aJob.id)), listitem=name, isFolder=False)
type = xbmcgui.ListItem(utils.getString(30067) + ": " + aJob.getType())
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=8&window=1&job=' + str(aJob.id)), listitem=type, isFolder=False)
command = xbmcgui.ListItem(aJob.getType() + ": " + aJob.command)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=4&window=1&job=' + str(aJob.id)), listitem=command, isFolder=False)
expression = xbmcgui.ListItem(utils.getString(30004) + ": " + aJob.expression)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=5&window=1&job=' + str(aJob.id)), listitem=expression, isFolder=False)
showNotification = 'No'
if(aJob.show_notification == 'true'):
showNotification = 'Yes'
notification = xbmcgui.ListItem(utils.getString(30005) + ": " + showNotification)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=6&window=1&job=' + str(aJob.id)), listitem=notification, isFolder=False)
runSkippedStatus = 'No'
if(aJob.run_if_skipped == 'true'):
runSkippedStatus = 'Yes'
runIfSkipped = xbmcgui.ListItem(utils.getString(30066) + ": " + runSkippedStatus)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=self.context_url % (
sys.argv[0], 'command=7&window=1&job=' + str(aJob.id)), listitem=runIfSkipped, isFolder=False)
xbmcplugin.endOfDirectory(int(sys.argv[1]), cacheToDisc=False)
# helper function to the get the incoming params
def get_params():
param = {}
try:
for i in sys.argv:
args = i
if(args.startswith('?')):
args = args[1:]
param.update(dict(parse_qsl(args)))
except ValueError:
pass
return param
params = get_params()
if('window' not in params):
params['window'] = 0
if('command' not in params):
params['command'] = 0
CronGUI(params).run()