Vidalia 0.2.15
HelpBrowser.h
Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file HelpBrowser.h
00013 ** \brief Displays a list of help topics and content
00014 */
00015 
00016 #ifndef _HELPBROWSER_H
00017 #define _HELPBROWSER_H
00018 
00019 #include "ui_HelpBrowser.h"
00020 #include "VidaliaWindow.h"
00021 
00022 #include <QMainWindow>
00023 #include <QCloseEvent>
00024 #include <QDomDocument>
00025 #include <QDomElement>
00026 #include <QDomNodeList>
00027 #include <QTreeWidgetItem>
00028 #include <QTextBrowser>
00029 #include <QTextCursor>
00030 
00031 
00032 class HelpBrowser : public VidaliaWindow
00033 {
00034   Q_OBJECT
00035 
00036 public:
00037   /** Default constructor **/
00038   HelpBrowser(QWidget *parent = 0);
00039  
00040 public slots:
00041   /** Overrides the default QWidget::show() */
00042   void showWindow(QString topic = QString());
00043 
00044 protected:
00045   /** Called when the user changes the UI translation. */
00046   virtual void retranslateUi();
00047 
00048 private slots:
00049   /** Called when the user clicks "Find Next" */
00050   void findNext();
00051   /** Called when the user clicks "Find Previous" */
00052   void findPrev();
00053   /** Called when the user starts a search */
00054   void search();
00055   /** Called when the user selects a different item in the contents tree */
00056   void contentsItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev);
00057   /** Called when the user selects a different item in the search tree */
00058   void searchItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev);
00059    
00060 private:
00061   /** Returns the language in which help topics should appear, or English
00062    * ("en") if no translated help files exist for the current GUI language. */
00063   QString language();
00064   /** Load the contents of the help topics tree from the specified XML file. */
00065   void loadContentsFromXml(QString xmlFile);
00066   /** Load the contents of the help topics tree from the given DOM document. */
00067   bool loadContents(const QDomDocument *document, QString &errorString);
00068   /** Parse a Topic element and handle all its children. */
00069   void parseHelpTopic(const QDomElement &element, QTreeWidgetItem *parent);
00070   /** Returns true if the given Topic element has the necessary attributes. */
00071   bool isValidTopicElement(const QDomElement &topicElement);
00072   /** Builds a resource path to an html file associated with a help topic. */
00073   QString getResourcePath(const QDomElement &topicElement);
00074   /** Searches the current page for the phrase in the Find box */
00075   void find(bool forward);
00076   /** Creates a new item to be placed in the topic tree. */
00077   QTreeWidgetItem* createTopicTreeItem(const QDomElement &topicElement,
00078                                        QTreeWidgetItem *parent);
00079   /** Called when the user selects a different item in the tree. */
00080   void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev);
00081   /** Finds a topic in the topic tree. */
00082   QTreeWidgetItem* findTopicItem(QTreeWidgetItem *startItem, QString topic);
00083   /** Shows the help browser and finds a specific a topic in the browser. */
00084   void showTopic(QString topic);
00085 
00086   /** List of DOM elements representing topics. */
00087   QList<QDomElement> _elementList;
00088   /** Last phrase used for 'Find' */
00089   QString _lastFind;
00090   /** Last phrase searched on */
00091   QString _lastSearch;
00092   /** Indicates if phrase was previously found on current page */
00093   bool _foundBefore;
00094 
00095   /** Qt Designer generated QObject */
00096   Ui::HelpBrowser ui;
00097 };
00098 
00099 #endif
00100