116 |
116 |
117 if invalidCount: |
117 if invalidCount: |
118 E5MessageBox.information(self.__ui, |
118 E5MessageBox.information(self.__ui, |
119 self.trUtf8("Read Time Tracker File"), |
119 self.trUtf8("Read Time Tracker File"), |
120 self.trUtf8("""<p>The time tracker file <b>{0}</b> contained""" |
120 self.trUtf8("""<p>The time tracker file <b>{0}</b> contained""" |
121 """ %n invalid entries. These have been discarded.""", |
121 """ %n invalid entries. These have been discarded.</p>""", |
122 "", invalidCount).format(self.__trackerFilePath)) |
122 "", invalidCount).format(self.__trackerFilePath)) |
123 |
123 |
124 def saveTrackerEntries(self, filePath="", ids=[]): |
124 def saveTrackerEntries(self, filePath="", ids=[]): |
125 """ |
125 """ |
126 Public slot to save the tracker entries to a file. |
126 Public slot to save the tracker entries to a file. |
199 if invalidCount != 0 or duplicateCount != 0: |
199 if invalidCount != 0 or duplicateCount != 0: |
200 if invalidCount != 0 and duplicateCount != 0: |
200 if invalidCount != 0 and duplicateCount != 0: |
201 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
201 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
202 """ %n invalid entries.""", |
202 """ %n invalid entries.""", |
203 "", invalidCount).format(fname) |
203 "", invalidCount).format(fname) |
204 msg += " " + self.tr("""%n duplicate entries were detected.""", |
204 msg += " " + self.tr(""" %n duplicate entries were detected.""", |
205 "", duplicateCount) |
205 "", duplicateCount) |
206 elif duplicateCount != 0: |
206 elif duplicateCount != 0: |
207 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
207 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
208 """ %n duplicate entries.""", |
208 """ %n duplicate entries.""", |
209 "", duplicateCount).format(fname) |
209 "", duplicateCount).format(fname) |
210 elif invalidCount != 0: |
210 elif invalidCount != 0: |
211 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
211 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
212 """ %n invalid entries.""", |
212 """ %n invalid entries.""", |
213 "", invalidCount).format(fname) |
213 "", invalidCount).format(fname) |
214 msg += " " + self.tr("""These have been ignored.""") |
214 msg += " " + self.tr(""" %n entries have been ignored.</p>""", |
|
215 "", invalidCount + duplicateCount) |
215 E5MessageBox.information(self.__ui, |
216 E5MessageBox.information(self.__ui, |
216 self.trUtf8("Import Time Tracker File"), |
217 self.trUtf8("Import Time Tracker File"), |
217 msg) |
218 msg) |
|
219 |
|
220 self.__widget.clear() |
|
221 self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) |
|
222 self.__widget.setCurrentEntry(self.__currentEntry) |
|
223 |
|
224 def addTrackerEntry(self, startDateTime, duration, task, comment): |
|
225 """ |
|
226 Public method to add a new tracker entry based on the given data. |
|
227 |
|
228 @param startDateTime start date and time (QDateTime) |
|
229 @param duration duration in minutes (integer) |
|
230 @param task task description (string) |
|
231 @param comment comment (string) |
|
232 """ |
|
233 if not self.__plugin.getPreferences("AllowDuplicates"): |
|
234 startDateTimes = [ |
|
235 entry.getStartDateTime() for entry in self.__entries.values()] |
|
236 if startDateTime in startDateTimes: |
|
237 return |
|
238 |
|
239 if duration < self.__plugin.getPreferences("MinimumDuration"): |
|
240 return |
|
241 |
|
242 if len(self.__entries.keys()): |
|
243 nextID = max(self.__entries.keys()) + 1 |
|
244 else: |
|
245 nextID = 0 |
|
246 |
|
247 entry = TimeTrackEntry(self.__plugin) |
|
248 entry.setID(nextID) |
|
249 entry.setStartDateTime(startDateTime) |
|
250 entry.setDuration(duration) |
|
251 entry.setTask(task) |
|
252 entry.setComment(comment) |
|
253 self.__entries[nextID] = entry |
218 |
254 |
219 self.__widget.clear() |
255 self.__widget.clear() |
220 self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) |
256 self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) |
221 self.__widget.setCurrentEntry(self.__currentEntry) |
257 self.__widget.setCurrentEntry(self.__currentEntry) |
222 |
258 |