[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r3987: HerdictWeb plugin now submits correctly and displays site in (vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin)



Author: tyree731
Date: 2009-07-30 18:42:10 -0400 (Thu, 30 Jul 2009)
New Revision: 3987

Modified:
   vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.cpp
   vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.h
   vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.ui
Log:
HerdictWeb plugin now submits correctly and displays site information. Large amount of code cleanup. All that remains is to make requests use SSL.


Modified: vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.cpp
===================================================================
--- vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.cpp	2009-07-30 02:02:46 UTC (rev 3986)
+++ vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.cpp	2009-07-30 22:42:10 UTC (rev 3987)
@@ -22,6 +22,7 @@
 #include <QNetworkProxy>
 #include <QNetworkReply>
 #include <QNetworkRequest>
+#include <QSslConfiguration>
 #include <QString>
 #include <QUrl>
 #include <QVariant>
@@ -38,23 +39,25 @@
   /* Create the status widget */
   _statusWidget = new QLabel(this);
 
-  /* Populate the left side of the panel */
-  populateHerdictOptions();
-
-  /* Proxy hostname and port */
+  /* Tor proxy hostname and port */
   QHostAddress address(QHostAddress::LocalHost);
   QString hostname = address.toString();
   quint16 port = 9050;
 
-  /* Create a network proxy for the Tor webview and a NAM to use it. */
+  /* Create a network proxy for the Tor network. */
   QNetworkProxy torProxy(QNetworkProxy::Socks5Proxy, hostname, port);
 
-  QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
-  networkAccessManager->setProxy(torProxy);
+  /* Create the access managers */
+  _accessManager = new QNetworkAccessManager(this);
+  _torAccessManager = new QNetworkAccessManager(this);
+  _torAccessManager->setProxy(torProxy);
 
   /* Make the Tor Web View use this network access manager */
-  ui.webViewTor->page()->setNetworkAccessManager(networkAccessManager);
+  ui.webViewTor->page()->setNetworkAccessManager(_torAccessManager);
 
+  /* Populate the left side of the panel */
+  populateHerdictOptions();
+
   /* Default to hiding the progress bars */
   ui.progressPlain->hide();
   ui.progressTor->hide();
@@ -67,6 +70,8 @@
   connect(ui.buttonInAccessible, SIGNAL(pressed()),
           this, SLOT(submitInAccessible()));
 
+  /* *** TODO: Fix status message signals *** */
+
   /* Connect page signals to their respective handlers */
   connect(ui.webViewPlain, SIGNAL(loadStarted()),
           this, SLOT(loadStarted()));
@@ -86,7 +91,9 @@
 
 HerdictWebReporterPanel::~HerdictWebReporterPanel()
 {
+  delete _accessManager;
   delete _statusWidget;
+  delete _torAccessManager;
 }
 
 QString 
@@ -98,6 +105,8 @@
 QIcon
 HerdictWebReporterPanel::tabIcon() const
 {
+  /* *** TODO: Better icon for the HerdictWeb Reporter Tab *** */
+
   return QIcon(":/images/16x16/go-home.png");
 }
 
@@ -126,14 +135,37 @@
 void
 HerdictWebReporterPanel::loadUrl()
 {
-  QString url = ui.lineUrlEntry->text();
-  ui.webViewPlain->load(QUrl(url));
-  ui.webViewTor->load(QUrl(url));
+  /* Load the website */
+  QUrl url(ui.lineUrlEntry->text());
+  ui.webViewPlain->load(url);
+  ui.webViewTor->load(url);
+
+  /* Acquire site information using Herdict API */
+  QString request("http://www.herdict.org/web/action/ajax/plugin/site/";);
+  request += (url.host() + QString("/"));
+  /* If no country is selected, default the United States */
+  if (ui.comboCountryEntry->currentIndex() >= 0) {
+    request += ui.comboCountryEntry->itemData(
+                               ui.comboCountryEntry->currentIndex()).toString();
+  }
+  else {
+    request += QString("US");
+  }
+  request += QString("/none/FF1.0/");
+
+  /* Build request */
+  QUrl informationUrl(request);
+  QNetworkRequest informationRequest(informationUrl);
+
+  /* Send request */
+  _accessManager->get(informationRequest);
 }
 
 void
 HerdictWebReporterPanel::plainLoadFinished(bool result)
 {
+  /* ***TODO: Add an error page that loads if the request failed *** */
+
   /* Hide the statusbar */
   ui.progressPlain->hide();
   if (!result)
@@ -143,10 +175,6 @@
 void
 HerdictWebReporterPanel::requestFinished(QNetworkReply* reply)
 {
-  /* If there was an error, do nothing */
-  if (reply->error() != QNetworkReply::NoError)
-    return;
-
   /* Create the json parser */
   bool result;
   QJson::Parser jsonParser;
@@ -154,81 +182,80 @@
   /* Figure out which request it was */
   QString url = reply->url().toString();
 
-  if (url == "http://www.herdict.org/web/action/ajax/plugin/init-categories/";) {
-    /* Retrieve all of the tuples */
-    QList<QVariant> jsonResultList = 
-      jsonParser.parse(reply, &result).toList();
+  if (url.contains("ajax/plugin/site", Qt::CaseInsensitive)) {
+    QVariantMap jsonResultMap = jsonParser.parse(reply, &result).toMap();
     /* If invalid json, do nothing */
     if (!result)
       return;
 
-    /* Evaluate each tuple as a map to obtain the necessary values */
-    QList<QVariant>::iterator it = jsonResultList.begin();
-    while (it != jsonResultList.end()) {
-      QVariantMap valueMap = (*it).toMap();
-      ui.comboCategoryEntry->addItem(valueMap["label"].toString(), 
-                                     valueMap["value"]);
-      it++;
-    }
+    /* Find the long country name */
+    QString countryName = ui.comboCountryEntry->itemText(
+                  ui.comboCountryEntry->findData(jsonResultMap["countryCode"]));
+
+    /* Construct site information string */
+    QString siteInfo(jsonResultMap["url"].toString());
+    siteInfo += " reported inaccessible ";
+    siteInfo += jsonResultMap["countryInaccessibleCount"].toString();
+    siteInfo += (QString(" times in ") + countryName);
+    siteInfo += QString(" (");
+    siteInfo += jsonResultMap["globalInaccessibleCount"].toString();
+    siteInfo += QString(" times globally)");
+
+    /* Set the label */
+    ui.lblSiteInformation->setText(siteInfo);
   }
-  else if (url == "http://www.herdict.org/web/action/ajax/plugin/init-countries/";) {
-    /* Retrieve all of the tuples */
-    QList<QVariant> jsonResultList =
-      jsonParser.parse(reply, &result).toList();
+  else if (url.contains("ajax/plugin/init-currentLocation")) {
+    /* Handle the json as a map */
+    QVariantMap jsonResultMap = jsonParser.parse(reply, &result).toMap();
     /* If invalid json, do nothing */
     if (!result)
       return;
 
-    /* Evaluate each tuple as a map to obtain the necessary values */
-    QList<QVariant>::iterator it = jsonResultList.begin();
-    while (it != jsonResultList.end()) {
-      QVariantMap valueMap = (*it).toMap();
-      ui.comboCountryEntry->addItem(valueMap["label"].toString(),
-                                     valueMap["value"]);
-      it++;
-    }
+    _defaultISP = jsonResultMap["ispName"].toString();
+    _defaultCountryCode = jsonResultMap["countryShort"].toString();
 
+    ui.lineISPEntry->setText(jsonResultMap["ispName"].toString());
+    ui.comboCountryEntry->setCurrentIndex(ui.comboCountryEntry->findText(
+                                   jsonResultMap["countryLong"].toString()));
   }
-  else if (url == "http://www.herdict.org/web/action/ajax/plugin/init-locations/";) {
-    /* Retrieve all of the tuples */
-    QList<QVariant> jsonResultList =
-      jsonParser.parse(reply, &result).toList();
-    /* If invalid json, do nothing */
-    if (!result)
-      return;
-
-    /* Evaluate each tuple as a map to obtain the necessary values */
-    QList<QVariant>::iterator it = jsonResultList.begin();
-    while (it != jsonResultList.end()) {
-      QVariantMap valueMap = (*it).toMap();
-      ui.comboLocationEntry->addItem(valueMap["label"].toString(),
-                                     valueMap["value"]);
-      it++;
+  else if (url.contains("ajax/plugin/report")) {
+    /* *** TODO: Create notifications of success or failure *** */
+    if (reply->error() != QNetworkReply::NoError) {
+      /* Notify user of submission issue */
     }
+    else {
+      /* Notify user of success */
+    }
 
+    /* Reenable buttons */
+    ui.buttonAccessible->setEnabled(true);
+    ui.buttonInAccessible->setEnabled(true);
   }
-  else if (url == "http://www.herdict.org/web/action/ajax/plugin/init-interests/";) {
-    /* Retrieve all of the tuples */
-    QList<QVariant> jsonResultList =
-      jsonParser.parse(reply, &result).toList();
-    /* If invalid json, do nothing */
-    if (!result)
+  else {
+    /* Other requests all parse the same, so group them together */
+    QComboBox* comboBox;
+    if (url.contains("ajax/plugin/init-countries")) {
+      comboBox = ui.comboCountryEntry;
+    }
+    else if (url.contains("ajax/plugin/init-locations")) {
+      comboBox = ui.comboLocationEntry;
+    }
+    else if (url.contains("ajax/plugin/init-interests")) {
+      comboBox = ui.comboUsefulnessEntry;
+    }
+    else if (url.contains("ajax/plugin/init-categories")) {
+      comboBox = ui.comboCategoryEntry;
+    }
+    else if (url.contains("ajax/plugin/init-reasons")) {
+      comboBox = ui.comboCauseEntry;
+    }
+    else {
+      /* What url is this? */
       return;
-
-    /* Evaluate each tuple as a map to obtain the necessary values */
-    QList<QVariant>::iterator it = jsonResultList.begin();
-    while (it != jsonResultList.end()) {
-      QVariantMap valueMap = (*it).toMap();
-      ui.comboUsefulnessEntry->addItem(valueMap["label"].toString(),
-                                     valueMap["value"]);
-      it++;
     }
 
-}
-  else if (url == "http://www.herdict.org/web/action/ajax/plugin/init-reasons/";) {
     /* Retrieve all of the tuples */
-    QList<QVariant> jsonResultList =
-      jsonParser.parse(reply, &result).toList();
+    QList<QVariant> jsonResultList = jsonParser.parse(reply, &result).toList();
     /* If invalid json, do nothing */
     if (!result)
       return;
@@ -237,27 +264,12 @@
     QList<QVariant>::iterator it = jsonResultList.begin();
     while (it != jsonResultList.end()) {
       QVariantMap valueMap = (*it).toMap();
-      ui.comboCauseEntry->addItem(valueMap["label"].toString(),
-                                     valueMap["value"]);
+      comboBox->addItem(valueMap["label"].toString(), valueMap["value"]);
       it++;
     }
 
-}
-  else if (url == "http://www.herdict.org/web/action/ajax/plugin/init-currentLocation/FF1.0";) {
-    /* Handle the json as a map */
-    QVariantMap jsonResultMap = jsonParser.parse(reply, &result).toMap();
-    /* If invalid json, do nothing */
-    if (!result)
-      return;
+  }
 
-    _defaultISP = jsonResultMap["ispName"].toString();
-    _defaultCountryCode = jsonResultMap["countryShort"].toString();
-
-    ui.lineISPEntry->setText(jsonResultMap["ispName"].toString());
-    ui.comboCountryEntry->setCurrentIndex(ui.comboCountryEntry->findText(
-                                   jsonResultMap["countryLong"].toString()));
-}
-
   /* Close the network reply */
   reply->close();
 }
@@ -265,24 +277,46 @@
 void
 HerdictWebReporterPanel::submitAccessible()
 {
+  /* *** TODO: Make use Tor+SSL *** */
+
+  /* Disable the submit buttons */
+  ui.buttonAccessible->setDisabled(true);
+  ui.buttonInAccessible->setDisabled(true);
+
   /* Construct request */
-  QString request = constructRequest(HerdictWebReporterPanel::Accessible);
+  QUrl request(constructRequest(HerdictWebReporterPanel::Accessible));
+  QNetworkRequest networkRequest(request);
+#if 0
+  networkRequest.setSslConfiguration(QSslConfiguration());
+#endif
   /* Send request */
-  QNetworkReply* reply = _accessManager->get(QNetworkRequest(QUrl(request)));
+  QNetworkReply* reply = _accessManager->get(networkRequest);
 }
 
 void
 HerdictWebReporterPanel::submitInAccessible()
 {
+  /* *** TODO: Make use Tor+SSL *** */
+
+  /* Disable the submit buttons */
+  ui.buttonAccessible->setDisabled(true);
+  ui.buttonInAccessible->setDisabled(true);
+
   /* Construct request */
-  QString request = constructRequest(HerdictWebReporterPanel::InAccessible);
+  QUrl request(constructRequest(HerdictWebReporterPanel::InAccessible));
+  QNetworkRequest networkRequest(request);
+#if 0
+  networkRequest.setSslConfiguration(QSslConfiguration());
+#endif
   /* Send request */
-  QNetworkReply* reply = _accessManager->get(QNetworkRequest(QUrl(request)));
+  QNetworkReply* reply = _accessManager->get(networkRequest);
 }
 
 void
 HerdictWebReporterPanel::torLoadFinished(bool result)
 {
+  /* *** TODO: Add an error page that loads if the request fails *** */
+
   /* Hide the statusbar */
   ui.progressTor->hide();
   if (!result)
@@ -311,12 +345,13 @@
                            ui.comboUsefulnessEntry->currentIndex()).toString());
   request += (QString("&report.reason=") + ui.comboCauseEntry->itemData(
                            ui.comboCauseEntry->currentIndex()).toString());
+  request += (QString("&report.sourceId=") + QString("%1").arg(3));
   request += (QString("&report.tag=") + ui.comboCategoryEntry->itemData(
                            ui.comboCategoryEntry->currentIndex()).toString());
   request += (QString("&report.comments=") +ui.textCommentEntry->toPlainText());
   request += (QString("&report.defaultCountryCode=") + _defaultCountryCode);
   request += (QString("&report.defaultISPName=") + _defaultISP);
-  request += (QString("&report.rot13=VidaliaPlugin"));
+  request += (QString("&encoding=none"));
 
   return request;
 }
@@ -324,9 +359,7 @@
 void
 HerdictWebReporterPanel::populateHerdictOptions()
 {
-  /* If no access manager, create one */
-  if (!_accessManager)
-    _accessManager = new QNetworkAccessManager(this);
+  /* *** TODO: Make all requests use SSL ***  */
 
   /* When access manager finishes a request, will send signal to handler */
   connect(_accessManager, SIGNAL(finished(QNetworkReply*)), 

Modified: vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.h
===================================================================
--- vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.h	2009-07-30 02:02:46 UTC (rev 3986)
+++ vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.h	2009-07-30 22:42:10 UTC (rev 3987)
@@ -77,6 +77,7 @@
   QLabel* _statusWidget;
   /** Access manager. Used for HerdictWeb requests */
   QNetworkAccessManager* _accessManager;
+  QNetworkAccessManager* _torAccessManager;
 
   /** Needed for the HerdictWeb API */
   QString _defaultCountryCode;

Modified: vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.ui
===================================================================
--- vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.ui	2009-07-30 02:02:46 UTC (rev 3986)
+++ vidalia/branches/extension-api/src/vidalia/HerdictWebReporterPlugin/HerdictWebReporterPanel.ui	2009-07-30 22:42:10 UTC (rev 3987)
@@ -57,6 +57,25 @@
     <property name="margin">
      <number>0</number>
     </property>
+    <item row="0" column="0" colspan="2">
+     <widget class="QLabel" name="lblHeaderBackground">
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+      <property name="pixmap">
+       <pixmap resource="../res/vidalia.qrc">:/herdict/herdict/herdict-header-background.gif</pixmap>
+      </property>
+      <property name="scaledContents">
+       <bool>true</bool>
+      </property>
+     </widget>
+    </item>
     <item row="1" column="0">
      <layout class="QVBoxLayout" name="verticalLayoutFields">
       <property name="sizeConstraint">
@@ -338,44 +357,16 @@
       </item>
      </layout>
     </item>
-    <item row="0" column="0" colspan="2">
-     <widget class="QLabel" name="lblHeaderBackground">
-      <property name="sizePolicy">
-       <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-        <horstretch>0</horstretch>
-        <verstretch>0</verstretch>
-       </sizepolicy>
-      </property>
-      <property name="text">
-       <string/>
-      </property>
-      <property name="pixmap">
-       <pixmap resource="../res/vidalia.qrc">:/herdict/herdict/herdict-header-background.gif</pixmap>
-      </property>
-      <property name="scaledContents">
-       <bool>true</bool>
-      </property>
-     </widget>
-    </item>
     <item row="1" column="1">
      <widget class="QSplitter" name="splitter">
-      <property name="sizePolicy">
-       <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-        <horstretch>0</horstretch>
-        <verstretch>0</verstretch>
-       </sizepolicy>
-      </property>
       <property name="orientation">
        <enum>Qt::Horizontal</enum>
       </property>
-      <widget class="QWidget" name="layoutWidgetTor">
-       <layout class="QVBoxLayout" name="verticalLayoutTor">
+      <widget class="QWidget" name="">
+       <layout class="QVBoxLayout" name="verticalLayout">
         <property name="spacing">
          <number>0</number>
         </property>
-        <property name="sizeConstraint">
-         <enum>QLayout::SetNoConstraint</enum>
-        </property>
         <item>
          <widget class="QWebView" name="webViewTor">
           <property name="sizePolicy">
@@ -392,25 +383,46 @@
          </widget>
         </item>
         <item>
-         <widget class="QProgressBar" name="progressTor">
-          <property name="enabled">
-           <bool>true</bool>
-          </property>
-          <property name="value">
-           <number>24</number>
-          </property>
-         </widget>
+         <layout class="QHBoxLayout" name="horizontalLayout">
+          <item>
+           <widget class="QLabel" name="label">
+            <property name="text">
+             <string>As seen by Tor</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item>
+           <widget class="QProgressBar" name="progressTor">
+            <property name="enabled">
+             <bool>true</bool>
+            </property>
+            <property name="value">
+             <number>24</number>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </item>
        </layout>
       </widget>
-      <widget class="QWidget" name="layoutWidgetPlain">
-       <layout class="QVBoxLayout" name="verticalLayoutPlain">
+      <widget class="QWidget" name="">
+       <layout class="QVBoxLayout" name="verticalLayout_2">
         <property name="spacing">
          <number>0</number>
         </property>
-        <property name="sizeConstraint">
-         <enum>QLayout::SetNoConstraint</enum>
-        </property>
         <item>
          <widget class="QWebView" name="webViewPlain">
           <property name="sizePolicy">
@@ -427,20 +439,44 @@
          </widget>
         </item>
         <item>
-         <widget class="QProgressBar" name="progressPlain">
-          <property name="enabled">
-           <bool>true</bool>
-          </property>
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-            <horstretch>0</horstretch>
-            <verstretch>0</verstretch>
-           </sizepolicy>
-          </property>
-          <property name="value">
-           <number>24</number>
-          </property>
-         </widget>
+         <layout class="QHBoxLayout" name="horizontalLayout_2">
+          <item>
+           <widget class="QLabel" name="label_2">
+            <property name="text">
+             <string>As seen by your ISP</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer_2">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item>
+           <widget class="QProgressBar" name="progressPlain">
+            <property name="enabled">
+             <bool>true</bool>
+            </property>
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="value">
+             <number>24</number>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </item>
        </layout>
       </widget>
@@ -469,8 +505,24 @@
      <pixmap resource="../res/vidalia.qrc">:/herdict/herdict/herdict-logo.gif</pixmap>
     </property>
    </widget>
+   <widget class="QLabel" name="lblSiteInformation">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>70</y>
+      <width>951</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string/>
+    </property>
+   </widget>
    <zorder>lblHeaderBackground</zorder>
    <zorder>splitter</zorder>
+   <zorder>label</zorder>
+   <zorder>label_2</zorder>
+   <zorder>lblSiteInformation</zorder>
    <zorder>lblHerdictLogo</zorder>
   </widget>
  </widget>