Refined the VirusTotal code.

Mon, 11 Apr 2011 20:06:15 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 11 Apr 2011 20:06:15 +0200
changeset 979
0ae0c8852d31
parent 978
11f8adbcac97
child 981
8217c9d312c3

Refined the VirusTotal code.

APIs/Python3/eric5.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.Helpviewer.HelpWindow.html file | annotate | diff | comparison | revisions
Documentation/Source/eric5.Helpviewer.VirusTotalApi.html file | annotate | diff | comparison | revisions
Documentation/Source/eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html file | annotate | diff | comparison | revisions
Helpviewer/HelpWindow.py file | annotate | diff | comparison | revisions
Helpviewer/VirusTotalApi.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/HelpVirusTotalPage.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric5.api	Sun Apr 10 18:33:20 2011 +0200
+++ b/APIs/Python3/eric5.api	Mon Apr 11 20:06:15 2011 +0200
@@ -2452,11 +2452,14 @@
 eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.ServiceResult_ItemPresent?7
 eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.ServiceResult_RequestLimitReached?7
 eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.TestServiceKeyScanID?7
+eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.checkServiceKeyFinished?7
 eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.checkServiceKeyValidity?4(key, protocol="")
-eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.getFileScanReportUrl?4(scanId)
+eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.fileScanReport?7
 eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.getSearchRequestData?4(term)
-eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.getUrlScanReportUrl?4(scanId)
+eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.preferencesChanged?4()
 eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.submitUrl?4(url)
+eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.submitUrlError?7
+eric5.Helpviewer.VirusTotalApi.VirusTotalAPI.urlScanReport?7
 eric5.Helpviewer.VirusTotalApi.VirusTotalAPI?1(parent=None)
 eric5.IconEditor.IconEditorGrid.IconEditCommand.redo?4()
 eric5.IconEditor.IconEditorGrid.IconEditCommand.setAfterImage?4(image)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sun Apr 10 18:33:20 2011 +0200
+++ b/Documentation/Help/source.qhp	Mon Apr 11 20:06:15 2011 +0200
@@ -2576,11 +2576,14 @@
       <keyword name="VirusTotalApi (Module)" id="VirusTotalApi (Module)" ref="eric5.Helpviewer.VirusTotalApi.html" />
       <keyword name="VirusTotalAPI" id="VirusTotalAPI" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI" />
       <keyword name="VirusTotalAPI (Constructor)" id="VirusTotalAPI (Constructor)" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.__init__" />
+      <keyword name="VirusTotalAPI.__checkServiceKeyValidityFinished" id="VirusTotalAPI.__checkServiceKeyValidityFinished" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.__checkServiceKeyValidityFinished" />
+      <keyword name="VirusTotalAPI.__getFileScanReportUrl" id="VirusTotalAPI.__getFileScanReportUrl" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.__getFileScanReportUrl" />
+      <keyword name="VirusTotalAPI.__getFileScanReportUrlFinished" id="VirusTotalAPI.__getFileScanReportUrlFinished" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.__getFileScanReportUrlFinished" />
       <keyword name="VirusTotalAPI.__loadSettings" id="VirusTotalAPI.__loadSettings" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.__loadSettings" />
+      <keyword name="VirusTotalAPI.__submitUrlFinished" id="VirusTotalAPI.__submitUrlFinished" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.__submitUrlFinished" />
       <keyword name="VirusTotalAPI.checkServiceKeyValidity" id="VirusTotalAPI.checkServiceKeyValidity" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.checkServiceKeyValidity" />
-      <keyword name="VirusTotalAPI.getFileScanReportUrl" id="VirusTotalAPI.getFileScanReportUrl" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.getFileScanReportUrl" />
       <keyword name="VirusTotalAPI.getSearchRequestData" id="VirusTotalAPI.getSearchRequestData" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.getSearchRequestData" />
-      <keyword name="VirusTotalAPI.getUrlScanReportUrl" id="VirusTotalAPI.getUrlScanReportUrl" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.getUrlScanReportUrl" />
+      <keyword name="VirusTotalAPI.preferencesChanged" id="VirusTotalAPI.preferencesChanged" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.preferencesChanged" />
       <keyword name="VirusTotalAPI.submitUrl" id="VirusTotalAPI.submitUrl" ref="eric5.Helpviewer.VirusTotalApi.html#VirusTotalAPI.submitUrl" />
       <keyword name="SslInfoDialog (Module)" id="SslInfoDialog (Module)" ref="eric5.Helpviewer.SslInfoDialog.html" />
       <keyword name="SslInfoDialog" id="SslInfoDialog" ref="eric5.Helpviewer.SslInfoDialog.html#SslInfoDialog" />
@@ -2808,9 +2811,12 @@
       <keyword name="HelpWindow.__syncTOC" id="HelpWindow.__syncTOC" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__syncTOC" />
       <keyword name="HelpWindow.__titleChanged" id="HelpWindow.__titleChanged" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__titleChanged" />
       <keyword name="HelpWindow.__viewFullScreen" id="HelpWindow.__viewFullScreen" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__viewFullScreen" />
+      <keyword name="HelpWindow.__virusTotalFileScanReport" id="HelpWindow.__virusTotalFileScanReport" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__virusTotalFileScanReport" />
       <keyword name="HelpWindow.__virusTotalScanCurrentSite" id="HelpWindow.__virusTotalScanCurrentSite" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__virusTotalScanCurrentSite" />
       <keyword name="HelpWindow.__virusTotalSearch" id="HelpWindow.__virusTotalSearch" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__virusTotalSearch" />
       <keyword name="HelpWindow.__virusTotalSearchChanged" id="HelpWindow.__virusTotalSearchChanged" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__virusTotalSearchChanged" />
+      <keyword name="HelpWindow.__virusTotalSubmitUrlError" id="HelpWindow.__virusTotalSubmitUrlError" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__virusTotalSubmitUrlError" />
+      <keyword name="HelpWindow.__virusTotalUrlScanReport" id="HelpWindow.__virusTotalUrlScanReport" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__virusTotalUrlScanReport" />
       <keyword name="HelpWindow.__warning" id="HelpWindow.__warning" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__warning" />
       <keyword name="HelpWindow.__whatsThis" id="HelpWindow.__whatsThis" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__whatsThis" />
       <keyword name="HelpWindow.__zoomIn" id="HelpWindow.__zoomIn" ref="eric5.Helpviewer.HelpWindow.html#HelpWindow.__zoomIn" />
@@ -7948,6 +7954,7 @@
       <keyword name="HelpVirusTotalPage" id="HelpVirusTotalPage" ref="eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html#HelpVirusTotalPage" />
       <keyword name="create" id="create" ref="eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html#create" />
       <keyword name="HelpVirusTotalPage (Constructor)" id="HelpVirusTotalPage (Constructor)" ref="eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html#HelpVirusTotalPage.__init__" />
+      <keyword name="HelpVirusTotalPage.__checkServiceKeyFinished" id="HelpVirusTotalPage.__checkServiceKeyFinished" ref="eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html#HelpVirusTotalPage.__checkServiceKeyFinished" />
       <keyword name="HelpVirusTotalPage.on_testButton_clicked" id="HelpVirusTotalPage.on_testButton_clicked" ref="eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html#HelpVirusTotalPage.on_testButton_clicked" />
       <keyword name="HelpVirusTotalPage.on_vtServiceKeyEdit_textChanged" id="HelpVirusTotalPage.on_vtServiceKeyEdit_textChanged" ref="eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html#HelpVirusTotalPage.on_vtServiceKeyEdit_textChanged" />
       <keyword name="HelpVirusTotalPage.save" id="HelpVirusTotalPage.save" ref="eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html#HelpVirusTotalPage.save" />
--- a/Documentation/Source/eric5.Helpviewer.HelpWindow.html	Sun Apr 10 18:33:20 2011 +0200
+++ b/Documentation/Source/eric5.Helpviewer.HelpWindow.html	Mon Apr 11 20:06:15 2011 +0200
@@ -280,6 +280,9 @@
 <td><a href="#HelpWindow.__viewFullScreen">__viewFullScreen</a></td>
 <td>Private slot called to toggle fullscreen mode.</td>
 </tr><tr>
+<td><a href="#HelpWindow.__virusTotalFileScanReport">__virusTotalFileScanReport</a></td>
+<td>Private slot to initiate the display of the file scan report page.</td>
+</tr><tr>
 <td><a href="#HelpWindow.__virusTotalScanCurrentSite">__virusTotalScanCurrentSite</a></td>
 <td>Private slot to ask VirusTotal for a scan of the URL of the current browser.</td>
 </tr><tr>
@@ -289,6 +292,12 @@
 <td><a href="#HelpWindow.__virusTotalSearchChanged">__virusTotalSearchChanged</a></td>
 <td>Private slot to react upon changes of the VirusTotal search text.</td>
 </tr><tr>
+<td><a href="#HelpWindow.__virusTotalSubmitUrlError">__virusTotalSubmitUrlError</a></td>
+<td>Private slot to handle an URL scan submission error.</td>
+</tr><tr>
+<td><a href="#HelpWindow.__virusTotalUrlScanReport">__virusTotalUrlScanReport</a></td>
+<td>Private slot to initiate the display of the URL scan report page.</td>
+</tr><tr>
 <td><a href="#HelpWindow.__warning">__warning</a></td>
 <td>Private slot handling warnings from the help engine.</td>
 </tr><tr>
@@ -873,7 +882,17 @@
 <b>__viewFullScreen</b>(<i></i>)
 <p>
         Private slot called to toggle fullscreen mode.
-</p><a NAME="HelpWindow.__virusTotalScanCurrentSite" ID="HelpWindow.__virusTotalScanCurrentSite"></a>
+</p><a NAME="HelpWindow.__virusTotalFileScanReport" ID="HelpWindow.__virusTotalFileScanReport"></a>
+<h4>HelpWindow.__virusTotalFileScanReport</h4>
+<b>__virusTotalFileScanReport</b>(<i>url</i>)
+<p>
+        Private slot to initiate the display of the file scan report page.
+</p><dl>
+<dt><i>url</i></dt>
+<dd>
+URL of the file scan report page (string)
+</dd>
+</dl><a NAME="HelpWindow.__virusTotalScanCurrentSite" ID="HelpWindow.__virusTotalScanCurrentSite"></a>
 <h4>HelpWindow.__virusTotalScanCurrentSite</h4>
 <b>__virusTotalScanCurrentSite</b>(<i></i>)
 <p>
@@ -893,6 +912,26 @@
 <dd>
 contents of the search (string)
 </dd>
+</dl><a NAME="HelpWindow.__virusTotalSubmitUrlError" ID="HelpWindow.__virusTotalSubmitUrlError"></a>
+<h4>HelpWindow.__virusTotalSubmitUrlError</h4>
+<b>__virusTotalSubmitUrlError</b>(<i>msg</i>)
+<p>
+        Private slot to handle an URL scan submission error.
+</p><dl>
+<dt><i>msg</i></dt>
+<dd>
+error message (str)
+</dd>
+</dl><a NAME="HelpWindow.__virusTotalUrlScanReport" ID="HelpWindow.__virusTotalUrlScanReport"></a>
+<h4>HelpWindow.__virusTotalUrlScanReport</h4>
+<b>__virusTotalUrlScanReport</b>(<i>url</i>)
+<p>
+        Private slot to initiate the display of the URL scan report page.
+</p><dl>
+<dt><i>url</i></dt>
+<dd>
+URL of the URL scan report page (string)
+</dd>
 </dl><a NAME="HelpWindow.__warning" ID="HelpWindow.__warning"></a>
 <h4>HelpWindow.__warning</h4>
 <b>__warning</b>(<i>msg</i>)
@@ -1202,7 +1241,12 @@
 <b>requestVirusTotalScan</b>(<i>url</i>)
 <p>
         Public method to submit a request to scan an URL by VirusTotal.
-</p><a NAME="HelpWindow.search" ID="HelpWindow.search"></a>
+</p><dl>
+<dt><i>url</i></dt>
+<dd>
+URL to be scanned (QUrl)
+</dd>
+</dl><a NAME="HelpWindow.search" ID="HelpWindow.search"></a>
 <h4>HelpWindow.search</h4>
 <b>search</b>(<i>word</i>)
 <p>
--- a/Documentation/Source/eric5.Helpviewer.VirusTotalApi.html	Sun Apr 10 18:33:20 2011 +0200
+++ b/Documentation/Source/eric5.Helpviewer.VirusTotalApi.html	Mon Apr 11 20:06:15 2011 +0200
@@ -44,7 +44,25 @@
 <h2>VirusTotalAPI</h2>
 <p>
     Class implementing the <a href="http://www.virustotal.com">VirusTotal</a> API.
-</p>
+</p><h4>Signals</h4>
+<dl>
+<dt>checkServiceKeyFinished(bool, str)</dt>
+<dd>
+emitted after the service key check
+            has been performed. It gives a flag indicating validity (boolean) and
+            an error message in case of a network error (string).
+</dd><dt>fileScanReport(str)</dt>
+<dd>
+emitted with the URL of the file scan report page
+</dd><dt>submitUrlError(str)</dt>
+<dd>
+emitted with the error string, if the URL scan
+            submission returned an error. 
+</dd><dt>urlScanReport(str)</dt>
+<dd>
+emitted with the URL of the URL scan report page
+</dd>
+</dl>
 <h3>Derived from</h3>
 QObject
 <h3>Class Attributes</h3>
@@ -57,20 +75,29 @@
 <td><a href="#VirusTotalAPI.__init__">VirusTotalAPI</a></td>
 <td>Constructor</td>
 </tr><tr>
+<td><a href="#VirusTotalAPI.__checkServiceKeyValidityFinished">__checkServiceKeyValidityFinished</a></td>
+<td>Private slot to determine the result of the service key validity check.</td>
+</tr><tr>
+<td><a href="#VirusTotalAPI.__getFileScanReportUrl">__getFileScanReportUrl</a></td>
+<td>Private method to get the report URL for a file scan.</td>
+</tr><tr>
+<td><a href="#VirusTotalAPI.__getFileScanReportUrlFinished">__getFileScanReportUrlFinished</a></td>
+<td>Private slot to determine the result of the file scan report URL request.</td>
+</tr><tr>
 <td><a href="#VirusTotalAPI.__loadSettings">__loadSettings</a></td>
 <td>Private method to load the settings.</td>
 </tr><tr>
+<td><a href="#VirusTotalAPI.__submitUrlFinished">__submitUrlFinished</a></td>
+<td>Private slot to determine the result of the URL scan submission.</td>
+</tr><tr>
 <td><a href="#VirusTotalAPI.checkServiceKeyValidity">checkServiceKeyValidity</a></td>
 <td>Public method to check the validity of the given service key.</td>
 </tr><tr>
-<td><a href="#VirusTotalAPI.getFileScanReportUrl">getFileScanReportUrl</a></td>
-<td>Public method to get the report URL for a file scan.</td>
+<td><a href="#VirusTotalAPI.getSearchRequestData">getSearchRequestData</a></td>
+<td>Class method to assemble the search request data structure.</td>
 </tr><tr>
-<td><a href="#VirusTotalAPI.getSearchRequestData">getSearchRequestData</a></td>
-<td></td>
-</tr><tr>
-<td><a href="#VirusTotalAPI.getUrlScanReportUrl">getUrlScanReportUrl</a></td>
-<td>Public method to get the report URL for a URL scan.</td>
+<td><a href="#VirusTotalAPI.preferencesChanged">preferencesChanged</a></td>
+<td>Public slot to handle a change of preferences.</td>
 </tr><tr>
 <td><a href="#VirusTotalAPI.submitUrl">submitUrl</a></td>
 <td>Public method to submit an URL to be scanned.</td>
@@ -86,11 +113,41 @@
 <dd>
 reference to the parent object (QObject)
 </dd>
-</dl><a NAME="VirusTotalAPI.__loadSettings" ID="VirusTotalAPI.__loadSettings"></a>
+</dl><a NAME="VirusTotalAPI.__checkServiceKeyValidityFinished" ID="VirusTotalAPI.__checkServiceKeyValidityFinished"></a>
+<h4>VirusTotalAPI.__checkServiceKeyValidityFinished</h4>
+<b>__checkServiceKeyValidityFinished</b>(<i></i>)
+<p>
+        Private slot to determine the result of the service key validity check.
+</p><a NAME="VirusTotalAPI.__getFileScanReportUrl" ID="VirusTotalAPI.__getFileScanReportUrl"></a>
+<h4>VirusTotalAPI.__getFileScanReportUrl</h4>
+<b>__getFileScanReportUrl</b>(<i>scanId</i>)
+<p>
+        Private method to get the report URL for a file scan.
+</p><dl>
+<dt><i>scanId</i></dt>
+<dd>
+ID of the scan to get the report URL for (string)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+file scan report URL (string)
+</dd>
+</dl><a NAME="VirusTotalAPI.__getFileScanReportUrlFinished" ID="VirusTotalAPI.__getFileScanReportUrlFinished"></a>
+<h4>VirusTotalAPI.__getFileScanReportUrlFinished</h4>
+<b>__getFileScanReportUrlFinished</b>(<i></i>)
+<p>
+        Private slot to determine the result of the file scan report URL request.
+</p><a NAME="VirusTotalAPI.__loadSettings" ID="VirusTotalAPI.__loadSettings"></a>
 <h4>VirusTotalAPI.__loadSettings</h4>
 <b>__loadSettings</b>(<i></i>)
 <p>
         Private method to load the settings.
+</p><a NAME="VirusTotalAPI.__submitUrlFinished" ID="VirusTotalAPI.__submitUrlFinished"></a>
+<h4>VirusTotalAPI.__submitUrlFinished</h4>
+<b>__submitUrlFinished</b>(<i></i>)
+<p>
+        Private slot to determine the result of the URL scan submission.
 </p><a NAME="VirusTotalAPI.checkServiceKeyValidity" ID="VirusTotalAPI.checkServiceKeyValidity"></a>
 <h4>VirusTotalAPI.checkServiceKeyValidity</h4>
 <b>checkServiceKeyValidity</b>(<i>key, protocol=""</i>)
@@ -110,44 +167,28 @@
 flag indicating validity (boolean) and an error message in
             case of a network error (string)
 </dd>
-</dl><a NAME="VirusTotalAPI.getFileScanReportUrl" ID="VirusTotalAPI.getFileScanReportUrl"></a>
-<h4>VirusTotalAPI.getFileScanReportUrl</h4>
-<b>getFileScanReportUrl</b>(<i>scanId</i>)
-<p>
-        Public method to get the report URL for a file scan.
-</p><dl>
-<dt><i>scanId</i></dt>
-<dd>
-ID of the scan to get the report URL for (string)
-</dd>
-</dl><dl>
-<dt>Returns:</dt>
-<dd>
-file scan report URL (string)
-</dd>
 </dl><a NAME="VirusTotalAPI.getSearchRequestData" ID="VirusTotalAPI.getSearchRequestData"></a>
 <h4>VirusTotalAPI.getSearchRequestData</h4>
 <b>getSearchRequestData</b>(<i>term</i>)
 <p>
-
-</p><p>
-
-</p><a NAME="VirusTotalAPI.getUrlScanReportUrl" ID="VirusTotalAPI.getUrlScanReportUrl"></a>
-<h4>VirusTotalAPI.getUrlScanReportUrl</h4>
-<b>getUrlScanReportUrl</b>(<i>scanId</i>)
-<p>
-        Public method to get the report URL for a URL scan.
+        Class method to assemble the search request data structure.
 </p><dl>
-<dt><i>scanId</i></dt>
+<dt><i>term</i></dt>
 <dd>
-ID of the scan to get the report URL for (string)
+search term (string)
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-URL scan report URL (string)
+tuple of network request object, operation and parameters
+            (QNetworkRequest, QNetworkAccessManager.Operation, QByteArray)
 </dd>
-</dl><a NAME="VirusTotalAPI.submitUrl" ID="VirusTotalAPI.submitUrl"></a>
+</dl><a NAME="VirusTotalAPI.preferencesChanged" ID="VirusTotalAPI.preferencesChanged"></a>
+<h4>VirusTotalAPI.preferencesChanged</h4>
+<b>preferencesChanged</b>(<i></i>)
+<p>
+        Public slot to handle a change of preferences.
+</p><a NAME="VirusTotalAPI.submitUrl" ID="VirusTotalAPI.submitUrl"></a>
 <h4>VirusTotalAPI.submitUrl</h4>
 <b>submitUrl</b>(<i>url</i>)
 <p>
--- a/Documentation/Source/eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html	Sun Apr 10 18:33:20 2011 +0200
+++ b/Documentation/Source/eric5.Preferences.ConfigurationPages.HelpVirusTotalPage.html	Mon Apr 11 20:06:15 2011 +0200
@@ -60,6 +60,9 @@
 <td><a href="#HelpVirusTotalPage.__init__">HelpVirusTotalPage</a></td>
 <td>Constructor</td>
 </tr><tr>
+<td><a href="#HelpVirusTotalPage.__checkServiceKeyFinished">__checkServiceKeyFinished</a></td>
+<td>Private slot to receive the result of the service key check.</td>
+</tr><tr>
 <td><a href="#HelpVirusTotalPage.on_testButton_clicked">on_testButton_clicked</a></td>
 <td>Private slot to test the entered service key.</td>
 </tr><tr>
@@ -80,6 +83,19 @@
 <dd>
 reference to the parent widget (QWidget)
 </dd>
+</dl><a NAME="HelpVirusTotalPage.__checkServiceKeyFinished" ID="HelpVirusTotalPage.__checkServiceKeyFinished"></a>
+<h4>HelpVirusTotalPage.__checkServiceKeyFinished</h4>
+<b>__checkServiceKeyFinished</b>(<i>result, msg</i>)
+<p>
+        Private slot to receive the result of the service key check.
+</p><dl>
+<dt><i>result</i></dt>
+<dd>
+flag indicating a successful check (boolean)
+</dd><dt><i>msg</i></dt>
+<dd>
+network error message (str)
+</dd>
 </dl><a NAME="HelpVirusTotalPage.on_testButton_clicked" ID="HelpVirusTotalPage.on_testButton_clicked"></a>
 <h4>HelpVirusTotalPage.on_testButton_clicked</h4>
 <b>on_testButton_clicked</b>(<i></i>)
--- a/Helpviewer/HelpWindow.py	Sun Apr 10 18:33:20 2011 +0200
+++ b/Helpviewer/HelpWindow.py	Mon Apr 11 20:06:15 2011 +0200
@@ -210,6 +210,11 @@
             
             self.__initHelpDb()
             
+            self.__virusTotal = VirusTotalAPI(self)
+            self.__virusTotal.submitUrlError.connect(self.__virusTotalSubmitUrlError)
+            self.__virusTotal.urlScanReport.connect(self.__virusTotalUrlScanReport)
+            self.__virusTotal.fileScanReport.connect(self.__virusTotalFileScanReport)
+            
             QTimer.singleShot(0, self.__lookForNewDocumentation)
             if self.__searchWord is not None:
                 QTimer.singleShot(0, self.__searchForWord)
@@ -1935,6 +1940,7 @@
         
         self.searchEdit.preferencesChanged()
         
+        self.__virusTotal.preferencesChanged()
         if not Preferences.getHelp("VirusTotalEnabled") or \
            Preferences.getHelp("VirusTotalServiceKey") == "":
             self.virustotalSearchEdit.setEnabled(False)
@@ -2690,16 +2696,34 @@
     def requestVirusTotalScan(self, url):
         """
         Public method to submit a request to scan an URL by VirusTotal.
+        
+        @param url URL to be scanned (QUrl)
         """
-        vt = VirusTotalAPI(self)
-        ok, res = vt.submitUrl(url)
-        if ok:
-            self.newTab(vt.getUrlScanReportUrl(res))
-            fileScanPageUrl = vt.getFileScanReportUrl(res)
-            if fileScanPageUrl:
-                self.newTab(fileScanPageUrl)
-        else:
-            E5MessageBox.critical(self,
-                self.trUtf8("VirusTotal Scan"),
-                self.trUtf8("""<p>The VirusTotal scan could not be"""
-                            """ scheduled.<p>\n<p>Reason: {0}</p>""").format(res))
+        self.__virusTotal.submitUrl(url)
+    
+    def __virusTotalSubmitUrlError(self, msg):
+        """
+        Private slot to handle an URL scan submission error.
+        
+        @param msg error message (str)
+        """
+        E5MessageBox.critical(self,
+            self.trUtf8("VirusTotal Scan"),
+            self.trUtf8("""<p>The VirusTotal scan could not be"""
+                        """ scheduled.<p>\n<p>Reason: {0}</p>""").format(msg))
+    
+    def __virusTotalUrlScanReport(self, url):
+        """
+        Private slot to initiate the display of the URL scan report page.
+        
+        @param url URL of the URL scan report page (string)
+        """
+        self.newTab(url)
+    
+    def __virusTotalFileScanReport(self, url):
+        """
+        Private slot to initiate the display of the file scan report page.
+        
+        @param url URL of the file scan report page (string)
+        """
+        self.newTab(url)
--- a/Helpviewer/VirusTotalApi.py	Sun Apr 10 18:33:20 2011 +0200
+++ b/Helpviewer/VirusTotalApi.py	Mon Apr 11 20:06:15 2011 +0200
@@ -9,7 +9,7 @@
 
 import json
 
-from PyQt4.QtCore import QObject, QUrl, QByteArray, QCoreApplication, QThread
+from PyQt4.QtCore import QObject, QUrl, QByteArray, pyqtSignal
 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager
 
 import Helpviewer.HelpWindow
@@ -19,7 +19,20 @@
 class VirusTotalAPI(QObject):
     """
     Class implementing the <a href="http://www.virustotal.com">VirusTotal</a> API.
+    
+    @signal checkServiceKeyFinished(bool, str) emitted after the service key check
+            has been performed. It gives a flag indicating validity (boolean) and
+            an error message in case of a network error (string).
+    @signal submitUrlError(str) emitted with the error string, if the URL scan
+            submission returned an error. 
+    @signal urlScanReport(str) emitted with the URL of the URL scan report page
+    @signal fileScanReport(str) emitted with the URL of the file scan report page
     """
+    checkServiceKeyFinished = pyqtSignal(bool, str)
+    submitUrlError = pyqtSignal(str)
+    urlScanReport = pyqtSignal(str)
+    fileScanReport = pyqtSignal(str)
+    
     TestServiceKeyScanID = \
         "4feed2c2e352f105f6188efd1d5a558f24aee6971bdf96d5fdb19c197d6d3fad"
     
@@ -45,6 +58,8 @@
         """
         QObject.__init__(self, parent)
         
+        self.__replies = []
+        
         self.__loadSettings()
     
     def __loadSettings(self):
@@ -65,6 +80,12 @@
              0: self.trUtf8("Requested item is not present.")
         }
     
+    def preferencesChanged(self):
+        """
+        Public slot to handle a change of preferences.
+        """
+        self.__loadSettings()
+    
     def checkServiceKeyValidity(self, key, protocol=""):
         """
         Public method to check the validity of the given service key.
@@ -86,20 +107,26 @@
         
         nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager()
         reply = nam.post(request, params)
-        while not reply.isFinished():
-            QCoreApplication.processEvents()
-            QThread.msleep(100)
-            if QCoreApplication.closingDown():
-                reply.abort()
-            QCoreApplication.processEvents()
+        reply.finished.connect(self.__checkServiceKeyValidityFinished)
+        self.__replies.append(reply)
+    
+    def __checkServiceKeyValidityFinished(self):
+        """
+        Private slot to determine the result of the service key validity check.
+        """
+        res = False
+        msg = ""
+        
+        reply = self.sender()
         if reply.error() == QNetworkReply.NoError:
             result = json.loads(str(reply.readAll(), "utf-8"))
             if result["result"] != self.ServiceResult_InvalidServiceKey:
-                return True, ""
-            else:
-                return False, ""
+                res = True
+        else:
+            msg = reply.errorString()
+        self.__replies.remove(reply)
         
-        return False, reply.errorString()
+        self.checkServiceKeyFinished.emit(res, msg)
     
     def submitUrl(self, url):
         """
@@ -117,39 +144,33 @@
         
         nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager()
         reply = nam.post(request, params)
-        while not reply.isFinished():
-            QCoreApplication.processEvents()
-            QThread.msleep(100)
-            if QCoreApplication.closingDown():
-                reply.abort()
-            QCoreApplication.processEvents()
+        reply.finished.connect(self.__submitUrlFinished)
+        self.__replies.append(reply)
+    
+    def __submitUrlFinished(self):
+        """
+        Private slot to determine the result of the URL scan submission.
+        """
+        reply = self.sender()
         if reply.error() == QNetworkReply.NoError:
             result = json.loads(str(reply.readAll(), "utf-8"))
             if result["result"] == self.ServiceResult_ItemPresent:
-                return True, result["scan_id"]
+                self.urlScanReport.emit(
+                    self.ReportUrlScanPagePattern.format(result["scan_id"]))
+                self.__getFileScanReportUrl(result["scan_id"])
             else:
-                return False, self.errorMessages[result["result"]]
-        
-        return False, reply.errorString()
+                self.submitUrlError.emit(self.errorMessages[result["result"]])
+        else:
+            self.submitUrlError.emit(reply.errorString())
+        self.__replies.remove(reply)
     
-    def getUrlScanReportUrl(self, scanId):
+    def __getFileScanReportUrl(self, scanId):
         """
-        Public method to get the report URL for a URL scan.
-        
-        @param scanId ID of the scan to get the report URL for (string)
-        @return URL scan report URL (string)
-        """
-        return self.ReportUrlScanPagePattern.format(scanId)
-        
-    def getFileScanReportUrl(self, scanId):
-        """
-        Public method to get the report URL for a file scan.
+        Private method to get the report URL for a file scan.
         
         @param scanId ID of the scan to get the report URL for (string)
         @return file scan report URL (string)
         """
-        fileScanPageUrl = ""    # default value
-        
         request = QNetworkRequest(QUrl(self.GetUrlReportUrl))
         request.setHeader(QNetworkRequest.ContentTypeHeader,
                           "application/x-www-form-urlencoded")
@@ -158,24 +179,29 @@
         
         nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager()
         reply = nam.post(request, params)
-        while not reply.isFinished():
-            QCoreApplication.processEvents()
-            QThread.msleep(100)
-            if QCoreApplication.closingDown():
-                reply.abort()
-            QCoreApplication.processEvents()
+        reply.finished.connect(self.__getFileScanReportUrlFinished)
+        self.__replies.append(reply)
+    
+    def __getFileScanReportUrlFinished(self):
+        """
+        Private slot to determine the result of the file scan report URL request.
+        """
+        reply = self.sender()
         if reply.error() == QNetworkReply.NoError:
             result = json.loads(str(reply.readAll(), "utf-8"))
             if "file-report" in result:
-                fileScanPageUrl = self.ReportFileScanPagePattern.format(
-                    result["file-report"])
-        
-        return fileScanPageUrl
+                self.fileScanReport.emit(
+                    self.ReportFileScanPagePattern.format(result["file-report"]))
+        self.__replies.remove(reply)
     
     @classmethod
     def getSearchRequestData(cls, term):
         """
+        Class method to assemble the search request data structure.
         
+        @param term search term (string)
+        @return tuple of network request object, operation and parameters
+            (QNetworkRequest, QNetworkAccessManager.Operation, QByteArray)
         """
         request = QNetworkRequest(QUrl(cls.SearchUrl))
         request.setHeader(QNetworkRequest.ContentTypeHeader,
--- a/Preferences/ConfigurationPages/HelpVirusTotalPage.py	Sun Apr 10 18:33:20 2011 +0200
+++ b/Preferences/ConfigurationPages/HelpVirusTotalPage.py	Mon Apr 11 20:06:15 2011 +0200
@@ -33,6 +33,9 @@
         
         self.testResultLabel.setHidden(True)
         
+        self.__vt = VirusTotalAPI(self)
+        self.__vt.checkServiceKeyFinished.connect(self.__checkServiceKeyFinished)
+        
         # set initial values
         self.vtEnabledCheckBox.setChecked(
             Preferences.getHelp("VirusTotalEnabled"))
@@ -70,12 +73,20 @@
         self.testResultLabel.setHidden(False)
         self.testResultLabel.setText(
             self.trUtf8("Checking validity of the service key..."))
-        vt = VirusTotalAPI(self)
         if self.vtSecureCheckBox.isChecked():
             protocol = "https"
         else:
             protocol = "http"
-        result, msg = vt.checkServiceKeyValidity(self.vtServiceKeyEdit.text(), protocol)
+        self.__vt.checkServiceKeyValidity(self.vtServiceKeyEdit.text(), protocol)
+    
+    @pyqtSlot(bool, str)
+    def __checkServiceKeyFinished(self, result, msg):
+        """
+        Private slot to receive the result of the service key check.
+        
+        @param result flag indicating a successful check (boolean)
+        @param msg network error message (str)
+        """
         if result:
             self.testResultLabel.setText(self.trUtf8("The service key is valid."))
         else:

eric ide

mercurial