~nmu-sscheel/gtg/rework-task-editor

« back to all changes in this revision

Viewing changes to GTG/gtk/dbuswrapper.py

  • Committer: Bertrand Rousseau
  • Date: 2012-05-09 22:33:25 UTC
  • mfrom: (1178 trunk)
  • mto: This revision was merged to the branch mainline in revision 1179.
  • Revision ID: bertrand.rousseau@gmail.com-20120509223325-a53d8nwo0x9g93bc
Merge nimit branch and trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import dbus.glib
23
23
import dbus.service
24
24
 
25
 
from GTG.core        import CoreConfig
26
 
from GTG.tools.dates import Date
27
 
 
 
25
from GTG.core           import CoreConfig
 
26
from GTG.tools.dates    import Date
 
27
from GTG.core.search    import InvalidQuery
 
28
from GTG.core.search    import parse_search_query
28
29
 
29
30
BUSNAME = CoreConfig.BUSNAME
30
31
BUSFACE = CoreConfig.BUSINTERFACE
33
34
def dsanitize(data):
34
35
    """
35
36
    Clean up a dict so that it can be transmitted through D-Bus.
36
 
    D-Bus does not have concepts for empty or null arrays or values 
 
37
    D-Bus does not have concepts for empty or null arrays or values
37
38
    so these need to be converted into blank values D-Bus accepts.
38
39
    @return: Cleaned up dictionary
39
40
    """
55
56
    """
56
57
    Translate a task object into a D-Bus dictionary
57
58
    """
 
59
    if not task:
 
60
        return None
58
61
    return dbus.Dictionary(dsanitize({
59
62
          "id": task.get_id(),
60
63
          "status": task.get_status(),
143
146
            return [self.GetTask(id) for id in tasks]
144
147
        else:
145
148
            return dbus.Array([], "s")
146
 
 
 
149
            
 
150
    @dbus.service.method(BUSNAME, in_signature="s")
 
151
    def SearchTasks(self, query):
 
152
        """
 
153
        Searches the task list
 
154
        """
 
155
        tree = self.req.get_tasks_tree().get_basetree()
 
156
        view = tree.get_viewtree()
 
157
        try:
 
158
            search = parse_search_query(query)
 
159
            view.apply_filter('search', parameters = search)
 
160
            tasks = view.get_all_nodes()
 
161
            if tasks:
 
162
                return [self.GetTask(id) for id in tasks]
 
163
        except InvalidQuery:
 
164
            pass
 
165
        return dbus.Array([], "s")
 
166
    
147
167
    @dbus.service.method(BUSNAME)
148
168
    def HasTask(self, tid):
149
169
        """
193
213
        or undefined in task_data will clear the value in the task,
194
214
        so the best way to update a task is to first retrieve it via
195
215
        get_task(tid), modify entries as desired, and send it back
196
 
        via this function.        
 
216
        via this function.
197
217
        """
198
218
        task = self.req.get_task(tid)
199
 
        task.set_status(task_data["status"], donedate=Date.parse(task_data["donedate"]))
 
219
        task.set_status(task_data["status"],
 
220
                    donedate=Date.parse(task_data["donedate"]))
200
221
        task.set_title(task_data["title"])
201
222
        task.set_due_date(Date.parse(task_data["duedate"]))
202
223
        task.set_start_date(Date.parse(task_data["startdate"]))
216
237
        This routine returns as soon as the GUI has launched.
217
238
        """
218
239
        self.view_manager.open_task(tid)
219
 
        
 
240
 
220
241
    @dbus.service.method(BUSNAME, in_signature="ss")
221
242
    def OpenNewTask(self, title, description):
222
243
        """