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 helpbrowser.h 00024 * \version $Id: helpbrowser.h 1808 2007-07-21 17:02:31Z edmanm $ 00025 * \brief Displays a list of help topics and content 00026 */ 00027 00028 #ifndef _HELPBROWSER_H 00029 #define _HELPBROWSER_H 00030 00031 #include <QMainWindow> 00032 #include <QCloseEvent> 00033 #include <QDomDocument> 00034 #include <QDomElement> 00035 #include <QDomNodeList> 00036 #include <QTreeWidgetItem> 00037 #include <QTextBrowser> 00038 #include <QTextCursor> 00039 #include <gui/common/vidaliawindow.h> 00040 00041 #include "ui_helpbrowser.h" 00042 00043 class HelpBrowser : public VidaliaWindow 00044 { 00045 Q_OBJECT 00046 00047 public: 00048 /** Default constructor **/ 00049 HelpBrowser(QWidget *parent = 0); 00050 00051 public slots: 00052 /** Overrides the default QWidget::show() */ 00053 void showWindow(QString topic = QString()); 00054 00055 private slots: 00056 /** Called when the user clicks "Find Next" */ 00057 void findNext(); 00058 /** Called when the user clicks "Find Previous" */ 00059 void findPrev(); 00060 /** Called when the user starts a search */ 00061 void search(); 00062 /** Called when the user selects a different item in the contents tree */ 00063 void contentsItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev); 00064 /** Called when the user selects a different item in the search tree */ 00065 void searchItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev); 00066 00067 private: 00068 /** Returns the language in which help topics should appear, or English 00069 * ("en") if no translated help files exist for the current GUI language. */ 00070 QString language(); 00071 /** Load the contents of the help topics tree from the specified XML file. */ 00072 void loadContentsFromXml(QString xmlFile); 00073 /** Load the contents of the help topics tree from the given DOM document. */ 00074 bool loadContents(const QDomDocument *document, QString &errorString); 00075 /** Parse a Topic element and handle all its children. */ 00076 void parseHelpTopic(const QDomElement &element, QTreeWidgetItem *parent); 00077 /** Returns true if the given Topic element has the necessary attributes. */ 00078 bool isValidTopicElement(const QDomElement &topicElement); 00079 /** Builds a resource path to an html file associated with a help topic. */ 00080 QString getResourcePath(const QDomElement &topicElement); 00081 /** Searches the current page for the phrase in the Find box */ 00082 void find(bool forward); 00083 /** Creates a new item to be placed in the topic tree. */ 00084 QTreeWidgetItem* createTopicTreeItem(const QDomElement &topicElement, 00085 QTreeWidgetItem *parent); 00086 /** Called when the user selects a different item in the tree. */ 00087 void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev); 00088 /** Finds a topic in the topic tree. */ 00089 QTreeWidgetItem* findTopicItem(QTreeWidgetItem *startItem, QString topic); 00090 /** Shows the help browser and finds a specific a topic in the browser. */ 00091 void showTopic(QString topic); 00092 00093 /** List of DOM elements representing topics. */ 00094 QList<QDomElement> _elementList; 00095 /** Last phrase used for 'Find' */ 00096 QString _lastFind; 00097 /** Last phrase searched on */ 00098 QString _lastSearch; 00099 /** Indicates if phrase was previously found on current page */ 00100 bool _foundBefore; 00101 00102 /** Qt Designer generated QObject */ 00103 Ui::HelpBrowser ui; 00104 }; 00105 00106 #endif 00107