Helpviewer/Download/DownloadManager.py

changeset 757
d3daf1d8f058
parent 748
eb7e73107d27
child 826
2e3e2055e715
equal deleted inserted replaced
755:e81e1f8d7874 757:d3daf1d8f058
189 Private method to add a download to the list of downloads. 189 Private method to add a download to the list of downloads.
190 190
191 @param itm reference to the download item (DownloadItem) 191 @param itm reference to the download item (DownloadItem)
192 """ 192 """
193 itm.statusChanged.connect(self.__updateRow) 193 itm.statusChanged.connect(self.__updateRow)
194 itm.downloadFinished.connect(self.__finished)
194 195
195 row = len(self.__downloads) 196 row = len(self.__downloads)
196 self.__model.beginInsertRows(QModelIndex(), row, row) 197 self.__model.beginInsertRows(QModelIndex(), row, row)
197 self.__downloads.append(itm) 198 self.__downloads.append(itm)
198 self.__model.endInsertRows() 199 self.__model.endInsertRows()
202 itm.setIcon(icon) 203 itm.setIcon(icon)
203 self.downloadsView.setRowHeight(row, itm.sizeHint().height()) 204 self.downloadsView.setRowHeight(row, itm.sizeHint().height())
204 # just in case the download finished before the constructor returned 205 # just in case the download finished before the constructor returned
205 self.__updateRow(itm) 206 self.__updateRow(itm)
206 self.changeOccurred() 207 self.changeOccurred()
208 self.__updateActiveItemCount()
207 209
208 def __updateRow(self, itm = None): 210 def __updateRow(self, itm = None):
209 """ 211 """
210 Private slot to update a download item. 212 Private slot to update a download item.
211 213
313 self.__addItem(itm) 315 self.__addItem(itm)
314 self.cleanupButton.setEnabled( 316 self.cleanupButton.setEnabled(
315 (len(self.__downloads) - self.activeDownloads()) > 0) 317 (len(self.__downloads) - self.activeDownloads()) > 0)
316 318
317 self.__loaded = True 319 self.__loaded = True
320 self.__updateActiveItemCount()
318 321
319 def cleanup(self): 322 def cleanup(self):
320 """ 323 """
321 Public slot to cleanup the downloads. 324 Public slot to cleanup the downloads.
322 """ 325 """
334 if len(self.__downloads) == 0 and \ 337 if len(self.__downloads) == 0 and \
335 self.__iconProvider is not None: 338 self.__iconProvider is not None:
336 self.__iconProvider = None 339 self.__iconProvider = None
337 340
338 self.changeOccurred() 341 self.changeOccurred()
342 self.__updateActiveItemCount()
339 343
340 def __updateItemCount(self): 344 def __updateItemCount(self):
341 """ 345 """
342 Private method to update the count label. 346 Private method to update the count label.
343 """ 347 """
344 count = len(self.__downloads) 348 count = len(self.__downloads)
345 self.countLabel.setText(self.trUtf8("%n Download(s)", "", count)) 349 self.countLabel.setText(self.trUtf8("%n Download(s)", "", count))
350
351 def __updateActiveItemCount(self):
352 """
353 Private method to update the window title.
354 """
355 count = self.activeDownloads()
356 if count > 0:
357 self.setWindowTitle(self.trUtf8("Downloading %n file(s)", "", count))
358 else:
359 self.setWindowTitle(self.trUtf8("Downloads"))
360
361 def __finished(self):
362 """
363 Private slot to handle a finished download.
364 """
365 self.__updateActiveItemCount()
366 if self.isVisible():
367 QApplication.alert(self)
346 368
347 def setDownloadDirectory(self, directory): 369 def setDownloadDirectory(self, directory):
348 """ 370 """
349 Public method to set the current download directory. 371 Public method to set the current download directory.
350 372

eric ide

mercurial