Vidalia  0.3.1
HelpBrowser.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file HelpBrowser.h
13 ** \brief Displays a list of help topics and content
14 */
15 
16 #ifndef _HELPBROWSER_H
17 #define _HELPBROWSER_H
18 
19 #include "ui_HelpBrowser.h"
20 #include "VidaliaWindow.h"
21 
22 #include <QMainWindow>
23 #include <QCloseEvent>
24 #include <QDomDocument>
25 #include <QDomElement>
26 #include <QDomNodeList>
27 #include <QTreeWidgetItem>
28 #include <QTextBrowser>
29 #include <QTextCursor>
30 
31 
32 class HelpBrowser : public VidaliaWindow
33 {
34  Q_OBJECT
35 
36 public:
37  /** Default constructor **/
38  HelpBrowser(QWidget *parent = 0);
39 
40 public slots:
41  /** Overrides the default QWidget::show() */
42  void showWindow(QString topic = QString());
43 
44 protected:
45  /** Called when the user changes the UI translation. */
46  virtual void retranslateUi();
47 
48 private slots:
49  /** Called when the user clicks "Find Next" */
50  void findNext();
51  /** Called when the user clicks "Find Previous" */
52  void findPrev();
53  /** Called when the user starts a search */
54  void search();
55  /** Called when the user selects a different item in the contents tree */
56  void contentsItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev);
57  /** Called when the user selects a different item in the search tree */
58  void searchItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev);
59 
60 private:
61  /** Returns the language in which help topics should appear, or English
62  * ("en") if no translated help files exist for the current GUI language. */
63  QString language();
64  /** Load the contents of the help topics tree from the specified XML file. */
65  void loadContentsFromXml(QString xmlFile);
66  /** Load the contents of the help topics tree from the given DOM document. */
67  bool loadContents(const QDomDocument *document, QString &errorString);
68  /** Parse a Topic element and handle all its children. */
69  void parseHelpTopic(const QDomElement &element, QTreeWidgetItem *parent);
70  /** Returns true if the given Topic element has the necessary attributes. */
71  bool isValidTopicElement(const QDomElement &topicElement);
72  /** Builds a resource path to an html file associated with a help topic. */
73  QString getResourcePath(const QDomElement &topicElement);
74  /** Searches the current page for the phrase in the Find box */
75  void find(bool forward);
76  /** Creates a new item to be placed in the topic tree. */
77  QTreeWidgetItem* createTopicTreeItem(const QDomElement &topicElement,
78  QTreeWidgetItem *parent);
79  /** Called when the user selects a different item in the tree. */
80  void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev);
81  /** Finds a topic in the topic tree. */
82  QTreeWidgetItem* findTopicItem(QTreeWidgetItem *startItem, QString topic);
83  /** Shows the help browser and finds a specific a topic in the browser. */
84  void showTopic(QString topic);
85 
86  /** List of DOM elements representing topics. */
87  QList<QDomElement> _elementList;
88  /** Last phrase used for 'Find' */
89  QString _lastFind;
90  /** Last phrase searched on */
91  QString _lastSearch;
92  /** Indicates if phrase was previously found on current page */
94 
95  /** Qt Designer generated QObject */
96  Ui::HelpBrowser ui;
97 };
98 
99 #endif
100