eric6/Preferences/ConfigurationPages/WebBrowserVirusTotalPage.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7196
ab0a91b82b37
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing VirusTotal configuration page (web browser variant).
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13
14 from .ConfigurationPageBase import ConfigurationPageBase
15 from .Ui_HelpVirusTotalPage import Ui_HelpVirusTotalPage
16
17 import Preferences
18
19
20 class WebBrowserVirusTotalPage(ConfigurationPageBase, Ui_HelpVirusTotalPage):
21 """
22 Class implementing VirusTotal configuration page (web browser variant).
23 """
24 def __init__(self):
25 """
26 Constructor
27 """
28 super(WebBrowserVirusTotalPage, self).__init__()
29 self.setupUi(self)
30 self.setObjectName("HelpVirusTotalPage")
31
32 self.testResultLabel.setHidden(True)
33
34 from WebBrowser.VirusTotal.VirusTotalApi import VirusTotalAPI
35 self.__vt = VirusTotalAPI(self)
36 self.__vt.checkServiceKeyFinished.connect(
37 self.__checkServiceKeyFinished)
38
39 # set initial values
40 self.vtEnabledCheckBox.setChecked(
41 Preferences.getHelp("VirusTotalEnabled"))
42 self.vtSecureCheckBox.setChecked(
43 Preferences.getHelp("VirusTotalSecure"))
44 self.vtServiceKeyEdit.setText(
45 Preferences.getHelp("VirusTotalServiceKey"))
46
47 def save(self):
48 """
49 Public slot to save the VirusTotal configuration.
50 """
51 Preferences.setHelp(
52 "VirusTotalEnabled",
53 self.vtEnabledCheckBox.isChecked())
54 Preferences.setHelp(
55 "VirusTotalSecure",
56 self.vtSecureCheckBox.isChecked())
57 Preferences.setHelp(
58 "VirusTotalServiceKey",
59 self.vtServiceKeyEdit.text())
60
61 @pyqtSlot(str)
62 def on_vtServiceKeyEdit_textChanged(self, txt):
63 """
64 Private slot to handle changes of the service key.
65
66 @param txt entered service key (string)
67 """
68 self.testButton.setEnabled(txt != "")
69
70 @pyqtSlot()
71 def on_testButton_clicked(self):
72 """
73 Private slot to test the entered service key.
74 """
75 self.testResultLabel.setHidden(False)
76 self.testResultLabel.setText(
77 self.tr("Checking validity of the service key..."))
78 if self.vtSecureCheckBox.isChecked():
79 protocol = "https"
80 else:
81 protocol = "http"
82 self.__vt.checkServiceKeyValidity(
83 self.vtServiceKeyEdit.text(), protocol)
84
85 @pyqtSlot(bool, str)
86 def __checkServiceKeyFinished(self, result, msg):
87 """
88 Private slot to receive the result of the service key check.
89
90 @param result flag indicating a successful check (boolean)
91 @param msg network error message (str)
92 """
93 if result:
94 self.testResultLabel.setText(
95 self.tr("The service key is valid."))
96 else:
97 if msg == "":
98 self.testResultLabel.setText(self.tr(
99 '<font color="#FF0000">The service key is'
100 ' not valid.</font>'))
101 else:
102 self.testResultLabel.setText(self.tr(
103 '<font color="#FF0000"><b>Error:</b> {0}</font>')
104 .format(msg))
105
106
107 def create(dlg):
108 """
109 Module function to create the configuration page.
110
111 @param dlg reference to the configuration dialog
112 @return reference to the instantiated page (ConfigurationPageBase)
113 """
114 page = WebBrowserVirusTotalPage()
115 return page

eric ide

mercurial