helptextbrowser.cpp

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /** 
00023  * \file helptextbrowser.cpp
00024  * \version $Id: helptextbrowser.cpp 1563 2006-12-26 06:06:04Z edmanm $
00025  * \brief Displays an HTML-based help document
00026  */
00027 
00028 #include <QFile>
00029 #include <vidalia.h>
00030 
00031 #include "helptextbrowser.h"
00032 
00033 /** Default constructor. */
00034 HelpTextBrowser::HelpTextBrowser(QWidget *parent)
00035 : QTextBrowser(parent)
00036 {
00037 }
00038 
00039 /** Loads a resource into the browser. If it is an HTML resource, we'll load
00040  * it as UTF-8, so the special characters in our translations appear properly. */
00041 QVariant
00042 HelpTextBrowser::loadResource(int type, const QUrl &name)
00043 {
00044   /* If it's an HTML file, we'll handle it ourselves */
00045   if (type == QTextDocument::HtmlResource) {
00046     QString helpPath = ":/help/";
00047     
00048 #if QT_VERSION >= 0x040104
00049     /* On Qt 4.1.4 or later, name.path() only includes the filename (not
00050      * the language code) for pages accessed by clicking on a link in another
00051      * page, so add it now if there isn't a path already. */
00052     if (!name.path().contains("/")) {
00053       helpPath += Vidalia::language() + "/";
00054     } 
00055 #endif
00056     
00057     QFile file(helpPath + name.path());
00058     if (!file.open(QIODevice::ReadOnly)) {
00059       return tr("Error opening help file: ") + name.path();
00060     }
00061     return QString::fromUtf8(file.readAll());
00062   }
00063   /* Everything else, just let QTextBrowser take care of it. */
00064   return QTextBrowser::loadResource(type, name);
00065 }
00066 

Generated on Wed Sep 5 15:49:27 2007 for Vidalia by  doxygen 1.5.3