src/eric7/WebBrowser/Download/DownloadManager.py

branch
eric7
changeset 10485
287a3ae95e00
parent 10475
ee41fab001f2
child 11090
f5f5f5803935
equal deleted inserted replaced
10484:ad7a6d699a0d 10485:287a3ae95e00
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the download manager class. 7 Module implementing the download manager class.
8 """ 8 """
9
10 import enum
9 11
10 from PyQt6.QtCore import ( 12 from PyQt6.QtCore import (
11 QBasicTimer, 13 QBasicTimer,
12 QFileInfo, 14 QFileInfo,
13 QModelIndex, 15 QModelIndex,
31 from .DownloadModel import DownloadModel 33 from .DownloadModel import DownloadModel
32 from .DownloadUtilities import speedString, timeString 34 from .DownloadUtilities import speedString, timeString
33 from .Ui_DownloadManager import Ui_DownloadManager 35 from .Ui_DownloadManager import Ui_DownloadManager
34 36
35 37
38 class DownloadManagerRemovePolicy(enum.Enum):
39 """
40 Class defining the remove policies.
41 """
42
43 Never = 0
44 Exit = 1
45 SuccessfullDownload = 2
46
47
48 DownloadManagerDefaultRemovePolicy = DownloadManagerRemovePolicy.Never
49
50
36 class DownloadManager(QDialog, Ui_DownloadManager): 51 class DownloadManager(QDialog, Ui_DownloadManager):
37 """ 52 """
38 Class implementing the download manager. 53 Class implementing the download manager.
39 54
40 @signal downloadsCountChanged() emitted to indicate a change of the 55 @signal downloadsCountChanged() emitted to indicate a change of the
41 count of download items 56 count of download items
42 """ 57 """
43
44 # TODO: change this to an enum
45 RemoveNever = 0
46 RemoveExit = 1
47 RemoveSuccessFullDownload = 2
48 58
49 UpdateTimerTimeout = 1000 59 UpdateTimerTimeout = 1000
50 60
51 downloadsCountChanged = pyqtSignal() 61 downloadsCountChanged = pyqtSignal()
52 62
364 374
365 remove = False 375 remove = False
366 376
367 if ( 377 if (
368 itm.downloadedSuccessfully() 378 itm.downloadedSuccessfully()
369 and self.removePolicy() == DownloadManager.RemoveSuccessFullDownload 379 and self.removePolicy() == DownloadManagerRemovePolicy.SuccessfullDownload
370 ): 380 ):
371 remove = True 381 remove = True
372 382
373 if remove: 383 if remove:
374 self.__model.removeRow(row) 384 self.__model.removeRow(row)
383 def removePolicy(self): 393 def removePolicy(self):
384 """ 394 """
385 Public method to get the remove policy. 395 Public method to get the remove policy.
386 396
387 @return remove policy 397 @return remove policy
388 @rtype int 398 @rtype DownloadManagerRemovePolicy
389 """ 399 """
390 return Preferences.getWebBrowser("DownloadManagerRemovePolicy") 400 try:
401 return DownloadManagerRemovePolicy(
402 Preferences.getWebBrowser("DownloadManagerRemovePolicy")
403 )
404 except ValueError:
405 # default value
406 return DownloadManagerDefaultRemovePolicy
391 407
392 def setRemovePolicy(self, policy): 408 def setRemovePolicy(self, policy):
393 """ 409 """
394 Public method to set the remove policy. 410 Public method to set the remove policy.
395 411
396 @param policy policy to be set 412 @param policy remove policy to be set
397 (DownloadManager.RemoveExit, DownloadManager.RemoveNever, 413 @type DownloadManagerRemovePolicy
398 DownloadManager.RemoveSuccessFullDownload) 414 """
399 @type int 415 if policy == self.removePolicy():
400 """ 416 return
401 if policy in ( 417
402 DownloadManager.RemoveExit, 418 Preferences.setWebBrowser("DownloadManagerRemovePolicy", self.policy.value)
403 DownloadManager.RemoveNever,
404 DownloadManager.RemoveSuccessFullDownload,
405 ):
406 if policy == self.removePolicy():
407 return
408
409 Preferences.setWebBrowser("DownloadManagerRemovePolicy", self.policy)
410 419
411 def save(self): 420 def save(self):
412 """ 421 """
413 Public method to save the download settings. 422 Public method to save the download settings.
414 """ 423 """
415 if not self.__loaded: 424 if not self.__loaded:
416 return 425 return
417 426
418 Preferences.setWebBrowser("DownloadManagerSize", self.size()) 427 Preferences.setWebBrowser("DownloadManagerSize", self.size())
419 Preferences.setWebBrowser("DownloadManagerPosition", self.pos()) 428 Preferences.setWebBrowser("DownloadManagerPosition", self.pos())
420 if self.removePolicy() == DownloadManager.RemoveExit: 429 if self.removePolicy() == DownloadManagerRemovePolicy.Exit:
421 return 430 return
422 431
423 if WebBrowserWindow.isPrivate(): 432 if WebBrowserWindow.isPrivate():
424 return 433 return
425 434

eric ide

mercurial