helptextbrowser.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <QDir>
00018 #include <QFile>
00019 #include <QDesktopServices>
00020 #include <vmessagebox.h>
00021 #include <html.h>
00022 #include <vidalia.h>
00023
00024 #include "helptextbrowser.h"
00025
00026
00027
00028 HelpTextBrowser::HelpTextBrowser(QWidget *parent)
00029 : QTextBrowser(parent)
00030 {
00031 setOpenExternalLinks(false);
00032 }
00033
00034
00035
00036 QVariant
00037 HelpTextBrowser::loadResource(int type, const QUrl &name)
00038 {
00039
00040 if (type == QTextDocument::HtmlResource) {
00041 QString helpPath = ":/help/";
00042
00043
00044
00045 if (!name.path().contains("/")) {
00046 QString language = Vidalia::language();
00047 if (!QDir(":/help/" + language).exists())
00048 language = "en";
00049 helpPath += language + "/";
00050 }
00051
00052 QFile file(helpPath + name.path());
00053 if (!file.open(QIODevice::ReadOnly)) {
00054 return tr("Error opening help file: ") + name.path();
00055 }
00056 return QString::fromUtf8(file.readAll());
00057 }
00058
00059 return QTextBrowser::loadResource(type, name);
00060 }
00061
00062
00063
00064
00065
00066 void
00067 HelpTextBrowser::setSource(const QUrl &url)
00068 {
00069 if (url.scheme() != "qrc" && !url.isRelative()) {
00070
00071 int ret = VMessageBox::question(this,
00072 tr("Opening External Link"),
00073 p(tr("Vidalia can open the link you selected in your default "
00074 "Web browser. If your browser is not currently "
00075 "configured to use Tor then the request will not be "
00076 "anonymous.")) +
00077 p(tr("Do you want Vidalia to open the link in your Web "
00078 "browser?")),
00079 VMessageBox::Yes|VMessageBox::Default,
00080 VMessageBox::Cancel|VMessageBox::Cancel);
00081
00082 if (ret == VMessageBox::Cancel)
00083 return;
00084
00085 bool ok = QDesktopServices::openUrl(url);
00086 if (!ok) {
00087 VMessageBox::information(this,
00088 tr("Unable to Open Link"),
00089 tr("Vidalia was unable to open the selected link in your Web browser. "
00090 "You can still copy the URL and paste it into your browser."),
00091 VMessageBox::Ok);
00092 }
00093 } else {
00094
00095 QTextBrowser::setSource(url);
00096 }
00097 }
00098