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 |
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 |