diff -r 25f7323b308d -r 645506ab3376 TimeTracker/TimeTracker.py --- a/TimeTracker/TimeTracker.py Sun Oct 21 17:17:53 2012 +0200 +++ b/TimeTracker/TimeTracker.py Sun Oct 21 19:23:08 2012 +0200 @@ -118,7 +118,7 @@ E5MessageBox.information(self.__ui, self.trUtf8("Read Time Tracker File"), self.trUtf8("""<p>The time tracker file <b>{0}</b> contained""" - """ %n invalid entries. These have been discarded.""", + """ %n invalid entries. These have been discarded.</p>""", "", invalidCount).format(self.__trackerFilePath)) def saveTrackerEntries(self, filePath="", ids=[]): @@ -201,7 +201,7 @@ msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" """ %n invalid entries.""", "", invalidCount).format(fname) - msg += " " + self.tr("""%n duplicate entries were detected.""", + msg += " " + self.tr(""" %n duplicate entries were detected.""", "", duplicateCount) elif duplicateCount != 0: msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" @@ -211,7 +211,8 @@ msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" """ %n invalid entries.""", "", invalidCount).format(fname) - msg += " " + self.tr("""These have been ignored.""") + msg += " " + self.tr(""" %n entries have been ignored.</p>""", + "", invalidCount + duplicateCount) E5MessageBox.information(self.__ui, self.trUtf8("Import Time Tracker File"), msg) @@ -220,6 +221,41 @@ self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) self.__widget.setCurrentEntry(self.__currentEntry) + def addTrackerEntry(self, startDateTime, duration, task, comment): + """ + Public method to add a new tracker entry based on the given data. + + @param startDateTime start date and time (QDateTime) + @param duration duration in minutes (integer) + @param task task description (string) + @param comment comment (string) + """ + if not self.__plugin.getPreferences("AllowDuplicates"): + startDateTimes = [ + entry.getStartDateTime() for entry in self.__entries.values()] + if startDateTime in startDateTimes: + return + + if duration < self.__plugin.getPreferences("MinimumDuration"): + return + + if len(self.__entries.keys()): + nextID = max(self.__entries.keys()) + 1 + else: + nextID = 0 + + entry = TimeTrackEntry(self.__plugin) + entry.setID(nextID) + entry.setStartDateTime(startDateTime) + entry.setDuration(duration) + entry.setTask(task) + entry.setComment(comment) + self.__entries[nextID] = entry + + self.__widget.clear() + self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) + self.__widget.setCurrentEntry(self.__currentEntry) + def pauseTrackerEntry(self): """ Public method to pause the current tracker entry. @@ -357,3 +393,12 @@ """ if self.__plugin.getPreferences("AutoSave"): self.saveTrackerEntries() + + def getPreferences(self, key): + """ + Public method to retrieve the various settings. + + @param key the key of the value to get + @return the requested setting + """ + return self.__plugin.getPreferences(key)