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