6
from GTG.core import CoreConfig
8
BUSNAME = CoreConfig.BUSNAME
9
BUSFACE = CoreConfig.BUSINTERFACE
14
Clean up a dict so that it can be transmitted through D-Bus.
15
D-Bus does not have concepts for empty or null arrays or values
16
so these need to be converted into blank values D-Bus accepts.
17
@return: Cleaned up dictionary
19
for k, v in data.items():
20
# Manually specify an arbitrary content type for empty Python arrays
21
# because D-Bus can't handle the type conversion for empty arrays
22
if not v and isinstance(v, list):
23
data[k] = dbus.Array([], "s")
24
# D-Bus has no concept of a null or empty value so we have to convert
25
# None types to something else. I use an empty string because it has
26
# the same behavior as None in a Python conditional expression
32
task111 = dbus.Dictionary(dsanitize({
35
"title": "Make a fake GTG dbus server",
36
"duedate": "2010-10-10",
37
"startdate": "2010-01-01",
39
"tags": ["@gtg", "@gsoc"],
40
"text": "You really should make it",
41
"subtask": ["112","113"],
45
task112 = dbus.Dictionary(dsanitize({
48
"title": "Rest a bit before doing the server",
49
"duedate": "2010-10-10",
50
"startdate": "2010-01-01",
52
"tags": ["@gtg", "@gsoc", "@freetime"],
53
"text": "Take as much time as you need",
58
task113 = dbus.Dictionary(dsanitize({
61
"title": "Find out what a 'server' is",
62
"duedate": "2010-10-10",
63
"startdate": "2010-01-01",
65
"tags": ["@gtg", "@gsoc", "@research"],
66
"text": "Check out wikipedia",
71
def task_to_dict(tid):
80
class DBusTaskWrapper(dbus.service.Object):
82
D-Bus service object that exposes GTG's task store to third-party apps
86
# Attach the object to D-Bus
87
self.bus = dbus.SessionBus()
88
bus_name = dbus.service.BusName(BUSNAME, bus=self.bus)
89
dbus.service.Object.__init__(self, bus_name, BUSFACE)
91
@dbus.service.method(BUSNAME)
92
def get_task(self, tid):
94
Retrieve a specific task by ID and return the data
96
toret = task_to_dict(tid)
99
@dbus.service.method(BUSNAME)
102
Retrieve a list of task data dicts
104
return self.get_tasks_filtered(['all'])
106
@dbus.service.method(BUSNAME, in_signature="as")
107
def get_active_tasks(self, tags):
109
Retrieve a list of task data dicts
111
return self.get_tasks_filtered(['active', 'workable'])
113
@dbus.service.method(BUSNAME, in_signature="as")
114
def get_task_ids_filtered(self, filters):
116
Filters the task list and provides list of remaining ids
117
@param: List of strings for filters to apply. See the
118
filters_bank documentation for a list of stock filters.
121
return ["111","112","113"]
123
@dbus.service.method(BUSNAME, in_signature="as")
124
def get_tasks_filtered(self, filters):
126
Gets a list of tasks for the given filters
127
@param: List of strings for filters to apply. See the
128
filters_bank documentation for a list of stock filters.
129
@return: List of task dicts
131
tasks = self.get_task_ids_filtered(filters)
133
return [self.get_task(id) for id in tasks]
135
return dbus.Array([], "s")
137
@dbus.service.method(BUSNAME)
138
def has_task(self, tid):
140
Returns true if the task id is present in the task backend.
141
Task could be either open or closed, but not deleted.
143
return self.req.has_task(tid)
145
@dbus.service.method(BUSNAME)
146
def delete_task(self, tid):
148
Delete the given task id from the repository.
150
self.req.delete_task(tid)
152
@dbus.service.method(BUSNAME, in_signature="sssssassas")
153
def new_task(self, status, title, duedate, startdate, donedate, tags,
156
Generate a new task object and return the task data as a dict
157
@param status: One of 'Active', 'Dismiss', or 'Done'
158
@param title: String name of the task
159
@param duedate: Date the task is due, such as "2010-05-01".
160
also supports 'now', 'soon', 'later'
161
@param startdate: Date the task will be started
162
@param donedate: Date the task was finished
163
@param tags: List of strings for tags to apply for this task
164
@param text: String description
165
@param subtasks: A list of task ids of tasks to add as children
166
@return: A dictionary with the data of the newly created task
168
nt = self.req.new_task(tags=tags)
171
nt.set_status(status, donedate=dates.strtodate(donedate))
173
nt.set_due_date(dates.strtodate(duedate))
174
nt.set_start_date(dates.strtodate(startdate))
176
return task_to_dict(nt)
178
@dbus.service.method(BUSNAME)
179
def modify_task(self, tid, task_data):
181
Updates the task with ID tid using the provided information
182
in the task_data structure. Note that any fields left blank
183
or undefined in task_data will clear the value in the task,
184
so the best way to update a task is to first retrieve it via
185
get_task(tid), modify entries as desired, and send it back
188
task = self.req.get_task(tid)
189
task.set_status(task_data["status"], donedate=dates.strtodate(task_data["donedate"]))
190
task.set_title(task_data["title"])
191
task.set_due_date(dates.strtodate(task_data["duedate"]))
192
task.set_start_date(dates.strtodate(task_data["startdate"]))
193
task.set_text(task_data["text"])
195
for tag in task_data["tags"]:
197
for sub in task_data["subtask"]:
199
return task_to_dict(task)
201
@dbus.service.method(BUSNAME)
202
def open_task_editor(self, tid):
204
Launches the GUI task editor showing the task with ID tid.
206
This routine returns as soon as the GUI has launched.
208
self.view_manager.open_task(tid)
210
@dbus.service.method(BUSNAME, in_signature="ss")
211
def open_new_task(self, title, description):
213
Launches the GUI task editor with a new task. The task is not
214
guaranteed to exist after the editor is closed, since the user
215
could cancel the editing session.
217
This routine returns as soon as the GUI has launched.
219
nt = self.req.new_task(newtask=True)
221
if description != "":
222
nt.set_text(description)
224
self.view_manager.open_task(uid,thisisnew=True)
226
@dbus.service.method(BUSNAME)
227
def hide_task_browser(self):
229
Causes the main task browser to become invisible. It is still
230
running but there will be no visible indication of this.
232
self.view_manager.hide_browser()
234
@dbus.service.method(BUSNAME)
235
def iconify_task_browser(self):
237
Minimizes the task browser
239
self.view_manager.iconify_browser()
241
@dbus.service.method(BUSNAME)
242
def show_task_browser(self):
244
Shows and unminimizes the task browser and brings it to the
247
self.view_manager.show_browser()
249
@dbus.service.method(BUSNAME)
250
def is_task_browser_visible(self):
252
Returns true if task browser is visible, either minimized or
253
unminimized, with or without active focus.
255
return self.view_manager.is_browser_visible()