diff --git a/src/plugins/help/contentstoolwindow.cpp b/src/plugins/help/contentstoolwindow.cpp deleted file mode 100644 index 65245c71f1a8b39b3a32d957e0521f6e431b9d40..0000000000000000000000000000000000000000 --- a/src/plugins/help/contentstoolwindow.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -**************************************************************************/ - -#include "contentstoolwindow.h" -#include "helpengine.h" - -#include <QtCore/QDebug> -#include <QtCore/QStack> -#include <QtGui/QFocusEvent> -#include <QtGui/QKeyEvent> - -using namespace Help::Internal; - -ContentsToolWidget::ContentsToolWidget() -{ - wasInitialized = false; - - setRootIsDecorated(true); - setItemHidden(headerItem(), true); - setUniformRowHeights(true); - setColumnCount(1); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - setWindowTitle(tr("Contents")); - setWindowIcon(QIcon(":/help/images/book.png")); -} - -void ContentsToolWidget::focusInEvent(QFocusEvent *e) -{ - if (wasInitialized) { - if (e && e->reason() != Qt::MouseFocusReason - && !currentItem() && topLevelItemCount()) - setCurrentItem(topLevelItem(0)); - return; - } - wasInitialized = true; - setCursor(QCursor(Qt::WaitCursor)); - emit buildRequested(); -} - -void ContentsToolWidget::showEvent(QShowEvent *) -{ - if (wasInitialized) - return; - wasInitialized = true; - setCursor(QCursor(Qt::WaitCursor)); - emit buildRequested(); -} - -void ContentsToolWidget::keyPressEvent(QKeyEvent *e) -{ - if (e && e->key() == Qt::Key_Escape) { - emit escapePressed(); - e->accept(); - return; - } - QTreeWidget::keyPressEvent(e); -} - - -enum -{ - LinkRole = Qt::UserRole + 1000 -}; - -ContentsToolWindow::ContentsToolWindow(const QList<int> &context, HelpEngine *help) -{ - m_widget = new ContentsToolWidget; - helpEngine = help; - connect(helpEngine, SIGNAL(contentsInitialized()), this, SLOT(contentsDone())); - connect(m_widget, SIGNAL(buildRequested()), helpEngine, SLOT(buildContents())); - - m_context = context; - m_context << 0; - - connect(m_widget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(indexRequested())); - connect(m_widget, SIGNAL(escapePressed()), this, SIGNAL(escapePressed())); -} - -ContentsToolWindow::~ContentsToolWindow() -{ - delete m_widget; -} - -const QList<int> &ContentsToolWindow::context() const -{ - return m_context; -} - -QWidget *ContentsToolWindow::widget() -{ - return m_widget; -} - -void ContentsToolWindow::contentsDone() -{ - m_widget->setCursor(QCursor(Qt::WaitCursor)); - QList<QPair<QString, ContentList> > contentList = helpEngine->contents(); - for (QList<QPair<QString, ContentList> >::Iterator it = contentList.begin(); it != contentList.end(); ++it) { - QTreeWidgetItem *newEntry; - QTreeWidgetItem *contentEntry; - QStack<QTreeWidgetItem*> stack; - stack.clear(); - int depth = 0; - bool root = false; - - QTreeWidgetItem *lastItem[64]; - for (int j = 0; j < 64; ++j) - lastItem[j] = 0; - - ContentList lst = (*it).second; - for (ContentList::ConstIterator it = lst.begin(); it != lst.end(); ++it) { - ContentItem item = *it; - if (item.depth == 0) { - newEntry = new QTreeWidgetItem(m_widget, 0); - newEntry->setIcon(0, QIcon(QString::fromUtf8(":/help/images/book.png"))); - newEntry->setText(0, item.title); - newEntry->setData(0, LinkRole, item.reference); - stack.push(newEntry); - depth = 1; - root = true; - } else { - if (item.depth > depth && root) { - depth = item.depth; - stack.push(contentEntry); - } - if (item.depth == depth) { - contentEntry = new QTreeWidgetItem(stack.top(), lastItem[ depth ]); - lastItem[ depth ] = contentEntry; - contentEntry->setText(0, item.title); - contentEntry->setData(0, LinkRole, item.reference); - } - else if (item.depth < depth) { - stack.pop(); - depth--; - item = *(--it); - } - } - } - } - m_widget->setCursor(QCursor(Qt::ArrowCursor)); -} - -void ContentsToolWindow::indexRequested() -{ - QTreeWidgetItem *itm = m_widget->currentItem(); - if (!itm) - return; - emit showLinkRequested(itm->data(0, LinkRole).toString(), false); -} diff --git a/src/plugins/help/contentstoolwindow.h b/src/plugins/help/contentstoolwindow.h deleted file mode 100644 index d62eb27097d4567c19e8ce53512583ce61ac859e..0000000000000000000000000000000000000000 --- a/src/plugins/help/contentstoolwindow.h +++ /dev/null @@ -1,100 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -**************************************************************************/ - -#ifndef CONTENTSTOOLWINDOW_H -#define CONTENTSTOOLWINDOW_H - -#include <coreplugin/iview.h> - -#include <QtGui/QTreeWidget> - -namespace Help { -namespace Internal { - -class HelpEngine; -class ContentsToolWindow; - -class ContentsToolWidget : public QTreeWidget -{ - Q_OBJECT - -public: - ContentsToolWidget(); - -signals: - void buildRequested(); - void escapePressed(); - -private: - friend class ContentsToolWindow; - void showEvent(QShowEvent *e); - void focusInEvent(QFocusEvent *e); - void keyPressEvent(QKeyEvent *e); - - bool wasInitialized; -}; - -class ContentsToolWindow : public Core::IView -{ - Q_OBJECT - -public: - ContentsToolWindow(const QList<int> &context, HelpEngine *help); - ~ContentsToolWindow(); - - const QList<int> &context() const; - QWidget *widget(); - - QList<QWidget*> dockToolBarWidgets() const { return QList<QWidget*>(); } - - const char *uniqueViewName() const { return "Help.ContentsToolWindow"; } - const char *globalMenuGroup() const { return "Help.Group"; } - inline QKeySequence defaultShortcut() const { return QKeySequence(); } - Qt::DockWidgetArea defaultArea() const { return Qt::RightDockWidgetArea; } - IView::ViewPosition defaultPosition() const { return IView::First; } - -signals: - void showLinkRequested(const QString &link, bool newWindow); - void escapePressed(); - -private slots: - void contentsDone(); - void indexRequested(); - -private: - HelpEngine *helpEngine; - - QList<int> m_context; - ContentsToolWidget *m_widget; -}; - -} // namespace Internal -} // namespace Help - -#endif // CONTENTSTOOLWINDOW_H diff --git a/src/plugins/help/helpengine.cpp b/src/plugins/help/helpengine.cpp deleted file mode 100644 index a58360a7a7d15b6cc97f04bdcf0edb1efa043e58..0000000000000000000000000000000000000000 --- a/src/plugins/help/helpengine.cpp +++ /dev/null @@ -1,588 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -**************************************************************************/ - -#include "helpengine.h" -#include "config.h" - -#include <QtCore/QDebug> -#include <QtCore/QDir> -#include <QtCore/QDateTime> -#include <QtCore/QCoreApplication> - -using namespace Help::Internal; - -static bool verifyDirectory(const QString &str) -{ - QFileInfo dirInfo(str); - if (!dirInfo.exists()) - return QDir().mkdir(str); - if (!dirInfo.isDir()) { - qWarning("'%s' exists but is not a directory", str.toLatin1().constData()); - return false; - } - return true; -} - -struct IndexKeyword -{ - IndexKeyword(const QString &kw, const QString &l) - : keyword(kw), link(l) {} - IndexKeyword() : keyword(QString()), link(QString()) {} - bool operator<(const IndexKeyword &ik) const { - return keyword.toLower() < ik.keyword.toLower(); - } - bool operator<=(const IndexKeyword &ik) const { - return keyword.toLower() <= ik.keyword.toLower(); - } - bool operator>(const IndexKeyword &ik) const { - return keyword.toLower() > ik.keyword.toLower(); - } - Q_DUMMY_COMPARISON_OPERATOR(IndexKeyword) - QString keyword; - QString link; -}; - -QDataStream &operator>>(QDataStream &s, IndexKeyword &ik) -{ - s >> ik.keyword; - s >> ik.link; - return s; -} - -QDataStream &operator<<(QDataStream &s, const IndexKeyword &ik) -{ - s << ik.keyword; - s << ik.link; - return s; -} - - -/** - * Compare in a human-preferred alphanumeric way, - * e.g. 'Qt tutorial 2' will be less than 'Qt tutorial 11'. - */ -bool caseInsensitiveLessThan(const QString &as, const QString &bs) -{ - const QChar *a = as.unicode(); - const QChar *b = bs.unicode(); - int result = 0; - while (result == 0) - { - ushort aa = a->unicode(); - ushort bb = b->unicode(); - - if (aa == 0 || bb == 0) { - result = aa - bb; - break; - } - else if (a->isDigit() && b->isDigit()) - { - const QChar *a_begin = a; - const QChar *b_begin = b; - bool loop = true; - do { - if (a->isDigit()) ++a; - else if (b->isDigit()) ++b; - else loop = false; - } while (loop); - - // optimization: comparing the length of the two numbers is more efficient than constructing two qstrings. - result = (a - a_begin) - (b - b_begin); - if (result == 0) { - QString astr(a_begin, a - a_begin); - QString bstr(b_begin, b - b_begin); - long la = astr.toLong(); - long lb = bstr.toLong(); - result = la - lb; - } - } else { - aa = QChar(aa).toLower().unicode(); - bb = QChar(bb).toLower().unicode(); - result = aa - bb; - ++a; - ++b; - } - } - - return result < 0 ? true : false; -} - -/** - * \a real is kinda a hack for the smart search, need a way to match a regexp to an item - * How would you say the best match for Q.*Wiget is QWidget? - */ -QModelIndex IndexListModel::filter(const QString &s, const QString &real) -{ - QStringList list; - - int goodMatch = -1; - int perfectMatch = -1; - if (s.isEmpty()) - perfectMatch = 0; - - const QRegExp regExp(s); - QMultiMap<QString, QString>::iterator it = contents.begin(); - QString lastKey; - for (; it != contents.end(); ++it) { - if (it.key() == lastKey) - continue; - lastKey = it.key(); - const QString key = it.key(); - if (key.contains(regExp) || key.contains(s, Qt::CaseInsensitive)) { - list.append(key); - //qDebug() << regExp << regExp.indexIn(s) << s << key << regExp.matchedLength(); - if (perfectMatch == -1 && (key.startsWith(real, Qt::CaseInsensitive))) { - if (goodMatch == -1) - goodMatch = list.count() - 1; - if (s.length() == key.length()) - perfectMatch = list.count() - 1; - } else if (perfectMatch > -1 && s == key) { - perfectMatch = list.count() - 1; - } - } - } - - int bestMatch = perfectMatch; - if (bestMatch == -1) - bestMatch = goodMatch; - - bestMatch = qMax(0, bestMatch); - - // sort the new list - QString match; - if (bestMatch >= 0 && list.count() > bestMatch) - match = list[bestMatch]; - qSort(list.begin(), list.end(), caseInsensitiveLessThan); - setStringList(list); - for (int i = 0; i < list.size(); ++i) { - if (list.at(i) == match){ - bestMatch = i; - break; - } - } - return index(bestMatch, 0, QModelIndex()); -} - - - -HelpEngine::HelpEngine(QObject *parent, const QString &defaultQtVersionPath) - : QObject(parent) -{ - titleMapThread = new TitleMapThread(this); - connect(titleMapThread, SIGNAL(errorOccured(const QString&)), - this, SIGNAL(errorOccured(const QString&))); - connect(titleMapThread, SIGNAL(finished()), this, SLOT(titleMapFinished())); - indexThread = new IndexThread(this); - connect(indexThread, SIGNAL(errorOccured(const QString&)), - this, SIGNAL(errorOccured(const QString&))); - connect(indexThread, SIGNAL(finished()), this, SLOT(indexFinished())); - - indexModel = new IndexListModel(this); - - Config::loadConfig(defaultQtVersionPath); - cacheFilesPath = QDir::homePath() + QLatin1String("/.assistant"); -} - -HelpEngine::~HelpEngine() -{ - Config::configuration()->save(); -} - -void HelpEngine::init() -{ -} - -QString HelpEngine::cacheFilePath() const -{ - return cacheFilesPath; -} - -IndexListModel *HelpEngine::indices() -{ - return indexModel; -} - -void HelpEngine::buildContents() -{ - contentsOnly = true; - if (!titleMapThread->isRunning()) { - titleMapThread->start(QThread::NormalPriority); - } -} - -void HelpEngine::buildIndex() -{ - if (!titleMapThread->isRunning()) { - contentsOnly = false; - titleMapThread->start(QThread::NormalPriority); - } - if (!indexThread->isRunning()) - indexThread->start(QThread::NormalPriority); -} - -void HelpEngine::titleMapFinished() -{ - contentList = titleMapThread->contents(); - titleMap = titleMapThread->documentTitleMap(); - if (contentsOnly) { - contentsOnly = false; - emit contentsInitialized(); - } -} - -void HelpEngine::indexFinished() -{ - indexModel = indexThread->model(); - emit indexInitialized(); -} - -void HelpEngine::removeOldCacheFiles(bool onlyFulltextSearchIndex) -{ - if (!verifyDirectory(cacheFilesPath)) { - qWarning("Failed to created assistant directory"); - return; - } - QString pname = QLatin1String(".") + Config::configuration()->profileName(); - - QStringList fileList; - fileList << QLatin1String("indexdb40.dict") - << QLatin1String("indexdb40.doc"); - - if (!onlyFulltextSearchIndex) - fileList << QLatin1String("indexdb40") << QLatin1String("contentdb40"); - - QStringList::iterator it = fileList.begin(); - for (; it != fileList.end(); ++it) { - if (QFile::exists(cacheFilesPath + QDir::separator() + *it + pname)) { - QFile f(cacheFilesPath + QDir::separator() + *it + pname); - f.remove(); - } - } -} - -quint32 HelpEngine::getFileAges() -{ - QStringList addDocuFiles = Config::configuration()->docFiles(); - QStringList::const_iterator i = addDocuFiles.begin(); - - quint32 fileAges = 0; - for (; i != addDocuFiles.end(); ++i) { - QFileInfo fi(*i); - if (fi.exists()) - fileAges += fi.lastModified().toTime_t(); - } - - return fileAges; -} - -QString HelpEngine::removeAnchorFromLink(const QString &link) -{ - int i = link.length(); - int j = link.lastIndexOf('/'); - int l = link.lastIndexOf(QDir::separator()); - if (l > j) - j = l; - if (j > -1) { - QString fileName = link.mid(j+1); - int k = fileName.lastIndexOf('#'); - if (k > -1) - i = j + k + 1; - } - return link.left(i); -} - -QString HelpEngine::titleOfLink(const QString &link) -{ - QString s = HelpEngine::removeAnchorFromLink(link); - s = titleMap[s]; - if (s.isEmpty()) - return link; - return s; -} - -QString HelpEngine::home() const -{ - QString link = Config::configuration()->homePage(); - if (!link.startsWith(QLatin1String("file:"))) - link.prepend("file:"); - return link; -} - - - -TitleMapThread::TitleMapThread(HelpEngine *he) - : QThread(he) -{ - engine = he; - done = false; -} - -TitleMapThread::~TitleMapThread() -{ - -} - -void TitleMapThread::run() -{ - if (done) { - engine->mutex.lock(); - engine->titleMapDoneCondition.wakeAll(); - engine->mutex.unlock(); - return; - } - - bool needRebuild = false; - if (Config::configuration()->profileName() == QLatin1String("default")) { - const QStringList docuFiles = Config::configuration()->docFiles(); - for (QStringList::ConstIterator it = docuFiles.begin(); it != docuFiles.end(); it++) { - if (!QFile::exists(*it)) { - Config::configuration()->saveProfile(Profile::createDefaultProfile()); - Config::configuration()->loadDefaultProfile(); - needRebuild = true; - break; - } - } - } - - if (Config::configuration()->docRebuild() || needRebuild) { - engine->removeOldCacheFiles(); - Config::configuration()->setDocRebuild(false); - Config::configuration()->save(); - } - if (contentList.isEmpty()) - getAllContents(); - - titleMap.clear(); - for (QList<QPair<QString, ContentList> >::Iterator it = contentList.begin(); it != contentList.end(); ++it) { - ContentList lst = (*it).second; - foreach (ContentItem item, lst) { - titleMap[item.reference] = item.title.trimmed(); - } - } - done = true; - engine->mutex.lock(); - engine->titleMapDoneCondition.wakeAll(); - engine->mutex.unlock(); -} - -void TitleMapThread::getAllContents() -{ - QFile contentFile(engine->cacheFilePath() + QDir::separator() + QLatin1String("contentdb40.") - + Config::configuration()->profileName()); - contentList.clear(); - if (!contentFile.open(QFile::ReadOnly)) { - buildContentDict(); - return; - } - - QDataStream ds(&contentFile); - quint32 fileAges; - ds >> fileAges; - if (fileAges != engine->getFileAges()) { - contentFile.close(); - engine->removeOldCacheFiles(true); - buildContentDict(); - return; - } - QString key; - QList<ContentItem> lst; - while (!ds.atEnd()) { - ds >> key; - ds >> lst; - contentList += qMakePair(key, QList<ContentItem>(lst)); - } - contentFile.close(); - -} - -void TitleMapThread::buildContentDict() -{ - QStringList docuFiles = Config::configuration()->docFiles(); - - quint32 fileAges = 0; - for (QStringList::iterator it = docuFiles.begin(); it != docuFiles.end(); it++) { - QFile file(*it); - if (!file.exists()) { -#ifdef _SHOW_ERRORS_ - emit errorOccured(tr("Documentation file %1 does not exist!\n" - "Skipping file.").arg(QFileInfo(file).absoluteFilePath())); -#endif - continue; - } - fileAges += QFileInfo(file).lastModified().toTime_t(); - DocuParser *handler = DocuParser::createParser(*it); - if (!handler) { -#ifdef _SHOW_ERRORS_ - emit errorOccured(tr("Documentation file %1 is not compatible!\n" - "Skipping file.").arg(QFileInfo(file).absoluteFilePath())); -#endif - continue; - } - bool ok = handler->parse(&file); - file.close(); - if (ok) { - contentList += qMakePair(*it, QList<ContentItem>(handler->getContentItems())); - delete handler; - } else { -#ifdef _SHOW_ERRORS_ - QString msg = QString::fromLatin1("In file %1:\n%2") - .arg(QFileInfo(file).absoluteFilePath()) - .arg(handler->errorProtocol()); - emit errorOccured(msg); -#endif - continue; - } - } - - QFile contentOut(engine->cacheFilePath() + QDir::separator() + QLatin1String("contentdb40.") - + Config::configuration()->profileName()); - if (contentOut.open(QFile::WriteOnly)) { - QDataStream s(&contentOut); - s << fileAges; - for (QList<QPair<QString, ContentList> >::Iterator it = contentList.begin(); it != contentList.end(); ++it) { - s << *it; - } - contentOut.close(); - } -} - - -IndexThread::IndexThread(HelpEngine *he) - : QThread(he) -{ - engine = he; - indexModel = new IndexListModel(this); - indexDone = false; -} - -void IndexThread::run() -{ - if (indexDone) - return; - engine->mutex.lock(); - if (engine->titleMapThread->isRunning()) - engine->titleMapDoneCondition.wait(&(engine->mutex)); - engine->mutex.unlock(); - - keywordDocuments.clear(); - QList<IndexKeyword> lst; - QFile indexFile(engine->cacheFilePath() + QDir::separator() + QLatin1String("indexdb40.") + - Config::configuration()->profileName()); - if (!indexFile.open(QFile::ReadOnly)) { - buildKeywordDB(); - if (!indexFile.open(QFile::ReadOnly)) { -#ifdef _SHOW_ERRORS_ - emit errorOccured(tr("Failed to load keyword index file!")); -#endif - return; - } - } - - QDataStream ds(&indexFile); - quint32 fileAges; - ds >> fileAges; - if (fileAges != engine->getFileAges()) { - indexFile.close(); - buildKeywordDB(); - if (!indexFile.open(QFile::ReadOnly)) { -#ifdef _SHOW_ERRORS_ - emit errorOccured(tr("Cannot open the index file %1") - .arg(QFileInfo(indexFile).absoluteFilePath())); -#endif - return; - } - ds.setDevice(&indexFile); - ds >> fileAges; - } - ds >> lst; - indexFile.close(); - - for (int i=0; i<lst.count(); ++i) { - const IndexKeyword &idx = lst.at(i); - indexModel->addLink(idx.keyword, idx.link); - keywordDocuments << HelpEngine::removeAnchorFromLink(idx.link); - } - indexModel->publish(); - indexDone = true; -} - -void IndexThread::buildKeywordDB() -{ - QStringList addDocuFiles = Config::configuration()->docFiles(); - QStringList::iterator i = addDocuFiles.begin(); - - int steps = 0; - for (; i != addDocuFiles.end(); i++) - steps += QFileInfo(*i).size(); - - QList<IndexKeyword> lst; - quint32 fileAges = 0; - for (i = addDocuFiles.begin(); i != addDocuFiles.end(); i++) { - QFile file(*i); - if (!file.exists()) { -#ifdef _SHOW_ERRORS_ - emit errorOccured(tr("Documentation file %1 does not exist!\n" - "Skipping file.").arg(QFileInfo(file).absoluteFilePath())); -#endif - continue; - } - fileAges += QFileInfo(file).lastModified().toTime_t(); - DocuParser *handler = DocuParser::createParser(*i); - bool ok = handler->parse(&file); - file.close(); - if (!ok){ -#ifdef _SHOW_ERRORS_ - QString msg = QString::fromLatin1("In file %1:\n%2") - .arg(QFileInfo(file).absoluteFilePath()) - .arg(handler->errorProtocol()); - emit errorOccured(msg); -#endif - delete handler; - continue; - } - - QList<IndexItem*> indLst = handler->getIndexItems(); - foreach (IndexItem *indItem, indLst) { - QFileInfo fi(indItem->reference); - lst.append(IndexKeyword(indItem->keyword, indItem->reference)); - } - delete handler; - } - if (!lst.isEmpty()) - qSort(lst); - - QFile indexout(engine->cacheFilePath() + QDir::separator() + QLatin1String("indexdb40.") - + Config::configuration()->profileName()); - if (verifyDirectory(engine->cacheFilePath()) && indexout.open(QFile::WriteOnly)) { - QDataStream s(&indexout); - s << fileAges; - s << lst; - indexout.close(); - } -} diff --git a/src/plugins/help/helpengine.h b/src/plugins/help/helpengine.h deleted file mode 100644 index 11e7e79674061d677417e0af8439563034cb4332..0000000000000000000000000000000000000000 --- a/src/plugins/help/helpengine.h +++ /dev/null @@ -1,179 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -**************************************************************************/ - -#ifndef HELPENGINE_H -#define HELPENGINE_H - -#include "docuparser.h" - -#include <QtCore/QThread> -#include <QtCore/QPair> -#include <QtCore/QMap> -#include <QtCore/QWaitCondition> -#include <QtCore/QMutex> -#include <QtGui/QStringListModel> - -namespace Help { -namespace Internal { - -class HelpEngine; - -typedef QList<ContentItem> ContentList; - -class IndexListModel: public QStringListModel -{ -public: - IndexListModel(QObject *parent = 0) - : QStringListModel(parent) {} - - void clear() { contents.clear(); setStringList(QStringList()); } - - QString description(int index) const { return stringList().at(index); } - QStringList links(int index) const { return contents.values(stringList().at(index)); } - void addLink(const QString &description, const QString &link) { contents.insert(description, link); } - - void publish() { filter(QString(), QString()); } - - QModelIndex filter(const QString &s, const QString &real); - - virtual Qt::ItemFlags flags(const QModelIndex &index) const - { return QStringListModel::flags(index) & ~Qt::ItemIsEditable; } - -private: - QMultiMap<QString, QString> contents; -}; - -class TitleMapThread : public QThread -{ - Q_OBJECT - -public: - TitleMapThread(HelpEngine *he); - ~TitleMapThread(); - void setup(); - QList<QPair<QString, ContentList> > contents() const { return contentList; } - QMap<QString, QString> documentTitleMap() const { return titleMap; } - -signals: - void errorOccured(const QString &errMsg); - -protected: - void run(); - -private: - void getAllContents(); - void buildContentDict(); - - QList<QPair<QString, ContentList> > contentList; - QMap<QString, QString> titleMap; - - HelpEngine *engine; - bool done; -}; - -class IndexThread : public QThread -{ - Q_OBJECT - -public: - IndexThread(HelpEngine *he); - void setup(); - IndexListModel *model() const { return indexModel; } - -protected: - void run(); - -signals: - void errorOccured(const QString &errMsg); - -private: - void buildKeywordDB(); - - HelpEngine *engine; - QStringList keywordDocuments; - IndexListModel *indexModel; - bool indexDone; -}; - -class HelpEngine : public QObject -{ - Q_OBJECT - -public: - HelpEngine(QObject *parent, const QString &defaultQtVersionPath); - ~HelpEngine(); - void init(); - QList<QPair<QString, ContentList> > contents() const { return contentList; } - IndexListModel *indices(); - - QString titleOfLink(const QString &link); - static QString removeAnchorFromLink(const QString &link); - - QString home() const; - -signals: - void indexInitialized(); - void contentsInitialized(); - void errorOccured(const QString &errMsg); - -public slots: - void buildContents(); - void buildIndex(); - -private slots: - void titleMapFinished(); - void indexFinished(); - -private: - friend class TitleMapThread; - friend class IndexThread; - - void removeOldCacheFiles(bool onlyFulltextSearchIndex = false); - QString cacheFilePath() const; - quint32 getFileAges(); - - QList<QPair<QString, ContentList> > contentList; - QMap<QString, QString> titleMap; - - QString cacheFilesPath; - IndexListModel *indexModel; - - QWaitCondition titleMapDoneCondition; - QMutex mutex; - - TitleMapThread *titleMapThread; - IndexThread *indexThread; - - bool contentsOnly; -}; - -} // namespace Internal -} // namespace Help - -#endif // HELPENGINE_H diff --git a/src/plugins/help/indextoolwindow.cpp b/src/plugins/help/indextoolwindow.cpp deleted file mode 100644 index 9bdb728385afecc67052da81eaf4c7639f941b21..0000000000000000000000000000000000000000 --- a/src/plugins/help/indextoolwindow.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -**************************************************************************/ - -#include "indextoolwindow.h" -#include "helpengine.h" -#include "topicchooser.h" - -#include <QtCore/QDebug> -#include <QtGui/QKeyEvent> -#include <QtGui/QFocusEvent> -#include <QtGui/QLayout> -#include <QtGui/QLabel> -#include <QtGui/QLineEdit> -#include <QtGui/QListView> -#include <QtGui/QApplication> - -using namespace Help::Internal; - -IndexToolWidget::IndexToolWidget() -{ - wasInitialized = false; - - QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); - - QLabel *l = new QLabel(tr("Look for:"), this); - layout->addWidget(l); - - findLineEdit = new QLineEdit(this); - findLineEdit->installEventFilter(this); - layout->addWidget(findLineEdit); - - indicesView = new QListView(this); - indicesView->setLayoutMode(QListView::Batched); - indicesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - layout->addWidget(indicesView); - - setWindowTitle(tr("Index")); - setWindowIcon(QIcon(":/help/images/find.png")); -} - -void IndexToolWidget::focusInEvent(QFocusEvent *e) -{ - showEvent(0); - if (e && e->reason() != Qt::MouseFocusReason) { - findLineEdit->selectAll(); - findLineEdit->setFocus(); - } -} - -void IndexToolWidget::showEvent(QShowEvent *) -{ - if (!wasInitialized) { - wasInitialized = true; - setCursor(QCursor(Qt::WaitCursor)); - emit buildRequested(); - } -} - -bool IndexToolWidget::eventFilter(QObject * o, QEvent * e) -{ - if (o == findLineEdit && e->type() == QEvent::KeyPress) { - switch (static_cast<QKeyEvent*>(e)->key()) { - case Qt::Key_Up: - case Qt::Key_Down: - case Qt::Key_PageDown: - case Qt::Key_PageUp: - QApplication::sendEvent(indicesView, e); - break; - case Qt::Key_Escape: - emit escapePressed(); - break; - default: - break; - } - } - return QWidget::eventFilter(o, e); -} - - -IndexToolWindow::IndexToolWindow(const QList<int> &context, HelpEngine *help) -{ - m_context = context; - m_context << 0; - - m_widget = new IndexToolWidget; - - helpEngine = help; - connect(helpEngine, SIGNAL(indexInitialized()), this, SLOT(indexDone())); - model = 0; - - connect(m_widget->findLineEdit, SIGNAL(textEdited(const QString&)), - this, SLOT(searchInIndex(const QString &))); - connect(m_widget->findLineEdit, SIGNAL(returnPressed()), this, SLOT(indexRequested())); - connect(m_widget, SIGNAL(buildRequested()), helpEngine, SLOT(buildIndex())); - - connect(m_widget->indicesView, SIGNAL(activated(const QModelIndex&)), - this, SLOT(indexRequested())); - connect(m_widget, SIGNAL(escapePressed()), this, SIGNAL(escapePressed())); - -} - -IndexToolWindow::~IndexToolWindow() -{ - delete m_widget; -} - -const QList<int> &IndexToolWindow::context() const -{ - return m_context; -} - -QWidget *IndexToolWindow::widget() -{ - return m_widget; -} - -void IndexToolWindow::indexDone() -{ - model = helpEngine->indices(); - m_widget->indicesView->setModel(model); - m_widget->setCursor(QCursor(Qt::ArrowCursor)); -} - -void IndexToolWindow::searchInIndex(const QString &str) -{ - if (!model) - return; - QRegExp atoz("[A-Z]"); - int matches = str.count(atoz); - if (matches > 0 && !str.contains(".*")) - { - int start = 0; - QString newSearch; - for (; matches > 0; --matches) { - int match = str.indexOf(atoz, start+1); - if (match <= start) - continue; - newSearch += str.mid(start, match-start); - newSearch += ".*"; - start = match; - } - newSearch += str.mid(start); - m_widget->indicesView->setCurrentIndex(model->filter(newSearch, str)); - } - else - m_widget->indicesView->setCurrentIndex(model->filter(str, str)); -} - -void IndexToolWindow::indexRequested() -{ - if (!model) - return; - int row = m_widget->indicesView->currentIndex().row(); - if (row == -1 || row >= model->rowCount()) - return; - - QString description = model->description(row); - QStringList links = model->links(row); - - bool blocked = m_widget->findLineEdit->blockSignals(true); - m_widget->findLineEdit->setText(description); - m_widget->findLineEdit->blockSignals(blocked); - - if (links.count() == 1) { - emit showLinkRequested(links.first(), false); - } else { - qSort(links); - QStringList::Iterator it = links.begin(); - QStringList linkList; - QStringList linkNames; - for (; it != links.end(); ++it) { - linkList << *it; - linkNames << helpEngine->titleOfLink(*it); - } - QString link = TopicChooser::getLink(m_widget, linkNames, linkList, description); - if (!link.isEmpty()) - emit showLinkRequested(link, false); - } - - model->publish(); - m_widget->indicesView->setCurrentIndex(model->index(model->stringList().indexOf(description))); - m_widget->indicesView->scrollTo(m_widget->indicesView->currentIndex(), QAbstractItemView::PositionAtTop); -} - diff --git a/src/plugins/help/indextoolwindow.h b/src/plugins/help/indextoolwindow.h deleted file mode 100644 index 6ddecc986e203f03e9c4a32a0db4479f58d3358f..0000000000000000000000000000000000000000 --- a/src/plugins/help/indextoolwindow.h +++ /dev/null @@ -1,110 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -**************************************************************************/ - -#ifndef INDEXTOOLWINDOW_H -#define INDEXTOOLWINDOW_H - -#include <coreplugin/iview.h> - -#include <QtCore/QModelIndex> -#include <QtGui/QWidget> - -class QListView; -class QLineEdit; - -namespace Help { -namespace Internal { - -class HelpEngine; -class IndexListModel; -class IndexToolWindow; - -class IndexToolWidget : public QWidget -{ - Q_OBJECT -public: - IndexToolWidget(); - -signals: - void buildRequested(); - void escapePressed(); - -private: - friend class IndexToolWindow; - - bool eventFilter(QObject * o, QEvent * e); - void showEvent(QShowEvent *e); - void focusInEvent(QFocusEvent *e); - - bool wasInitialized; - QLineEdit *findLineEdit; - QListView *indicesView; -}; - - -class IndexToolWindow : public Core::IView -{ - Q_OBJECT - -public: - IndexToolWindow(const QList<int> &context, HelpEngine *help); - ~IndexToolWindow(); - - const QList<int> &context() const; - QWidget *widget(); - - QList<QWidget*> dockToolBarWidgets() const { return QList<QWidget*>(); } - - const char *uniqueViewName() const { return "Help.IndexToolWindow"; } - const char *globalMenuGroup() const { return "Help.Group"; } - inline QKeySequence defaultShortcut() const { return QKeySequence(); } - Qt::DockWidgetArea defaultArea() const { return Qt::RightDockWidgetArea; } - IView::ViewPosition defaultPosition() const { return IView::Second; } - -signals: - void showLinkRequested(const QString &link, bool newWindow); - void escapePressed(); - -private slots: - void indexDone(); - void searchInIndex(const QString &str); - void indexRequested(); - -private: - HelpEngine *helpEngine; - IndexListModel *model; - - QList<int> m_context; - IndexToolWidget *m_widget; -}; - -} // namespace Internal -} // namespace Help - -#endif // INDEXTOOLWINDOW_H