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

[vidalia-svn] r2679: Support clickable external links in the help browser. If an (in vidalia: . trunk/src/vidalia/help/browser)



Author: edmanm
Date: 2008-06-09 23:07:10 -0400 (Mon, 09 Jun 2008)
New Revision: 2679

Modified:
   vidalia/
   vidalia/trunk/src/vidalia/help/browser/helptextbrowser.cpp
   vidalia/trunk/src/vidalia/help/browser/helptextbrowser.h
Log:
 r486@thebe:  edmanm | 2008-06-09 23:04:58 -0400
 Support clickable external links in the help browser. If an external link is
 clicked, warn the user that their request might not be anonymous. (This is a
 message box that could likely use one of those 'Yeah, I know. Stop telling
 me.' buttons.) If they're cool with that, then open the link in their default
 web browser.



Property changes on: vidalia
___________________________________________________________________
 svk:merge ticket from /local/vidalia [r486] on 45a62a8a-8088-484c-baad-c7b3e776dd32

Modified: vidalia/trunk/src/vidalia/help/browser/helptextbrowser.cpp
===================================================================
--- vidalia/trunk/src/vidalia/help/browser/helptextbrowser.cpp	2008-06-08 17:57:34 UTC (rev 2678)
+++ vidalia/trunk/src/vidalia/help/browser/helptextbrowser.cpp	2008-06-10 03:07:10 UTC (rev 2679)
@@ -16,6 +16,9 @@
 
 #include <QDir>
 #include <QFile>
+#include <QDesktopServices>
+#include <vmessagebox.h>
+#include <html.h>
 #include <vidalia.h>
 
 #include "helptextbrowser.h"
@@ -23,8 +26,9 @@
 
 /** Default constructor. */
 HelpTextBrowser::HelpTextBrowser(QWidget *parent)
-: QTextBrowser(parent)
+  : QTextBrowser(parent)
 {
+  setOpenExternalLinks(false);
 }
 
 /** Loads a resource into the browser. If it is an HTML resource, we'll load
@@ -55,3 +59,40 @@
   return QTextBrowser::loadResource(type, name);
 }
 
+
+/** Called when the displayed document is changed. If <b>url</b> specifies
+ * an external link, then the user will be prompted for whether they want to
+ * open the link in their default browser or not. */
+void
+HelpTextBrowser::setSource(const QUrl &url)
+{
+  if (url.scheme() != "qrc" && !url.isRelative()) {
+    /* External link. Prompt the user for a response. */
+    int ret = VMessageBox::question(this,
+                tr("Opening External Link"),
+                p(tr("Vidalia can open the link you selected in your default "
+                     "Web browser. If your browser is not currently "
+                     "configured to use Tor then the request will not be "
+                     "anonymous.")) +
+                p(tr("Do you want Vidalia to open the link in your Web "
+                     "browser?")),
+                VMessageBox::Yes|VMessageBox::Default, 
+                VMessageBox::Cancel|VMessageBox::Cancel);
+    
+    if (ret == VMessageBox::Cancel)
+      return;
+    
+    bool ok = QDesktopServices::openUrl(url);
+    if (!ok) {
+      VMessageBox::information(this,
+        tr("Unable to Open Link"),
+        tr("Vidalia was unable to open the selected link in your Web browser. "
+           "You can still copy the URL and paste it into your browser."),
+        VMessageBox::Ok);
+    }
+  } else {
+    /* Internal link. Just load it like normal. */
+    QTextBrowser::setSource(url);
+  }
+}
+

Modified: vidalia/trunk/src/vidalia/help/browser/helptextbrowser.h
===================================================================
--- vidalia/trunk/src/vidalia/help/browser/helptextbrowser.h	2008-06-08 17:57:34 UTC (rev 2678)
+++ vidalia/trunk/src/vidalia/help/browser/helptextbrowser.h	2008-06-10 03:07:10 UTC (rev 2679)
@@ -30,6 +30,12 @@
   HelpTextBrowser(QWidget *parent = 0);
   /** Loads a resource into the browser. */
   QVariant loadResource(int type, const QUrl &name);
+
+public slots:
+  /** Called when the displayed document is changed. If <b>url</b> specifies
+   * an external link, then the user will be prompted for whether they want to
+   * open the link in their default browser or not. */
+  virtual void setSource(const QUrl &url);
 };
 
 #endif