| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the Qt Assistant of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #ifndef HELPDIALOG_H | 
|---|
| 43 | #define HELPDIALOG_H | 
|---|
| 44 |  | 
|---|
| 45 | #include "ui_helpdialog.h" | 
|---|
| 46 | #include "index.h" | 
|---|
| 47 | #include "helpwindow.h" | 
|---|
| 48 | #include "docuparser.h" | 
|---|
| 49 |  | 
|---|
| 50 | #include <QList> | 
|---|
| 51 | #include <QPair> | 
|---|
| 52 | #include <QListWidget> | 
|---|
| 53 | #include <QTreeWidget> | 
|---|
| 54 | #include <QMap> | 
|---|
| 55 | #include <QStringList> | 
|---|
| 56 | #include <QValidator> | 
|---|
| 57 | #include <qmenu.h> | 
|---|
| 58 | #include <QHash> | 
|---|
| 59 |  | 
|---|
| 60 | QT_BEGIN_NAMESPACE | 
|---|
| 61 |  | 
|---|
| 62 | class QProgressBar; | 
|---|
| 63 | class MainWindow; | 
|---|
| 64 | class QTextBrowser; | 
|---|
| 65 | class IndexListModel; | 
|---|
| 66 |  | 
|---|
| 67 | class HelpNavigationListItem : public QListWidgetItem | 
|---|
| 68 | { | 
|---|
| 69 | public: | 
|---|
| 70 | HelpNavigationListItem(QListWidget *ls, const QString &txt); | 
|---|
| 71 |  | 
|---|
| 72 | void addLink(const QString &link); | 
|---|
| 73 | QStringList links() const { return linkList; } | 
|---|
| 74 | private: | 
|---|
| 75 | QStringList linkList; | 
|---|
| 76 |  | 
|---|
| 77 | }; | 
|---|
| 78 |  | 
|---|
| 79 | class SearchValidator : public QValidator | 
|---|
| 80 | { | 
|---|
| 81 | Q_OBJECT | 
|---|
| 82 | public: | 
|---|
| 83 | SearchValidator(QObject *parent) | 
|---|
| 84 | : QValidator(parent) {} | 
|---|
| 85 | ~SearchValidator() {} | 
|---|
| 86 | QValidator::State validate(QString &str, int &) const; | 
|---|
| 87 | }; | 
|---|
| 88 |  | 
|---|
| 89 | class HelpDialog : public QWidget | 
|---|
| 90 | { | 
|---|
| 91 | Q_OBJECT | 
|---|
| 92 | public: | 
|---|
| 93 | HelpDialog(QWidget *parent, MainWindow *h); | 
|---|
| 94 |  | 
|---|
| 95 | inline QTabWidget *tabWidget() const | 
|---|
| 96 | { return ui.tabWidget; } | 
|---|
| 97 |  | 
|---|
| 98 | QString titleOfLink(const QString &link); | 
|---|
| 99 | bool eventFilter(QObject *, QEvent *); | 
|---|
| 100 | bool lastWindowClosed() { return lwClosed; } | 
|---|
| 101 |  | 
|---|
| 102 | void timerEvent(QTimerEvent *e); | 
|---|
| 103 | static QString removeAnchorFromLink(const QString &link); | 
|---|
| 104 |  | 
|---|
| 105 | signals: | 
|---|
| 106 | void showLink(const QString &s); | 
|---|
| 107 | void showSearchLink(const QString &s, const QStringList &terms); | 
|---|
| 108 |  | 
|---|
| 109 | public slots: | 
|---|
| 110 | void initialize(); | 
|---|
| 111 | void startSearch(); | 
|---|
| 112 | void addBookmark(); | 
|---|
| 113 | void currentTabChanged(int index); | 
|---|
| 114 | void locateContents(const QString &link); | 
|---|
| 115 |  | 
|---|
| 116 | private slots: | 
|---|
| 117 | void on_buttonAdd_clicked(); | 
|---|
| 118 | void on_buttonRemove_clicked(); | 
|---|
| 119 | void on_termsEdit_returnPressed(); | 
|---|
| 120 | void on_helpButton_clicked(); | 
|---|
| 121 | void on_searchButton_clicked(); | 
|---|
| 122 | void on_resultBox_itemActivated(QListWidgetItem*); | 
|---|
| 123 | void updateSearchButton(const QString &txt); | 
|---|
| 124 |  | 
|---|
| 125 | void showResultPage(QListWidgetItem *); | 
|---|
| 126 |  | 
|---|
| 127 | void showTopic(QTreeWidgetItem *); | 
|---|
| 128 | void loadIndexFile(); | 
|---|
| 129 | void insertContents(); | 
|---|
| 130 | void setupFullTextIndex(); | 
|---|
| 131 | void showTopic(); | 
|---|
| 132 | void searchInIndex(const QString &s); | 
|---|
| 133 | void toggleContents(); | 
|---|
| 134 | void toggleIndex(); | 
|---|
| 135 | void toggleBookmarks(); | 
|---|
| 136 | void toggleSearch(); | 
|---|
| 137 | void lastWinClosed(); | 
|---|
| 138 | void setIndexingProgress(int prog); | 
|---|
| 139 | void showListItemMenu(const QPoint &pos); | 
|---|
| 140 | void showIndexItemMenu(const QPoint &pos); | 
|---|
| 141 | void showTreeItemMenu(const QPoint &pos); | 
|---|
| 142 | void insertBookmarks(); | 
|---|
| 143 | void processEvents(); | 
|---|
| 144 |  | 
|---|
| 145 | private: | 
|---|
| 146 | typedef QList<ContentItem> ContentList; | 
|---|
| 147 | void removeOldCacheFiles(bool onlyFulltextSearchIndex = false); | 
|---|
| 148 | void buildKeywordDB(); | 
|---|
| 149 | quint32 getFileAges(); | 
|---|
| 150 | void showIndexTopic(); | 
|---|
| 151 | void showBookmarkTopic(); | 
|---|
| 152 | void setupTitleMap(); | 
|---|
| 153 | void saveBookmarks(); | 
|---|
| 154 | void showContentsTopic(); | 
|---|
| 155 | void showInitDoneMessage(); | 
|---|
| 156 | void buildContentDict(); | 
|---|
| 157 | QTreeWidgetItem * locateLink(QTreeWidgetItem *item, const QString &link); | 
|---|
| 158 |  | 
|---|
| 159 | private: | 
|---|
| 160 | Ui::HelpDialog ui; | 
|---|
| 161 |  | 
|---|
| 162 | IndexListModel *indexModel; | 
|---|
| 163 | QMap<QString, QString> titleMap; | 
|---|
| 164 | bool indexDone, bookmarksInserted, titleMapDone, contentsInserted; | 
|---|
| 165 | bool lwClosed; | 
|---|
| 166 | MainWindow *help; | 
|---|
| 167 | QString documentationPath; | 
|---|
| 168 | Index *fullTextIndex; | 
|---|
| 169 | QStringList terms, foundDocs; | 
|---|
| 170 | bool initDoneMsgShown; | 
|---|
| 171 | void getAllContents(); | 
|---|
| 172 | QList<QPair<QString, ContentList> > contentList; | 
|---|
| 173 | QMenu *itemPopup; | 
|---|
| 174 | QString cacheFilesPath; | 
|---|
| 175 | QStringList keywordDocuments; | 
|---|
| 176 |  | 
|---|
| 177 | QAction *actionOpenCurrentTab; | 
|---|
| 178 | QAction *actionOpenLinkInNewWindow; | 
|---|
| 179 | QAction *actionOpenLinkInNewTab; | 
|---|
| 180 | }; | 
|---|
| 181 |  | 
|---|
| 182 | QT_END_NAMESPACE | 
|---|
| 183 |  | 
|---|
| 184 | #endif // HELPDIALOG_H | 
|---|