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