5 |
5 |
6 """ |
6 """ |
7 Module implementing the time tracker widget. |
7 Module implementing the time tracker widget. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import pyqtSlot, QPoint, Qt, QDate, QTime |
10 from PyQt4.QtCore import pyqtSlot, QPoint, Qt, QDate, QTime, QFileInfo |
11 from PyQt4.QtGui import QWidget, QMenu, QTreeWidgetItem, QCursor |
11 from PyQt4.QtGui import QWidget, QMenu, QTreeWidgetItem, QCursor |
12 |
12 |
13 from E5Gui import E5MessageBox |
13 from E5Gui import E5MessageBox, E5FileDialog |
14 |
14 |
15 from .Ui_TimeTrackerWidget import Ui_TimeTrackerWidget |
15 from .Ui_TimeTrackerWidget import Ui_TimeTrackerWidget |
|
16 |
|
17 import Preferences |
|
18 import Utilities |
16 |
19 |
17 |
20 |
18 class TimeTrackerWidget(QWidget, Ui_TimeTrackerWidget): |
21 class TimeTrackerWidget(QWidget, Ui_TimeTrackerWidget): |
19 """ |
22 """ |
20 Class implementing the time tracker widget. |
23 Class implementing the time tracker widget. |
87 """ |
90 """ |
88 Private slot to end the current timer and start a new one. |
91 Private slot to end the current timer and start a new one. |
89 """ |
92 """ |
90 # stop the current tracker |
93 # stop the current tracker |
91 eid, duration = self.__tracker.stopTrackerEntry() |
94 eid, duration = self.__tracker.stopTrackerEntry() |
92 itm = self.entriesList.topLevelItem(0) |
95 if eid > -1: |
93 itm.setText(self.DurationColumn, self.tr("{0} min").format(duration)) |
96 itm = self.entriesList.topLevelItem(0) |
94 itm.setData(0, Qt.UserRole, eid) |
97 itm.setText(self.DurationColumn, self.tr("{0} min").format(duration)) |
|
98 itm.setData(0, Qt.UserRole, eid) |
|
99 else: |
|
100 itm = self.entriesList.takeTopLevelItem(0) |
|
101 del itm |
95 self.entriesList.resizeColumnToContents(self.CommentColumn) |
102 self.entriesList.resizeColumnToContents(self.CommentColumn) |
96 |
103 |
97 # start a new one |
104 # start a new one |
98 self.__tracker.startTrackerEntry() |
105 self.__tracker.startTrackerEntry() |
99 |
106 |
112 menu.addSeparator() |
119 menu.addSeparator() |
113 menu.addAction(self.tr("Save"), self.__saveEntries) |
120 menu.addAction(self.tr("Save"), self.__saveEntries) |
114 menu.addSeparator() |
121 menu.addSeparator() |
115 menu.addAction(self.tr("Import"), self.__importEntries) |
122 menu.addAction(self.tr("Import"), self.__importEntries) |
116 menu.addAction(self.tr("Export Selected"), self.__exportSelectedEntries) |
123 menu.addAction(self.tr("Export Selected"), self.__exportSelectedEntries) |
117 menu.addAction(self.tr("Export All"), self.__exportAllEntries) |
124 menu.addAction(self.tr("Export All"), self.__exportEntries) |
118 menu.exec_(QCursor.pos()) |
125 menu.exec_(QCursor.pos()) |
119 |
126 |
120 def __editEntry(self): |
127 def __editEntry(self): |
121 """ |
128 """ |
122 Private slot to edit the selected tracker entry. |
129 Private slot to edit the selected tracker entry. |
152 Private slot to import tracker entries. |
159 Private slot to import tracker entries. |
153 """ |
160 """ |
154 # TODO: not implemented yet |
161 # TODO: not implemented yet |
155 raise NotImplementedError |
162 raise NotImplementedError |
156 |
163 |
|
164 def __exportEntries(self, ids=[]): |
|
165 """ |
|
166 Private method to export all or selected entries. |
|
167 |
|
168 @keyparam ids list of IDs to export or all if empty (list of integer) |
|
169 """ |
|
170 path = Preferences.getMultiProject("Workspace") or Utilities.getHomeDir() |
|
171 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
|
172 self, |
|
173 self.trUtf8("Export Tracker Entries"), |
|
174 path, |
|
175 self.tr("Text Files (*.txt);;All Files (*)"), |
|
176 None, |
|
177 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
|
178 if fname: |
|
179 ext = QFileInfo(fname).suffix() |
|
180 if not ext: |
|
181 ex = selectedFilter.split("(*")[1].split(")")[0] |
|
182 if ex: |
|
183 fname += ex |
|
184 if QFileInfo(fname).exists(): |
|
185 res = E5MessageBox.yesNo(self, |
|
186 self.trUtf8("Export Tracker Entries"), |
|
187 self.trUtf8("<p>The file <b>{0}</b> already exists." |
|
188 " Overwrite it?</p>").format(fname), |
|
189 icon=E5MessageBox.Warning) |
|
190 if not res: |
|
191 return |
|
192 fname = Utilities.toNativeSeparators(fname) |
|
193 self.__tracker.saveTrackerEntries(filePath=fname, ids=ids) |
|
194 |
157 def __exportSelectedEntries(self): |
195 def __exportSelectedEntries(self): |
158 """ |
196 """ |
159 Private slot to export the selected tracker entries. |
197 Private slot to export the selected tracker entries. |
160 """ |
198 """ |
161 # TODO: not implemented yet |
199 ids = [] |
162 raise NotImplementedError |
200 for itm in self.entriesList.selectedItems(): |
163 |
201 eid = itm.data(0, Qt.UserRole) |
164 def __exportAllEntries(self): |
202 if eid > -1: |
165 """ |
203 ids.append(eid) |
166 Private slot to export all tracker entries. |
204 |
167 """ |
205 if ids: |
168 # TODO: not implemented yet |
206 self.__exportEntries(ids=ids) |
169 raise NotImplementedError |
|
170 |
207 |
171 def __insertEntry(self, entry, index=-1): |
208 def __insertEntry(self, entry, index=-1): |
172 """ |
209 """ |
173 Private method to insert a tracker entry into the list. |
210 Private method to insert a tracker entry into the list. |
174 |
211 |