1
# -*- coding: utf-8 -*-
2
# Copyright (c) 2009 - Luca Invernizzi <invernizzi.l@gmail.com>
4
# This program is free software: you can redistribute it and/or modify it under
5
# the terms of the GNU General Public License as published by the Free Software
6
# Foundation, either version 3 of the License, or (at your option) any later
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
# You should have received a copy of the GNU General Public License along with
15
# this program. If not, see <http://www.gnu.org/licenses/>.
20
from GTG.plugins.evolution_sync.genericTask import GenericTask
23
class EvolutionTask(GenericTask):
25
def __init__(self, evo_task, evolution_proxy):
26
super(EvolutionTask, self).__init__(evolution_proxy)
27
self._evo_task = evo_task
30
return self._evo_task.get_summary()
32
def _set_title(self, title):
33
self._evo_task.set_summary(title)
34
self.get_proxy().update_task(self)
37
return self._evo_task.get_uid()
40
#We could use Evolution's "Categories" as tags
41
raise NotImplementedError()
43
def _set_tags(self, tags):
44
raise NotImplementedError()
45
self.get_proxy().update_task(self)
48
desc = self._evo_task.get_description()
53
def _set_text(self, text):
54
self._evo_task.set_description(text)
55
self.get_proxy().update_task(self)
57
def _set_status(self, status):
58
#Since Evolution's statuses are fare more than GTG's,
59
# we need to check that the current status is not one of the various
60
# statuses translated in the same gtg status, passed by argument.
61
# This way, we avoid to force a status change when it's not needed
63
current_status_in_gtg_terms = self.get_proxy()._evo_to_gtg_status[\
64
self._evo_task.get_status()]
65
if current_status_in_gtg_terms != status:
66
new_evo_status = self.get_proxy()._gtg_to_evo_status[status]
67
self._evo_task.set_status(new_evo_status)
68
self.get_proxy().update_task(self)
70
def _get_status(self):
71
status = self._evo_task.get_status()
72
return self.get_proxy()._evo_to_gtg_status[status]
74
def _get_due_date(self):
75
due = self._evo_task.get_due()
76
if isinstance(due, (int, float)):
77
return self.__time_evo_to_date(due)
79
def _set_due_date(self, due):
81
#TODO: I haven't find a way to reset the due date
82
# We could copy the task, but that would lose all the attributes
83
# currently not supported by the library used (and they're a lot)
86
self._evo_task.set_due(self.__time_date_to_evo(due))
87
self.get_proxy().update_task(self)
89
def _get_modified(self):
90
return self.__time_evo_to_datetime(self._evo_task.get_modified())
92
def __time_evo_to_date(self, timestamp):
93
return datetime.datetime.fromtimestamp(timestamp + time.timezone).date()
95
def __time_evo_to_datetime(self, timestamp):
96
return datetime.datetime.fromtimestamp(timestamp)
98
def __time_datetime_to_evo(self, timeobject):
99
return int(time.mktime(timeobject.timetuple()))
101
def __time_date_to_evo(self, timeobject):
102
#NOTE: need to substract the timezone to avoid the "one day before bug
103
# (at the airport => no internet now, need to fill bug number in)
104
#Explanation: gtg date format is converted to datetime in date/00:00 in
105
# local time, and time.mktime considers that when converting to UNIX
106
# time. Evolution, however, doesn't convert back to local time.
107
return self.__time_datetime_to_evo(timeobject) - time.timezone
109
def get_evolution_task(self):
110
return self._evo_task