diff options
author | Rohan McGovern <rohan.mcgovern@nokia.com> | 2010-02-01 06:02:59 (GMT) |
---|---|---|
committer | Rohan McGovern <rohan.mcgovern@nokia.com> | 2010-02-01 06:02:59 (GMT) |
commit | dc1cab966938edc5463f26189607ece134549a22 (patch) | |
tree | ecaab6c64758f41fa9cb5b376b395831a77e6c83 /tools | |
parent | 4915439de467d1119a46af66ea08dbe161d2f336 (diff) | |
parent | bde40a9fa852107c237ac408f93a33b5955b9290 (diff) | |
download | Qt-dc1cab966938edc5463f26189607ece134549a22.zip Qt-dc1cab966938edc5463f26189607ece134549a22.tar.gz Qt-dc1cab966938edc5463f26189607ece134549a22.tar.bz2 |
Merge commit 'oslo1/master' into oslo1-master
Conflicts:
doc/src/getting-started/installation.qdoc
src/gui/dialogs/qfiledialog_win.cpp
tools/assistant/tools/assistant/centralwidget.cpp
tools/assistant/tools/assistant/helpviewer.cpp
Diffstat (limited to 'tools')
45 files changed, 2361 insertions, 1120 deletions
diff --git a/tools/assistant/lib/qclucenefieldnames.cpp b/tools/assistant/lib/qclucenefieldnames.cpp index 1a94291..84e3a1a 100644 --- a/tools/assistant/lib/qclucenefieldnames.cpp +++ b/tools/assistant/lib/qclucenefieldnames.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/tools/assistant/lib/qclucenefieldnames_p.h b/tools/assistant/lib/qclucenefieldnames_p.h index 489832f..ae13515 100644 --- a/tools/assistant/lib/qclucenefieldnames_p.h +++ b/tools/assistant/lib/qclucenefieldnames_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/tools/assistant/lib/qhelp_global.cpp b/tools/assistant/lib/qhelp_global.cpp index e6a26c4..8e96b55 100644 --- a/tools/assistant/lib/qhelp_global.cpp +++ b/tools/assistant/lib/qhelp_global.cpp @@ -89,10 +89,11 @@ QString QHelpGlobal::codecFromHtmlData(const QByteArray &data) QString head = QString::fromUtf8(data.constData(), qMin(1000, data.size())); int start = head.indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive); if (start > 0) { - int end; QRegExp r(QLatin1String("charset=([^\"\\s]+)")); while (start != -1) { - end = head.indexOf(QLatin1Char('>'), start) + 1; + const int end = head.indexOf(QLatin1Char('>'), start) + 1; + if (end <= start) + break; const QString &meta = head.mid(start, end - start).toLower(); if (r.indexIn(meta) != -1) return r.cap(1); diff --git a/tools/assistant/lib/qhelpgenerator.cpp b/tools/assistant/lib/qhelpgenerator.cpp index a193134..63164cd 100644 --- a/tools/assistant/lib/qhelpgenerator.cpp +++ b/tools/assistant/lib/qhelpgenerator.cpp @@ -538,7 +538,8 @@ bool QHelpGenerator::insertFiles(const QStringList &files, const QString &rootPa } int fileId = -1; - if (!d->fileMap.contains(fileName)) { + QMap<QString, int>::Iterator fileMapIt = d->fileMap.find(fileName); + if (fileMapIt == d->fileMap.end()) { fileDataList.append(qCompress(data)); fileNameData.name = fileName; @@ -552,18 +553,20 @@ bool QHelpGenerator::insertFiles(const QStringList &files, const QString &rootPa ++tableFileId; } else { - fileId = d->fileMap.value(fileName); + fileId = fileMapIt.value(); + QSet<int> &fileFilterSet = d->fileFilterMap[fileId]; + QSet<int> &tmpFileFilterSet = tmpFileFilterMap[fileId]; foreach (const int &filter, filterAtts) { - if (!d->fileFilterMap.value(fileId).contains(filter) - && !tmpFileFilterMap.value(fileId).contains(filter)) { - d->fileFilterMap[fileId].insert(filter); - tmpFileFilterMap[fileId].insert(filter); + if (!fileFilterSet.contains(filter) + && !tmpFileFilterSet.contains(filter)) { + fileFilterSet.insert(filter); + tmpFileFilterSet.insert(filter); } } } } - if (tmpFileFilterMap.count()) { + if (!tmpFileFilterMap.isEmpty()) { d->query->exec(QLatin1String("BEGIN")); QMap<int, QSet<int> >::const_iterator it = tmpFileFilterMap.constBegin(); while (it != tmpFileFilterMap.constEnd()) { @@ -626,8 +629,7 @@ bool QHelpGenerator::registerCustomFilter(const QString &filterName, while (d->query->next()) { attributeMap.insert(d->query->value(1).toString(), d->query->value(0).toInt()); - if (idsToInsert.contains(d->query->value(1).toString())) - idsToInsert.removeAll(d->query->value(1).toString()); + idsToInsert.removeAll(d->query->value(1).toString()); } foreach (QString id, idsToInsert) { @@ -675,7 +677,7 @@ bool QHelpGenerator::registerCustomFilter(const QString &filterName, return true; } -bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords, +bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> &keywords, const QStringList &filterAttributes) { if (!d->query) @@ -705,7 +707,17 @@ bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords, int i = 0; d->query->exec(QLatin1String("BEGIN")); - foreach (QHelpDataIndexItem itm, keywords) { + QSet<QString> indices; + foreach (const QHelpDataIndexItem &itm, keywords) { + + /* + * Identical ids make no sense and just confuse the Assistant user, + * so we ignore all repetitions. + */ + if (indices.contains(itm.identifier)) + continue; + indices.insert(itm.identifier); + pos = itm.reference.indexOf(QLatin1Char('#')); fileName = itm.reference.left(pos); if (pos > -1) @@ -717,8 +729,9 @@ bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords, if (fName.startsWith(QLatin1String("./"))) fName = fName.mid(2); - if (d->fileMap.contains(fName)) - fileId = d->fileMap.value(fName); + QMap<QString, int>::ConstIterator it = d->fileMap.find(fName); + if (it != d->fileMap.end()) + fileId = it.value(); else fileId = 1; @@ -750,7 +763,7 @@ bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords, d->query->exec(QLatin1String("COMMIT")); d->query->exec(QLatin1String("SELECT COUNT(Id) FROM IndexTable")); - if (d->query->next() && d->query->value(0).toInt() >= keywords.count()) + if (d->query->next() && d->query->value(0).toInt() >= indices.count()) return true; return false; } diff --git a/tools/assistant/lib/qhelpgenerator_p.h b/tools/assistant/lib/qhelpgenerator_p.h index 21c04f5..823a07a 100644 --- a/tools/assistant/lib/qhelpgenerator_p.h +++ b/tools/assistant/lib/qhelpgenerator_p.h @@ -97,7 +97,7 @@ private: const QStringList &filterAttribs, bool forceUpdate = false); bool registerVirtualFolder(const QString &folderName, const QString &ns); bool insertFilterAttributes(const QStringList &attributes); - bool insertKeywords(const QList<QHelpDataIndexItem> keywords, + bool insertKeywords(const QList<QHelpDataIndexItem> &keywords, const QStringList &filterAttributes); bool insertFiles(const QStringList &files, const QString &rootPath, const QStringList &filterAttributes); diff --git a/tools/assistant/lib/qhelpsearchquerywidget.cpp b/tools/assistant/lib/qhelpsearchquerywidget.cpp index cb7b1ef..ab48dac 100644 --- a/tools/assistant/lib/qhelpsearchquerywidget.cpp +++ b/tools/assistant/lib/qhelpsearchquerywidget.cpp @@ -41,8 +41,6 @@ #include "qhelpsearchquerywidget.h" -#include <QtCore/QDebug> - #include <QtCore/QAbstractListModel> #include <QtCore/QObject> #include <QtCore/QStringList> @@ -101,8 +99,9 @@ private: }; QHelpSearchQueryWidgetPrivate() - : QObject(), simpleSearch(true), - searchCompleter(new CompleterModel(this), this) + : QObject() + , simpleSearch(true) + , searchCompleter(new CompleterModel(this), this) { searchButton = 0; advancedSearchWidget = 0; @@ -195,8 +194,8 @@ private: } } - void nextOrPrevQuery(int maxOrMinIndex, int addend, - QToolButton *thisButton, QToolButton *otherButton) + void nextOrPrevQuery(int maxOrMinIndex, int addend, QToolButton *thisButton, + QToolButton *otherButton) { QueryHistory *queryHist; QList<QLineEdit *> lineEdits; @@ -206,7 +205,7 @@ private: } else { queryHist = &complexQueries; lineEdits << allQuery << atLeastQuery << similarQuery - << withoutQuery << exactQuery; + << withoutQuery << exactQuery; } foreach (QLineEdit *lineEdit, lineEdits) lineEdit->clear(); @@ -251,11 +250,11 @@ private: void enableOrDisableToolButtons() { - const QueryHistory &queryHist = - simpleSearch ? simpleQueries : complexQueries; + const QueryHistory &queryHist = simpleSearch ? simpleQueries + : complexQueries; prevQueryButton->setEnabled(queryHist.curQuery > 0); - nextQueryButton->setEnabled(queryHist.curQuery < - queryHist.queries.size() - 1); + nextQueryButton->setEnabled(queryHist.curQuery + < queryHist.queries.size() - 1); } private slots: @@ -279,20 +278,22 @@ private slots: QList<QHelpSearchQuery> queryList; #if !defined(QT_CLUCENE_SUPPORT) queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, - QStringList(defaultQuery->text()))); + QStringList(defaultQuery->text()))); #else if (defaultQuery->isEnabled()) { queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, - buildTermList(defaultQuery->text()))); + buildTermList(defaultQuery->text()))); } else { const QRegExp exp(QLatin1String("\\s+")); - QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts); + QStringList lst = similarQuery->text().split(exp, + QString::SkipEmptyParts); if (!lst.isEmpty()) { QStringList fuzzy; foreach (const QString term, lst) fuzzy += buildTermList(term); - queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy)); + queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, + fuzzy)); } lst = withoutQuery->text().split(exp, QString::SkipEmptyParts); @@ -300,13 +301,15 @@ private slots: QStringList without; foreach (const QString term, lst) without.append(term); - queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without)); + queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, + without)); } if (!exactQuery->text().isEmpty()) { QString phrase = exactQuery->text().remove(QLatin1Char('\"')); phrase = phrase.simplified(); - queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, QStringList(phrase))); + queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, + QStringList(phrase))); } lst = allQuery->text().split(exp, QString::SkipEmptyParts); @@ -322,7 +325,8 @@ private slots: QStringList atLeast; foreach (const QString term, lst) atLeast += buildTermList(term); - queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, atLeast)); + queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, + atLeast)); } } #endif @@ -336,8 +340,9 @@ private slots: void nextQuery() { - nextOrPrevQuery((simpleSearch ? simpleQueries : complexQueries).queries.size() - 1, - 1, nextQueryButton, prevQueryButton); + nextOrPrevQuery((simpleSearch ? simpleQueries + : complexQueries).queries.size() - 1, 1, nextQueryButton, + prevQueryButton); } void prevQuery() @@ -388,8 +393,9 @@ private: \fn void QHelpSearchQueryWidget::search() This signal is emitted when a the user has the search button invoked. - After reciving the signal you can ask the QHelpSearchQueryWidget for the build list - of QHelpSearchQuery's that you may pass to the QHelpSearchEngine's search() function. + After reciving the signal you can ask the QHelpSearchQueryWidget for the + build list of QHelpSearchQuery's that you may pass to the QHelpSearchEngine's + search() function. */ /*! @@ -517,7 +523,8 @@ QList<QHelpSearchQuery> QHelpSearchQueryWidget::query() const QList<QHelpSearchQuery>() : queryHist.queries.last(); } -/*! \reimp +/*! + \reimp */ void QHelpSearchQueryWidget::focusInEvent(QFocusEvent *focusEvent) { diff --git a/tools/assistant/tools/assistant/aboutdialog.cpp b/tools/assistant/tools/assistant/aboutdialog.cpp index 0ab8659..26d488d 100644 --- a/tools/assistant/tools/assistant/aboutdialog.cpp +++ b/tools/assistant/tools/assistant/aboutdialog.cpp @@ -38,6 +38,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "helpviewer.h" +#include "tracer.h" #include <QtCore/QBuffer> @@ -56,6 +58,7 @@ QT_BEGIN_NAMESPACE AboutLabel::AboutLabel(QWidget *parent) : QTextBrowser(parent) { + TRACE_OBJ setFrameStyle(QFrame::NoFrame); QPalette p; p.setColor(QPalette::Base, p.color(QPalette::Background)); @@ -64,6 +67,7 @@ AboutLabel::AboutLabel(QWidget *parent) void AboutLabel::setText(const QString &text, const QByteArray &resources) { + TRACE_OBJ QDataStream in(resources); in >> m_resourceMap; @@ -72,6 +76,7 @@ void AboutLabel::setText(const QString &text, const QByteArray &resources) QSize AboutLabel::minimumSizeHint() const { + TRACE_OBJ QTextDocument *doc = document(); doc->adjustSize(); return QSize(int(doc->size().width()), int(doc->size().height())); @@ -79,6 +84,7 @@ QSize AboutLabel::minimumSizeHint() const QVariant AboutLabel::loadResource(int type, const QUrl &name) { + TRACE_OBJ if (type == 2 || type == 3) { if (m_resourceMap.contains(name.toString())) { return m_resourceMap.value(name.toString()); @@ -89,9 +95,9 @@ QVariant AboutLabel::loadResource(int type, const QUrl &name) void AboutLabel::setSource(const QUrl &url) { - if (url.isValid() - && (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("ftp") - || url.scheme() == QLatin1String("mailto") || url.path().endsWith(QLatin1String("pdf")))) { + TRACE_OBJ + if (url.isValid() && (!HelpViewer::isLocalUrl(url) + || !HelpViewer::canOpenPage(url.path()))) { if (!QDesktopServices::openUrl(url)) { QMessageBox::warning(this, tr("Warning"), tr("Unable to launch external application.\n"), @@ -103,6 +109,7 @@ void AboutLabel::setSource(const QUrl &url) AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint|Qt::WindowTitleHint|Qt::WindowSystemMenuHint) { + TRACE_OBJ m_pixmapLabel = 0; m_aboutLabel = new AboutLabel(); @@ -121,12 +128,14 @@ AboutDialog::AboutDialog(QWidget *parent) void AboutDialog::setText(const QString &text, const QByteArray &resources) { + TRACE_OBJ m_aboutLabel->setText(text, resources); updateSize(); } void AboutDialog::setPixmap(const QPixmap &pixmap) { + TRACE_OBJ if (!m_pixmapLabel) { m_pixmapLabel = new QLabel(); m_layout->addWidget(m_pixmapLabel, 0, 0, 1, -1, Qt::AlignCenter); @@ -137,11 +146,13 @@ void AboutDialog::setPixmap(const QPixmap &pixmap) QString AboutDialog::documentTitle() const { + TRACE_OBJ return m_aboutLabel->documentTitle(); } void AboutDialog::updateSize() { + TRACE_OBJ QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size(); int limit = qMin(screenSize.width()/2, 500); diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro index 81677c3..980f078 100644 --- a/tools/assistant/tools/assistant/assistant.pro +++ b/tools/assistant/tools/assistant/assistant.pro @@ -11,6 +11,7 @@ PROJECTNAME = Assistant DESTDIR = ../../../../bin target.path = $$[QT_INSTALL_BINS] INSTALLS += target +DEPENDPATH += ../shared # ## Work around a qmake issue when statically linking to # ## not-yet-installed plugins @@ -31,7 +32,9 @@ HEADERS += helpviewer.h \ aboutdialog.h \ qtdocinstaller.h \ xbelsupport.h \ - ../shared/collectionconfiguration.h + ../shared/collectionconfiguration.h \ + helpenginewrapper.h \ + tracer.h win32:HEADERS += remotecontrol_win.h SOURCES += helpviewer.cpp \ main.cpp \ @@ -50,7 +53,8 @@ SOURCES += helpviewer.cpp \ aboutdialog.cpp \ qtdocinstaller.cpp \ xbelsupport.cpp \ - ../shared/collectionconfiguration.cpp + ../shared/collectionconfiguration.cpp \ + helpenginewrapper.cpp FORMS += topicchooser.ui \ preferencesdialog.ui \ filternamedialog.ui \ diff --git a/tools/assistant/tools/assistant/bookmarkmanager.cpp b/tools/assistant/tools/assistant/bookmarkmanager.cpp index 331ea4b..b7bd449 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.cpp +++ b/tools/assistant/tools/assistant/bookmarkmanager.cpp @@ -38,10 +38,11 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "bookmarkmanager.h" #include "centralwidget.h" -#include "../shared/collectionconfiguration.h" +#include "helpenginewrapper.h" #include <QtGui/QMenu> #include <QtGui/QIcon> @@ -57,7 +58,6 @@ #include <QtGui/QToolButton> #include <QtGui/QPushButton> #include <QtGui/QApplication> -#include <QtHelp/QHelpEngineCore> #include <QtGui/QDialogButtonBox> #include <QtGui/QSortFilterProxyModel> @@ -70,6 +70,7 @@ BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title, , m_title(title) , bookmarkManager(manager) { + TRACE_OBJ ui.setupUi(this); installEventFilter(this); @@ -118,10 +119,12 @@ BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title, BookmarkDialog::~BookmarkDialog() { + TRACE_OBJ } void BookmarkDialog::addAccepted() { + TRACE_OBJ QItemSelectionModel *model = ui.treeView->selectionModel(); const QModelIndexList &list = model->selection().indexes(); @@ -135,6 +138,7 @@ void BookmarkDialog::addAccepted() void BookmarkDialog::addNewFolder() { + TRACE_OBJ QItemSelectionModel *model = ui.treeView->selectionModel(); const QModelIndexList &list = model->selection().indexes(); @@ -160,6 +164,7 @@ void BookmarkDialog::addNewFolder() void BookmarkDialog::toolButtonClicked() { + TRACE_OBJ bool visible = !ui.treeView->isVisible(); ui.treeView->setVisible(visible); ui.newFolderButton->setVisible(visible); @@ -175,6 +180,7 @@ void BookmarkDialog::toolButtonClicked() void BookmarkDialog::itemChanged(QStandardItem *item) { + TRACE_OBJ if (renameItem != item) { renameItem = item; oldText = item->text(); @@ -195,11 +201,13 @@ void BookmarkDialog::itemChanged(QStandardItem *item) void BookmarkDialog::textChanged(const QString &string) { + TRACE_OBJ ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!string.isEmpty()); } void BookmarkDialog::selectBookmarkFolder(const QString &folderName) { + TRACE_OBJ if (folderName.isEmpty()) return; @@ -223,6 +231,7 @@ void BookmarkDialog::selectBookmarkFolder(const QString &folderName) void BookmarkDialog::customContextMenuRequested(const QPoint &point) { + TRACE_OBJ QModelIndex index = ui.treeView->indexAt(point); if (!index.isValid()) return; @@ -255,6 +264,7 @@ void BookmarkDialog::customContextMenuRequested(const QPoint &point) void BookmarkDialog::renameFolder(const QModelIndex &index, const QModelIndex &proxyIndex) { + TRACE_OBJ const BookmarkModel * const model = bookmarkManager->treeBookmarkModel(); if (QStandardItem *item = model->itemFromIndex(proxyIndex)) { item->setEditable(true); @@ -265,6 +275,7 @@ void BookmarkDialog::renameFolder(const QModelIndex &index, void BookmarkDialog::currentChanged(const QModelIndex ¤t) { + TRACE_OBJ QString text = tr("Bookmarks"); if (current.isValid()) text = current.data().toString(); @@ -273,6 +284,7 @@ void BookmarkDialog::currentChanged(const QModelIndex ¤t) bool BookmarkDialog::eventFilter(QObject *object, QEvent *e) { + TRACE_OBJ if (object != ui.treeView && object != ui.treeView->viewport()) return QWidget::eventFilter(object, e); @@ -323,6 +335,7 @@ BookmarkWidget::BookmarkWidget(BookmarkManager *manager, QWidget *parent, , removeButton(0) , bookmarkManager(manager) { + TRACE_OBJ setup(showButtons); installEventFilter(this); @@ -332,10 +345,12 @@ BookmarkWidget::BookmarkWidget(BookmarkManager *manager, QWidget *parent, BookmarkWidget::~BookmarkWidget() { + TRACE_OBJ } void BookmarkWidget::removeClicked() { + TRACE_OBJ const QModelIndex &index = treeView->currentIndex(); if (searchField->text().isEmpty()) { bookmarkManager->removeBookmarkItem(treeView, @@ -345,6 +360,7 @@ void BookmarkWidget::removeClicked() void BookmarkWidget::filterChanged() { + TRACE_OBJ bool searchBookmarks = searchField->text().isEmpty(); if (!searchBookmarks) { regExp.setPattern(searchField->text()); @@ -372,6 +388,7 @@ void BookmarkWidget::filterChanged() void BookmarkWidget::expand(const QModelIndex &index) { + TRACE_OBJ const QModelIndex &source = filterBookmarkModel->mapToSource(index); QStandardItem *item = bookmarkManager->treeBookmarkModel()->itemFromIndex(source); @@ -381,6 +398,7 @@ void BookmarkWidget::expand(const QModelIndex &index) void BookmarkWidget::activated(const QModelIndex &index) { + TRACE_OBJ if (!index.isValid()) return; @@ -391,6 +409,7 @@ void BookmarkWidget::activated(const QModelIndex &index) void BookmarkWidget::customContextMenuRequested(const QPoint &point) { + TRACE_OBJ QModelIndex index = treeView->indexAt(point); if (!index.isValid()) return; @@ -443,6 +462,7 @@ void BookmarkWidget::customContextMenuRequested(const QPoint &point) void BookmarkWidget::setup(bool showButtons) { + TRACE_OBJ regExp.setPatternSyntax(QRegExp::FixedString); regExp.setCaseSensitivity(Qt::CaseInsensitive); @@ -519,6 +539,7 @@ void BookmarkWidget::setup(bool showButtons) void BookmarkWidget::expandItems() { + TRACE_OBJ QStandardItemModel *model = bookmarkManager->treeBookmarkModel(); QList<QStandardItem*>list = model->findItems(QLatin1String("*"), Qt::MatchWildcard | Qt::MatchRecursive, 0); @@ -531,6 +552,7 @@ void BookmarkWidget::expandItems() void BookmarkWidget::focusInEvent(QFocusEvent *e) { + TRACE_OBJ if (e->reason() != Qt::MouseFocusReason) { searchField->selectAll(); searchField->setFocus(); @@ -544,6 +566,7 @@ void BookmarkWidget::focusInEvent(QFocusEvent *e) bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) { + TRACE_OBJ if (object != this && object != treeView && object != treeView->viewport()) { return QWidget::eventFilter(object, e); @@ -619,19 +642,23 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) BookmarkModel::BookmarkModel(int rows, int columns, QObject *parent) : QStandardItemModel(rows, columns, parent) { + TRACE_OBJ } BookmarkModel::~BookmarkModel() { + TRACE_OBJ } Qt::DropActions BookmarkModel::supportedDropActions() const { + TRACE_OBJ return Qt::MoveAction; } Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const { + TRACE_OBJ Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index); if ((!index.isValid()) // can only happen for the invisible root item || index.data(Qt::UserRole + 10).toString() == QLatin1String("Folder")) @@ -644,12 +671,12 @@ Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const // BookmarkManager -BookmarkManager::BookmarkManager(QHelpEngineCore *_helpEngine) +BookmarkManager::BookmarkManager() : treeModel(new BookmarkModel(0, 1, this)) , listModel(new BookmarkModel(0, 1, this)) , renameItem(0) - , helpEngine(_helpEngine) { + TRACE_OBJ folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon); bookmarkIcon = QIcon(QLatin1String(":/trolltech/assistant/images/bookmark.png")); @@ -663,31 +690,36 @@ BookmarkManager::BookmarkManager(QHelpEngineCore *_helpEngine) BookmarkManager::~BookmarkManager() { + TRACE_OBJ treeModel->clear(); listModel->clear(); } BookmarkModel* BookmarkManager::treeBookmarkModel() { + TRACE_OBJ return treeModel; } BookmarkModel* BookmarkManager::listBookmarkModel() { + TRACE_OBJ return listModel; } void BookmarkManager::saveBookmarks() { + TRACE_OBJ QByteArray bookmarks; QDataStream stream(&bookmarks, QIODevice::WriteOnly); readBookmarksRecursive(treeModel->invisibleRootItem(), stream, 0); - CollectionConfiguration::setBookmarks(*helpEngine, bookmarks); + HelpEngineWrapper::instance().setBookmarks(bookmarks); } QStringList BookmarkManager::bookmarkFolders() const { + TRACE_OBJ QStringList folders(tr("Bookmarks")); QList<QStandardItem*>list = treeModel->findItems(QLatin1String("*"), @@ -704,6 +736,7 @@ QStringList BookmarkManager::bookmarkFolders() const QModelIndex BookmarkManager::addNewFolder(const QModelIndex &index) { + TRACE_OBJ QStandardItem *item = new QStandardItem(uniqueFolderName()); item->setEditable(false); item->setData(false, Qt::UserRole + 11); @@ -721,6 +754,7 @@ QModelIndex BookmarkManager::addNewFolder(const QModelIndex &index) void BookmarkManager::removeBookmarkItem(QTreeView *treeView, const QModelIndex &index) { + TRACE_OBJ QStandardItem *item = treeModel->itemFromIndex(index); if (item) { QString data = index.data(Qt::UserRole + 10).toString(); @@ -752,6 +786,7 @@ void BookmarkManager::removeBookmarkItem(QTreeView *treeView, void BookmarkManager::showBookmarkDialog(QWidget *parent, const QString &name, const QString &url) { + TRACE_OBJ BookmarkDialog dialog(this, name, url, parent); dialog.exec(); } @@ -759,6 +794,7 @@ void BookmarkManager::showBookmarkDialog(QWidget *parent, const QString &name, void BookmarkManager::addNewBookmark(const QModelIndex &index, const QString &name, const QString &url) { + TRACE_OBJ QStandardItem *item = new QStandardItem(name); item->setEditable(false); item->setIcon(bookmarkIcon); @@ -775,6 +811,7 @@ void BookmarkManager::addNewBookmark(const QModelIndex &index, void BookmarkManager::fillBookmarkMenu(QMenu *menu) { + TRACE_OBJ if (!menu || !treeModel) return; @@ -784,6 +821,7 @@ void BookmarkManager::fillBookmarkMenu(QMenu *menu) void BookmarkManager::fillBookmarkMenu(QMenu *menu, QStandardItem *root) { + TRACE_OBJ for (int i = 0; i < root->rowCount(); ++i) { QStandardItem *item = root->child(i); if (item && item->data(Qt::UserRole + 10) @@ -799,6 +837,7 @@ void BookmarkManager::fillBookmarkMenu(QMenu *menu, QStandardItem *root) QUrl BookmarkManager::urlForAction(QAction* action) const { + TRACE_OBJ if (map.contains(action)) { const QModelIndex &index = map.value(action); if (QStandardItem* item = treeModel->itemFromIndex(index)) @@ -809,6 +848,7 @@ QUrl BookmarkManager::urlForAction(QAction* action) const void BookmarkManager::itemChanged(QStandardItem *item) { + TRACE_OBJ if (renameItem != item) { renameItem = item; oldText = item->text(); @@ -826,6 +866,7 @@ void BookmarkManager::itemChanged(QStandardItem *item) void BookmarkManager::setupBookmarkModels() { + TRACE_OBJ treeModel->clear(); listModel->clear(); @@ -835,7 +876,7 @@ void BookmarkManager::setupBookmarkModels() QList<int> lastDepths; QList<QStandardItem*> parents; - QByteArray ba = CollectionConfiguration::bookmarks(*helpEngine); + QByteArray ba = HelpEngineWrapper::instance().bookmarks(); QDataStream stream(ba); while (!stream.atEnd()) { stream >> depth >> name >> type >> expanded; @@ -871,6 +912,7 @@ void BookmarkManager::setupBookmarkModels() QString BookmarkManager::uniqueFolderName() const { + TRACE_OBJ QString folderName = tr("New Folder"); QList<QStandardItem*> list = treeModel->findItems(folderName, Qt::MatchContains | Qt::MatchRecursive, 0); @@ -890,6 +932,7 @@ QString BookmarkManager::uniqueFolderName() const void BookmarkManager::removeBookmarkFolderItems(QStandardItem *item) { + TRACE_OBJ for (int j = 0; j < item->rowCount(); ++j) { QStandardItem *child = item->child(j); if (child->rowCount() > 0) @@ -909,6 +952,7 @@ void BookmarkManager::removeBookmarkFolderItems(QStandardItem *item) void BookmarkManager::readBookmarksRecursive(const QStandardItem *item, QDataStream &stream, const qint32 depth) const { + TRACE_OBJ for (int j = 0; j < item->rowCount(); ++j) { const QStandardItem *child = item->child(j); stream << depth; diff --git a/tools/assistant/tools/assistant/bookmarkmanager.h b/tools/assistant/tools/assistant/bookmarkmanager.h index 71a1778..fbacc2c 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.h +++ b/tools/assistant/tools/assistant/bookmarkmanager.h @@ -168,7 +168,7 @@ class BookmarkManager : public QObject Q_OBJECT public: - BookmarkManager(QHelpEngineCore* helpEngine); + BookmarkManager(); ~BookmarkManager(); BookmarkModel* treeBookmarkModel(); @@ -208,7 +208,6 @@ private: BookmarkModel *treeModel; BookmarkModel *listModel; QStandardItem *renameItem; - QHelpEngineCore *helpEngine; QMap<QAction*, QModelIndex> map; }; diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index b5fe262..076498e 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -38,8 +38,10 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "centralwidget.h" +#include "helpenginewrapper.h" #include "helpviewer.h" #include "searchwidget.h" #include "mainwindow.h" @@ -68,7 +70,6 @@ #include <QtGui/QPrintPreviewDialog> #include <QtGui/QPageSetupDialog> -#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpSearchEngine> QT_BEGIN_NAMESPACE @@ -91,6 +92,7 @@ FindWidget::FindWidget(QWidget *parent) : QWidget(parent) , appPalette(qApp->palette()) { + TRACE_OBJ QHBoxLayout *hboxLayout = new QHBoxLayout(this); QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); @@ -149,10 +151,12 @@ FindWidget::FindWidget(QWidget *parent) FindWidget::~FindWidget() { + TRACE_OBJ } void FindWidget::hideEvent(QHideEvent* event) { + TRACE_OBJ #if !defined(QT_NO_WEBKIT) // TODO: remove this once webkit supports setting the palette if (!event->spontaneous()) @@ -164,6 +168,7 @@ void FindWidget::hideEvent(QHideEvent* event) void FindWidget::showEvent(QShowEvent* event) { + TRACE_OBJ #if !defined(QT_NO_WEBKIT) // TODO: remove this once webkit supports setting the palette if (!event->spontaneous()) { @@ -181,6 +186,7 @@ void FindWidget::showEvent(QShowEvent* event) void FindWidget::updateButtons() { + TRACE_OBJ if (editFind->text().isEmpty()) { toolPrevious->setEnabled(false); toolNext->setEnabled(false); @@ -192,6 +198,7 @@ void FindWidget::updateButtons() QToolButton* FindWidget::setupToolButton(const QString &text, const QString &icon) { + TRACE_OBJ QToolButton *toolButton = new QToolButton(this); toolButton->setText(text); @@ -206,18 +213,17 @@ QToolButton* FindWidget::setupToolButton(const QString &text, const QString &ico // -- -CentralWidget::CentralWidget(QHelpEngine *engine, MainWindow *parent) +CentralWidget::CentralWidget(MainWindow *parent) : QWidget(parent) , lastTabPage(0) - , collectionFile(engine->collectionFile()) , findBar(0) , tabWidget(0) , findWidget(0) - , helpEngine(engine) , printer(0) , usesDefaultCollection(parent->usesDefaultCollection()) , m_searchWidget(0) { + TRACE_OBJ globalActionList.clear(); staticCentralWidget = this; QVBoxLayout *vboxLayout = new QVBoxLayout(this); @@ -289,14 +295,11 @@ CentralWidget::CentralWidget(QHelpEngine *engine, MainWindow *parent) CentralWidget::~CentralWidget() { + TRACE_OBJ #ifndef QT_NO_PRINTER delete printer; #endif - QHelpEngineCore engine(collectionFile, 0); - if (!engine.setupData()) - return; - QStringList zoomFactors; QStringList currentPages; bool searchAttached = m_searchWidget->isAttached(); @@ -310,19 +313,22 @@ CentralWidget::~CentralWidget() } } - CollectionConfiguration::setLastTabPage(engine, lastTabPage); - CollectionConfiguration::setLastShownPages(engine, currentPages); - CollectionConfiguration::setSearchWasAttached(engine, searchAttached); - CollectionConfiguration::setLastZoomFactors(engine, zoomFactors); + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + helpEngine.setLastTabPage(tabWidget->currentIndex()); + helpEngine.setLastShownPages(currentPages); + helpEngine.setSearchWasAttached(searchAttached); + helpEngine.setLastZoomFactors(zoomFactors); } CentralWidget *CentralWidget::instance() { + TRACE_OBJ return staticCentralWidget; } void CentralWidget::newTab() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); #if !defined(QT_NO_WEBKIT) if (viewer && viewer->hasLoadFinished()) @@ -334,6 +340,7 @@ void CentralWidget::newTab() void CentralWidget::zoomIn() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (viewer) viewer->zoomIn(); @@ -344,6 +351,7 @@ void CentralWidget::zoomIn() void CentralWidget::zoomOut() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (viewer) viewer->zoomOut(); @@ -354,11 +362,13 @@ void CentralWidget::zoomOut() void CentralWidget::findNext() { - find(findWidget->editFind->text(), true, false); + TRACE_OBJ + find(findWidget->editFind->text(), true); } void CentralWidget::nextPage() { + TRACE_OBJ int index = tabWidget->currentIndex() + 1; if (index >= tabWidget->count()) index = 0; @@ -367,6 +377,7 @@ void CentralWidget::nextPage() void CentralWidget::resetZoom() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (viewer) viewer->resetZoom(); @@ -377,6 +388,7 @@ void CentralWidget::resetZoom() void CentralWidget::previousPage() { + TRACE_OBJ int index = tabWidget->currentIndex() -1; if (index < 0) index = tabWidget->count() -1; @@ -385,11 +397,13 @@ void CentralWidget::previousPage() void CentralWidget::findPrevious() { - find(findWidget->editFind->text(), false, true); + TRACE_OBJ + find(findWidget->editFind->text(), false); } void CentralWidget::closeTab() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (!viewer|| tabWidget->count() == 1) return; @@ -400,12 +414,13 @@ void CentralWidget::closeTab() void CentralWidget::setSource(const QUrl &url) { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); HelpViewer *lastViewer = qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage)); if (!viewer && !lastViewer) { - viewer = new HelpViewer(helpEngine, this); + viewer = new HelpViewer(this); viewer->installEventFilter(this); lastTabPage = tabWidget->addTab(viewer, QString()); tabWidget->setCurrentIndex(lastTabPage); @@ -423,16 +438,14 @@ void CentralWidget::setSource(const QUrl &url) void CentralWidget::setupWidget() { - int option = CollectionConfiguration::startOption(*helpEngine); + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + int option = helpEngine.startOption(); if (option != ShowLastPages) { QString homePage; - if (option == ShowHomePage) { - // TODO: Can this fall-back logic go into the wrapper class? - homePage = CollectionConfiguration::homePage(*helpEngine); - if (homePage.isEmpty()) - homePage = CollectionConfiguration::defaultHomePage(*helpEngine); - } - if (option == ShowBlankPage) + if (option == ShowHomePage) + homePage = helpEngine.homePage(); + else if (option == ShowBlankPage) homePage = QLatin1String("about:blank"); setSource(homePage); } else { @@ -442,8 +455,9 @@ void CentralWidget::setupWidget() void CentralWidget::setLastShownPages() { - const QStringList lastShownPageList = - CollectionConfiguration::lastShownPages(*helpEngine); + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + const QStringList lastShownPageList = helpEngine.lastShownPages(); const int pageCount = lastShownPageList.count(); if (pageCount == 0) { if (usesDefaultCollection) @@ -452,38 +466,39 @@ void CentralWidget::setLastShownPages() setSource(QUrl(QLatin1String("about:blank"))); return; } - - QStringList zoomFactors = - CollectionConfiguration::lastZoomFactors(*helpEngine); + QStringList zoomFactors = helpEngine.lastZoomFactors(); while (zoomFactors.count() < pageCount) zoomFactors.append(CollectionConfiguration::DefaultZoomFactor); - QStringList::const_iterator zIt = zoomFactors.constBegin(); - QStringList::const_iterator it = lastShownPageList.constBegin(); - for (; it != lastShownPageList.constEnd(); ++it, ++zIt) - setSourceInNewTab((*it), (*zIt).toFloat()); - - int tab = CollectionConfiguration::lastTabPage(*helpEngine); - const bool searchIsAttached = m_searchWidget->isAttached(); - const bool searchWasAttached = - CollectionConfiguration::searchWasAttached(*helpEngine); - - if (searchWasAttached && !searchIsAttached) - --tab; + const bool searchWasAttached = helpEngine.searchWasAttached(); + int tabToShow = helpEngine.lastTabPage(); + if (searchWasAttached && !searchIsAttached && tabToShow != 0) + --tabToShow; else if (!searchWasAttached && searchIsAttached) - ++tab; - tabWidget->setCurrentIndex(tab); + ++tabToShow; + + for (int curTab = 0; curTab < pageCount; ++curTab) { + const QString &curFile = lastShownPageList.at(curTab); + if (helpEngine.findFile(curFile).isValid()) + setSourceInNewTab(curFile, zoomFactors.at(curTab).toFloat()); + else if (curTab + searchIsAttached <= tabToShow) + --tabToShow; + } + + tabWidget->setCurrentIndex(tabToShow); } bool CentralWidget::hasSelection() const { + TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); return viewer ? viewer->hasSelection() : false; } QUrl CentralWidget::currentSource() const { + TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); if (viewer) return viewer->source(); @@ -493,6 +508,7 @@ QUrl CentralWidget::currentSource() const QString CentralWidget::currentTitle() const { + TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); if (viewer) return viewer->documentTitle(); @@ -502,6 +518,7 @@ QString CentralWidget::currentTitle() const void CentralWidget::copySelection() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (viewer) viewer->copy(); @@ -509,6 +526,7 @@ void CentralWidget::copySelection() void CentralWidget::showTextSearch() { + TRACE_OBJ findBar->show(); findWidget->editFind->selectAll(); findWidget->editFind->setFocus(Qt::ShortcutFocusReason); @@ -516,6 +534,7 @@ void CentralWidget::showTextSearch() void CentralWidget::initPrinter() { + TRACE_OBJ #ifndef QT_NO_PRINTER if (!printer) printer = new QPrinter(QPrinter::HighResolution); @@ -524,6 +543,7 @@ void CentralWidget::initPrinter() void CentralWidget::print() { + TRACE_OBJ #ifndef QT_NO_PRINTER HelpViewer *viewer = currentHelpViewer(); if (!viewer) @@ -547,6 +567,7 @@ void CentralWidget::print() void CentralWidget::printPreview() { + TRACE_OBJ #ifndef QT_NO_PRINTER initPrinter(); QPrintPreviewDialog preview(printer, this); @@ -558,6 +579,7 @@ void CentralWidget::printPreview() void CentralWidget::printPreview(QPrinter *p) { + TRACE_OBJ #ifndef QT_NO_PRINTER HelpViewer *viewer = currentHelpViewer(); if (viewer) @@ -567,6 +589,7 @@ void CentralWidget::printPreview(QPrinter *p) void CentralWidget::pageSetup() { + TRACE_OBJ #ifndef QT_NO_PRINTER initPrinter(); QPageSetupDialog dlg(printer); @@ -576,11 +599,13 @@ void CentralWidget::pageSetup() bool CentralWidget::isHomeAvailable() const { + TRACE_OBJ return currentHelpViewer() ? true : false; } void CentralWidget::home() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (viewer) viewer->home(); @@ -588,6 +613,7 @@ void CentralWidget::home() bool CentralWidget::isForwardAvailable() const { + TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); if (viewer) return viewer->isForwardAvailable(); @@ -597,6 +623,7 @@ bool CentralWidget::isForwardAvailable() const void CentralWidget::forward() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (viewer) viewer->forward(); @@ -604,6 +631,7 @@ void CentralWidget::forward() bool CentralWidget::isBackwardAvailable() const { + TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); if (viewer) return viewer->isBackwardAvailable(); @@ -613,6 +641,7 @@ bool CentralWidget::isBackwardAvailable() const void CentralWidget::backward() { + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (viewer) viewer->backward(); @@ -621,16 +650,19 @@ void CentralWidget::backward() QList<QAction*> CentralWidget::globalActions() const { + TRACE_OBJ return globalActionList; } void CentralWidget::setGlobalActions(const QList<QAction*> &actions) { + TRACE_OBJ globalActionList = actions; } void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) { + TRACE_OBJ HelpViewer *viewer; #if defined(QT_NO_WEBKIT) @@ -639,7 +671,7 @@ void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) return; #endif - viewer = new HelpViewer(helpEngine, this); + viewer = new HelpViewer(this); viewer->installEventFilter(this); viewer->setSource(url); viewer->setFocus(Qt::OtherFocusReason); @@ -663,7 +695,8 @@ void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) HelpViewer *CentralWidget::newEmptyTab() { - HelpViewer *viewer = new HelpViewer(helpEngine, this); + TRACE_OBJ + HelpViewer *viewer = new HelpViewer(this); viewer->installEventFilter(this); viewer->setFocus(Qt::OtherFocusReason); #if defined(QT_NO_WEBKIT) @@ -677,11 +710,13 @@ HelpViewer *CentralWidget::newEmptyTab() void CentralWidget::findCurrentText(const QString &text) { - find(text, false, false); + TRACE_OBJ + find(text, true); } void CentralWidget::connectSignals() { + TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); if (viewer) { connect(viewer, SIGNAL(copyAvailable(bool)), this, @@ -701,11 +736,13 @@ void CentralWidget::connectSignals() HelpViewer *CentralWidget::currentHelpViewer() const { + TRACE_OBJ return qobject_cast<HelpViewer*>(tabWidget->currentWidget()); } void CentralWidget::activateTab(bool onlyHelpViewer) { + TRACE_OBJ if (currentHelpViewer()) { currentHelpViewer()->setFocus(); } else { @@ -719,6 +756,7 @@ void CentralWidget::activateTab(bool onlyHelpViewer) void CentralWidget::setTabTitle(const QUrl &url) { + TRACE_OBJ Q_UNUSED(url) #if !defined(QT_NO_WEBKIT) QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget); @@ -740,6 +778,7 @@ void CentralWidget::setTabTitle(const QUrl &url) void CentralWidget::currentPageChanged(int index) { + TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); if (viewer) lastTabPage = index; @@ -755,6 +794,7 @@ void CentralWidget::currentPageChanged(int index) void CentralWidget::showTabBarContextMenu(const QPoint &point) { + TRACE_OBJ HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, point); if (!viewer) return; @@ -807,6 +847,7 @@ void CentralWidget::showTabBarContextMenu(const QPoint &point) bool CentralWidget::eventFilter(QObject *object, QEvent *e) { + TRACE_OBJ if (e->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast<QKeyEvent*>(e); switch (ke->key()) { @@ -862,6 +903,7 @@ bool CentralWidget::eventFilter(QObject *object, QEvent *e) void CentralWidget::keyPressEvent(QKeyEvent *e) { + TRACE_OBJ const QString &text = e->text(); if (text.startsWith(QLatin1Char('/'))) { if (!findBar->isVisible()) { @@ -876,19 +918,37 @@ void CentralWidget::keyPressEvent(QKeyEvent *e) QWidget::keyPressEvent(e); } -void CentralWidget::find(const QString &ttf, bool forward, bool backward) +void CentralWidget::find(const QString &ttf, bool forward) { + TRACE_OBJ QPalette p = findWidget->editFind->palette(); p.setColor(QPalette::Active, QPalette::Base, Qt::white); - if (!ttf.isEmpty()) { - HelpViewer *viewer = currentHelpViewer(); + bool found = false; - bool found = false; +#if defined(QT_NO_WEBKIT) + found = findInTextBrowser(ttf, forward); +#else + found = findInWebPage(ttf, forward); +#endif + + if (!found && !ttf.isEmpty()) + p.setColor(QPalette::Active, QPalette::Base, QColor(255, 102, 102)); + + if (!findWidget->isVisible()) + findWidget->show(); + findWidget->editFind->setPalette(p); +} + +bool CentralWidget::findInWebPage(const QString &ttf, bool forward) +{ + TRACE_OBJ #if !defined(QT_NO_WEBKIT) - if (viewer) { - QWebPage::FindFlags options; - if (backward) + if (HelpViewer *viewer = currentHelpViewer()) { + bool found = false; + QWebPage::FindFlags options; + if (!ttf.isEmpty()) { + if (!forward) options |= QWebPage::FindBackward; if (findWidget->checkCase->isChecked()) @@ -903,30 +963,31 @@ void CentralWidget::find(const QString &ttf, bool forward, bool backward) if (found) findWidget->labelWrapped->show(); } - } else if (tabWidget->currentWidget() == m_searchWidget) { - QTextBrowser *browser = qFindChild<QTextBrowser*>(m_searchWidget); - found = findInTextBrowser(browser, ttf, forward, backward); } -#else - QTextBrowser *browser = qobject_cast<QTextBrowser*>(viewer); - if (tabWidget->currentWidget() == m_searchWidget) - browser = qFindChild<QTextBrowser*>(m_searchWidget); - found = findInTextBrowser(browser, ttf, forward, backward); -#endif - - if (!found) - p.setColor(QPalette::Active, QPalette::Base, QColor(255, 102, 102)); + // force highlighting of all other matches, also when empty (clear) + options = QWebPage::HighlightAllOccurrences; + viewer->findText(QLatin1String(""), options); + viewer->findText(ttf, options); + return found; } - if (!findWidget->isVisible()) - findWidget->show(); - findWidget->editFind->setPalette(p); + // this needs to stay, case for active search results page + return findInTextBrowser(ttf, forward); +#else + Q_UNUSED(ttf); + Q_UNUSED(forward); +#endif + return false; } -bool CentralWidget::findInTextBrowser(QTextBrowser* browser, const QString &ttf, - bool forward, bool backward) +bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) { - if (!browser) + TRACE_OBJ + QTextBrowser *browser = qobject_cast<QTextBrowser*>(currentHelpViewer()); + if (tabWidget->currentWidget() == m_searchWidget) + browser = qFindChild<QTextBrowser*>(m_searchWidget); + + if (!browser || ttf.isEmpty()) return false; QTextDocument *doc = browser->document(); @@ -942,7 +1003,7 @@ bool CentralWidget::findInTextBrowser(QTextBrowser* browser, const QString &ttf, QTextCursor::MoveAnchor); } - if (backward) + if (!forward) options |= QTextDocument::FindBackward; if (findWidget->checkCase->isChecked()) @@ -973,6 +1034,7 @@ bool CentralWidget::findInTextBrowser(QTextBrowser* browser, const QString &ttf, void CentralWidget::updateBrowserFont() { + TRACE_OBJ QFont font; bool searchAttached = searchWidgetAttached(); if (searchAttached) { @@ -982,12 +1044,13 @@ void CentralWidget::updateBrowserFont() int i = searchAttached ? 1 : 0; getBrowserFontFor(tabWidget->widget(i), &font); - for (; i < tabWidget->count(); ++i) + for ( ; i < tabWidget->count(); ++i) setBrowserFontFor(tabWidget->widget(i), font); } void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine) { + TRACE_OBJ if (m_searchWidget) return; @@ -1004,8 +1067,9 @@ void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine) void CentralWidget::activateSearchWidget(bool updateLastTabPage) { + TRACE_OBJ if (!m_searchWidget) - createSearchWidget(helpEngine->searchEngine()); + createSearchWidget(HelpEngineWrapper::instance().searchEngine()); if (!m_searchWidget->isAttached()) { tabWidget->insertTab(0, m_searchWidget, tr("Search")); @@ -1021,6 +1085,7 @@ void CentralWidget::activateSearchWidget(bool updateLastTabPage) void CentralWidget::removeSearchWidget() { + TRACE_OBJ if (searchWidgetAttached()) { tabWidget->removeTab(0); m_searchWidget->setAttached(false); @@ -1029,6 +1094,7 @@ void CentralWidget::removeSearchWidget() int CentralWidget::availableHelpViewer() const { + TRACE_OBJ int count = tabWidget->count(); if (searchWidgetAttached()) count--; @@ -1037,6 +1103,7 @@ int CentralWidget::availableHelpViewer() const bool CentralWidget::enableTabCloseAction() const { + TRACE_OBJ int minTabCount = 1; if (searchWidgetAttached()) minTabCount = 2; @@ -1046,6 +1113,7 @@ bool CentralWidget::enableTabCloseAction() const QString CentralWidget::quoteTabTitle(const QString &title) const { + TRACE_OBJ QString s = title; return s.replace(QLatin1Char('&'), QLatin1String("&&")); } @@ -1053,26 +1121,39 @@ QString CentralWidget::quoteTabTitle(const QString &title) const void CentralWidget::setSourceFromSearch(const QUrl &url) { + TRACE_OBJ setSource(url); +#if defined(QT_NO_WEBKIT) highlightSearchTerms(); +#else + connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); +#endif } void CentralWidget::setSourceFromSearchInNewTab(const QUrl &url) { + TRACE_OBJ setSourceInNewTab(url); +#if defined(QT_NO_WEBKIT) highlightSearchTerms(); +#else + connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); +#endif } void CentralWidget::highlightSearchTerms() { -#if defined(QT_NO_WEBKIT) + TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); if (!viewer) return; - QHelpSearchEngine *searchEngine = helpEngine->searchEngine(); + QHelpSearchEngine *searchEngine = + HelpEngineWrapper::instance().searchEngine(); QList<QHelpSearchQuery> queryList = searchEngine->query(); QStringList terms; @@ -1089,6 +1170,7 @@ CentralWidget::highlightSearchTerms() } } +#if defined(QT_NO_WEBKIT) viewer->viewport()->setUpdatesEnabled(false); QTextCharFormat marker; @@ -1120,22 +1202,44 @@ CentralWidget::highlightSearchTerms() viewer->setTextCursor(firstHit); viewer->viewport()->setUpdatesEnabled(true); +#else + viewer->findText("", QWebPage::HighlightAllOccurrences); + // clears existing selections + foreach (const QString& term, terms) + viewer->findText(term, QWebPage::HighlightAllOccurrences); + + disconnect(viewer, SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); #endif } -void CentralWidget::closeTabs(const QList<int> &indices) +void CentralWidget::closeOrReloadTabs(const QList<int> &indices, bool tryReload) { + TRACE_OBJ QList<int> sortedIndices = indices; qSort(sortedIndices); - for (int i = sortedIndices.count(); --i >= 0;) - closeTabAt(sortedIndices.at(i)); + for (int i = sortedIndices.count(); --i >= 0;) { + const int tab = sortedIndices.at(i); + bool close = true; + if (tryReload) { + HelpViewer *viewer = + qobject_cast<HelpViewer*>(tabWidget->widget(tab)); + if (HelpEngineWrapper::instance().findFile(viewer->source()).isValid()) { + viewer->reload(); + close = false; + } + } + if (close) + closeTabAt(tab); + } if (availableHelpViewer() == 0) setSource(QUrl(QLatin1String("about:blank"))); } void CentralWidget::closeTabAt(int index) { + TRACE_OBJ HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(index)); tabWidget->removeTab(index); QTimer::singleShot(0, viewer, SLOT(deleteLater())); @@ -1143,8 +1247,9 @@ void CentralWidget::closeTabAt(int index) QMap<int, QString> CentralWidget::currentSourceFileList() const { + TRACE_OBJ QMap<int, QString> sourceList; - for (int i = 1; i < tabWidget->count(); ++i) { + for (int i = 0; i < tabWidget->count(); ++i) { HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i)); if (viewer && viewer->source().isValid()) sourceList.insert(i, viewer->source().host()); @@ -1154,8 +1259,9 @@ QMap<int, QString> CentralWidget::currentSourceFileList() const void CentralWidget::getBrowserFontFor(QWidget *viewer, QFont *font) { - const QLatin1String key("useBrowserFont"); - if (!CollectionConfiguration::usesBrowserFont(*helpEngine)) { + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + if (!helpEngine.usesBrowserFont()) { *font = qApp->font(); // case for QTextBrowser and SearchWidget #if !defined(QT_NO_WEBKIT) QWebView *view = qobject_cast<QWebView*> (viewer); @@ -1166,12 +1272,13 @@ void CentralWidget::getBrowserFontFor(QWidget *viewer, QFont *font) } #endif } else { - *font = CollectionConfiguration::browserFont(*helpEngine); + *font = helpEngine.browserFont(); } } void CentralWidget::setBrowserFontFor(QWidget *widget, const QFont &font) { + TRACE_OBJ #if !defined(QT_NO_WEBKIT) QWebView *view = qobject_cast<QWebView*> (widget); if (view) { diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h index c2cb698..c0bee81 100644 --- a/tools/assistant/tools/assistant/centralwidget.h +++ b/tools/assistant/tools/assistant/centralwidget.h @@ -110,7 +110,7 @@ class CentralWidget : public QWidget Q_OBJECT public: - CentralWidget(QHelpEngine *engine, MainWindow *parent); + CentralWidget(MainWindow *parent); ~CentralWidget(); void setupWidget(); @@ -135,7 +135,7 @@ public: int availableHelpViewer() const; bool enableTabCloseAction() const; - void closeTabs(const QList<int> &indices); + void closeOrReloadTabs(const QList<int> &indices, bool tryReload); void closeTabAt(int index); QMap<int, QString> currentSourceFileList() const; @@ -184,16 +184,16 @@ private slots: void printPreview(QPrinter *printer); void setSourceFromSearch(const QUrl &url); void setSourceFromSearchInNewTab(const QUrl &url); + void highlightSearchTerms(); private: void connectSignals(); bool eventFilter(QObject *object, QEvent *e); - void find(const QString &ttf, bool forward, bool backward); - bool findInTextBrowser(QTextBrowser* browser, const QString &ttf, - bool forward, bool backward); + void find(const QString &ttf, bool forward); + bool findInWebPage(const QString &ttf, bool forward); + bool findInTextBrowser(const QString &ttf, bool forward); void initPrinter(); QString quoteTabTitle(const QString &title) const; - void highlightSearchTerms(); void setLastShownPages(); void getBrowserFontFor(QWidget* viewer, QFont *font); @@ -201,13 +201,11 @@ private: private: int lastTabPage; - QString collectionFile; QList<QAction*> globalActionList; QWidget *findBar; QTabWidget *tabWidget; FindWidget *findWidget; - QHelpEngine *helpEngine; QPrinter *printer; bool usesDefaultCollection; diff --git a/tools/assistant/tools/assistant/cmdlineparser.cpp b/tools/assistant/tools/assistant/cmdlineparser.cpp index 30db7a0..b3ba93c 100644 --- a/tools/assistant/tools/assistant/cmdlineparser.cpp +++ b/tools/assistant/tools/assistant/cmdlineparser.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include <QtCore/QFileInfo> #include <QtGui/QMessageBox> @@ -71,6 +72,7 @@ const QString CmdLineParser::m_helpMessage = QLatin1String( " file.\n" "-setCurrentFilter filter Set the filter as the active filter.\n" "-remove-search-index Removes the full text search index.\n" + "-rebuild-search-index Re-builds the full text search index (potentially slow).\n" "-quiet Does not display any error or\n" " status message.\n" "-help Displays this help.\n" @@ -86,8 +88,10 @@ CmdLineParser::CmdLineParser(const QStringList &arguments) m_search(Untouched), m_register(None), m_removeSearchIndex(false), + m_rebuildSearchIndex(false), m_quiet(false) { + TRACE_OBJ for (int i = 1; i < arguments.count(); ++i) { const QString &arg = arguments.at(i); if (arg.toLower() == "-quiet") @@ -99,6 +103,7 @@ CmdLineParser::CmdLineParser(const QStringList &arguments) CmdLineParser::Result CmdLineParser::parse() { + TRACE_OBJ bool showHelp = false; while (m_error.isEmpty() && hasMoreArgs()) { @@ -123,6 +128,8 @@ CmdLineParser::Result CmdLineParser::parse() handleSetCurrentFilterOption(); else if (arg == QLatin1String("-remove-search-index")) m_removeSearchIndex = true; + else if (arg == QLatin1String("-rebuild-search-index")) + m_rebuildSearchIndex = true; else if (arg == QLatin1String("-help")) showHelp = true; else @@ -141,17 +148,20 @@ CmdLineParser::Result CmdLineParser::parse() bool CmdLineParser::hasMoreArgs() const { + TRACE_OBJ return m_pos < m_arguments.count(); } const QString &CmdLineParser::nextArg() { + TRACE_OBJ Q_ASSERT(hasMoreArgs()); return m_arguments.at(m_pos++); } void CmdLineParser::handleCollectionFileOption() { + TRACE_OBJ if (hasMoreArgs()) { const QString &fileName = nextArg(); m_collectionFile = getFileName(fileName); @@ -165,6 +175,7 @@ void CmdLineParser::handleCollectionFileOption() void CmdLineParser::handleShowUrlOption() { + TRACE_OBJ if (hasMoreArgs()) { const QString &urlString = nextArg(); QUrl url(urlString); @@ -179,21 +190,25 @@ void CmdLineParser::handleShowUrlOption() void CmdLineParser::handleShowOption() { + TRACE_OBJ handleShowOrHideOrActivateOption(Show); } void CmdLineParser::handleHideOption() { + TRACE_OBJ handleShowOrHideOrActivateOption(Hide); } void CmdLineParser::handleActivateOption() { + TRACE_OBJ handleShowOrHideOrActivateOption(Activate); } void CmdLineParser::handleShowOrHideOrActivateOption(ShowState state) { + TRACE_OBJ if (hasMoreArgs()) { const QString &widget = nextArg().toLower(); if (widget == QLatin1String("contents")) @@ -213,16 +228,19 @@ void CmdLineParser::handleShowOrHideOrActivateOption(ShowState state) void CmdLineParser::handleRegisterOption() { + TRACE_OBJ handleRegisterOrUnregisterOption(Register); } void CmdLineParser::handleUnregisterOption() { + TRACE_OBJ handleRegisterOrUnregisterOption(Unregister); } void CmdLineParser::handleRegisterOrUnregisterOption(RegisterState state) { + TRACE_OBJ if (hasMoreArgs()) { const QString &fileName = nextArg(); m_helpFile = getFileName(fileName); @@ -237,6 +255,7 @@ void CmdLineParser::handleRegisterOrUnregisterOption(RegisterState state) void CmdLineParser::handleSetCurrentFilterOption() { + TRACE_OBJ if (hasMoreArgs()) m_currentFilter = nextArg(); else @@ -245,6 +264,7 @@ void CmdLineParser::handleSetCurrentFilterOption() QString CmdLineParser::getFileName(const QString &fileName) { + TRACE_OBJ QFileInfo fi(fileName); if (!fi.exists()) return QString(); @@ -253,6 +273,7 @@ QString CmdLineParser::getFileName(const QString &fileName) void CmdLineParser::showMessage(const QString &msg, bool error) { + TRACE_OBJ if (m_quiet) return; #ifdef Q_OS_WIN @@ -268,61 +289,79 @@ void CmdLineParser::showMessage(const QString &msg, bool error) void CmdLineParser::setCollectionFile(const QString &file) { + TRACE_OBJ m_collectionFile = file; } QString CmdLineParser::collectionFile() const { + TRACE_OBJ return m_collectionFile; } QUrl CmdLineParser::url() const { + TRACE_OBJ return m_url; } bool CmdLineParser::enableRemoteControl() const { + TRACE_OBJ return m_enableRemoteControl; } CmdLineParser::ShowState CmdLineParser::contents() const { + TRACE_OBJ return m_contents; } CmdLineParser::ShowState CmdLineParser::index() const { + TRACE_OBJ return m_index; } CmdLineParser::ShowState CmdLineParser::bookmarks() const { + TRACE_OBJ return m_bookmarks; } CmdLineParser::ShowState CmdLineParser::search() const { + TRACE_OBJ return m_search; } QString CmdLineParser::currentFilter() const { + TRACE_OBJ return m_currentFilter; } bool CmdLineParser::removeSearchIndex() const { + TRACE_OBJ return m_removeSearchIndex; } +bool CmdLineParser::rebuildSearchIndex() const +{ + TRACE_OBJ + return m_rebuildSearchIndex; +} + CmdLineParser::RegisterState CmdLineParser::registerRequest() const { + TRACE_OBJ return m_register; } QString CmdLineParser::helpFile() const { + TRACE_OBJ return m_helpFile; } diff --git a/tools/assistant/tools/assistant/cmdlineparser.h b/tools/assistant/tools/assistant/cmdlineparser.h index fbd7c1d..5573081 100644 --- a/tools/assistant/tools/assistant/cmdlineparser.h +++ b/tools/assistant/tools/assistant/cmdlineparser.h @@ -70,6 +70,7 @@ public: ShowState search() const; QString currentFilter() const; bool removeSearchIndex() const; + bool rebuildSearchIndex() const; RegisterState registerRequest() const; QString helpFile() const; @@ -106,6 +107,7 @@ private: RegisterState m_register; QString m_currentFilter; bool m_removeSearchIndex; + bool m_rebuildSearchIndex; bool m_quiet; QString m_error; }; diff --git a/tools/assistant/tools/assistant/contentwindow.cpp b/tools/assistant/tools/assistant/contentwindow.cpp index 5852d3d..976ed7a 100644 --- a/tools/assistant/tools/assistant/contentwindow.cpp +++ b/tools/assistant/tools/assistant/contentwindow.cpp @@ -38,25 +38,26 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "contentwindow.h" #include "centralwidget.h" +#include "helpenginewrapper.h" +#include "helpviewer.h" #include <QtGui/QLayout> #include <QtGui/QFocusEvent> #include <QtGui/QMenu> -#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpContentWidget> QT_BEGIN_NAMESPACE -ContentWindow::ContentWindow(QHelpEngine *helpEngine) - : m_helpEngine(helpEngine) - , m_contentWidget(0) +ContentWindow::ContentWindow() + : m_contentWidget(HelpEngineWrapper::instance().contentWidget()) , m_expandDepth(-2) { - m_contentWidget = m_helpEngine->contentWidget(); + TRACE_OBJ m_contentWidget->viewport()->installEventFilter(this); m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu); @@ -76,10 +77,12 @@ ContentWindow::ContentWindow(QHelpEngine *helpEngine) ContentWindow::~ContentWindow() { + TRACE_OBJ } bool ContentWindow::syncToContent(const QUrl& url) { + TRACE_OBJ QModelIndex idx = m_contentWidget->indexOf(url); if (!idx.isValid()) return false; @@ -89,6 +92,7 @@ bool ContentWindow::syncToContent(const QUrl& url) void ContentWindow::expandTOC() { + TRACE_OBJ Q_ASSERT(m_expandDepth >= -2); if (m_expandDepth > -2) { expandToDepth(m_expandDepth); @@ -98,6 +102,7 @@ void ContentWindow::expandTOC() void ContentWindow::expandToDepth(int depth) { + TRACE_OBJ Q_ASSERT(depth >= -2); m_expandDepth = depth; if (depth == -1) @@ -110,18 +115,21 @@ void ContentWindow::expandToDepth(int depth) void ContentWindow::focusInEvent(QFocusEvent *e) { + TRACE_OBJ if (e->reason() != Qt::MouseFocusReason) m_contentWidget->setFocus(); } void ContentWindow::keyPressEvent(QKeyEvent *e) { + TRACE_OBJ if (e->key() == Qt::Key_Escape) emit escapePressed(); } bool ContentWindow::eventFilter(QObject *o, QEvent *e) { + TRACE_OBJ if (m_contentWidget && o == m_contentWidget->viewport() && e->type() == QEvent::MouseButtonRelease) { QMouseEvent *me = static_cast<QMouseEvent*>(e); @@ -136,7 +144,7 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e) qobject_cast<QHelpContentModel*>(m_contentWidget->model()); if (contentModel) { QHelpContentItem *itm = contentModel->contentItemAt(index); - if (itm && !isPdfFile(itm)) + if (itm && HelpViewer::canOpenPage(itm->url().path())) CentralWidget::instance()->setSourceInNewTab(itm->url()); } } else if (button == Qt::LeftButton) { @@ -150,6 +158,7 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e) void ContentWindow::showContextMenu(const QPoint &pos) { + TRACE_OBJ if (!m_contentWidget->indexAt(pos).isValid()) return; @@ -161,7 +170,7 @@ void ContentWindow::showContextMenu(const QPoint &pos) QMenu menu; QAction *curTab = menu.addAction(tr("Open Link")); QAction *newTab = menu.addAction(tr("Open Link in New Tab")); - if (isPdfFile(itm)) + if (!HelpViewer::canOpenPage(itm->url().path())) newTab->setEnabled(false); menu.move(m_contentWidget->mapToGlobal(pos)); @@ -175,6 +184,7 @@ void ContentWindow::showContextMenu(const QPoint &pos) void ContentWindow::itemClicked(const QModelIndex &index) { + TRACE_OBJ QHelpContentModel *contentModel = qobject_cast<QHelpContentModel*>(m_contentWidget->model()); @@ -185,10 +195,4 @@ void ContentWindow::itemClicked(const QModelIndex &index) } } -bool ContentWindow::isPdfFile(QHelpContentItem *item) const -{ - const QString &path = item->url().path(); - return path.endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive); -} - QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/contentwindow.h b/tools/assistant/tools/assistant/contentwindow.h index f3bf060..62855dd 100644 --- a/tools/assistant/tools/assistant/contentwindow.h +++ b/tools/assistant/tools/assistant/contentwindow.h @@ -57,7 +57,7 @@ class ContentWindow : public QWidget Q_OBJECT public: - ContentWindow(QHelpEngine *helpEngine); + ContentWindow(); ~ContentWindow(); bool syncToContent(const QUrl &url); @@ -78,8 +78,7 @@ private: bool eventFilter(QObject *o, QEvent *e); bool isPdfFile(QHelpContentItem *item) const; - QHelpEngine *m_helpEngine; - QHelpContentWidget *m_contentWidget; + QHelpContentWidget * const m_contentWidget; int m_expandDepth; }; diff --git a/tools/assistant/tools/assistant/filternamedialog.cpp b/tools/assistant/tools/assistant/filternamedialog.cpp index 1560e04..f75f999 100644 --- a/tools/assistant/tools/assistant/filternamedialog.cpp +++ b/tools/assistant/tools/assistant/filternamedialog.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include <QtGui/QPushButton> @@ -48,6 +49,7 @@ QT_BEGIN_NAMESPACE FilterNameDialog::FilterNameDialog(QWidget *parent) : QDialog(parent) { + TRACE_OBJ m_ui.setupUi(this); connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); @@ -61,11 +63,13 @@ FilterNameDialog::FilterNameDialog(QWidget *parent) QString FilterNameDialog::filterName() const { + TRACE_OBJ return m_ui.lineEdit->text(); } void FilterNameDialog::updateOkButton() { + TRACE_OBJ m_ui.buttonBox->button(QDialogButtonBox::Ok) ->setDisabled(m_ui.lineEdit->text().isEmpty()); } diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp new file mode 100644 index 0000000..9785710 --- /dev/null +++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp @@ -0,0 +1,799 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Assistant of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "tracer.h" + +#include "helpenginewrapper.h" +#include "../shared/collectionconfiguration.h" + +#include <QtCore/QDateTime> +#include <QtCore/QFileInfo> +#include <QtCore/QFileSystemWatcher> +#include <QtCore/QPair> +#include <QtCore/QSharedPointer> +#include <QtCore/QTimer> +#include <QtHelp/QHelpContentModel> +#include <QtHelp/QHelpEngine> +#include <QtHelp/QHelpIndexModel> +#include <QtHelp/QHelpSearchEngine> + +QT_BEGIN_NAMESPACE + +namespace { + const QString AppFontKey(QLatin1String("appFont")); + const QString AppWritingSystemKey(QLatin1String("appWritingSystem")); + const QString BookmarksKey(QLatin1String("Bookmarks")); + const QString BrowserFontKey(QLatin1String("browserFont")); + const QString BrowserWritingSystemKey(QLatin1String("browserWritingSystem")); + const QString HomePageKey(QLatin1String("homepage")); + const QString MainWindowKey(QLatin1String("MainWindow")); + const QString MainWindowGeometryKey(QLatin1String("MainWindowGeometry")); + const QString SearchWasAttachedKey(QLatin1String("SearchWasAttached")); + const QString StartOptionKey(QLatin1String("StartOption")); + const QString UnfilteredInsertedKey(QLatin1String("UnfilteredFilterInserted")); + const QString UseAppFontKey(QLatin1String("useAppFont")); + const QString UseBrowserFontKey(QLatin1String("useBrowserFont")); + const QString VersionKey(QString(QLatin1String("qtVersion%1$$$%2")). + arg(QLatin1String(QT_VERSION_STR))); +} // anonymous namespace + +class TimeoutForwarder : public QObject +{ + Q_OBJECT +public: + TimeoutForwarder(const QString &fileName); +private slots: + void forward(); +private: + friend class HelpEngineWrapperPrivate; + + const QString m_fileName; +}; + +class HelpEngineWrapperPrivate : public QObject +{ + Q_OBJECT + friend class HelpEngineWrapper; + friend class TimeoutForwarder; +private slots: + void qchFileChanged(const QString &fileName); + +signals: + void documentationRemoved(const QString &namespaceName); + void documentationUpdated(const QString &namespaceName); + +private: + HelpEngineWrapperPrivate(const QString &collectionFile); + + void initFileSystemWatchers(); + void assertDocFilesWatched(); + void qchFileChanged(const QString &fileName, bool fromTimeout); + + static const int UpdateGracePeriod = 2000; + + QHelpEngine * const m_helpEngine; + QFileSystemWatcher * const m_qchWatcher; + typedef QPair<QDateTime, QSharedPointer<TimeoutForwarder> > RecentSignal; + QMap<QString, RecentSignal> m_recentQchUpdates; +}; + +HelpEngineWrapper *HelpEngineWrapper::helpEngineWrapper = 0; + +HelpEngineWrapper &HelpEngineWrapper::instance(const QString &collectionFile) +{ + TRACE_OBJ + /* + * Note that this Singleton cannot be static, because it has to be + * deleted before the QApplication. + */ + if (helpEngineWrapper == 0) + helpEngineWrapper = new HelpEngineWrapper(collectionFile); + return *helpEngineWrapper; +} + +void HelpEngineWrapper::removeInstance() +{ + TRACE_OBJ + delete helpEngineWrapper; + helpEngineWrapper = 0; +} + +HelpEngineWrapper::HelpEngineWrapper(const QString &collectionFile) + : d(new HelpEngineWrapperPrivate(collectionFile)) +{ + TRACE_OBJ + connect(d, SIGNAL(documentationRemoved(QString)), + this, SIGNAL(documentationRemoved(QString))); + connect(d, SIGNAL(documentationUpdated(QString)), + this, SIGNAL(documentationUpdated(QString))); + connect(d->m_helpEngine, SIGNAL(currentFilterChanged(QString)), + this, SIGNAL(currentFilterChanged(QString))); + connect(d->m_helpEngine, SIGNAL(setupFinished()), + this, SIGNAL(setupFinished())); +} + +HelpEngineWrapper::~HelpEngineWrapper() +{ + TRACE_OBJ + delete d; +} + +QHelpSearchEngine *HelpEngineWrapper::searchEngine() const +{ + TRACE_OBJ + return d->m_helpEngine->searchEngine(); +} + +QHelpContentModel *HelpEngineWrapper::contentModel() const +{ + TRACE_OBJ + return d->m_helpEngine->contentModel(); +} + +QHelpIndexModel *HelpEngineWrapper::indexModel() const +{ + TRACE_OBJ + return d->m_helpEngine->indexModel(); +} + +QHelpContentWidget *HelpEngineWrapper::contentWidget() +{ + TRACE_OBJ + return d->m_helpEngine->contentWidget(); +} + +QHelpIndexWidget *HelpEngineWrapper::indexWidget() +{ + TRACE_OBJ + return d->m_helpEngine->indexWidget(); +} + +const QStringList HelpEngineWrapper::registeredDocumentations() const +{ + TRACE_OBJ + return d->m_helpEngine->registeredDocumentations(); +} + +const QString HelpEngineWrapper::collectionFile() const +{ + TRACE_OBJ + return d->m_helpEngine->collectionFile(); +} + +bool HelpEngineWrapper::registerDocumentation(const QString &docFile) +{ + TRACE_OBJ + d->assertDocFilesWatched(); + if (!d->m_helpEngine->registerDocumentation(docFile)) + return false; + d->m_qchWatcher->addPath(docFile); + d->assertDocFilesWatched(); + return true; +} + +bool HelpEngineWrapper::unregisterDocumentation(const QString &namespaceName) +{ + TRACE_OBJ + d->assertDocFilesWatched(); + const QString &file = d->m_helpEngine->documentationFileName(namespaceName); + if (!d->m_helpEngine->unregisterDocumentation(namespaceName)) + return false; + d->m_qchWatcher->removePath(file); + d->assertDocFilesWatched(); + return true; +} + +bool HelpEngineWrapper::setupData() +{ + TRACE_OBJ + return d->m_helpEngine->setupData(); +} + +bool HelpEngineWrapper::addCustomFilter(const QString &filterName, + const QStringList &attributes) +{ + TRACE_OBJ + return d->m_helpEngine->addCustomFilter(filterName, attributes); +} + +bool HelpEngineWrapper::removeCustomFilter(const QString &filterName) +{ + TRACE_OBJ + return d->m_helpEngine->removeCustomFilter(filterName); +} + +void HelpEngineWrapper::setCurrentFilter(const QString ¤tFilter) +{ + TRACE_OBJ + d->m_helpEngine->setCurrentFilter(currentFilter); +} + +const QString HelpEngineWrapper::currentFilter() const +{ + TRACE_OBJ + return d->m_helpEngine->currentFilter(); +} + +const QStringList HelpEngineWrapper::customFilters() const +{ + TRACE_OBJ + return d->m_helpEngine->customFilters(); +} + +QUrl HelpEngineWrapper::findFile(const QUrl &url) const +{ + TRACE_OBJ + return d->m_helpEngine->findFile(url); +} + +QByteArray HelpEngineWrapper::fileData(const QUrl &url) const +{ + TRACE_OBJ + return d->m_helpEngine->fileData(url); +} + +QMap<QString, QUrl> HelpEngineWrapper::linksForIdentifier(const QString &id) const +{ + TRACE_OBJ + return d->m_helpEngine->linksForIdentifier(id); +} + +const QStringList HelpEngineWrapper::filterAttributes() const +{ + TRACE_OBJ + return d->m_helpEngine->filterAttributes(); +} + +const QStringList HelpEngineWrapper::filterAttributes(const QString &filterName) const +{ + TRACE_OBJ + return d->m_helpEngine->filterAttributes(filterName); +} + +QString HelpEngineWrapper::error() const +{ + TRACE_OBJ + return d->m_helpEngine->error(); +} + +bool HelpEngineWrapper::unfilteredInserted() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(UnfilteredInsertedKey).toInt() == 1; +} + +void HelpEngineWrapper::setUnfilteredInserted() +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(UnfilteredInsertedKey, 1); +} + +const QStringList HelpEngineWrapper::qtDocInfo(const QString &component) const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(VersionKey.arg(component)).toString(). + split(CollectionConfiguration::ListSeparator); +} + +void HelpEngineWrapper::setQtDocInfo(const QString &component, + const QStringList &doc) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(VersionKey.arg(component), + doc.join(CollectionConfiguration::ListSeparator)); +} + +const QStringList HelpEngineWrapper::lastShownPages() const +{ + TRACE_OBJ + return CollectionConfiguration::lastShownPages(*d->m_helpEngine); +} + +void HelpEngineWrapper::setLastShownPages(const QStringList &lastShownPages) +{ + TRACE_OBJ + CollectionConfiguration::setLastShownPages(*d->m_helpEngine, lastShownPages); +} + +const QStringList HelpEngineWrapper::lastZoomFactors() const +{ + TRACE_OBJ + return CollectionConfiguration::lastZoomFactors(*d->m_helpEngine); +} + +void HelpEngineWrapper::setLastZoomFactors(const QStringList &lastZoomFactors) +{ + TRACE_OBJ + CollectionConfiguration::setLastZoomFactors(*d->m_helpEngine, lastZoomFactors); +} + +const QString HelpEngineWrapper::cacheDir() const +{ + TRACE_OBJ + return CollectionConfiguration::cacheDir(*d->m_helpEngine); +} + +bool HelpEngineWrapper::cacheDirIsRelativeToCollection() const +{ + TRACE_OBJ + return CollectionConfiguration::cacheDirIsRelativeToCollection(*d->m_helpEngine); +} + +void HelpEngineWrapper::setCacheDir(const QString &cacheDir, + bool relativeToCollection) +{ + TRACE_OBJ + CollectionConfiguration::setCacheDir(*d->m_helpEngine, cacheDir, + relativeToCollection); +} + +bool HelpEngineWrapper::filterFunctionalityEnabled() const +{ + TRACE_OBJ + return CollectionConfiguration::filterFunctionalityEnabled(*d->m_helpEngine); +} + +void HelpEngineWrapper::setFilterFunctionalityEnabled(bool enabled) +{ + TRACE_OBJ + CollectionConfiguration::setFilterFunctionalityEnabled(*d->m_helpEngine, + enabled); +} + +bool HelpEngineWrapper::filterToolbarVisible() const +{ + TRACE_OBJ + return CollectionConfiguration::filterToolbarVisible(*d->m_helpEngine); +} + +void HelpEngineWrapper::setFilterToolbarVisible(bool visible) +{ + TRACE_OBJ + CollectionConfiguration::setFilterToolbarVisible(*d->m_helpEngine, visible); +} + +bool HelpEngineWrapper::addressBarEnabled() const +{ + TRACE_OBJ + return CollectionConfiguration::addressBarEnabled(*d->m_helpEngine); +} + +void HelpEngineWrapper::setAddressBarEnabled(bool enabled) +{ + TRACE_OBJ + CollectionConfiguration::setAddressBarEnabled(*d->m_helpEngine, enabled); +} + +bool HelpEngineWrapper::addressBarVisible() const +{ + TRACE_OBJ + return CollectionConfiguration::addressBarVisible(*d->m_helpEngine); +} + +void HelpEngineWrapper::setAddressBarVisible(bool visible) +{ + TRACE_OBJ + CollectionConfiguration::setAddressBarVisible(*d->m_helpEngine, visible); +} + +bool HelpEngineWrapper::documentationManagerEnabled() const +{ + TRACE_OBJ + return CollectionConfiguration::documentationManagerEnabled(*d->m_helpEngine); +} + +void HelpEngineWrapper::setDocumentationManagerEnabled(bool enabled) +{ + TRACE_OBJ + CollectionConfiguration::setDocumentationManagerEnabled(*d->m_helpEngine, + enabled); +} + +const QByteArray HelpEngineWrapper::aboutMenuTexts() const +{ + TRACE_OBJ + return CollectionConfiguration::aboutMenuTexts(*d->m_helpEngine); +} + +void HelpEngineWrapper::setAboutMenuTexts(const QByteArray &texts) +{ + TRACE_OBJ + CollectionConfiguration::setAboutMenuTexts(*d->m_helpEngine, texts); +} + +const QByteArray HelpEngineWrapper::aboutIcon() const +{ + TRACE_OBJ + return CollectionConfiguration::aboutIcon(*d->m_helpEngine); +} + +void HelpEngineWrapper::setAboutIcon(const QByteArray &icon) +{ + TRACE_OBJ + CollectionConfiguration::setAboutIcon(*d->m_helpEngine, icon); +} + +const QByteArray HelpEngineWrapper::aboutImages() const +{ + TRACE_OBJ + return CollectionConfiguration::aboutImages(*d->m_helpEngine); +} + +void HelpEngineWrapper::setAboutImages(const QByteArray &images) +{ + TRACE_OBJ + CollectionConfiguration::setAboutImages(*d->m_helpEngine, images); +} + +const QByteArray HelpEngineWrapper::aboutTexts() const +{ + TRACE_OBJ + return CollectionConfiguration::aboutTexts(*d->m_helpEngine); +} + +void HelpEngineWrapper::setAboutTexts(const QByteArray &texts) +{ + TRACE_OBJ + CollectionConfiguration::setAboutTexts(*d->m_helpEngine, texts); +} + +const QString HelpEngineWrapper::windowTitle() const +{ + TRACE_OBJ + return CollectionConfiguration::windowTitle(*d->m_helpEngine); +} + +void HelpEngineWrapper::setWindowTitle(const QString &windowTitle) +{ + TRACE_OBJ + CollectionConfiguration::setWindowTitle(*d->m_helpEngine, windowTitle); +} + +const QByteArray HelpEngineWrapper::applicationIcon() const +{ + TRACE_OBJ + return CollectionConfiguration::applicationIcon(*d->m_helpEngine); +} + +void HelpEngineWrapper::setApplicationIcon(const QByteArray &icon) +{ + TRACE_OBJ + CollectionConfiguration::setApplicationIcon(*d->m_helpEngine, icon); +} + +const QByteArray HelpEngineWrapper::mainWindow() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(MainWindowKey).toByteArray(); +} + +void HelpEngineWrapper::setMainWindow(const QByteArray &mainWindow) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(MainWindowKey, mainWindow); +} + +const QByteArray HelpEngineWrapper::mainWindowGeometry() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(MainWindowGeometryKey).toByteArray(); +} + +void HelpEngineWrapper::setMainWindowGeometry(const QByteArray &geometry) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(MainWindowGeometryKey, geometry); +} + +const QByteArray HelpEngineWrapper::bookmarks() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(BookmarksKey).toByteArray(); +} + +void HelpEngineWrapper::setBookmarks(const QByteArray &bookmarks) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(BookmarksKey, bookmarks); +} + +int HelpEngineWrapper::lastTabPage() const +{ + TRACE_OBJ + return CollectionConfiguration::lastTabPage(*d->m_helpEngine); +} + +void HelpEngineWrapper::setLastTabPage(int lastPage) +{ + TRACE_OBJ + CollectionConfiguration::setLastTabPage(*d->m_helpEngine, lastPage); +} + +bool HelpEngineWrapper::searchWasAttached() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(SearchWasAttachedKey).toBool(); +} + +void HelpEngineWrapper::setSearchWasAttached(bool attached) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(SearchWasAttachedKey, attached); +} + +int HelpEngineWrapper::startOption() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(StartOptionKey, ShowLastPages).toInt(); +} + +void HelpEngineWrapper::setStartOption(int option) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(StartOptionKey, option); +} + +const QString HelpEngineWrapper::homePage() const +{ + TRACE_OBJ + const QString &homePage + = d->m_helpEngine->customValue(HomePageKey).toString(); + if (!homePage.isEmpty()) + return homePage; + return defaultHomePage(); +} + +void HelpEngineWrapper::setHomePage(const QString &page) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(HomePageKey, page); + +} + +const QString HelpEngineWrapper::defaultHomePage() const +{ + TRACE_OBJ + return CollectionConfiguration::defaultHomePage(*d->m_helpEngine); +} + +void HelpEngineWrapper::setDefaultHomePage(const QString &page) +{ + TRACE_OBJ + CollectionConfiguration::setDefaultHomePage(*d->m_helpEngine, page); +} + +bool HelpEngineWrapper::hasFontSettings() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(UseAppFontKey).isValid(); +} + +bool HelpEngineWrapper::usesAppFont() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(UseAppFontKey).toBool(); +} + +void HelpEngineWrapper::setUseAppFont(bool useAppFont) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(UseAppFontKey, useAppFont); +} + +bool HelpEngineWrapper::usesBrowserFont() const +{ + TRACE_OBJ + return d->m_helpEngine->customValue(UseBrowserFontKey, false).toBool(); +} + +void HelpEngineWrapper::setUseBrowserFont(bool useBrowserFont) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(UseBrowserFontKey, useBrowserFont); +} + +const QFont HelpEngineWrapper::appFont() const +{ + TRACE_OBJ + return qVariantValue<QFont>(d->m_helpEngine->customValue(AppFontKey)); +} + +void HelpEngineWrapper::setAppFont(const QFont &font) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(AppFontKey, font); +} + +QFontDatabase::WritingSystem HelpEngineWrapper::appWritingSystem() const +{ + TRACE_OBJ + return static_cast<QFontDatabase::WritingSystem>( + d->m_helpEngine->customValue(AppWritingSystemKey).toInt()); +} + +void HelpEngineWrapper::setAppWritingSystem(QFontDatabase::WritingSystem system) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(AppWritingSystemKey, system); +} + +const QFont HelpEngineWrapper::browserFont() const +{ + TRACE_OBJ + return qVariantValue<QFont>(d->m_helpEngine->customValue(BrowserFontKey)); +} + +void HelpEngineWrapper::setBrowserFont(const QFont &font) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(BrowserFontKey, font); +} + +QFontDatabase::WritingSystem HelpEngineWrapper::browserWritingSystem() const +{ + TRACE_OBJ + return static_cast<QFontDatabase::WritingSystem>( + d->m_helpEngine->customValue(BrowserWritingSystemKey).toInt()); +} + +void HelpEngineWrapper::setBrowserWritingSystem(QFontDatabase::WritingSystem system) +{ + TRACE_OBJ + d->m_helpEngine->setCustomValue(BrowserWritingSystemKey, system); +} + + +TimeoutForwarder::TimeoutForwarder(const QString &fileName) + : m_fileName(fileName) +{ + TRACE_OBJ +} + +void TimeoutForwarder::forward() +{ + TRACE_OBJ + HelpEngineWrapper::instance().d->qchFileChanged(m_fileName, true); +} + + +HelpEngineWrapperPrivate::HelpEngineWrapperPrivate(const QString &collectionFile) + : m_helpEngine(new QHelpEngine(collectionFile, this)), + m_qchWatcher(new QFileSystemWatcher(this)) +{ + TRACE_OBJ + initFileSystemWatchers(); +} + +void HelpEngineWrapperPrivate::initFileSystemWatchers() +{ + TRACE_OBJ + foreach(const QString &ns, m_helpEngine->registeredDocumentations()) { + const QString &docFile = m_helpEngine->documentationFileName(ns); + m_qchWatcher->addPath(docFile); + connect(m_qchWatcher, SIGNAL(fileChanged(QString)), + this, SLOT(qchFileChanged(QString))); + } + assertDocFilesWatched(); +} + +void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName) +{ + TRACE_OBJ + qchFileChanged(fileName, false); +} + +void HelpEngineWrapperPrivate::assertDocFilesWatched() +{ + TRACE_OBJ + Q_ASSERT(m_qchWatcher->files().count() + == m_helpEngine->registeredDocumentations().count()); +} + +void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName, + bool fromTimeout) +{ + TRACE_OBJ + + /* + * We don't use QHelpEngineCore::namespaceName(fileName), because the file + * may not exist anymore or contain a different namespace. + */ + QString ns; + foreach (const QString &curNs, m_helpEngine->registeredDocumentations()) { + if (m_helpEngine->documentationFileName(curNs) == fileName) { + ns = curNs; + break; + } + } + + /* + * We can't do an assertion here, because QFileSystemWatcher may send the + * signal more than once. + */ + if (ns.isEmpty()) { + m_recentQchUpdates.remove(fileName); + return; + } + + /* + * Since the QFileSystemWatcher typically sends the signal more than once, + * we repeatedly delay our reaction a bit until we think the last signal + * was sent. + */ + + QMap<QString, RecentSignal>::Iterator it = m_recentQchUpdates.find(fileName); + const QDateTime &now = QDateTime::currentDateTime(); + + // Case 1: This is the first recent signal for the file. + if (it == m_recentQchUpdates.end()) { + QSharedPointer<TimeoutForwarder> forwarder(new TimeoutForwarder(fileName)); + m_recentQchUpdates.insert(fileName, RecentSignal(now, forwarder)); + QTimer::singleShot(UpdateGracePeriod, forwarder.data(), SLOT(forward())); + return; + } + + // Case 2: The last signal for this file has not expired yet. + if (it.value().first > now.addMSecs(-UpdateGracePeriod)) { + if (!fromTimeout) + it.value().first = now; + else + QTimer::singleShot(UpdateGracePeriod, it.value().second.data(), + SLOT(forward())); + return; + } + + // Case 3: The last signal for this file has expired. + if (m_helpEngine->unregisterDocumentation(ns)) { + if (!QFileInfo(fileName).exists() + || !m_helpEngine->registerDocumentation(fileName)) { + m_qchWatcher->removePath(fileName); + emit documentationRemoved(ns); + } else { + emit documentationUpdated(ns); + } + m_helpEngine->setupData(); + } + m_recentQchUpdates.erase(it); +} + + +QT_END_NAMESPACE + +#include "helpenginewrapper.moc" diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h new file mode 100644 index 0000000..ea7b762 --- /dev/null +++ b/tools/assistant/tools/assistant/helpenginewrapper.h @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Assistant of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HELPENGINEWRAPPER_H +#define HELPENGINEWRAPPER_H + +#include <QtCore/QMap> +#include <QtCore/QObject> +#include <QtCore/QString> +#include <QtCore/QStringList> +#include <QtCore/QUrl> +#include <QtGui/QFont> +#include <QtGui/QFontDatabase> + +QT_BEGIN_NAMESPACE + +class QFileSystemWatcher; +class QHelpContentModel; +class QHelpContentWidget; +class QHelpIndexModel; +class QHelpIndexWidget; +class QHelpSearchEngine; + +enum { + ShowHomePage = 0, + ShowBlankPage = 1, + ShowLastPages = 2 +}; + +class HelpEngineWrapperPrivate; +class TimeoutForwarder; + +class HelpEngineWrapper : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(HelpEngineWrapper) + friend class TimeoutForwarder; +public: + static HelpEngineWrapper &instance(const QString &collectionFile = QString()); + static void removeInstance(); + + // Forwarded help engine member functions, possibly enriched. + QHelpSearchEngine *searchEngine() const; + QHelpContentModel *contentModel() const; + QHelpIndexModel *indexModel() const; + QHelpContentWidget *contentWidget(); + QHelpIndexWidget *indexWidget(); + bool setupData(); + const QStringList registeredDocumentations() const; + const QString collectionFile() const; + bool registerDocumentation(const QString &docFile); + bool unregisterDocumentation(const QString &namespaceName); + bool addCustomFilter(const QString &filterName, + const QStringList &attributes); + bool removeCustomFilter(const QString &filterName); + void setCurrentFilter(const QString &filterName); + const QString currentFilter() const; + const QStringList customFilters() const; + QUrl findFile(const QUrl &url) const; + QByteArray fileData(const QUrl &url) const; + QMap<QString, QUrl> linksForIdentifier(const QString &id) const; + const QStringList filterAttributes() const; + const QStringList filterAttributes(const QString &filterName) const; + QString error() const; + + // Access to a collection's custom values. + bool unfilteredInserted() const; + void setUnfilteredInserted(); + + const QStringList qtDocInfo(const QString &component) const; + void setQtDocInfo(const QString &component, const QStringList &doc); + + const QString homePage() const; + void setHomePage(const QString &page); + const QString defaultHomePage() const; + void setDefaultHomePage(const QString &page); + + int lastTabPage() const; + void setLastTabPage(int lastPage); + + // TODO: Don't allow last pages and zoom factors to be set in isolation + // Perhaps also fill up missing elements automatically or assert. + const QStringList lastShownPages() const; + void setLastShownPages(const QStringList &lastShownPages); + const QStringList lastZoomFactors() const; + void setLastZoomFactors(const QStringList &lastZoomFactors); + + const QString cacheDir() const; + bool cacheDirIsRelativeToCollection() const; + void setCacheDir(const QString &cacheDir, bool relativeToCollection); + + bool filterFunctionalityEnabled() const; + void setFilterFunctionalityEnabled(bool enabled); + + bool filterToolbarVisible() const; + void setFilterToolbarVisible(bool visible); + + bool addressBarEnabled() const; + void setAddressBarEnabled(bool enabled); + + bool addressBarVisible() const; + void setAddressBarVisible(bool visible); + + bool documentationManagerEnabled() const; + void setDocumentationManagerEnabled(bool enabled); + + const QByteArray aboutMenuTexts() const; + void setAboutMenuTexts(const QByteArray &texts); + const QByteArray aboutTexts() const; + void setAboutTexts(const QByteArray &texts); + const QByteArray aboutIcon() const; + void setAboutIcon(const QByteArray &icon); + const QByteArray aboutImages() const; + void setAboutImages(const QByteArray &images); + + const QString windowTitle() const; + void setWindowTitle(const QString &windowTitle); + + const QByteArray applicationIcon() const; + void setApplicationIcon(const QByteArray &icon); + + const QByteArray mainWindow() const; + void setMainWindow(const QByteArray &mainWindow); + const QByteArray mainWindowGeometry() const; + void setMainWindowGeometry(const QByteArray &geometry); + + const QByteArray bookmarks() const; + void setBookmarks(const QByteArray &bookmarks); + + int startOption() const; + void setStartOption(int option); + + bool searchWasAttached() const; + void setSearchWasAttached(bool attached); + + bool hasFontSettings() const; + bool usesAppFont() const; + void setUseAppFont(bool useAppFont); + bool usesBrowserFont() const; + void setUseBrowserFont(bool useBrowserFont); + const QFont appFont() const; + void setAppFont(const QFont &font); + QFontDatabase::WritingSystem appWritingSystem() const; + void setAppWritingSystem(QFontDatabase::WritingSystem system); + const QFont browserFont() const; + void setBrowserFont(const QFont &font); + QFontDatabase::WritingSystem browserWritingSystem() const; + void setBrowserWritingSystem(QFontDatabase::WritingSystem system); + +signals: + + // For asynchronous doc updates triggered by external actions. + void documentationRemoved(const QString &namespaceName); + void documentationUpdated(const QString &namespaceName); + + // Forwarded from QHelpEngineCore. + void currentFilterChanged(const QString ¤tFilter); + void setupFinished(); + +private: + HelpEngineWrapper(const QString &collectionFile); + ~HelpEngineWrapper(); + + static HelpEngineWrapper *helpEngineWrapper; + + HelpEngineWrapperPrivate *d; +}; + +QT_END_NAMESPACE + +#endif // HELPENGINEWRAPPER_H diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index 7ff2a72..efdee92 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -38,15 +38,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "helpviewer.h" #include "centralwidget.h" -#include "../shared/collectionconfiguration.h" +#include "helpenginewrapper.h" #include <QtCore/QDir> #include <QtCore/QEvent> #include <QtCore/QVariant> #include <QtCore/QByteArray> +#include <QtCore/QStringBuilder> +#include <QtCore/QTemporaryFile> #include <QtCore/QTimer> #include <QtGui/QMenu> @@ -56,8 +59,6 @@ #include <QtGui/QMessageBox> #include <QtGui/QDesktopServices> -#include <QtHelp/QHelpEngine> - #include <QNetworkAccessManager> #include <QNetworkReply> #include <QNetworkRequest> @@ -95,6 +96,7 @@ HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request, const QByteArray &fileData, const QString& mimeType) : data(fileData), origLen(fileData.length()) { + TRACE_OBJ setRequest(request); setOpenMode(QIODevice::ReadOnly); @@ -106,11 +108,13 @@ HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request, void HelpNetworkReply::abort() { + TRACE_OBJ // nothing to do } qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen) { + TRACE_OBJ qint64 len = qMin(qint64(data.length()), maxlen); if (len) { qMemCopy(buffer, data.constData(), len); @@ -124,25 +128,23 @@ qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen) class HelpNetworkAccessManager : public QNetworkAccessManager { public: - HelpNetworkAccessManager(QHelpEngine *engine, QObject *parent); + HelpNetworkAccessManager(QObject *parent); protected: virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0); - -private: - QHelpEngine *helpEngine; }; -HelpNetworkAccessManager::HelpNetworkAccessManager(QHelpEngine *engine, - QObject *parent) - : QNetworkAccessManager(parent), helpEngine(engine) +HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent) + : QNetworkAccessManager(parent) { + TRACE_OBJ } QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, const QNetworkRequest &request, QIODevice* /*outgoingData*/) { + TRACE_OBJ const QUrl& url = request.url(); QString mimeType = url.toString(); if (mimeType.endsWith(QLatin1String(".svg")) @@ -158,8 +160,9 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, mimeType = QLatin1String("text/html"); } - const QByteArray &data = helpEngine->findFile(url).isValid() - ? helpEngine->fileData(url) + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + const QByteArray &data = helpEngine.findFile(url).isValid() + ? helpEngine.fileData(url) : PageNotFoundMessage.arg(url.toString()).toUtf8(); return new HelpNetworkReply(request, data, mimeType); } @@ -167,7 +170,7 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, class HelpPage : public QWebPage { public: - HelpPage(CentralWidget *central, QHelpEngine *engine, QObject *parent); + HelpPage(CentralWidget *central, QObject *parent); protected: virtual QWebPage *createWindow(QWebPage::WebWindowType); @@ -178,7 +181,6 @@ protected: private: CentralWidget *centralWidget; - QHelpEngine *helpEngine; bool closeNewTabIfNeeded; friend class HelpViewer; @@ -186,18 +188,19 @@ private: Qt::KeyboardModifiers m_keyboardModifiers; }; -HelpPage::HelpPage(CentralWidget *central, QHelpEngine *engine, QObject *parent) +HelpPage::HelpPage(CentralWidget *central, QObject *parent) : QWebPage(parent) , centralWidget(central) - , helpEngine(engine) , closeNewTabIfNeeded(false) , m_pressedButtons(Qt::NoButton) , m_keyboardModifiers(Qt::NoModifier) { + TRACE_OBJ } QWebPage *HelpPage::createWindow(QWebPage::WebWindowType) { + TRACE_OBJ HelpPage* newPage = static_cast<HelpPage*>(centralWidget->newEmptyTab()->page()); if (newPage) newPage->closeNewTabIfNeeded = closeNewTabIfNeeded; @@ -205,21 +208,9 @@ QWebPage *HelpPage::createWindow(QWebPage::WebWindowType) return newPage; } -static bool isLocalUrl(const QUrl &url) -{ - const QString scheme = url.scheme(); - if (scheme.isEmpty() - || scheme == QLatin1String("file") - || scheme == QLatin1String("qrc") - || scheme == QLatin1String("data") - || scheme == QLatin1String("qthelp") - || scheme == QLatin1String("about")) - return true; - return false; -} - void HelpPage::triggerAction(WebAction action, bool checked) { + TRACE_OBJ switch (action) { case OpenLinkInNewWindow: closeNewTabIfNeeded = true; @@ -232,26 +223,25 @@ void HelpPage::triggerAction(WebAction action, bool checked) bool HelpPage::acceptNavigationRequest(QWebFrame *, const QNetworkRequest &request, QWebPage::NavigationType type) { + TRACE_OBJ const QUrl &url = request.url(); const bool closeNewTab = closeNewTabIfNeeded; closeNewTabIfNeeded = false; - if (isLocalUrl(url)) { + if (HelpViewer::isLocalUrl(url)) { const QString& path = url.path(); - if (path.endsWith(QLatin1String(".pdf"))) { - const int lastDash = path.lastIndexOf(QChar('/')); - QString fileName = QDir::tempPath() + QDir::separator(); - if (lastDash < 0) - fileName += path; - else - fileName += path.mid(lastDash + 1, path.length()); - - QFile tmpFile(QDir::cleanPath(fileName)); - if (tmpFile.open(QIODevice::ReadWrite)) { - tmpFile.write(helpEngine->fileData(url)); - tmpFile.close(); + if (!HelpViewer::canOpenPage(path)) { + QTemporaryFile tmpTmpFile; + if (!tmpTmpFile.open()) + return false; + const QString extension = QFileInfo(path).completeSuffix(); + QFile actualTmpFile(tmpTmpFile.fileName() % QLatin1String(".") + % extension); + if (actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) { + actualTmpFile.write(HelpEngineWrapper::instance().fileData(url)); + actualTmpFile.close(); + QDesktopServices::openUrl(QUrl(actualTmpFile.fileName())); } - QDesktopServices::openUrl(QUrl(tmpFile.fileName())); if (closeNewTab) QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab"); @@ -275,17 +265,18 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *, return false; } -HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) +HelpViewer::HelpViewer(CentralWidget *parent) : QWebView(parent) - , helpEngine(engine) , parentWidget(parent) , loadFinished(false) + , helpEngine(HelpEngineWrapper::instance()) { + TRACE_OBJ setAcceptDrops(false); - setPage(new HelpPage(parent, helpEngine, this)); + setPage(new HelpPage(parent, this)); - page()->setNetworkAccessManager(new HelpNetworkAccessManager(engine, this)); + page()->setNetworkAccessManager(new HelpNetworkAccessManager(this)); QAction* action = pageAction(QWebPage::OpenLinkInNewWindow); action->setText(tr("Open Link in New Tab")); @@ -310,6 +301,7 @@ HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) void HelpViewer::setSource(const QUrl &url) { + TRACE_OBJ loadFinished = false; if (url.toString() == QLatin1String("help")) { load(QUrl(QLatin1String("qthelp://com.trolltech.com." @@ -321,21 +313,25 @@ void HelpViewer::setSource(const QUrl &url) void HelpViewer::resetZoom() { + TRACE_OBJ setTextSizeMultiplier(1.0); } void HelpViewer::zoomIn(qreal range) { + TRACE_OBJ setTextSizeMultiplier(textSizeMultiplier() + range / 10.0); } void HelpViewer::zoomOut(qreal range) { + TRACE_OBJ setTextSizeMultiplier(qMax(0.0, textSizeMultiplier() - range / 10.0)); } void HelpViewer::wheelEvent(QWheelEvent *e) { + TRACE_OBJ if (e->modifiers() & Qt::ControlModifier) { const int delta = e->delta(); if (delta > 0) @@ -350,6 +346,7 @@ void HelpViewer::wheelEvent(QWheelEvent *e) void HelpViewer::mouseReleaseEvent(QMouseEvent *e) { + TRACE_OBJ if (e->button() == Qt::XButton1) { triggerPageAction(QWebPage::Back); return; @@ -365,6 +362,7 @@ void HelpViewer::mouseReleaseEvent(QMouseEvent *e) void HelpViewer::actionChanged() { + TRACE_OBJ QAction *a = qobject_cast<QAction *>(sender()); if (a == pageAction(QWebPage::Copy)) emit copyAvailable(a->isEnabled()); @@ -376,6 +374,7 @@ void HelpViewer::actionChanged() void HelpViewer::mousePressEvent(QMouseEvent *event) { + TRACE_OBJ HelpPage *currentPage = static_cast<HelpPage*>(page()); if (currentPage) { currentPage->m_pressedButtons = event->buttons(); @@ -386,31 +385,34 @@ void HelpViewer::mousePressEvent(QMouseEvent *event) void HelpViewer::setLoadFinished(bool ok) { + TRACE_OBJ loadFinished = ok; emit sourceChanged(url()); } #else // !defined(QT_NO_WEBKIT) -HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) +HelpViewer::HelpViewer(CentralWidget *parent) : QTextBrowser(parent) , zoomCount(0) , controlPressed(false) , lastAnchor(QString()) - , helpEngine(engine) , parentWidget(parent) + , helpEngine(HelpEngineWrapper::instance()) { + TRACE_OBJ document()->setDocumentMargin(8); } void HelpViewer::setSource(const QUrl &url) { + TRACE_OBJ bool help = url.toString() == QLatin1String("help"); if (url.isValid() && !help) { if (launchedWithExternalApp(url)) return; - QUrl u = helpEngine->findFile(url); + QUrl u = helpEngine.findFile(url); if (u.isValid()) { QTextBrowser::setSource(u); return; @@ -429,6 +431,7 @@ void HelpViewer::setSource(const QUrl &url) void HelpViewer::resetZoom() { + TRACE_OBJ if (zoomCount == 0) return; @@ -438,6 +441,7 @@ void HelpViewer::resetZoom() void HelpViewer::zoomIn(int range) { + TRACE_OBJ if (zoomCount == 10) return; @@ -447,6 +451,7 @@ void HelpViewer::zoomIn(int range) void HelpViewer::zoomOut(int range) { + TRACE_OBJ if (zoomCount == -5) return; @@ -456,12 +461,11 @@ void HelpViewer::zoomOut(int range) bool HelpViewer::launchedWithExternalApp(const QUrl &url) { - bool isPdf = url.path().endsWith(QLatin1String(".pdf")); - if (url.scheme() == QLatin1String("http") - || url.scheme() == QLatin1String("ftp") - || url.scheme() == QLatin1String("mailto") || isPdf) { + TRACE_OBJ + const bool canOpen = canOpenPage(url.path()); + if (!isLocalUrl(url) || !canOpen) { bool launched = false; - if (isPdf && url.scheme() == QLatin1String("qthelp")) { + if (!canOpen && url.scheme() == QLatin1String("qthelp")) { const QString& path = url.path(); const int lastDash = path.lastIndexOf(QChar('/')); QString fileName = QDir::tempPath() + QDir::separator(); @@ -472,7 +476,7 @@ bool HelpViewer::launchedWithExternalApp(const QUrl &url) QFile tmpFile(QDir::cleanPath(fileName)); if (tmpFile.open(QIODevice::ReadWrite)) { - tmpFile.write(helpEngine->fileData(url)); + tmpFile.write(helpEngine.fileData(url)); tmpFile.close(); } launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName())); @@ -491,9 +495,10 @@ bool HelpViewer::launchedWithExternalApp(const QUrl &url) QVariant HelpViewer::loadResource(int type, const QUrl &name) { + TRACE_OBJ QByteArray ba; if (type < 4) { - ba = helpEngine->fileData(name); + ba = helpEngine.fileData(name); if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) { QImage image; image.loadFromData(ba, "svg"); @@ -506,6 +511,7 @@ QVariant HelpViewer::loadResource(int type, const QUrl &name) void HelpViewer::openLinkInNewTab() { + TRACE_OBJ if(lastAnchor.isEmpty()) return; @@ -515,12 +521,14 @@ void HelpViewer::openLinkInNewTab() void HelpViewer::openLinkInNewTab(const QString &link) { + TRACE_OBJ lastAnchor = link; openLinkInNewTab(); } bool HelpViewer::hasAnchorAt(const QPoint& pos) { + TRACE_OBJ lastAnchor = anchorAt(pos); if (lastAnchor.isEmpty()) return false; @@ -537,6 +545,7 @@ bool HelpViewer::hasAnchorAt(const QPoint& pos) void HelpViewer::contextMenuEvent(QContextMenuEvent *e) { + TRACE_OBJ QMenu menu(QLatin1String(""), 0); QUrl link; @@ -560,6 +569,7 @@ void HelpViewer::contextMenuEvent(QContextMenuEvent *e) void HelpViewer::mouseReleaseEvent(QMouseEvent *e) { + TRACE_OBJ if (e->button() == Qt::XButton1) { QTextBrowser::backward(); return; @@ -582,6 +592,7 @@ void HelpViewer::mouseReleaseEvent(QMouseEvent *e) void HelpViewer::keyPressEvent(QKeyEvent *e) { + TRACE_OBJ if ((e->key() == Qt::Key_Home && e->modifiers() != Qt::NoModifier) || (e->key() == Qt::Key_End && e->modifiers() != Qt::NoModifier)) { QKeyEvent* event = new QKeyEvent(e->type(), e->key(), Qt::NoModifier, @@ -593,6 +604,7 @@ void HelpViewer::keyPressEvent(QKeyEvent *e) void HelpViewer::wheelEvent(QWheelEvent *e) { + TRACE_OBJ if (e->modifiers() == Qt::CTRL) { e->accept(); (e->delta() > 0) ? zoomIn() : zoomOut(); @@ -606,10 +618,29 @@ void HelpViewer::wheelEvent(QWheelEvent *e) void HelpViewer::home() { - QString homePage = CollectionConfiguration::homePage(*helpEngine); - if (homePage.isEmpty()) - homePage = CollectionConfiguration::defaultHomePage(*helpEngine); - setSource(homePage); + TRACE_OBJ + setSource(helpEngine.homePage()); +} + +bool HelpViewer::canOpenPage(const QString &url) +{ + TRACE_OBJ + return url.endsWith(QLatin1String(".html"), Qt::CaseInsensitive) + || url.endsWith(QLatin1String(".htm"), Qt::CaseInsensitive) + || url == QLatin1String("blank"); } +bool HelpViewer::isLocalUrl(const QUrl &url) +{ + TRACE_OBJ + const QString scheme = url.scheme(); + return scheme.isEmpty() + || scheme == QLatin1String("file") + || scheme == QLatin1String("qrc") + || scheme == QLatin1String("data") + || scheme == QLatin1String("qthelp") + || scheme == QLatin1String("about"); +} + + QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h index 3618a73..4dd8064 100644 --- a/tools/assistant/tools/assistant/helpviewer.h +++ b/tools/assistant/tools/assistant/helpviewer.h @@ -53,8 +53,8 @@ QT_BEGIN_NAMESPACE -class QHelpEngine; class CentralWidget; +class HelpEngineWrapper; class QPoint; class QString; @@ -69,7 +69,7 @@ class HelpViewer : public QWebView Q_OBJECT public: - HelpViewer(QHelpEngine *helpEngine, CentralWidget *parent); + HelpViewer(CentralWidget *parent); void setSource(const QUrl &url); inline QUrl source() const @@ -97,6 +97,9 @@ public: inline qreal zoom() const { return textSizeMultiplier(); } + static bool canOpenPage(const QString &url); + static bool isLocalUrl(const QUrl &url); + public Q_SLOTS: void home(); void backward() { back(); } @@ -118,9 +121,9 @@ private Q_SLOTS: void setLoadFinished(bool ok); private: - QHelpEngine *helpEngine; CentralWidget* parentWidget; bool loadFinished; + HelpEngineWrapper &helpEngine; }; #else @@ -130,7 +133,7 @@ class HelpViewer : public QTextBrowser Q_OBJECT public: - HelpViewer(QHelpEngine *helpEngine, CentralWidget *parent); + HelpViewer(CentralWidget *parent); void setSource(const QUrl &url); void resetZoom(); @@ -143,6 +146,8 @@ public: { return textCursor().hasSelection(); } bool launchedWithExternalApp(const QUrl &url); + static bool canOpenPage(const QString &url); + static bool isLocalUrl(const QUrl &url); public Q_SLOTS: void home(); @@ -165,8 +170,8 @@ private: int zoomCount; bool controlPressed; QString lastAnchor; - QHelpEngine *helpEngine; CentralWidget* parentWidget; + HelpEngineWrapper &helpEngine; }; #endif diff --git a/tools/assistant/tools/assistant/indexwindow.cpp b/tools/assistant/tools/assistant/indexwindow.cpp index 24a212e..82242e5 100644 --- a/tools/assistant/tools/assistant/indexwindow.cpp +++ b/tools/assistant/tools/assistant/indexwindow.cpp @@ -38,9 +38,12 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "indexwindow.h" #include "centralwidget.h" +#include "helpenginewrapper.h" +#include "helpviewer.h" #include "topicchooser.h" #include <QtGui/QLayout> @@ -51,22 +54,20 @@ #include <QtGui/QContextMenuEvent> #include <QtGui/QListWidgetItem> -#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpIndexWidget> QT_BEGIN_NAMESPACE -IndexWindow::IndexWindow(QHelpEngine *helpEngine, QWidget *parent) +IndexWindow::IndexWindow(QWidget *parent) : QWidget(parent) - , m_searchLineEdit(0) - , m_indexWidget(0) - , m_helpEngine(helpEngine) + , m_searchLineEdit(new QLineEdit) + , m_indexWidget(HelpEngineWrapper::instance().indexWidget()) { + TRACE_OBJ QVBoxLayout *layout = new QVBoxLayout(this); QLabel *l = new QLabel(tr("&Look for:")); layout->addWidget(l); - m_searchLineEdit = new QLineEdit(); l->setBuddy(m_searchLineEdit); connect(m_searchLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterIndices(QString))); @@ -74,11 +75,11 @@ IndexWindow::IndexWindow(QHelpEngine *helpEngine, QWidget *parent) layout->setMargin(4); layout->addWidget(m_searchLineEdit); - m_indexWidget = m_helpEngine->indexWidget(); + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); m_indexWidget->installEventFilter(this); - connect(m_helpEngine->indexModel(), SIGNAL(indexCreationStarted()), this, + connect(helpEngine.indexModel(), SIGNAL(indexCreationStarted()), this, SLOT(disableSearchLineEdit())); - connect(m_helpEngine->indexModel(), SIGNAL(indexCreated()), this, + connect(helpEngine.indexModel(), SIGNAL(indexCreated()), this, SLOT(enableSearchLineEdit())); connect(m_indexWidget, SIGNAL(linkActivated(QUrl,QString)), this, SIGNAL(linkActivated(QUrl))); @@ -93,10 +94,12 @@ IndexWindow::IndexWindow(QHelpEngine *helpEngine, QWidget *parent) IndexWindow::~IndexWindow() { + TRACE_OBJ } void IndexWindow::filterIndices(const QString &filter) { + TRACE_OBJ if (filter.contains(QLatin1Char('*'))) m_indexWidget->filterIndices(filter, filter); else @@ -105,6 +108,7 @@ void IndexWindow::filterIndices(const QString &filter) bool IndexWindow::eventFilter(QObject *obj, QEvent *e) { + TRACE_OBJ if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast<QKeyEvent*>(e); QModelIndex idx = m_indexWidget->currentIndex(); @@ -170,22 +174,26 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) void IndexWindow::enableSearchLineEdit() { + TRACE_OBJ m_searchLineEdit->setDisabled(false); filterIndices(m_searchLineEdit->text()); } void IndexWindow::disableSearchLineEdit() { + TRACE_OBJ m_searchLineEdit->setDisabled(true); } void IndexWindow::setSearchLineEditText(const QString &text) { + TRACE_OBJ m_searchLineEdit->setText(text); } void IndexWindow::focusInEvent(QFocusEvent *e) { + TRACE_OBJ if (e->reason() != Qt::MouseFocusReason) { m_searchLineEdit->selectAll(); m_searchLineEdit->setFocus(); @@ -194,6 +202,7 @@ void IndexWindow::focusInEvent(QFocusEvent *e) void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) { + TRACE_OBJ QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(indexWidget->model()); if (model) { QString keyword = model->data(index, Qt::DisplayRole).toString(); @@ -210,7 +219,7 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) return; } - if (url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive)) + if (!HelpViewer::canOpenPage(url.path())) CentralWidget::instance()->setSource(url); else CentralWidget::instance()->setSourceInNewTab(url); diff --git a/tools/assistant/tools/assistant/indexwindow.h b/tools/assistant/tools/assistant/indexwindow.h index 4343d0e..eb587b1 100644 --- a/tools/assistant/tools/assistant/indexwindow.h +++ b/tools/assistant/tools/assistant/indexwindow.h @@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE class QHelpIndexWidget; -class QHelpEngine; class QModelIndex; class IndexWindow : public QWidget @@ -57,7 +56,7 @@ class IndexWindow : public QWidget Q_OBJECT public: - IndexWindow(QHelpEngine *helpEngine, QWidget *parent = 0); + IndexWindow(QWidget *parent = 0); ~IndexWindow(); void setSearchLineEditText(const QString &text); @@ -84,7 +83,6 @@ private: QLineEdit *m_searchLineEdit; QHelpIndexWidget *m_indexWidget; - QHelpEngine *m_helpEngine; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/installdialog.cpp b/tools/assistant/tools/assistant/installdialog.cpp index 95a1226..f3bf6f6 100644 --- a/tools/assistant/tools/assistant/installdialog.cpp +++ b/tools/assistant/tools/assistant/installdialog.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "installdialog.h" @@ -66,6 +67,7 @@ InstallDialog::InstallDialog(QHelpEngineCore *helpEngine, QWidget *parent, const QString &host, int port) : QDialog(parent), m_helpEngine(helpEngine), m_host(host), m_port(port) { + TRACE_OBJ m_ui.setupUi(this); m_ui.installButton->setEnabled(false); @@ -94,15 +96,18 @@ InstallDialog::InstallDialog(QHelpEngineCore *helpEngine, QWidget *parent, InstallDialog::~InstallDialog() { + TRACE_OBJ } QStringList InstallDialog::installedDocumentations() const { + TRACE_OBJ return m_installedDocumentations; } void InstallDialog::init() { + TRACE_OBJ m_ui.statusLabel->setText(tr("Downloading documentation info...")); m_ui.progressBar->show(); @@ -122,6 +127,7 @@ void InstallDialog::init() void InstallDialog::updateInstallButton() { + TRACE_OBJ QListWidgetItem *item = 0; for (int i=0; i<m_ui.listWidget->count(); ++i) { item = m_ui.listWidget->item(i); @@ -136,6 +142,7 @@ void InstallDialog::updateInstallButton() void InstallDialog::updateDocItemList() { + TRACE_OBJ QStringList registeredDocs = m_helpEngine->registeredDocumentations(); QListWidgetItem *item = 0; for (int i=0; i<m_ui.listWidget->count(); ++i) { @@ -151,6 +158,7 @@ void InstallDialog::updateDocItemList() void InstallDialog::cancelDownload() { + TRACE_OBJ m_ui.statusLabel->setText(tr("Download canceled.")); m_httpAborted = true; m_itemsToInstall.clear(); @@ -162,6 +170,7 @@ void InstallDialog::cancelDownload() void InstallDialog::install() { + TRACE_OBJ QListWidgetItem *item = 0; for (int i=0; i<m_ui.listWidget->count(); ++i) { item = m_ui.listWidget->item(i); @@ -174,6 +183,7 @@ void InstallDialog::install() void InstallDialog::downloadNextFile() { + TRACE_OBJ if (!m_itemsToInstall.count()) { m_ui.cancelButton->setEnabled(false); m_ui.closeButton->setEnabled(true); @@ -226,6 +236,7 @@ void InstallDialog::downloadNextFile() void InstallDialog::httpRequestFinished(int requestId, bool error) { + TRACE_OBJ if (requestId == m_docInfoId && m_buffer) { m_ui.progressBar->hide(); if (error) { @@ -296,6 +307,7 @@ void InstallDialog::httpRequestFinished(int requestId, bool error) void InstallDialog::installFile(const QString &fileName) { + TRACE_OBJ if (m_helpEngine->registerDocumentation(fileName)) { m_installedDocumentations .append(QHelpEngineCore::namespaceName(fileName)); @@ -308,6 +320,7 @@ void InstallDialog::installFile(const QString &fileName) void InstallDialog::readResponseHeader(const QHttpResponseHeader &responseHeader) { + TRACE_OBJ if (responseHeader.statusCode() != 200) { QMessageBox::information(this, m_windowTitle, tr("Download failed: %1.") @@ -321,6 +334,7 @@ void InstallDialog::readResponseHeader(const QHttpResponseHeader &responseHeader void InstallDialog::updateDataReadProgress(int bytesRead, int totalBytes) { + TRACE_OBJ if (m_httpAborted) return; @@ -330,6 +344,7 @@ void InstallDialog::updateDataReadProgress(int bytesRead, int totalBytes) void InstallDialog::browseDirectories() { + TRACE_OBJ QString dir = QFileDialog::getExistingDirectory(this, m_windowTitle, m_ui.pathLineEdit->text()); if (!dir.isEmpty()) diff --git a/tools/assistant/tools/assistant/main.cpp b/tools/assistant/tools/assistant/main.cpp index 2c0d4a8..434a211 100644 --- a/tools/assistant/tools/assistant/main.cpp +++ b/tools/assistant/tools/assistant/main.cpp @@ -38,28 +38,34 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include <QtCore/QDir> #include <QtCore/QFileInfo> +#include <QtCore/QLibraryInfo> #include <QtCore/QLocale> +#include <QtCore/QScopedPointer> +#include <QtCore/QStringList> #include <QtCore/QTranslator> -#include <QtCore/QLibraryInfo> #include <QtCore/QUrl> -#include <QtCore/QStringList> #include <QtGui/QApplication> #include <QtGui/QDesktopServices> -#include <QtHelp/QHelpEngineCore> +#include <QtHelp/QHelpEngine> +#include <QtHelp/QHelpSearchEngine> #include <QtNetwork/QLocalSocket> #include <QtSql/QSqlDatabase> #include "../shared/collectionconfiguration.h" +#include "helpenginewrapper.h" #include "mainwindow.h" #include "cmdlineparser.h" +// #define TRACING_REQUESTED + QT_USE_NAMESPACE #if defined(USE_STATIC_SQLITE_PLUGIN) @@ -72,6 +78,7 @@ namespace { void updateLastPagesOnUnregister(QHelpEngineCore& helpEngine, const QString& nsName) { + TRACE_OBJ int lastPage = CollectionConfiguration::lastTabPage(helpEngine); QStringList currentPages = CollectionConfiguration::lastShownPages(helpEngine); if (!currentPages.isEmpty()) { @@ -96,30 +103,27 @@ updateLastPagesOnUnregister(QHelpEngineCore& helpEngine, const QString& nsName) bool updateUserCollection(QHelpEngineCore& user, const QHelpEngineCore& caller) { + TRACE_OBJ if (!CollectionConfiguration::isNewer(caller, user)) return false; CollectionConfiguration::copyConfiguration(caller, user); return true; } -bool -referencedHelpFilesExistAll(QHelpEngineCore& user, QStringList& nameSpaces) +void stripNonexistingDocs(QHelpEngineCore& collection) { - QFileInfo fi; - int counter = nameSpaces.count(); - for (int i = counter; --i >= 0;) { - const QString& nameSpace = nameSpaces.at(i); - fi.setFile(user.documentationFileName(nameSpace)); - if (!fi.exists() || !fi.isFile()) { - user.unregisterDocumentation(nameSpace); - nameSpaces.removeAll(nameSpace); - } + TRACE_OBJ + const QStringList &namespaces = collection.registeredDocumentations(); + foreach (const QString &ns, namespaces) { + QFileInfo fi(collection.documentationFileName(ns)); + if (!fi.exists() || !fi.isFile()) + collection.unregisterDocumentation(ns); } - return (counter != nameSpaces.count()) ? false : true; } QString indexFilesFolder(const QString &collectionFile) { + TRACE_OBJ QString indexFilesFolder = QLatin1String(".fulltextsearch"); if (!collectionFile.isEmpty()) { QFileInfo fi(collectionFile); @@ -129,30 +133,183 @@ QString indexFilesFolder(const QString &collectionFile) return indexFilesFolder; } -} // Anonymous namespace. +/* + * Returns the expected absolute file path of the cached collection file + * correspondinging to the given collection's file. + * It may or may not exist yet. + */ +QString constructCachedCollectionFilePath(const QHelpEngineCore &collection) +{ + TRACE_OBJ + const QString &filePath = collection.collectionFile(); + const QString &fileName = QFileInfo(filePath).fileName(); + const QString &cacheDir = CollectionConfiguration::cacheDir(collection); + const QString &dir = !cacheDir.isEmpty() + && CollectionConfiguration::cacheDirIsRelativeToCollection(collection) + ? QFileInfo(filePath).dir().absolutePath() + + QDir::separator() + cacheDir + : MainWindow::collectionFileDirectory(false, cacheDir); + return dir + QDir::separator() + fileName; +} -int main(int argc, char *argv[]) +bool synchronizeDocs(QHelpEngineCore &collection, + QHelpEngineCore &cachedCollection, + CmdLineParser &cmd) +{ + TRACE_OBJ + const QDateTime &lastCollectionRegisterTime = + CollectionConfiguration::lastRegisterTime(collection); + if (!lastCollectionRegisterTime.isValid() || lastCollectionRegisterTime + < CollectionConfiguration::lastRegisterTime(cachedCollection)) + return true; + + const QStringList &docs = collection.registeredDocumentations(); + const QStringList &cachedDocs = cachedCollection.registeredDocumentations(); + + /* + * Ensure that the cached collection contains all docs that + * the collection contains. + */ + foreach (const QString &doc, docs) { + if (!cachedDocs.contains(doc)) { + const QString &docFile = collection.documentationFileName(doc); + if (!cachedCollection.registerDocumentation(docFile)) { + cmd.showMessage(QObject::tr("Error registering documentation file '%1': %2"). + arg(docFile).arg(cachedCollection.error()), true); + return false; + } + } + } + + CollectionConfiguration::updateLastRegisterTime(cachedCollection); + + return true; +} + +bool removeSearchIndex(const QString &collectionFile) +{ + TRACE_OBJ + QString path = QFileInfo(collectionFile).path(); + path += QLatin1Char('/') + indexFilesFolder(collectionFile); + + QLocalSocket localSocket; + localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) + .arg(QLatin1String(QT_VERSION_STR))); + + QDir dir(path); // check if there is no other instance ruinning + if (!dir.exists() || localSocket.waitForConnected()) + return false; + + QStringList lst = dir.entryList(QDir::Files | QDir::Hidden); + foreach (const QString &item, lst) + dir.remove(item); + return true; +} + +bool rebuildSearchIndex(QCoreApplication &app, const QString &collectionFile, + CmdLineParser &cmd) { -#ifndef Q_OS_WIN - // First do a quick search for arguments that imply command-line mode. + TRACE_OBJ + QHelpEngine engine(collectionFile); + if (!engine.setupData()) { + cmd.showMessage(QObject::tr("Error: %1").arg(engine.error()), true); + return false; + } + + QHelpSearchEngine * const searchEngine = engine.searchEngine(); + QObject::connect(searchEngine, SIGNAL(indexingFinished()), &app, + SLOT(quit())); + searchEngine->reindexDocumentation(); + return app.exec() == 0; +} + +bool useGui(int argc, char *argv[]) +{ + TRACE_OBJ + bool gui = true; +#ifndef Q_OS_WIN + // Look for arguments that imply command-line mode. const char * cmdModeArgs[] = { - "-help", "-register", "-unregister", "-remove-search-index" + "-help", "-register", "-unregister", "-remove-search-index", + "-rebuild-search-index" }; - bool useGui = true; for (int i = 1; i < argc; ++i) { for (size_t j = 0; j < sizeof cmdModeArgs/sizeof *cmdModeArgs; ++j) { if(strcmp(argv[i], cmdModeArgs[j]) == 0) { - useGui = false; + gui = false; break; } } } - QApplication a(argc, argv, useGui); -#else - QApplication a(argc, argv); #endif + return gui; +} + +bool registerDocumentation(QHelpEngineCore &collection, CmdLineParser &cmd, + bool printSuccess) +{ + TRACE_OBJ + if (!collection.registerDocumentation(cmd.helpFile())) { + cmd.showMessage( + QObject::tr("Could not register documentation file\n%1\n\nReason:\n%2") + .arg(cmd.helpFile()).arg(collection.error()), true); + return false; + } + if (printSuccess) + cmd.showMessage(QObject::tr("Documentation successfully registered."), + false); + CollectionConfiguration::updateLastRegisterTime(collection); + return true; +} + +bool unregisterDocumentation(QHelpEngineCore &collection, + const QString &namespaceName, CmdLineParser &cmd, bool printSuccess) +{ + TRACE_OBJ + if (!collection.unregisterDocumentation(namespaceName)) { + cmd.showMessage(QObject::tr("Could not unregister documentation" + " file\n%1\n\nReason:\n%2"). + arg(cmd.helpFile()).arg(collection.error()), true); + return false; + } + updateLastPagesOnUnregister(collection, namespaceName); + if (printSuccess) + cmd.showMessage(QObject::tr("Documentation successfully unregistered."), + false); + return true; +} + +void setupTranslation(const QString &fileName, const QString &dir) +{ + QTranslator *translator = new QTranslator(QCoreApplication::instance()); + if (translator->load(fileName, dir)) { + QCoreApplication::installTranslator(translator); + } else { + qWarning("Could not load translation file %s in directory %s.", + qPrintable(fileName), qPrintable(dir)); + } +} + +void setupTranslations() +{ + TRACE_OBJ + const QString& locale = QLocale::system().name(); + const QString &resourceDir + = QLibraryInfo::location(QLibraryInfo::TranslationsPath); + setupTranslation(QLatin1String("assistant_") + locale, resourceDir); + setupTranslation(QLatin1String("qt_") + locale, resourceDir); + setupTranslation(QLatin1String("qt_help_") + locale, resourceDir); +} + +} // Anonymous namespace. + +int main(int argc, char *argv[]) +{ + TRACE_OBJ + QApplication a(argc, argv, useGui(argc, argv)); a.addLibraryPath(a.applicationDirPath() + QLatin1String("/plugins")); + // Parse arguments. CmdLineParser cmd(a.arguments()); CmdLineParser::Result res = cmd.parse(); if (res == CmdLineParser::Help) @@ -160,165 +317,109 @@ int main(int argc, char *argv[]) else if (res == CmdLineParser::Error) return -1; - QString cmdCollectionFile = cmd.collectionFile(); - if (cmd.registerRequest() != CmdLineParser::None) { - if (cmdCollectionFile.isEmpty()) - cmdCollectionFile = MainWindow::defaultHelpCollectionFileName(); - QHelpEngineCore help(cmdCollectionFile); - help.setupData(); - if (cmd.registerRequest() == CmdLineParser::Register) { - if (!help.registerDocumentation(cmd.helpFile())) { - cmd.showMessage( - QObject::tr("Could not register documentation file\n%1\n\nReason:\n%2") - .arg(cmd.helpFile()).arg(help.error()), true); - return -1; - } else { - cmd.showMessage(QObject::tr("Documentation successfully registered."), - false); - } - } else { - QString nsName = QHelpEngineCore::namespaceName(cmd.helpFile()); - if (help.unregisterDocumentation(nsName)) { - updateLastPagesOnUnregister(help, nsName); - cmd.showMessage( - QObject::tr("Documentation successfully unregistered."), - false); - } else { - cmd.showMessage(QObject::tr("Could not unregister documentation" - " file\n%1\n\nReason:\n%2").arg(cmd.helpFile()). - arg(help.error()), true); - return -1; - } + /* + * Create the collection objects that we need. We always have the + * cached collection file. Depending on whether the user specified + * one, we also may have an input collection file. + */ + const QString collectionFile = cmd.collectionFile(); + const bool collectionFileGiven = !collectionFile.isEmpty(); + QScopedPointer<QHelpEngineCore> collection; + if (collectionFileGiven) { + collection.reset(new QHelpEngineCore(collectionFile)); + if (!collection->setupData()) { + cmd.showMessage(QObject::tr("Error reading collection file '%1': %2."). + arg(collectionFile).arg(collection->error()), true); + return EXIT_FAILURE; } - CollectionConfiguration::setDocUpdatePending(help, true); - return 0; } - - if (cmd.removeSearchIndex()) { - QString file = cmdCollectionFile; - if (file.isEmpty()) - file = MainWindow::defaultHelpCollectionFileName(); - QString path = QFileInfo(file).path(); - path += QLatin1Char('/') + indexFilesFolder(file); - - QLocalSocket localSocket; - localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) - .arg(QLatin1String(QT_VERSION_STR))); - - QDir dir(path); // check if there is no other instance ruinning - if (!localSocket.waitForConnected() && dir.exists()) { - QStringList lst = dir.entryList(QDir::Files | QDir::Hidden); - foreach (const QString &item, lst) - dir.remove(item); - return 0; - } else { - return -1; - } + const QString &cachedCollectionFile = collectionFileGiven + ? constructCachedCollectionFilePath(*collection) + : MainWindow::defaultHelpCollectionFileName(); + if (collectionFileGiven && !QFileInfo(cachedCollectionFile).exists() + && !collection->copyCollectionFile(cachedCollectionFile)) { + cmd.showMessage(QObject::tr("Error creating collection file '%1': %2."). + arg(cachedCollectionFile).arg(collection->error()), true); + return EXIT_FAILURE; + } + QHelpEngineCore cachedCollection(cachedCollectionFile); + if (!cachedCollection.setupData()) { + cmd.showMessage(QObject::tr("Error reading collection file '%1': %2"). + arg(cachedCollectionFile). + arg(cachedCollection.error()), true); + return EXIT_FAILURE; } - { - QSqlDatabase db; - QStringList sqlDrivers(db.drivers()); - if (sqlDrivers.isEmpty() - || !sqlDrivers.contains(QLatin1String("QSQLITE"))) { - cmd.showMessage(QObject::tr("Cannot load sqlite database driver!"), - true); - return -1; - } + stripNonexistingDocs(cachedCollection); + if (collectionFileGiven) { + if (CollectionConfiguration::isNewer(*collection, cachedCollection)) + CollectionConfiguration::copyConfiguration(*collection, + cachedCollection); + if (!synchronizeDocs(*collection, cachedCollection, cmd)) + return EXIT_FAILURE; } - if (!cmdCollectionFile.isEmpty()) { - QHelpEngineCore caller(cmdCollectionFile); - if (!caller.setupData()) { - cmd.showMessage(QObject::tr("The specified collection file could " - "not be read!"), true); - return -1; + if (cmd.registerRequest() != CmdLineParser::None) { + const QStringList &cachedDocs = + cachedCollection.registeredDocumentations(); + const QString &namespaceName = + QHelpEngineCore::namespaceName(cmd.helpFile()); + if (cmd.registerRequest() == CmdLineParser::Register) { + if (collectionFileGiven && !registerDocumentation(*collection, cmd, true)) + return EXIT_FAILURE; + if (!cachedDocs.contains(namespaceName) + && !registerDocumentation(cachedCollection, cmd, !collectionFileGiven)) + return EXIT_FAILURE; + return EXIT_SUCCESS; } - - QString fileName = QFileInfo(cmdCollectionFile).fileName(); - const QString &cacheDir = CollectionConfiguration::cacheDir(caller); - const QString dir = !cacheDir.isEmpty() - && CollectionConfiguration::cacheDirIsRelativeToCollection(caller) - ? QFileInfo(cmdCollectionFile).dir().absolutePath() - + QDir::separator() + cacheDir - : MainWindow::collectionFileDirectory(false, cacheDir); - - bool collectionFileExists = true; - QFileInfo fi(dir + QDir::separator() + fileName); - if (!fi.exists()) { - collectionFileExists = false; - if (!caller.copyCollectionFile(fi.absoluteFilePath())) { - cmd.showMessage(caller.error(), true); - return -1; - } + if (cmd.registerRequest() == CmdLineParser::Unregister) { + if (collectionFileGiven + && !unregisterDocumentation(*collection, namespaceName, cmd, true)) + return EXIT_FAILURE; + if (cachedDocs.contains(namespaceName) + && !unregisterDocumentation(cachedCollection, namespaceName, + cmd, !collectionFileGiven)) + return EXIT_FAILURE; + return EXIT_SUCCESS; } - - if (collectionFileExists) { - QHelpEngineCore user(fi.absoluteFilePath()); - if (user.setupData()) { - // some docs might have been un/registered - bool docUpdate = CollectionConfiguration::docUpdatePending(caller); - - // update in case the passed collection file changed - if (updateUserCollection(user, caller)) - docUpdate = true; - - QStringList userDocs = user.registeredDocumentations(); - // update user collection file, docs might have been (re)moved - if (!referencedHelpFilesExistAll(user, userDocs)) - docUpdate = true; - - if (docUpdate) { - QStringList callerDocs = caller.registeredDocumentations(); - foreach (const QString &doc, callerDocs) { - if (!userDocs.contains(doc)) { - user.registerDocumentation( - caller.documentationFileName(doc)); - } - } - - QLatin1String intern("com.trolltech.com.assistantinternal-"); - foreach (const QString &doc, userDocs) { - if (!callerDocs.contains(doc) && !doc.startsWith(intern)) - user.unregisterDocumentation(doc); - } - - CollectionConfiguration::setDocUpdatePending(caller, false); - } - } - } - cmd.setCollectionFile(fi.absoluteFilePath()); } - if (!cmd.currentFilter().isEmpty()) { - QString collectionFile; - if (cmdCollectionFile.isEmpty()) { - MainWindow::collectionFileDirectory(true); - cmdCollectionFile = MainWindow::defaultHelpCollectionFileName(); - } - - QHelpEngineCore user(cmdCollectionFile); - if (user.setupData()) - user.setCurrentFilter(cmd.currentFilter()); + if (cmd.removeSearchIndex()) { + return removeSearchIndex(cachedCollectionFile) + ? EXIT_SUCCESS : EXIT_FAILURE; } - const QString& locale = QLocale::system().name(); - QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); - - QTranslator translator(0); - translator.load(QLatin1String("assistant_") + locale, resourceDir); - a.installTranslator(&translator); + if (cmd.rebuildSearchIndex()) { + return rebuildSearchIndex(a, cachedCollectionFile, cmd) + ? EXIT_SUCCESS : EXIT_FAILURE; + } - QTranslator qtTranslator(0); - qtTranslator.load(QLatin1String("qt_") + locale, resourceDir); - a.installTranslator(&qtTranslator); + if (!QSqlDatabase::isDriverAvailable(QLatin1String("QSQLITE"))) { + cmd.showMessage(QObject::tr("Cannot load sqlite database driver!"), + true); + return EXIT_FAILURE; + } - QTranslator qtHelpTranslator(0); - qtHelpTranslator.load(QLatin1String("qt_help_") + locale, resourceDir); - a.installTranslator(&qtHelpTranslator); + if (!cmd.currentFilter().isEmpty()) { + if (collectionFileGiven) + collection->setCurrentFilter(cmd.currentFilter()); + cachedCollection.setCurrentFilter(cmd.currentFilter()); + } - MainWindow w(&cmd); - w.show(); + setupTranslations(); + + /* + * We need to be careful here: The main window has to be deleted before + * the help engine wrapper, which has to be deleted before the + * QApplication. + */ + if (collectionFileGiven) + cmd.setCollectionFile(cachedCollectionFile); + MainWindow *w = new MainWindow(&cmd); + w->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); - return a.exec(); + const int retval = a.exec(); + delete w; + HelpEngineWrapper::removeInstance(); + return retval; } diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index f05f337..ac33fc5 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "mainwindow.h" #include "centralwidget.h" @@ -47,18 +48,22 @@ #include "contentwindow.h" #include "preferencesdialog.h" #include "bookmarkmanager.h" +#include "helpenginewrapper.h" #include "remotecontrol.h" #include "cmdlineparser.h" #include "aboutdialog.h" #include "searchwidget.h" #include "qtdocinstaller.h" #include "xbelsupport.h" -#include "../shared/collectionconfiguration.h" + +// #define TRACING_REQUESTED #include <QtCore/QDir> #include <QtCore/QTimer> +#include <QtCore/QDateTime> #include <QtCore/QDebug> #include <QtCore/QFileSystemWatcher> +#include <QtCore/QPair> #include <QtCore/QResource> #include <QtCore/QByteArray> #include <QtCore/QTextStream> @@ -81,7 +86,7 @@ #include <QtGui/QToolButton> #include <QtGui/QFileDialog> -#include <QtHelp/QHelpEngine> +#include <QtHelp/QHelpEngineCore> #include <QtHelp/QHelpSearchEngine> #include <QtHelp/QHelpContentModel> #include <QtHelp/QHelpIndexModel> @@ -95,29 +100,32 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) , m_cmdLine(cmdLine) , m_progressWidget(0) , m_qtDocInstaller(0) - , m_qchWatcher(new QFileSystemWatcher(this)) , m_connectedInitSignals(false) { + TRACE_OBJ + setToolButtonStyle(Qt::ToolButtonFollowStyle); + QString collectionFile; if (usesDefaultCollection()) { MainWindow::collectionFileDirectory(true); - m_helpEngine = new QHelpEngine(MainWindow::defaultHelpCollectionFileName(), - this); + collectionFile = MainWindow::defaultHelpCollectionFileName(); } else { - m_helpEngine = new QHelpEngine(cmdLine->collectionFile(), this); + collectionFile = cmdLine->collectionFile(); } + HelpEngineWrapper &helpEngineWrapper = + HelpEngineWrapper::instance(collectionFile); - m_centralWidget = new CentralWidget(m_helpEngine, this); + m_centralWidget = new CentralWidget(this); setCentralWidget(m_centralWidget); - m_indexWindow = new IndexWindow(m_helpEngine); + m_indexWindow = new IndexWindow(this); QDockWidget *indexDock = new QDockWidget(tr("Index"), this); indexDock->setObjectName(QLatin1String("IndexWindow")); indexDock->setWidget(m_indexWindow); addDockWidget(Qt::LeftDockWidgetArea, indexDock); - m_contentWindow = new ContentWindow(m_helpEngine); + m_contentWindow = new ContentWindow; QDockWidget *contentDock = new QDockWidget(tr("Contents"), this); contentDock->setObjectName(QLatin1String("ContentWindow")); contentDock->setWidget(m_contentWindow); @@ -128,7 +136,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) bookmarkDock->setWidget(setupBookmarkWidget()); addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock); - QHelpSearchEngine *searchEngine = m_helpEngine->searchEngine(); + QHelpSearchEngine *searchEngine = helpEngineWrapper.searchEngine(); connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted())); connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished())); @@ -153,11 +161,9 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) connect(m_bookmarkManager, SIGNAL(bookmarksChanged()), this, SLOT(updateBookmarkMenu())); - const QString windowTitle = - CollectionConfiguration::windowTitle(*m_helpEngine); + const QString windowTitle = helpEngineWrapper.windowTitle(); setWindowTitle(windowTitle.isEmpty() ? defWindowTitle : windowTitle); - QByteArray iconArray = - CollectionConfiguration::applicationIcon(*m_helpEngine); + QByteArray iconArray = helpEngineWrapper.applicationIcon(); if (iconArray.size() > 0) { QPixmap pix; pix.loadFromData(iconArray); @@ -171,11 +177,11 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) // Show the widget here, otherwise the restore geometry and state won't work // on x11. show(); - QByteArray ba(CollectionConfiguration::mainWindow(*m_helpEngine)); + QByteArray ba(helpEngineWrapper.mainWindow()); if (!ba.isEmpty()) restoreState(ba); - ba = CollectionConfiguration::mainWindowGeometry(*m_helpEngine); + ba = helpEngineWrapper.mainWindowGeometry(); if (!ba.isEmpty()) { restoreGeometry(ba); } else { @@ -185,15 +191,13 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) resize(QSize(800, 600)); } - if (!CollectionConfiguration::hasFontSettings(*m_helpEngine)) { - CollectionConfiguration::setUseAppFont(*m_helpEngine, false); - CollectionConfiguration::setUseBrowserFont(*m_helpEngine, false); - CollectionConfiguration::setAppFont(*m_helpEngine, qApp->font()); - CollectionConfiguration::setAppWritingSystem(*m_helpEngine, - QFontDatabase::Latin); - CollectionConfiguration::setBrowserFont(*m_helpEngine, qApp->font()); - CollectionConfiguration::setBrowserWritingSystem(*m_helpEngine, - QFontDatabase::Latin); + if (!helpEngineWrapper.hasFontSettings()) { + helpEngineWrapper.setUseAppFont(false); + helpEngineWrapper.setUseBrowserFont(false); + helpEngineWrapper.setAppFont(qApp->font()); + helpEngineWrapper.setAppWritingSystem(QFontDatabase::Latin); + helpEngineWrapper.setBrowserFont(qApp->font()); + helpEngineWrapper.setBrowserWritingSystem(QFontDatabase::Latin); } else { updateApplicationFont(); } @@ -202,7 +206,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) QTimer::singleShot(0, this, SLOT(insertLastPages())); if (m_cmdLine->enableRemoteControl()) - (void)new RemoteControl(this, m_helpEngine, m_qchWatcher); + (void)new RemoteControl(this); if (m_cmdLine->contents() == CmdLineParser::Show) showContents(); @@ -233,8 +237,8 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) if (!m_cmdLine->currentFilter().isEmpty()) { const QString &curFilter = m_cmdLine->currentFilter(); - if (m_helpEngine->customFilters().contains(curFilter)) - m_helpEngine->setCurrentFilter(curFilter); + if (helpEngineWrapper.customFilters().contains(curFilter)) + helpEngineWrapper.setCurrentFilter(curFilter); } if (usesDefaultCollection()) @@ -242,45 +246,46 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) else checkInitState(); - foreach(const QString &ns, m_helpEngine->registeredDocumentations()) { - const QString &docFile = m_helpEngine->documentationFileName(ns); - m_qchWatcher->addPath(docFile); - connect(m_qchWatcher, SIGNAL(fileChanged(QString)), this, - SLOT(qchFileChanged(QString))); - } + connect(&helpEngineWrapper, SIGNAL(documentationRemoved(QString)), + this, SLOT(documentationRemoved(QString))); + connect(&helpEngineWrapper, SIGNAL(documentationUpdated(QString)), + this, SLOT(documentationUpdated(QString))); } setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); } MainWindow::~MainWindow() { + TRACE_OBJ if (m_qtDocInstaller) delete m_qtDocInstaller; } bool MainWindow::usesDefaultCollection() const { + TRACE_OBJ return m_cmdLine->collectionFile().isEmpty(); } void MainWindow::closeEvent(QCloseEvent *e) { + TRACE_OBJ m_bookmarkManager->saveBookmarks(); - CollectionConfiguration::setMainWindow(*m_helpEngine, saveState()); - CollectionConfiguration::setMainWindowGeometry(*m_helpEngine, - saveGeometry()); - + HelpEngineWrapper::instance().setMainWindow(saveState()); + HelpEngineWrapper::instance().setMainWindowGeometry(saveGeometry()); QMainWindow::closeEvent(e); } bool MainWindow::initHelpDB() { - if (!m_helpEngine->setupData()) + TRACE_OBJ + HelpEngineWrapper &helpEngineWrapper = HelpEngineWrapper::instance(); + if (!helpEngineWrapper.setupData()) return false; bool assistantInternalDocRegistered = false; QString intern(QLatin1String("com.trolltech.com.assistantinternal-")); - foreach (const QString &ns, m_helpEngine->registeredDocumentations()) { + foreach (const QString &ns, helpEngineWrapper.registeredDocumentations()) { if (ns.startsWith(intern)) { intern = ns; assistantInternalDocRegistered = true; @@ -288,8 +293,7 @@ bool MainWindow::initHelpDB() } } - const QString &collectionFile = m_helpEngine->collectionFile(); - + const QString &collectionFile = helpEngineWrapper.collectionFile(); QFileInfo fi(collectionFile); QString helpFile; QTextStream(&helpFile) << fi.absolutePath() << QDir::separator() @@ -306,84 +310,78 @@ bool MainWindow::initHelpDB() file.close(); } - QHelpEngineCore hc(fi.absoluteFilePath()); - hc.setupData(); - const QString internalFile = hc.documentationFileName(intern); - if (hc.unregisterDocumentation(intern)) - m_qchWatcher->removePath(internalFile); - if (hc.registerDocumentation(helpFile)) - m_qchWatcher->addPath(helpFile); + helpEngineWrapper.unregisterDocumentation(intern); + helpEngineWrapper.registerDocumentation(helpFile); needsSetup = true; } - if (!CollectionConfiguration::unfilteredInserted(*m_helpEngine)) { - { - QHelpEngineCore hc(collectionFile); - hc.setupData(); - hc.addCustomFilter(tr("Unfiltered"), QStringList()); - CollectionConfiguration::setUnfilteredInserted(hc); - } - - m_helpEngine->blockSignals(true); - m_helpEngine->setCurrentFilter(tr("Unfiltered")); - m_helpEngine->blockSignals(false); + if (!helpEngineWrapper.unfilteredInserted()) { + helpEngineWrapper.addCustomFilter(tr("Unfiltered"), QStringList()); + helpEngineWrapper.setUnfilteredInserted(); + helpEngineWrapper.setCurrentFilter(tr("Unfiltered")); needsSetup = true; } - if (needsSetup) { - m_helpEngine->setupData(); - Q_ASSERT(m_qchWatcher->files().count() - == m_helpEngine->registeredDocumentations().count()); - } + if (needsSetup) + helpEngineWrapper.setupData(); return true; } void MainWindow::lookForNewQtDocumentation() { - m_qtDocInstaller = - new QtDocInstaller(m_helpEngine->collectionFile(), m_qchWatcher); - connect(m_qtDocInstaller, SIGNAL(errorMessage(QString)), this, - SLOT(displayInstallationError(QString))); + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + QStringList docs; + docs << QLatin1String("assistant") + << QLatin1String("designer") + << QLatin1String("linguist") + << QLatin1String("qmake") + << QLatin1String("qt"); + QList<QtDocInstaller::DocInfo> qtDocInfos; + foreach (const QString &doc, docs) + qtDocInfos.append(QtDocInstaller::DocInfo(doc, helpEngine.qtDocInfo(doc))); + + m_qtDocInstaller = new QtDocInstaller(qtDocInfos); connect(m_qtDocInstaller, SIGNAL(docsInstalled(bool)), this, SLOT(qtDocumentationInstalled(bool))); - - if (CollectionConfiguration::qtDocInfo(*m_helpEngine, QLatin1String("qt")). - count() != 2) + connect(m_qtDocInstaller, SIGNAL(qchFileNotFound(QString)), this, + SLOT(resetQtDocInfo(QString))); + connect(m_qtDocInstaller, SIGNAL(registerDocumentation(QString, QString)), + this, SLOT(registerDocumentation(QString, QString))); + if (helpEngine.qtDocInfo(QLatin1String("qt")).count() != 2) statusBar()->showMessage(tr("Looking for Qt Documentation...")); m_qtDocInstaller->installDocs(); } -void MainWindow::displayInstallationError(const QString &errorMessage) -{ - QMessageBox::warning(this, tr("Qt Assistant"), errorMessage); -} - void MainWindow::qtDocumentationInstalled(bool newDocsInstalled) { + TRACE_OBJ if (newDocsInstalled) - m_helpEngine->setupData(); + HelpEngineWrapper::instance().setupData(); statusBar()->clearMessage(); checkInitState(); } void MainWindow::checkInitState() { + TRACE_OBJ if (!m_cmdLine->enableRemoteControl()) return; - if (m_helpEngine->contentModel()->isCreatingContents() - || m_helpEngine->indexModel()->isCreatingIndex()) { + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + if (helpEngine.contentModel()->isCreatingContents() + || helpEngine.indexModel()->isCreatingIndex()) { if (!m_connectedInitSignals) { - connect(m_helpEngine->contentModel(), SIGNAL(contentsCreated()), + connect(helpEngine.contentModel(), SIGNAL(contentsCreated()), this, SLOT(checkInitState())); - connect(m_helpEngine->indexModel(), SIGNAL(indexCreated()), this, + connect(helpEngine.indexModel(), SIGNAL(indexCreated()), this, SLOT(checkInitState())); m_connectedInitSignals = true; } } else { if (m_connectedInitSignals) { - disconnect(m_helpEngine->contentModel(), 0, this, 0); - disconnect(m_helpEngine->indexModel(), 0, this, 0); + disconnect(helpEngine.contentModel(), 0, this, 0); + disconnect(helpEngine.indexModel(), 0, this, 0); } emit initDone(); } @@ -391,6 +389,7 @@ void MainWindow::checkInitState() void MainWindow::updateBookmarkMenu() { + TRACE_OBJ if (m_bookmarkManager) { m_bookmarkMenu->removeAction(m_importBookmarkAction); m_bookmarkMenu->removeAction(m_exportBookmarkAction); @@ -409,6 +408,7 @@ void MainWindow::updateBookmarkMenu() void MainWindow::showBookmark(QAction *action) { + TRACE_OBJ if (m_bookmarkManager) { const QUrl &url = m_bookmarkManager->urlForAction(action); if (url.isValid()) @@ -418,6 +418,7 @@ void MainWindow::showBookmark(QAction *action) void MainWindow::insertLastPages() { + TRACE_OBJ if (m_cmdLine->url().isValid()) m_centralWidget->setSource(m_cmdLine->url()); else @@ -429,6 +430,7 @@ void MainWindow::insertLastPages() void MainWindow::setupActions() { + TRACE_OBJ QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); #ifdef Q_OS_MAC setUnifiedTitleAndToolBarOnMac(true); @@ -654,6 +656,7 @@ void MainWindow::setupActions() QMenu *MainWindow::toolBarMenu() { + TRACE_OBJ if (!m_toolBarMenu) { m_viewMenu->addSeparator(); m_toolBarMenu = m_viewMenu->addMenu(tr("Toolbars")); @@ -663,7 +666,9 @@ QMenu *MainWindow::toolBarMenu() void MainWindow::setupFilterToolbar() { - if (!CollectionConfiguration::filterFunctionalityEnabled(*m_helpEngine)) + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + if (!helpEngine.filterFunctionalityEnabled()) return; m_filterCombo = new QComboBox(this); @@ -676,15 +681,15 @@ void MainWindow::setupFilterToolbar() this)); filterToolBar->addWidget(m_filterCombo); - if (!CollectionConfiguration::filterToolbarVisible(*m_helpEngine)) + if (!helpEngine.filterToolbarVisible()) filterToolBar->hide(); toolBarMenu()->addAction(filterToolBar->toggleViewAction()); - connect(m_helpEngine, SIGNAL(setupFinished()), this, - SLOT(setupFilterCombo())); + connect(&helpEngine, SIGNAL(setupFinished()), this, + SLOT(setupFilterCombo()), Qt::QueuedConnection); connect(m_filterCombo, SIGNAL(activated(QString)), this, SLOT(filterDocumentation(QString))); - connect(m_helpEngine, SIGNAL(currentFilterChanged(QString)), this, + connect(&helpEngine, SIGNAL(currentFilterChanged(QString)), this, SLOT(currentFilterChanged(QString))); setupFilterCombo(); @@ -692,7 +697,9 @@ void MainWindow::setupFilterToolbar() void MainWindow::setupAddressToolbar() { - if (!CollectionConfiguration::addressBarEnabled(*m_helpEngine)) + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + if (!helpEngine.addressBarEnabled()) return; m_addressLineEdit = new QLineEdit(this); @@ -704,7 +711,7 @@ void MainWindow::setupAddressToolbar() this)); addressToolBar->addWidget(m_addressLineEdit); - if (!CollectionConfiguration::addressBarVisible(*m_helpEngine)) + if (!helpEngine.addressBarVisible()) addressToolBar->hide(); toolBarMenu()->addAction(addressToolBar->toggleViewAction()); @@ -719,56 +726,60 @@ void MainWindow::setupAddressToolbar() void MainWindow::updateAboutMenuText() { - if (m_helpEngine) { - QByteArray ba = CollectionConfiguration::aboutMenuTexts(*m_helpEngine); - if (ba.size() > 0) { - QString lang; - QString str; - QString trStr; - QString currentLang = QLocale::system().name(); - int i = currentLang.indexOf(QLatin1Char('_')); - if (i > -1) - currentLang = currentLang.left(i); - QDataStream s(&ba, QIODevice::ReadOnly); - while (!s.atEnd()) { - s >> lang; - s >> str; - if (lang == QLatin1String("default") && trStr.isEmpty()) { - trStr = str; - } else if (lang == currentLang) { - trStr = str; - break; - } + TRACE_OBJ + QByteArray ba = HelpEngineWrapper::instance().aboutMenuTexts(); + if (ba.size() > 0) { + QString lang; + QString str; + QString trStr; + QString currentLang = QLocale::system().name(); + int i = currentLang.indexOf(QLatin1Char('_')); + if (i > -1) + currentLang = currentLang.left(i); + QDataStream s(&ba, QIODevice::ReadOnly); + while (!s.atEnd()) { + s >> lang; + s >> str; + if (lang == QLatin1String("default") && trStr.isEmpty()) { + trStr = str; + } else if (lang == currentLang) { + trStr = str; + break; } - if (!trStr.isEmpty()) - m_aboutAction->setText(trStr); } + if (!trStr.isEmpty()) + m_aboutAction->setText(trStr); } } void MainWindow::showNewAddress() { + TRACE_OBJ showNewAddress(m_centralWidget->currentSource()); } void MainWindow::showNewAddress(const QUrl &url) { + TRACE_OBJ m_addressLineEdit->setText(url.toString()); } void MainWindow::addBookmark() { + TRACE_OBJ addNewBookmark(m_centralWidget->currentTitle(), m_centralWidget->currentSource().toString()); } void MainWindow::gotoAddress() { + TRACE_OBJ m_centralWidget->setSource(m_addressLineEdit->text()); } void MainWindow::updateNavigationItems() { + TRACE_OBJ bool hasCurrentViewer = m_centralWidget->isHomeAvailable(); m_copyAction->setEnabled(m_centralWidget->hasSelection()); m_homeAction->setEnabled(hasCurrentViewer); @@ -782,12 +793,14 @@ void MainWindow::updateNavigationItems() void MainWindow::updateTabCloseAction() { + TRACE_OBJ m_closeTabAction->setEnabled(m_centralWidget->enableTabCloseAction()); } void MainWindow::showTopicChooser(const QMap<QString, QUrl> &links, const QString &keyword) { + TRACE_OBJ TopicChooser tc(this, keyword, links); if (tc.exec() == QDialog::Accepted) { m_centralWidget->setSource(tc.link()); @@ -796,7 +809,8 @@ void MainWindow::showTopicChooser(const QMap<QString, QUrl> &links, void MainWindow::showPreferences() { - PreferencesDialog dia(m_helpEngine, m_qchWatcher, this); + TRACE_OBJ + PreferencesDialog dia(this); connect(&dia, SIGNAL(updateApplicationFont()), this, SLOT(updateApplicationFont())); @@ -808,6 +822,7 @@ void MainWindow::showPreferences() void MainWindow::syncContents() { + TRACE_OBJ qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); const QUrl url = m_centralWidget->currentSource(); showContents(); @@ -819,11 +834,13 @@ void MainWindow::syncContents() void MainWindow::copyAvailable(bool yes) { + TRACE_OBJ m_copyAction->setEnabled(yes); } void MainWindow::addNewBookmark(const QString &title, const QString &url) { + TRACE_OBJ if (url.isEmpty() || url == QLatin1String("about:blank")) return; @@ -832,26 +849,26 @@ void MainWindow::addNewBookmark(const QString &title, const QString &url) void MainWindow::showAboutDialog() { + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); QByteArray contents; - if (m_helpEngine) { - QByteArray ba = CollectionConfiguration::aboutTexts(*m_helpEngine); - if (!ba.isEmpty()) { - QString lang; - QByteArray cba; - QString currentLang = QLocale::system().name(); - int i = currentLang.indexOf(QLatin1Char('_')); - if (i > -1) - currentLang = currentLang.left(i); - QDataStream s(&ba, QIODevice::ReadOnly); - while (!s.atEnd()) { - s >> lang; - s >> cba; - if (lang == QLatin1String("default") && contents.isEmpty()) { - contents = cba; - } else if (lang == currentLang) { - contents = cba; - break; - } + QByteArray ba = helpEngine.aboutTexts(); + if (!ba.isEmpty()) { + QString lang; + QByteArray cba; + QString currentLang = QLocale::system().name(); + int i = currentLang.indexOf(QLatin1Char('_')); + if (i > -1) + currentLang = currentLang.left(i); + QDataStream s(&ba, QIODevice::ReadOnly); + while (!s.atEnd()) { + s >> lang; + s >> cba; + if (lang == QLatin1String("default") && contents.isEmpty()) { + contents = cba; + } else if (lang == currentLang) { + contents = cba; + break; } } } @@ -860,9 +877,8 @@ void MainWindow::showAboutDialog() QByteArray iconArray; if (!contents.isEmpty()) { - iconArray = CollectionConfiguration::aboutIcon(*m_helpEngine); - QByteArray resources = - CollectionConfiguration::aboutImages(*m_helpEngine); + iconArray = helpEngine.aboutIcon(); + QByteArray resources = helpEngine.aboutImages(); QPixmap pix; pix.loadFromData(iconArray); aboutDia.setText(QString::fromUtf8(contents), resources); @@ -887,6 +903,7 @@ void MainWindow::showAboutDialog() void MainWindow::setContentsVisible(bool visible) { + TRACE_OBJ if (visible) showContents(); else @@ -895,16 +912,19 @@ void MainWindow::setContentsVisible(bool visible) void MainWindow::showContents() { + TRACE_OBJ activateDockWidget(m_contentWindow); } void MainWindow::hideContents() { + TRACE_OBJ m_contentWindow->parentWidget()->hide(); } void MainWindow::setIndexVisible(bool visible) { + TRACE_OBJ if (visible) showIndex(); else @@ -913,16 +933,19 @@ void MainWindow::setIndexVisible(bool visible) void MainWindow::showIndex() { + TRACE_OBJ activateDockWidget(m_indexWindow); } void MainWindow::hideIndex() { + TRACE_OBJ m_indexWindow->parentWidget()->hide(); } void MainWindow::setBookmarksVisible(bool visible) { + TRACE_OBJ if (visible) showBookmarks(); else @@ -932,16 +955,19 @@ void MainWindow::setBookmarksVisible(bool visible) void MainWindow::showBookmarks() { + TRACE_OBJ activateDockWidget(m_bookmarkWidget); } void MainWindow::hideBookmarks() { + TRACE_OBJ m_bookmarkWidget->parentWidget()->hide(); } void MainWindow::setSearchVisible(bool visible) { + TRACE_OBJ if (visible) showSearch(); else @@ -950,16 +976,19 @@ void MainWindow::setSearchVisible(bool visible) void MainWindow::showSearch() { + TRACE_OBJ m_centralWidget->activateSearchWidget(); } void MainWindow::hideSearch() { + TRACE_OBJ m_centralWidget->removeSearchWidget(); } void MainWindow::activateDockWidget(QWidget *w) { + TRACE_OBJ w->parentWidget()->show(); w->parentWidget()->raise(); w->setFocus(); @@ -967,11 +996,13 @@ void MainWindow::activateDockWidget(QWidget *w) void MainWindow::setIndexString(const QString &str) { + TRACE_OBJ m_indexWindow->setSearchLineEditText(str); } void MainWindow::activateCurrentBrowser() { + TRACE_OBJ CentralWidget *cw = CentralWidget::instance(); if (cw) { cw->activateTab(true); @@ -980,30 +1011,36 @@ void MainWindow::activateCurrentBrowser() void MainWindow::activateCurrentCentralWidgetTab() { + TRACE_OBJ m_centralWidget->activateTab(); } void MainWindow::showSearchWidget() { + TRACE_OBJ m_centralWidget->activateSearchWidget(true); } void MainWindow::updateApplicationFont() { + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); QFont font = qApp->font(); - if (CollectionConfiguration::usesAppFont(*m_helpEngine)) - font = CollectionConfiguration::appFont(*m_helpEngine); + if (helpEngine.usesAppFont()) + font = helpEngine.appFont(); qApp->setFont(font, "QWidget"); } void MainWindow::setupFilterCombo() { + TRACE_OBJ + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); QString curFilter = m_filterCombo->currentText(); if (curFilter.isEmpty()) - curFilter = m_helpEngine->currentFilter(); + curFilter = helpEngine.currentFilter(); m_filterCombo->clear(); - m_filterCombo->addItems(m_helpEngine->customFilters()); + m_filterCombo->addItems(helpEngine.customFilters()); int idx = m_filterCombo->findText(curFilter); if (idx < 0) idx = 0; @@ -1012,17 +1049,20 @@ void MainWindow::setupFilterCombo() void MainWindow::filterDocumentation(const QString &customFilter) { - m_helpEngine->setCurrentFilter(customFilter); + TRACE_OBJ + HelpEngineWrapper::instance().setCurrentFilter(customFilter); } void MainWindow::expandTOC(int depth) { + TRACE_OBJ Q_ASSERT(depth >= -1); m_contentWindow->expandToDepth(depth); } void MainWindow::indexingStarted() { + TRACE_OBJ if (!m_progressWidget) { m_progressWidget = new QWidget(); QLayout* hlayout = new QHBoxLayout(m_progressWidget); @@ -1048,6 +1088,7 @@ void MainWindow::indexingStarted() void MainWindow::indexingFinished() { + TRACE_OBJ statusBar()->removeWidget(m_progressWidget); delete m_progressWidget; m_progressWidget = 0; @@ -1055,7 +1096,8 @@ void MainWindow::indexingFinished() QWidget* MainWindow::setupBookmarkWidget() { - m_bookmarkManager = new BookmarkManager(m_helpEngine); + TRACE_OBJ + m_bookmarkManager = new BookmarkManager; m_bookmarkWidget = new BookmarkWidget(m_bookmarkManager, this); connect(m_bookmarkWidget, SIGNAL(addBookmark()), this, SLOT(addBookmark())); return m_bookmarkWidget; @@ -1063,6 +1105,7 @@ QWidget* MainWindow::setupBookmarkWidget() QString MainWindow::collectionFileDirectory(bool createDir, const QString &cacheDir) { + TRACE_OBJ QString collectionPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); if (collectionPath.isEmpty()) { @@ -1088,13 +1131,16 @@ QString MainWindow::collectionFileDirectory(bool createDir, const QString &cache QString MainWindow::defaultHelpCollectionFileName() { - return collectionFileDirectory() + QDir::separator() + + TRACE_OBJ + // forces creation of the default collection file path + return collectionFileDirectory(true) + QDir::separator() + QString(QLatin1String("qthelpcollection_%1.qhc")). arg(QLatin1String(QT_VERSION_STR)); } void MainWindow::importBookmarks() { + TRACE_OBJ const QString &fileName = QFileDialog::getOpenFileName(0, tr("Open File"), QDir::currentPath(), tr("Files (*.xbel)")); @@ -1111,6 +1157,7 @@ void MainWindow::importBookmarks() void MainWindow::exportBookmarks() { + TRACE_OBJ QString fileName = QFileDialog::getSaveFileName(0, tr("Save File"), "untitled.xbel", tr("Files (*.xbel)")); @@ -1130,38 +1177,56 @@ void MainWindow::exportBookmarks() void MainWindow::currentFilterChanged(const QString &filter) { + TRACE_OBJ const int index = m_filterCombo->findText(filter); Q_ASSERT(index != -1); m_filterCombo->setCurrentIndex(index); } -void MainWindow::qchFileChanged(const QString &fileName) +void MainWindow::documentationRemoved(const QString &namespaceName) { - /* - * We don't use QHelpEngineCore::namespaceName(fileName), because the file - * may not exist anymore or contain a different namespace. - */ - QString ns; - foreach (const QString &curNs, m_helpEngine->registeredDocumentations()) { - if (m_helpEngine->documentationFileName(curNs) == fileName) { - ns = curNs; - break; - } - } + TRACE_OBJ + CentralWidget* widget = CentralWidget::instance(); + widget->closeOrReloadTabs(widget->currentSourceFileList(). + keys(namespaceName), false); +} + +void MainWindow::documentationUpdated(const QString &namespaceName) +{ + TRACE_OBJ + CentralWidget* widget = CentralWidget::instance(); + widget->closeOrReloadTabs(widget->currentSourceFileList(). + keys(namespaceName), true); +} - /* - * We can't do an assertion here, because QFileSystemWatcher may send the - * signal more than once. - */ +void MainWindow::resetQtDocInfo(const QString &component) +{ + TRACE_OBJ + HelpEngineWrapper::instance().setQtDocInfo(component, + QStringList(QDateTime().toString(Qt::ISODate))); +} + +void MainWindow::registerDocumentation(const QString &component, + const QString &absFileName) +{ + TRACE_OBJ + QString ns = QHelpEngineCore::namespaceName(absFileName); if (ns.isEmpty()) return; - CentralWidget* widget = CentralWidget::instance(); - widget->closeTabs(widget->currentSourceFileList().keys(ns)); - if (m_helpEngine->unregisterDocumentation(ns) && - (!QFileInfo(fileName).exists() - || !m_helpEngine->registerDocumentation(fileName))) - m_qchWatcher->removePath(fileName); + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + if (helpEngine.registeredDocumentations().contains(ns)) + helpEngine.unregisterDocumentation(ns); + if (!helpEngine.registerDocumentation(absFileName)) { + QMessageBox::warning(this, tr("Qt Assistant"), + tr("Could not register file '%1': %2"). + arg(absFileName).arg(helpEngine.error())); + } else { + QStringList docInfo; + docInfo << QFileInfo(absFileName).lastModified().toString(Qt::ISODate) + << absFileName; + helpEngine.setQtDocInfo(component, docInfo); + } } QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h index 8672526..3c70666 100644 --- a/tools/assistant/tools/assistant/mainwindow.h +++ b/tools/assistant/tools/assistant/mainwindow.h @@ -117,10 +117,13 @@ private slots: void lookForNewQtDocumentation(); void indexingStarted(); void indexingFinished(); - void displayInstallationError(const QString &errorMessage); void qtDocumentationInstalled(bool newDocsInstalled); + void registerDocumentation(const QString &component, + const QString &absFileName); + void resetQtDocInfo(const QString &component); void checkInitState(); - void qchFileChanged(const QString &fileName); + void documentationRemoved(const QString &namespaceName); + void documentationUpdated(const QString &namespaceName); void updateBookmarkMenu(); void showBookmark(QAction *action); @@ -143,7 +146,6 @@ private: void hideBookmarks(); void hideSearch(); - QHelpEngine *m_helpEngine; CentralWidget *m_centralWidget; IndexWindow *m_indexWindow; ContentWindow *m_contentWindow; @@ -179,7 +181,6 @@ private: QWidget *m_progressWidget; QtDocInstaller *m_qtDocInstaller; - QFileSystemWatcher * const m_qchWatcher; bool m_connectedInitSignals; }; diff --git a/tools/assistant/tools/assistant/preferencesdialog.cpp b/tools/assistant/tools/assistant/preferencesdialog.cpp index f7de9e9..fb41590 100644 --- a/tools/assistant/tools/assistant/preferencesdialog.cpp +++ b/tools/assistant/tools/assistant/preferencesdialog.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "preferencesdialog.h" #include "filternamedialog.h" @@ -45,7 +46,7 @@ #include "fontpanel.h" #include "centralwidget.h" #include "aboutdialog.h" -#include "../shared/collectionconfiguration.h" +#include "helpenginewrapper.h" #include <QtCore/QtAlgorithms> #include <QtCore/QFileSystemWatcher> @@ -62,14 +63,13 @@ QT_BEGIN_NAMESPACE -PreferencesDialog::PreferencesDialog(QHelpEngineCore *helpEngine, - QFileSystemWatcher *qchWatcher, QWidget *parent) +PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) - , m_helpEngine(helpEngine) , m_appFontChanged(false) , m_browserFontChanged(false) - , m_qchWatcher(qchWatcher) + , helpEngine(HelpEngineWrapper::instance()) { + TRACE_OBJ m_ui.setupUi(this); connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), @@ -77,10 +77,8 @@ PreferencesDialog::PreferencesDialog(QHelpEngineCore *helpEngine, connect(m_ui.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); - m_hideFiltersTab = - !CollectionConfiguration::filterFunctionalityEnabled(*m_helpEngine); - m_hideDocsTab = - !CollectionConfiguration::documentationManagerEnabled(*m_helpEngine); + m_hideFiltersTab = !helpEngine.filterFunctionalityEnabled(); + m_hideDocsTab = !helpEngine.documentationManagerEnabled(); if (!m_hideFiltersTab) { m_ui.attributeWidget->header()->hide(); @@ -109,7 +107,7 @@ PreferencesDialog::PreferencesDialog(QHelpEngineCore *helpEngine, connect(m_ui.docRemoveButton, SIGNAL(clicked()), this, SLOT(removeDocumentation())); - m_docsBackup = m_helpEngine->registeredDocumentations(); + m_docsBackup = helpEngine.registeredDocumentations(); m_ui.registeredDocsListWidget->addItems(m_docsBackup); } else { m_ui.tabWidget->removeTab(m_ui.tabWidget->indexOf(m_ui.docsTab)); @@ -121,22 +119,17 @@ PreferencesDialog::PreferencesDialog(QHelpEngineCore *helpEngine, PreferencesDialog::~PreferencesDialog() { + TRACE_OBJ if (m_appFontChanged) { - CollectionConfiguration::setAppFont(*m_helpEngine, - m_appFontPanel->selectedFont()); - CollectionConfiguration::setUseAppFont(*m_helpEngine, - m_appFontPanel->isChecked()); - CollectionConfiguration::setAppWritingSystem(*m_helpEngine, - m_appFontPanel->writingSystem()); + helpEngine.setAppFont(m_appFontPanel->selectedFont()); + helpEngine.setUseAppFont(m_appFontPanel->isChecked()); + helpEngine.setAppWritingSystem(m_appFontPanel->writingSystem()); } if (m_browserFontChanged) { - CollectionConfiguration::setBrowserFont(*m_helpEngine, - m_browserFontPanel->selectedFont()); - CollectionConfiguration::setUseBrowserFont(*m_helpEngine, - m_browserFontPanel->isChecked()); - CollectionConfiguration::setBrowserWritingSystem(*m_helpEngine, - m_browserFontPanel->writingSystem()); + helpEngine.setBrowserFont(m_browserFontPanel->selectedFont()); + helpEngine.setUseBrowserFont(m_browserFontPanel->isChecked()); + helpEngine.setBrowserWritingSystem(m_browserFontPanel->writingSystem()); } if (m_appFontChanged || m_browserFontChanged) { @@ -147,32 +140,29 @@ PreferencesDialog::~PreferencesDialog() QString homePage = m_ui.homePageLineEdit->text(); if (homePage.isEmpty()) homePage = QLatin1String("help"); - CollectionConfiguration::setHomePage(*m_helpEngine, homePage); + helpEngine.setHomePage(homePage); int option = m_ui.helpStartComboBox->currentIndex(); - CollectionConfiguration::setStartOption(*m_helpEngine, option); + helpEngine.setStartOption(option); } void PreferencesDialog::showDialog() { + TRACE_OBJ if (exec() != Accepted) m_appFontChanged = m_browserFontChanged = false; } void PreferencesDialog::updateFilterPage() { - if (!m_helpEngine) - return; - + TRACE_OBJ m_ui.filterWidget->clear(); m_ui.attributeWidget->clear(); - QHelpEngineCore help(m_helpEngine->collectionFile(), 0); - help.setupData(); m_filterMapBackup.clear(); - const QStringList filters = help.customFilters(); + const QStringList filters = helpEngine.customFilters(); foreach (const QString &filter, filters) { - QStringList atts = help.filterAttributes(filter); + QStringList atts = helpEngine.filterAttributes(filter); m_filterMapBackup.insert(filter, atts); if (!m_filterMap.contains(filter)) m_filterMap.insert(filter, atts); @@ -180,15 +170,16 @@ void PreferencesDialog::updateFilterPage() m_ui.filterWidget->addItems(m_filterMap.keys()); - foreach (const QString &a, help.filterAttributes()) + foreach (const QString &a, helpEngine.filterAttributes()) new QTreeWidgetItem(m_ui.attributeWidget, QStringList() << a); - if (m_filterMap.keys().count()) + if (!m_filterMap.keys().isEmpty()) m_ui.filterWidget->setCurrentRow(0); } void PreferencesDialog::updateAttributes(QListWidgetItem *item) { + TRACE_OBJ QStringList checkedList; if (item) checkedList = m_filterMap.value(item->text()); @@ -204,6 +195,7 @@ void PreferencesDialog::updateAttributes(QListWidgetItem *item) void PreferencesDialog::updateFilterMap() { + TRACE_OBJ if (!m_ui.filterWidget->currentItem()) return; QString filter = m_ui.filterWidget->currentItem()->text(); @@ -222,6 +214,7 @@ void PreferencesDialog::updateFilterMap() void PreferencesDialog::addFilter() { + TRACE_OBJ FilterNameDialog dia(this); if (dia.exec() == QDialog::Rejected) return; @@ -239,6 +232,7 @@ void PreferencesDialog::addFilter() void PreferencesDialog::removeFilter() { + TRACE_OBJ QListWidgetItem *item = m_ui.filterWidget ->takeItem(m_ui.filterWidget->currentRow()); if (!item) @@ -253,6 +247,7 @@ void PreferencesDialog::removeFilter() void PreferencesDialog::addDocumentationLocal() { + TRACE_OBJ const QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Add Documentation"), QString(), tr("Qt Compressed Help Files (*.qch)")); if (fileNames.isEmpty()) @@ -273,14 +268,11 @@ void PreferencesDialog::addDocumentationLocal() continue; } - if (m_helpEngine->registerDocumentation(fileName)) { - m_qchWatcher->addPath(fileName); - Q_ASSERT(m_qchWatcher->files().count() - == m_helpEngine->registeredDocumentations().count()); + if (helpEngine.registerDocumentation(fileName)) { + m_ui.registeredDocsListWidget->addItem(nameSpace); + m_regDocs.append(nameSpace); + m_unregDocs.removeAll(nameSpace); } - m_ui.registeredDocsListWidget->addItem(nameSpace); - m_regDocs.append(nameSpace); - m_unregDocs.removeAll(nameSpace); } if (!invalidFiles.isEmpty() || !alreadyRegistered.isEmpty()) { @@ -309,6 +301,7 @@ void PreferencesDialog::addDocumentationLocal() void PreferencesDialog::removeDocumentation() { + TRACE_OBJ bool foundBefore = false; CentralWidget* widget = CentralWidget::instance(); QMap<int, QString> openedDocList = widget->currentSourceFileList(); @@ -340,6 +333,7 @@ void PreferencesDialog::removeDocumentation() void PreferencesDialog::applyChanges() { + TRACE_OBJ bool filtersWereChanged = false; if (!m_hideFiltersTab) { if (m_filterMap.count() != m_filterMapBackup.count()) { @@ -372,32 +366,28 @@ void PreferencesDialog::applyChanges() if (filtersWereChanged) { foreach (const QString &filter, m_removedFilters) - m_helpEngine->removeCustomFilter(filter); + helpEngine.removeCustomFilter(filter); QMapIterator<QString, QStringList> it(m_filterMap); while (it.hasNext()) { it.next(); - m_helpEngine->addCustomFilter(it.key(), it.value()); + helpEngine.addCustomFilter(it.key(), it.value()); } } - CentralWidget::instance()->closeTabs(m_TabsToClose); + CentralWidget::instance()->closeOrReloadTabs(m_TabsToClose, false); - foreach (const QString &doc, m_unregDocs) { - const QString docFile = m_helpEngine->documentationFileName(doc); - if (m_helpEngine->unregisterDocumentation(doc)) - m_qchWatcher->removePath(docFile); - } - Q_ASSERT(m_qchWatcher->files().count() - == m_helpEngine->registeredDocumentations().count()); + foreach (const QString &doc, m_unregDocs) + helpEngine.unregisterDocumentation(doc); - if (filtersWereChanged || m_regDocs.count() || m_unregDocs.count()) - m_helpEngine->setupData(); + if (filtersWereChanged || !m_regDocs.isEmpty() || !m_unregDocs.isEmpty()) + helpEngine.setupData(); accept(); } void PreferencesDialog::updateFontSettingsPage() { + TRACE_OBJ m_browserFontPanel = new FontPanel(this); m_browserFontPanel->setCheckable(true); m_ui.stackedWidget_2->insertWidget(0, m_browserFontPanel); @@ -411,26 +401,23 @@ void PreferencesDialog::updateFontSettingsPage() const QString customSettings(tr("Use custom settings")); m_appFontPanel->setTitle(customSettings); - QFont font = CollectionConfiguration::appFont(*m_helpEngine); + QFont font = helpEngine.appFont(); m_appFontPanel->setSelectedFont(font); - QFontDatabase::WritingSystem system = - CollectionConfiguration::appWritingSystem(*m_helpEngine); + QFontDatabase::WritingSystem system = helpEngine.appWritingSystem(); m_appFontPanel->setWritingSystem(system); - m_appFontPanel->setChecked(CollectionConfiguration:: - usesAppFont(*m_helpEngine)); + m_appFontPanel->setChecked(helpEngine.usesAppFont()); m_browserFontPanel->setTitle(customSettings); - font = CollectionConfiguration::browserFont(*m_helpEngine); + font = helpEngine.browserFont(); m_browserFontPanel->setSelectedFont(font); - system = CollectionConfiguration::browserWritingSystem(*m_helpEngine); + system = helpEngine.browserWritingSystem(); m_browserFontPanel->setWritingSystem(system); - m_browserFontPanel->setChecked(CollectionConfiguration:: - usesBrowserFont(*m_helpEngine)); + m_browserFontPanel->setChecked(helpEngine.usesBrowserFont()); connect(m_appFontPanel, SIGNAL(toggled(bool)), this, SLOT(appFontSettingToggled(bool))); @@ -452,36 +439,38 @@ void PreferencesDialog::updateFontSettingsPage() void PreferencesDialog::appFontSettingToggled(bool on) { + TRACE_OBJ Q_UNUSED(on) m_appFontChanged = true; } void PreferencesDialog::appFontSettingChanged(int index) { + TRACE_OBJ Q_UNUSED(index) m_appFontChanged = true; } void PreferencesDialog::browserFontSettingToggled(bool on) { + TRACE_OBJ Q_UNUSED(on) m_browserFontChanged = true; } void PreferencesDialog::browserFontSettingChanged(int index) { + TRACE_OBJ Q_UNUSED(index) m_browserFontChanged = true; } void PreferencesDialog::updateOptionsPage() { - QString homePage = CollectionConfiguration::homePage(*m_helpEngine); - if (homePage.isEmpty()) - homePage = CollectionConfiguration::defaultHomePage(*m_helpEngine); - m_ui.homePageLineEdit->setText(homePage); + TRACE_OBJ + m_ui.homePageLineEdit->setText(helpEngine.homePage()); - int option = CollectionConfiguration::startOption(*m_helpEngine); + int option = helpEngine.startOption(); m_ui.helpStartComboBox->setCurrentIndex(option); connect(m_ui.blankPageButton, SIGNAL(clicked()), this, SLOT(setBlankPage())); @@ -491,11 +480,13 @@ void PreferencesDialog::updateOptionsPage() void PreferencesDialog::setBlankPage() { + TRACE_OBJ m_ui.homePageLineEdit->setText(QLatin1String("about:blank")); } void PreferencesDialog::setCurrentPage() { + TRACE_OBJ QString homepage = CentralWidget::instance()->currentSource().toString(); if (homepage.isEmpty()) homepage = QLatin1String("help"); @@ -505,8 +496,8 @@ void PreferencesDialog::setCurrentPage() void PreferencesDialog::setDefaultPage() { - QString homePage = CollectionConfiguration::defaultHomePage(*m_helpEngine); - m_ui.homePageLineEdit->setText(homePage); + TRACE_OBJ + m_ui.homePageLineEdit->setText(helpEngine.defaultHomePage()); } QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/preferencesdialog.h b/tools/assistant/tools/assistant/preferencesdialog.h index 2e74fd6..2894494 100644 --- a/tools/assistant/tools/assistant/preferencesdialog.h +++ b/tools/assistant/tools/assistant/preferencesdialog.h @@ -48,22 +48,15 @@ QT_BEGIN_NAMESPACE class FontPanel; +class HelpEngineWrapper; class QFileSystemWatcher; -class QHelpEngineCore; - -enum { - ShowHomePage = 0, - ShowBlankPage = 1, - ShowLastPages = 2 -}; class PreferencesDialog : public QDialog { Q_OBJECT public: - PreferencesDialog(QHelpEngineCore *helpEngine, - QFileSystemWatcher *qchWatcher, QWidget *parent = 0); + PreferencesDialog(QWidget *parent = 0); ~PreferencesDialog(); void showDialog(); @@ -95,7 +88,6 @@ private: void updateOptionsPage(); Ui::PreferencesDialogClass m_ui; - QHelpEngineCore *m_helpEngine; bool m_hideFiltersTab; bool m_hideDocsTab; QMap<QString, QStringList> m_filterMapBackup; @@ -109,7 +101,7 @@ private: FontPanel *m_browserFontPanel; bool m_appFontChanged; bool m_browserFontChanged; - QFileSystemWatcher * const m_qchWatcher; + HelpEngineWrapper &helpEngine; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/qtdocinstaller.cpp b/tools/assistant/tools/assistant/qtdocinstaller.cpp index 7355750..5a501bf 100644 --- a/tools/assistant/tools/assistant/qtdocinstaller.cpp +++ b/tools/assistant/tools/assistant/qtdocinstaller.cpp @@ -38,27 +38,27 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include <QtCore/QDir> #include <QtCore/QLibraryInfo> #include <QtCore/QDateTime> #include <QtCore/QFileSystemWatcher> #include <QtHelp/QHelpEngineCore> -#include "../shared/collectionconfiguration.h" +#include "helpenginewrapper.h" #include "qtdocinstaller.h" QT_BEGIN_NAMESPACE -QtDocInstaller::QtDocInstaller(const QString &collectionFile, - QFileSystemWatcher *qchWatcher) - : m_qchWatcher(qchWatcher) +QtDocInstaller::QtDocInstaller(const QList<DocInfo> &docInfos) + : m_abort(false), m_docInfos(docInfos) { - m_abort = false; - m_collectionFile = collectionFile; + TRACE_OBJ } QtDocInstaller::~QtDocInstaller() { + TRACE_OBJ if (!isRunning()) return; m_mutex.lock(); @@ -69,92 +69,59 @@ QtDocInstaller::~QtDocInstaller() void QtDocInstaller::installDocs() { + TRACE_OBJ start(LowPriority); } void QtDocInstaller::run() { - QHelpEngineCore *helpEngine = new QHelpEngineCore(m_collectionFile); - helpEngine->setupData(); - bool changes = false; - - QStringList docs; - docs << QLatin1String("assistant") - << QLatin1String("designer") - << QLatin1String("linguist") - << QLatin1String("qmake") - << QLatin1String("qt"); + TRACE_OBJ + m_qchDir = QLibraryInfo::location(QLibraryInfo::DocumentationPath) + + QDir::separator() + QLatin1String("qch"); + m_qchFiles = m_qchDir.entryList(QStringList() << QLatin1String("*.qch")); - foreach (const QString &doc, docs) { - changes |= installDoc(doc, helpEngine); + bool changes = false; + foreach (const DocInfo &docInfo, m_docInfos) { + changes |= installDoc(docInfo); m_mutex.lock(); if (m_abort) { - delete helpEngine; m_mutex.unlock(); return; } m_mutex.unlock(); } - delete helpEngine; emit docsInstalled(changes); } -bool QtDocInstaller::installDoc(const QString &name, QHelpEngineCore *helpEngine) +bool QtDocInstaller::installDoc(const DocInfo &docInfo) { - QStringList lst = CollectionConfiguration::qtDocInfo(*helpEngine, name); - + TRACE_OBJ + const QString &component = docInfo.first; + const QStringList &info = docInfo.second; QDateTime dt; - if (!lst.isEmpty() && !lst.first().isEmpty()) - dt = QDateTime::fromString(lst.first(), Qt::ISODate); + if (!info.isEmpty() && !info.first().isEmpty()) + dt = QDateTime::fromString(info.first(), Qt::ISODate); QString qchFile; - if (lst.count() == 2) - qchFile = lst.last(); - - QDir dir(QLibraryInfo::location(QLibraryInfo::DocumentationPath) - + QDir::separator() + QLatin1String("qch")); + if (info.count() == 2) + qchFile = info.last(); - const QStringList files = dir.entryList(QStringList() << QLatin1String("*.qch")); - if (files.isEmpty()) { - CollectionConfiguration::setQtDocInfo(*helpEngine, name, - QStringList(QDateTime().toString(Qt::ISODate))); + if (m_qchFiles.isEmpty()) { + emit qchFileNotFound(component); return false; } - foreach (const QString &f, files) { - if (f.startsWith(name)) { - QFileInfo fi(dir.absolutePath() + QDir::separator() + f); + foreach (const QString &f, m_qchFiles) { + if (f.startsWith(component)) { + QFileInfo fi(m_qchDir.absolutePath() + QDir::separator() + f); if (dt.isValid() && fi.lastModified().toTime_t() == dt.toTime_t() && qchFile == fi.absoluteFilePath()) return false; - - QString namespaceName = QHelpEngineCore::namespaceName(fi.absoluteFilePath()); - if (namespaceName.isEmpty()) - continue; - - if (helpEngine->registeredDocumentations().contains(namespaceName)) { - const QString docFile = - helpEngine->documentationFileName(namespaceName); - if (helpEngine->unregisterDocumentation(namespaceName)) - m_qchWatcher->removePath(docFile); - } - - if (!helpEngine->registerDocumentation(fi.absoluteFilePath())) { - emit errorMessage( - tr("The file %1 could not be registered successfully!\n\nReason: %2") - .arg(fi.absoluteFilePath()).arg(helpEngine->error())); - } else { - m_qchWatcher->addPath(fi.absoluteFilePath()); - } - - Q_ASSERT(m_qchWatcher->files().count() - == helpEngine->registeredDocumentations().count()); - - CollectionConfiguration::setQtDocInfo(*helpEngine, name, - QStringList() << fi.lastModified().toString(Qt::ISODate) - << fi.absoluteFilePath()); + emit registerDocumentation(component, fi.absoluteFilePath()); return true; } } + + emit qchFileNotFound(component); return false; } diff --git a/tools/assistant/tools/assistant/qtdocinstaller.h b/tools/assistant/tools/assistant/qtdocinstaller.h index 46e548a..92a707b 100644 --- a/tools/assistant/tools/assistant/qtdocinstaller.h +++ b/tools/assistant/tools/assistant/qtdocinstaller.h @@ -42,36 +42,41 @@ #ifndef QTDOCINSTALLER #define QTDOCINSTALLER -#include <QtCore/QThread> +#include <QtCore/QDir> #include <QtCore/QMutex> +#include <QtCore/QPair> +#include <QtCore/QStringList> +#include <QtCore/QThread> QT_BEGIN_NAMESPACE -class QFileSystemWatcher; -class QHelpEngineCore; +class HelpEngineWrapper; class QtDocInstaller : public QThread { Q_OBJECT public: - QtDocInstaller(const QString &collectionFile, QFileSystemWatcher *qchWatcher); + typedef QPair<QString, QStringList> DocInfo; + QtDocInstaller(const QList<DocInfo> &docInfos); ~QtDocInstaller(); void installDocs(); signals: - void errorMessage(const QString &msg); + void qchFileNotFound(const QString &component); + void registerDocumentation(const QString &component, + const QString &absFileName); void docsInstalled(bool newDocsInstalled); private: void run(); - bool installDoc(const QString &name, - QHelpEngineCore *helpEngine); + bool installDoc(const DocInfo &docInfo); bool m_abort; - QString m_collectionFile; QMutex m_mutex; - QFileSystemWatcher * const m_qchWatcher; + QStringList m_qchFiles; + QDir m_qchDir; + QList<DocInfo> m_docInfos; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/remotecontrol.cpp b/tools/assistant/tools/assistant/remotecontrol.cpp index d0ff430..5ecdd69 100644 --- a/tools/assistant/tools/assistant/remotecontrol.cpp +++ b/tools/assistant/tools/assistant/remotecontrol.cpp @@ -38,10 +38,12 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "remotecontrol.h" #include "mainwindow.h" #include "centralwidget.h" +#include "helpenginewrapper.h" #include <QtCore/QFile> #include <QtCore/QFileInfo> @@ -67,16 +69,19 @@ QT_BEGIN_NAMESPACE StdInListenerWin::StdInListenerWin(QObject *parent) : QThread(parent) { + TRACE_OBJ } StdInListenerWin::~StdInListenerWin() { + TRACE_OBJ terminate(); wait(); } void StdInListenerWin::run() { + TRACE_OBJ bool ok = true; char chBuf[4096]; DWORD dwRead; @@ -106,18 +111,17 @@ void StdInListenerWin::run() } #endif -RemoteControl::RemoteControl(MainWindow *mainWindow, QHelpEngine *helpEngine, - QFileSystemWatcher *qchWatcher) +RemoteControl::RemoteControl(MainWindow *mainWindow) : QObject(mainWindow) , m_mainWindow(mainWindow) - , m_helpEngine(helpEngine) , m_debug(false) , m_caching(true) , m_syncContents(false) , m_expandTOC(-2) - , m_qchWatcher(qchWatcher) + , helpEngine(HelpEngineWrapper::instance()) { + TRACE_OBJ connect(m_mainWindow, SIGNAL(initDone()), this, SLOT(applyCache())); #ifdef Q_OS_WIN StdInListenerWin *l = new StdInListenerWin(this); @@ -134,6 +138,7 @@ RemoteControl::RemoteControl(MainWindow *mainWindow, QHelpEngine *helpEngine, void RemoteControl::receivedData() { + TRACE_OBJ QByteArray ba; while (true) { char c = getc(stdin); @@ -149,6 +154,7 @@ void RemoteControl::receivedData() void RemoteControl::handleCommandString(const QString &cmdString) { + TRACE_OBJ QStringList cmds = cmdString.split(QLatin1Char(';')); QStringList::const_iterator it = cmds.constBegin(); while (it != cmds.constEnd()) { @@ -193,6 +199,7 @@ void RemoteControl::handleCommandString(const QString &cmdString) void RemoteControl::splitInputString(const QString &input, QString &cmd, QString &arg) { + TRACE_OBJ QString cmdLine = input.trimmed(); int i = cmdLine.indexOf(QLatin1Char(' ')); cmd = cmdLine.left(i); @@ -202,11 +209,13 @@ void RemoteControl::splitInputString(const QString &input, QString &cmd, void RemoteControl::handleDebugCommand(const QString &arg) { + TRACE_OBJ m_debug = arg == QLatin1String("on"); } void RemoteControl::handleShowOrHideCommand(const QString &arg, bool show) { + TRACE_OBJ if (arg.toLower() == QLatin1String("contents")) m_mainWindow->setContentsVisible(show); else if (arg.toLower() == QLatin1String("index")) @@ -219,6 +228,7 @@ void RemoteControl::handleShowOrHideCommand(const QString &arg, bool show) void RemoteControl::handleSetSourceCommand(const QString &arg) { + TRACE_OBJ QUrl url(arg); if (url.isValid()) { if (url.isRelative()) @@ -234,6 +244,7 @@ void RemoteControl::handleSetSourceCommand(const QString &arg) void RemoteControl::handleSyncContentsCommand() { + TRACE_OBJ if (m_caching) m_syncContents = true; else @@ -242,24 +253,25 @@ void RemoteControl::handleSyncContentsCommand() void RemoteControl::handleActivateKeywordCommand(const QString &arg) { + TRACE_OBJ if (m_caching) { clearCache(); m_activateKeyword = arg; } else { m_mainWindow->setIndexString(arg); if (!arg.isEmpty()) - m_helpEngine->indexWidget()->activateCurrentItem(); + helpEngine.indexWidget()->activateCurrentItem(); } } void RemoteControl::handleActivateIdentifierCommand(const QString &arg) { + TRACE_OBJ if (m_caching) { clearCache(); m_activateIdentifier = arg; } else { - const QMap<QString, QUrl> &links = - m_helpEngine->linksForIdentifier(arg); + const QMap<QString, QUrl> &links = helpEngine.linksForIdentifier(arg); if (!links.isEmpty()) CentralWidget::instance()->setSource(links.constBegin().value()); } @@ -267,6 +279,7 @@ void RemoteControl::handleActivateIdentifierCommand(const QString &arg) void RemoteControl::handleExpandTocCommand(const QString &arg) { + TRACE_OBJ bool ok = false; int depth = -2; if (!arg.isEmpty()) @@ -282,59 +295,56 @@ void RemoteControl::handleExpandTocCommand(const QString &arg) void RemoteControl::handleSetCurrentFilterCommand(const QString &arg) { - if (m_helpEngine->customFilters().contains(arg)) { + TRACE_OBJ + if (helpEngine.customFilters().contains(arg)) { if (m_caching) { clearCache(); m_currentFilter = arg; } else { - m_helpEngine->setCurrentFilter(arg); + helpEngine.setCurrentFilter(arg); } } } void RemoteControl::handleRegisterCommand(const QString &arg) { + TRACE_OBJ const QString &absFileName = QFileInfo(arg).absoluteFilePath(); - if (m_helpEngine->registeredDocumentations(). + if (helpEngine.registeredDocumentations(). contains(QHelpEngineCore::namespaceName(absFileName))) return; - if (m_helpEngine->registerDocumentation(absFileName)) { - m_qchWatcher->addPath(absFileName); - m_helpEngine->setupData(); - Q_ASSERT(m_qchWatcher->files().count() - == m_helpEngine->registeredDocumentations().count()); - } + if (helpEngine.registerDocumentation(absFileName)) + helpEngine.setupData(); } void RemoteControl::handleUnregisterCommand(const QString &arg) { + TRACE_OBJ const QString &absFileName = QFileInfo(arg).absoluteFilePath(); const QString &ns = QHelpEngineCore::namespaceName(absFileName); - if (m_helpEngine->registeredDocumentations().contains(ns)) { + if (helpEngine.registeredDocumentations().contains(ns)) { CentralWidget* widget = CentralWidget::instance(); - widget->closeTabs(widget->currentSourceFileList().keys(ns)); - const QString docFile = m_helpEngine->documentationFileName(ns); - if (m_helpEngine->unregisterDocumentation(ns)) { - m_qchWatcher->removePath(docFile); - m_helpEngine->setupData(); - } + widget->closeOrReloadTabs(widget->currentSourceFileList().keys(ns), false); + if (helpEngine.unregisterDocumentation(ns)) + helpEngine.setupData(); } } void RemoteControl::applyCache() { + TRACE_OBJ if (m_setSource.isValid()) { CentralWidget::instance()->setSource(m_setSource); } else if (!m_activateKeyword.isEmpty()) { m_mainWindow->setIndexString(m_activateKeyword); - m_helpEngine->indexWidget()->activateCurrentItem(); + helpEngine.indexWidget()->activateCurrentItem(); } else if (!m_activateIdentifier.isEmpty()) { QMap<QString, QUrl> links = - m_helpEngine->linksForIdentifier(m_activateIdentifier); - if (links.count()) + helpEngine.linksForIdentifier(m_activateIdentifier); + if (!links.isEmpty()) CentralWidget::instance()->setSource(links.constBegin().value()); } else if (!m_currentFilter.isEmpty()) { - m_helpEngine->setCurrentFilter(m_currentFilter); + helpEngine.setCurrentFilter(m_currentFilter); } if (m_syncContents) @@ -349,6 +359,7 @@ void RemoteControl::applyCache() void RemoteControl::clearCache() { + TRACE_OBJ m_currentFilter.clear(); m_setSource.clear(); m_syncContents = false; diff --git a/tools/assistant/tools/assistant/remotecontrol.h b/tools/assistant/tools/assistant/remotecontrol.h index adb6646..0777878 100644 --- a/tools/assistant/tools/assistant/remotecontrol.h +++ b/tools/assistant/tools/assistant/remotecontrol.h @@ -48,17 +48,15 @@ QT_BEGIN_NAMESPACE +class HelpEngineWrapper; class MainWindow; -class QFileSystemWatcher; -class QHelpEngine; class RemoteControl : public QObject { Q_OBJECT public: - RemoteControl(MainWindow *mainWindow, QHelpEngine *helpEngine, - QFileSystemWatcher *qchWatcher); + RemoteControl(MainWindow *mainWindow); private slots: void receivedData(); @@ -81,7 +79,6 @@ private: private: MainWindow *m_mainWindow; - QHelpEngine *m_helpEngine; bool m_debug; bool m_caching; @@ -91,7 +88,7 @@ private: QString m_activateIdentifier; int m_expandTOC; QString m_currentFilter; - QFileSystemWatcher * const m_qchWatcher; + HelpEngineWrapper &helpEngine; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/searchwidget.cpp b/tools/assistant/tools/assistant/searchwidget.cpp index ad24231..d83790d 100644 --- a/tools/assistant/tools/assistant/searchwidget.cpp +++ b/tools/assistant/tools/assistant/searchwidget.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "mainwindow.h" #include "searchwidget.h" @@ -65,6 +66,7 @@ SearchWidget::SearchWidget(QHelpSearchEngine *engine, QWidget *parent) , attached(false) , searchEngine(engine) { + TRACE_OBJ QVBoxLayout *vLayout = new QVBoxLayout(this); resultWidget = searchEngine->resultWidget(); @@ -91,11 +93,13 @@ SearchWidget::SearchWidget(QHelpSearchEngine *engine, QWidget *parent) SearchWidget::~SearchWidget() { + TRACE_OBJ // nothing todo } void SearchWidget::zoomIn() { + TRACE_OBJ QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget); if (browser && zoomCount != 10) { zoomCount++; @@ -105,6 +109,7 @@ void SearchWidget::zoomIn() void SearchWidget::zoomOut() { + TRACE_OBJ QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget); if (browser && zoomCount != -5) { zoomCount--; @@ -114,6 +119,7 @@ void SearchWidget::zoomOut() void SearchWidget::resetZoom() { + TRACE_OBJ if (zoomCount == 0) return; @@ -126,33 +132,39 @@ void SearchWidget::resetZoom() bool SearchWidget::isAttached() const { + TRACE_OBJ return attached; } void SearchWidget::setAttached(bool state) { + TRACE_OBJ attached = state; } void SearchWidget::search() const { + TRACE_OBJ QList<QHelpSearchQuery> query = searchEngine->queryWidget()->query(); searchEngine->search(query); } void SearchWidget::searchingStarted() { + TRACE_OBJ qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); } void SearchWidget::searchingFinished(int hits) { + TRACE_OBJ Q_UNUSED(hits) qApp->restoreOverrideCursor(); } bool SearchWidget::eventFilter(QObject* o, QEvent *e) { + TRACE_OBJ QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget); if (browser && o == browser->viewport() && e->type() == QEvent::MouseButtonRelease){ @@ -171,6 +183,7 @@ bool SearchWidget::eventFilter(QObject* o, QEvent *e) void SearchWidget::keyPressEvent(QKeyEvent *keyEvent) { + TRACE_OBJ if (keyEvent->key() == Qt::Key_Escape) MainWindow::activateCurrentBrowser(); else @@ -179,6 +192,7 @@ void SearchWidget::keyPressEvent(QKeyEvent *keyEvent) void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent) { + TRACE_OBJ QMenu menu; QPoint point = contextMenuEvent->globalPos(); diff --git a/tools/assistant/tools/assistant/topicchooser.cpp b/tools/assistant/tools/assistant/topicchooser.cpp index 5c04244..5aafd5a 100644 --- a/tools/assistant/tools/assistant/topicchooser.cpp +++ b/tools/assistant/tools/assistant/topicchooser.cpp @@ -38,9 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - -#include <QtCore/QMap> -#include <QtCore/QUrl> +#include "tracer.h" #include "topicchooser.h" @@ -50,13 +48,15 @@ TopicChooser::TopicChooser(QWidget *parent, const QString &keyword, const QMap<QString, QUrl> &links) : QDialog(parent) { + TRACE_OBJ ui.setupUi(this); ui.label->setText(tr("Choose a topic for <b>%1</b>:").arg(keyword)); - m_links = links; - QMap<QString, QUrl>::const_iterator it = m_links.constBegin(); - for (; it != m_links.constEnd(); ++it) + QMap<QString, QUrl>::const_iterator it = links.constBegin(); + for (; it != links.constEnd(); ++it) { ui.listWidget->addItem(it.key()); + m_links.append(it.value()); + } if (ui.listWidget->count() != 0) ui.listWidget->setCurrentRow(0); @@ -72,15 +72,18 @@ TopicChooser::TopicChooser(QWidget *parent, const QString &keyword, QUrl TopicChooser::link() const { + TRACE_OBJ QListWidgetItem *item = ui.listWidget->currentItem(); if (!item) return QUrl(); QString title = item->text(); - if (title.isEmpty() || !m_links.contains(title)) + if (title.isEmpty()) return QUrl(); - return m_links.value(title); + const int row = ui.listWidget->row(item); + Q_ASSERT(row < m_links.count()); + return m_links.at(row); } QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/topicchooser.h b/tools/assistant/tools/assistant/topicchooser.h index 4dba726..4113cee 100644 --- a/tools/assistant/tools/assistant/topicchooser.h +++ b/tools/assistant/tools/assistant/topicchooser.h @@ -44,9 +44,10 @@ #include "ui_topicchooser.h" -#include <QUrl> -#include <QMap> -#include <QString> +#include <QtCore/QList> +#include <QtCore/QMap> +#include <QtCore/QString> +#include <QtCore/QUrl> #include <QtGui/QDialog> @@ -64,7 +65,7 @@ public: private: Ui::TopicChooser ui; - QMap<QString, QUrl> m_links; + QList<QUrl> m_links; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/tracer.h b/tools/assistant/tools/assistant/tracer.h index 1967606..66d450a 100644 --- a/tools/assistant/tools/assistant/tracer.h +++ b/tools/assistant/tools/assistant/tracer.h @@ -65,6 +65,7 @@ private: QT_END_NAMESPACE +// #define TRACING_REQUESTED #ifdef TRACING_REQUESTED #define TRACE_OBJ Tracer traceObj__(Q_FUNC_INFO); #else diff --git a/tools/assistant/tools/assistant/xbelsupport.cpp b/tools/assistant/tools/assistant/xbelsupport.cpp index 545be6c..f2c0bcb 100644 --- a/tools/assistant/tools/assistant/xbelsupport.cpp +++ b/tools/assistant/tools/assistant/xbelsupport.cpp @@ -38,12 +38,15 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include "tracer.h" #include "xbelsupport.h" #include "bookmarkmanager.h" #include <QtCore/QCoreApplication> +QT_BEGIN_NAMESPACE + struct Bookmark { QString title; QString url; @@ -54,11 +57,13 @@ XbelWriter::XbelWriter(BookmarkModel *model) : QXmlStreamWriter() , treeModel(model) { + TRACE_OBJ setAutoFormatting(true); } void XbelWriter::writeToFile(QIODevice *device) { + TRACE_OBJ setDevice(device); writeStartDocument(); @@ -75,6 +80,7 @@ void XbelWriter::writeToFile(QIODevice *device) void XbelWriter::writeData(QStandardItem *child) { + TRACE_OBJ Bookmark entry; entry.title = child->data(Qt::DisplayRole).toString(); entry.url = child->data(Qt::UserRole + 10).toString(); @@ -109,12 +115,14 @@ XbelReader::XbelReader(BookmarkModel *tree, BookmarkModel *list) , treeModel(tree) , listModel(list) { + TRACE_OBJ folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon); bookmarkIcon = QIcon(QLatin1String(":/trolltech/assistant/images/bookmark.png")); } bool XbelReader::readFromFile(QIODevice *device) { + TRACE_OBJ setDevice(device); while (!atEnd()) { @@ -136,6 +144,7 @@ bool XbelReader::readFromFile(QIODevice *device) void XbelReader::readXBEL() { + TRACE_OBJ while (!atEnd()) { readNext(); @@ -155,6 +164,7 @@ void XbelReader::readXBEL() void XbelReader::readUnknownElement() { + TRACE_OBJ while (!atEnd()) { readNext(); @@ -168,6 +178,7 @@ void XbelReader::readUnknownElement() void XbelReader::readFolder(QStandardItem *item) { + TRACE_OBJ QStandardItem *folder = createChildItem(item); folder->setIcon(folderIcon); folder->setData(QLatin1String("Folder"), Qt::UserRole + 10); @@ -197,6 +208,7 @@ void XbelReader::readFolder(QStandardItem *item) void XbelReader::readBookmark(QStandardItem *item) { + TRACE_OBJ QStandardItem *bookmark = createChildItem(item); bookmark->setIcon(bookmarkIcon); bookmark->setText(QCoreApplication::tr("Unknown title")); @@ -222,6 +234,7 @@ void XbelReader::readBookmark(QStandardItem *item) QStandardItem *XbelReader::createChildItem(QStandardItem *item) { + TRACE_OBJ QStandardItem *childItem = new QStandardItem(); childItem->setEditable(false); @@ -232,3 +245,5 @@ QStandardItem *XbelReader::createChildItem(QStandardItem *item) return childItem; } + +QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/xbelsupport.h b/tools/assistant/tools/assistant/xbelsupport.h index 005cfbb..16f53f5 100644 --- a/tools/assistant/tools/assistant/xbelsupport.h +++ b/tools/assistant/tools/assistant/xbelsupport.h @@ -48,6 +48,8 @@ QT_FORWARD_DECLARE_CLASS(QIODevice) QT_FORWARD_DECLARE_CLASS(QStandardItem) +QT_BEGIN_NAMESPACE + class BookmarkModel; class XbelWriter : public QXmlStreamWriter @@ -84,4 +86,6 @@ private: BookmarkModel *listModel; }; +QT_END_NAMESPACE + #endif // XBELSUPPORT_H diff --git a/tools/assistant/tools/qcollectiongenerator/main.cpp b/tools/assistant/tools/qcollectiongenerator/main.cpp index d45279d..f75d891 100644 --- a/tools/assistant/tools/qcollectiongenerator/main.cpp +++ b/tools/assistant/tools/qcollectiongenerator/main.cpp @@ -42,19 +42,19 @@ #include "../shared/collectionconfiguration.h" #include "../shared/helpgenerator.h" +#include <private/qhelpgenerator_p.h> +#include <private/qhelpprojectdata_p.h> + #include <QtCore/QDir> #include <QtCore/QMap> #include <QtCore/QFileInfo> #include <QtCore/QCoreApplication> #include <QtCore/QDateTime> #include <QtCore/QBuffer> - -#include <private/qhelpgenerator_p.h> -#include <private/qhelpprojectdata_p.h> #include <QtHelp/QHelpEngineCore> - #include <QtXml/QXmlStreamReader> + QT_USE_NAMESPACE class CollectionConfigReader : public QXmlStreamReader @@ -467,8 +467,7 @@ int main(int argc, char *argv[]) } if (!config.currentFilter().isEmpty()) { - CollectionConfiguration::setCurrentFilter(helpEngine, - config.currentFilter()); + helpEngine.setCurrentFilter(config.currentFilter()); } if (!config.cacheDirectory().isEmpty()) { diff --git a/tools/assistant/tools/shared/collectionconfiguration.cpp b/tools/assistant/tools/shared/collectionconfiguration.cpp index d0650e4..896afaf 100644 --- a/tools/assistant/tools/shared/collectionconfiguration.cpp +++ b/tools/assistant/tools/shared/collectionconfiguration.cpp @@ -46,31 +46,22 @@ QT_BEGIN_NAMESPACE namespace { - const QString ListSeparator(QLatin1String("|")); - const QString AboutIconKey(QLatin1String("AboutIcon")); const QString AboutImagesKey(QLatin1String("AboutImages")); const QString AboutMenuTextsKey(QLatin1String("AboutMenuTexts")); const QString AboutTextsKey(QLatin1String("AboutTexts")); - const QString AppFontKey(QLatin1String("appFont")); const QString ApplicationIconKey(QLatin1String("ApplicationIcon")); - const QString AppWritingSystemKey(QLatin1String("appWritingSystem")); - const QString BookmarksKey(QLatin1String("Bookmarks")); - const QString BrowserFontKey(QLatin1String("browserFont")); - const QString BrowserWritingSystemKey(QLatin1String("browserWritingSystem")); const QString CacheDirKey(QLatin1String("CacheDirectory")); const QString CacheDirRelativeToCollectionKey(QLatin1String("CacheDirRelativeToCollection")); const QString CreationTimeKey(QLatin1String("CreationTime")); - const QString CurrentFilterKey(QLatin1String("CurrentFilter")); const QString DefaultHomePageKey(QLatin1String("defaultHomepage")); - const QString DocUpdatePendingKey(QLatin1String("DocUpdate")); const QString EnableAddressBarKey(QLatin1String("EnableAddressBar")); const QString EnableDocManagerKey(QLatin1String("EnableDocumentationManager")); const QString EnableFilterKey(QLatin1String("EnableFilterFunctionality")); - const QString FilterToolbarHiddenKey(QLatin1String("HideFilterFunctionality")); const QString HideAddressBarKey(QLatin1String("HideAddressBar")); - const QString HomePageKey(QLatin1String("homepage")); + const QString FilterToolbarHiddenKey(QLatin1String("HideFilterFunctionality")); const QString LastPageKey(QLatin1String("LastTabPage")); + const QString LastRegisterTime(QLatin1String("LastRegisterTime")); const QString LastShownPagesKey(QLatin1String("LastShownPages")); const QString LastZoomFactorsKey(QLatin1String( #if !defined(QT_NO_WEBKIT) @@ -79,19 +70,11 @@ namespace { "LastPagesZoomTextBrowser" #endif )); - const QString MainWindowKey(QLatin1String("MainWindow")); - const QString MainWindowGeometryKey(QLatin1String("MainWindowGeometry")); - const QString SearchWasAttachedKey(QLatin1String("SearchWasAttached")); - const QString StartOptionKey(QLatin1String("StartOption")); - const QString UnfilteredInsertedKey(QLatin1String("UnfilteredFilterInserted")); - const QString UseAppFontKey(QLatin1String("useAppFont")); - const QString UseBrowserFontKey(QLatin1String("useBrowserFont")); - const QString VersionKey(QString(QLatin1String("qtVersion%1$$$%2")). - arg(QLatin1String(QT_VERSION_STR))); const QString WindowTitleKey(QLatin1String("WindowTitle")); } // anonymous namespace const QString CollectionConfiguration::DefaultZoomFactor(QLatin1String("0.0")); +const QString CollectionConfiguration::ListSeparator(QLatin1String("|")); uint CollectionConfiguration::creationTime(const QHelpEngineCore &helpEngine) { @@ -109,84 +92,18 @@ const QString CollectionConfiguration::windowTitle(const QHelpEngineCore &helpEn } void CollectionConfiguration::setWindowTitle(QHelpEngineCore &helpEngine, - const QString &windowTitle) + const QString &windowTitle) { helpEngine.setCustomValue(WindowTitleKey, windowTitle); } - -int CollectionConfiguration::lastTabPage(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(LastPageKey, 1).toInt(); -} - -void CollectionConfiguration::setLastTabPage(QHelpEngineCore &helpEngine, int lastPage) -{ - helpEngine.setCustomValue(LastPageKey, lastPage); -} - - -const QStringList CollectionConfiguration::lastShownPages(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(LastShownPagesKey).toString(). - split(ListSeparator, QString::SkipEmptyParts); -} - -void CollectionConfiguration::setLastShownPages(QHelpEngineCore &helpEngine, - const QStringList &lastShownPages) -{ - helpEngine. - setCustomValue(LastShownPagesKey, lastShownPages.join(ListSeparator)); -} - -const QStringList CollectionConfiguration::lastZoomFactors(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(LastZoomFactorsKey).toString(). - split(ListSeparator, QString::SkipEmptyParts); -} - -void CollectionConfiguration::setLastZoomFactors(QHelpEngineCore &helpEngine, - const QStringList &lastZoomFactors) -{ - helpEngine.setCustomValue(LastZoomFactorsKey, lastZoomFactors.join(ListSeparator)); -} - -const QString CollectionConfiguration::currentFilter(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(CurrentFilterKey).toString(); -} - -void CollectionConfiguration::setCurrentFilter(QHelpEngineCore &helpEngine, - const QString ¤tFilter) -{ - helpEngine.setCustomValue(CurrentFilterKey, currentFilter); -} - -const QString CollectionConfiguration::cacheDir(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(CacheDirKey).toString(); -} - -bool CollectionConfiguration::cacheDirIsRelativeToCollection(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(CacheDirRelativeToCollectionKey).toBool(); -} - -void CollectionConfiguration::setCacheDir(QHelpEngineCore &helpEngine, - const QString &cacheDir, bool relativeToCollection) -{ - helpEngine.setCustomValue(CacheDirKey, cacheDir); - helpEngine.setCustomValue(CacheDirRelativeToCollectionKey, - relativeToCollection); -} - bool CollectionConfiguration::filterFunctionalityEnabled(const QHelpEngineCore &helpEngine) { return helpEngine.customValue(EnableFilterKey, true).toBool(); } void CollectionConfiguration::setFilterFunctionalityEnabled(QHelpEngineCore &helpEngine, - bool enabled) + bool enabled) { helpEngine.setCustomValue(EnableFilterKey, enabled); } @@ -197,7 +114,7 @@ bool CollectionConfiguration::filterToolbarVisible(const QHelpEngineCore &helpEn } void CollectionConfiguration::setFilterToolbarVisible(QHelpEngineCore &helpEngine, - bool visible) + bool visible) { helpEngine.setCustomValue(FilterToolbarHiddenKey, !visible); } @@ -224,6 +141,24 @@ void CollectionConfiguration::setAddressBarVisible(QHelpEngineCore &helpEngine, helpEngine.setCustomValue(HideAddressBarKey, !visible); } +const QString CollectionConfiguration::cacheDir(const QHelpEngineCore &helpEngine) +{ + return helpEngine.customValue(CacheDirKey).toString(); +} + +bool CollectionConfiguration::cacheDirIsRelativeToCollection(const QHelpEngineCore &helpEngine) +{ + return helpEngine.customValue(CacheDirRelativeToCollectionKey).toBool(); +} + +void CollectionConfiguration::setCacheDir(QHelpEngineCore &helpEngine, + const QString &cacheDir, bool relativeToCollection) +{ + helpEngine.setCustomValue(CacheDirKey, cacheDir); + helpEngine.setCustomValue(CacheDirRelativeToCollectionKey, + relativeToCollection); +} + bool CollectionConfiguration::documentationManagerEnabled(const QHelpEngineCore &helpEngine) { return helpEngine.customValue(EnableDocManagerKey, true).toBool(); @@ -302,180 +237,51 @@ void CollectionConfiguration::setDefaultHomePage(QHelpEngineCore &helpEngine, helpEngine.setCustomValue(DefaultHomePageKey, page); } -const QString CollectionConfiguration::homePage(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(HomePageKey).toString(); -} - -void CollectionConfiguration::setHomePage(QHelpEngineCore &helpEngine, - const QString &page) -{ - helpEngine.setCustomValue(HomePageKey, page); -} - -int CollectionConfiguration::startOption(const QHelpEngineCore &helpEngine) -{ - // TODO: After moving to helpengine wrapper, put LastPages in that header file - // and use it here as default value. - return helpEngine.customValue(StartOptionKey).toInt(); -} - -void CollectionConfiguration::setStartOption(QHelpEngineCore &helpEngine, - int option) -{ - helpEngine.setCustomValue(StartOptionKey, option); -} - -bool CollectionConfiguration::docUpdatePending(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(DocUpdatePendingKey, false).toBool(); -} - -void CollectionConfiguration::setDocUpdatePending(QHelpEngineCore &helpEngine, - bool pending) -{ - helpEngine.setCustomValue(DocUpdatePendingKey, pending); -} - -const QByteArray CollectionConfiguration::bookmarks(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(BookmarksKey).toByteArray(); -} - -void CollectionConfiguration::setBookmarks(QHelpEngineCore &helpEngine, - const QByteArray &bookmarks) -{ - helpEngine.setCustomValue(BookmarksKey, bookmarks); -} - -const QByteArray CollectionConfiguration::mainWindow(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(MainWindowKey).toByteArray(); -} - -void CollectionConfiguration::setMainWindow(QHelpEngineCore &helpEngine, - const QByteArray &mainWindow) -{ - helpEngine.setCustomValue(MainWindowKey, mainWindow); -} - -const QByteArray CollectionConfiguration::mainWindowGeometry(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(MainWindowGeometryKey).toByteArray(); -} - -void CollectionConfiguration::setMainWindowGeometry(QHelpEngineCore &helpEngine, - const QByteArray &geometry) -{ - helpEngine.setCustomValue(MainWindowGeometryKey, geometry); -} - -bool CollectionConfiguration::usesAppFont(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(UseAppFontKey).toBool(); -} - -void CollectionConfiguration::setUseAppFont(QHelpEngineCore &helpEngine, - bool useAppFont) -{ - helpEngine.setCustomValue(UseAppFontKey, useAppFont); -} - -bool CollectionConfiguration::usesBrowserFont(const QHelpEngineCore &helpEngine) -{ - return helpEngine.customValue(UseBrowserFontKey, false).toBool(); -} - -void CollectionConfiguration::setUseBrowserFont(QHelpEngineCore &helpEngine, - bool useBrowserFont) -{ - helpEngine.setCustomValue(UseBrowserFontKey, useBrowserFont); -} - -const QFont CollectionConfiguration::appFont(const QHelpEngineCore &helpEngine) -{ - return qVariantValue<QFont>(helpEngine.customValue(AppFontKey)); -} - -void CollectionConfiguration::setAppFont(QHelpEngineCore &helpEngine, - const QFont &font) -{ - helpEngine.setCustomValue(AppFontKey, font); -} - -QFontDatabase::WritingSystem CollectionConfiguration::appWritingSystem(const QHelpEngineCore &helpEngine) -{ - return static_cast<QFontDatabase::WritingSystem>( - helpEngine.customValue(AppWritingSystemKey).toInt()); -} - -void CollectionConfiguration::setAppWritingSystem(QHelpEngineCore &helpEngine, - QFontDatabase::WritingSystem system) -{ - helpEngine.setCustomValue(AppWritingSystemKey, system); -} - -const QFont CollectionConfiguration::browserFont(const QHelpEngineCore &helpEngine) -{ - return qVariantValue<QFont>(helpEngine.customValue(BrowserFontKey)); -} - -void CollectionConfiguration::setBrowserFont(QHelpEngineCore &helpEngine, - const QFont &font) -{ - helpEngine.setCustomValue(BrowserFontKey, font); -} - -QFontDatabase::WritingSystem CollectionConfiguration::browserWritingSystem(const QHelpEngineCore &helpEngine) -{ - return static_cast<QFontDatabase::WritingSystem>( - helpEngine.customValue(BrowserWritingSystemKey).toInt()); -} - -void CollectionConfiguration::setBrowserWritingSystem(QHelpEngineCore &helpEngine, - QFontDatabase::WritingSystem system) +const QStringList CollectionConfiguration::lastShownPages(const QHelpEngineCore &helpEngine) { - helpEngine.setCustomValue(BrowserWritingSystemKey, system); + return helpEngine.customValue(LastShownPagesKey).toString(). + split(ListSeparator, QString::SkipEmptyParts); } -bool CollectionConfiguration::unfilteredInserted(const QHelpEngineCore &helpEngine) +void CollectionConfiguration::setLastShownPages(QHelpEngineCore &helpEngine, + const QStringList &lastShownPages) { - return helpEngine.customValue(UnfilteredInsertedKey).toInt() == 1; + helpEngine.setCustomValue(LastShownPagesKey, + lastShownPages.join(ListSeparator)); } -void CollectionConfiguration::setUnfilteredInserted(QHelpEngineCore &helpEngine) +const QStringList CollectionConfiguration::lastZoomFactors(const QHelpEngineCore &helpEngine) { - helpEngine.setCustomValue(UnfilteredInsertedKey, 1); + return helpEngine.customValue(LastZoomFactorsKey).toString(). + split(ListSeparator, QString::SkipEmptyParts); } -const QStringList CollectionConfiguration::qtDocInfo(const QHelpEngineCore &helpEngine, - const QString &component) +void CollectionConfiguration::setLastZoomFactors(QHelpEngineCore &helpEngine, + const QStringList &lastZoomFactors) { - return helpEngine.customValue(VersionKey.arg(component)).toString(). - split(ListSeparator); + helpEngine.setCustomValue(LastZoomFactorsKey, + lastZoomFactors.join(ListSeparator)); } -void CollectionConfiguration::setQtDocInfo(QHelpEngineCore &helpEngine, - const QString &component, const QStringList &doc) +int CollectionConfiguration::lastTabPage(const QHelpEngineCore &helpEngine) { - helpEngine.setCustomValue(VersionKey.arg(component), - doc.join(ListSeparator)); + return helpEngine.customValue(LastPageKey, 1).toInt(); } -bool CollectionConfiguration::searchWasAttached(const QHelpEngineCore &helpEngine) +void CollectionConfiguration::setLastTabPage(QHelpEngineCore &helpEngine, + int lastPage) { - return helpEngine.customValue(SearchWasAttachedKey).toBool(); + helpEngine.setCustomValue(LastPageKey, lastPage); } -void CollectionConfiguration::setSearchWasAttached(QHelpEngineCore &helpEngine, - bool attached) +const QDateTime CollectionConfiguration::lastRegisterTime(const QHelpEngineCore &helpEngine) { - helpEngine.setCustomValue(SearchWasAttachedKey, attached); + return helpEngine.customValue(LastRegisterTime, QDateTime()).toDateTime(); } -bool CollectionConfiguration::hasFontSettings(const QHelpEngineCore &helpEngine) +void CollectionConfiguration::updateLastRegisterTime(QHelpEngineCore &helpEngine) { - return helpEngine.customValue(UseAppFontKey).isValid(); + helpEngine.setCustomValue(LastRegisterTime, QDateTime::currentDateTime()); } bool CollectionConfiguration::isNewer(const QHelpEngineCore &newer, @@ -489,9 +295,7 @@ void CollectionConfiguration::copyConfiguration(const QHelpEngineCore &source, { setCreationTime(target, creationTime(source)); setWindowTitle(target, windowTitle(source)); - setLastShownPages(target, lastShownPages(source)); - setLastZoomFactors(target, lastZoomFactors(source)); - setCurrentFilter(target, currentFilter(source)); + target.setCurrentFilter(source.currentFilter()); setCacheDir(target, cacheDir(source), cacheDirIsRelativeToCollection(source)); setFilterFunctionalityEnabled(target, filterFunctionalityEnabled(source)); setFilterToolbarVisible(target, filterToolbarVisible(source)); diff --git a/tools/assistant/tools/shared/collectionconfiguration.h b/tools/assistant/tools/shared/collectionconfiguration.h index 48d2803..d897adb 100644 --- a/tools/assistant/tools/shared/collectionconfiguration.h +++ b/tools/assistant/tools/shared/collectionconfiguration.h @@ -44,10 +44,9 @@ #include <QtCore/QByteArray> #include <QtCore/QCoreApplication> +#include <QtCore/QDateTime> #include <QtCore/QString> #include <QtCore/QStringList> -#include <QtGui/QFont> -#include <QtGui/QFontDatabase> QT_BEGIN_NAMESPACE @@ -56,29 +55,18 @@ class QHelpEngineCore; class CollectionConfiguration { public: - static int lastTabPage(const QHelpEngineCore &helpEngine); - static void setLastTabPage(QHelpEngineCore &helpEngine, int lastPage); - - static const QStringList lastShownPages(const QHelpEngineCore &helpEngine); - static void setLastShownPages(QHelpEngineCore &helpEngine, - const QStringList &lastShownPages); - - - // TODO: Don't allow last pages and zoom factors to be set in isolation - // Perhaps also fill up missing elements automatically or assert. - static const QStringList lastZoomFactors(const QHelpEngineCore &helpEngine); - static void setLastZoomFactors(QHelpEngineCore &helpEngine, - const QStringList &lastZoomFactors); - - static const QString currentFilter(const QHelpEngineCore &helpEngine); - static void setCurrentFilter(QHelpEngineCore &helpEngine, - const QString ¤tFilter); + static const QString windowTitle(const QHelpEngineCore &helpEngine); + static void setWindowTitle(QHelpEngineCore &helpEngine, + const QString &windowTitle); static const QString cacheDir(const QHelpEngineCore &helpEngine); static bool cacheDirIsRelativeToCollection(const QHelpEngineCore &helpEngine); static void setCacheDir(QHelpEngineCore &helpEngine, const QString &cacheDir, bool relativeToCollection); + static uint creationTime(const QHelpEngineCore &helpEngine); + static void setCreationTime(QHelpEngineCore &helpEngine, uint time); + static bool filterFunctionalityEnabled(const QHelpEngineCore &helpEngine); static void setFilterFunctionalityEnabled(QHelpEngineCore &helpEngine, bool enabled); @@ -93,12 +81,6 @@ public: static bool addressBarVisible(const QHelpEngineCore &helpEngine); static void setAddressBarVisible(QHelpEngineCore &helpEngine, bool visible); - static uint creationTime(const QHelpEngineCore &helpEngine); - static void setCreationTime(QHelpEngineCore &helpEngine, uint time); - - static const QString windowTitle(const QHelpEngineCore &helpEngine); - static void setWindowTitle(QHelpEngineCore &helpEngine, - const QString &windowTitle); static bool documentationManagerEnabled(const QHelpEngineCore &helpEngine); static void setDocumentationManagerEnabled(QHelpEngineCore &helpEngine, @@ -108,12 +90,6 @@ public: static void setApplicationIcon(QHelpEngineCore &helpEngine, const QByteArray &icon); - static const QString homePage(const QHelpEngineCore &helpEngine); - static void setHomePage(QHelpEngineCore &helpEngine, const QString &page); - - static int startOption(const QHelpEngineCore &helpEngine); - static void setStartOption(QHelpEngineCore &helpEngine, int option); - // TODO: Encapsulate encoding from/to QByteArray here static const QByteArray aboutMenuTexts(const QHelpEngineCore &helpEngine); static void setAboutMenuTexts(QHelpEngineCore &helpEngine, @@ -136,61 +112,32 @@ public: static void setDefaultHomePage(QHelpEngineCore &helpEngine, const QString &page); - static bool docUpdatePending(const QHelpEngineCore &helpEngine); - static void setDocUpdatePending(QHelpEngineCore &helpEngine, bool pending); - - // TODO: Put these GUI-specific functions in the help engine wrapper - static const QByteArray bookmarks(const QHelpEngineCore &helpEngine); - static void setBookmarks(QHelpEngineCore &helpEngine, - const QByteArray &bookmarks); - - static const QByteArray mainWindow(const QHelpEngineCore &helpEngine); - static void setMainWindow(QHelpEngineCore &helpEngine, - const QByteArray &mainWindow); - - static const QByteArray mainWindowGeometry(const QHelpEngineCore &helpEngine); - static void setMainWindowGeometry(QHelpEngineCore &helpEngine, - const QByteArray &geometry); - - static bool usesAppFont(const QHelpEngineCore &helpEngine); - static void setUseAppFont(QHelpEngineCore &helpEngine, bool useAppFont); - - static bool usesBrowserFont(const QHelpEngineCore &helpEngine); - static void setUseBrowserFont(QHelpEngineCore &helpEngine, - bool useBrowserFont); - - static const QFont appFont(const QHelpEngineCore &helpEngine); - static void setAppFont(QHelpEngineCore &helpEngine, const QFont &font); - - static QFontDatabase::WritingSystem appWritingSystem(const QHelpEngineCore &helpEngine); - static void setAppWritingSystem(QHelpEngineCore &helpEngine, - QFontDatabase::WritingSystem system); - - static const QFont browserFont(const QHelpEngineCore &helpEngine); - static void setBrowserFont(QHelpEngineCore &helpEngine, const QFont &font); - - static QFontDatabase::WritingSystem browserWritingSystem(const QHelpEngineCore &helpEngine); - static void setBrowserWritingSystem(QHelpEngineCore &helpEngine, - QFontDatabase::WritingSystem system); - - static bool unfilteredInserted(const QHelpEngineCore &helpEngine); - static void setUnfilteredInserted(QHelpEngineCore &helpEngine); - - static const QStringList qtDocInfo(const QHelpEngineCore &helpEngine, - const QString &component); - static void setQtDocInfo(QHelpEngineCore &helpEngine, - const QString &component, const QStringList &doc); + // TODO: Don't allow last pages and zoom factors to be set in isolation + // Perhaps also fill up missing elements automatically or assert. + static const QStringList lastShownPages(const QHelpEngineCore &helpEngine); + static void setLastShownPages(QHelpEngineCore &helpEngine, + const QStringList &lastShownPages); + static const QStringList lastZoomFactors(const QHelpEngineCore &helpEngine); + static void setLastZoomFactors(QHelpEngineCore &helPEngine, + const QStringList &lastZoomFactors); - static bool searchWasAttached(const QHelpEngineCore &helpEngine); - static void setSearchWasAttached(QHelpEngineCore &helpEngine, bool attached); + static int lastTabPage(const QHelpEngineCore &helpEngine); + static void setLastTabPage(QHelpEngineCore &helpEngine, int lastPage); - static bool hasFontSettings(const QHelpEngineCore &helpEngine); static bool isNewer(const QHelpEngineCore &newer, const QHelpEngineCore &older); static void copyConfiguration(const QHelpEngineCore &source, QHelpEngineCore &target); + /* + * Note that this only reflects register actions caused by the + * "-register" command line switch, not GUI or remote control actions. + */ + static const QDateTime lastRegisterTime(const QHelpEngineCore &helpEngine); + static void updateLastRegisterTime(QHelpEngineCore &helpEngine); + static const QString DefaultZoomFactor; + static const QString ListSeparator; }; QT_END_NAMESPACE diff --git a/tools/linguist/linguist/mainwindow.ui b/tools/linguist/linguist/mainwindow.ui index 450ce89..4edde5e 100644 --- a/tools/linguist/linguist/mainwindow.ui +++ b/tools/linguist/linguist/mainwindow.ui @@ -679,7 +679,7 @@ <string>About Qt</string> </property> <property name="whatsThis"> - <string>Display information about the Qt toolkit by Trolltech.</string> + <string>Display information about the Qt toolkit by Nokia.</string> </property> <property name="menuRole"> <enum>QAction::AboutQtRole</enum> diff --git a/tools/qdbus/qdbus/qdbus.cpp b/tools/qdbus/qdbus/qdbus.cpp index 48b0dad..b08910a 100644 --- a/tools/qdbus/qdbus/qdbus.cpp +++ b/tools/qdbus/qdbus/qdbus.cpp @@ -248,8 +248,8 @@ static QStringList readList(QStringList &args) return retval; } -static void placeCall(const QString &service, const QString &path, const QString &interface, - const QString &member, QStringList args) +static int placeCall(const QString &service, const QString &path, const QString &interface, + const QString &member, QStringList args, bool try_prop=true) { QDBusInterface iface(service, path, interface, connection); @@ -273,10 +273,22 @@ static void placeCall(const QString &service, const QString &path, const QString } if (midx == -1) { + // Failed to set property after falling back? + // Bail out without displaying an error + if (!try_prop) + return 1; + if (try_prop && args.size() == 1) { + QStringList proparg; + proparg += interface; + proparg += member; + proparg += args.first(); + if (!placeCall(service, path, "org.freedesktop.DBus.Properties", "Set", proparg, false)) + return 0; + } fprintf(stderr, "Cannot find '%s.%s' in object %s at %s\n", qPrintable(interface), qPrintable(member), qPrintable(path), qPrintable(service)); - exit(1); + return 1; } QMetaMethod mm = mo->method(midx); @@ -314,7 +326,7 @@ static void placeCall(const QString &service, const QString &path, const QString if (p.type() == QVariant::Invalid) { fprintf(stderr, "Could not convert '%s' to type '%s'.\n", qPrintable(argument), types.at(i).constData()); - exit(1); + return 1 ; } } else if (id == qMetaTypeId<QDBusVariant>()) { QDBusVariant tmp(p); @@ -324,7 +336,7 @@ static void placeCall(const QString &service, const QString &path, const QString if (path.path().isNull()) { fprintf(stderr, "Cannot pass argument '%s' because it is not a valid object path.\n", qPrintable(argument)); - exit(1); + return 1; } p = qVariantFromValue(path); } else if (id == qMetaTypeId<QDBusSignature>()) { @@ -332,39 +344,50 @@ static void placeCall(const QString &service, const QString &path, const QString if (sig.signature().isNull()) { fprintf(stderr, "Cannot pass argument '%s' because it is not a valid signature.\n", qPrintable(argument)); - exit(1); + return 1; } p = qVariantFromValue(sig); } else { fprintf(stderr, "Sorry, can't pass arg of type '%s'.\n", types.at(i).constData()); - exit(1); + return 1; } params += p; } if (params.count() != types.count() || !args.isEmpty()) { fprintf(stderr, "Invalid number of parameters\n"); - exit(1); + return 1; } } QDBusMessage reply = iface.callWithArgumentList(QDBus::Block, member, params); if (reply.type() == QDBusMessage::ErrorMessage) { QDBusError err = reply; + // Failed to retrieve property after falling back? + // Bail out without displaying an error + if (!try_prop) + return 1; + if (err.type() == QDBusError::UnknownMethod && try_prop) { + QStringList proparg; + proparg += interface; + proparg += member; + if (!placeCall(service, path, "org.freedesktop.DBus.Properties", "Get", proparg, false)) + return 0; + } if (err.type() == QDBusError::ServiceUnknown) fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service)); else printf("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); - exit(2); + return 2; } else if (reply.type() != QDBusMessage::ReplyMessage) { fprintf(stderr, "Invalid reply type %d\n", int(reply.type())); - exit(1); + return 1; } foreach (QVariant v, reply.arguments()) printArg(v); - exit(0); + return 0; } static bool globServices(QDBusConnectionInterface *bus, const QString &glob) @@ -483,6 +506,7 @@ int main(int argc, char **argv) exit(1); } - placeCall(service, path, interface, member, args); + int ret = placeCall(service, path, interface, member, args); + exit(ret); } diff --git a/tools/qdoc3/test/qt-build-docs.qdocconf b/tools/qdoc3/test/qt-build-docs.qdocconf index ef4d04f..e8595f6 100644 --- a/tools/qdoc3/test/qt-build-docs.qdocconf +++ b/tools/qdoc3/test/qt-build-docs.qdocconf @@ -8,10 +8,11 @@ project = Qt description = Qt Reference Documentation url = http://qt.nokia.com/doc/4.7 -edition.Desktop.modules = QtCore QtDBus QtGui QtNetwork QtOpenGL QtScript QtScriptTools QtSql \ - QtSvg QtWebKit QtXml QtXmlPatterns Qt3Support QtHelp \ - QtDesigner QAxContainer Phonon QAxServer QtUiTools \ - QtTest QtDBus +edition.Desktop.modules = QtCore QtDBus QtGui QtNetwork QtOpenGL QtScript QtScriptTools QtSql QtSvg \ + QtWebKit QtXml QtXmlPatterns Qt3Support QtHelp \ + QtDesigner QtAssistant QAxContainer Phonon \ + QAxServer QtUiTools QtTest QtDBus + edition.DesktopLight.modules = QtCore QtDBus QtGui Qt3SupportLight QtTest edition.DesktopLight.groups = -graphicsview-api |