143 self.trUtf8("Save Time Tracker File"), |
143 self.trUtf8("Save Time Tracker File"), |
144 self.trUtf8("""<p>The time tracker file <b>{0}</b> could not be""" |
144 self.trUtf8("""<p>The time tracker file <b>{0}</b> could not be""" |
145 """ saved.</p><p>Reason: {1}</p>""").format( |
145 """ saved.</p><p>Reason: {1}</p>""").format( |
146 self.__trackerFilePath, str(err))) |
146 self.__trackerFilePath, str(err))) |
147 |
147 |
|
148 def importTrackerEntries(self, fname): |
|
149 """ |
|
150 Public slot to import tracker entries from a file. |
|
151 |
|
152 @param fname name of the file to import (string) |
|
153 """ |
|
154 try: |
|
155 f = open(fname, "r", encoding="utf-8") |
|
156 data = f.read() |
|
157 f.close() |
|
158 except (IOError, OSError) as err: |
|
159 E5MessageBox.critical(self.__ui, |
|
160 self.trUtf8("Import Time Tracker File"), |
|
161 self.trUtf8("""<p>The time tracker file <b>{0}</b> could not be""" |
|
162 """ read.</p><p>Reason: {1}</p>""").format( |
|
163 fname, str(err))) |
|
164 return |
|
165 |
|
166 invalidCount = 0 |
|
167 duplicateCount = 0 |
|
168 entries = [] |
|
169 for line in data.splitlines(): |
|
170 entry = TimeTrackEntry(self.__plugin) |
|
171 eid = entry.fromString(line.strip()) |
|
172 if eid > -1: |
|
173 entries.append(entry) |
|
174 else: |
|
175 invalidCount += 1 |
|
176 |
|
177 if not self.__plugin.getPreferences("AllowDuplicates"): |
|
178 startDateTimes = [ |
|
179 entry.getStartDateTime() for entry in self.__entries.values()] |
|
180 for entry in entries[:]: |
|
181 if entry.getStartDateTime() in startDateTimes: |
|
182 entries.remove(entry) |
|
183 duplicateCount += 1 |
|
184 |
|
185 if len(self.__entries.keys()): |
|
186 nextID = max(self.__entries.keys()) + 1 |
|
187 else: |
|
188 nextID = 0 |
|
189 for entry in entries: |
|
190 entry.setID(nextID) |
|
191 self.__entries[nextID] = entry |
|
192 nextID += 1 |
|
193 |
|
194 if invalidCount != 0 or duplicateCount != 0: |
|
195 if invalidCount != 0 and duplicateCount != 0: |
|
196 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
|
197 """ %n invalid entries.""", |
|
198 "", invalidCount).format(fname) |
|
199 msg += " " + self.tr("""%n duplicate entries were detected.""", |
|
200 "", duplicateCount) |
|
201 elif duplicateCount != 0: |
|
202 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
|
203 """ %n duplicate entries.""", |
|
204 "", duplicateCount).format(fname) |
|
205 elif invalidCount != 0: |
|
206 msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" |
|
207 """ %n invalid entries.""", |
|
208 "", invalidCount).format(fname) |
|
209 msg += " " + self.tr("""These have been ignored.""") |
|
210 E5MessageBox.information(self.__ui, |
|
211 self.trUtf8("Import Time Tracker File"), |
|
212 msg) |
|
213 |
148 def pauseTrackerEntry(self): |
214 def pauseTrackerEntry(self): |
149 """ |
215 """ |
150 Public method to pause the current tracker entry. |
216 Public method to pause the current tracker entry. |
151 """ |
217 """ |
152 self.__currentEntry.pause() |
218 self.__currentEntry.pause() |