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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
'''
Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
All rights reserved.
Contact: Nokia Corporation (qt-info@nokia.com)
This file is part of the Qt Mobility Components.
$QT_BEGIN_LICENSE:LGPL$
No Commercial Usage
This file contains pre-release code and may not be distributed.
You may use this file in accordance with the terms and conditions
contained in the Technology Preview License Agreement accompanying
this package.
GNU Lesser General Public License Usage
Alternatively, this file may be used under the terms of the GNU Lesser
General Public License version 2.1 as published by the Free Software
Foundation and appearing in the file LICENSE.LGPL included in the
packaging of this file. Please review the following information to
ensure the GNU Lesser General Public License version 2.1 requirements
will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
In addition, as a special exception, Nokia gives you certain additional
rights. These rights are described in the Nokia Qt LGPL Exception
version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
If you have questions regarding the use of this file, please contact
Nokia at qt-info@nokia.com.
'''
import os
import sys
from PySide.QtCore import QObject, Signal, Slot, Property, QUrl, qWarning
from PySide.QtCore import QAbstractItemModel, QDate, QDateTime, QTime
from PySide.QtGui import QApplication
from PySide.QtDeclarative import QDeclarativeView
from QtMobility.Organizer import QOrganizerManager, QOrganizerItemSortOrder
from QtMobility.Organizer import QOrganizerTodo, QOrganizerTodoTime
from QtMobility.Organizer import QOrganizerItemFilter, QOrganizerItemDetailFilter
from QtMobility.Organizer import QOrganizerItemPriority, QOrganizerTodoProgress
from QtMobility.Organizer import QOrganizerItemType
class TodoManager(QObject):
def __init__(self):
QObject.__init__(self)
self.manager = QOrganizerManager("memory")
self._todos = [] # FIXME Use a model instead of a string list as model
self._todo = None # Current todo being edited or created
self.reload()
@Slot()
def reload(self):
self._todos = []
sortOrder = QOrganizerItemSortOrder()
sortOrder.setDetailDefinitionName(QOrganizerTodoTime.DefinitionName,
QOrganizerTodoTime.FieldDueDateTime)
todoFilter = QOrganizerItemFilter()
items = self.manager.items(todoFilter, [sortOrder])
todos = []
for item in items:
if item.type() == QOrganizerItemType.TypeTodo:
todo = QOrganizerTodo(item)
display = todo.startDateTime().toString("yy/MM/dd hh:mm") +\
"-" + todo.dueDateTime().toString("yy/MM/dd hh:mm") +\
"\n" + todo.displayLabel()
todos.append((display, todo))
self._todos = todos
self.todosChanged.emit()
@Slot()
def deleteCurrent(self):
self.manager.removeItem(self._todo.id())
self.reload()
currentTodoChanged = Signal()
@Slot()
def editNewTodo(self):
"""Sets the current todo to a newly created todo"""
newTodo = QOrganizerTodo()
newTodo.setPriority(QOrganizerItemPriority.HighPriority)
newTodo.setStatus(QOrganizerTodoProgress.StatusNotStarted)
currentDateTime = QDateTime(QDate.currentDate(), QTime.currentTime())
newTodo.setStartDateTime(currentDateTime)
newTodo.setDueDateTime(currentDateTime.addSecs(60*60))
self._todo = newTodo
self._todo.isNewTodo = True
self.currentTodoChanged.emit()
@Property(bool, notify=currentTodoChanged)
def isNewTodo(self):
return self._todo.isNewTodo if self._todo else True
@Slot(int)
def editExistingTodo(self, index):
self._todo = self._todos[index][1]
self._todo.isNewTodo = False
self.currentTodoChanged.emit()
@Slot()
def saveTodo(self):
self.manager.saveItem(self._todo)
self._todo = None
self.reload()
todosChanged = Signal()
@Property("QStringList", notify=todosChanged)
def todos(self):
return [x[0] for x in self._todos]
@todos.setter
def setTodo(self, value):
self._todos = value
self.todosChanged.emit()
# Subject
currentTodoSubjectChanged = Signal()
@Property(str, notify=currentTodoSubjectChanged)
def todoSubject(self):
return self._todo.displayLabel()
@todoSubject.setter
def setTodoSubject(self, value):
self._todo.setDisplayLabel(value)
self.currentTodoSubjectChanged.emit()
# Dates and times
def datetimeToStrList(self, datetime):
date = datetime.date()
time = datetime.time()
return (("%02d "*5) % (date.year(), date.month(), date.day(),
time.hour(), time.minute())).split()
# @Slot(result="QStringList")
@Property("QStringList", notify=currentTodoChanged)
def todoStartDateTime(self):
return self.datetimeToStrList(self._todo.startDateTime())
@Slot(int, int, int)
def setTodoStartDate(self, year, month, day):
orig_time = self._todo.startDateTime().time()
date = QDate(year, month, day)
datetime = QDateTime(date, orig_time)
self._todo.setStartDateTime(datetime)
self.currentTodoChanged.emit()
@Slot(int, int)
def setTodoStartTime(self, hour, minute):
orig_date = self._todo.startDateTime().date()
time = QTime(hour, minute)
datetime = QDateTime(orig_date, time)
self._todo.setStartDateTime(datetime)
self.currentTodoChanged.emit()
@Property("QStringList", notify=currentTodoChanged)
def todoDueDateTime(self):
return self.datetimeToStrList(self._todo.dueDateTime())
@Slot(int, int, int)
def setTodoDueDate(self, year, month, day):
orig_time = self._todo.dueDateTime().time()
date = QDate(year, month, day)
datetime = QDateTime(date, orig_time)
self._todo.setDueDateTime(datetime)
self.currentTodoChanged.emit()
@Slot(int, int)
def setTodoDueTime(self, hour, minute):
orig_date = self._todo.dueDateTime().date()
time = QTime(hour, minute)
datetime = QDateTime(orig_date, time)
self._todo.setDueDateTime(datetime)
self.currentTodoChanged.emit()
# Status
Status = [
QOrganizerTodoProgress.StatusNotStarted,
QOrganizerTodoProgress.StatusInProgress,
QOrganizerTodoProgress.StatusComplete,
]
@Property(int, notify=currentTodoChanged)
def todoStatus(self):
status = self._todo.status()
try:
index = self.Status.index(status)
return index
except ValueError:
return 0
@todoStatus.setter
def setTodoStatus(self, value):
try:
self._todo.setStatus(self.Status[value])
self.currentTodoChanged.emit()
except IndexError:
pass # Fail silently...
# Priority
Priority = [
QOrganizerItemPriority.UnknownPriority,
QOrganizerItemPriority.HighestPriority,
QOrganizerItemPriority.ExtremelyHighPriority,
QOrganizerItemPriority.VeryHighPriority,
QOrganizerItemPriority.HighPriority,
QOrganizerItemPriority.MediumPriority,
QOrganizerItemPriority.LowPriority,
QOrganizerItemPriority.VeryLowPriority,
QOrganizerItemPriority.ExtremelyLowPriority,
QOrganizerItemPriority.LowestPriority,
]
@Property(int, notify=currentTodoChanged)
def todoPriority(self):
priority = self._todo.priority()
try:
index = self.Priority.index(priority)
return index
except ValueError:
return 0
@todoPriority.setter
def setTodoPriority(self, value):
try:
self._todo.setPriority(self.Priority[value])
self.currentTodoChanged.emit()
except IndexError:
pass # Fail silently...
def main():
app = QApplication([])
view = QDeclarativeView()
manager = TodoManager()
context = view.rootContext()
context.setContextProperty("manager", manager)
url = QUrl('main.qml')
view.setSource(url)
if "-no-fs" not in sys.argv:
view.showFullScreen()
else:
view.show()
app.exec_()
if __name__ == '__main__':
main()
|