WebBrowser/Download/DownloadManager.py

changeset 5928
a3809f75ca07
parent 5829
d3448873ced3
child 6048
82ad8ec9548c
equal deleted inserted replaced
5927:a865eaac5b16 5928:a3809f75ca07
52 52
53 self.__iconProvider = None 53 self.__iconProvider = None
54 self.__downloads = [] 54 self.__downloads = []
55 self.__downloadDirectory = "" 55 self.__downloadDirectory = ""
56 self.__loaded = False 56 self.__loaded = False
57
58 self.__rowHeightMultiplier = 1.1
57 59
58 self.setDownloadDirectory(Preferences.getUI("DownloadPath")) 60 self.setDownloadDirectory(Preferences.getUI("DownloadPath"))
59 61
60 self.downloadsView.setShowGrid(False) 62 self.downloadsView.setShowGrid(False)
61 self.downloadsView.verticalHeader().hide() 63 self.downloadsView.verticalHeader().hide()
201 self.show() 203 self.show()
202 204
203 self.activateWindow() 205 self.activateWindow()
204 self.raise_() 206 self.raise_()
205 207
206 def __addItem(self, itm): 208 def __addItem(self, itm, append=False):
207 """ 209 """
208 Private method to add a download to the list of downloads. 210 Private method to add a download to the list of downloads.
209 211
210 @param itm reference to the download item (DownloadItem) 212 @param itm reference to the download item
213 @type DownloadItem
214 @param append flag indicating to append the item
215 @type bool
211 """ 216 """
212 itm.statusChanged.connect(self.__updateRow) 217 itm.statusChanged.connect(self.__updateRow)
213 itm.downloadFinished.connect(self.__finished) 218 itm.downloadFinished.connect(self.__finished)
214 219
215 row = len(self.__downloads) 220 # insert at top of window
221 if append:
222 row = len(self.__downloads)
223 else:
224 row = 0
216 self.__model.beginInsertRows(QModelIndex(), row, row) 225 self.__model.beginInsertRows(QModelIndex(), row, row)
217 self.__downloads.append(itm) 226 if append:
227 self.__downloads.append(itm)
228 else:
229 self.__downloads.insert(0, itm)
218 self.__model.endInsertRows() 230 self.__model.endInsertRows()
219 231
220 self.downloadsView.setIndexWidget(self.__model.index(row, 0), itm) 232 self.downloadsView.setIndexWidget(self.__model.index(row, 0), itm)
221 icon = self.style().standardIcon(QStyle.SP_FileIcon) 233 icon = self.style().standardIcon(QStyle.SP_FileIcon)
222 itm.setIcon(icon) 234 itm.setIcon(icon)
223 self.downloadsView.setRowHeight(row, itm.sizeHint().height() * 1.5) 235 self.downloadsView.setRowHeight(
236 row, itm.sizeHint().height() * self.__rowHeightMultiplier)
224 # just in case the download finished before the constructor returned 237 # just in case the download finished before the constructor returned
225 self.__updateRow(itm) 238 self.__updateRow(itm)
226 self.changeOccurred() 239 self.changeOccurred()
227 self.__updateActiveItemCount() 240 self.__updateActiveItemCount()
228 241
246 icon = self.__iconProvider.icon(QFileInfo(itm.fileName())) 259 icon = self.__iconProvider.icon(QFileInfo(itm.fileName()))
247 if icon.isNull(): 260 if icon.isNull():
248 icon = self.style().standardIcon(QStyle.SP_FileIcon) 261 icon = self.style().standardIcon(QStyle.SP_FileIcon)
249 itm.setIcon(icon) 262 itm.setIcon(icon)
250 263
251 oldHeight = self.downloadsView.rowHeight(row)
252 self.downloadsView.setRowHeight( 264 self.downloadsView.setRowHeight(
253 row, 265 row,
254 max(oldHeight, itm.minimumSizeHint().height() * 1.5)) 266 itm.minimumSizeHint().height() * self.__rowHeightMultiplier)
255 267
256 remove = False 268 remove = False
257 269
258 if itm.downloadedSuccessfully() and \ 270 if itm.downloadedSuccessfully() and \
259 self.removePolicy() == DownloadManager.RemoveSuccessFullDownload: 271 self.removePolicy() == DownloadManager.RemoveSuccessFullDownload:
332 if not download[0].isEmpty() and \ 344 if not download[0].isEmpty() and \
333 download[1] != "": 345 download[1] != "":
334 from .DownloadItem import DownloadItem 346 from .DownloadItem import DownloadItem
335 itm = DownloadItem(parent=self) 347 itm = DownloadItem(parent=self)
336 itm.setData(download) 348 itm.setData(download)
337 self.__addItem(itm) 349 self.__addItem(itm, append=True)
338 self.cleanupButton.setEnabled( 350 self.cleanupButton.setEnabled(
339 (len(self.__downloads) - self.activeDownloads()) > 0) 351 (len(self.__downloads) - self.activeDownloads()) > 0)
340 352
341 self.__loaded = True 353 self.__loaded = True
342 self.__updateActiveItemCount() 354 self.__updateActiveItemCount()

eric ide

mercurial