|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing HelpVirusTotalPage. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 |
|
12 from .ConfigurationPageBase import ConfigurationPageBase |
|
13 from .Ui_HelpVirusTotalPage import Ui_HelpVirusTotalPage |
|
14 |
|
15 from Helpviewer.VirusTotalApi import VirusTotalAPI |
|
16 |
|
17 import Preferences |
|
18 |
|
19 |
|
20 class HelpVirusTotalPage(ConfigurationPageBase, Ui_HelpVirusTotalPage): |
|
21 """ |
|
22 Class documentation goes here. |
|
23 """ |
|
24 def __init__(self, parent = None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 ConfigurationPageBase.__init__(self) |
|
31 self.setupUi(self) |
|
32 self.setObjectName("HelpVirusTotalPage") |
|
33 |
|
34 self.testResultLabel.setHidden(True) |
|
35 |
|
36 # set initial values |
|
37 self.vtEnabledCheckBox.setChecked( |
|
38 Preferences.getHelp("VirusTotalEnabled")) |
|
39 self.vtSecureCheckBox.setChecked( |
|
40 Preferences.getHelp("VirusTotalSecure")) |
|
41 self.vtServiceKeyEdit.setText( |
|
42 Preferences.getHelp("VirusTotalServiceKey")) |
|
43 |
|
44 |
|
45 def save(self): |
|
46 """ |
|
47 Public slot to save the VirusTotal configuration. |
|
48 """ |
|
49 Preferences.setHelp("VirusTotalEnabled", |
|
50 self.vtEnabledCheckBox.isChecked()) |
|
51 Preferences.setHelp("VirusTotalSecure", |
|
52 self.vtSecureCheckBox.isChecked()) |
|
53 Preferences.setHelp("VirusTotalServiceKey", |
|
54 self.vtServiceKeyEdit.text()) |
|
55 |
|
56 @pyqtSlot(str) |
|
57 def on_vtServiceKeyEdit_textChanged(self, txt): |
|
58 """ |
|
59 Private slot to handle changes of the service key. |
|
60 |
|
61 @param txt entered service key (string) |
|
62 """ |
|
63 self.testButton.setEnabled(txt != "") |
|
64 |
|
65 @pyqtSlot() |
|
66 def on_testButton_clicked(self): |
|
67 """ |
|
68 Private slot to test the entered service key. |
|
69 """ |
|
70 self.testResultLabel.setHidden(False) |
|
71 self.testResultLabel.setText( |
|
72 self.trUtf8("Checking validity of the service key...")) |
|
73 vt = VirusTotalAPI(self) |
|
74 if self.vtSecureCheckBox.isChecked(): |
|
75 protocol = "https" |
|
76 else: |
|
77 protocol = "http" |
|
78 result, msg = vt.checkServiceKeyValidity(self.vtServiceKeyEdit.text(), protocol) |
|
79 if result: |
|
80 self.testResultLabel.setText(self.trUtf8("The service key is valid.")) |
|
81 else: |
|
82 if msg == "": |
|
83 self.testResultLabel.setText(self.trUtf8( |
|
84 '<font color="#FF0000">The service key is not valid.</font>')) |
|
85 else: |
|
86 self.testResultLabel.setText(self.trUtf8( |
|
87 '<font color="#FF0000"><b>Error:</b> {0}</font>').format(msg)) |
|
88 |
|
89 |
|
90 def create(dlg): |
|
91 """ |
|
92 Module function to create the configuration page. |
|
93 |
|
94 @param dlg reference to the configuration dialog |
|
95 """ |
|
96 page = HelpVirusTotalPage(dlg) |
|
97 return page |