|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to ask for a download action. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtWidgets import QDialog |
|
11 |
|
12 from .Ui_DownloadAskActionDialog import Ui_DownloadAskActionDialog |
|
13 |
|
14 import Preferences |
|
15 |
|
16 |
|
17 class DownloadAskActionDialog(QDialog, Ui_DownloadAskActionDialog): |
|
18 """ |
|
19 Class implementing a dialog to ask for a download action. |
|
20 """ |
|
21 def __init__(self, fileName, mimeType, baseUrl, parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param fileName file name (string) |
|
26 @param mimeType mime type (string) |
|
27 @param baseUrl URL (string) |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super().__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.infoLabel.setText("<b>{0}</b>".format(fileName)) |
|
34 self.typeLabel.setText(mimeType) |
|
35 self.siteLabel.setText(baseUrl) |
|
36 |
|
37 if ( |
|
38 not Preferences.getWebBrowser("VirusTotalEnabled") or |
|
39 Preferences.getWebBrowser("VirusTotalServiceKey") == "" |
|
40 ): |
|
41 self.scanButton.setHidden(True) |
|
42 |
|
43 msh = self.minimumSizeHint() |
|
44 self.resize(max(self.width(), msh.width()), msh.height()) |
|
45 |
|
46 def getAction(self): |
|
47 """ |
|
48 Public method to get the selected action. |
|
49 |
|
50 @return selected action ("save", "open", "scan" or "cancel") |
|
51 """ |
|
52 if self.openButton.isChecked(): |
|
53 return "open" |
|
54 elif self.scanButton.isChecked(): |
|
55 return "scan" |
|
56 elif self.saveButton.isChecked(): |
|
57 return "save" |
|
58 else: |
|
59 # should not happen, but keep it safe |
|
60 return "cancel" |