Changeset 846 for trunk/tools/assistant
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 149 edited
- 28 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/tools/assistant/assistant.pro
r2 r846 4 4 SUBDIRS += lib/fulltextsearch \ 5 5 lib \ 6 tools \ 7 compat \ 8 compat/lib \ 6 tools -
trunk/tools/assistant/lib/fulltextsearch/fulltextsearch.pro
r631 r846 32 32 CONFIG -= exceptions_off 33 33 CONFIG += exceptions 34 !win32|win32-g++ {34 !win32|win32-g++ { 35 35 QMAKE_CFLAGS -= -fno-exceptions 36 36 QMAKE_CXXFLAGS -= -fno-exceptions … … 49 49 # the following define could be set globally in case we need it elsewhere 50 50 solaris* { 51 DEFINES += Q_SOLARIS_VERSION=$$system(uname -r | sed -e 's/5\ .//')51 DEFINES += Q_SOLARIS_VERSION=$$system(uname -r | sed -e 's/5\.//') 52 52 } -
trunk/tools/assistant/lib/fulltextsearch/qanalyzer.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qanalyzer_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qclucene-config_p.h
r769 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** … … 315 315 #endif 316 316 317 // Do not use the tchar.h that ships with mingw, this causes the qt build to 318 // fail (211547, 211401, etc...), reuse the replacement as with any other compiler 319 // #if defined(__MINGW32__) 320 // /* Define to 1 if you have the <tchar.h> header file. */ 321 // # ifndef _CL_HAVE_TCHAR_H 322 // # define _CL_HAVE_TCHAR_H 1 323 // # endif 324 // #endif 317 #if defined(__MINGW32__) 318 /* Define to 1 if you have the <tchar.h> header file. */ 319 # ifndef _CL_HAVE_TCHAR_H 320 # define _CL_HAVE_TCHAR_H 1 321 # endif 322 #endif 325 323 326 324 #if defined(__MINGW32__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C) -
trunk/tools/assistant/lib/fulltextsearch/qclucene_global_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** … … 37 37 #include <QtCore/QString> 38 38 39 #if !defined(_MSC_VER) 39 #if !defined(_MSC_VER) 40 40 # if !defined(TCHAR) 41 41 # if defined(_CL_HAVE_WCHAR_H) && defined(_CL_HAVE_WCHAR_T) && !defined(_ASCII) -
trunk/tools/assistant/lib/fulltextsearch/qdocument.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qdocument_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qfield.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qfield_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qfilter.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qfilter_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qhits.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qhits_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qindexreader.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qindexreader_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qindexwriter.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** … … 89 89 90 90 d->writer->addIndexes(readerArray); 91 delete readerArray;91 delete 92 92 } 93 93 -
trunk/tools/assistant/lib/fulltextsearch/qindexwriter_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qquery.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qquery_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qqueryparser.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qqueryparser_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qreader.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qreader_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qsearchable.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qsearchable_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qsort.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** … … 85 85 for (int i = 0; i < fieldNames.count(); ++i) 86 86 delete [] nameArray[i]; 87 delete nameArray;87 delete nameArray; 88 88 } 89 89 -
trunk/tools/assistant/lib/fulltextsearch/qsort_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** … … 65 65 { 66 66 public: 67 68 69 QCLuceneSort(const QString &field, bool reverse = false);67 QCLuceneSort(); 68 QCLuceneSort(const QStringList &fieldNames); 69 QCLuceneSort(const QString &field, bool reverse = false); 70 70 71 71 virtual ~QCLuceneSort(); … … 73 73 QString toString() const; 74 74 void setSort(const QStringList &fieldNames); 75 75 void setSort(const QString &field, bool reverse = false); 76 76 77 77 protected: -
trunk/tools/assistant/lib/fulltextsearch/qterm.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qterm_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qtoken.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qtoken_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qtokenizer.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qtokenizer_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qtokenstream.cpp
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/fulltextsearch/qtokenstream_p.h
r651 r846 4 4 ** All rights reserved. 5 5 ** 6 ** Portion Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).6 ** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 7 7 ** All rights reserved. 8 8 ** -
trunk/tools/assistant/lib/lib.pro
r561 r846 24 24 QtXml 25 25 LIBS_PRIVATE += -l$$qclucene 26 27 26 RESOURCES += helpsystem.qrc 28 27 SOURCES += qhelpenginecore.cpp \ … … 42 41 qhelpsearchindexreader_default.cpp \ 43 42 qhelpsearchindexreader.cpp \ 43 44 44 qhelp_global.cpp 45 45 … … 64 64 qhelpsearchindexwriter_default_p.h \ 65 65 qhelpsearchindexreader_default_p.h \ 66 qhelpsearchindexreader_p.h 66 qhelpsearchindexreader_p.h \ 67 qclucenefieldnames_p.h 67 68 68 69 # access to clucene -
trunk/tools/assistant/lib/qhelp_global.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 40 40 ****************************************************************************/ 41 41 42 42 43 #include <QtCore/QRegExp> 43 44 #include <QtCore/QMutexLocker> … … 56 57 57 58 return QString::fromLatin1("%1-%2-%3"). 58 arg(name).arg( long(pointer)).arg(counter);59 arg(name).arg((pointer)).arg(counter); 59 60 } 60 61 61 62 QString QHelpGlobal::documentTitle(const QString &content) 62 63 { 63 QString title = Q Object::tr("Untitled");64 QString title = Q"Untitled"); 64 65 if (!content.isEmpty()) { 65 66 int start = content.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7; … … 87 88 QString QHelpGlobal::codecFromHtmlData(const QByteArray &data) 88 89 { 89 QString content = QString::fromUtf8(data.constData(), data.size());90 int start = content.indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive);90 QString )); 91 int start = .indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive); 91 92 if (start > 0) { 92 int end;93 93 QRegExp r(QLatin1String("charset=([^\"\\s]+)")); 94 94 while (start != -1) { 95 end = content.indexOf(QLatin1Char('>'), start) + 1; 96 const QString &meta = content.mid(start, end - start).toLower(); 95 const int end = head.indexOf(QLatin1Char('>'), start) + 1; 96 if (end <= start) 97 break; 98 const QString &meta = head.mid(start, end - start).toLower(); 97 99 if (r.indexIn(meta) != -1) 98 100 return r.cap(1); 99 start = content.indexOf(QLatin1String("<meta"), end,101 start = .indexOf(QLatin1String("<meta"), end, 100 102 Qt::CaseInsensitive); 101 103 } … … 106 108 QString QHelpGlobal::codecFromXmlData(const QByteArray &data) 107 109 { 108 QString content = QString::fromUtf8(data.constData(), data.size());110 QString )); 109 111 const QRegExp encodingExp(QLatin1String("^\\s*<\\?xml version=" 110 112 "\"\\d\\.\\d\" encoding=\"([^\"]+)\"\\?>.*")); 111 return encodingExp.exactMatch( content) ? encodingExp.cap(1) : QString();113 return encodingExp.exactMatch() ? encodingExp.cap(1) : QString(); 112 114 } -
trunk/tools/assistant/lib/qhelp_global.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpcollectionhandler.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 115 115 } 116 116 117 118 119 117 120 m_query.exec(QLatin1String("SELECT COUNT(*) FROM sqlite_master WHERE TYPE=\'table\'" 118 121 "AND Name=\'NamespaceTable\'")); … … 163 166 return false; 164 167 } 168 169 170 165 171 166 172 if (!createTables(copyQuery)) { … … 309 315 m_query.bindValue(0, filterName); 310 316 m_query.exec(); 311 while (m_query.next()) {317 312 318 nameId = m_query.value(0).toInt(); 313 break;314 }315 319 316 320 m_query.exec(QLatin1String("SELECT Id, Name FROM FilterAttributeTable")); … … 585 589 586 590 QSqlQuery query(db); 591 592 587 593 db.exec(QLatin1String("CREATE INDEX IF NOT EXISTS NameIndex ON IndexTable(Name)")); 588 594 db.exec(QLatin1String("CREATE INDEX IF NOT EXISTS FileNameIndex ON FileNameTable(Name)")); -
trunk/tools/assistant/lib/qhelpcollectionhandler_p.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 77 77 typedef QList<DocInfo> DocInfoList; 78 78 79 QHelpCollectionHandler(const QString &collectionFile, QObject *parent = 0); 79 explicit QHelpCollectionHandler(const QString &collectionFile, 80 QObject *parent = 0); 80 81 ~QHelpCollectionHandler(); 81 82 -
trunk/tools/assistant/lib/qhelpcontentwidget.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 371 371 d->rootItem = 0; 372 372 } 373 reset(); 373 if (!onShutDown) 374 reset(); 374 375 } 375 376 -
trunk/tools/assistant/lib/qhelpcontentwidget.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpdatainterface.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpdatainterface_p.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpdbreader.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 206 206 "AND c.Name=? AND c.NamespaceId=d.Id AND d.Name=?")); 207 207 m_query->bindValue(0, filePath); 208 m_query->bindValue(1, Q Latin1String("./") + filePath);208 m_query->bindValue(1, Q); 209 209 m_query->bindValue(2, virtualFolder); 210 210 m_query->bindValue(3, m_namespace); -
trunk/tools/assistant/lib/qhelpdbreader_p.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpengine.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 76 76 QHelpEngineCorePrivate::init(collectionFile, helpEngineCore); 77 77 78 contentModel = new QHelpContentModel(this); 79 indexModel = new QHelpIndexModel(this); 80 81 connect(helpEngineCore, SIGNAL(setupFinished()), 82 this, SLOT(applyCurrentFilter())); 83 connect(helpEngineCore, SIGNAL(currentFilterChanged(QString)), 84 this, SLOT(applyCurrentFilter())); 85 78 if (!contentModel) 79 contentModel = new QHelpContentModel(this); 80 if (!indexModel) 81 indexModel = new QHelpIndexModel(this); 82 83 connect(helpEngineCore, SIGNAL(setupFinished()), this, 84 SLOT(applyCurrentFilter())); 85 connect(helpEngineCore, SIGNAL(currentFilterChanged(QString)), this, 86 SLOT(applyCurrentFilter())); 86 87 } 87 88 -
trunk/tools/assistant/lib/qhelpengine.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 63 63 64 64 public: 65 QHelpEngine(const QString &collectionFile, QObject *parent = 0);65 QHelpEngine(const QString &collectionFile, QObject *parent = 0); 66 66 ~QHelpEngine(); 67 67 -
trunk/tools/assistant/lib/qhelpengine_p.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpenginecore.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 120 120 QHelpGlobal::uniquifyConnectionName(info.fileName, this), this); 121 121 if (!reader->init()) { 122 emit q->warning( tr("Cannot open documentation file %1: %2!")122 emit q->warning(tr("Cannot open documentation file %1: %2!") 123 123 .arg(absFileName, reader->errorMessage())); 124 124 continue; … … 407 407 /*! 408 408 Adds the new custom filter \a filterName. The filter attributes 409 are specified by \a attributes. The function returns false if 410 the filter can not be added, e.g. when the filter already exists. 409 are specified by \a attributes. If the filter already exists, 410 its attribute set is replaced. The function returns true if 411 the operation succeeded, otherwise it returns false. 411 412 412 413 \sa customFilters(), removeCustomFilter() … … 706 707 707 708 /*! 708 Returns a description of the last error that occur ed.709 Returns a description of the last error that occured. 709 710 */ 710 711 QString QHelpEngineCore::error() const -
trunk/tools/assistant/lib/qhelpenginecore.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 66 66 67 67 public: 68 QHelpEngineCore(const QString &collectionFile, QObject *parent = 0);68 QHelpEngineCore(const QString &collectionFile, QObject *parent = 0); 69 69 virtual ~QHelpEngineCore(); 70 70 -
trunk/tools/assistant/lib/qhelpgenerator.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 48 48 #include <QtCore/QDir> 49 49 #include <QtCore/QDebug> 50 50 51 #include <QtCore/QVariant> 51 52 #include <QtCore/QDateTime> … … 190 191 return false; 191 192 } 193 194 195 192 196 193 197 addProgress(1.0); … … 538 542 539 543 int fileId = -1; 540 if (!d->fileMap.contains(fileName)) { 544 QMap<QString, int>::Iterator fileMapIt = d->fileMap.find(fileName); 545 if (fileMapIt == d->fileMap.end()) { 541 546 fileDataList.append(qCompress(data)); 542 547 … … 552 557 ++tableFileId; 553 558 } else { 554 fileId = d->fileMap.value(fileName); 559 fileId = fileMapIt.value(); 560 QSet<int> &fileFilterSet = d->fileFilterMap[fileId]; 561 QSet<int> &tmpFileFilterSet = tmpFileFilterMap[fileId]; 555 562 foreach (const int &filter, filterAtts) { 556 if (! d->fileFilterMap.value(fileId).contains(filter)557 && !tmpFileFilter Map.value(fileId).contains(filter)) {558 d->fileFilterMap[fileId].insert(filter);559 tmpFileFilterMap[fileId].insert(filter);563 if (!.contains(filter) 564 && !tmpFileFilter.contains(filter)) { 565 .insert(filter); 566 .insert(filter); 560 567 } 561 568 } … … 563 570 } 564 571 565 if ( tmpFileFilterMap.count()) {572 if (()) { 566 573 d->query->exec(QLatin1String("BEGIN")); 567 574 QMap<int, QSet<int> >::const_iterator it = tmpFileFilterMap.constBegin(); … … 626 633 attributeMap.insert(d->query->value(1).toString(), 627 634 d->query->value(0).toInt()); 628 if (idsToInsert.contains(d->query->value(1).toString())) 629 idsToInsert.removeAll(d->query->value(1).toString()); 635 idsToInsert.removeAll(d->query->value(1).toString()); 630 636 } 631 637 … … 675 681 } 676 682 677 bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords,683 bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords, 678 684 const QStringList &filterAttributes) 679 685 { … … 705 711 int i = 0; 706 712 d->query->exec(QLatin1String("BEGIN")); 713 707 714 foreach (const QHelpDataIndexItem &itm, keywords) { 715 716 717 718 719 720 721 722 723 724 708 725 pos = itm.reference.indexOf(QLatin1Char('#')); 709 726 fileName = itm.reference.left(pos); … … 717 734 fName = fName.mid(2); 718 735 719 if (d->fileMap.contains(fName)) 720 fileId = d->fileMap.value(fName); 736 QMap<QString, int>::ConstIterator it = d->fileMap.find(fName); 737 if (it != d->fileMap.end()) 738 fileId = it.value(); 721 739 else 722 740 fileId = 1; … … 750 768 751 769 d->query->exec(QLatin1String("SELECT COUNT(Id) FROM IndexTable")); 752 if (d->query->next() && d->query->value(0).toInt() >= keywords.count())770 if (d->query->next() && d->query->value(0).toInt() >= s.count()) 753 771 return true; 754 772 return false; … … 825 843 } 826 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 827 908 QT_END_NAMESPACE 909 -
trunk/tools/assistant/lib/qhelpgenerator_p.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 75 75 bool generate(QHelpDataInterface *helpData, 76 76 const QString &outputFileName); 77 77 78 QString error() const; 78 79 … … 97 98 bool registerVirtualFolder(const QString &folderName, const QString &ns); 98 99 bool insertFilterAttributes(const QStringList &attributes); 99 bool insertKeywords(const QList<QHelpDataIndexItem> keywords,100 bool insertKeywords(const QList<QHelpDataIndexItem> keywords, 100 101 const QStringList &filterAttributes); 101 102 bool insertFiles(const QStringList &files, const QString &rootPath, -
trunk/tools/assistant/lib/qhelpindexwidget.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 245 245 d->indexProvider->stopCollecting(); 246 246 d->indices.clear(); 247 filter(QString()); 247 if (!onShutDown) 248 filter(QString()); 248 249 } 249 250 -
trunk/tools/assistant/lib/qhelpindexwidget.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpprojectdata.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 42 42 #include "qhelpprojectdata_p.h" 43 43 44 44 45 #include <QtCore/QDir> 45 46 #include <QtCore/QFileInfo> … … 47 48 #include <QtCore/QMap> 48 49 #include <QtCore/QRegExp> 50 49 51 #include <QtCore/QVariant> 50 52 #include <QtXml/QXmlStreamReader> … … 77 79 void raiseUnknownTokenError(); 78 80 void addMatchingFiles(const QString &pattern); 81 79 82 80 83 QMap<QString, QStringList> dirEntriesCache; … … 83 86 void QHelpProjectDataPrivate::raiseUnknownTokenError() 84 87 { 85 raiseError(Q Object::tr("Unknown token."));88 raiseError(Q"Unknown token.")); 86 89 } 87 90 … … 96 99 readProject(); 97 100 else 98 raiseError(QObject::tr("Unknown token. Expected \"QtHelpProject\"!")); 101 raiseError(QCoreApplication::translate("QHelpProject", 102 "Unknown token. Expected \"QtHelpProject\"!")); 99 103 } 100 104 } 101 105 102 106 if (hasError()) { 103 raiseError(QObject::tr("Error in line %1: %2").arg(lineNumber()) 107 raiseError(QCoreApplication::translate("QHelpProject", 108 "Error in line %1: %2").arg(lineNumber()) 104 109 .arg(errorString())); 105 110 } … … 113 118 if (name() == QLatin1String("virtualFolder")) { 114 119 virtualFolder = readElementText(); 115 if (virtualFolder.contains(QLatin1String("/"))) 116 raiseError(QObject::tr("A virtual folder must not contain a \'/\' character!")); 120 if (!hasValidSyntax(QLatin1String("test"), virtualFolder)) 121 raiseError(QCoreApplication::translate("QHelpProject", 122 "Virtual folder has invalid syntax.")); 117 123 } else if (name() == QLatin1String("namespace")) { 118 124 namespaceName = readElementText(); 119 if (namespaceName.contains(QLatin1String("/"))) 120 raiseError(QObject::tr("A namespace must not contain a \'/\' character!")); 125 if (!hasValidSyntax(namespaceName, QLatin1String("test"))) 126 raiseError(QCoreApplication::translate("QHelpProject", 127 "Namespace has invalid syntax.")); 121 128 } else if (name() == QLatin1String("customFilter")) { 122 129 readCustomFilter(); … … 126 133 QString n = attributes().value(QLatin1String("name")).toString(); 127 134 if (!metaData.contains(n)) 128 metaData[n] = attributes().value(QLatin1String("value")).toString(); 135 metaData[n] 136 = attributes().value(QLatin1String("value")).toString(); 129 137 else 130 metaData.insert(n, attributes().value(QLatin1String("value")).toString()); 138 metaData.insert(n, attributes(). 139 value(QLatin1String("value")).toString()); 131 140 } else { 132 141 raiseUnknownTokenError(); … … 134 143 } else if (isEndElement() && name() == QLatin1String("QtHelpProject")) { 135 144 if (namespaceName.isEmpty()) 136 raiseError(QObject::tr("Missing namespace in QtHelpProject.")); 145 raiseError(QCoreApplication::translate("QHelpProject", 146 "Missing namespace in QtHelpProject.")); 137 147 else if (virtualFolder.isEmpty()) 138 raiseError(QObject::tr("Missing virtual folder in QtHelpProject")); 148 raiseError(QCoreApplication::translate("QHelpProject", 149 "Missing virtual folder in QtHelpProject")); 139 150 break; 140 151 } … … 224 235 || (attributes().value(QLatin1String("name")).toString().isEmpty() 225 236 && attributes().value(QLatin1String("id")).toString().isEmpty())) 226 raiseError(QObject::tr("Missing attribute in keyword at line %1.") 227 .arg(lineNumber())); 228 filterSectionList.last().addIndex( 229 QHelpDataIndexItem(attributes().value(QLatin1String("name")).toString(), 230 attributes().value(QLatin1String("id")).toString(), 231 attributes().value(QLatin1String("ref")).toString())); 237 raiseError(QCoreApplication::translate("QHelpProject", 238 "Missing attribute in keyword at line %1.") 239 .arg(lineNumber())); 240 filterSectionList.last() 241 .addIndex(QHelpDataIndexItem(attributes(). 242 value(QLatin1String("name")).toString(), 243 attributes().value(QLatin1String("id")).toString(), 244 attributes().value(QLatin1String("ref")).toString())); 232 245 } else { 233 246 raiseUnknownTokenError(); … … 306 319 } 307 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 308 339 /*! 309 340 \internal … … 347 378 QFile file(fileName); 348 379 if (!file.open(QIODevice::ReadOnly)) { 349 d->errorMsg = Q Object::tr("The input file %1 could not be opened!")350 .arg(fileName);380 d->errorMsg = Q 381 .arg(fileName); 351 382 return false; 352 383 } -
trunk/tools/assistant/lib/qhelpprojectdata_p.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchengine.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 264 264 265 265 After starting the indexing process the signal indexingStarted() is emitted and 266 on the end of the indexing process the indexingFinished() is emit ed. To stop266 on the end of the indexing process the indexingFinished() is emited. To stop 267 267 the indexing one can call cancelIndexing(). 268 268 … … 270 270 thru its index for a given term. To do this one may use the possibility of creating the 271 271 QHelpSearchQuery list by self or reuse the QHelpSearchQueryWidget which has the inbuild 272 functionality to set up a proper search quer ys list that get's passed to the search engines272 functionality to set up a proper search quers list that get's passed to the search engines 273 273 search() function. 274 274 275 275 After the list of querys has been passed to the search engine, the signal searchingStarted() 276 is emit ed and after the search has finished the searchingFinished() signal is emited. The276 is emitted. The 277 277 search process can be stopped by calling cancelSearching(). 278 278 … … 319 319 The QHelpEngine's setupFinished() signal is automatically connected to the 320 320 QHelpSearchEngine's indexing function, so that new documentation will be indexed 321 after the signal is emit ed.321 after the signal is emited. 322 322 */ 323 323 QHelpSearchEngine::QHelpSearchEngine(QHelpEngineCore *helpEngine, QObject *parent) … … 435 435 436 436 /*! 437 Starts the search process using the given list of quer ys \a queryList437 Starts the search process using the given list of quers \a queryList 438 438 build by the search field name and the values to search for. 439 439 */ -
trunk/tools/assistant/lib/qhelpsearchengine.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 81 81 82 82 public: 83 QHelpSearchEngine(QHelpEngineCore *helpEngine, QObject *parent = 0); 83 explicit QHelpSearchEngine(QHelpEngineCore *helpEngine, 84 QObject *parent = 0); 84 85 ~QHelpSearchEngine(); 85 86 -
trunk/tools/assistant/lib/qhelpsearchindex_default.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchindex_default_p.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchindexreader.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 40 40 ****************************************************************************/ 41 41 42 43 44 45 42 46 #include "qhelpenginecore.h" 43 #include "fulltextsearch/qsearchable_p.h" 44 #include "fulltextsearch/qqueryparser_p.h" 45 #include "fulltextsearch/qindexreader_p.h" 47 46 48 #include "qhelpsearchindexreader_clucene_p.h" 47 49 … … 50 52 #include <QtCore/QString> 51 53 #include <QtCore/QFileInfo> 54 52 55 #include <QtCore/QStringList> 53 56 #include <QtCore/QTextStream> … … 108 111 try { 109 112 #endif 110 QCLuceneBooleanQuery booleanQuery; 113 QCLuceneBooleanQuery booleanQueryTitle; 114 QCLuceneBooleanQuery booleanQueryContent; 111 115 QCLuceneStandardAnalyzer analyzer; 112 if (!buildQuery(booleanQuery, queryList, analyzer)) { 116 const QStringList& attribList = 117 engine.filterAttributes(engine.currentFilter()); 118 bool titleQueryIsValid = buildQuery(queryList, TitleTokenizedField, 119 attribList, booleanQueryTitle, analyzer); 120 bool contentQueryIsValid = buildQuery(queryList, ContentField, 121 attribList, booleanQueryContent, analyzer); 122 if (!titleQueryIsValid && !contentQueryIsValid) { 113 123 emit searchingFinished(0); 114 124 return; 115 125 } 116 126 117 const QStringList attribList = engine.filterAttributes(engine.currentFilter()); 118 if (!attribList.isEmpty()) { 119 QCLuceneQuery* query = QCLuceneQueryParser::parse(QLatin1String("+") 120 + attribList.join(QLatin1String(" +")), QLatin1String("attribute"), analyzer); 121 122 if (!query) { 127 QCLuceneIndexSearcher indexSearcher(indexPath); 128 129 // QCLuceneHits object must be allocated on the heap, because 130 // there is no default constructor. 131 QSharedPointer<QCLuceneHits> titleHits; 132 QSharedPointer<QCLuceneHits> contentHits; 133 if (titleQueryIsValid) { 134 titleHits = QSharedPointer<QCLuceneHits>(new QCLuceneHits( 135 indexSearcher.search(booleanQueryTitle))); 136 } 137 if (contentQueryIsValid) { 138 contentHits = QSharedPointer<QCLuceneHits>(new QCLuceneHits( 139 indexSearcher.search(booleanQueryContent))); 140 } 141 bool boost = true; 142 if ((titleHits.isNull() || titleHits->length() == 0) 143 && (contentHits.isNull() || contentHits->length() == 0)) { 144 booleanQueryTitle = QCLuceneBooleanQuery(); 145 booleanQueryContent = QCLuceneBooleanQuery(); 146 titleQueryIsValid = 147 buildTryHarderQuery(queryList, TitleTokenizedField, 148 attribList, booleanQueryTitle, analyzer); 149 contentQueryIsValid = 150 buildTryHarderQuery(queryList, ContentField, attribList, 151 booleanQueryContent, analyzer); 152 if (!titleQueryIsValid && !contentQueryIsValid) { 123 153 emit searchingFinished(0); 124 154 return; 125 155 } 126 booleanQuery.add(query, true, true, false); 127 } 128 129 QCLuceneIndexSearcher indexSearcher(indexPath); 130 QCLuceneHits hits = indexSearcher.search(booleanQuery); 131 132 bool boost = true; 133 QCLuceneBooleanQuery tryHarderQuery; 134 if (hits.length() == 0) { 135 if (buildTryHarderQuery(tryHarderQuery, queryList, analyzer)) { 136 if (!attribList.isEmpty()) { 137 QCLuceneQuery* query = QCLuceneQueryParser::parse(QLatin1String("+") 138 + attribList.join(QLatin1String(" +")), QLatin1String("attribute"), 139 analyzer); 140 tryHarderQuery.add(query, true, true, false); 141 } 142 hits = indexSearcher.search(tryHarderQuery); 143 boost = (hits.length() == 0); 156 if (titleQueryIsValid) { 157 titleHits = QSharedPointer<QCLuceneHits>(new QCLuceneHits( 158 indexSearcher.search(booleanQueryTitle))); 144 159 } 145 } 160 if (contentQueryIsValid) { 161 contentHits = QSharedPointer<QCLuceneHits>(new QCLuceneHits( 162 indexSearcher.search(booleanQueryContent))); 163 } 164 boost = false; 165 } 166 QList<QSharedPointer<QCLuceneHits> > cluceneHitsList; 167 if (!titleHits.isNull()) 168 cluceneHitsList.append(titleHits); 169 if (!contentHits.isNull()) 170 cluceneHitsList.append(contentHits); 146 171 147 172 QSet<QString> pathSet; … … 149 174 const QStringList namespaceList = engine.registeredDocumentations(); 150 175 151 for (qint32 i = 0; i < hits.length(); i++) { 152 document = hits.document(i); 153 const QString path = document.get(QLatin1String("path")); 154 if (!pathSet.contains(path) && namespaceList.contains( 155 document.get(QLatin1String("namespace")), Qt::CaseInsensitive)) { 156 pathSet.insert(path); 157 hitList.append(qMakePair(path, document.get(QLatin1String("title")))); 176 foreach (const QSharedPointer<QCLuceneHits> &hits, cluceneHitsList) { 177 for (qint32 i = 0; i < hits->length(); i++) { 178 document = hits->document(i); 179 const QString path = document.get(PathField); 180 if (!pathSet.contains(path) && namespaceList.contains( 181 document.get(NamespaceField), Qt::CaseInsensitive)) { 182 pathSet.insert(path); 183 hitList.append(qMakePair(path, document.get(TitleField))); 184 } 185 document.clear(); 186 187 mutex.lock(); 188 if (m_cancel) { 189 mutex.unlock(); 190 emit searchingFinished(0); 191 return; 192 } 193 mutex.unlock(); 158 194 } 159 document.clear();160 161 mutex.lock();162 if (m_cancel) {163 mutex.unlock();164 emit searchingFinished(0);165 return;166 }167 mutex.unlock();168 195 } 169 196 … … 185 212 } 186 213 187 bool QHelpSearchIndexReaderClucene::defaultQuery(const QString &term, QCLuceneBooleanQuery &booleanQuery, 188 QCLuceneStandardAnalyzer &analyzer) 189 { 190 const QLatin1String c("content"); 191 const QLatin1String t("titleTokenized"); 192 193 QCLuceneQuery *query = QCLuceneQueryParser::parse(term, c, analyzer); 194 QCLuceneQuery *query2 = QCLuceneQueryParser::parse(term, t, analyzer); 195 if (query && query2) { 196 booleanQuery.add(query, true, false, false); 197 booleanQuery.add(query2, true, false, false); 214 bool QHelpSearchIndexReaderClucene::buildQuery( 215 const QList<QHelpSearchQuery> &queries, const QString &fieldName, 216 const QStringList &filterAttributes, QCLuceneBooleanQuery &booleanQuery, 217 QCLuceneAnalyzer &analyzer) 218 { 219 bool queryIsValid = false; 220 foreach (const QHelpSearchQuery &query, queries) { 221 if (fieldName != ContentField && isNegativeQuery(query)) { 222 queryIsValid = false; 223 break; 224 } 225 switch (query.fieldName) { 226 case QHelpSearchQuery::FUZZY: 227 if (addFuzzyQuery(query, fieldName, booleanQuery, analyzer)) 228 queryIsValid = true; 229 break; 230 case QHelpSearchQuery::WITHOUT: 231 if (fieldName != ContentField) 232 return false; 233 if (addWithoutQuery(query, fieldName, booleanQuery)) 234 queryIsValid = true; 235 break; 236 case QHelpSearchQuery::PHRASE: 237 if (addPhraseQuery(query, fieldName, booleanQuery)) 238 queryIsValid = true; 239 break; 240 case QHelpSearchQuery::ALL: 241 if (addAllQuery(query, fieldName, booleanQuery)) 242 queryIsValid = true; 243 break; 244 case QHelpSearchQuery::DEFAULT: 245 if (addDefaultQuery(query, fieldName, true, booleanQuery, analyzer)) 246 queryIsValid = true; 247 break; 248 case QHelpSearchQuery::ATLEAST: 249 if (addAtLeastQuery(query, fieldName, booleanQuery, analyzer)) 250 queryIsValid = true; 251 break; 252 default: 253 Q_ASSERT(!"Invalid field name"); 254 } 255 } 256 257 if (queryIsValid && !filterAttributes.isEmpty()) { 258 queryIsValid = 259 addAttributesQuery(filterAttributes, booleanQuery, analyzer); 260 } 261 262 return queryIsValid; 263 } 264 265 bool QHelpSearchIndexReaderClucene::buildTryHarderQuery( 266 const QList<QHelpSearchQuery> &queries, const QString &fieldName, 267 const QStringList &filterAttributes, QCLuceneBooleanQuery &booleanQuery, 268 QCLuceneAnalyzer &analyzer) 269 { 270 if (queries.isEmpty()) 271 return false; 272 const QHelpSearchQuery &query = queries.front(); 273 if (query.fieldName != QHelpSearchQuery::DEFAULT) 274 return false; 275 if (isNegativeQuery(query)) 276 return false; 277 if (!addDefaultQuery(query, fieldName, false, booleanQuery, analyzer)) 278 return false; 279 if (filterAttributes.isEmpty()) 198 280 return true; 199 } 200 201 return false; 202 } 203 204 bool QHelpSearchIndexReaderClucene::buildQuery(QCLuceneBooleanQuery &booleanQuery, 205 const QList<QHelpSearchQuery> &queryList, QCLuceneStandardAnalyzer &analyzer) 206 { 207 foreach (const QHelpSearchQuery query, queryList) { 208 switch (query.fieldName) { 209 case QHelpSearchQuery::FUZZY: { 210 const QLatin1String fuzzy("~"); 211 foreach (const QString &term, query.wordList) { 212 if (term.isEmpty() 213 || !defaultQuery(term.toLower() + fuzzy, booleanQuery, analyzer)) { 214 return false; 215 } 216 } 217 } break; 218 219 case QHelpSearchQuery::WITHOUT: { 220 QStringList stopWords = QCLuceneStopAnalyzer().englishStopWords(); 221 foreach (const QString &term, query.wordList) { 222 if (stopWords.contains(term, Qt::CaseInsensitive)) 223 continue; 224 225 QCLuceneQuery *query = new QCLuceneTermQuery(QCLuceneTerm( 226 QLatin1String("content"), term.toLower())); 227 QCLuceneQuery *query2 = new QCLuceneTermQuery(QCLuceneTerm( 228 QLatin1String("titleTokenized"), term.toLower())); 229 230 if (query && query2) { 231 booleanQuery.add(query, true, false, true); 232 booleanQuery.add(query2, true, false, true); 233 } else { 234 return false; 235 } 236 } 237 } break; 238 239 case QHelpSearchQuery::PHRASE: { 240 const QString &term = query.wordList.at(0).toLower(); 241 if (term.contains(QLatin1Char(' '))) { 242 QStringList termList = term.split(QLatin1String(" ")); 243 QCLucenePhraseQuery *q = new QCLucenePhraseQuery(); 244 QStringList stopWords = QCLuceneStopAnalyzer().englishStopWords(); 245 foreach (const QString &term, termList) { 246 if (!stopWords.contains(term, Qt::CaseInsensitive)) 247 q->addTerm(QCLuceneTerm(QLatin1String("content"), term.toLower())); 248 } 249 booleanQuery.add(q, true, true, false); 250 } else { 251 QCLuceneQuery *query = new QCLuceneTermQuery(QCLuceneTerm( 252 QLatin1String("content"), term.toLower())); 253 QCLuceneQuery *query2 = new QCLuceneTermQuery(QCLuceneTerm( 254 QLatin1String("titleTokenized"), term.toLower())); 255 256 if (query && query2) { 257 booleanQuery.add(query, true, true, false); 258 booleanQuery.add(query2, true, false, false); 259 } else { 260 return false; 261 } 262 } 263 } break; 264 265 case QHelpSearchQuery::ALL: { 266 QStringList stopWords = QCLuceneStopAnalyzer().englishStopWords(); 267 foreach (const QString &term, query.wordList) { 268 if (stopWords.contains(term, Qt::CaseInsensitive)) 269 continue; 270 271 QCLuceneQuery *query = new QCLuceneTermQuery(QCLuceneTerm( 272 QLatin1String("content"), term.toLower())); 273 274 if (query) { 275 booleanQuery.add(query, true, true, false); 276 } else { 277 return false; 278 } 279 } 280 } break; 281 282 case QHelpSearchQuery::DEFAULT: { 283 foreach (const QString &term, query.wordList) { 284 QCLuceneQuery *query = QCLuceneQueryParser::parse(term.toLower(), 285 QLatin1String("content"), analyzer); 286 287 if (query) 288 booleanQuery.add(query, true, true, false); 289 } 290 } break; 291 292 case QHelpSearchQuery::ATLEAST: { 293 foreach (const QString &term, query.wordList) { 294 if (term.isEmpty() || !defaultQuery(term.toLower(), booleanQuery, analyzer)) 295 return false; 296 } 297 } 298 } 299 } 300 281 return addAttributesQuery(filterAttributes, booleanQuery, analyzer); 282 } 283 284 bool QHelpSearchIndexReaderClucene::isNegativeQuery(const QHelpSearchQuery &query) const 285 { 286 const QString &search = query.wordList.join(" "); 287 return search.contains('!') || search.contains('-') 288 || search.contains(QLatin1String(" NOT ")); 289 } 290 291 bool QHelpSearchIndexReaderClucene::addFuzzyQuery(const QHelpSearchQuery &query, 292 const QString &fieldName, QCLuceneBooleanQuery &booleanQuery, 293 QCLuceneAnalyzer &analyzer) 294 { 295 bool queryIsValid = false; 296 const QLatin1String fuzzy("~"); 297 foreach (const QString &term, query.wordList) { 298 if (!term.isEmpty()) { 299 QCLuceneQuery *lQuery = 300 QCLuceneQueryParser::parse(term + fuzzy, fieldName, analyzer); 301 if (lQuery != 0) { 302 booleanQuery.add(lQuery, true, false, false); 303 queryIsValid = true; 304 } 305 } 306 } 307 return queryIsValid; 308 } 309 310 bool QHelpSearchIndexReaderClucene::addWithoutQuery(const QHelpSearchQuery &query, 311 const QString &fieldName, QCLuceneBooleanQuery &booleanQuery) 312 { 313 bool queryIsValid = false; 314 const QStringList &stopWords = QCLuceneStopAnalyzer().englishStopWords(); 315 foreach (const QString &term, query.wordList) { 316 if (stopWords.contains(term, Qt::CaseInsensitive)) 317 continue; 318 QCLuceneQuery *lQuery = new QCLuceneTermQuery(QCLuceneTerm( 319 fieldName, term.toLower())); 320 booleanQuery.add(lQuery, true, false, true); 321 queryIsValid = true; 322 } 323 return queryIsValid; 324 } 325 326 bool QHelpSearchIndexReaderClucene::addPhraseQuery(const QHelpSearchQuery &query, 327 const QString &fieldName, QCLuceneBooleanQuery &booleanQuery) 328 { 329 bool queryIsValid = false; 330 const QString &term = query.wordList.at(0).toLower(); 331 if (term.contains(QLatin1Char(' '))) { 332 const QStringList termList = term.split(QLatin1String(" ")); 333 QCLucenePhraseQuery *q = new QCLucenePhraseQuery(); 334 const QStringList stopWords = QCLuceneStopAnalyzer().englishStopWords(); 335 foreach (const QString &term, termList) { 336 if (!stopWords.contains(term, Qt::CaseInsensitive)) 337 q->addTerm(QCLuceneTerm(fieldName, term.toLower())); 338 } 339 if (!q->getTerms().isEmpty()) { 340 booleanQuery.add(q, true, true, false); 341 queryIsValid = true; 342 } 343 } else { 344 QCLuceneQuery *lQuery = new QCLuceneTermQuery(QCLuceneTerm( 345 fieldName, term.toLower())); 346 booleanQuery.add(lQuery, true, true, false); 347 queryIsValid = true; 348 } 349 return queryIsValid; 350 } 351 352 bool QHelpSearchIndexReaderClucene::addAllQuery(const QHelpSearchQuery &query, 353 const QString &fieldName, QCLuceneBooleanQuery &booleanQuery) 354 { 355 bool queryIsValid = false; 356 const QStringList &stopWords = QCLuceneStopAnalyzer().englishStopWords(); 357 foreach (const QString &term, query.wordList) { 358 if (stopWords.contains(term, Qt::CaseInsensitive)) 359 continue; 360 QCLuceneQuery *lQuery = new QCLuceneTermQuery(QCLuceneTerm( 361 fieldName, term.toLower())); 362 booleanQuery.add(lQuery, true, true, false); 363 queryIsValid = true; 364 } 365 return queryIsValid; 366 } 367 368 bool QHelpSearchIndexReaderClucene::addDefaultQuery(const QHelpSearchQuery &query, 369 const QString &fieldName, bool allTermsRequired, 370 QCLuceneBooleanQuery &booleanQuery, 371 QCLuceneAnalyzer &analyzer) 372 { 373 bool queryIsValid = false; 374 foreach (const QString &term, query.wordList) { 375 QCLuceneQuery *lQuery = 376 QCLuceneQueryParser::parse(term.toLower(), fieldName, analyzer); 377 if (lQuery) { 378 booleanQuery.add(lQuery, true, allTermsRequired, false); 379 queryIsValid = true; 380 } 381 } 382 return queryIsValid; 383 } 384 385 bool QHelpSearchIndexReaderClucene::addAtLeastQuery( 386 const QHelpSearchQuery &query, const QString &fieldName, 387 QCLuceneBooleanQuery &booleanQuery, QCLuceneAnalyzer &analyzer) 388 { 389 bool queryIsValid = false; 390 foreach (const QString &term, query.wordList) { 391 if (!term.isEmpty()) { 392 QCLuceneQuery *lQuery = 393 QCLuceneQueryParser::parse(term, fieldName, analyzer); 394 if (lQuery) { 395 booleanQuery.add(lQuery, true, false, false); 396 queryIsValid = true; 397 } 398 } 399 } 400 return queryIsValid; 401 } 402 403 bool QHelpSearchIndexReaderClucene::addAttributesQuery( 404 const QStringList &filterAttributes, QCLuceneBooleanQuery &booleanQuery, 405 QCLuceneAnalyzer &analyzer) 406 { 407 QCLuceneQuery* lQuery = QCLuceneQueryParser::parse(QLatin1String("+") 408 + filterAttributes.join(QLatin1String(" +")), AttributeField, analyzer); 409 if (!lQuery) 410 return false; 411 booleanQuery.add(lQuery, true, true, false); 301 412 return true; 302 }303 304 bool QHelpSearchIndexReaderClucene::buildTryHarderQuery(QCLuceneBooleanQuery &booleanQuery,305 const QList<QHelpSearchQuery> &queryList, QCLuceneStandardAnalyzer &analyzer)306 {307 bool retVal = false;308 foreach (const QHelpSearchQuery query, queryList) {309 switch (query.fieldName) {310 default: break;311 case QHelpSearchQuery::DEFAULT: {312 foreach (const QString &term, query.wordList) {313 QCLuceneQuery *query = QCLuceneQueryParser::parse(term.toLower(),314 QLatin1String("content"), analyzer);315 316 if (query) {317 retVal = true;318 booleanQuery.add(query, true, false, false);319 }320 }321 } break;322 }323 }324 return retVal;325 413 } 326 414 … … 328 416 QList<QHelpSearchEngine::SearchHit> &hitList, const QList<QHelpSearchQuery> &queryList) 329 417 { 330 foreach (const QHelpSearchQuery query, queryList) {418 foreach (const QHelpSearchQuery query, queryList) { 331 419 if (query.fieldName != QHelpSearchQuery::DEFAULT) 332 420 continue; … … 336 424 QCLuceneStandardAnalyzer analyzer; 337 425 QCLuceneQuery *parsedQuery = QCLuceneQueryParser::parse( 338 joinedQuery, QLatin1String("content"), analyzer);426 joinedQuery, , analyzer); 339 427 340 428 if (parsedQuery) { … … 343 431 } 344 432 345 int length = QString(QLatin1String("content:")).length(); 346 int index = joinedQuery.indexOf(QLatin1String("content:")); 433 const QString contentString(ContentField + QLatin1String(":")); 434 int length = contentString.length(); 435 int index = joinedQuery.indexOf(contentString); 347 436 348 437 QString term; … … 350 439 QStringList searchTerms; 351 440 while (index != -1) { 352 nextIndex = joinedQuery.indexOf( QLatin1String("content:"), index + 1);441 nextIndex = joinedQuery.indexOf(, index + 1); 353 442 term = joinedQuery.mid(index + length, nextIndex - (length + index)).simplified(); 354 443 if (term.startsWith(QLatin1String("\"")) -
trunk/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 54 54 // 55 55 56 #include "qhelpsearchindexreader_p.h" 56 #include <QtCore/QList> 57 #include <QtCore/QString> 58 #include <QtCore/QStringList> 57 59 58 60 #include "fulltextsearch/qanalyzer_p.h" 59 61 #include "fulltextsearch/qquery_p.h" 62 60 63 61 64 QT_BEGIN_NAMESPACE … … 74 77 private: 75 78 void run(); 76 bool defaultQuery(const QString &term, QCLuceneBooleanQuery &booleanQuery,77 QCLuceneStandardAnalyzer &analyzer);78 bool buildQuery(QCLuceneBooleanQuery &booleanQuery, const QList<QHelpSearchQuery> &queryList,79 QCLuceneStandardAnalyzer &analyzer);80 bool buildTryHarderQuery(QCLuceneBooleanQuery &booleanQuery,81 const QList<QHelpSearchQuery> &queryList, QCLuceneStandardAnalyzer &analyzer);82 79 void boostSearchHits(const QHelpEngineCore &engine, QList<QHelpSearchEngine::SearchHit> &hitList, 83 80 const QList<QHelpSearchQuery> &queryList); 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 84 107 }; 85 108 -
trunk/tools/assistant/lib/qhelpsearchindexreader_default.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchindexreader_default_p.h
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 61 61 62 62 QT_BEGIN_NAMESPACE 63 64 struct Entry;65 struct PosEntry;66 63 67 64 namespace fulltextsearch { -
trunk/tools/assistant/lib/qhelpsearchindexreader_p.h
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 40 40 ****************************************************************************/ 41 41 42 42 43 #include "qhelpenginecore.h" 43 44 #include "qhelp_global.h" … … 407 408 408 409 if(!parsedData.isEmpty()) { 409 document->add(new QCLuceneField( QLatin1String("content"),410 document->add(new QCLuceneField(, 410 411 parsedData,QCLuceneField::INDEX_TOKENIZED)); 411 document->add(new QCLuceneField( QLatin1String("path"), fileName,412 document->add(new QCLuceneField(, fileName, 412 413 QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED)); 413 document->add(new QCLuceneField( QLatin1String("title"), parsedTitle,414 document->add(new QCLuceneField(, parsedTitle, 414 415 QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED)); 415 document->add(new QCLuceneField( QLatin1String("titleTokenized"), parsedTitle,416 document->add(new QCLuceneField(, parsedTitle, 416 417 QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED)); 417 document->add(new QCLuceneField( QLatin1String("namespace"), namespaceName,418 document->add(new QCLuceneField(, namespaceName, 418 419 QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED)); 419 document->add(new QCLuceneField( QLatin1String("attribute"), attributes,420 document->add(new QCLuceneField(, attributes, 420 421 QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED)); 421 422 return true; … … 716 717 if (indexMap.contains(namespaceName)) { 717 718 // make sure we really have content indexed for namespace 718 // NOTE: Extra variable just for GCC 3.3.5 719 QLatin1String key("namespace"); 720 QCLuceneTermQuery query(QCLuceneTerm(key, namespaceName)); 719 QCLuceneTermQuery query(QCLuceneTerm(NamespaceField, namespaceName)); 721 720 QCLuceneIndexSearcher indexSearcher(indexPath); 722 721 QCLuceneHits hits = indexSearcher.search(query); … … 852 851 853 852 QCLuceneIndexReader reader = QCLuceneIndexReader::open(indexPath); 854 reader.deleteDocuments(QCLuceneTerm(QLatin1String("namespace"), 855 namespaceName)); 853 reader.deleteDocuments(QCLuceneTerm(NamespaceField, namespaceName)); 856 854 857 855 reader.close(); -
trunk/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchindexwriter_default.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchindexwriter_default_p.h
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchquerywidget.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 42 42 #include "qhelpsearchquerywidget.h" 43 43 44 #include <QtCore/QDebug>45 46 44 #include <QtCore/QAbstractListModel> 47 45 #include <QtCore/QObject> … … 102 100 103 101 QHelpSearchQueryWidgetPrivate() 104 : QObject(), simpleSearch(true), 105 searchCompleter(new CompleterModel(this), this) 102 : QObject() 103 , simpleSearch(true) 104 , searchCompleter(new CompleterModel(this), this) 106 105 { 107 106 searchButton = 0; … … 135 134 atLeastLabel->setText(QHelpSearchQueryWidget::tr("with <B>at least one</B> of the words:")); 136 135 #endif 137 }138 139 QString escapeString(const QString &text)140 {141 QString retValue = text;142 const QString escape(QLatin1String("\\"));143 QStringList escapableCharsList;144 escapableCharsList << QLatin1String("\\") << QLatin1String("+")145 << QLatin1String("-") << QLatin1String("!") << QLatin1String("(")146 << QLatin1String(")") << QLatin1String(":") << QLatin1String("^")147 << QLatin1String("[") << QLatin1String("]") << QLatin1String("{")148 << QLatin1String("}") << QLatin1String("~");149 150 // make sure we won't end up with an empty string151 foreach (const QString &escapeChar, escapableCharsList) {152 if (retValue.contains(escapeChar))153 retValue.replace(escapeChar, QLatin1String(""));154 }155 if (retValue.trimmed().isEmpty())156 return retValue;157 158 retValue = text; // now really escape the string...159 foreach (const QString &escapeChar, escapableCharsList) {160 if (retValue.contains(escapeChar))161 retValue.replace(escapeChar, escape + escapeChar);162 }163 return retValue;164 136 } 165 137 … … 223 195 } 224 196 225 void nextOrPrevQuery(int maxOrMinIndex, int addend, 226 QToolButton *thisButton,QToolButton *otherButton)197 void nextOrPrevQuery(int maxOrMinIndex, int addend, 198 QToolButton *otherButton) 227 199 { 228 200 QueryHistory *queryHist; … … 234 206 queryHist = &complexQueries; 235 207 lineEdits << allQuery << atLeastQuery << similarQuery 236 208 << withoutQuery << exactQuery; 237 209 } 238 210 foreach (QLineEdit *lineEdit, lineEdits) … … 279 251 void enableOrDisableToolButtons() 280 252 { 281 const QueryHistory &queryHist = 282 simpleSearch ? simpleQueries: complexQueries;253 const QueryHistory &queryHist = 254 : complexQueries; 283 255 prevQueryButton->setEnabled(queryHist.curQuery > 0); 284 nextQueryButton->setEnabled(queryHist.curQuery <285 256 nextQueryButton->setEnabled(queryHist.curQuery 257 queryHist.queries.size() - 1); 286 258 } 287 259 … … 307 279 #if !defined(QT_CLUCENE_SUPPORT) 308 280 queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, 309 281 QStringList(defaultQuery->text()))); 310 282 311 283 #else 312 284 if (defaultQuery->isEnabled()) { 313 285 queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT, 314 buildTermList(escapeString(defaultQuery->text()))));286 )))); 315 287 } else { 316 288 const QRegExp exp(QLatin1String("\\s+")); 317 QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts); 289 QStringList lst = similarQuery->text().split(exp, 290 QString::SkipEmptyParts); 318 291 if (!lst.isEmpty()) { 319 292 QStringList fuzzy; 320 293 foreach (const QString &term, lst) 321 fuzzy += buildTermList(escapeString(term)); 322 queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy)); 294 fuzzy += buildTermList(term); 295 queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, 296 fuzzy)); 323 297 } 324 298 … … 327 301 QStringList without; 328 302 foreach (const QString &term, lst) 329 without.append(escapeString(term)); 330 queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without)); 303 without.append(term); 304 queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, 305 without)); 331 306 } 332 307 333 308 if (!exactQuery->text().isEmpty()) { 334 309 QString phrase = exactQuery->text().remove(QLatin1Char('\"')); 335 phrase = escapeString(phrase.simplified()); 336 queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, QStringList(phrase))); 310 phrase = phrase.simplified(); 311 queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, 312 QStringList(phrase))); 337 313 } 338 314 … … 341 317 QStringList all; 342 318 foreach (const QString &term, lst) 343 all.append( escapeString(term));319 all.append(); 344 320 queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all)); 345 321 } … … 349 325 QStringList atLeast; 350 326 foreach (const QString &term, lst) 351 atLeast += buildTermList(escapeString(term)); 352 queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, atLeast)); 327 atLeast += buildTermList(term); 328 queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, 329 atLeast)); 353 330 } 354 331 } … … 364 341 void nextQuery() 365 342 { 366 nextOrPrevQuery((simpleSearch ? simpleQueries : complexQueries).queries.size() - 1, 367 1, nextQueryButton, prevQueryButton); 343 nextOrPrevQuery((simpleSearch ? simpleQueries 344 : complexQueries).queries.size() - 1, 1, nextQueryButton, 345 prevQueryButton); 368 346 } 369 347 … … 416 394 417 395 This signal is emitted when a the user has the search button invoked. 418 After reciving the signal you can ask the QHelpSearchQueryWidget for the build list 419 of QHelpSearchQuery's that you may pass to the QHelpSearchEngine's search() function. 396 After reciving the signal you can ask the QHelpSearchQueryWidget for the 397 build list of QHelpSearchQuery's that you may pass to the QHelpSearchEngine's 398 search() function. 420 399 */ 421 400 … … 545 524 } 546 525 547 /*! \reimp 526 /*! 527 \reimp 548 528 */ 549 529 void QHelpSearchQueryWidget::focusInEvent(QFocusEvent *focusEvent) -
trunk/tools/assistant/lib/qhelpsearchquerywidget.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/lib/qhelpsearchresultwidget.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 305 305 } 306 306 } 307 hitsLabel->setText( tr("%1 - %2 of %3 Hits").arg(first).arg(last).arg(count));307 hitsLabel->setText(t)); 308 308 } 309 309 -
trunk/tools/assistant/lib/qhelpsearchresultwidget.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/assistant/aboutdialog.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 42 41 43 42 44 #include <QtCore/QBuffer> … … 57 59 : QTextBrowser(parent) 58 60 { 61 59 62 setFrameStyle(QFrame::NoFrame); 60 63 QPalette p; … … 65 68 void AboutLabel::setText(const QString &text, const QByteArray &resources) 66 69 { 70 67 71 QDataStream in(resources); 68 72 in >> m_resourceMap; 69 73 70 74 QTextBrowser::setText(text); 71 75 } … … 73 77 QSize AboutLabel::minimumSizeHint() const 74 78 { 79 75 80 QTextDocument *doc = document(); 76 81 doc->adjustSize(); … … 80 85 QVariant AboutLabel::loadResource(int type, const QUrl &name) 81 86 { 87 82 88 if (type == 2 || type == 3) { 83 89 if (m_resourceMap.contains(name.toString())) { … … 90 96 void AboutLabel::setSource(const QUrl &url) 91 97 { 92 if (url.isValid()93 && (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("ftp")94 || url.scheme() == QLatin1String("mailto") || url.path().endsWith(QLatin1String("pdf")))) {98 99 100 )))) { 95 101 if (!QDesktopServices::openUrl(url)) { 96 102 QMessageBox::warning(this, tr("Warning"), 97 tr("Unable to launch external application.\n"), 98 tr("OK")); 103 tr("Unable to launch external application.\n"), tr("OK")); 99 104 } 100 105 } … … 102 107 103 108 AboutDialog::AboutDialog(QWidget *parent) 104 : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint|Qt::WindowTitleHint|Qt::WindowSystemMenuHint) 109 : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint | 110 Qt::WindowTitleHint|Qt::WindowSystemMenuHint) 105 111 { 112 106 113 m_pixmapLabel = 0; 107 114 m_aboutLabel = new AboutLabel(); 108 115 109 116 m_closeButton = new QPushButton(); 110 117 m_closeButton->setText(tr("&Close")); 111 connect(m_closeButton, SIGNAL(clicked()), 112 this, SLOT(close())); 118 connect(m_closeButton, SIGNAL(clicked()), this, SLOT(close())); 113 119 114 120 m_layout = new QGridLayout(this); 115 121 m_layout->addWidget(m_aboutLabel, 1, 0, 1, -1); 116 m_layout->addItem(new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1, 1, 1); 122 m_layout->addItem(new QSpacerItem(20, 10, QSizePolicy::Minimum, 123 QSizePolicy::Fixed), 2, 1, 1, 1); 117 124 m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 0, 1, 1); 118 125 m_layout->addWidget(m_closeButton, 3, 1, 1, 1); 119 m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 2, 1, 1); 126 m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 2, 1, 1); 120 127 } 121 128 122 129 void AboutDialog::setText(const QString &text, const QByteArray &resources) 123 130 { 131 124 132 m_aboutLabel->setText(text, resources); 125 133 updateSize(); … … 128 136 void AboutDialog::setPixmap(const QPixmap &pixmap) 129 137 { 138 130 139 if (!m_pixmapLabel) { 131 140 m_pixmapLabel = new QLabel(); … … 138 147 QString AboutDialog::documentTitle() const 139 148 { 149 140 150 return m_aboutLabel->documentTitle(); 141 151 } … … 143 153 void AboutDialog::updateSize() 144 154 { 145 QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size(); 155 TRACE_OBJ 156 QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()) 157 .size(); 146 158 int limit = qMin(screenSize.width()/2, 500); 147 159 … … 155 167 if (width > limit) 156 168 width = limit; 157 169 158 170 QFontMetrics fm(qApp->font("QWorkspaceTitleBar")); 159 171 int windowTitleWidth = qMin(fm.width(windowTitle()) + 50, limit); … … 163 175 layout()->activate(); 164 176 int height = (layout()->hasHeightForWidth()) 165 166 177 ? layout()->totalHeightForWidth(width) 178 : layout()->totalMinimumSize().height(); 167 179 setFixedSize(width, height); 168 180 QCoreApplication::removePostedEvents(this, QEvent::LayoutRequest); -
trunk/tools/assistant/tools/assistant/aboutdialog.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/assistant/assistant.pro
r647 r846 1 include($$QT_SOURCE_TREE/tools/shared/fontpanel/fontpanel.pri) 2 1 include(../../../shared/fontpanel/fontpanel.pri) 3 2 TEMPLATE = app 4 3 LANGUAGE = C++ 5 4 TARGET = assistant 5 6 7 8 9 10 11 12 13 14 6 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 7 44 contains(QT_CONFIG, webkit) { 8 QT += webkit 45 HEADERS += helpviewer_qwv.h 46 } else { 47 HEADERS += helpviewer_qtb.h 48 } 49 win32|os2:HEADERS += remotecontrol_win.h 50 51 SOURCES += aboutdialog.cpp \ 52 bookmarkdialog.cpp \ 53 bookmarkfiltermodel.cpp \ 54 bookmarkitem.cpp \ 55 bookmarkmanager.cpp \ 56 bookmarkmanagerwidget.cpp \ 57 bookmarkmodel.cpp \ 58 centralwidget.cpp \ 59 cmdlineparser.cpp \ 60 contentwindow.cpp \ 61 findwidget.cpp \ 62 filternamedialog.cpp \ 63 helpenginewrapper.cpp \ 64 helpviewer.cpp \ 65 indexwindow.cpp \ 66 installdialog.cpp \ 67 main.cpp \ 68 mainwindow.cpp \ 69 preferencesdialog.cpp \ 70 qtdocinstaller.cpp \ 71 remotecontrol.cpp \ 72 searchwidget.cpp \ 73 topicchooser.cpp \ 74 xbelsupport.cpp \ 75 ../shared/collectionconfiguration.cpp 76 contains(QT_CONFIG, webkit) { 77 SOURCES += helpviewer_qwv.cpp 78 } else { 79 SOURCES += helpviewer_qtb.cpp 9 80 } 10 81 11 CONFIG += qt warn_on help 82 FORMS += bookmarkdialog.ui \ 83 bookmarkmanagerwidget.ui \ 84 bookmarkwidget.ui \ 85 filternamedialog.ui \ 86 installdialog.ui \ 87 preferencesdialog.ui \ 88 topicchooser.ui 12 89 13 QT += network 14 15 PROJECTNAME = Assistant 16 DESTDIR = ../../../../bin 17 18 target.path=$$[QT_INSTALL_BINS] 19 INSTALLS += target 20 21 ### Work around a qmake issue when statically linking to 22 ### not-yet-installed plugins 23 LIBS += -L$$QT_BUILD_TREE/plugins/sqldrivers 24 25 HEADERS += helpviewer.h \ 26 mainwindow.h \ 27 indexwindow.h \ 28 topicchooser.h \ 29 contentwindow.h \ 30 searchwidget.h \ 31 preferencesdialog.h \ 32 filternamedialog.h \ 33 centralwidget.h \ 34 installdialog.h \ 35 bookmarkmanager.h \ 36 remotecontrol.h \ 37 cmdlineparser.h \ 38 aboutdialog.h \ 39 qtdocinstaller.h 40 41 win32|os2 { 42 HEADERS += remotecontrol_win.h 43 } 44 45 SOURCES += helpviewer.cpp \ 46 main.cpp \ 47 mainwindow.cpp \ 48 indexwindow.cpp \ 49 topicchooser.cpp \ 50 contentwindow.cpp \ 51 searchwidget.cpp \ 52 preferencesdialog.cpp \ 53 filternamedialog.cpp \ 54 centralwidget.cpp \ 55 installdialog.cpp \ 56 bookmarkmanager.cpp \ 57 remotecontrol.cpp \ 58 cmdlineparser.cpp \ 59 aboutdialog.cpp \ 60 qtdocinstaller.cpp 61 62 FORMS += topicchooser.ui \ 63 preferencesdialog.ui \ 64 filternamedialog.ui \ 65 installdialog.ui \ 66 bookmarkdialog.ui 67 68 RESOURCES += assistant.qrc assistant_images.qrc 90 RESOURCES += assistant.qrc \ 91 assistant_images.qrc 69 92 70 93 win32 { -
trunk/tools/assistant/tools/assistant/assistant.rc
r651 r846 19 19 VALUE "FileDescription", "Qt Assistant" 20 20 VALUE "FileVersion", "1.0.0.0" 21 VALUE "LegalCopyright", "Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies)."21 VALUE "LegalCopyright", "Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies)." 22 22 VALUE "InternalName", "assistant.exe" 23 23 VALUE "OriginalFilename", "assistant.exe" -
trunk/tools/assistant/tools/assistant/assistant_images.qrc
r2 r846 5 5 <file>images/assistant.png</file> 6 6 <file>images/wrap.png</file> 7 7 8 #mac 8 9 <file>images/mac/addtab.png</file> -
trunk/tools/assistant/tools/assistant/bookmarkdialog.ui
r2 r846 1 <ui version="4.0" > 1 <?xml version="1.0" encoding="UTF-8"?> 2 <ui version="4.0"> 2 3 <class>BookmarkDialog</class> 3 <widget class="QDialog" name="BookmarkDialog" 4 <property name="geometry" 4 <widget class="QDialog" name="BookmarkDialog"> 5 <property name="geometry"> 5 6 <rect> 6 7 <x>0</x> 7 8 <y>0</y> 8 9 <width>450</width> 9 <height>13 5</height>10 <height>13</height> 10 11 </rect> 11 12 </property> 12 <property name="sizePolicy" 13 <sizepolicy vsizetype="Preferred" hsizetype="Preferred">13 <property name="sizePolicy"> 14 <sizepolicy > 14 15 <horstretch>0</horstretch> 15 16 <verstretch>0</verstretch> 16 17 </sizepolicy> 17 18 </property> 18 <property name="windowTitle" 19 <property name="windowTitle"> 19 20 <string>Add Bookmark</string> 20 21 </property> 21 <layout class="QVBoxLayout" name="verticalLayout_3" 22 <layout class="QVBoxLayout" name="verticalLayout_3"> 22 23 <item> 23 <layout class="QHBoxLayout" name="horizontalLayout" 24 <layout class="QHBoxLayout" name="horizontalLayout"> 24 25 <item> 25 <layout class="QVBoxLayout" name="verticalLayout_2" 26 <layout class="QVBoxLayout" name="verticalLayout_2"> 26 27 <item> 27 <widget class="QLabel" name="label" 28 <property name="text" 28 <widget class="QLabel" name="label"> 29 <property name="text"> 29 30 <string>Bookmark:</string> 30 31 </property> … … 32 33 </item> 33 34 <item> 34 <widget class="QLabel" name="label_2" 35 <property name="text" 35 <widget class="QLabel" name="label_2"> 36 <property name="text"> 36 37 <string>Add in Folder:</string> 37 38 </property> … … 41 42 </item> 42 43 <item> 43 <layout class="QVBoxLayout" name="verticalLayout" 44 <layout class="QVBoxLayout" name="verticalLayout"> 44 45 <item> 45 <widget class="QLineEdit" name="bookmarkEdit" 46 <widget class="QLineEdit" name="bookmarkEdit"/> 46 47 </item> 47 48 <item> 48 <widget class="QComboBox" name="bookmarkFolders" 49 <widget class="QComboBox" name="bookmarkFolders"/> 49 50 </item> 50 51 </layout> … … 53 54 </item> 54 55 <item> 55 <layout class="QHBoxLayout" name="horizontalLayout_3" 56 <layout class="QHBoxLayout" name="horizontalLayout_3"> 56 57 <item> 57 <widget class="QToolButton" name="toolButton" 58 <property name="minimumSize" 58 <widget class="QToolButton" name="toolButton"> 59 <property name="minimumSize"> 59 60 <size> 60 61 <width>25</width> … … 62 63 </size> 63 64 </property> 64 <property name="text" 65 <property name="text"> 65 66 <string>+</string> 66 67 </property> … … 68 69 </item> 69 70 <item> 70 <widget class="Line" name="line" 71 <property name="orientation" 71 <widget class="Line" name="line"> 72 <property name="orientation"> 72 73 <enum>Qt::Horizontal</enum> 73 74 </property> … … 77 78 </item> 78 79 <item> 79 <widget class="QTreeView" name="treeView" 80 <property name="sizePolicy" 81 <sizepolicy vsizetype="Ignored" hsizetype="Expanding">80 <widget class="QTreeView" name="treeView"> 81 <property name="sizePolicy"> 82 <sizepolicy > 82 83 <horstretch>0</horstretch> 83 84 <verstretch>0</verstretch> 84 85 </sizepolicy> 85 86 </property> 87 88 89 90 91 92 93 94 95 86 96 </widget> 87 97 </item> 88 98 <item> 89 <layout class="QHBoxLayout" name="horizontalLayout_4" 99 <layout class="QHBoxLayout" name="horizontalLayout_4"> 90 100 <item> 91 <widget class="QPushButton" name="newFolderButton" 92 <property name="text" 101 <widget class="QPushButton" name="newFolderButton"> 102 <property name="text"> 93 103 <string>New Folder</string> 94 104 </property> … … 96 106 </item> 97 107 <item> 98 <widget class="QDialogButtonBox" name="buttonBox" 99 <property name="orientation" 108 <widget class="QDialogButtonBox" name="buttonBox"> 109 <property name="orientation"> 100 110 <enum>Qt::Horizontal</enum> 101 111 </property> 102 <property name="standardButtons" 112 <property name="standardButtons"> 103 113 <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> 104 114 </property> … … 117 127 <slot>accept()</slot> 118 128 <hints> 119 <hint type="sourcelabel" 129 <hint type="sourcelabel"> 120 130 <x>248</x> 121 131 <y>254</y> 122 132 </hint> 123 <hint type="destinationlabel" 133 <hint type="destinationlabel"> 124 134 <x>157</x> 125 135 <y>274</y> … … 133 143 <slot>reject()</slot> 134 144 <hints> 135 <hint type="sourcelabel" 145 <hint type="sourcelabel"> 136 146 <x>316</x> 137 147 <y>260</y> 138 148 </hint> 139 <hint type="destinationlabel" 149 <hint type="destinationlabel"> 140 150 <x>286</x> 141 151 <y>274</y> -
trunk/tools/assistant/tools/assistant/bookmarkmanager.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "bookmarkmanager.h" 44 45 46 47 48 43 49 #include "centralwidget.h" 50 44 51 45 52 #include <QtGui/QMenu> 46 #include <QtGui/QIcon>47 #include <QtGui/QStyle>48 #include <QtGui/QLabel>49 #include <QtGui/QLayout>50 #include <QtCore/QEvent>51 #include <QtGui/QComboBox>52 53 #include <QtGui/QKeyEvent> 53 #include <QtGui/QLineEdit>54 54 #include <QtGui/QMessageBox> 55 #include <QtGui/QHeaderView>56 #include <QtGui/QToolButton>57 #include <QtGui/QPushButton>58 #include <QtGui/QApplication>59 #include <QtHelp/QHelpEngineCore>60 #include <QtGui/QDialogButtonBox>61 55 #include <QtGui/QSortFilterProxyModel> 62 56 63 57 QT_BEGIN_NAMESPACE 64 58 65 BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title, 66 const QString &url, QWidget *parent) 67 : QDialog(parent) 68 , m_url(url) 69 , m_title(title) 70 , bookmarkManager(manager) 71 { 72 ui.setupUi(this); 73 74 installEventFilter(this); 75 ui.treeView->installEventFilter(this); 76 ui.treeView->viewport()->installEventFilter(this); 77 78 ui.bookmarkEdit->setText(title); 79 ui.newFolderButton->setVisible(false); 80 ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); 81 ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); 82 83 proxyModel = new QSortFilterProxyModel(this); 84 proxyModel->setFilterKeyColumn(0); 85 proxyModel->setDynamicSortFilter(true); 86 proxyModel->setFilterRole(Qt::UserRole + 10); 87 proxyModel->setSourceModel(bookmarkManager->treeBookmarkModel()); 88 proxyModel->setFilterRegExp(QRegExp(QLatin1String("Folder"), 89 Qt::CaseSensitive, QRegExp::FixedString)); 90 ui.treeView->setModel(proxyModel); 91 92 ui.treeView->expandAll(); 93 ui.treeView->setVisible(false); 94 ui.treeView->header()->setVisible(false); 95 ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu); 96 97 connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 98 connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(addAccepted())); 99 connect(ui.newFolderButton, SIGNAL(clicked()), this, SLOT(addNewFolder())); 100 connect(ui.toolButton, SIGNAL(clicked()), this, SLOT(toolButtonClicked())); 101 connect(ui.bookmarkEdit, SIGNAL(textChanged(QString)), this, 59 // -- BookmarkManager::BookmarkWidget 60 61 void BookmarkManager::BookmarkWidget::focusInEvent(QFocusEvent *event) 62 { 63 TRACE_OBJ 64 if (event->reason() != Qt::MouseFocusReason) { 65 ui.lineEdit->selectAll(); 66 ui.lineEdit->setFocus(); 67 68 // force the focus in event on bookmark manager 69 emit focusInEvent(); 70 } 71 } 72 73 // -- BookmarkManager::BookmarkTreeView 74 75 BookmarkManager::BookmarkTreeView::BookmarkTreeView(QWidget *parent) 76 : QTreeView(parent) 77 { 78 TRACE_OBJ 79 setAcceptDrops(true); 80 setDragEnabled(true); 81 setAutoExpandDelay(1000); 82 setUniformRowHeights(true); 83 setDropIndicatorShown(true); 84 setExpandsOnDoubleClick(true); 85 86 connect(this, SIGNAL(expanded(QModelIndex)), this, 87 SLOT(setExpandedData(QModelIndex))); 88 connect(this, SIGNAL(collapsed(QModelIndex)), this, 89 SLOT(setExpandedData(QModelIndex))); 90 91 } 92 93 void BookmarkManager::BookmarkTreeView::subclassKeyPressEvent(QKeyEvent *event) 94 { 95 TRACE_OBJ 96 QTreeView::keyPressEvent(event); 97 } 98 99 void BookmarkManager::BookmarkTreeView::setExpandedData(const QModelIndex &index) 100 { 101 TRACE_OBJ 102 if (BookmarkModel *treeModel = qobject_cast<BookmarkModel*> (model())) 103 treeModel->setData(index, isExpanded(index), UserRoleExpanded); 104 } 105 106 // -- BookmarkManager 107 108 QMutex BookmarkManager::mutex; 109 BookmarkManager* BookmarkManager::bookmarkManager = 0; 110 111 // -- public 112 113 BookmarkManager* BookmarkManager::instance() 114 { 115 TRACE_OBJ 116 if (!bookmarkManager) { 117 QMutexLocker _(&mutex); 118 if (!bookmarkManager) 119 bookmarkManager = new BookmarkManager(); 120 } 121 return bookmarkManager; 122 } 123 124 void BookmarkManager::destroy() 125 { 126 TRACE_OBJ 127 delete bookmarkManager; 128 bookmarkManager = 0; 129 } 130 131 QWidget* BookmarkManager::bookmarkDockWidget() const 132 { 133 TRACE_OBJ 134 if (bookmarkWidget) 135 return bookmarkWidget; 136 return 0; 137 } 138 139 void BookmarkManager::takeBookmarksMenu(QMenu* menu) 140 { 141 TRACE_OBJ 142 bookmarkMenu = menu; 143 refeshBookmarkMenu(); 144 } 145 146 // -- public slots 147 148 void BookmarkManager::addBookmark(const QString &title, const QString &url) 149 { 150 TRACE_OBJ 151 showBookmarkDialog(title.isEmpty() ? tr("Untitled") : title, 152 url.isEmpty() ? QLatin1String("about:blank") : url); 153 } 154 155 // -- private 156 157 BookmarkManager::BookmarkManager() 158 : typeAndSearch(false) 159 , bookmarkMenu(0) 160 , bookmarkModel(new BookmarkModel) 161 , bookmarkWidget(new BookmarkWidget) 162 , bookmarkTreeView(new BookmarkTreeView) 163 , bookmarkManagerWidget(0) 164 { 165 TRACE_OBJ 166 bookmarkWidget->installEventFilter(this); 167 connect(bookmarkWidget->ui.add, SIGNAL(clicked()), this, 168 SLOT(addBookmark())); 169 connect(bookmarkWidget->ui.remove, SIGNAL(clicked()), this, 170 SLOT(removeBookmark())); 171 connect(bookmarkWidget->ui.lineEdit, SIGNAL(textChanged(QString)), this, 102 172 SLOT(textChanged(QString))); 103 104 connect(bookmarkManager->treeBookmarkModel(), 105 SIGNAL(itemChanged(QStandardItem*)), 106 this, SLOT(itemChanged(QStandardItem*))); 107 108 connect(ui.bookmarkFolders, SIGNAL(currentIndexChanged(QString)), this, 109 SLOT(selectBookmarkFolder(QString))); 110 111 connect(ui.treeView, SIGNAL(customContextMenuRequested(QPoint)), this, 173 connect(bookmarkWidget, SIGNAL(focusInEvent()), this, SLOT(focusInEvent())); 174 175 bookmarkTreeView->setModel(bookmarkModel); 176 bookmarkTreeView->installEventFilter(this); 177 bookmarkTreeView->viewport()->installEventFilter(this); 178 bookmarkTreeView->setContextMenuPolicy(Qt::CustomContextMenu); 179 bookmarkWidget->ui.stackedWidget->addWidget(bookmarkTreeView); 180 181 connect(bookmarkTreeView, SIGNAL(activated(QModelIndex)), this, 182 SLOT(setSourceFromIndex(QModelIndex))); 183 connect(bookmarkTreeView, SIGNAL(customContextMenuRequested(QPoint)), this, 112 184 SLOT(customContextMenuRequested(QPoint))); 113 185 114 connect(ui.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, 115 QModelIndex)), this, SLOT(currentChanged(QModelIndex))); 116 } 117 118 BookmarkDialog::~BookmarkDialog() 119 { 120 } 121 122 void BookmarkDialog::addAccepted() 123 { 124 QItemSelectionModel *model = ui.treeView->selectionModel(); 125 const QModelIndexList &list = model->selection().indexes(); 126 127 QModelIndex index; 128 if (!list.isEmpty()) 129 index = proxyModel->mapToSource(list.at(0)); 130 131 bookmarkManager->addNewBookmark(index, ui.bookmarkEdit->text(), m_url); 132 accept(); 133 } 134 135 void BookmarkDialog::addNewFolder() 136 { 137 QItemSelectionModel *model = ui.treeView->selectionModel(); 138 const QModelIndexList &list = model->selection().indexes(); 139 140 QModelIndex index; 141 if (!list.isEmpty()) 142 index = list.at(0); 143 144 QModelIndex newFolder = 145 bookmarkManager->addNewFolder(proxyModel->mapToSource(index)); 146 if (newFolder.isValid()) { 147 ui.treeView->expand(index); 148 const QModelIndex &index = proxyModel->mapFromSource(newFolder); 149 model->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); 150 151 ui.bookmarkFolders->clear(); 152 ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); 153 154 const QString &name = index.data().toString(); 155 ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name)); 156 } 157 ui.treeView->setFocus(); 158 } 159 160 void BookmarkDialog::toolButtonClicked() 161 { 162 bool visible = !ui.treeView->isVisible(); 163 ui.treeView->setVisible(visible); 164 ui.newFolderButton->setVisible(visible); 165 166 if (visible) { 167 resize(QSize(width(), 400)); 168 ui.toolButton->setText(QLatin1String("-")); 169 } else { 170 resize(width(), minimumHeight()); 171 ui.toolButton->setText(QLatin1String("+")); 172 } 173 } 174 175 void BookmarkDialog::itemChanged(QStandardItem *item) 176 { 177 if (renameItem != item) { 178 renameItem = item; 179 oldText = item->text(); 180 return; 181 } 182 183 if (item->text() != oldText) { 184 ui.bookmarkFolders->clear(); 185 ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); 186 187 QString name = tr("Bookmarks"); 188 const QModelIndex &index = ui.treeView->currentIndex(); 189 if (index.isValid()) 190 name = index.data().toString(); 191 ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name)); 192 } 193 } 194 195 void BookmarkDialog::textChanged(const QString &string) 196 { 197 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!string.isEmpty()); 198 } 199 200 void BookmarkDialog::selectBookmarkFolder(const QString &folderName) 201 { 202 if (folderName.isEmpty()) 203 return; 204 205 if (folderName == tr("Bookmarks")) { 206 ui.treeView->clearSelection(); 207 return; 208 } 209 210 QStandardItemModel *model = bookmarkManager->treeBookmarkModel(); 211 QList<QStandardItem*> list = model->findItems(folderName, 212 Qt::MatchCaseSensitive | Qt::MatchRecursive, 0); 213 if (!list.isEmpty()) { 214 const QModelIndex &index = model->indexFromItem(list.at(0)); 215 QItemSelectionModel *model = ui.treeView->selectionModel(); 216 if (model) { 217 model->setCurrentIndex(proxyModel->mapFromSource(index), 218 QItemSelectionModel::ClearAndSelect); 219 } 220 } 221 } 222 223 void BookmarkDialog::customContextMenuRequested(const QPoint &point) 224 { 225 QModelIndex index = ui.treeView->indexAt(point); 226 if (!index.isValid()) 227 return; 228 229 QMenu menu(QLatin1String(""), this); 230 231 QAction *removeItem = menu.addAction(tr("Delete Folder")); 232 QAction *renameItem = menu.addAction(tr("Rename Folder")); 233 234 QAction *picked = menu.exec(ui.treeView->mapToGlobal(point)); 235 if (!picked) 236 return; 237 238 const QModelIndex &proxyIndex = proxyModel->mapToSource(index); 239 if (picked == removeItem) { 240 bookmarkManager->removeBookmarkItem(ui.treeView, proxyIndex); 241 ui.bookmarkFolders->clear(); 242 ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); 243 244 QString name = tr("Bookmarks"); 245 index = ui.treeView->currentIndex(); 246 if (index.isValid()) 247 name = index.data().toString(); 248 ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name)); 249 } 250 else if (picked == renameItem) { 251 BookmarkModel *model = bookmarkManager->treeBookmarkModel(); 252 if (QStandardItem *item = model->itemFromIndex(proxyIndex)) { 253 item->setEditable(true); 254 ui.treeView->edit(index); 255 item->setEditable(false); 256 } 257 } 258 } 259 260 void BookmarkDialog::currentChanged(const QModelIndex ¤t) 261 { 262 QString text = tr("Bookmarks"); 263 if (current.isValid()) 264 text = current.data().toString(); 265 ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(text)); 266 } 267 268 bool BookmarkDialog::eventFilter(QObject *object, QEvent *e) 269 { 270 if (object != ui.treeView && object != ui.treeView->viewport()) 271 return QWidget::eventFilter(object, e); 272 273 if (e->type() == QEvent::KeyPress) { 274 QKeyEvent *ke = static_cast<QKeyEvent*>(e); 186 connect(&HelpEngineWrapper::instance(), SIGNAL(setupFinished()), this, 187 SLOT(setupFinished())); 188 connect(bookmarkModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, 189 SLOT(refeshBookmarkMenu())); 190 connect(bookmarkModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, 191 SLOT(refeshBookmarkMenu())); 192 connect(bookmarkModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, 193 SLOT(refeshBookmarkMenu())); 194 } 195 196 BookmarkManager::~BookmarkManager() 197 { 198 TRACE_OBJ 199 delete bookmarkManagerWidget; 200 HelpEngineWrapper::instance().setBookmarks(bookmarkModel->bookmarks()); 201 delete bookmarkModel; 202 } 203 204 void BookmarkManager::removeItem(const QModelIndex &index) 205 { 206 TRACE_OBJ 207 QModelIndex current = index; 208 if (typeAndSearch) { // need to map because of proxy 209 current = typeAndSearchModel->mapToSource(current); 210 current = bookmarkFilterModel->mapToSource(current); 211 } else if (!bookmarkModel->parent(index).isValid()) { 212 return; // check if we should delete the "Bookmarks Menu", bail 213 } 214 215 if (bookmarkModel->hasChildren(current)) { 216 int value = QMessageBox::question(bookmarkTreeView, tr("Remove"), 217 tr("You are going to delete a Folder, this will also<br>" 218 "remove it's content. Are you sure to continue?"), 219 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); 220 if (value == QMessageBox::Cancel) 221 return; 222 } 223 bookmarkModel->removeItem(current); 224 } 225 226 bool BookmarkManager::eventFilter(QObject *object, QEvent *event) 227 { 228 if (object != bookmarkTreeView && object != bookmarkTreeView->viewport() 229 && object != bookmarkWidget) 230 return QObject::eventFilter(object, event); 231 232 TRACE_OBJ 233 const bool isWidget = object == bookmarkWidget; 234 if (event->type() == QEvent::KeyPress) { 235 QKeyEvent *ke = static_cast<QKeyEvent*>(event); 275 236 switch (ke->key()) { 276 237 case Qt::Key_F2: { 277 const QModelIndex &index = ui.treeView->currentIndex(); 278 const QModelIndex &source = proxyModel->mapToSource(index); 279 QStandardItem *item = 280 bookmarkManager->treeBookmarkModel()->itemFromIndex(source); 281 if (item) { 282 item->setEditable(true); 283 ui.treeView->edit(index); 284 item->setEditable(false); 285 } 238 renameBookmark(bookmarkTreeView->currentIndex()); 286 239 } break; 287 240 288 241 case Qt::Key_Delete: { 289 const QModelIndex &index = ui.treeView->currentIndex(); 290 bookmarkManager->removeBookmarkItem(ui.treeView, 291 proxyModel->mapToSource(index)); 292 ui.bookmarkFolders->clear(); 293 ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders()); 294 295 QString name = tr("Bookmarks"); 296 if (index.isValid()) 297 name = index.data().toString(); 298 ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name)); 299 } break; 300 301 default: 302 break; 242 removeItem(bookmarkTreeView->currentIndex()); 243 return true; 244 } break; 245 246 case Qt::Key_Up: { // needs event filter on widget 247 case Qt::Key_Down: 248 if (isWidget) 249 bookmarkTreeView->subclassKeyPressEvent(ke); 250 } break; 251 252 case Qt::Key_Escape: { 253 emit escapePressed(); 254 } break; 255 256 default: break; 303 257 } 304 258 } 305 259 306 return QObject::eventFilter(object, e); 307 } 308 309 310 // #pragma mark -- BookmarkWidget 311 312 313 BookmarkWidget::BookmarkWidget(BookmarkManager *manager, QWidget *parent, 314 bool showButtons) 315 : QWidget(parent) 316 , addButton(0) 317 , removeButton(0) 318 , bookmarkManager(manager) 319 { 320 setup(showButtons); 321 322 installEventFilter(this); 323 treeView->installEventFilter(this); 324 treeView->viewport()->installEventFilter(this); 325 } 326 327 BookmarkWidget::~BookmarkWidget() 328 { 329 } 330 331 void BookmarkWidget::removeClicked() 332 { 333 const QModelIndex &index = treeView->currentIndex(); 334 if (searchField->text().isEmpty()) { 335 bookmarkManager->removeBookmarkItem(treeView, 336 filterBookmarkModel->mapToSource(index)); 337 } 338 } 339 340 void BookmarkWidget::filterChanged() 341 { 342 bool searchBookmarks = searchField->text().isEmpty(); 343 if (!searchBookmarks) { 344 regExp.setPattern(searchField->text()); 345 filterBookmarkModel->setSourceModel(bookmarkManager->listBookmarkModel()); 260 if (event->type() == QEvent::MouseButtonRelease && !isWidget) { 261 QMouseEvent *me = static_cast<QMouseEvent*>(event); 262 switch (me->button()) { 263 case Qt::LeftButton: { 264 if (me->modifiers() & Qt::ControlModifier) 265 setSourceFromIndex(bookmarkTreeView->currentIndex(), true); 266 } break; 267 268 case Qt::MidButton: { 269 setSourceFromIndex(bookmarkTreeView->currentIndex(), true); 270 } break; 271 272 default: break; 273 } 274 } 275 276 return QObject::eventFilter(object, event); 277 } 278 279 void BookmarkManager::buildBookmarksMenu(const QModelIndex &index, QMenu* menu) 280 { 281 TRACE_OBJ 282 if (!index.isValid()) 283 return; 284 285 const QString &text = index.data().toString(); 286 const QIcon &icon = qVariantValue<QIcon>(index.data(Qt::DecorationRole)); 287 if (index.data(UserRoleFolder).toBool()) { 288 if (QMenu* subMenu = menu->addMenu(icon, text)) { 289 for (int i = 0; i < bookmarkModel->rowCount(index); ++i) 290 buildBookmarksMenu(bookmarkModel->index(i, 0, index), subMenu); 291 } 346 292 } else { 347 regExp.setPattern(QLatin1String("")); 348 filterBookmarkModel->setSourceModel(bookmarkManager->treeBookmarkModel()); 349 } 350 351 if (addButton) 352 addButton->setEnabled(searchBookmarks); 353 354 if (removeButton) 355 removeButton->setEnabled(searchBookmarks); 356 357 filterBookmarkModel->setFilterRegExp(regExp); 358 359 const QModelIndex &index = treeView->indexAt(QPoint(1, 1)); 360 if (index.isValid()) 361 treeView->setCurrentIndex(index); 362 363 if (searchBookmarks) 364 expandItems(); 365 } 366 367 void BookmarkWidget::expand(const QModelIndex &index) 368 { 369 const QModelIndex &source = filterBookmarkModel->mapToSource(index); 370 QStandardItem *item = 371 bookmarkManager->treeBookmarkModel()->itemFromIndex(source); 372 if (item) 373 item->setData(treeView->isExpanded(index), Qt::UserRole + 11); 374 } 375 376 void BookmarkWidget::activated(const QModelIndex &index) 377 { 293 QAction *action = menu->addAction(icon, text); 294 action->setData(index.data(UserRoleUrl).toString()); 295 } 296 } 297 298 void BookmarkManager::showBookmarkDialog(const QString &name, const QString &url) 299 { 300 TRACE_OBJ 301 BookmarkDialog dialog(bookmarkModel, name, url, bookmarkTreeView); 302 dialog.exec(); 303 } 304 305 // -- private slots 306 307 void BookmarkManager::setupFinished() 308 { 309 TRACE_OBJ 310 bookmarkModel->setBookmarks(HelpEngineWrapper::instance().bookmarks()); 311 bookmarkModel->expandFoldersIfNeeeded(bookmarkTreeView); 312 313 refeshBookmarkMenu(); 314 315 bookmarkTreeView->hideColumn(1); 316 bookmarkTreeView->header()->setVisible(false); 317 bookmarkTreeView->header()->setStretchLastSection(true); 318 319 bookmarkFilterModel = new BookmarkFilterModel(this); 320 bookmarkFilterModel->setSourceModel(bookmarkModel); 321 bookmarkFilterModel->filterBookmarkFolders(); 322 323 typeAndSearchModel = new QSortFilterProxyModel(this); 324 typeAndSearchModel->setDynamicSortFilter(true); 325 typeAndSearchModel->setSourceModel(bookmarkFilterModel); 326 } 327 328 void BookmarkManager::addBookmark() 329 { 330 TRACE_OBJ 331 if (CentralWidget *widget = CentralWidget::instance()) 332 addBookmark(widget->currentTitle(), widget->currentSource().toString()); 333 } 334 335 void BookmarkManager::removeBookmark() 336 { 337 TRACE_OBJ 338 removeItem(bookmarkTreeView->currentIndex()); 339 } 340 341 void BookmarkManager::manageBookmarks() 342 { 343 TRACE_OBJ 344 if (bookmarkManagerWidget == 0) { 345 bookmarkManagerWidget = new BookmarkManagerWidget(bookmarkModel); 346 connect(bookmarkManagerWidget, SIGNAL(setSource(QUrl)), this, 347 SIGNAL(setSource(QUrl))); 348 connect(bookmarkManagerWidget, SIGNAL(setSourceInNewTab(QUrl)) 349 , this, SIGNAL(setSourceInNewTab(QUrl))); 350 connect(bookmarkManagerWidget, SIGNAL(managerWidgetAboutToClose()) 351 , this, SLOT(managerWidgetAboutToClose())); 352 } 353 bookmarkManagerWidget->show(); 354 bookmarkManagerWidget->raise(); 355 } 356 357 void BookmarkManager::refeshBookmarkMenu() 358 { 359 TRACE_OBJ 360 if (!bookmarkMenu) 361 return; 362 363 bookmarkMenu->clear(); 364 365 bookmarkMenu->addAction(tr("Manage Bookmarks..."), this, 366 SLOT(manageBookmarks())); 367 bookmarkMenu->addAction(QIcon::fromTheme("bookmark-new"), 368 tr("Add Bookmark..."), this, SLOT(addBookmark()), 369 QKeySequence(tr("Ctrl+D"))); 370 bookmarkMenu->addSeparator(); 371 372 const QModelIndex &root = bookmarkModel->index(0, 0, QModelIndex()); 373 for (int i = 0; i < bookmarkModel->rowCount(root); ++i) 374 buildBookmarksMenu(bookmarkModel->index(i, 0, root), bookmarkMenu); 375 376 connect(bookmarkMenu, SIGNAL(triggered(QAction*)), this, 377 SLOT(setSourceFromAction(QAction*))); 378 } 379 380 void BookmarkManager::renameBookmark(const QModelIndex &index) 381 { 382 // check if we should rename the "Bookmarks Menu", bail 383 if (!typeAndSearch && !bookmarkModel->parent(index).isValid()) 384 return; 385 386 bookmarkModel->setItemsEditable(true); 387 bookmarkTreeView->edit(index); 388 bookmarkModel->setItemsEditable(false); 389 } 390 391 void BookmarkManager::setSourceFromAction(QAction *action) 392 { 393 TRACE_OBJ 394 const QVariant &data = action->data(); 395 396 if (data.canConvert<QUrl>()) 397 emit setSource(data.toUrl()); 398 } 399 400 void BookmarkManager::setSourceFromIndex(const QModelIndex &index, bool newTab) 401 { 402 TRACE_OBJ 403 QAbstractItemModel *base = bookmarkModel; 404 if (typeAndSearch) 405 base = typeAndSearchModel; 406 407 if (base->data(index, UserRoleFolder).toBool()) 408 return; 409 410 const QVariant &data = base->data(index, UserRoleUrl); 411 if (data.canConvert<QUrl>()) { 412 if (newTab) 413 emit setSourceInNewTab(data.toUrl()); 414 else 415 emit setSource(data.toUrl()); 416 } 417 } 418 419 void BookmarkManager::customContextMenuRequested(const QPoint &point) 420 { 421 TRACE_OBJ 422 QModelIndex index = bookmarkTreeView->indexAt(point); 378 423 if (!index.isValid()) 379 424 return; 380 425 381 QString data = index.data(Qt::UserRole + 10).toString(); 382 if (data != QLatin1String("Folder")) 383 emit requestShowLink(data); 384 } 385 386 void BookmarkWidget::customContextMenuRequested(const QPoint &point) 387 { 388 QModelIndex index = treeView->indexAt(point); 389 if (!index.isValid()) 390 return; 391 426 // check if we should open the menu on "Bookmarks Menu", bail 427 if (!typeAndSearch && !bookmarkModel->parent(index).isValid()) 428 return; 429 430 QAction *remove = 0; 431 QAction *rename = 0; 392 432 QAction *showItem = 0; 393 QAction *removeItem = 0; 394 QAction *renameItem = 0; 395 QAction *showItemNewTab = 0; 396 397 QMenu menu(QLatin1String(""), this); 398 QString data = index.data(Qt::UserRole + 10).toString(); 399 if (data == QLatin1String("Folder")) { 400 removeItem = menu.addAction(tr("Delete Folder")); 401 renameItem = menu.addAction(tr("Rename Folder")); 433 QAction *showItemInNewTab = 0; 434 435 QMenu menu(QLatin1String("")); 436 if (!typeAndSearch && bookmarkModel->data(index, UserRoleFolder).toBool()) { 437 remove = menu.addAction(tr("Delete Folder")); 438 rename = menu.addAction(tr("Rename Folder")); 402 439 } else { 403 440 showItem = menu.addAction(tr("Show Bookmark")); 404 showItemNewTab = menu.addAction(tr("Show Bookmark in New Tab")); 405 if (searchField->text().isEmpty()) { 406 menu.addSeparator(); 407 removeItem = menu.addAction(tr("Delete Bookmark")); 408 renameItem = menu.addAction(tr("Rename Bookmark")); 441 showItemInNewTab = menu.addAction(tr("Show Bookmark in New Tab")); 442 menu.addSeparator(); 443 remove = menu.addAction(tr("Delete Bookmark")); 444 rename = menu.addAction(tr("Rename Bookmark")); 445 } 446 447 QAction *pickedAction = menu.exec(bookmarkTreeView->mapToGlobal(point)); 448 if (pickedAction == rename) 449 renameBookmark(index); 450 else if (pickedAction == remove) 451 removeItem(index); 452 else if (pickedAction == showItem || pickedAction == showItemInNewTab) 453 setSourceFromIndex(index, pickedAction == showItemInNewTab); 454 } 455 456 void BookmarkManager::focusInEvent() 457 { 458 TRACE_OBJ 459 const QModelIndex &index = bookmarkTreeView->indexAt(QPoint(2, 2)); 460 if (index.isValid()) 461 bookmarkTreeView->setCurrentIndex(index); 462 } 463 464 void BookmarkManager::managerWidgetAboutToClose() 465 { 466 delete bookmarkManagerWidget; 467 bookmarkManagerWidget = 0; 468 } 469 470 void BookmarkManager::textChanged(const QString &text) 471 { 472 TRACE_OBJ 473 if (!bookmarkWidget->ui.lineEdit->text().isEmpty()) { 474 if (!typeAndSearch) { 475 typeAndSearch = true; 476 bookmarkTreeView->setItemsExpandable(false); 477 bookmarkTreeView->setRootIsDecorated(false); 478 bookmarkTreeView->setModel(typeAndSearchModel); 409 479 } 410 } 411 412 QAction *pickedAction = menu.exec(treeView->mapToGlobal(point)); 413 if (!pickedAction) 414 return; 415 416 if (pickedAction == showItem) { 417 emit requestShowLink(data); 418 } 419 else if (pickedAction == showItemNewTab) { 420 CentralWidget::instance()->setSourceInNewTab(data); 421 } 422 else if (pickedAction == removeItem) { 423 bookmarkManager->removeBookmarkItem(treeView, 424 filterBookmarkModel->mapToSource(index)); 425 } 426 else if (pickedAction == renameItem) { 427 const QModelIndex &source = filterBookmarkModel->mapToSource(index); 428 QStandardItem *item = 429 bookmarkManager->treeBookmarkModel()->itemFromIndex(source); 430 if (item) { 431 item->setEditable(true); 432 treeView->edit(index); 433 item->setEditable(false); 434 } 435 } 436 } 437 438 void BookmarkWidget::setup(bool showButtons) 439 { 440 regExp.setPatternSyntax(QRegExp::FixedString); 441 regExp.setCaseSensitivity(Qt::CaseInsensitive); 442 443 QLayout *vlayout = new QVBoxLayout(this); 444 vlayout->setMargin(4); 445 446 QLabel *label = new QLabel(tr("Filter:"), this); 447 vlayout->addWidget(label); 448 449 searchField = new QLineEdit(this); 450 vlayout->addWidget(searchField); 451 connect(searchField, SIGNAL(textChanged(QString)), this, 452 SLOT(filterChanged())); 453 454 treeView = new TreeView(this); 455 vlayout->addWidget(treeView); 456 457 #ifdef Q_OS_MAC 458 # define SYSTEM "mac" 459 #else 460 # define SYSTEM "win" 461 #endif 462 463 if (showButtons) { 464 QLayout *hlayout = new QHBoxLayout(); 465 vlayout->addItem(hlayout); 466 467 hlayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); 468 469 addButton = new QToolButton(this); 470 addButton->setText(tr("Add")); 471 addButton->setIcon(QIcon(QLatin1String(":/trolltech/assistant/images/" 472 SYSTEM "/addtab.png"))); 473 addButton->setAutoRaise(true); 474 addButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 475 hlayout->addWidget(addButton); 476 connect(addButton, SIGNAL(clicked()), this, SIGNAL(addBookmark())); 477 478 removeButton = new QToolButton(this); 479 removeButton->setText(tr("Remove")); 480 removeButton->setIcon(QIcon(QLatin1String(":/trolltech/assistant/images/" 481 SYSTEM "/closetab.png"))); 482 removeButton->setAutoRaise(true); 483 removeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 484 hlayout->addWidget(removeButton); 485 connect(removeButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 486 } 487 488 filterBookmarkModel = new QSortFilterProxyModel(this); 489 treeView->setModel(filterBookmarkModel); 490 491 treeView->setDragEnabled(true); 492 treeView->setAcceptDrops(true); 493 treeView->setAutoExpandDelay(1000); 494 treeView->setDropIndicatorShown(true); 495 treeView->header()->setVisible(false); 496 treeView->setContextMenuPolicy(Qt::CustomContextMenu); 497 498 connect(treeView, SIGNAL(expanded(QModelIndex)), this, 499 SLOT(expand(QModelIndex))); 500 connect(treeView, SIGNAL(collapsed(QModelIndex)), this, 501 SLOT(expand(QModelIndex))); 502 connect(treeView, SIGNAL(activated(QModelIndex)), this, 503 SLOT(activated(QModelIndex))); 504 connect(treeView, SIGNAL(customContextMenuRequested(QPoint)), 505 this, SLOT(customContextMenuRequested(QPoint))); 506 507 filterBookmarkModel->setFilterKeyColumn(0); 508 filterBookmarkModel->setDynamicSortFilter(true); 509 filterBookmarkModel->setSourceModel(bookmarkManager->treeBookmarkModel()); 510 511 expandItems(); 512 } 513 514 void BookmarkWidget::expandItems() 515 { 516 QStandardItemModel *model = bookmarkManager->treeBookmarkModel(); 517 QList<QStandardItem*>list = model->findItems(QLatin1String("*"), 518 Qt::MatchWildcard | Qt::MatchRecursive, 0); 519 foreach (const QStandardItem *item, list) { 520 const QModelIndex &index = model->indexFromItem(item); 521 treeView->setExpanded(filterBookmarkModel->mapFromSource(index), 522 item->data(Qt::UserRole + 11).toBool()); 523 } 524 } 525 526 void BookmarkWidget::focusInEvent(QFocusEvent *e) 527 { 528 if (e->reason() != Qt::MouseFocusReason) { 529 searchField->selectAll(); 530 searchField->setFocus(); 531 532 QModelIndex index = treeView->indexAt(QPoint(1, 1)); 533 if (index.isValid()) 534 treeView->setCurrentIndex(index); 535 536 } 537 } 538 539 bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) 540 { 541 if (object != this && object != treeView 542 && object != treeView->viewport()) { 543 return QWidget::eventFilter(object, e); 544 } 545 546 if (e->type() == QEvent::KeyPress) { 547 QKeyEvent *ke = static_cast<QKeyEvent*>(e); 548 const bool tree = object == treeView || object == treeView->viewport(); 549 switch (ke->key()) { 550 case Qt::Key_F2: { 551 const QModelIndex &index = treeView->currentIndex(); 552 const QModelIndex &src = filterBookmarkModel->mapToSource(index); 553 if (tree && searchField->text().isEmpty()) { 554 if (QStandardItem *item = bookmarkManager->treeBookmarkModel() 555 ->itemFromIndex(src)) { 556 item->setEditable(true); 557 treeView->edit(index); 558 item->setEditable(false); 559 } 560 } 561 } break; 562 563 case Qt::Key_Enter: { 564 case Qt::Key_Return: 565 if (tree) { 566 const QString &data = treeView->selectionModel()->currentIndex() 567 .data(Qt::UserRole + 10).toString(); 568 if (!data.isEmpty() && data != QLatin1String("Folder")) 569 emit requestShowLink(data); 570 } 571 } break; 572 573 case Qt::Key_Delete: { 574 const QModelIndex &index = treeView->currentIndex(); 575 const QModelIndex &src = filterBookmarkModel->mapToSource(index); 576 if (tree && searchField->text().isEmpty()) 577 bookmarkManager->removeBookmarkItem(treeView, src); 578 } break; 579 580 case Qt::Key_Up: { 581 case Qt::Key_Down: 582 if (!tree) 583 treeView->subclassKeyPressEvent(ke); 584 } break; 585 586 case Qt::Key_Escape: { 587 emit escapePressed(); 588 } break; 589 590 default: break; 591 } 592 } 593 594 if (e->type() == QEvent::MouseButtonRelease) { 595 QMouseEvent *me = static_cast<QMouseEvent*>(e); 596 bool controlPressed = me->modifiers() & Qt::ControlModifier; 597 if(((me->button() == Qt::LeftButton) && controlPressed) 598 || (me->button() == Qt::MidButton)) { 599 const QModelIndex &index = treeView->currentIndex(); 600 const QString &data = index.data(Qt::UserRole + 10).toString(); 601 if (!data.isEmpty() && data != QLatin1String("Folder")) 602 CentralWidget::instance()->setSourceInNewTab(data); 603 } 604 } 605 606 return QWidget::eventFilter(object, e); 607 } 608 609 610 // #pragma mark -- BookmarkModel 611 612 613 BookmarkModel::BookmarkModel(int rows, int columns, QObject *parent) 614 : QStandardItemModel(rows, columns, parent) 615 { 616 } 617 618 BookmarkModel::~BookmarkModel() 619 { 620 } 621 622 Qt::DropActions BookmarkModel::supportedDropActions() const 623 { 624 return Qt::MoveAction; 625 } 626 627 Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const 628 { 629 Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index); 630 if ((!index.isValid()) // can only happen for the invisible root item 631 || index.data(Qt::UserRole + 10).toString() == QLatin1String("Folder")) 632 return (Qt::ItemIsDropEnabled | defaultFlags) &~ Qt::ItemIsDragEnabled; 633 634 return (Qt::ItemIsDragEnabled | defaultFlags) &~ Qt::ItemIsDropEnabled; 635 } 636 637 638 // #pragma mark -- BookmarkManager 639 640 641 BookmarkManager::BookmarkManager(QHelpEngineCore *_helpEngine) 642 : treeModel(new BookmarkModel(0, 1, this)) 643 , listModel(new BookmarkModel(0, 1, this)) 644 , renameItem(0) 645 , helpEngine(_helpEngine) 646 { 647 folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon); 648 649 connect(treeModel, SIGNAL(itemChanged(QStandardItem*)), this, 650 SLOT(itemChanged(QStandardItem*))); 651 connect(treeModel, SIGNAL(itemChanged(QStandardItem*)), this, 652 SIGNAL(bookmarksChanged())); 653 connect(treeModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), 654 this, SIGNAL(bookmarksChanged())); 655 } 656 657 BookmarkManager::~BookmarkManager() 658 { 659 treeModel->clear(); 660 listModel->clear(); 661 } 662 663 BookmarkModel* BookmarkManager::treeBookmarkModel() 664 { 665 return treeModel; 666 } 667 668 BookmarkModel* BookmarkManager::listBookmarkModel() 669 { 670 return listModel; 671 } 672 673 void BookmarkManager::saveBookmarks() 674 { 675 QByteArray bookmarks; 676 QDataStream stream(&bookmarks, QIODevice::WriteOnly); 677 678 readBookmarksRecursive(treeModel->invisibleRootItem(), stream, 0); 679 helpEngine->setCustomValue(QLatin1String("Bookmarks"), bookmarks); 680 } 681 682 QStringList BookmarkManager::bookmarkFolders() const 683 { 684 QStringList folders(tr("Bookmarks")); 685 686 QList<QStandardItem*>list = treeModel->findItems(QLatin1String("*"), 687 Qt::MatchWildcard | Qt::MatchRecursive, 0); 688 689 QString data; 690 foreach (const QStandardItem *item, list) { 691 data = item->data(Qt::UserRole + 10).toString(); 692 if (data == QLatin1String("Folder")) 693 folders << item->data(Qt::DisplayRole).toString(); 694 } 695 return folders; 696 } 697 698 QModelIndex BookmarkManager::addNewFolder(const QModelIndex &index) 699 { 700 QStandardItem *item = new QStandardItem(uniqueFolderName()); 701 item->setEditable(false); 702 item->setData(false, Qt::UserRole + 11); 703 item->setData(QLatin1String("Folder"), Qt::UserRole + 10); 704 item->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon)); 705 706 if (index.isValid()) { 707 treeModel->itemFromIndex(index)->appendRow(item); 480 typeAndSearchModel->setFilterRegExp(QRegExp(text)); 708 481 } else { 709 treeModel->appendRow(item); 710 } 711 return treeModel->indexFromItem(item); 712 } 713 714 void BookmarkManager::removeBookmarkItem(QTreeView *treeView, 715 const QModelIndex &index) 716 { 717 QStandardItem *item = treeModel->itemFromIndex(index); 718 if (item) { 719 QString data = index.data(Qt::UserRole + 10).toString(); 720 if (data == QLatin1String("Folder") && item->rowCount() > 0) { 721 int value = QMessageBox::question(treeView, tr("Remove"), 722 tr("You are going to delete a Folder, this will also<br>" 723 "remove it's content. Are you sure to continue?"), 724 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); 725 726 if (value == QMessageBox::Cancel) 727 return; 728 } 729 730 if (data != QLatin1String("Folder")) { 731 QList<QStandardItem*>itemList = listModel->findItems(item->text()); 732 foreach (const QStandardItem *i, itemList) { 733 if (i->data(Qt::UserRole + 10) == data) { 734 listModel->removeRow(i->row()); 735 break; 736 } 737 } 738 } else { 739 removeBookmarkFolderItems(item); 740 } 741 treeModel->removeRow(item->row(), index.parent()); 742 } 743 } 744 745 void BookmarkManager::showBookmarkDialog(QWidget *parent, const QString &name, 746 const QString &url) 747 { 748 BookmarkDialog dialog(this, name, url, parent); 749 dialog.exec(); 750 } 751 752 void BookmarkManager::addNewBookmark(const QModelIndex &index, 753 const QString &name, const QString &url) 754 { 755 QStandardItem *item = new QStandardItem(name); 756 item->setEditable(false); 757 item->setData(false, Qt::UserRole + 11); 758 item->setData(url, Qt::UserRole + 10); 759 760 if (index.isValid()) 761 treeModel->itemFromIndex(index)->appendRow(item); 762 else 763 treeModel->appendRow(item); 764 listModel->appendRow(item->clone()); 765 emit bookmarksChanged(); 766 } 767 768 void BookmarkManager::fillBookmarkMenu(QMenu *menu) 769 { 770 if (!menu || !treeModel) 771 return; 772 773 map.clear(); 774 fillBookmarkMenu(menu, treeModel->invisibleRootItem()); 775 } 776 777 void BookmarkManager::fillBookmarkMenu(QMenu *menu, QStandardItem *root) 778 { 779 for (int i = 0; i < root->rowCount(); ++i) { 780 QStandardItem *item = root->child(i); 781 if (item && item->data(Qt::UserRole + 10) 782 .toString() == QLatin1String("Folder")) { 783 QMenu* newMenu = menu->addMenu(folderIcon, item->text()); 784 if (item->rowCount() > 0) 785 fillBookmarkMenu(newMenu, item); 786 } else { 787 map.insert(menu->addAction(item->text()), item->index()); 788 } 789 } 790 } 791 792 QUrl BookmarkManager::urlForAction(QAction* action) const 793 { 794 if (map.contains(action)) { 795 const QModelIndex &index = map.value(action); 796 if (QStandardItem* item = treeModel->itemFromIndex(index)) 797 return QUrl(item->data(Qt::UserRole + 10).toString()); 798 } 799 return QUrl(); 800 } 801 802 void BookmarkManager::itemChanged(QStandardItem *item) 803 { 804 if (renameItem != item) { 805 renameItem = item; 806 oldText = item->text(); 807 return; 808 } 809 810 if (item->text() != oldText) { 811 if (item->data(Qt::UserRole + 10).toString() != QLatin1String("Folder")) { 812 QList<QStandardItem*>itemList = listModel->findItems(oldText); 813 if (itemList.count() > 0) 814 itemList.at(0)->setText(item->text()); 815 } 816 } 817 } 818 819 void BookmarkManager::setupBookmarkModels() 820 { 821 treeModel->clear(); 822 listModel->clear(); 823 824 qint32 depth; 825 bool expanded; 826 QString name, type; 827 QList<int> lastDepths; 828 QList<QStandardItem*> parents; 829 830 QByteArray ba = 831 helpEngine->customValue(QLatin1String("Bookmarks")).toByteArray(); 832 QDataStream stream(ba); 833 while (!stream.atEnd()) { 834 stream >> depth >> name >> type >> expanded; 835 836 QStandardItem *item = new QStandardItem(name); 837 item->setEditable(false); 838 item->setData(type, Qt::UserRole + 10); 839 item->setData(expanded, Qt::UserRole + 11); 840 if (depth == 0) { 841 parents.clear(); lastDepths.clear(); 842 treeModel->appendRow(item); 843 parents << item; lastDepths << depth; 844 } else { 845 if (depth <= lastDepths.last()) { 846 while (depth <= lastDepths.last() && parents.count() > 0) { 847 parents.pop_back(); lastDepths.pop_back(); 848 } 849 } 850 parents.last()->appendRow(item); 851 if (type == QLatin1String("Folder")) { 852 parents << item; lastDepths << depth; 853 } 854 } 855 856 if (type == QLatin1String("Folder")) 857 item->setIcon(folderIcon); 858 else 859 listModel->appendRow(item->clone()); 860 } 861 } 862 863 QString BookmarkManager::uniqueFolderName() const 864 { 865 QString folderName = tr("New Folder"); 866 QList<QStandardItem*> list = treeModel->findItems(folderName, 867 Qt::MatchContains | Qt::MatchRecursive, 0); 868 if (!list.isEmpty()) { 869 QStringList names; 870 foreach (const QStandardItem *item, list) 871 names << item->text(); 872 873 for (int i = 1; i <= names.count(); ++i) { 874 folderName = (tr("New Folder") + QLatin1String(" %1")).arg(i); 875 if (!names.contains(folderName)) 876 break; 877 } 878 } 879 return folderName; 880 } 881 882 void BookmarkManager::removeBookmarkFolderItems(QStandardItem *item) 883 { 884 for (int j = 0; j < item->rowCount(); ++j) { 885 QStandardItem *child = item->child(j); 886 if (child->rowCount() > 0) 887 removeBookmarkFolderItems(child); 888 889 QString data = child->data(Qt::UserRole + 10).toString(); 890 QList<QStandardItem*>itemList = listModel->findItems(child->text()); 891 foreach (const QStandardItem *i, itemList) { 892 if (i->data(Qt::UserRole + 10) == data) { 893 listModel->removeRow(i->row()); 894 break; 895 } 896 } 897 } 898 } 899 900 void BookmarkManager::readBookmarksRecursive(const QStandardItem *item, 901 QDataStream &stream, const qint32 depth) const 902 { 903 for (int j = 0; j < item->rowCount(); ++j) { 904 const QStandardItem *child = item->child(j); 905 stream << depth; 906 stream << child->data(Qt::DisplayRole).toString(); 907 stream << child->data(Qt::UserRole + 10).toString(); 908 stream << child->data(Qt::UserRole + 11).toBool(); 909 910 if (child->rowCount() > 0) 911 readBookmarksRecursive(child, stream, (depth +1)); 482 typeAndSearch = false; 483 bookmarkTreeView->setModel(bookmarkModel); 484 bookmarkTreeView->setItemsExpandable(true); 485 bookmarkTreeView->setRootIsDecorated(true); 486 bookmarkModel->expandFoldersIfNeeeded(bookmarkTreeView); 912 487 } 913 488 } -
trunk/tools/assistant/tools/assistant/bookmarkmanager.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 42 41 #ifndef BOOKMARKMANAGER_H 43 42 #define BOOKMARKMANAGER_H 44 43 45 #include "ui_bookmarkdialog.h" 44 #include <QtCore/QMutex> 45 #include <QtGui/QTreeView> 46 46 47 #include <QtCore/QUrl> 48 #include <QtCore/QObject> 49 #include <QtCore/QString> 50 #include <QtCore/QByteArray> 51 #include <QtCore/QDataStream> 52 53 #include <QtGui/QIcon> 54 #include <QtGui/QDialog> 55 #include <QtGui/QWidget> 56 #include <QtGui/QTreeView> 57 #include <QtGui/QStandardItemModel> 47 #include "ui_bookmarkwidget.h" 58 48 59 49 QT_BEGIN_NAMESPACE 60 50 61 class QEvent; 62 class QLineEdit; 63 class QTreeView; 64 class QToolButton; 65 class QStandardItem; 66 class QHelpEngineCore; 67 class QAbstractItemModel; 51 class BookmarkManagerWidget; 52 class BookmarkModel; 53 class BookmarkFilterModel; 54 class QKeyEvent; 68 55 class QSortFilterProxyModel; 69 70 class BookmarkManager;71 72 class BookmarkDialog : public QDialog73 {74 Q_OBJECT75 76 public:77 BookmarkDialog(BookmarkManager *manager, const QString &title,78 const QString &url, QWidget *parent = 0);79 ~BookmarkDialog();80 81 private slots:82 void addAccepted();83 void addNewFolder();84 void toolButtonClicked();85 void itemChanged(QStandardItem *item);86 void textChanged(const QString& string);87 void selectBookmarkFolder(const QString &folderName);88 void customContextMenuRequested(const QPoint &point);89 void currentChanged(const QModelIndex& current);90 91 private:92 bool eventFilter(QObject *object, QEvent *e);93 94 private:95 QString m_url;96 QString m_title;97 98 QString oldText;99 QStandardItem *renameItem;100 101 Ui::BookmarkDialog ui;102 BookmarkManager *bookmarkManager;103 QSortFilterProxyModel *proxyModel;104 };105 106 class TreeView : public QTreeView {107 Q_OBJECT108 public:109 TreeView(QWidget* parent = 0) : QTreeView(parent) {}110 void subclassKeyPressEvent(QKeyEvent* event)111 {112 QTreeView::keyPressEvent(event);113 }114 };115 116 class BookmarkWidget : public QWidget117 {118 Q_OBJECT119 120 public:121 BookmarkWidget(BookmarkManager *manager, QWidget *parent = 0,122 bool showButtons = true);123 ~BookmarkWidget();124 125 signals:126 void addBookmark();127 void requestShowLink(const QUrl &url);128 void escapePressed();129 130 private slots:131 void removeClicked();132 void filterChanged();133 void expand(const QModelIndex& index);134 void activated(const QModelIndex &index);135 void customContextMenuRequested(const QPoint &point);136 137 private:138 void setup(bool showButtons);139 void expandItems();140 void focusInEvent(QFocusEvent *e);141 bool eventFilter(QObject *object, QEvent *event);142 143 private:144 QRegExp regExp;145 TreeView *treeView;146 QLineEdit *searchField;147 QToolButton *addButton;148 QToolButton *removeButton;149 BookmarkManager *bookmarkManager;150 QSortFilterProxyModel* filterBookmarkModel;151 };152 153 class BookmarkModel : public QStandardItemModel154 {155 Q_OBJECT156 157 public:158 BookmarkModel(int rows, int columns, QObject *parent = 0);159 ~BookmarkModel();160 161 Qt::DropActions supportedDropActions() const;162 Qt::ItemFlags flags(const QModelIndex &index) const;163 };164 56 165 57 class BookmarkManager : public QObject 166 58 { 167 59 Q_OBJECT 60 61 62 63 168 64 169 65 public: 170 BookmarkManager(QHelpEngineCore* helpEngine); 66 static BookmarkManager* instance(); 67 static void destroy(); 68 69 QWidget* bookmarkDockWidget() const; 70 void takeBookmarksMenu(QMenu* menu); 71 72 public slots: 73 void addBookmark(const QString &title, const QString &url); 74 75 signals: 76 void escapePressed(); 77 void setSource(const QUrl &url); 78 void setSourceInNewTab(const QUrl &url); 79 80 private: 81 BookmarkManager(); 171 82 ~BookmarkManager(); 172 83 173 BookmarkModel* treeBookmarkModel(); 174 BookmarkModel* listBookmarkModel(); 84 void removeItem(const QModelIndex &index); 85 bool eventFilter(QObject *object, QEvent *event); 86 void buildBookmarksMenu(const QModelIndex &index, QMenu *menu); 87 void showBookmarkDialog(const QString &name, const QString &url); 175 88 176 void saveBookmarks(); 177 QStringList bookmarkFolders() const; 178 QModelIndex addNewFolder(const QModelIndex& index); 179 void removeBookmarkItem(QTreeView *treeView, const QModelIndex& index); 180 void showBookmarkDialog(QWidget* parent, const QString &name, 181 const QString &url); 182 void addNewBookmark(const QModelIndex& index, const QString &name, 183 const QString &url); 184 void setupBookmarkModels(); 89 private slots: 90 void setupFinished(); 185 91 186 void fillBookmarkMenu(QMenu *menu); 187 QUrl urlForAction(QAction* action) const; 92 void addBookmark(); 93 void removeBookmark(); 94 void manageBookmarks(); 95 void refeshBookmarkMenu(); 96 void renameBookmark(const QModelIndex &index); 97 98 void setSourceFromAction(QAction *action); 99 void setSourceFromIndex(const QModelIndex &index, bool newTab = false); 100 101 void focusInEvent(); 102 void managerWidgetAboutToClose(); 103 void textChanged(const QString &text); 104 void customContextMenuRequested(const QPoint &point); 105 106 private: 107 bool typeAndSearch; 108 109 static QMutex mutex; 110 static BookmarkManager *bookmarkManager; 111 112 QMenu *bookmarkMenu; 113 114 BookmarkModel *bookmarkModel; 115 BookmarkFilterModel *bookmarkFilterModel; 116 QSortFilterProxyModel *typeAndSearchModel; 117 118 BookmarkWidget *bookmarkWidget; 119 BookmarkTreeView *bookmarkTreeView; 120 BookmarkManagerWidget *bookmarkManagerWidget; 121 }; 122 123 class BookmarkManager::BookmarkWidget : public QWidget 124 { 125 Q_OBJECT 126 public: 127 BookmarkWidget(QWidget *parent = 0) 128 : QWidget(parent) { ui.setupUi(this); } 129 virtual ~BookmarkWidget() {} 130 131 Ui::BookmarkWidget ui; 188 132 189 133 signals: 190 void bookmarksChanged(); 134 void focusInEvent(); 135 136 private: 137 void focusInEvent(QFocusEvent *event); 138 }; 139 140 class BookmarkManager::BookmarkTreeView : public QTreeView 141 { 142 Q_OBJECT 143 public: 144 BookmarkTreeView(QWidget *parent = 0); 145 ~BookmarkTreeView() {} 146 147 void subclassKeyPressEvent(QKeyEvent *event); 191 148 192 149 private slots: 193 void itemChanged(QStandardItem *item); 194 195 private: 196 QString uniqueFolderName() const; 197 void removeBookmarkFolderItems(QStandardItem *item); 198 void readBookmarksRecursive(const QStandardItem *item, QDataStream &stream, 199 const qint32 depth) const; 200 void fillBookmarkMenu(QMenu *menu, QStandardItem *root); 201 202 private: 203 QString oldText; 204 QIcon folderIcon; 205 206 BookmarkModel *treeModel; 207 BookmarkModel *listModel; 208 QStandardItem *renameItem; 209 QHelpEngineCore *helpEngine; 210 QMap<QAction*, QModelIndex> map; 150 void setExpandedData(const QModelIndex &index); 211 151 }; 212 152 213 153 QT_END_NAMESPACE 214 154 215 #endif 155 #endif -
trunk/tools/assistant/tools/assistant/centralwidget.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "centralwidget.h" 43 #include "helpviewer.h" 44 #include "findwidget.h" 45 #include "helpenginewrapper.h" 44 46 #include "searchwidget.h" 45 47 #include "mainwindow.h" 46 #include "preferencesdialog.h" 47 48 #include <QtCore/QDir> 49 #include <QtCore/QEvent> 48 #include "../shared/collectionconfiguration.h" 49 50 #if defined(QT_NO_WEBKIT) 51 #include "helpviewer_qtb.h" 52 #else 53 #include "helpviewer_qwv.h" 54 #endif // QT_NO_WEBKIT 55 50 56 #include <QtCore/QTimer> 51 57 58 59 60 52 61 #include <QtGui/QMenu> 53 #include <QtGui/QLabel>54 #include <QtGui/QLayout>55 62 #include <QtGui/QPrinter> 56 #include <QtGui/QLineEdit>57 #include <QtGui/QCheckBox>58 63 #include <QtGui/QTabBar> 59 64 #include <QtGui/QTabWidget> 65 60 66 #include <QtGui/QToolButton> 61 #include <QtGui/QMouseEvent> 62 #include <QtGui/QSpacerItem> 63 #include <QtGui/QTextCursor> 67 #include <QtGui/QPageSetupDialog> 64 68 #include <QtGui/QPrintDialog> 65 #include <QtGui/QApplication>66 #include <QtGui/QTextDocumentFragment>67 69 #include <QtGui/QPrintPreviewDialog> 68 #include <QtGui/QPageSetupDialog> 69 70 #include <QtHelp/QHelpEngine> 70 71 71 #include <QtHelp/QHelpSearchEngine> 72 72 … … 77 77 const QPoint &point) 78 78 { 79 79 80 QTabBar *tabBar = qFindChild<QTabBar*>(widget); 80 81 for (int i = 0; i < tabBar->count(); ++i) { … … 87 88 } 88 89 89 FindWidget::FindWidget(QWidget *parent) 90 : QWidget(parent) 91 , appPalette(qApp->palette()) 92 { 93 QHBoxLayout *hboxLayout = new QHBoxLayout(this); 94 QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); 95 96 #ifndef Q_OS_MAC 97 hboxLayout->setMargin(0); 98 hboxLayout->setSpacing(6); 99 resourcePath.append(QLatin1String("win")); 100 #else 101 resourcePath.append(QLatin1String("mac")); 102 #endif 103 104 toolClose = setupToolButton(QLatin1String(""), 105 resourcePath + QLatin1String("/closetab.png")); 106 hboxLayout->addWidget(toolClose); 107 108 editFind = new QLineEdit(this); 109 hboxLayout->addWidget(editFind); 110 editFind->setMinimumSize(QSize(150, 0)); 111 connect(editFind, SIGNAL(textChanged(QString)), this, SLOT(updateButtons())); 112 113 toolPrevious = setupToolButton(tr("Previous"), 114 resourcePath + QLatin1String("/previous.png")); 115 hboxLayout->addWidget(toolPrevious); 116 117 toolNext = setupToolButton(tr("Next"), 118 resourcePath + QLatin1String("/next.png")); 119 hboxLayout->addWidget(toolNext); 120 121 checkCase = new QCheckBox(tr("Case Sensitive"), this); 122 hboxLayout->addWidget(checkCase); 123 124 checkWholeWords = new QCheckBox(tr("Whole words"), this); 125 hboxLayout->addWidget(checkWholeWords); 126 #if !defined(QT_NO_WEBKIT) 127 checkWholeWords->hide(); 128 #endif 129 130 labelWrapped = new QLabel(this); 131 labelWrapped->setScaledContents(true); 132 labelWrapped->setTextFormat(Qt::RichText); 133 labelWrapped->setMinimumSize(QSize(0, 20)); 134 labelWrapped->setMaximumSize(QSize(105, 20)); 135 labelWrapped->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); 136 labelWrapped->setText(tr("<img src=\":/trolltech/assistant/images/wrap.png\"" 137 "> Search wrapped")); 138 hboxLayout->addWidget(labelWrapped); 139 140 QSpacerItem *spacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding, 141 QSizePolicy::Minimum); 142 hboxLayout->addItem(spacerItem); 143 setMinimumWidth(minimumSizeHint().width()); 144 labelWrapped->hide(); 145 146 updateButtons(); 147 } 148 149 FindWidget::~FindWidget() 150 { 151 } 152 153 void FindWidget::hideEvent(QHideEvent* event) 154 { 155 #if !defined(QT_NO_WEBKIT) 156 // TODO: remove this once webkit supports setting the palette 157 if (!event->spontaneous()) 158 qApp->setPalette(appPalette); 159 #else 160 Q_UNUSED(event); 161 #endif 162 } 163 164 void FindWidget::showEvent(QShowEvent* event) 165 { 166 #if !defined(QT_NO_WEBKIT) 167 // TODO: remove this once webkit supports setting the palette 168 if (!event->spontaneous()) { 169 QPalette p = appPalette; 170 p.setColor(QPalette::Inactive, QPalette::Highlight, 171 p.color(QPalette::Active, QPalette::Highlight)); 172 p.setColor(QPalette::Inactive, QPalette::HighlightedText, 173 p.color(QPalette::Active, QPalette::HighlightedText)); 174 qApp->setPalette(p); 175 } 176 #else 177 Q_UNUSED(event); 178 #endif 179 } 180 181 void FindWidget::updateButtons() 182 { 183 if (editFind->text().isEmpty()) { 184 toolPrevious->setEnabled(false); 185 toolNext->setEnabled(false); 186 } else { 187 toolPrevious->setEnabled(true); 188 toolNext->setEnabled(true); 189 } 190 } 191 192 QToolButton* FindWidget::setupToolButton(const QString &text, const QString &icon) 193 { 194 QToolButton *toolButton = new QToolButton(this); 195 196 toolButton->setText(text); 197 toolButton->setAutoRaise(true); 198 toolButton->setIcon(QIcon(icon)); 199 toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 200 201 return toolButton; 202 } 203 204 205 // -- 206 207 208 CentralWidget::CentralWidget(QHelpEngine *engine, MainWindow *parent) 90 // -- CentralWidget 91 92 CentralWidget::CentralWidget(MainWindow *parent) 209 93 : QWidget(parent) 210 94 , lastTabPage(0) 211 , collectionFile(engine->collectionFile())212 , findBar(0)213 95 , tabWidget(0) 214 96 , findWidget(0) 215 , helpEngine(engine)216 97 , printer(0) 217 98 , usesDefaultCollection(parent->usesDefaultCollection()) 218 99 , m_searchWidget(0) 219 100 { 101 220 102 globalActionList.clear(); 221 103 staticCentralWidget = this; … … 254 136 vboxLayout->addWidget(tabWidget); 255 137 256 findBar = new QWidget(this); 257 findWidget = new FindWidget(findBar); 258 findBar->setMinimumHeight(findWidget->minimumSizeHint().height()); 259 findWidget->move(0, 0); 260 vboxLayout->addWidget(findBar); 261 findBar->hide(); 262 findWidget->editFind->installEventFilter(this); 263 264 connect(findWidget->toolClose, SIGNAL(clicked()), findBar, SLOT(hide())); 265 connect(findWidget->toolNext, SIGNAL(clicked()), this, SLOT(findNext())); 266 connect(findWidget->editFind, SIGNAL(returnPressed()), this, SLOT(findNext())); 267 connect(findWidget->editFind, SIGNAL(textChanged(QString)), this, 268 SLOT(findCurrentText(QString))); 269 connect(findWidget->toolPrevious, SIGNAL(clicked()), this, SLOT(findPrevious())); 138 findWidget = new FindWidget(this); 139 vboxLayout->addWidget(findWidget); 140 findWidget->hide(); 141 142 connect(findWidget, SIGNAL(findNext()), this, SLOT(findNext())); 143 connect(findWidget, SIGNAL(findPrevious()), this, SLOT(findPrevious())); 144 connect(findWidget, SIGNAL(find(QString, bool)), this, 145 SLOT(find(QString, bool))); 146 connect(findWidget, SIGNAL(escapePressed()), this, SLOT(activateTab())); 270 147 271 148 QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget); … … 289 166 CentralWidget::~CentralWidget() 290 167 { 168 291 169 #ifndef QT_NO_PRINTER 292 170 delete printer; 293 171 #endif 294 172 295 QHelpEngineCore engine(collectionFile, 0); 296 if (!engine.setupData()) 297 return; 298 299 QString zoomCount; 300 QString currentPages; 301 QLatin1Char separator('|'); 173 QStringList zoomFactors; 174 QStringList currentPages; 302 175 bool searchAttached = m_searchWidget->isAttached(); 303 176 … … 306 179 HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i)); 307 180 if (viewer && viewer->source().isValid()) { 308 currentPages += viewer->source().toString() + separator;309 zoom Count += QString::number(viewer->zoom()) + separator;181 currentPages ; 182 zoom; 310 183 } 311 184 } 312 185 313 engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage); 314 engine.setCustomValue(QLatin1String("LastShownPages"), currentPages); 315 engine.setCustomValue(QLatin1String("SearchWasAttached"), searchAttached); 316 #if !defined(QT_NO_WEBKIT) 317 engine.setCustomValue(QLatin1String("LastPagesZoomWebView"), zoomCount); 318 #else 319 engine.setCustomValue(QLatin1String("LastPagesZoomTextBrowser"), zoomCount); 320 #endif 186 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 187 helpEngine.setLastTabPage(tabWidget->currentIndex()); 188 helpEngine.setLastShownPages(currentPages); 189 helpEngine.setSearchWasAttached(searchAttached); 190 helpEngine.setLastZoomFactors(zoomFactors); 321 191 } 322 192 323 193 CentralWidget *CentralWidget::instance() 324 194 { 195 325 196 return staticCentralWidget; 326 197 } … … 328 199 void CentralWidget::newTab() 329 200 { 201 330 202 HelpViewer *viewer = currentHelpViewer(); 331 203 #if !defined(QT_NO_WEBKIT) … … 339 211 void CentralWidget::zoomIn() 340 212 { 341 HelpViewer *viewer = currentHelpViewer(); 342 if (viewer) 343 viewer->zoomIn(); 213 TRACE_OBJ 214 HelpViewer *viewer = currentHelpViewer(); 215 if (viewer) 216 viewer->scaleUp(); 344 217 345 218 if (tabWidget->currentWidget() == m_searchWidget) … … 349 222 void CentralWidget::zoomOut() 350 223 { 351 HelpViewer *viewer = currentHelpViewer(); 352 if (viewer) 353 viewer->zoomOut(); 224 TRACE_OBJ 225 HelpViewer *viewer = currentHelpViewer(); 226 if (viewer) 227 viewer->scaleDown(); 354 228 355 229 if (tabWidget->currentWidget() == m_searchWidget) … … 357 231 } 358 232 359 void CentralWidget::findNext()360 {361 find(findWidget->editFind->text(), true);362 }363 364 233 void CentralWidget::nextPage() 365 234 { 235 366 236 int index = tabWidget->currentIndex() + 1; 367 237 if (index >= tabWidget->count()) … … 372 242 void CentralWidget::resetZoom() 373 243 { 374 HelpViewer *viewer = currentHelpViewer();375 if ( viewer)376 viewer->reset Zoom();244 245 if () 246 viewer->reset(); 377 247 378 248 if (tabWidget->currentWidget() == m_searchWidget) … … 382 252 void CentralWidget::previousPage() 383 253 { 254 384 255 int index = tabWidget->currentIndex() -1; 385 256 if (index < 0) … … 388 259 } 389 260 390 void CentralWidget::findPrevious()391 {392 find(findWidget->editFind->text(), false);393 }394 395 261 void CentralWidget::closeTab() 396 262 { 263 397 264 HelpViewer *viewer = currentHelpViewer(); 398 265 if (!viewer|| tabWidget->count() == 1) … … 405 272 void CentralWidget::setSource(const QUrl &url) 406 273 { 274 407 275 HelpViewer *viewer = currentHelpViewer(); 408 276 HelpViewer *lastViewer = … … 410 278 411 279 if (!viewer && !lastViewer) { 412 viewer = new HelpViewer( helpEngine,this);280 viewer = new HelpViewer(this); 413 281 viewer->installEventFilter(this); 414 282 lastTabPage = tabWidget->addTab(viewer, QString()); … … 428 296 void CentralWidget::setupWidget() 429 297 { 430 int option = helpEngine->customValue(QLatin1String("StartOption"),431 ShowLastPages).toInt();432 298 299 (); 300 int option = helpEngine.startOption(); 433 301 if (option != ShowLastPages) { 434 302 QString homePage; 435 if (option == ShowHomePage) { 436 homePage = helpEngine->customValue(QLatin1String("defaultHomepage"), 437 QLatin1String("help")).toString(); 438 homePage = helpEngine->customValue(QLatin1String("homepage"), 439 homePage).toString(); 440 } 441 if (option == ShowBlankPage) 303 if (option == ShowHomePage) 304 homePage = helpEngine.homePage(); 305 else if (option == ShowBlankPage) 442 306 homePage = QLatin1String("about:blank"); 443 307 setSource(homePage); … … 449 313 void CentralWidget::setLastShownPages() 450 314 { 451 const QLatin1String key("LastShownPages"); 452 QString value = helpEngine->customValue(key, QString()).toString(); 453 const QStringList lastShownPageList = value.split(QLatin1Char('|'), 454 QString::SkipEmptyParts); 455 315 TRACE_OBJ 316 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 317 const QStringList &lastShownPageList = helpEngine.lastShownPages(); 456 318 const int pageCount = lastShownPageList.count(); 457 319 if (pageCount == 0) { … … 462 324 return; 463 325 } 464 465 #if !defined(QT_NO_WEBKIT) 466 const QLatin1String zoom("LastPagesZoomWebView"); 467 #else 468 const QLatin1String zoom("LastPagesZoomTextBrowser"); 469 #endif 470 471 value = helpEngine->customValue(zoom, QString()).toString(); 472 QVector<QString> zoomVector = value.split(QLatin1Char('|'), 473 QString::SkipEmptyParts).toVector(); 474 475 const int zoomCount = zoomVector.count(); 476 zoomVector.insert(zoomCount, pageCount - zoomCount, QLatin1String("0.0")); 477 478 QVector<QString>::const_iterator zIt = zoomVector.constBegin(); 479 QStringList::const_iterator it = lastShownPageList.constBegin(); 480 for (; it != lastShownPageList.constEnd(); ++it, ++zIt) 481 setSourceInNewTab((*it), (*zIt).toFloat()); 482 483 const QLatin1String lastTab("LastTabPage"); 484 int tab = helpEngine->customValue(lastTab, 1).toInt(); 485 486 const QLatin1String searchKey("SearchWasAttached"); 326 QStringList zoomFactors = helpEngine.lastZoomFactors(); 327 while (zoomFactors.count() < pageCount) 328 zoomFactors.append(CollectionConfiguration::DefaultZoomFactor); 329 487 330 const bool searchIsAttached = m_searchWidget->isAttached(); 488 const bool searchWasAttached = helpEngine ->customValue(searchKey).toBool();489 490 if (searchWasAttached && !searchIsAttached )491 tabWidget->setCurrentIndex(--tab);331 const bool searchWasAttached = helpEngine(); 332 int tabToShow = helpEngine.lastTabPage(); 333 if (searchWasAttached && !searchIsAttached) 334 ; 492 335 else if (!searchWasAttached && searchIsAttached) 493 tabWidget->setCurrentIndex(++tab); 494 else 495 tabWidget->setCurrentIndex(tab); 336 ++tabToShow; 337 338 for (int curTab = 0; curTab < pageCount; ++curTab) { 339 const QString &curFile = lastShownPageList.at(curTab); 340 if (helpEngine.findFile(curFile).isValid() 341 || curFile == QLatin1String("about:blank")) { 342 setSourceInNewTab(curFile, zoomFactors.at(curTab).toFloat()); 343 } else if (curTab + searchIsAttached <= tabToShow) 344 --tabToShow; 345 } 346 347 tabWidget->setCurrentIndex(tabToShow); 496 348 } 497 349 498 350 bool CentralWidget::hasSelection() const 499 351 { 352 500 353 const HelpViewer *viewer = currentHelpViewer(); 501 354 return viewer ? viewer->hasSelection() : false; … … 504 357 QUrl CentralWidget::currentSource() const 505 358 { 359 506 360 const HelpViewer *viewer = currentHelpViewer(); 507 361 if (viewer) … … 513 367 QString CentralWidget::currentTitle() const 514 368 { 369 515 370 const HelpViewer *viewer = currentHelpViewer(); 516 371 if (viewer) … … 522 377 void CentralWidget::copySelection() 523 378 { 379 524 380 HelpViewer *viewer = currentHelpViewer(); 525 381 if (viewer) … … 529 385 void CentralWidget::showTextSearch() 530 386 { 531 findBar->show(); 532 findWidget->editFind->selectAll(); 533 findWidget->editFind->setFocus(Qt::ShortcutFocusReason); 387 TRACE_OBJ 388 findWidget->show(); 534 389 } 535 390 536 391 void CentralWidget::initPrinter() 537 392 { 393 538 394 #ifndef QT_NO_PRINTER 539 395 if (!printer) … … 544 400 void CentralWidget::print() 545 401 { 402 546 403 #ifndef QT_NO_PRINTER 547 404 HelpViewer *viewer = currentHelpViewer(); … … 551 408 initPrinter(); 552 409 553 QPrintDialog *dlg = new QPrintDialog(printer, this);410 QPrintDialog g(printer, this); 554 411 #if defined(QT_NO_WEBKIT) 555 412 if (viewer->textCursor().hasSelection()) 556 dlg ->addEnabledOption(QAbstractPrintDialog::PrintSelection);557 #endif 558 dlg ->addEnabledOption(QAbstractPrintDialog::PrintPageRange);559 dlg ->addEnabledOption(QAbstractPrintDialog::PrintCollateCopies);560 dlg ->setWindowTitle(tr("Print Document"));561 if (dlg ->exec() == QDialog::Accepted) {413 dlgaddEnabledOption(QAbstractPrintDialog::PrintSelection); 414 #endif 415 dlgaddEnabledOption(QAbstractPrintDialog::PrintPageRange); 416 dlgaddEnabledOption(QAbstractPrintDialog::PrintCollateCopies); 417 dlgsetWindowTitle(tr("Print Document")); 418 if (dlgexec() == QDialog::Accepted) { 562 419 viewer->print(printer); 563 420 } 564 delete dlg;565 421 #endif 566 422 } … … 568 424 void CentralWidget::printPreview() 569 425 { 426 570 427 #ifndef QT_NO_PRINTER 571 428 initPrinter(); … … 579 436 void CentralWidget::printPreview(QPrinter *p) 580 437 { 438 581 439 #ifndef QT_NO_PRINTER 582 440 HelpViewer *viewer = currentHelpViewer(); … … 588 446 void CentralWidget::pageSetup() 589 447 { 448 590 449 #ifndef QT_NO_PRINTER 591 450 initPrinter(); … … 597 456 bool CentralWidget::isHomeAvailable() const 598 457 { 458 599 459 return currentHelpViewer() ? true : false; 600 460 } … … 602 462 void CentralWidget::home() 603 463 { 464 604 465 HelpViewer *viewer = currentHelpViewer(); 605 466 if (viewer) … … 609 470 bool CentralWidget::isForwardAvailable() const 610 471 { 472 611 473 const HelpViewer *viewer = currentHelpViewer(); 612 474 if (viewer) … … 618 480 void CentralWidget::forward() 619 481 { 482 620 483 HelpViewer *viewer = currentHelpViewer(); 621 484 if (viewer) … … 625 488 bool CentralWidget::isBackwardAvailable() const 626 489 { 490 627 491 const HelpViewer *viewer = currentHelpViewer(); 628 492 if (viewer) … … 634 498 void CentralWidget::backward() 635 499 { 500 636 501 HelpViewer *viewer = currentHelpViewer(); 637 502 if (viewer) … … 642 507 QList<QAction*> CentralWidget::globalActions() const 643 508 { 509 644 510 return globalActionList; 645 511 } … … 647 513 void CentralWidget::setGlobalActions(const QList<QAction*> &actions) 648 514 { 515 649 516 globalActionList = actions; 650 517 } … … 652 519 void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) 653 520 { 654 HelpViewer *viewer; 655 656 #if defined(QT_NO_WEBKIT) 657 viewer = currentHelpViewer(); 658 if (viewer && viewer->launchedWithExternalApp(url)) 659 return; 660 #endif 661 662 viewer = new HelpViewer(helpEngine, this); 521 TRACE_OBJ 522 if (HelpViewer *viewer = currentHelpViewer()) { 523 if (viewer->launchWithExternalApp(url)) 524 return; 525 } 526 527 HelpViewer *viewer = new HelpViewer(this, zoom); 663 528 viewer->installEventFilter(this); 664 529 viewer->setSource(url); … … 666 531 tabWidget->setCurrentIndex(tabWidget->addTab(viewer, 667 532 quoteTabTitle(viewer->documentTitle()))); 668 669 QFont font;670 getBrowserFontFor(viewer, &font);671 672 #if defined(QT_NO_WEBKIT)673 font.setPointSize((int)(font.pointSize() + zoom));674 setBrowserFontFor(viewer, font);675 viewer->setZoom((int)zoom);676 #else677 setBrowserFontFor(viewer, font);678 viewer->setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom);679 #endif680 681 533 connectSignals(); 682 534 } … … 684 536 HelpViewer *CentralWidget::newEmptyTab() 685 537 { 686 HelpViewer *viewer = new HelpViewer(helpEngine, this); 538 TRACE_OBJ 539 HelpViewer *viewer = new HelpViewer(this); 687 540 viewer->installEventFilter(this); 688 541 viewer->setFocus(Qt::OtherFocusReason); … … 696 549 } 697 550 698 void CentralWidget::findCurrentText(const QString &text)699 {700 find(text, true);701 }702 703 551 void CentralWidget::connectSignals() 704 552 { 553 705 554 const HelpViewer *viewer = currentHelpViewer(); 706 555 if (viewer) { … … 717 566 connect(viewer, SIGNAL(sourceChanged(QUrl)), this, 718 567 SLOT(setTabTitle(QUrl))); 719 } 720 } 721 722 HelpViewer *CentralWidget::currentHelpViewer() const 723 { 568 connect(viewer, SIGNAL(printRequested()), this, SLOT(print())); 569 } 570 } 571 572 HelpViewer* CentralWidget::viewerAt(int index) const 573 { 574 TRACE_OBJ 575 return qobject_cast<HelpViewer*>(tabWidget->widget(index)); 576 } 577 578 HelpViewer* CentralWidget::currentHelpViewer() const 579 { 580 TRACE_OBJ 724 581 return qobject_cast<HelpViewer*>(tabWidget->currentWidget()); 725 582 } … … 727 584 void CentralWidget::activateTab(bool onlyHelpViewer) 728 585 { 586 729 587 if (currentHelpViewer()) { 730 588 currentHelpViewer()->setFocus(); … … 740 598 void CentralWidget::setTabTitle(const QUrl &url) 741 599 { 600 742 601 Q_UNUSED(url) 743 602 #if !defined(QT_NO_WEBKIT) … … 761 620 void CentralWidget::currentPageChanged(int index) 762 621 { 622 763 623 const HelpViewer *viewer = currentHelpViewer(); 764 624 if (viewer) … … 776 636 void CentralWidget::showTabBarContextMenu(const QPoint &point) 777 637 { 638 778 639 HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, point); 779 640 if (!viewer) … … 823 684 824 685 if (pickedAction == newBookmark) 825 emit add NewBookmark(viewer->documentTitle(), viewer->source().toString());686 emit addBookmark(viewer->documentTitle(), viewer->source().toString()); 826 687 } 827 688 828 689 bool CentralWidget::eventFilter(QObject *object, QEvent *e) 829 690 { 691 830 692 if (e->type() == QEvent::KeyPress) { 831 693 QKeyEvent *ke = static_cast<QKeyEvent*>(e); … … 833 695 default: { 834 696 return QWidget::eventFilter(object, e); 835 } break;836 837 case Qt::Key_Escape: {838 if (findWidget->editFind == object) {839 findBar->hide();840 if (HelpViewer *viewer = currentHelpViewer())841 viewer->setFocus();842 }843 697 } break; 844 698 … … 883 737 void CentralWidget::keyPressEvent(QKeyEvent *e) 884 738 { 739 885 740 const QString &text = e->text(); 886 741 if (text.startsWith(QLatin1Char('/'))) { 887 if (!findBar->isVisible()) { 888 findBar->show(); 889 findWidget->editFind->clear(); 742 if (!findWidget->isVisible()) { 743 findWidget->showAndClear(); 890 744 } else { 891 findWidget-> editFind->selectAll();745 findWidget->(); 892 746 } 893 findWidget->editFind->setFocus(); 894 return; 895 } 896 QWidget::keyPressEvent(e); 747 } else { 748 QWidget::keyPressEvent(e); 749 } 750 } 751 752 void CentralWidget::findNext() 753 { 754 TRACE_OBJ 755 find(findWidget->text(), true); 756 } 757 758 void CentralWidget::findPrevious() 759 { 760 TRACE_OBJ 761 find(findWidget->text(), false); 897 762 } 898 763 899 764 void CentralWidget::find(const QString &ttf, bool forward) 900 765 { 901 QPalette p = findWidget->editFind->palette(); 902 p.setColor(QPalette::Active, QPalette::Base, Qt::white); 903 766 TRACE_OBJ 904 767 bool found = false; 905 906 768 #if defined(QT_NO_WEBKIT) 907 769 found = findInTextBrowser(ttf, forward); … … 910 772 #endif 911 773 912 if (!found && !ttf.isEmpty())913 p.setColor(QPalette::Active, QPalette::Base, QColor(255, 102, 102));774 if (!found && ttf.isEmpty()) 775 914 776 915 777 if (!findWidget->isVisible()) 916 778 findWidget->show(); 917 findWidget-> editFind->setPalette(p);779 findWidget->); 918 780 } 919 781 920 782 bool CentralWidget::findInWebPage(const QString &ttf, bool forward) 921 783 { 784 922 785 #if !defined(QT_NO_WEBKIT) 923 786 if (HelpViewer *viewer = currentHelpViewer()) { … … 928 791 options |= QWebPage::FindBackward; 929 792 930 if (findWidget->c heckCase->isChecked())793 if (findWidget->c()) 931 794 options |= QWebPage::FindCaseSensitively; 932 795 933 796 found = viewer->findText(ttf, options); 934 findWidget-> labelWrapped->hide();797 findWidget->); 935 798 936 799 if (!found) { … … 938 801 found = viewer->findText(ttf, options); 939 802 if (found) 940 findWidget-> labelWrapped->show();803 findWidget->); 941 804 } 942 805 } 943 806 // force highlighting of all other matches, also when empty (clear) 944 807 options = QWebPage::HighlightAllOccurrences; 808 809 945 810 viewer->findText(QLatin1String(""), options); 946 811 viewer->findText(ttf, options); … … 950 815 // this needs to stay, case for active search results page 951 816 return findInTextBrowser(ttf, forward); 817 818 819 952 820 #endif 953 821 return false; … … 956 824 bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) 957 825 { 826 958 827 QTextBrowser *browser = qobject_cast<QTextBrowser*>(currentHelpViewer()); 959 828 if (tabWidget->currentWidget() == m_searchWidget) … … 979 848 options |= QTextDocument::FindBackward; 980 849 981 if (findWidget->c heckCase->isChecked())850 if (findWidget->c()) 982 851 options |= QTextDocument::FindCaseSensitively; 983 852 984 if (findWidget->checkWholeWords->isChecked()) 985 options |= QTextDocument::FindWholeWords; 986 987 findWidget->labelWrapped->hide(); 853 findWidget->setTextWrappedVisible(false); 988 854 989 855 bool found = true; … … 998 864 newCursor = cursor; 999 865 } else { 1000 findWidget-> labelWrapped->show();866 findWidget->); 1001 867 } 1002 868 } … … 1007 873 void CentralWidget::updateBrowserFont() 1008 874 { 1009 QFont font;1010 bool searchAttached = searchWidgetAttached();875 876 bool searchAttached = searchWidgetAttached(); 1011 877 if (searchAttached) { 1012 getBrowserFontFor(m_searchWidget, &font); 1013 setBrowserFontFor(m_searchWidget, font); 1014 } 1015 1016 int i = searchAttached ? 1 : 0; 1017 getBrowserFontFor(tabWidget->widget(i), &font); 1018 for ( ; i < tabWidget->count(); ++i) 1019 setBrowserFontFor(tabWidget->widget(i), font); 878 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 879 m_searchWidget->setFont(helpEngine.usesBrowserFont() 880 ? helpEngine.browserFont() : qApp->font()); 881 } 882 883 const int count = tabWidget->count(); 884 if (HelpViewer* viewer = viewerAt(count - 1)) { 885 const QFont &font = viewer->viewerFont(); 886 for (int i = searchAttached ? 1 : 0; i < count; ++i) 887 viewerAt(i)->setViewerFont(font); 888 } 889 } 890 891 bool CentralWidget::searchWidgetAttached() const 892 { 893 TRACE_OBJ 894 return m_searchWidget && m_searchWidget->isAttached(); 1020 895 } 1021 896 1022 897 void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine) 1023 898 { 899 1024 900 if (m_searchWidget) 1025 901 return; … … 1031 907 SLOT(setSourceFromSearchInNewTab(QUrl))); 1032 908 1033 QFont font;1034 getBrowserFontFor(m_searchWidget, &font);1035 setBrowserFontFor(m_searchWidget, font);909 ; 910 911 ); 1036 912 } 1037 913 1038 914 void CentralWidget::activateSearchWidget(bool updateLastTabPage) 1039 915 { 916 1040 917 if (!m_searchWidget) 1041 createSearchWidget( helpEngine->searchEngine());918 createSearchWidget(searchEngine()); 1042 919 1043 920 if (!m_searchWidget->isAttached()) { … … 1055 932 void CentralWidget::removeSearchWidget() 1056 933 { 934 1057 935 if (searchWidgetAttached()) { 1058 936 tabWidget->removeTab(0); … … 1063 941 int CentralWidget::availableHelpViewer() const 1064 942 { 943 1065 944 int count = tabWidget->count(); 1066 945 if (searchWidgetAttached()) … … 1071 950 bool CentralWidget::enableTabCloseAction() const 1072 951 { 952 1073 953 int minTabCount = 1; 1074 954 if (searchWidgetAttached()) … … 1080 960 QString CentralWidget::quoteTabTitle(const QString &title) const 1081 961 { 962 1082 963 QString s = title; 1083 964 return s.replace(QLatin1Char('&'), QLatin1String("&&")); … … 1087 968 CentralWidget::setSourceFromSearch(const QUrl &url) 1088 969 { 970 1089 971 setSource(url); 1090 972 #if defined(QT_NO_WEBKIT) … … 1099 981 CentralWidget::setSourceFromSearchInNewTab(const QUrl &url) 1100 982 { 983 1101 984 setSourceInNewTab(url); 1102 985 #if defined(QT_NO_WEBKIT) … … 1111 994 CentralWidget::highlightSearchTerms() 1112 995 { 996 1113 997 HelpViewer *viewer = currentHelpViewer(); 1114 998 if (!viewer) 1115 999 return; 1116 1000 1117 QHelpSearchEngine *searchEngine = helpEngine->searchEngine(); 1001 QHelpSearchEngine *searchEngine = 1002 HelpEngineWrapper::instance().searchEngine(); 1118 1003 QList<QHelpSearchQuery> queryList = searchEngine->query(); 1119 1004 … … 1127 1012 case QHelpSearchQuery::ATLEAST: 1128 1013 foreach (QString term, query.wordList) 1129 terms.append(term.remove(QLatin1 String("\"")));1014 terms.append(term.remove(QLatin1))); 1130 1015 } 1131 1016 } … … 1175 1060 } 1176 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1177 1086 void CentralWidget::closeTabAt(int index) 1178 1087 { 1088 1179 1089 HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(index)); 1180 1090 tabWidget->removeTab(index); … … 1184 1094 QMap<int, QString> CentralWidget::currentSourceFileList() const 1185 1095 { 1096 1186 1097 QMap<int, QString> sourceList; 1187 for (int i = 1; i < tabWidget->count(); ++i) {1098 for (int i = ; i < tabWidget->count(); ++i) { 1188 1099 HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i)); 1189 1100 if (viewer && viewer->source().isValid()) … … 1193 1104 } 1194 1105 1195 void CentralWidget::getBrowserFontFor(QWidget *viewer, QFont *font)1196 {1197 const QLatin1String key("useBrowserFont");1198 if (!helpEngine->customValue(key, false).toBool()) {1199 *font = qApp->font(); // case for QTextBrowser and SearchWidget1200 #if !defined(QT_NO_WEBKIT)1201 QWebView *view = qobject_cast<QWebView*> (viewer);1202 if (view) {1203 QWebSettings *settings = QWebSettings::globalSettings();1204 *font = QFont(settings->fontFamily(QWebSettings::StandardFont),1205 settings->fontSize(QWebSettings::DefaultFontSize));1206 }1207 #endif1208 } else {1209 *font = qVariantValue<QFont>(helpEngine->customValue(1210 QLatin1String("browserFont")));1211 }1212 }1213 1214 void CentralWidget::setBrowserFontFor(QWidget *widget, const QFont &font)1215 {1216 #if !defined(QT_NO_WEBKIT)1217 QWebView *view = qobject_cast<QWebView*> (widget);1218 if (view) {1219 QWebSettings *settings = view->settings();1220 settings->setFontFamily(QWebSettings::StandardFont, font.family());1221 settings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());1222 } else if (widget && widget->font() != font) {1223 widget->setFont(font);1224 }1225 #else1226 if (widget && widget->font() != font)1227 widget->setFont(font);1228 #endif1229 }1230 1231 1106 QT_END_NAMESPACE -
trunk/tools/assistant/tools/assistant/centralwidget.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 42 41 #ifndef CENTRALWIDGET_H 43 42 #define CENTRALWIDGET_H 44 43 45 44 #include <QtCore/QUrl> 46 #include <QtCore/QPoint>47 #include <QtCore/QObject>48 49 45 #include <QtGui/QWidget> 50 51 #include "searchwidget.h"52 46 53 47 QT_BEGIN_NAMESPACE 54 48 55 class QEvent; 56 class QLabel; 57 class QAction; 58 class QCheckBox; 59 class QLineEdit; 60 class QTextBrowser; 61 class QToolButton; 62 49 class FindWidget; 63 50 class HelpViewer; 51 52 64 53 class QTabWidget; 65 class QHelpEngine; 66 class CentralWidget; 67 class PrintHelper; 68 class MainWindow; 69 70 class QHelpSearchEngine; 71 72 class FindWidget : public QWidget 73 { 74 Q_OBJECT 75 76 public: 77 FindWidget(QWidget *parent = 0); 78 ~FindWidget(); 79 80 signals: 81 void findNext(); 82 void findPrevious(); 83 84 protected: 85 void hideEvent(QHideEvent* event); 86 void showEvent(QShowEvent * event); 87 88 private slots: 89 void updateButtons(); 90 91 private: 92 QToolButton* setupToolButton(const QString &text, const QString &icon); 93 94 private: 95 QLineEdit *editFind; 96 QCheckBox *checkCase; 97 QLabel *labelWrapped; 98 QToolButton *toolNext; 99 QToolButton *toolClose; 100 QToolButton *toolPrevious; 101 QCheckBox *checkWholeWords; 102 103 QPalette appPalette; 104 friend class CentralWidget; 105 }; 54 class SearchWidget; 106 55 107 56 class CentralWidget : public QWidget … … 110 59 111 60 public: 112 CentralWidget( QHelpEngine *engine,MainWindow *parent);61 CentralWidget(MainWindow *parent); 113 62 ~CentralWidget(); 114 63 … … 122 71 QList<QAction*> globalActions() const; 123 72 void setGlobalActions(const QList<QAction*> &actions); 73 74 124 75 HelpViewer *currentHelpViewer() const; 125 void activateTab(bool onlyHelpViewer = false);126 76 127 bool searchWidgetAttached() const { 128 return m_searchWidget && m_searchWidget->isAttached(); 129 } 77 bool searchWidgetAttached() const; 130 78 void createSearchWidget(QHelpSearchEngine *searchEngine); 131 79 void activateSearchWidget(bool updateLastTabPage = false); … … 135 83 bool enableTabCloseAction() const; 136 84 85 137 86 void closeTabAt(int index); 138 87 QMap<int, QString> currentSourceFileList() const; … … 143 92 void zoomIn(); 144 93 void zoomOut(); 145 void findNext();146 94 void nextPage(); 147 95 void resetZoom(); 148 96 void previousPage(); 149 void findPrevious();150 97 void copySelection(); 151 98 void showTextSearch(); … … 156 103 void setSource(const QUrl &url); 157 104 void setSourceInNewTab(const QUrl &url, qreal zoom = 0.0); 158 void findCurrentText(const QString &text);159 105 HelpViewer *newEmptyTab(); 160 106 void home(); 161 107 void forward(); 162 108 void backward(); 109 110 111 112 113 114 163 115 164 116 signals: … … 169 121 void forwardAvailable(bool available); 170 122 void backwardAvailable(bool available); 171 void add NewBookmark(const QString &title, const QString &url);123 void addBookmark(const QString &title, const QString &url); 172 124 173 125 protected: … … 188 140 void connectSignals(); 189 141 bool eventFilter(QObject *object, QEvent *e); 190 void find(const QString &ttf, bool forward);191 142 bool findInWebPage(const QString &ttf, bool forward); 192 143 bool findInTextBrowser(const QString &ttf, bool forward); … … 195 146 void setLastShownPages(); 196 147 197 void getBrowserFontFor(QWidget* viewer, QFont *font);198 void setBrowserFontFor(QWidget *widget, const QFont &font);199 200 148 private: 201 149 int lastTabPage; 202 QString collectionFile;203 150 QList<QAction*> globalActionList; 204 151 205 QWidget *findBar;206 152 QTabWidget *tabWidget; 207 153 FindWidget *findWidget; 208 QHelpEngine *helpEngine;209 154 QPrinter *printer; 210 155 bool usesDefaultCollection; -
trunk/tools/assistant/tools/assistant/cmdlineparser.cpp
r697 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include <QtCore/QFileInfo> 44 43 45 #include <QtGui/QMessageBox> 44 46 … … 47 49 QT_BEGIN_NAMESPACE 48 50 49 #define CHECK_NEXT_ARG \ 50 ++i < arguments.count() && !arguments.at(i).startsWith(QLatin1String("-")) 51 52 CmdLineParser::CmdLineParser() 53 : m_enableRemoteControl(false), 54 m_contents(Untouched), 55 m_index(Untouched), 56 m_bookmarks(Untouched), 57 m_search(Untouched), 58 m_register(None), 59 m_removeSearchIndex(false), 60 m_copy(false), 61 m_quiet(false) 62 { 63 m_helpMessage = QLatin1String( 51 static const char helpMessage[] = QT_TRANSLATE_NOOP("CmdLineParser", 64 52 "Usage: assistant [Options]\n\n" 65 53 "-collectionFile file Uses the specified collection\n" … … 86 74 "-setCurrentFilter filter Set the filter as the active filter.\n" 87 75 "-remove-search-index Removes the full text search index.\n" 76 88 77 "-quiet Does not display any error or\n" 89 78 " status message.\n" 90 79 "-help Displays this help.\n" 91 80 ); 92 } 93 94 CmdLineParser::Result CmdLineParser::parse(const QStringList &arguments) 95 { 96 QString error; 81 82 83 CmdLineParser::CmdLineParser(const QStringList &arguments) 84 : m_pos(0), 85 m_enableRemoteControl(false), 86 m_contents(Untouched), 87 m_index(Untouched), 88 m_bookmarks(Untouched), 89 m_search(Untouched), 90 m_register(None), 91 m_removeSearchIndex(false), 92 m_rebuildSearchIndex(false), 93 m_quiet(false) 94 { 95 TRACE_OBJ 96 for (int i = 1; i < arguments.count(); ++i) { 97 const QString &arg = arguments.at(i); 98 if (arg.toLower() == "-quiet") 99 m_quiet = true; 100 else 101 m_arguments.append(arg); 102 } 103 } 104 105 CmdLineParser::Result CmdLineParser::parse() 106 { 107 TRACE_OBJ 97 108 bool showHelp = false; 98 109 99 for (int j=1; j<arguments.count(); ++j) { 100 if (arguments.at(j).toLower() == QLatin1String("-quiet")) { 101 m_quiet = true; 102 break; 103 } 104 } 105 106 for (int i=1; i<arguments.count(); ++i) { 107 QString arg = arguments.at(i).toLower(); 108 if (arg == QLatin1String("-collectionfile")) { 109 if (CHECK_NEXT_ARG) { 110 m_collectionFile = getFileName(arguments.at(i)); 111 if (m_collectionFile.isEmpty()) { 112 error = QObject::tr("The specified collection file does not exist!"); 113 break; 114 } 115 } else { 116 error = QObject::tr("Missing collection file!"); 117 break; 118 } 119 } else if (arg == QLatin1String("-showurl")) { 120 if (CHECK_NEXT_ARG) { 121 QUrl url(arguments.at(i)); 122 if (url.isValid()) { 123 m_url = url; 124 } else { 125 error = QObject::tr("Invalid URL!"); 126 break; 127 } 128 } else { 129 error = QObject::tr("Missing URL!"); 130 break; 131 } 132 } else if (arg == QLatin1String("-enableremotecontrol")) { 110 while (m_error.isEmpty() && hasMoreArgs()) { 111 const QString &arg = nextArg().toLower(); 112 if (arg == QLatin1String("-collectionfile")) 113 handleCollectionFileOption(); 114 else if (arg == QLatin1String("-showurl")) 115 handleShowUrlOption(); 116 else if (arg == QLatin1String("-enableremotecontrol")) 133 117 m_enableRemoteControl = true; 134 } else if (arg == QLatin1String("-show")) { 135 if (CHECK_NEXT_ARG) { 136 arg = arguments.at(i).toLower(); 137 if (arg == QLatin1String("contents")) { 138 m_contents = Show; 139 } else if (arg == QLatin1String("index")) { 140 m_index = Show; 141 } else if (arg == QLatin1String("bookmarks")) { 142 m_bookmarks = Show; 143 } else if (arg == QLatin1String("search")) { 144 m_search = Show; 145 } else { 146 error = QObject::tr("Unknown widget: %1").arg(arg); 147 break; 148 } 149 } else { 150 error = QObject::tr("Missing widget!"); 151 break; 152 } 153 } else if (arg == QLatin1String("-hide")) { 154 if (CHECK_NEXT_ARG) { 155 arg = arguments.at(i).toLower(); 156 if (arg == QLatin1String("contents")) { 157 m_contents = Hide; 158 } else if (arg == QLatin1String("index")) { 159 m_index = Hide; 160 } else if (arg == QLatin1String("bookmarks")) { 161 m_bookmarks = Hide; 162 } else if (arg == QLatin1String("search")) { 163 m_search = Hide; 164 } else { 165 error = QObject::tr("Unknown widget: %1").arg(arg); 166 break; 167 } 168 } else { 169 error = QObject::tr("Missing widget!"); 170 break; 171 } 172 } else if (arg == QLatin1String("-activate")) { 173 if (CHECK_NEXT_ARG) { 174 arg = arguments.at(i).toLower(); 175 if (arg == QLatin1String("contents")) { 176 m_contents = Activate; 177 } else if (arg == QLatin1String("index")) { 178 m_index = Activate; 179 } else if (arg == QLatin1String("bookmarks")) { 180 m_bookmarks = Activate; 181 } else if (arg == QLatin1String("search")) { 182 m_search = Activate; 183 } else { 184 error = QObject::tr("Unknown widget: %1").arg(arg); 185 break; 186 } 187 } else { 188 error = QObject::tr("Missing widget!"); 189 break; 190 } 191 } else if (arg == QLatin1String("-register")) { 192 if (CHECK_NEXT_ARG) { 193 m_helpFile = getFileName(arguments.at(i)); 194 if (m_helpFile.isEmpty()) { 195 error = QObject::tr("The specified Qt help file does not exist!"); 196 break; 197 } 198 m_register = Register; 199 } else { 200 error = QObject::tr("Missing help file!"); 201 break; 202 } 203 } else if (arg == QLatin1String("-unregister")) { 204 if (CHECK_NEXT_ARG) { 205 m_helpFile = getFileName(arguments.at(i)); 206 if (m_helpFile.isEmpty()) { 207 error = QObject::tr("The specified Qt help file does not exist!"); 208 break; 209 } 210 m_register = Unregister; 211 } else { 212 error = QObject::tr("Missing help file!"); 213 break; 214 } 215 } else if (arg == QLatin1String("-setcurrentfilter")) { 216 if (CHECK_NEXT_ARG) { 217 m_currentFilter = arguments.at(i); 218 } else { 219 error = QObject::tr("Missing filter argument!"); 220 break; 221 } 222 } else if (arg == QLatin1String("-remove-search-index")) { 118 else if (arg == QLatin1String("-show")) 119 handleShowOption(); 120 else if (arg == QLatin1String("-hide")) 121 handleHideOption(); 122 else if (arg == QLatin1String("-activate")) 123 handleActivateOption(); 124 else if (arg == QLatin1String("-register")) 125 handleRegisterOption(); 126 else if (arg == QLatin1String("-unregister")) 127 handleUnregisterOption(); 128 else if (arg == QLatin1String("-setcurrentfilter")) 129 handleSetCurrentFilterOption(); 130 else if (arg == QLatin1String("-remove-search-index")) 223 131 m_removeSearchIndex = true; 224 } else if (arg == QLatin1String("-quiet")) {225 continue;226 } else if (arg == QLatin1String("-help")) {132 133 ue; 134 227 135 showHelp = true; 228 } else if (arg == QLatin1String("-copy")) { 229 m_copy = true; 230 } else { 231 error = QObject::tr("Unknown option: %1").arg(arg); 232 break; 233 } 234 } 235 236 if (!error.isEmpty()) { 237 showMessage(error + QLatin1String("\n\n\n") + m_helpMessage, true); 136 else 137 m_error = tr("Unknown option: %1").arg(arg); 138 } 139 140 if (!m_error.isEmpty()) { 141 showMessage(m_error + QLatin1String("\n\n\n") + tr(helpMessage), true); 238 142 return Error; 239 143 } else if (showHelp) { 240 showMessage( m_helpMessage, false);144 showMessage(, false); 241 145 return Help; 242 146 } … … 244 148 } 245 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 246 266 QString CmdLineParser::getFileName(const QString &fileName) 247 267 { 268 248 269 QFileInfo fi(fileName); 249 270 if (!fi.exists()) … … 254 275 void CmdLineParser::showMessage(const QString &msg, bool error) 255 276 { 277 256 278 if (m_quiet) 257 279 return; 258 280 #if defined(Q_OS_WIN) || defined(Q_OS_OS2) 259 QString s = QLatin1String("<pre>") + msg +QLatin1String("</pre>");281 QString QLatin1String("</pre>"); 260 282 if (error) 261 QMessageBox::critical(0, QObject::tr("Qt Assistant"), s);283 QMessageBox::critical(0, ); 262 284 else 263 QMessageBox::information(0, QObject::tr("Qt Assistant"), s);285 QMessageBox::information(0, ); 264 286 #else 265 287 fprintf(error ? stderr : stdout, "%s\n", qPrintable(msg)); … … 269 291 void CmdLineParser::setCollectionFile(const QString &file) 270 292 { 293 271 294 m_collectionFile = file; 272 295 } … … 274 297 QString CmdLineParser::collectionFile() const 275 298 { 299 276 300 return m_collectionFile; 277 301 } 278 302 303 304 305 306 307 308 309 279 310 QUrl CmdLineParser::url() const 280 311 { 312 281 313 return m_url; 282 314 } … … 284 316 bool CmdLineParser::enableRemoteControl() const 285 317 { 318 286 319 return m_enableRemoteControl; 287 320 } … … 289 322 CmdLineParser::ShowState CmdLineParser::contents() const 290 323 { 324 291 325 return m_contents; 292 326 } … … 294 328 CmdLineParser::ShowState CmdLineParser::index() const 295 329 { 330 296 331 return m_index; 297 332 } … … 299 334 CmdLineParser::ShowState CmdLineParser::bookmarks() const 300 335 { 336 301 337 return m_bookmarks; 302 338 } … … 304 340 CmdLineParser::ShowState CmdLineParser::search() const 305 341 { 342 306 343 return m_search; 307 344 } … … 309 346 QString CmdLineParser::currentFilter() const 310 347 { 348 311 349 return m_currentFilter; 312 350 } … … 314 352 bool CmdLineParser::removeSearchIndex() const 315 353 { 354 316 355 return m_removeSearchIndex; 317 356 } 318 357 358 359 360 361 362 363 319 364 CmdLineParser::RegisterState CmdLineParser::registerRequest() const 320 365 { 366 321 367 return m_register; 322 368 } … … 324 370 QString CmdLineParser::helpFile() const 325 371 { 372 326 373 return m_helpFile; 327 374 } -
trunk/tools/assistant/tools/assistant/cmdlineparser.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 43 43 #define CMDLINEPARSER_H 44 44 45 45 46 #include <QtCore/QStringList> 46 47 #include <QtCore/QUrl> … … 50 51 class CmdLineParser 51 52 { 53 52 54 public: 53 55 enum Result {Ok, Help, Error}; … … 55 57 enum RegisterState {None, Register, Unregister}; 56 58 57 CmdLineParser( );58 Result parse( const QStringList &arguments);59 CmdLineParser(); 60 Result parse(); 59 61 60 62 void setCollectionFile(const QString &file); 61 63 QString collectionFile() const; 64 62 65 QString cloneFile() const; 63 66 QUrl url() const; … … 69 72 QString currentFilter() const; 70 73 bool removeSearchIndex() const; 74 71 75 RegisterState registerRequest() const; 72 76 QString helpFile() const; 73 74 bool copy() const { return m_copy; }75 77 76 78 void showMessage(const QString &msg, bool error); … … 78 80 private: 79 81 QString getFileName(const QString &fileName); 82 83 84 85 86 87 88 89 90 91 92 93 80 94 81 QString m_helpMessage; 95 QStringList m_arguments; 96 int m_pos; 82 97 QString m_collectionFile; 83 98 QString m_cloneFile; … … 93 108 QString m_currentFilter; 94 109 bool m_removeSearchIndex; 95 bool m_ copy;110 bool m_; 96 111 bool m_quiet; 112 97 113 }; 98 114 -
trunk/tools/assistant/tools/assistant/contentwindow.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "contentwindow.h" 43 44 #include "centralwidget.h" 45 46 44 47 45 48 #include <QtGui/QLayout> … … 47 50 #include <QtGui/QMenu> 48 51 49 #include <QtHelp/QHelpEngine>50 52 #include <QtHelp/QHelpContentWidget> 51 53 52 54 QT_BEGIN_NAMESPACE 53 55 54 ContentWindow::ContentWindow(QHelpEngine *helpEngine) 55 : m_helpEngine(helpEngine) 56 , m_contentWidget(0) 56 ContentWindow::ContentWindow() 57 : m_contentWidget(HelpEngineWrapper::instance().contentWidget()) 57 58 , m_expandDepth(-2) 58 59 { 59 m_contentWidget = m_helpEngine->contentWidget();60 60 61 m_contentWidget->viewport()->installEventFilter(this); 61 62 m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu); … … 77 78 ContentWindow::~ContentWindow() 78 79 { 80 79 81 } 80 82 81 83 bool ContentWindow::syncToContent(const QUrl& url) 82 84 { 85 83 86 QModelIndex idx = m_contentWidget->indexOf(url); 84 87 if (!idx.isValid()) … … 90 93 void ContentWindow::expandTOC() 91 94 { 95 96 92 97 if (m_expandDepth > -2) { 93 98 expandToDepth(m_expandDepth); … … 98 103 void ContentWindow::expandToDepth(int depth) 99 104 { 105 106 100 107 m_expandDepth = depth; 101 108 if (depth == -1) 102 109 m_contentWidget->expandAll(); 110 111 103 112 else 104 m_contentWidget->expandToDepth(depth );113 m_contentWidget->expandToDepth(depth); 105 114 } 106 115 107 116 void ContentWindow::focusInEvent(QFocusEvent *e) 108 117 { 118 109 119 if (e->reason() != Qt::MouseFocusReason) 110 120 m_contentWidget->setFocus(); … … 113 123 void ContentWindow::keyPressEvent(QKeyEvent *e) 114 124 { 125 115 126 if (e->key() == Qt::Key_Escape) 116 127 emit escapePressed(); … … 119 130 bool ContentWindow::eventFilter(QObject *o, QEvent *e) 120 131 { 132 121 133 if (m_contentWidget && o == m_contentWidget->viewport() 122 134 && e->type() == QEvent::MouseButtonRelease) { 123 135 QMouseEvent *me = static_cast<QMouseEvent*>(e); 124 QModelIndex index = m_contentWidget->indexAt(me->pos()); 136 const QModelIndex &index = m_contentWidget->indexAt(me->pos()); 137 if (!index.isValid()) 138 return QWidget::eventFilter(o, e); 139 140 const Qt::MouseButtons button = me->button(); 125 141 QItemSelectionModel *sm = m_contentWidget->selectionModel(); 126 127 Qt::MouseButtons button = me->button(); 128 if (index.isValid() && (sm && sm->isSelected(index))) { 142 if (sm->isSelected(index)) { 129 143 if ((button == Qt::LeftButton && (me->modifiers() & Qt::ControlModifier)) 130 144 || (button == Qt::MidButton)) { … … 133 147 if (contentModel) { 134 148 QHelpContentItem *itm = contentModel->contentItemAt(index); 135 if (itm && !isPdfFile(itm))149 if (itm && )) 136 150 CentralWidget::instance()->setSourceInNewTab(itm->url()); 137 151 } … … 147 161 void ContentWindow::showContextMenu(const QPoint &pos) 148 162 { 163 149 164 if (!m_contentWidget->indexAt(pos).isValid()) 150 165 return; … … 158 173 QAction *curTab = menu.addAction(tr("Open Link")); 159 174 QAction *newTab = menu.addAction(tr("Open Link in New Tab")); 160 if ( isPdfFile(itm))175 if ()) 161 176 newTab->setEnabled(false); 162 177 … … 172 187 void ContentWindow::itemClicked(const QModelIndex &index) 173 188 { 189 174 190 QHelpContentModel *contentModel = 175 191 qobject_cast<QHelpContentModel*>(m_contentWidget->model()); 176 192 177 193 if (contentModel) { 178 QHelpContentItem *itm = contentModel->contentItemAt(index); 179 if (itm) 180 emit linkActivated(itm->url()); 194 if (QHelpContentItem *itm = contentModel->contentItemAt(index)) { 195 const QUrl &url = itm->url(); 196 if (url != CentralWidget::instance()->currentSource()) 197 emit linkActivated(url); 198 } 181 199 } 182 200 } 183 201 184 bool ContentWindow::isPdfFile(QHelpContentItem *item) const185 {186 const QString &path = item->url().path();187 return path.endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive);188 }189 190 202 QT_END_NAMESPACE -
trunk/tools/assistant/tools/assistant/contentwindow.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 58 58 59 59 public: 60 ContentWindow( QHelpEngine *helpEngine);60 ContentWindow(); 61 61 ~ContentWindow(); 62 62 … … 79 79 bool isPdfFile(QHelpContentItem *item) const; 80 80 81 QHelpEngine *m_helpEngine; 82 QHelpContentWidget *m_contentWidget; 81 QHelpContentWidget * const m_contentWidget; 83 82 int m_expandDepth; 84 83 }; -
trunk/tools/assistant/tools/assistant/doc/assistant.qdoc
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 7 7 ** This file is part of the documentation of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE: LGPL$9 ** $QT_BEGIN_LICENSE:L$ 10 10 ** Commercial Usage 11 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 15 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 23 ** 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 ** 28 ** GNU General Public License Usage 29 ** Alternatively, this file may be used under the terms of the GNU 30 ** General Public License version 3.0 as published by the Free Software 31 ** Foundation and appearing in the file LICENSE.GPL included in the 32 ** packaging of this file. Please review the following information to 33 ** ensure the GNU General Public License version 3.0 requirements will be 34 ** met: http://www.gnu.org/copyleft/gpl.html. 13 ** Software or, alternatively, in accordance with the terms contained in a 14 ** written agreement between you and Nokia. 15 ** 16 ** GNU Free Documentation License 17 ** Alternatively, this file may be used under the terms of the GNU Free 18 ** Documentation License version 1.3 as published by the Free Software 19 ** Foundation and appearing in the file included in the packaging of this 20 ** file. 35 21 ** 36 22 ** If you have questions regarding the use of this file, please contact -
trunk/tools/assistant/tools/assistant/doc/assistant.qdocconf
r769 r846 13 13 "<td width=\"30%\" align=\"left\">Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies)</td>\n" \ 14 14 "<td width=\"40%\" align=\"center\">Trademarks</td>\n" \ 15 "<td width=\"30%\" align=\"right\"><div align=\"right\">Qt 4. 6.3</div></td>\n" \15 "<td width=\"30%\" align=\"right\"><div align=\"right\">Qt 4.</div></td>\n" \ 16 16 "</tr></table></div></address>" -
trunk/tools/assistant/tools/assistant/filternamedialog.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include <QtGui/QPushButton> … … 49 50 : QDialog(parent) 50 51 { 52 51 53 m_ui.setupUi(this); 52 54 connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), … … 62 64 QString FilterNameDialog::filterName() const 63 65 { 66 64 67 return m_ui.lineEdit->text(); 65 68 } … … 67 70 void FilterNameDialog::updateOkButton() 68 71 { 72 69 73 m_ui.buttonBox->button(QDialogButtonBox::Ok) 70 74 ->setDisabled(m_ui.lineEdit->text().isEmpty()); -
trunk/tools/assistant/tools/assistant/filternamedialog.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/assistant/helpviewer.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 42 43 41 44 42 #include "helpviewer.h" 43 #include "centralwidget.h" 45 #include <QtCore/QCoreApplication> 46 #include <QtCore/QFileInfo> 47 #include <QtCore/QStringBuilder> 48 #include <QtCore/QTemporaryFile> 49 #include <QtCore/QUrl> 44 50 45 #include <QtCore/QDir>46 #include <QtCore/QEvent>47 #include <QtCore/QVariant>48 #include <QtCore/QByteArray>49 #include <QtCore/QTimer>50 51 #include <QtGui/QMenu>52 #include <QtGui/QKeyEvent>53 #include <QtGui/QClipboard>54 #include <QtGui/QApplication>55 #include <QtGui/QMessageBox>56 51 #include <QtGui/QDesktopServices> 57 58 #include <QtHelp/QHelpEngine>59 60 #include <QNetworkAccessManager>61 #include <QNetworkReply>62 #include <QNetworkRequest>63 52 64 53 QT_BEGIN_NAMESPACE 65 54 66 #if !defined(QT_NO_WEBKIT) 55 const QLatin1String AbstractHelpViewer::DocPath("qthelp://com.trolltech."); 67 56 68 class HelpNetworkReply : public QNetworkReply 69 { 70 public: 71 HelpNetworkReply(const QNetworkRequest &request, const QByteArray &fileData, 72 const QString &mimeType); 57 const QString AbstractHelpViewer::AboutBlank = 58 QCoreApplication::translate("HelpViewer", "<title>about:blank</title>"); 73 59 74 virtual void abort(); 60 const QString AbstractHelpViewer::LocalHelpFile = QLatin1String("qthelp://" 61 "com.trolltech.com.assistantinternal-1.0.0/assistant/assistant.html"); 75 62 76 virtual qint64 bytesAvailable() const 77 { return data.length() + QNetworkReply::bytesAvailable(); } 63 const QString AbstractHelpViewer::PageNotFoundMessage = 64 QCoreApplication::translate("HelpViewer", "<title>Error 404...</title><div " 65 "align=\"center\"><br><br><h1>The page could not be found</h1><br><h3>'%1'" 66 "</h3></div>"); 78 67 79 protected: 80 virtual qint64 readData(char *data, qint64 maxlen); 81 82 private: 83 QByteArray data; 84 qint64 origLen; 68 struct ExtensionMap { 69 const char *extension; 70 const char *mimeType; 71 } extensionMap[] = { 72 { ".bmp", "image/bmp" }, 73 { ".css", "text/css" }, 74 { ".gif", "image/gif" }, 75 { ".html", "text/html" }, 76 { ".htm", "text/html" }, 77 { ".ico", "image/x-icon" }, 78 { ".jpeg", "image/jpeg" }, 79 { ".jpg", "image/jpeg" }, 80 { ".js", "application/x-javascript" }, 81 { ".mng", "video/x-mng" }, 82 { ".pbm", "image/x-portable-bitmap" }, 83 { ".pgm", "image/x-portable-graymap" }, 84 { ".pdf", "application/pdf" }, 85 { ".png", "image/png" }, 86 { ".ppm", "image/x-portable-pixmap" }, 87 { ".rss", "application/rss+xml" }, 88 { ".svg", "image/svg+xml" }, 89 { ".svgz", "image/svg+xml" }, 90 { ".text", "text/plain" }, 91 { ".tif", "image/tiff" }, 92 { ".tiff", "image/tiff" }, 93 { ".txt", "text/plain" }, 94 { ".xbm", "image/x-xbitmap" }, 95 { ".xml", "text/xml" }, 96 { ".xpm", "image/x-xpm" }, 97 { ".xsl", "text/xsl" }, 98 { ".xhtml", "application/xhtml+xml" }, 99 { ".wml", "text/vnd.wap.wml" }, 100 { ".wmlc", "application/vnd.wap.wmlc" }, 101 { "about:blank", 0 }, 102 { 0, 0 } 85 103 }; 86 104 87 HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request, 88 const QByteArray &fileData, const QString& mimeType) 89 : data(fileData), origLen(fileData.length()) 90 { 91 setRequest(request); 92 setOpenMode(QIODevice::ReadOnly); 105 // -- AbstractHelpViewer 93 106 94 setHeader(QNetworkRequest::ContentTypeHeader, mimeType); 95 setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen)); 96 QTimer::singleShot(0, this, SIGNAL(metaDataChanged())); 97 QTimer::singleShot(0, this, SIGNAL(readyRead())); 98 } 99 100 void HelpNetworkReply::abort() 101 { 102 // nothing to do 103 } 104 105 qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen) 106 { 107 qint64 len = qMin(qint64(data.length()), maxlen); 108 if (len) { 109 qMemCopy(buffer, data.constData(), len); 110 data.remove(0, len); 111 } 112 if (!data.length()) 113 QTimer::singleShot(0, this, SIGNAL(finished())); 114 return len; 115 } 116 117 class HelpNetworkAccessManager : public QNetworkAccessManager 118 { 119 public: 120 HelpNetworkAccessManager(QHelpEngine *engine, QObject *parent); 121 122 protected: 123 virtual QNetworkReply *createRequest(Operation op, 124 const QNetworkRequest &request, QIODevice *outgoingData = 0); 125 126 private: 127 QHelpEngine *helpEngine; 128 }; 129 130 HelpNetworkAccessManager::HelpNetworkAccessManager(QHelpEngine *engine, 131 QObject *parent) 132 : QNetworkAccessManager(parent), helpEngine(engine) 107 AbstractHelpViewer::AbstractHelpViewer() 133 108 { 134 109 } 135 110 136 QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, 137 const QNetworkRequest &request, QIODevice* /*outgoingData*/) 138 { 139 const QUrl& url = request.url(); 140 QString mimeType = url.toString(); 141 if (mimeType.endsWith(QLatin1String(".svg")) 142 || mimeType.endsWith(QLatin1String(".svgz"))) { 143 mimeType = QLatin1String("image/svg+xml"); 144 } else if (mimeType.endsWith(QLatin1String(".css"))) { 145 mimeType = QLatin1String("text/css"); 146 } else if (mimeType.endsWith(QLatin1String(".js"))) { 147 mimeType = QLatin1String("text/javascript"); 148 } else if (mimeType.endsWith(QLatin1String(".txt"))) { 149 mimeType = QLatin1String("text/plain"); 150 } else { 151 mimeType = QLatin1String("text/html"); 152 } 153 154 const QByteArray &data = helpEngine->findFile(url).isValid() 155 ? helpEngine->fileData(url) : QByteArray("File not found!"); 156 return new HelpNetworkReply(request, data, mimeType); 157 } 158 159 class HelpPage : public QWebPage 160 { 161 public: 162 HelpPage(CentralWidget *central, QHelpEngine *engine, QObject *parent); 163 164 protected: 165 virtual QWebPage *createWindow(QWebPage::WebWindowType); 166 virtual void triggerAction(WebAction action, bool checked = false); 167 168 virtual bool acceptNavigationRequest(QWebFrame *frame, 169 const QNetworkRequest &request, NavigationType type); 170 171 private: 172 CentralWidget *centralWidget; 173 QHelpEngine *helpEngine; 174 bool closeNewTabIfNeeded; 175 176 friend class HelpViewer; 177 Qt::MouseButtons m_pressedButtons; 178 Qt::KeyboardModifiers m_keyboardModifiers; 179 }; 180 181 HelpPage::HelpPage(CentralWidget *central, QHelpEngine *engine, QObject *parent) 182 : QWebPage(parent) 183 , centralWidget(central) 184 , helpEngine(engine) 185 , closeNewTabIfNeeded(false) 186 , m_pressedButtons(Qt::NoButton) 187 , m_keyboardModifiers(Qt::NoModifier) 111 AbstractHelpViewer::~AbstractHelpViewer() 188 112 { 189 113 } 190 114 191 QWebPage *HelpPage::createWindow(QWebPage::WebWindowType)115 ) 192 116 { 193 HelpPage* newPage = static_cast<HelpPage*>(centralWidget->newEmptyTab()->page()); 194 if (newPage) 195 newPage->closeNewTabIfNeeded = closeNewTabIfNeeded; 196 closeNewTabIfNeeded = false; 197 return newPage; 198 } 199 200 static bool isLocalUrl(const QUrl &url) 201 { 202 const QString scheme = url.scheme(); 203 if (scheme.isEmpty() 117 TRACE_OBJ 118 const QString &scheme = url.scheme(); 119 return scheme.isEmpty() 204 120 || scheme == QLatin1String("file") 205 121 || scheme == QLatin1String("qrc") 206 122 || scheme == QLatin1String("data") 207 123 || scheme == QLatin1String("qthelp") 208 || scheme == QLatin1String("about")) 209 return true; 210 return false; 124 || scheme == QLatin1String("about"); 211 125 } 212 126 213 void HelpPage::triggerAction(WebAction action, bool checked)127 ) 214 128 { 215 switch (action) { 216 case OpenLinkInNewWindow: 217 closeNewTabIfNeeded = true; 218 default: // fall through 219 QWebPage::triggerAction(action, checked); 220 break; 221 } 129 TRACE_OBJ 130 return !mimeFromUrl(url).isEmpty(); 222 131 } 223 132 224 bool HelpPage::acceptNavigationRequest(QWebFrame *, 225 const QNetworkRequest &request, QWebPage::NavigationType type) 133 QString AbstractHelpViewer::mimeFromUrl(const QUrl &url) 226 134 { 227 const QUrl &url = request.url(); 228 const bool closeNewTab = closeNewTabIfNeeded; 229 closeNewTabIfNeeded = false; 135 TRACE_OBJ 136 const QString &path = url.path(); 137 const int index = path.lastIndexOf(QLatin1Char('.')); 138 const QByteArray &ext = path.mid(index).toUtf8().toLower(); 230 139 231 if (isLocalUrl(url)) { 232 const QString& path = url.path(); 233 if (path.endsWith(QLatin1String(".pdf"))) { 234 const int lastDash = path.lastIndexOf(QChar('/')); 235 QString fileName = QDir::tempPath() + QDir::separator(); 236 if (lastDash < 0) 237 fileName += path; 238 else 239 fileName += path.mid(lastDash + 1, path.length()); 240 241 QFile tmpFile(QDir::cleanPath(fileName)); 242 if (tmpFile.open(QIODevice::ReadWrite)) { 243 tmpFile.write(helpEngine->fileData(url)); 244 tmpFile.close(); 245 } 246 QDesktopServices::openUrl(QUrl(tmpFile.fileName())); 247 248 if (closeNewTab) 249 QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab"); 250 return false; 251 } 252 253 if (type == QWebPage::NavigationTypeLinkClicked 254 && (m_keyboardModifiers & Qt::ControlModifier 255 || m_pressedButtons == Qt::MidButton)) { 256 HelpViewer* viewer = centralWidget->newEmptyTab(); 257 if (viewer) 258 CentralWidget::instance()->setSource(url); 259 m_pressedButtons = Qt::NoButton; 260 m_keyboardModifiers = Qt::NoModifier; 261 return false; 262 } 263 return true; 140 const ExtensionMap *e = extensionMap; 141 while (e->extension) { 142 if (ext == e->extension) 143 return QLatin1String(e->mimeType); 144 ++e; 264 145 } 265 266 QDesktopServices::openUrl(url); 267 return false; 146 return QLatin1String(""); 268 147 } 269 148 270 HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) 271 : QWebView(parent) 272 , helpEngine(engine) 273 , parentWidget(parent) 274 , loadFinished(false) 149 bool AbstractHelpViewer::launchWithExternalApp(const QUrl &url) 275 150 { 276 setAcceptDrops(false); 151 TRACE_OBJ 152 if (isLocalUrl(url)) { 153 const HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 154 const QUrl &resolvedUrl = helpEngine.findFile(url); 155 if (!resolvedUrl.isValid()) 156 return false; 277 157 278 setPage(new HelpPage(parent, helpEngine, this)); 158 const QString& path = resolvedUrl.path(); 159 if (!canOpenPage(path)) { 160 QTemporaryFile tmpTmpFile; 161 if (!tmpTmpFile.open()) 162 return false; 279 163 280 page()->setNetworkAccessManager(new HelpNetworkAccessManager(engine, this)); 164 const QString &extension = QFileInfo(path).completeSuffix(); 165 QFile actualTmpFile(tmpTmpFile.fileName() % QLatin1String(".") 166 % extension); 167 if (!actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) 168 return false; 281 169 282 QAction* action = pageAction(QWebPage::OpenLinkInNewWindow); 283 action->setText(tr("Open Link in New Tab")); 284 if (!parent) 285 action->setVisible(false); 286 287 pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false); 288 pageAction(QWebPage::DownloadImageToDisk)->setVisible(false); 289 pageAction(QWebPage::OpenImageInNewWindow)->setVisible(false); 290 291 connect(pageAction(QWebPage::Copy), SIGNAL(changed()), this, 292 SLOT(actionChanged())); 293 connect(pageAction(QWebPage::Back), SIGNAL(changed()), this, 294 SLOT(actionChanged())); 295 connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this, 296 SLOT(actionChanged())); 297 connect(page(), SIGNAL(linkHovered(QString,QString,QString)), this, 298 SIGNAL(highlighted(QString))); 299 connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); 300 connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool))); 301 } 302 303 void HelpViewer::setSource(const QUrl &url) 304 { 305 loadFinished = false; 306 if (url.toString() == QLatin1String("help")) { 307 load(QUrl(QLatin1String("qthelp://com.trolltech.com." 308 "assistantinternal-1.0.0/assistant/assistant.html"))); 309 } else { 310 load(url); 311 } 312 } 313 314 void HelpViewer::resetZoom() 315 { 316 setTextSizeMultiplier(1.0); 317 } 318 319 void HelpViewer::zoomIn(qreal range) 320 { 321 setTextSizeMultiplier(textSizeMultiplier() + range / 10.0); 322 } 323 324 void HelpViewer::zoomOut(qreal range) 325 { 326 setTextSizeMultiplier(qMax(0.0, textSizeMultiplier() - range / 10.0)); 327 } 328 329 void HelpViewer::home() 330 { 331 QString homepage = helpEngine->customValue(QLatin1String("homepage"), 332 QLatin1String("")).toString(); 333 334 if (homepage.isEmpty()) { 335 homepage = helpEngine->customValue(QLatin1String("defaultHomepage"), 336 QLatin1String("help")).toString(); 337 } 338 339 setSource(homepage); 340 } 341 342 void HelpViewer::wheelEvent(QWheelEvent *e) 343 { 344 if (e->modifiers() & Qt::ControlModifier) { 345 const int delta = e->delta(); 346 if (delta > 0) 347 zoomIn(delta / 120); 348 else if (delta < 0) 349 zoomOut(-delta / 120); 350 e->accept(); 351 return; 352 } 353 QWebView::wheelEvent(e); 354 } 355 356 void HelpViewer::mouseReleaseEvent(QMouseEvent *e) 357 { 358 if (e->button() == Qt::XButton1) { 359 triggerPageAction(QWebPage::Back); 360 return; 361 } 362 363 if (e->button() == Qt::XButton2) { 364 triggerPageAction(QWebPage::Forward); 365 return; 366 } 367 368 QWebView::mouseReleaseEvent(e); 369 } 370 371 void HelpViewer::actionChanged() 372 { 373 QAction *a = qobject_cast<QAction *>(sender()); 374 if (a == pageAction(QWebPage::Copy)) 375 emit copyAvailable(a->isEnabled()); 376 else if (a == pageAction(QWebPage::Back)) 377 emit backwardAvailable(a->isEnabled()); 378 else if (a == pageAction(QWebPage::Forward)) 379 emit forwardAvailable(a->isEnabled()); 380 } 381 382 void HelpViewer::mousePressEvent(QMouseEvent *event) 383 { 384 HelpPage *currentPage = static_cast<HelpPage*>(page()); 385 if (currentPage) { 386 currentPage->m_pressedButtons = event->buttons(); 387 currentPage->m_keyboardModifiers = event->modifiers(); 388 } 389 QWebView::mousePressEvent(event); 390 } 391 392 void HelpViewer::setLoadFinished(bool ok) 393 { 394 loadFinished = ok; 395 emit sourceChanged(url()); 396 } 397 398 #else // !defined(QT_NO_WEBKIT) 399 400 HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) 401 : QTextBrowser(parent) 402 , zoomCount(0) 403 , controlPressed(false) 404 , lastAnchor(QString()) 405 , helpEngine(engine) 406 , parentWidget(parent) 407 { 408 document()->setDocumentMargin(8); 409 } 410 411 void HelpViewer::setSource(const QUrl &url) 412 { 413 bool help = url.toString() == QLatin1String("help"); 414 if (url.isValid() && !help) { 415 if (launchedWithExternalApp(url)) 416 return; 417 418 QUrl u = helpEngine->findFile(url); 419 if (u.isValid()) { 420 QTextBrowser::setSource(u); 421 return; 170 actualTmpFile.write(helpEngine.fileData(resolvedUrl)); 171 actualTmpFile.close(); 172 return QDesktopServices::openUrl(QUrl(actualTmpFile.fileName())); 422 173 } 423 } 424 425 if (help) { 426 QTextBrowser::setSource(QUrl(QLatin1String("qthelp://com.trolltech.com." 427 "assistantinternal-1.0.0/assistant/assistant.html"))); 428 } else { 429 QTextBrowser::setSource(url); 430 setHtml(tr("<title>Error 404...</title><div align=\"center\"><br><br>" 431 "<h1>The page could not be found</h1><br><h3>'%1'</h3></div>") 432 .arg(url.toString())); 433 emit sourceChanged(url); 434 } 435 } 436 437 void HelpViewer::resetZoom() 438 { 439 if (zoomCount == 0) 440 return; 441 442 QTextBrowser::zoomOut(zoomCount); 443 zoomCount = 0; 444 } 445 446 void HelpViewer::zoomIn(int range) 447 { 448 if (zoomCount == 10) 449 return; 450 451 QTextBrowser::zoomIn(range); 452 zoomCount++; 453 } 454 455 void HelpViewer::zoomOut(int range) 456 { 457 if (zoomCount == -5) 458 return; 459 460 QTextBrowser::zoomOut(range); 461 zoomCount--; 462 } 463 464 bool HelpViewer::launchedWithExternalApp(const QUrl &url) 465 { 466 bool isPdf = url.path().endsWith(QLatin1String(".pdf")); 467 if (url.scheme() == QLatin1String("http") 468 || url.scheme() == QLatin1String("ftp") 469 || url.scheme() == QLatin1String("mailto") || isPdf) { 470 bool launched = false; 471 if (isPdf && url.scheme() == QLatin1String("qthelp")) { 472 const QString& path = url.path(); 473 const int lastDash = path.lastIndexOf(QChar('/')); 474 QString fileName = QDir::tempPath() + QDir::separator(); 475 if (lastDash < 0) 476 fileName += path; 477 else 478 fileName += path.mid(lastDash + 1, path.length()); 479 480 QFile tmpFile(QDir::cleanPath(fileName)); 481 if (tmpFile.open(QIODevice::ReadWrite)) { 482 tmpFile.write(helpEngine->fileData(url)); 483 tmpFile.close(); 484 } 485 launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName())); 486 } else { 487 launched = QDesktopServices::openUrl(url); 488 } 489 490 if (!launched) { 491 QMessageBox::information(this, tr("Help"), 492 tr("Unable to launch external application.\n"), tr("OK")); 493 } 494 return true; 174 } else if (url.scheme() == QLatin1String("http")) { 175 return QDesktopServices::openUrl(url); 495 176 } 496 177 return false; 497 178 } 498 179 499 QVariant HelpViewer::loadResource(int type, const QUrl &name)500 {501 QByteArray ba;502 if (type < 4) {503 ba = helpEngine->fileData(name);504 if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {505 QImage image;506 image.loadFromData(ba, "svg");507 if (!image.isNull())508 return image;509 }510 }511 return ba;512 }513 514 void HelpViewer::openLinkInNewTab()515 {516 if(lastAnchor.isEmpty())517 return;518 519 parentWidget->setSourceInNewTab(QUrl(lastAnchor));520 lastAnchor.clear();521 }522 523 void HelpViewer::openLinkInNewTab(const QString &link)524 {525 lastAnchor = link;526 openLinkInNewTab();527 }528 529 bool HelpViewer::hasAnchorAt(const QPoint& pos)530 {531 lastAnchor = anchorAt(pos);532 if (lastAnchor.isEmpty())533 return false;534 535 lastAnchor = source().resolved(lastAnchor).toString();536 if (lastAnchor.at(0) == QLatin1Char('#')) {537 QString src = source().toString();538 int hsh = src.indexOf(QLatin1Char('#'));539 lastAnchor = (hsh>=0 ? src.left(hsh) : src) + lastAnchor;540 }541 542 return true;543 }544 545 void HelpViewer::contextMenuEvent(QContextMenuEvent *e)546 {547 QMenu menu(QLatin1String(""), 0);548 549 QUrl link;550 QAction *copyAnchorAction = 0;551 if (hasAnchorAt(e->pos())) {552 link = anchorAt(e->pos());553 if (link.isRelative())554 link = source().resolved(link);555 copyAnchorAction = menu.addAction(tr("Copy &Link Location"));556 copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid());557 558 menu.addAction(tr("Open Link in New Tab\tCtrl+LMB"), this,559 SLOT(openLinkInNewTab()));560 menu.addSeparator();561 }562 menu.addActions(parentWidget->globalActions());563 QAction *action = menu.exec(e->globalPos());564 if (action == copyAnchorAction)565 QApplication::clipboard()->setText(link.toString());566 }567 568 void HelpViewer::mouseReleaseEvent(QMouseEvent *e)569 {570 if (e->button() == Qt::XButton1) {571 QTextBrowser::backward();572 return;573 }574 575 if (e->button() == Qt::XButton2) {576 QTextBrowser::forward();577 return;578 }579 580 controlPressed = e->modifiers() & Qt::ControlModifier;581 if ((controlPressed && hasAnchorAt(e->pos())) ||582 (e->button() == Qt::MidButton && hasAnchorAt(e->pos()))) {583 openLinkInNewTab();584 return;585 }586 587 QTextBrowser::mouseReleaseEvent(e);588 }589 590 void HelpViewer::keyPressEvent(QKeyEvent *e)591 {592 if ((e->key() == Qt::Key_Home && e->modifiers() != Qt::NoModifier)593 || (e->key() == Qt::Key_End && e->modifiers() != Qt::NoModifier)) {594 QKeyEvent* event = new QKeyEvent(e->type(), e->key(), Qt::NoModifier,595 e->text(), e->isAutoRepeat(), e->count());596 e = event;597 }598 QTextBrowser::keyPressEvent(e);599 }600 601 void HelpViewer::home()602 {603 QString homepage = helpEngine->customValue(QLatin1String("homepage"),604 QLatin1String("")).toString();605 606 if (homepage.isEmpty()) {607 homepage = helpEngine->customValue(QLatin1String("defaultHomepage"),608 QLatin1String("help")).toString();609 }610 611 setSource(homepage);612 }613 614 void HelpViewer::wheelEvent(QWheelEvent *e)615 {616 if (e->modifiers() == Qt::CTRL) {617 e->accept();618 (e->delta() > 0) ? zoomIn() : zoomOut();619 } else {620 e->ignore();621 QTextBrowser::wheelEvent(e);622 }623 }624 625 #endif // !defined(QT_NO_WEBKIT)626 627 180 QT_END_NAMESPACE -
trunk/tools/assistant/tools/assistant/helpviewer.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 42 41 #ifndef HELPVIEWER_H 43 42 #define HELPVIEWER_H 44 43 45 #include <QtCore/QUrl> 46 #include <QtCore/QVariant> 47 #include <QtGui/QTextBrowser> 48 #include <QtGui/QAction> 44 #include <QtCore/QString> 49 45 50 #if !defined(QT_NO_WEBKIT) 51 #include <QWebView> 52 #endif 46 #include <QtGui/QFont> 53 47 54 48 QT_BEGIN_NAMESPACE 55 49 56 class Q HelpEngine;57 class CentralWidget;50 class Q; 51 class ; 58 52 59 class QPoint;60 class QString; 61 class QKeyEvent; 62 class QMouseEvent;63 class QContextMenuEvent;53 class 54 { 55 public: 56 ; 57 ; 64 58 65 #if !defined(QT_NO_WEBKIT) 59 virtual QFont viewerFont() const = 0; 60 virtual void setViewerFont(const QFont &font) = 0; 66 61 67 class HelpViewer : public QWebView 68 { 69 Q_OBJECT 62 virtual void scaleUp() = 0; 63 virtual void scaleDown() = 0; 64 65 virtual void resetScale() = 0; 66 virtual qreal scale() const = 0; 70 67 71 public: 72 HelpViewer(QHelpEngine *helpEngine, CentralWidget *parent); 73 void setSource(const QUrl &url); 68 virtual bool handleForwardBackwardMouseButtons(QMouseEvent *e) = 0; 74 69 75 inline QUrl source() const 76 { return url(); } 70 static const QLatin1String DocPath; 71 static const QString AboutBlank; 72 static const QString LocalHelpFile; 73 static const QString PageNotFoundMessage; 77 74 78 inline QString documentTitle() const 79 { return title(); } 80 81 inline bool hasSelection() const 82 { return !selectedText().isEmpty(); } // ### this is suboptimal 83 84 void resetZoom(); 85 void zoomIn(qreal range = 1); 86 void zoomOut(qreal range = 1); 87 88 inline void copy() 89 { return triggerPageAction(QWebPage::Copy); } 90 91 inline bool isForwardAvailable() const 92 { return pageAction(QWebPage::Forward)->isEnabled(); } 93 inline bool isBackwardAvailable() const 94 { return pageAction(QWebPage::Back)->isEnabled(); } 95 inline bool hasLoadFinished() const 96 { return loadFinished; } 97 inline qreal zoom() const 98 { return textSizeMultiplier(); } 99 100 public Q_SLOTS: 101 void home(); 102 void backward() { back(); } 103 104 Q_SIGNALS: 105 void copyAvailable(bool enabled); 106 void forwardAvailable(bool enabled); 107 void backwardAvailable(bool enabled); 108 void highlighted(const QString &); 109 void sourceChanged(const QUrl &); 110 111 protected: 112 virtual void wheelEvent(QWheelEvent *); 113 void mouseReleaseEvent(QMouseEvent *e); 114 void mousePressEvent(QMouseEvent *event); 115 116 private Q_SLOTS: 117 void actionChanged(); 118 void setLoadFinished(bool ok); 119 120 private: 121 QHelpEngine *helpEngine; 122 CentralWidget* parentWidget; 123 bool loadFinished; 75 static bool isLocalUrl(const QUrl &url); 76 static bool canOpenPage(const QString &url); 77 static QString mimeFromUrl(const QUrl &url); 78 static bool launchWithExternalApp(const QUrl &url); 124 79 }; 125 126 #else127 128 class HelpViewer : public QTextBrowser129 {130 Q_OBJECT131 132 public:133 HelpViewer(QHelpEngine *helpEngine, CentralWidget *parent);134 void setSource(const QUrl &url);135 136 void resetZoom();137 void zoomIn(int range = 1);138 void zoomOut(int range = 1);139 int zoom() const { return zoomCount; }140 void setZoom(int zoom) { zoomCount = zoom; }141 142 inline bool hasSelection() const143 { return textCursor().hasSelection(); }144 145 bool launchedWithExternalApp(const QUrl &url);146 147 public Q_SLOTS:148 void home();149 150 protected:151 void wheelEvent(QWheelEvent *e);152 153 private:154 QVariant loadResource(int type, const QUrl &name);155 void openLinkInNewTab(const QString &link);156 bool hasAnchorAt(const QPoint& pos);157 void contextMenuEvent(QContextMenuEvent *e);158 void mouseReleaseEvent(QMouseEvent *e);159 void keyPressEvent(QKeyEvent *e);160 161 private slots:162 void openLinkInNewTab();163 164 private:165 int zoomCount;166 bool controlPressed;167 QString lastAnchor;168 QHelpEngine *helpEngine;169 CentralWidget* parentWidget;170 };171 172 #endif173 80 174 81 QT_END_NAMESPACE 175 82 176 #endif 83 #endif -
trunk/tools/assistant/tools/assistant/indexwindow.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "indexwindow.h" 43 44 #include "centralwidget.h" 45 46 44 47 #include "topicchooser.h" 45 48 … … 52 55 #include <QtGui/QListWidgetItem> 53 56 54 #include <QtHelp/QHelpEngine>55 57 #include <QtHelp/QHelpIndexWidget> 56 58 57 59 QT_BEGIN_NAMESPACE 58 60 59 IndexWindow::IndexWindow(Q HelpEngine *helpEngine, QWidget *parent)61 IndexWindow::IndexWindow(QWidget *parent) 60 62 : QWidget(parent) 61 , m_searchLineEdit( 0)62 , m_indexWidget( 0)63 , m_helpEngine(helpEngine) 64 { 63 , m_searchLineEdit() 64 , m_indexWidget() 65 { 66 TRACE_OBJ 65 67 QVBoxLayout *layout = new QVBoxLayout(this); 66 68 QLabel *l = new QLabel(tr("&Look for:")); 67 69 layout->addWidget(l); 68 70 69 m_searchLineEdit = new QLineEdit();70 71 l->setBuddy(m_searchLineEdit); 71 72 connect(m_searchLineEdit, SIGNAL(textChanged(QString)), this, … … 75 76 layout->addWidget(m_searchLineEdit); 76 77 77 m_indexWidget = m_helpEngine->indexWidget();78 (); 78 79 m_indexWidget->installEventFilter(this); 79 connect( m_helpEngine->indexModel(), SIGNAL(indexCreationStarted()), this,80 connect(indexModel(), SIGNAL(indexCreationStarted()), this, 80 81 SLOT(disableSearchLineEdit())); 81 connect( m_helpEngine->indexModel(), SIGNAL(indexCreated()), this,82 connect(indexModel(), SIGNAL(indexCreated()), this, 82 83 SLOT(enableSearchLineEdit())); 83 84 connect(m_indexWidget, SIGNAL(linkActivated(QUrl,QString)), this, … … 94 95 IndexWindow::~IndexWindow() 95 96 { 97 96 98 } 97 99 98 100 void IndexWindow::filterIndices(const QString &filter) 99 101 { 102 100 103 if (filter.contains(QLatin1Char('*'))) 101 104 m_indexWidget->filterIndices(filter, filter); … … 106 109 bool IndexWindow::eventFilter(QObject *obj, QEvent *e) 107 110 { 111 108 112 if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) { 109 113 QKeyEvent *ke = static_cast<QKeyEvent*>(e); … … 171 175 void IndexWindow::enableSearchLineEdit() 172 176 { 177 173 178 m_searchLineEdit->setDisabled(false); 174 179 filterIndices(m_searchLineEdit->text()); … … 177 182 void IndexWindow::disableSearchLineEdit() 178 183 { 184 179 185 m_searchLineEdit->setDisabled(true); 180 186 } … … 182 188 void IndexWindow::setSearchLineEditText(const QString &text) 183 189 { 190 184 191 m_searchLineEdit->setText(text); 185 192 } … … 187 194 void IndexWindow::focusInEvent(QFocusEvent *e) 188 195 { 196 189 197 if (e->reason() != Qt::MouseFocusReason) { 190 198 m_searchLineEdit->selectAll(); … … 195 203 void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) 196 204 { 205 197 206 QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(indexWidget->model()); 198 207 if (model) { … … 211 220 } 212 221 213 if ( url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive))222 if ()) 214 223 CentralWidget::instance()->setSource(url); 215 224 else -
trunk/tools/assistant/tools/assistant/indexwindow.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 50 50 51 51 class QHelpIndexWidget; 52 class QHelpEngine;53 52 class QModelIndex; 54 53 … … 58 57 59 58 public: 60 IndexWindow(Q HelpEngine *helpEngine, QWidget *parent = 0);59 IndexWindow(QWidget *parent = 0); 61 60 ~IndexWindow(); 62 61 … … 85 84 QLineEdit *m_searchLineEdit; 86 85 QHelpIndexWidget *m_indexWidget; 87 QHelpEngine *m_helpEngine;88 86 }; 89 87 -
trunk/tools/assistant/tools/assistant/installdialog.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "installdialog.h" … … 67 68 : QDialog(parent), m_helpEngine(helpEngine), m_host(host), m_port(port) 68 69 { 70 69 71 m_ui.setupUi(this); 70 72 … … 95 97 InstallDialog::~InstallDialog() 96 98 { 99 97 100 } 98 101 99 102 QStringList InstallDialog::installedDocumentations() const 100 103 { 104 101 105 return m_installedDocumentations; 102 106 } … … 104 108 void InstallDialog::init() 105 109 { 110 106 111 m_ui.statusLabel->setText(tr("Downloading documentation info...")); 107 112 m_ui.progressBar->show(); … … 123 128 void InstallDialog::updateInstallButton() 124 129 { 130 125 131 QListWidgetItem *item = 0; 126 132 for (int i=0; i<m_ui.listWidget->count(); ++i) { … … 137 143 void InstallDialog::updateDocItemList() 138 144 { 145 139 146 QStringList registeredDocs = m_helpEngine->registeredDocumentations(); 140 147 QListWidgetItem *item = 0; … … 152 159 void InstallDialog::cancelDownload() 153 160 { 161 154 162 m_ui.statusLabel->setText(tr("Download canceled.")); 155 163 m_httpAborted = true; … … 163 171 void InstallDialog::install() 164 172 { 173 165 174 QListWidgetItem *item = 0; 166 175 for (int i=0; i<m_ui.listWidget->count(); ++i) { … … 175 184 void InstallDialog::downloadNextFile() 176 185 { 186 177 187 if (!m_itemsToInstall.count()) { 178 188 m_ui.cancelButton->setEnabled(false); … … 227 237 void InstallDialog::httpRequestFinished(int requestId, bool error) 228 238 { 239 229 240 if (requestId == m_docInfoId && m_buffer) { 230 241 m_ui.progressBar->hide(); … … 297 308 void InstallDialog::installFile(const QString &fileName) 298 309 { 310 299 311 if (m_helpEngine->registerDocumentation(fileName)) { 300 312 m_installedDocumentations … … 309 321 void InstallDialog::readResponseHeader(const QHttpResponseHeader &responseHeader) 310 322 { 323 311 324 if (responseHeader.statusCode() != 200) { 312 325 QMessageBox::information(this, m_windowTitle, … … 322 335 void InstallDialog::updateDataReadProgress(int bytesRead, int totalBytes) 323 336 { 337 324 338 if (m_httpAborted) 325 339 return; … … 331 345 void InstallDialog::browseDirectories() 332 346 { 347 333 348 QString dir = QFileDialog::getExistingDirectory(this, m_windowTitle, 334 349 m_ui.pathLineEdit->text()); -
trunk/tools/assistant/tools/assistant/installdialog.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 62 62 63 63 public: 64 InstallDialog(QHelpEngineCore *helpEngine, QWidget *parent = 0,64 InstallDialog(QHelpEngineCore *helpEngine, QWidget *parent = 0, 65 65 const QString &host = QString(), int port = -1); 66 66 ~InstallDialog(); -
trunk/tools/assistant/tools/assistant/main.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include <QtCore/QDir> 43 44 #include <QtCore/QFileInfo> 45 44 46 #include <QtCore/QLocale> 47 48 45 49 #include <QtCore/QTranslator> 46 #include <QtCore/QLibraryInfo>47 50 #include <QtCore/QUrl> 48 #include <QtCore/QStringList>49 51 50 52 #include <QtGui/QApplication> 51 53 #include <QtGui/QDesktopServices> 52 54 53 #include <QtHelp/QHelpEngineCore> 55 #include <QtHelp/QHelpEngine> 56 #include <QtHelp/QHelpSearchEngine> 54 57 55 58 #include <QtNetwork/QLocalSocket> … … 57 60 #include <QtSql/QSqlDatabase> 58 61 62 63 59 64 #include "mainwindow.h" 60 65 #include "cmdlineparser.h" 66 67 61 68 62 69 QT_USE_NAMESPACE … … 67 74 #endif 68 75 76 77 69 78 void 70 79 updateLastPagesOnUnregister(QHelpEngineCore& helpEngine, const QString& nsName) 71 80 { 72 int lastPage = helpEngine.customValue(QLatin1String("LastTabPage")).toInt(); 73 74 QLatin1String sep("|"); 75 QLatin1String pages("LastShownPages"); 76 #if !defined(QT_NO_WEBKIT) 77 QLatin1String zoom("LastPagesZoomWebView"); 78 #else 79 QLatin1String zoom("LastPagesZoomTextBrowser"); 80 #endif 81 82 QStringList currentPages = 83 helpEngine.customValue(pages).toString(). 84 split(QLatin1Char('|'), QString::SkipEmptyParts); 85 81 TRACE_OBJ 82 int lastPage = CollectionConfiguration::lastTabPage(helpEngine); 83 QStringList currentPages = CollectionConfiguration::lastShownPages(helpEngine); 86 84 if (!currentPages.isEmpty()) { 87 QVector<QString>zoomList = helpEngine.customValue(zoom).toString(). 88 split(sep, QString::SkipEmptyParts).toVector(); 89 if (zoomList.isEmpty()) 90 zoomList.fill(QLatin1String("0.0"), currentPages.size()); 91 else if(zoomList.count() < currentPages.count()) { 92 zoomList.insert(zoomList.count(), 93 currentPages.count() - zoomList.count(), QLatin1String("0.0")); 94 } 85 QStringList zoomList = CollectionConfiguration::lastZoomFactors(helpEngine); 86 while (zoomList.count() < currentPages.count()) 87 zoomList.append(CollectionConfiguration::DefaultZoomFactor); 95 88 96 89 for (int i = currentPages.count(); --i >= 0;) { 97 90 if (QUrl(currentPages.at(i)).host() == nsName) { 98 zoomList.remove (i);91 zoomList.remove(i); 99 92 currentPages.removeAt(i); 100 93 lastPage = (lastPage == (i + 1)) ? 1 : lastPage; … … 102 95 } 103 96 104 helpEngine.setCustomValue(pages, currentPages.join(sep));105 helpEngine.setCustomValue(QLatin1String("LastTabPage"), lastPage);106 helpEngine.setCustomValue(zoom, QStringList(zoomList.toList()).join(sep));97 ); 98 , lastPage); 99 ); 107 100 } 108 101 } … … 111 104 updateUserCollection(QHelpEngineCore& user, const QHelpEngineCore& caller) 112 105 { 113 const uint callerCollectionCreationTime = caller. 114 customValue(QLatin1String("CreationTime"), 0).toUInt(); 115 const uint userCollectionCreationTime = user. 116 customValue(QLatin1String("CreationTime"), 1).toUInt(); 117 118 if (callerCollectionCreationTime <= userCollectionCreationTime) 106 TRACE_OBJ 107 if (!CollectionConfiguration::isNewer(caller, user)) 119 108 return false; 120 121 user.setCustomValue(QLatin1String("CreationTime"), 122 callerCollectionCreationTime); 123 user.setCustomValue(QLatin1String("WindowTitle"), 124 caller.customValue(QLatin1String("WindowTitle"))); 125 user.setCustomValue(QLatin1String("LastShownPages"), 126 caller.customValue(QLatin1String("LastShownPages"))); 127 #if !defined(QT_NO_WEBKIT) 128 const QLatin1String zoomKey("LastPagesZoomWebView"); 129 #else 130 const QLatin1String zoomKey("LastPagesZoomTextBrowser"); 131 #endif 132 user.setCustomValue(zoomKey, caller.customValue(zoomKey)); 133 user.setCustomValue(QLatin1String("CurrentFilter"), 134 caller.customValue(QLatin1String("CurrentFilter"))); 135 user.setCustomValue(QLatin1String("CacheDirectory"), 136 caller.customValue(QLatin1String("CacheDirectory"))); 137 user.setCustomValue(QLatin1String("EnableFilterFunctionality"), 138 caller.customValue(QLatin1String("EnableFilterFunctionality"))); 139 user.setCustomValue(QLatin1String("HideFilterFunctionality"), 140 caller.customValue(QLatin1String("HideFilterFunctionality"))); 141 user.setCustomValue(QLatin1String("EnableDocumentationManager"), 142 caller.customValue(QLatin1String("EnableDocumentationManager"))); 143 user.setCustomValue(QLatin1String("EnableAddressBar"), 144 caller.customValue(QLatin1String("EnableAddressBar"))); 145 user.setCustomValue(QLatin1String("HideAddressBar"), 146 caller.customValue(QLatin1String("HideAddressBar"))); 147 user.setCustomValue(QLatin1String("ApplicationIcon"), 148 caller.customValue(QLatin1String("ApplicationIcon"))); 149 user.setCustomValue(QLatin1String("AboutMenuTexts"), 150 caller.customValue(QLatin1String("AboutMenuTexts"))); 151 user.setCustomValue(QLatin1String("AboutIcon"), 152 caller.customValue(QLatin1String("AboutIcon"))); 153 user.setCustomValue(QLatin1String("AboutTexts"), 154 caller.customValue(QLatin1String("AboutTexts"))); 155 user.setCustomValue(QLatin1String("AboutImages"), 156 caller.customValue(QLatin1String("AboutImages"))); 157 user.setCustomValue(QLatin1String("defaultHomepage"), 158 caller.customValue(QLatin1String("defaultHomepage"))); 159 109 CollectionConfiguration::copyConfiguration(caller, user); 160 110 return true; 161 111 } 162 112 163 bool 164 referencedHelpFilesExistAll(QHelpEngineCore& user, QStringList& nameSpaces) 165 { 166 QFileInfo fi; 167 int counter = nameSpaces.count(); 168 for (int i = counter; --i >= 0;) { 169 const QString& nameSpace = nameSpaces.at(i); 170 fi.setFile(user.documentationFileName(nameSpace)); 171 if (!fi.exists() || !fi.isFile()) { 172 user.unregisterDocumentation(nameSpace); 173 nameSpaces.removeAll(nameSpace); 174 } 175 } 176 return (counter != nameSpaces.count()) ? false : true; 113 void stripNonexistingDocs(QHelpEngineCore& collection) 114 { 115 TRACE_OBJ 116 const QStringList &namespaces = collection.registeredDocumentations(); 117 foreach (const QString &ns, namespaces) { 118 QFileInfo fi(collection.documentationFileName(ns)); 119 if (!fi.exists() || !fi.isFile()) 120 collection.unregisterDocumentation(ns); 121 } 177 122 } 178 123 179 124 QString indexFilesFolder(const QString &collectionFile) 180 125 { 126 181 127 QString indexFilesFolder = QLatin1String(".fulltextsearch"); 182 128 if (!collectionFile.isEmpty()) { … … 188 134 } 189 135 190 int main(int argc, char *argv[]) 191 { 192 #ifndef Q_OS_WIN 193 // First do a quick search for arguments that imply command-line mode. 136 /* 137 * Returns the expected absolute file path of the cached collection file 138 * correspondinging to the given collection's file. 139 * It may or may not exist yet. 140 */ 141 QString constructCachedCollectionFilePath(const QHelpEngineCore &collection) 142 { 143 TRACE_OBJ 144 const QString &filePath = collection.collectionFile(); 145 const QString &fileName = QFileInfo(filePath).fileName(); 146 const QString &cacheDir = CollectionConfiguration::cacheDir(collection); 147 const QString &dir = !cacheDir.isEmpty() 148 && CollectionConfiguration::cacheDirIsRelativeToCollection(collection) 149 ? QFileInfo(filePath).dir().absolutePath() 150 + QDir::separator() + cacheDir 151 : MainWindow::collectionFileDirectory(false, cacheDir); 152 return dir + QDir::separator() + fileName; 153 } 154 155 bool synchronizeDocs(QHelpEngineCore &collection, 156 QHelpEngineCore &cachedCollection, 157 CmdLineParser &cmd) 158 { 159 TRACE_OBJ 160 const QDateTime &lastCollectionRegisterTime = 161 CollectionConfiguration::lastRegisterTime(collection); 162 if (!lastCollectionRegisterTime.isValid() || lastCollectionRegisterTime 163 < CollectionConfiguration::lastRegisterTime(cachedCollection)) 164 return true; 165 166 const QStringList &docs = collection.registeredDocumentations(); 167 const QStringList &cachedDocs = cachedCollection.registeredDocumentations(); 168 169 /* 170 * Ensure that the cached collection contains all docs that 171 * the collection contains. 172 */ 173 foreach (const QString &doc, docs) { 174 if (!cachedDocs.contains(doc)) { 175 const QString &docFile = collection.documentationFileName(doc); 176 if (!cachedCollection.registerDocumentation(docFile)) { 177 cmd.showMessage(QCoreApplication::translate("Assistant", 178 "Error registering documentation file '%1': %2"). 179 arg(docFile).arg(cachedCollection.error()), true); 180 return false; 181 } 182 } 183 } 184 185 CollectionConfiguration::updateLastRegisterTime(cachedCollection); 186 187 return true; 188 } 189 190 bool removeSearchIndex(const QString &collectionFile) 191 { 192 TRACE_OBJ 193 QString path = QFileInfo(collectionFile).path(); 194 path += QLatin1Char('/') + indexFilesFolder(collectionFile); 195 196 QLocalSocket localSocket; 197 localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) 198 .arg(QLatin1String(QT_VERSION_STR))); 199 200 QDir dir(path); // check if there is no other instance ruinning 201 if (!dir.exists() || localSocket.waitForConnected()) 202 return false; 203 204 QStringList lst = dir.entryList(QDir::Files | QDir::Hidden); 205 foreach (const QString &item, lst) 206 dir.remove(item); 207 return true; 208 } 209 210 bool rebuildSearchIndex(QCoreApplication &app, const QString &collectionFile, 211 CmdLineParser &cmd) 212 { 213 TRACE_OBJ 214 QHelpEngine engine(collectionFile); 215 if (!engine.setupData()) { 216 cmd.showMessage(QCoreApplication::translate("Assistant", "Error: %1") 217 .arg(engine.error()), true); 218 return false; 219 } 220 221 QHelpSearchEngine * const searchEngine = engine.searchEngine(); 222 QObject::connect(searchEngine, SIGNAL(indexingFinished()), &app, 223 SLOT(quit())); 224 searchEngine->reindexDocumentation(); 225 return app.exec() == 0; 226 } 227 228 bool useGui(int argc, char *argv[]) 229 { 230 TRACE_OBJ 231 bool gui = true; 232 #ifndef Q_OS_WIN 233 // Look for arguments that imply command-line mode. 194 234 const char * cmdModeArgs[] = { 195 "-help", "-register", "-unregister", "-remove-search-index" 235 "-help", "-register", "-unregister", "-remove-search-index", 236 "-rebuild-search-index" 196 237 }; 197 bool useGui = true;198 238 for (int i = 1; i < argc; ++i) { 199 239 for (size_t j = 0; j < sizeof cmdModeArgs/sizeof *cmdModeArgs; ++j) { 200 240 if(strcmp(argv[i], cmdModeArgs[j]) == 0) { 201 useGui = false;241 ui = false; 202 242 break; 203 243 } 204 244 } 205 245 } 206 QApplication a(argc, argv, useGui);207 246 #else 208 QApplication a(argc, argv); 247 Q_UNUSED(argc) 248 Q_UNUSED(argv) 209 249 #endif 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 210 318 a.addLibraryPath(a.applicationDirPath() + QLatin1String("/plugins")); 211 212 CmdLineParser cmd; 213 CmdLineParser::Result res = cmd.parse(a.arguments()); 319 setupTranslations(); 320 321 // Parse arguments. 322 CmdLineParser cmd(a.arguments()); 323 CmdLineParser::Result res = cmd.parse(); 214 324 if (res == CmdLineParser::Help) 215 325 return 0; … … 217 327 return -1; 218 328 219 QString cmdCollectionFile = cmd.collectionFile(); 329 /* 330 * Create the collection objects that we need. We always have the 331 * cached collection file. Depending on whether the user specified 332 * one, we also may have an input collection file. 333 */ 334 const QString collectionFile = cmd.collectionFile(); 335 const bool collectionFileGiven = !collectionFile.isEmpty(); 336 QScopedPointer<QHelpEngineCore> collection; 337 if (collectionFileGiven) { 338 collection.reset(new QHelpEngineCore(collectionFile)); 339 if (!collection->setupData()) { 340 cmd.showMessage(QCoreApplication::translate("Assistant", 341 "Error reading collection file '%1': %2."). 342 arg(collectionFile).arg(collection->error()), true); 343 return EXIT_FAILURE; 344 } 345 } 346 const QString &cachedCollectionFile = collectionFileGiven 347 ? constructCachedCollectionFilePath(*collection) 348 : MainWindow::defaultHelpCollectionFileName(); 349 if (collectionFileGiven && !QFileInfo(cachedCollectionFile).exists() 350 && !collection->copyCollectionFile(cachedCollectionFile)) { 351 cmd.showMessage(QCoreApplication::translate("Assistant", 352 "Error creating collection file '%1': %2."). 353 arg(cachedCollectionFile).arg(collection->error()), true); 354 return EXIT_FAILURE; 355 } 356 QHelpEngineCore cachedCollection(cachedCollectionFile); 357 if (!cachedCollection.setupData()) { 358 cmd.showMessage(QCoreApplication::translate("Assistant", 359 "Error reading collection file '%1': %2."). 360 arg(cachedCollectionFile). 361 arg(cachedCollection.error()), true); 362 return EXIT_FAILURE; 363 } 364 365 stripNonexistingDocs(cachedCollection); 366 if (collectionFileGiven) { 367 if (CollectionConfiguration::isNewer(*collection, cachedCollection)) 368 CollectionConfiguration::copyConfiguration(*collection, 369 cachedCollection); 370 if (!synchronizeDocs(*collection, cachedCollection, cmd)) 371 return EXIT_FAILURE; 372 } 373 220 374 if (cmd.registerRequest() != CmdLineParser::None) { 221 if (cmdCollectionFile.isEmpty())222 c mdCollectionFile = MainWindow::defaultHelpCollectionFileName();223 QHelpEngineCore help(cmdCollectionFile);224 help.setupData();375 376 c(); 377 378 ); 225 379 if (cmd.registerRequest() == CmdLineParser::Register) { 226 if (!help.registerDocumentation(cmd.helpFile())) { 227 cmd.showMessage( 228 QObject::tr("Could not register documentation file\n%1\n\nReason:\n%2") 229 .arg(cmd.helpFile()).arg(help.error()), true); 230 return -1; 231 } else { 232 cmd.showMessage(QObject::tr("Documentation successfully registered."), 233 false); 234 } 235 } else { 236 QString nsName = QHelpEngineCore::namespaceName(cmd.helpFile()); 237 if (help.unregisterDocumentation(nsName)) { 238 updateLastPagesOnUnregister(help, nsName); 239 cmd.showMessage( 240 QObject::tr("Documentation successfully unregistered."), 241 false); 242 } else { 243 cmd.showMessage(QObject::tr("Could not unregister documentation" 244 " file\n%1\n\nReason:\n%2").arg(cmd.helpFile()). 245 arg(help.error()), true); 246 return -1; 247 } 248 } 249 help.setCustomValue(QLatin1String("DocUpdate"), true); 250 return 0; 380 if (collectionFileGiven 381 && !registerDocumentation(*collection, cmd, true)) 382 return EXIT_FAILURE; 383 if (!cachedDocs.contains(namespaceName) 384 && !registerDocumentation(cachedCollection, cmd, !collectionFileGiven)) 385 return EXIT_FAILURE; 386 return EXIT_SUCCESS; 387 } 388 if (cmd.registerRequest() == CmdLineParser::Unregister) { 389 if (collectionFileGiven 390 && !unregisterDocumentation(*collection, namespaceName, cmd, true)) 391 return EXIT_FAILURE; 392 if (cachedDocs.contains(namespaceName) 393 && !unregisterDocumentation(cachedCollection, namespaceName, 394 cmd, !collectionFileGiven)) 395 return EXIT_FAILURE; 396 return EXIT_SUCCESS; 397 } 251 398 } 252 399 253 400 if (cmd.removeSearchIndex()) { 254 QString file = cmdCollectionFile; 255 if (file.isEmpty()) 256 file = MainWindow::defaultHelpCollectionFileName(); 257 QString path = QFileInfo(file).path(); 258 path += QLatin1Char('/') + indexFilesFolder(file); 259 260 QLocalSocket localSocket; 261 localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) 262 .arg(QLatin1String(QT_VERSION_STR))); 263 264 QDir dir(path); // check if there is no other instance ruinning 265 if (!localSocket.waitForConnected() && dir.exists()) { 266 QStringList lst = dir.entryList(QDir::Files | QDir::Hidden); 267 foreach (const QString &item, lst) 268 dir.remove(item); 269 return 0; 270 } else { 271 return -1; 272 } 273 } 274 275 { 276 QSqlDatabase db; 277 QStringList sqlDrivers(db.drivers()); 278 if (sqlDrivers.isEmpty() 279 || !sqlDrivers.contains(QLatin1String("QSQLITE"))) { 280 cmd.showMessage(QObject::tr("Cannot load sqlite database driver!"), 281 true); 282 return -1; 283 } 284 } 285 286 if (!cmdCollectionFile.isEmpty()) { 287 QHelpEngineCore caller(cmdCollectionFile); 288 if (!caller.setupData()) { 289 cmd.showMessage(QObject::tr("The specified collection file could " 290 "not be read!"), true); 291 return -1; 292 } 293 294 QString fileName = QFileInfo(cmdCollectionFile).fileName(); 295 QString dir = MainWindow::collectionFileDirectory(false, 296 caller.customValue(QLatin1String("CacheDirectory"), 297 QString()).toString()); 298 299 bool collectionFileExists = true; 300 QFileInfo fi(dir + QDir::separator() + fileName); 301 if (!fi.exists()) { 302 collectionFileExists = false; 303 if (!caller.copyCollectionFile(fi.absoluteFilePath())) { 304 cmd.showMessage(caller.error(), true); 305 return -1; 306 } 307 } 308 309 if (collectionFileExists) { 310 QHelpEngineCore user(fi.absoluteFilePath()); 311 if (user.setupData()) { 312 // some docs might have been un/registered 313 bool docUpdate = caller. 314 customValue(QLatin1String("DocUpdate"), false).toBool(); 315 316 // update in case the passed collection file changed 317 if (updateUserCollection(user, caller)) 318 docUpdate = true; 319 320 QStringList userDocs = user.registeredDocumentations(); 321 // update user collection file, docs might have been (re)moved 322 if (!referencedHelpFilesExistAll(user, userDocs)) 323 docUpdate = true; 324 325 if (docUpdate) { 326 QStringList callerDocs = caller.registeredDocumentations(); 327 foreach (const QString &doc, callerDocs) { 328 if (!userDocs.contains(doc)) { 329 user.registerDocumentation( 330 caller.documentationFileName(doc)); 331 } 332 } 333 334 QLatin1String intern("com.trolltech.com.assistantinternal-"); 335 foreach (const QString &doc, userDocs) { 336 if (!callerDocs.contains(doc) && !doc.startsWith(intern)) 337 user.unregisterDocumentation(doc); 338 } 339 340 caller.setCustomValue(QLatin1String("DocUpdate"), false); 341 } 342 } 343 } 344 cmd.setCollectionFile(fi.absoluteFilePath()); 401 return removeSearchIndex(cachedCollectionFile) 402 ? EXIT_SUCCESS : EXIT_FAILURE; 403 } 404 405 if (cmd.rebuildSearchIndex()) { 406 return rebuildSearchIndex(a, cachedCollectionFile, cmd) 407 ? EXIT_SUCCESS : EXIT_FAILURE; 408 } 409 410 if (!QSqlDatabase::isDriverAvailable(QLatin1String("QSQLITE"))) { 411 cmd.showMessage(QCoreApplication::translate("Assistant", 412 "Cannot load sqlite database driver!"), 413 true); 414 return EXIT_FAILURE; 345 415 } 346 416 347 417 if (!cmd.currentFilter().isEmpty()) { 348 QString collectionFile; 349 if (cmdCollectionFile.isEmpty()) { 350 MainWindow::collectionFileDirectory(true); 351 cmdCollectionFile = MainWindow::defaultHelpCollectionFileName(); 352 } 353 354 QHelpEngineCore user(cmdCollectionFile); 355 if (user.setupData()) 356 user.setCurrentFilter(cmd.currentFilter()); 357 } 358 359 const QString& locale = QLocale::system().name(); 360 QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); 361 362 QTranslator translator(0); 363 translator.load(QLatin1String("assistant_") + locale, resourceDir); 364 a.installTranslator(&translator); 365 366 QTranslator qtTranslator(0); 367 qtTranslator.load(QLatin1String("qt_") + locale, resourceDir); 368 a.installTranslator(&qtTranslator); 369 370 QTranslator qtHelpTranslator(0); 371 qtHelpTranslator.load(QLatin1String("qt_help_") + locale, resourceDir); 372 a.installTranslator(&qtHelpTranslator); 373 374 MainWindow w(&cmd); 375 w.show(); 418 if (collectionFileGiven) 419 collection->setCurrentFilter(cmd.currentFilter()); 420 cachedCollection.setCurrentFilter(cmd.currentFilter()); 421 } 422 423 if (collectionFileGiven) 424 cmd.setCollectionFile(cachedCollectionFile); 425 426 MainWindow *w = new MainWindow(&cmd); 427 w->show(); 376 428 a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); 377 return a.exec(); 378 } 429 430 /* 431 * We need to be careful here: The main window has to be deleted before 432 * the help engine wrapper, which has to be deleted before the 433 * QApplication. 434 */ 435 const int retval = a.exec(); 436 delete w; 437 HelpEngineWrapper::removeInstance(); 438 return retval; 439 } -
trunk/tools/assistant/tools/assistant/mainwindow.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "mainwindow.h" 44 45 43 46 #include "centralwidget.h" 44 #include "helpviewer.h"45 47 #include "indexwindow.h" 46 48 #include "topicchooser.h" 47 49 #include "contentwindow.h" 48 50 #include "preferencesdialog.h" 49 #include " bookmarkmanager.h"51 #include "er.h" 50 52 #include "remotecontrol.h" 51 53 #include "cmdlineparser.h" … … 54 56 #include "qtdocinstaller.h" 55 57 58 59 56 60 #include <QtCore/QDir> 57 61 #include <QtCore/QTimer> 62 58 63 #include <QtCore/QDebug> 64 65 59 66 #include <QtCore/QResource> 60 67 #include <QtCore/QByteArray> … … 77 84 #include <QtGui/QDesktopServices> 78 85 #include <QtGui/QToolButton> 79 80 #include <QtHelp/QHelpEngine> 86 #include <QtGui/QFileDialog> 87 88 #include <QtHelp/QHelpEngineCore> 81 89 #include <QtHelp/QHelpSearchEngine> 82 90 #include <QtHelp/QHelpContentModel> … … 87 95 MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) 88 96 : QMainWindow(parent) 97 89 98 , m_filterCombo(0) 90 99 , m_toolBarMenu(0) … … 94 103 , m_connectedInitSignals(false) 95 104 { 105 106 96 107 setToolButtonStyle(Qt::ToolButtonFollowStyle); 97 108 109 98 110 if (usesDefaultCollection()) { 99 111 MainWindow::collectionFileDirectory(true); 100 m_helpEngine = new QHelpEngine(MainWindow::defaultHelpCollectionFileName(), 101 this); 112 collectionFile = MainWindow::defaultHelpCollectionFileName(); 102 113 } else { 103 m_helpEngine = new QHelpEngine(cmdLine->collectionFile(), this); 104 } 105 106 m_centralWidget = new CentralWidget(m_helpEngine, this); 114 collectionFile = cmdLine->collectionFile(); 115 } 116 HelpEngineWrapper &helpEngineWrapper = 117 HelpEngineWrapper::instance(collectionFile); 118 119 m_centralWidget = new CentralWidget(this); 107 120 setCentralWidget(m_centralWidget); 108 121 109 m_indexWindow = new IndexWindow( m_helpEngine);122 m_indexWindow = new IndexWindow(); 110 123 QDockWidget *indexDock = new QDockWidget(tr("Index"), this); 111 124 indexDock->setObjectName(QLatin1String("IndexWindow")); … … 113 126 addDockWidget(Qt::LeftDockWidgetArea, indexDock); 114 127 115 m_contentWindow = new ContentWindow (m_helpEngine);128 m_contentWindow = new ContentWindow; 116 129 QDockWidget *contentDock = new QDockWidget(tr("Contents"), this); 117 130 contentDock->setObjectName(QLatin1String("ContentWindow")); … … 119 132 addDockWidget(Qt::LeftDockWidgetArea, contentDock); 120 133 121 QDockWidget *bookmarkDock = new QDockWidget(tr("Bookmarks"), this); 122 bookmarkDock->setObjectName(QLatin1String("BookmarkWindow")); 123 bookmarkDock->setWidget(setupBookmarkWidget()); 124 addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock); 125 126 QHelpSearchEngine *searchEngine = m_helpEngine->searchEngine(); 134 QDockWidget *bookmarkDock = 0; 135 if (BookmarkManager *manager = BookmarkManager::instance()) { 136 bookmarkDock = new QDockWidget(tr("Bookmarks"), this); 137 bookmarkDock->setObjectName(QLatin1String("BookmarkWindow")); 138 bookmarkDock->setWidget(m_bookmarkWidget = manager->bookmarkDockWidget()); 139 addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock); 140 141 connect(manager, SIGNAL(escapePressed()), this, 142 SLOT(activateCurrentCentralWidgetTab())); 143 connect(manager, SIGNAL(setSource(QUrl)), m_centralWidget, 144 SLOT(setSource(QUrl))); 145 connect(manager, SIGNAL(setSourceInNewTab(QUrl)), m_centralWidget, 146 SLOT(setSourceInNewTab(QUrl))); 147 connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)), manager, 148 SLOT(addBookmark(QString, QString))); 149 } 150 151 QHelpSearchEngine *searchEngine = helpEngineWrapper.searchEngine(); 127 152 connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted())); 128 153 connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished())); … … 137 162 statusBar()->show(); 138 163 139 if (initHelpDB( )) {164 if (initHelpDB()) { 140 165 setupFilterToolbar(); 141 166 setupAddressToolbar(); 142 167 143 m_bookmarkManager->setupBookmarkModels(); 144 m_bookmarkMenu->addSeparator(); 145 m_bookmarkManager->fillBookmarkMenu(m_bookmarkMenu); 146 connect(m_bookmarkMenu, SIGNAL(triggered(QAction*)), this, 147 SLOT(showBookmark(QAction*))); 148 connect(m_bookmarkManager, SIGNAL(bookmarksChanged()), this, 149 SLOT(updateBookmarkMenu())); 150 151 setWindowTitle(m_helpEngine->customValue(QLatin1String("WindowTitle"), 152 defWindowTitle).toString()); 153 QByteArray iconArray = m_helpEngine->customValue(QLatin1String("ApplicationIcon"), 154 QByteArray()).toByteArray(); 168 const QString windowTitle = helpEngineWrapper.windowTitle(); 169 setWindowTitle(windowTitle.isEmpty() ? defWindowTitle : windowTitle); 170 QByteArray iconArray = helpEngineWrapper.applicationIcon(); 155 171 if (iconArray.size() > 0) { 156 172 QPixmap pix; … … 166 182 // on x11. 167 183 show(); 168 QByteArray ba( m_helpEngine->customValue(QLatin1String("MainWindow")).toByteArray());184 QByteArray ba(()); 169 185 if (!ba.isEmpty()) 170 186 restoreState(ba); 171 187 172 ba = m_helpEngine->customValue(QLatin1String("MainWindowGeometry")).toByteArray();188 ba = y(); 173 189 if (!ba.isEmpty()) { 174 190 restoreGeometry(ba); 175 191 } else { 176 192 tabifyDockWidget(contentDock, indexDock); 177 tabifyDockWidget(indexDock, bookmarkDock); 193 if (bookmarkDock) 194 tabifyDockWidget(indexDock, bookmarkDock); 178 195 contentDock->raise(); 179 196 resize(QSize(800, 600)); 180 197 } 181 198 182 if (!m_helpEngine->customValue(QLatin1String("useAppFont")).isValid()) { 183 m_helpEngine->setCustomValue(QLatin1String("useAppFont"), false); 184 m_helpEngine->setCustomValue(QLatin1String("useBrowserFont"), false); 185 m_helpEngine->setCustomValue(QLatin1String("appFont"), qApp->font()); 186 m_helpEngine->setCustomValue(QLatin1String("appWritingSystem"), 187 QFontDatabase::Latin); 188 m_helpEngine->setCustomValue(QLatin1String("browserFont"), qApp->font()); 189 m_helpEngine->setCustomValue(QLatin1String("browserWritingSystem"), 190 QFontDatabase::Latin); 199 if (!helpEngineWrapper.hasFontSettings()) { 200 helpEngineWrapper.setUseAppFont(false); 201 helpEngineWrapper.setUseBrowserFont(false); 202 helpEngineWrapper.setAppFont(qApp->font()); 203 helpEngineWrapper.setAppWritingSystem(QFontDatabase::Latin); 204 helpEngineWrapper.setBrowserFont(qApp->font()); 205 helpEngineWrapper.setBrowserWritingSystem(QFontDatabase::Latin); 191 206 } else { 192 207 updateApplicationFont(); … … 197 212 QTimer::singleShot(0, this, SLOT(insertLastPages())); 198 213 if (m_cmdLine->enableRemoteControl()) 199 (void)new RemoteControl(this , m_helpEngine);214 (void)new RemoteControl(this); 200 215 201 216 if (m_cmdLine->contents() == CmdLineParser::Show) … … 210 225 211 226 if (m_cmdLine->bookmarks() == CmdLineParser::Show) 212 showBookmarks ();227 showBookmarks(); 213 228 else if (m_cmdLine->bookmarks() == CmdLineParser::Hide) 214 hideBookmarks ();229 hideBookmarks(); 215 230 216 231 if (m_cmdLine->search() == CmdLineParser::Show) … … 224 239 showIndex(); 225 240 else if (m_cmdLine->bookmarks() == CmdLineParser::Activate) 226 showBookmarks ();241 showBookmarks(); 227 242 228 243 if (!m_cmdLine->currentFilter().isEmpty()) { 229 244 const QString &curFilter = m_cmdLine->currentFilter(); 230 if ( m_helpEngine->customFilters().contains(curFilter))231 m_helpEngine->setCurrentFilter(curFilter);245 if (customFilters().contains(curFilter)) 246 setCurrentFilter(curFilter); 232 247 } 233 248 … … 236 251 else 237 252 checkInitState(); 253 254 255 256 257 238 258 } 239 259 setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); … … 242 262 MainWindow::~MainWindow() 243 263 { 264 244 265 if (m_qtDocInstaller) 245 266 delete m_qtDocInstaller; … … 248 269 bool MainWindow::usesDefaultCollection() const 249 270 { 271 250 272 return m_cmdLine->collectionFile().isEmpty(); 251 273 } … … 253 275 void MainWindow::closeEvent(QCloseEvent *e) 254 276 { 255 m_bookmarkManager->saveBookmarks(); 256 m_helpEngine->setCustomValue(QLatin1String("MainWindow"), saveState()); 257 m_helpEngine->setCustomValue(QLatin1String("MainWindowGeometry"), 258 saveGeometry()); 259 277 TRACE_OBJ 278 BookmarkManager::destroy(); 279 HelpEngineWrapper::instance().setMainWindow(saveState()); 280 HelpEngineWrapper::instance().setMainWindowGeometry(saveGeometry()); 260 281 QMainWindow::closeEvent(e); 261 282 } 262 283 263 bool MainWindow::initHelpDB() 264 { 265 if (!m_helpEngine->setupData()) 284 bool MainWindow::initHelpDB(bool registerInternalDoc) 285 { 286 TRACE_OBJ 287 HelpEngineWrapper &helpEngineWrapper = HelpEngineWrapper::instance(); 288 if (!helpEngineWrapper.setupData()) 266 289 return false; 267 290 291 292 293 294 295 268 296 bool assistantInternalDocRegistered = false; 269 297 QString intern(QLatin1String("com.trolltech.com.assistantinternal-")); 270 foreach (const QString &ns, m_helpEngine->registeredDocumentations()) {298 foreach (const QString &ns, registeredDocumentations()) { 271 299 if (ns.startsWith(intern)) { 272 300 intern = ns; … … 276 304 } 277 305 278 const QString &collectionFile = m_helpEngine->collectionFile(); 279 306 const QString &collectionFile = helpEngineWrapper.collectionFile(); 280 307 QFileInfo fi(collectionFile); 281 308 QString helpFile; … … 294 321 file.close(); 295 322 } 296 QHelpEngineCore hc(fi.absoluteFilePath()); 297 hc.setupData(); 298 hc.unregisterDocumentation(intern); 299 hc.registerDocumentation(helpFile); 323 helpEngineWrapper.unregisterDocumentation(intern); 324 helpEngineWrapper.registerDocumentation(helpFile); 300 325 needsSetup = true; 301 326 } 302 327 303 const QLatin1String unfiltered("UnfilteredFilterInserted");304 if (1 != m_helpEngine->customValue(unfiltered).toInt()) {305 {306 QHelpEngineCore hc(collectionFile);307 hc.setupData();308 hc.addCustomFilter(tr("Unfiltered"), QStringList());309 hc.setCustomValue(unfiltered, 1);310 }311 312 m_helpEngine->blockSignals(true);313 m_helpEngine->setCurrentFilter(tr("Unfiltered"));314 m_helpEngine->blockSignals(false);315 needsSetup = true;316 }317 318 328 if (needsSetup) 319 m_helpEngine->setupData();329 setupData(); 320 330 return true; 321 331 } … … 323 333 void MainWindow::lookForNewQtDocumentation() 324 334 { 325 m_qtDocInstaller = new QtDocInstaller(m_helpEngine->collectionFile()); 326 connect(m_qtDocInstaller, SIGNAL(errorMessage(QString)), this, 327 SLOT(displayInstallationError(QString))); 335 TRACE_OBJ 336 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 337 QStringList docs; 338 docs << QLatin1String("assistant") 339 << QLatin1String("designer") 340 << QLatin1String("linguist") 341 << QLatin1String("qmake") 342 << QLatin1String("qt"); 343 QList<QtDocInstaller::DocInfo> qtDocInfos; 344 foreach (const QString &doc, docs) 345 qtDocInfos.append(QtDocInstaller::DocInfo(doc, helpEngine.qtDocInfo(doc))); 346 347 m_qtDocInstaller = new QtDocInstaller(qtDocInfos); 328 348 connect(m_qtDocInstaller, SIGNAL(docsInstalled(bool)), this, 329 SLOT(qtDocumentationInstalled(bool))); 330 331 QString versionKey = QString(QLatin1String("qtVersion%1$$$qt")). 332 arg(QLatin1String(QT_VERSION_STR)); 333 if (m_helpEngine->customValue(versionKey, 0).toInt() != 1) 349 SLOT(qtDocumentationInstalled())); 350 connect(m_qtDocInstaller, SIGNAL(qchFileNotFound(QString)), this, 351 SLOT(resetQtDocInfo(QString))); 352 connect(m_qtDocInstaller, SIGNAL(registerDocumentation(QString, QString)), 353 this, SLOT(registerDocumentation(QString, QString))); 354 if (helpEngine.qtDocInfo(QLatin1String("qt")).count() != 2) 334 355 statusBar()->showMessage(tr("Looking for Qt Documentation...")); 335 356 m_qtDocInstaller->installDocs(); 336 357 } 337 358 338 void MainWindow::displayInstallationError(const QString &errorMessage) 339 { 340 QMessageBox::warning(this, tr("Qt Assistant"), errorMessage); 341 } 342 343 void MainWindow::qtDocumentationInstalled(bool newDocsInstalled) 344 { 345 if (newDocsInstalled) 346 m_helpEngine->setupData(); 359 void MainWindow::qtDocumentationInstalled() 360 { 361 TRACE_OBJ 347 362 statusBar()->clearMessage(); 348 363 checkInitState(); … … 351 366 void MainWindow::checkInitState() 352 367 { 368 369 353 370 if (!m_cmdLine->enableRemoteControl()) 354 371 return; 355 372 356 if (m_helpEngine->contentModel()->isCreatingContents() 357 || m_helpEngine->indexModel()->isCreatingIndex()) { 373 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 374 if (helpEngine.contentModel()->isCreatingContents() 375 || helpEngine.indexModel()->isCreatingIndex()) { 358 376 if (!m_connectedInitSignals) { 359 connect( m_helpEngine->contentModel(), SIGNAL(contentsCreated()),377 connect(contentModel(), SIGNAL(contentsCreated()), 360 378 this, SLOT(checkInitState())); 361 connect( m_helpEngine->indexModel(), SIGNAL(indexCreated()), this,379 connect(indexModel(), SIGNAL(indexCreated()), this, 362 380 SLOT(checkInitState())); 363 381 m_connectedInitSignals = true; … … 365 383 } else { 366 384 if (m_connectedInitSignals) { 367 disconnect( m_helpEngine->contentModel(), 0, this, 0);368 disconnect( m_helpEngine->indexModel(), 0, this, 0);385 disconnect(contentModel(), 0, this, 0); 386 disconnect(indexModel(), 0, this, 0); 369 387 } 370 388 emit initDone(); … … 372 390 } 373 391 374 void MainWindow::updateBookmarkMenu()375 {376 if (m_bookmarkManager) {377 m_bookmarkMenu->removeAction(m_bookmarkMenuAction);378 379 m_bookmarkMenu->clear();380 381 m_bookmarkMenu->addAction(m_bookmarkMenuAction);382 m_bookmarkMenu->addSeparator();383 384 m_bookmarkManager->fillBookmarkMenu(m_bookmarkMenu);385 }386 }387 388 void MainWindow::showBookmark(QAction *action)389 {390 if (m_bookmarkManager) {391 const QUrl &url = m_bookmarkManager->urlForAction(action);392 if (url.isValid())393 m_centralWidget->setSource(url);394 }395 }396 397 392 void MainWindow::insertLastPages() 398 393 { 394 399 395 if (m_cmdLine->url().isValid()) 400 396 m_centralWidget->setSource(m_cmdLine->url()); … … 408 404 void MainWindow::setupActions() 409 405 { 406 410 407 QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); 411 408 #ifdef Q_OS_MAC … … 418 415 QMenu *menu = menuBar()->addMenu(tr("&File")); 419 416 417 418 419 420 421 420 422 m_pageSetupAction = menu->addAction(tr("Page Set&up..."), m_centralWidget, 421 423 SLOT(pageSetup())); … … 430 432 menu->addSeparator(); 431 433 432 m_newTabAction = menu->addAction(tr("New &Tab"), m_centralWidget, SLOT(newTab()));433 m_newTabAction->setShortcut(QKeySequence::AddTab);434 435 434 m_closeTabAction = menu->addAction(tr("&Close Tab"), m_centralWidget, 436 435 SLOT(closeTab())); 437 436 m_closeTabAction->setShortcuts(QKeySequence::Close); 438 437 439 QAction *tmp = menu->addAction(tr("&Quit"), this, SLOT(close())); 438 QAction *tmp = menu->addAction(QIcon::fromTheme("application-exit"), 439 tr("&Quit"), this, SLOT(close())); 440 tmp->setMenuRole(QAction::QuitRole); 441 #ifdef Q_OS_WIN 442 tmp->setShortcut(QKeySequence(tr("CTRL+Q"))); 443 #else 440 444 tmp->setShortcut(QKeySequence::Quit); 441 tmp->setMenuRole(QAction::QuitRole); 445 #endif 442 446 443 447 menu = menuBar()->addMenu(tr("&Edit")); … … 493 497 m_viewMenu->addAction(tr("Index"), this, SLOT(showIndex()), 494 498 QKeySequence(tr("ALT+I"))); 495 m_viewMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarks ()),499 m_viewMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarks()), 496 500 QKeySequence(tr("ALT+O"))); 497 501 m_viewMenu->addAction(tr("Search"), this, SLOT(showSearchWidget()), … … 529 533 << QKeySequence(Qt::CTRL + Qt::Key_PageUp)); 530 534 531 m_bookmarkMenu = menuBar()->addMenu(tr("&Bookmarks")); 532 m_bookmarkMenuAction = m_bookmarkMenu->addAction(tr("Add Bookmark..."), 533 this, SLOT(addBookmark())); 534 m_bookmarkMenuAction->setShortcut(tr("CTRL+D")); 535 if (BookmarkManager *manager = BookmarkManager::instance()) 536 manager->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks"))); 535 537 536 538 menu = menuBar()->addMenu(tr("&Help")); … … 539 541 540 542 #ifdef Q_WS_X11 543 544 541 545 m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon())); 542 546 m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon())); … … 548 552 m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon())); 549 553 m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon())); 554 555 550 556 m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon())); 557 551 558 #endif 552 559 … … 593 600 connect(m_centralWidget, SIGNAL(highlighted(QString)), statusBar(), 594 601 SLOT(showMessage(QString))); 595 connect(m_centralWidget, SIGNAL(addNewBookmark(QString,QString)), this,596 SLOT(addNewBookmark(QString,QString)));597 598 // bookmarks599 connect(m_bookmarkWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,600 SLOT(setSource(QUrl)));601 connect(m_bookmarkWidget, SIGNAL(escapePressed()), this,602 SLOT(activateCurrentCentralWidgetTab()));603 602 604 603 // index window … … 625 624 QMenu *MainWindow::toolBarMenu() 626 625 { 626 627 627 if (!m_toolBarMenu) { 628 628 m_viewMenu->addSeparator(); … … 634 634 void MainWindow::setupFilterToolbar() 635 635 { 636 if (!m_helpEngine-> 637 customValue(QLatin1String("EnableFilterFunctionality"), true).toBool()) 636 TRACE_OBJ 637 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 638 if (!helpEngine.filterFunctionalityEnabled()) 638 639 return; 639 640 … … 648 649 filterToolBar->addWidget(m_filterCombo); 649 650 650 const QLatin1String hideFilter("HideFilterFunctionality"); 651 if (m_helpEngine->customValue(hideFilter, true).toBool()) 651 if (!helpEngine.filterToolbarVisible()) 652 652 filterToolBar->hide(); 653 653 toolBarMenu()->addAction(filterToolBar->toggleViewAction()); 654 654 655 connect( m_helpEngine, SIGNAL(setupFinished()), this,656 SLOT(setupFilterCombo()) );655 connect(helpEngine, SIGNAL(setupFinished()), this, 656 SLOT(setupFilterCombo())); 657 657 connect(m_filterCombo, SIGNAL(activated(QString)), this, 658 658 SLOT(filterDocumentation(QString))); 659 connect( m_helpEngine, SIGNAL(currentFilterChanged(QString)), this,659 connect(helpEngine, SIGNAL(currentFilterChanged(QString)), this, 660 660 SLOT(currentFilterChanged(QString))); 661 661 … … 665 665 void MainWindow::setupAddressToolbar() 666 666 { 667 if (!m_helpEngine->customValue(QLatin1String("EnableAddressBar"), true).toBool()) 667 TRACE_OBJ 668 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); 669 if (!helpEngine.addressBarEnabled()) 668 670 return; 669 671 … … 677 679 addressToolBar->addWidget(m_addressLineEdit); 678 680 679 if ( m_helpEngine->customValue(QLatin1String("HideAddressBar"), true).toBool())681 if (()) 680 682 addressToolBar->hide(); 681 683 toolBarMenu()->addAction(addressToolBar->toggleViewAction()); … … 692 694 void MainWindow::updateAboutMenuText() 693 695 { 694 if (m_helpEngine) { 695 QByteArray ba = m_helpEngine->customValue(QLatin1String("AboutMenuTexts"), 696 QByteArray()).toByteArray(); 697 if (ba.size() > 0) { 698 QString lang; 699 QString str; 700 QString trStr; 701 QString currentLang = QLocale::system().name(); 702 int i = currentLang.indexOf(QLatin1Char('_')); 703 if (i > -1) 704 currentLang = currentLang.left(i); 705 QDataStream s(&ba, QIODevice::ReadOnly); 706 while (!s.atEnd()) { 707 s >> lang; 708 s >> str; 709 if (lang == QLatin1String("default") && trStr.isEmpty()) { 710 trStr = str; 711 } else if (lang == currentLang) { 712 trStr = str; 713 break; 714 } 696 TRACE_OBJ 697 QByteArray ba = HelpEngineWrapper::instance().aboutMenuTexts(); 698 if (ba.size() > 0) { 699 QString lang; 700 QString str; 701 QString trStr; 702 QString currentLang = QLocale::system().name(); 703 int i = currentLang.indexOf(QLatin1Char('_')); 704 if (i > -1) 705 currentLang = currentLang.left(i); 706 QDataStream s(&ba, QIODevice::ReadOnly); 707 while (!s.atEnd()) { 708 s >> lang; 709 s >> str; 710 if (lang == QLatin1String("default") && trStr.isEmpty()) { 711 trStr = str; 712 } else if (lang == currentLang) { 713 trStr = str; 714 break; 715 715 } 716 if (!trStr.isEmpty())717 m_aboutAction->setText(trStr);718 716 } 717 718 719 719 } 720 720 } … … 722 722 void MainWindow::showNewAddress() 723 723 { 724 724 725 showNewAddress(m_centralWidget->currentSource()); 725 726 } … … 727 728 void MainWindow::showNewAddress(const QUrl &url) 728 729 { 730 729 731 m_addressLineEdit->setText(url.toString()); 730 732 } 731 733 732 void MainWindow::addBookmark()733 {734 addNewBookmark(m_centralWidget->currentTitle(),735 m_centralWidget->currentSource().toString());736 }737 738 734 void MainWindow::gotoAddress() 739 735 { 736 740 737 m_centralWidget->setSource(m_addressLineEdit->text()); 741 738 } … … 743 740 void MainWindow::updateNavigationItems() 744 741 { 742 745 743 bool hasCurrentViewer = m_centralWidget->isHomeAvailable(); 746 744 m_copyAction->setEnabled(m_centralWidget->hasSelection()); … … 756 754 void MainWindow::updateTabCloseAction() 757 755 { 756 758 757 m_closeTabAction->setEnabled(m_centralWidget->enableTabCloseAction()); 759 758 } … … 762 761 const QString &keyword) 763 762 { 763 764 764 TopicChooser tc(this, keyword, links); 765 765 if (tc.exec() == QDialog::Accepted) { … … 770 770 void MainWindow::showPreferences() 771 771 { 772 PreferencesDialog dia(m_helpEngine, this);773 772 773 PreferencesDialog dia(this); 774 774 connect(&dia, SIGNAL(updateApplicationFont()), this, 775 775 SLOT(updateApplicationFont())); 776 776 connect(&dia, SIGNAL(updateBrowserFont()), m_centralWidget, 777 777 SLOT(updateBrowserFont())); 778 779 778 dia.showDialog(); 780 779 } … … 782 781 void MainWindow::syncContents() 783 782 { 783 784 784 qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); 785 785 const QUrl url = m_centralWidget->currentSource(); … … 793 793 void MainWindow::copyAvailable(bool yes) 794 794 { 795 795 796 m_copyAction->setEnabled(yes); 796 797 } 797 798 798 void MainWindow::addNewBookmark(const QString &title, const QString &url)799 {800 if (url.isEmpty() || url == QLatin1String("about:blank"))801 return;802 803 m_bookmarkManager->showBookmarkDialog(this, title, url);804 }805 806 799 void MainWindow::showAboutDialog() 807 800 { 801 802 808 803 QByteArray contents; 809 if (m_helpEngine) { 810 QByteArray ba = m_helpEngine->customValue(QLatin1String("AboutTexts"), 811 QByteArray()).toByteArray(); 812 if (!ba.isEmpty()) { 813 QString lang; 814 QByteArray cba; 815 QString currentLang = QLocale::system().name(); 816 int i = currentLang.indexOf(QLatin1Char('_')); 817 if (i > -1) 818 currentLang = currentLang.left(i); 819 QDataStream s(&ba, QIODevice::ReadOnly); 820 while (!s.atEnd()) { 821 s >> lang; 822 s >> cba; 823 if (lang == QLatin1String("default") && contents.isEmpty()) { 824 contents = cba; 825 } else if (lang == currentLang) { 826 contents = cba; 827 break; 828 } 804 QByteArray ba = helpEngine.aboutTexts(); 805 if (!ba.isEmpty()) { 806 QString lang; 807 QByteArray cba; 808 QString currentLang = QLocale::system().name(); 809 int i = currentLang.indexOf(QLatin1Char('_')); 810 if (i > -1) 811 currentLang = currentLang.left(i); 812 QDataStream s(&ba, QIODevice::ReadOnly); 813 while (!s.atEnd()) { 814 s >> lang; 815 s >> cba; 816 if (lang == QLatin1String("default") && contents.isEmpty()) { 817 contents = cba; 818 } else if (lang == currentLang) { 819 contents = cba; 820 break; 829 821 } 830 822 } … … 835 827 QByteArray iconArray; 836 828 if (!contents.isEmpty()) { 837 iconArray = m_helpEngine->customValue(QLatin1String("AboutIcon"), 838 QByteArray()).toByteArray(); 839 QByteArray resources = 840 m_helpEngine->customValue(QLatin1String("AboutImages"), 841 QByteArray()).toByteArray(); 829 iconArray = helpEngine.aboutIcon(); 830 QByteArray resources = helpEngine.aboutImages(); 842 831 QPixmap pix; 843 832 pix.loadFromData(iconArray); … … 848 837 } else { 849 838 QByteArray resources; 850 aboutDia.setText( QString::fromLatin1("<center>"839 aboutDia.setText(("<center>" 851 840 "<h3>%1</h3>" 852 841 "<p>Version %2</p></center>" 853 "<p>Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).</p>")842 "<p>Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).</p>") 854 843 .arg(tr("Qt Assistant")).arg(QLatin1String(QT_VERSION_STR)), 855 844 resources); … … 862 851 } 863 852 853 854 855 856 857 858 859 860 861 864 862 void MainWindow::showContents() 865 863 { 864 866 865 activateDockWidget(m_contentWindow); 867 866 } 868 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 869 883 void MainWindow::showIndex() 870 884 { 885 871 886 activateDockWidget(m_indexWindow); 872 887 } 873 888 874 void MainWindow::showBookmarks() 875 { 876 activateDockWidget(m_bookmarkWidget); 889 void MainWindow::hideIndex() 890 { 891 TRACE_OBJ 892 m_indexWindow->parentWidget()->hide(); 893 } 894 895 void MainWindow::setBookmarksVisible(bool visible) 896 { 897 TRACE_OBJ 898 if (visible) 899 showBookmarksDockWidget(); 900 else 901 hideBookmarksDockWidget(); 902 } 903 904 void MainWindow::showBookmarksDockWidget() 905 { 906 TRACE_OBJ 907 if (m_bookmarkWidget) 908 activateDockWidget(m_bookmarkWidget); 909 } 910 911 void MainWindow::hideBookmarksDockWidget() 912 { 913 TRACE_OBJ 914 if (m_bookmarkWidget) 915 m_bookmarkWidget->parentWidget()->hide(); 916 } 917 918 void MainWindow::setSearchVisible(bool visible) 919 { 920 TRACE_OBJ 921 if (visible) 922 showSearch(); 923 else 924 hideSearch(); 925 } 926 927 void MainWindow::showSearch() 928 { 929 TRACE_OBJ 930 m_centralWidget->activateSearchWidget(); 931 } 932 933 void MainWindow::hideSearch() 934 { 935 TRACE_OBJ 936 m_centralWidget->removeSearchWidget(); 877 937 } 878 938 879 939 void MainWindow::activateDockWidget(QWidget *w) 880 940 { 941 881 942 w->parentWidget()->show(); 882 943 w->parentWidget()->raise(); … … 884 945 } 885 946 886 void MainWindow::hideContents()887 {888 m_contentWindow->parentWidget()->hide();889 }890 891 void MainWindow::hideIndex()892 {893 m_indexWindow->parentWidget()->hide();894 }895 896 void MainWindow::hideBookmarks()897 {898 m_bookmarkWidget->parentWidget()->hide();899 }900 901 947 void MainWindow::setIndexString(const QString &str) 902 948 { 949 903 950 m_indexWindow->setSearchLineEditText(str); 904 951 } … … 906 953 void MainWindow::activateCurrentBrowser() 907 954 { 955 908 956 CentralWidget *cw = CentralWidget::instance(); 909 957 if (cw) { … … 914 962 void MainWindow::activateCurrentCentralWidgetTab() 915 963 { 964 916 965 m_centralWidget->activateTab(); 917 966 } 918 967 919 void MainWindow::showSearch()920 {921 m_centralWidget->activateSearchWidget();922 }923 924 968 void MainWindow::showSearchWidget() 925 969 { 970 926 971 m_centralWidget->activateSearchWidget(true); 927 972 } 928 973 929 void MainWindow::hideSearch()930 {931 m_centralWidget->removeSearchWidget();932 }933 934 974 void MainWindow::updateApplicationFont() 935 975 { 976 977 936 978 QFont font = qApp->font(); 937 if (m_helpEngine->customValue(QLatin1String("useAppFont")).toBool()) 938 font = qVariantValue<QFont>(m_helpEngine->customValue(QLatin1String("appFont"))); 939 940 qApp->setFont(font, "QWidget"); 979 if (helpEngine.usesAppFont()) 980 font = helpEngine.appFont(); 981 982 const QWidgetList &widgets = qApp->allWidgets(); 983 foreach (QWidget* widget, widgets) 984 widget->setFont(font); 941 985 } 942 986 943 987 void MainWindow::setupFilterCombo() 944 988 { 989 990 945 991 QString curFilter = m_filterCombo->currentText(); 946 992 if (curFilter.isEmpty()) 947 curFilter = m_helpEngine->currentFilter();993 curFilter = currentFilter(); 948 994 m_filterCombo->clear(); 949 m_filterCombo->addItems( m_helpEngine->customFilters());995 m_filterCombo->addItems(customFilters()); 950 996 int idx = m_filterCombo->findText(curFilter); 951 997 if (idx < 0) … … 956 1002 void MainWindow::filterDocumentation(const QString &customFilter) 957 1003 { 958 m_helpEngine->setCurrentFilter(customFilter); 1004 TRACE_OBJ 1005 HelpEngineWrapper::instance().setCurrentFilter(customFilter); 959 1006 } 960 1007 961 1008 void MainWindow::expandTOC(int depth) 962 1009 { 1010 1011 963 1012 m_contentWindow->expandToDepth(depth); 964 1013 } … … 966 1015 void MainWindow::indexingStarted() 967 1016 { 1017 968 1018 if (!m_progressWidget) { 969 1019 m_progressWidget = new QWidget(); … … 991 1041 void MainWindow::indexingFinished() 992 1042 { 1043 993 1044 statusBar()->removeWidget(m_progressWidget); 994 1045 delete m_progressWidget; … … 996 1047 } 997 1048 998 QWidget* MainWindow::setupBookmarkWidget()999 {1000 m_bookmarkManager = new BookmarkManager(m_helpEngine);1001 m_bookmarkWidget = new BookmarkWidget(m_bookmarkManager, this);1002 connect(m_bookmarkWidget, SIGNAL(addBookmark()), this, SLOT(addBookmark()));1003 return m_bookmarkWidget;1004 }1005 1006 1049 QString MainWindow::collectionFileDirectory(bool createDir, const QString &cacheDir) 1007 1050 { 1051 1008 1052 QString collectionPath = 1009 1053 QDesktopServices::storageLocation(QDesktopServices::DataLocation); … … 1031 1075 QString MainWindow::defaultHelpCollectionFileName() 1032 1076 { 1033 return collectionFileDirectory() + QDir::separator() + 1077 TRACE_OBJ 1078 // forces creation of the default collection file path 1079 return collectionFileDirectory(true) + QDir::separator() + 1034 1080 QString(QLatin1String("qthelpcollection_%1.qhc")). 1035 1081 arg(QLatin1String(QT_VERSION_STR)); … … 1038 1084 void MainWindow::currentFilterChanged(const QString &filter) 1039 1085 { 1086 1040 1087 const int index = m_filterCombo->findText(filter); 1041 1088 Q_ASSERT(index != -1); … … 1043 1090 } 1044 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1045 1138 QT_END_NAMESPACE -
trunk/tools/assistant/tools/assistant/mainwindow.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 49 49 50 50 class QAction; 51 51 52 class QLineEdit; 52 53 class QComboBox; … … 58 59 class CentralWidget; 59 60 class ContentWindow; 60 class BookmarkManager;61 class BookmarkWidget;62 61 class CmdLineParser; 63 62 class QtDocInstaller; … … 68 67 69 68 public: 70 MainWindow(CmdLineParser *cmdLine, QWidget *parent = 0);69 MainWindow(CmdLineParser *cmdLine, QWidget *parent = 0); 71 70 ~MainWindow(); 72 71 … … 77 76 78 77 public: 79 void hideContents();80 void hideIndex();81 void hideBookmarks();82 void hideSearch();83 78 void setIndexString(const QString &str); 84 79 void expandTOC(int depth); … … 89 84 90 85 public slots: 91 void s howContents();92 void s howIndex();93 void s howBookmarks();94 void s howSearch();86 void s); 87 void s); 88 void s); 89 void s); 95 90 void showSearchWidget(); 96 91 void syncContents(); … … 99 94 100 95 private slots: 96 97 98 101 99 void insertLastPages(); 102 void addBookmark();103 100 void gotoAddress(); 104 101 void showPreferences(); … … 109 106 void updateTabCloseAction(); 110 107 void showNewAddress(const QUrl &url); 111 void addNewBookmark(const QString &title, const QString &url);112 108 void showTopicChooser(const QMap<QString, QUrl> &links, const QString &keyword); 113 109 void updateApplicationFont(); … … 117 113 void indexingStarted(); 118 114 void indexingFinished(); 119 void displayInstallationError(const QString &errorMessage); 120 void qtDocumentationInstalled(bool newDocsInstalled); 115 void qtDocumentationInstalled(); 116 void registerDocumentation(const QString &component, 117 const QString &absFileName); 118 void resetQtDocInfo(const QString &component); 121 119 void checkInitState(); 122 123 void updateBookmarkMenu(); 124 void showBookmark(QAction *action); 120 void documentationRemoved(const QString &namespaceName); 121 void documentationUpdated(const QString &namespaceName); 125 122 126 123 private: 127 bool initHelpDB( );124 bool initHelpDB(); 128 125 void setupActions(); 129 126 void closeEvent(QCloseEvent *e); … … 133 130 void setupAddressToolbar(); 134 131 QMenu *toolBarMenu(); 135 QWidget *setupBookmarkWidget(); 132 void hideContents(); 133 void hideIndex(); 134 void hideSearch(); 136 135 137 QHelpEngine *m_helpEngine; 136 private slots: 137 void showBookmarksDockWidget(); 138 void hideBookmarksDockWidget(); 139 140 private: 141 QWidget *m_bookmarkWidget; 142 143 private: 138 144 CentralWidget *m_centralWidget; 139 145 IndexWindow *m_indexWindow; 140 146 ContentWindow *m_contentWindow; 141 BookmarkWidget *m_bookmarkWidget;142 BookmarkManager *m_bookmarkManager;143 147 QLineEdit *m_addressLineEdit; 144 148 QComboBox *m_filterCombo; … … 162 166 QMenu *m_viewMenu; 163 167 QMenu *m_toolBarMenu; 164 QMenu *m_bookmarkMenu;165 QAction *m_bookmarkMenuAction;166 168 167 169 CmdLineParser *m_cmdLine; -
trunk/tools/assistant/tools/assistant/preferencesdialog.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 42 41 #include "preferencesdialog.h" 42 43 43 44 #include "filternamedialog.h" 45 46 44 47 #include "installdialog.h" 45 #include "fontpanel.h" 46 #include "centralwidget.h" 47 #include "aboutdialog.h" 48 49 #include <QtAlgorithms> 50 48 #include "tracer.h" 49 50 #include <QtCore/QtAlgorithms> 51 #include <QtCore/QFileSystemWatcher> 52 53 #include <QtGui/QDesktopWidget> 54 #include <QtGui/QFileDialog> 55 #include <QtGui/QFontDatabase> 51 56 #include <QtGui/QHeaderView> 52 #include <QtGui/Q FileDialog>57 #include <QtGui/Q> 53 58 #include <QtGui/QMessageBox> 54 #include <QtGui/QMenu>55 #include <QtGui/QFontDatabase>56 #include <QtGui/QApplication>57 #include <QtGui/QDesktopWidget>58 59 59 60 #include <QtHelp/QHelpEngineCore> … … 61 62 QT_BEGIN_NAMESPACE 62 63 63 PreferencesDialog::PreferencesDialog(Q HelpEngineCore *helpEngine, QWidget *parent)64 PreferencesDialog::PreferencesDialog(QWidget *parent) 64 65 : QDialog(parent) 65 , m_helpEngine(helpEngine)66 66 , m_appFontChanged(false) 67 67 , m_browserFontChanged(false) 68 { 68 , helpEngine(HelpEngineWrapper::instance()) 69 { 70 TRACE_OBJ 69 71 m_ui.setupUi(this); 70 72 … … 74 76 this, SLOT(reject())); 75 77 76 QLatin1String key("EnableFilterFunctionality"); 77 m_hideFiltersTab = !m_helpEngine->customValue(key, true).toBool(); 78 79 key = QLatin1String("EnableDocumentationManager"); 80 m_hideDocsTab = !m_helpEngine->customValue(key, true).toBool(); 78 m_hideFiltersTab = !helpEngine.filterFunctionalityEnabled(); 79 m_hideDocsTab = !helpEngine.documentationManagerEnabled(); 81 80 82 81 if (!m_hideFiltersTab) { … … 107 106 SLOT(removeDocumentation())); 108 107 109 m_docsBackup = m_helpEngine->registeredDocumentations();108 m_docsBackup = registeredDocumentations(); 110 109 m_ui.registeredDocsListWidget->addItems(m_docsBackup); 111 110 } else { … … 115 114 updateFontSettingsPage(); 116 115 updateOptionsPage(); 116 117 118 117 119 } 118 120 119 121 PreferencesDialog::~PreferencesDialog() 120 122 { 121 QLatin1String key("");123 122 124 if (m_appFontChanged) { 123 key = QLatin1String("appFont"); 124 m_helpEngine->setCustomValue(key, m_appFontPanel->selectedFont()); 125 126 key = QLatin1String("useAppFont"); 127 m_helpEngine->setCustomValue(key, m_appFontPanel->isChecked()); 128 129 key = QLatin1String("appWritingSystem"); 130 m_helpEngine->setCustomValue(key, m_appFontPanel->writingSystem()); 125 helpEngine.setAppFont(m_appFontPanel->selectedFont()); 126 helpEngine.setUseAppFont(m_appFontPanel->isChecked()); 127 helpEngine.setAppWritingSystem(m_appFontPanel->writingSystem()); 128 emit updateApplicationFont(); 131 129 } 132 130 133 131 if (m_browserFontChanged) { 134 key = QLatin1String("browserFont"); 135 m_helpEngine->setCustomValue(key, m_browserFontPanel->selectedFont()); 136 137 key = QLatin1String("useBrowserFont"); 138 m_helpEngine->setCustomValue(key, m_browserFontPanel->isChecked()); 139 140 key = QLatin1String("browserWritingSystem"); 141 m_helpEngine->setCustomValue(key, m_browserFontPanel->writingSystem()); 142 } 143 144 if (m_appFontChanged || m_browserFontChanged) { 145 emit updateApplicationFont(); 132 helpEngine.setBrowserFont(m_browserFontPanel->selectedFont()); 133 helpEngine.setUseBrowserFont(m_browserFontPanel->isChecked()); 134 helpEngine.setBrowserWritingSystem(m_browserFontPanel->writingSystem()); 146 135 emit updateBrowserFont(); 147 136 } … … 150 139 if (homePage.isEmpty()) 151 140 homePage = QLatin1String("help"); 152 m_helpEngine->setCustomValue(QLatin1String("homepage"),homePage);141 homePage); 153 142 154 143 int option = m_ui.helpStartComboBox->currentIndex(); 155 m_helpEngine->setCustomValue(QLatin1String("StartOption"),option);144 option); 156 145 } 157 146 158 147 void PreferencesDialog::showDialog() 159 148 { 149 160 150 if (exec() != Accepted) 161 151 m_appFontChanged = m_browserFontChanged = false; … … 164 154 void PreferencesDialog::updateFilterPage() 165 155 { 166 if (!m_helpEngine) 167 return; 168 156 TRACE_OBJ 169 157 m_ui.filterWidget->clear(); 170 158 m_ui.attributeWidget->clear(); 171 159 172 QHelpEngineCore help(m_helpEngine->collectionFile(), 0);173 help.setupData();174 160 m_filterMapBackup.clear(); 175 const QStringList filters = help.customFilters();161 const QStringList .customFilters(); 176 162 foreach (const QString &filter, filters) { 177 QStringList atts = help.filterAttributes(filter); 163 if (filter == HelpEngineWrapper::TrUnfiltered) 164 continue; 165 QStringList atts = helpEngine.filterAttributes(filter); 178 166 m_filterMapBackup.insert(filter, atts); 179 167 if (!m_filterMap.contains(filter)) … … 183 171 m_ui.filterWidget->addItems(m_filterMap.keys()); 184 172 185 foreach (const QString &a, help .filterAttributes())173 foreach (const QString &a, help.filterAttributes()) 186 174 new QTreeWidgetItem(m_ui.attributeWidget, QStringList() << a); 187 175 188 if ( m_filterMap.keys().count())176 if (()) 189 177 m_ui.filterWidget->setCurrentRow(0); 190 178 } … … 192 180 void PreferencesDialog::updateAttributes(QListWidgetItem *item) 193 181 { 182 194 183 QStringList checkedList; 195 184 if (item) … … 207 196 void PreferencesDialog::updateFilterMap() 208 197 { 198 209 199 if (!m_ui.filterWidget->currentItem()) 210 200 return; … … 225 215 void PreferencesDialog::addFilter() 226 216 { 217 227 218 FilterNameDialog dia(this); 228 219 if (dia.exec() == QDialog::Rejected) … … 242 233 void PreferencesDialog::removeFilter() 243 234 { 235 244 236 QListWidgetItem *item = 245 237 m_ui.filterWidget ->takeItem(m_ui.filterWidget->currentRow()); … … 256 248 void PreferencesDialog::addDocumentationLocal() 257 249 { 250 258 251 const QStringList fileNames = QFileDialog::getOpenFileNames(this, 259 252 tr("Add Documentation"), QString(), tr("Qt Compressed Help Files (*.qch)")); … … 276 269 } 277 270 278 m_helpEngine->registerDocumentation(fileName); 279 m_ui.registeredDocsListWidget->addItem(nameSpace); 280 m_regDocs.append(nameSpace); 281 m_unregDocs.removeAll(nameSpace); 271 if (helpEngine.registerDocumentation(fileName)) { 272 m_ui.registeredDocsListWidget->addItem(nameSpace); 273 m_regDocs.append(nameSpace); 274 m_unregDocs.removeAll(nameSpace); 275 } 282 276 } 283 277 … … 308 302 void PreferencesDialog::removeDocumentation() 309 303 { 304 310 305 bool foundBefore = false; 311 306 CentralWidget* widget = CentralWidget::instance(); … … 339 334 void PreferencesDialog::applyChanges() 340 335 { 336 341 337 bool filtersWereChanged = false; 342 338 if (!m_hideFiltersTab) { … … 371 367 if (filtersWereChanged) { 372 368 foreach (const QString &filter, m_removedFilters) 373 m_helpEngine->removeCustomFilter(filter);369 removeCustomFilter(filter); 374 370 QMapIterator<QString, QStringList> it(m_filterMap); 375 371 while (it.hasNext()) { 376 372 it.next(); 377 m_helpEngine->addCustomFilter(it.key(), it.value()); 378 } 379 } 380 381 qSort(m_TabsToClose); 382 CentralWidget* widget = CentralWidget::instance(); 383 for (int i = m_TabsToClose.count(); --i >= 0;) 384 widget->closeTabAt(m_TabsToClose.at(i)); 385 if (widget->availableHelpViewer()== 0) 386 widget->setSource(QUrl(QLatin1String("about:blank"))); 387 388 if (m_unregDocs.count()) { 389 foreach (const QString &doc, m_unregDocs) 390 m_helpEngine->unregisterDocumentation(doc); 391 } 392 393 if (filtersWereChanged || m_regDocs.count() || m_unregDocs.count()) 394 m_helpEngine->setupData(); 373 helpEngine.addCustomFilter(it.key(), it.value()); 374 } 375 } 376 377 CentralWidget::instance()->closeOrReloadTabs(m_TabsToClose, false); 378 379 foreach (const QString &doc, m_unregDocs) 380 helpEngine.unregisterDocumentation(doc); 381 382 if (filtersWereChanged || !m_regDocs.isEmpty() || !m_unregDocs.isEmpty()) 383 helpEngine.setupData(); 395 384 396 385 accept(); … … 399 388 void PreferencesDialog::updateFontSettingsPage() 400 389 { 390 401 391 m_browserFontPanel = new FontPanel(this); 402 392 m_browserFontPanel->setCheckable(true); … … 412 402 m_appFontPanel->setTitle(customSettings); 413 403 414 QLatin1String key = QLatin1String("appFont"); 415 QFont font = qVariantValue<QFont>(m_helpEngine->customValue(key)); 404 QFont font = helpEngine.appFont(); 416 405 m_appFontPanel->setSelectedFont(font); 417 406 418 key = QLatin1String("appWritingSystem"); 419 QFontDatabase::WritingSystem system = static_cast<QFontDatabase::WritingSystem> 420 (m_helpEngine->customValue(key).toInt()); 407 QFontDatabase::WritingSystem system = helpEngine.appWritingSystem(); 421 408 m_appFontPanel->setWritingSystem(system); 422 409 423 key = QLatin1String("useAppFont"); 424 m_appFontPanel->setChecked(m_helpEngine->customValue(key).toBool()); 410 m_appFontPanel->setChecked(helpEngine.usesAppFont()); 425 411 426 412 m_browserFontPanel->setTitle(customSettings); 427 413 428 key = QLatin1String("browserFont"); 429 font = qVariantValue<QFont>(m_helpEngine->customValue(key)); 414 font = helpEngine.browserFont(); 430 415 m_browserFontPanel->setSelectedFont(font); 431 416 432 key = QLatin1String("browserWritingSystem"); 433 system = static_cast<QFontDatabase::WritingSystem> 434 (m_helpEngine->customValue(key).toInt()); 417 system = helpEngine.browserWritingSystem(); 435 418 m_browserFontPanel->setWritingSystem(system); 436 419 437 key = QLatin1String("useBrowserFont"); 438 m_browserFontPanel->setChecked(m_helpEngine->customValue(key).toBool()); 420 m_browserFontPanel->setChecked(helpEngine.usesBrowserFont()); 439 421 440 422 connect(m_appFontPanel, SIGNAL(toggled(bool)), this, … … 458 440 void PreferencesDialog::appFontSettingToggled(bool on) 459 441 { 442 460 443 Q_UNUSED(on) 461 444 m_appFontChanged = true; … … 464 447 void PreferencesDialog::appFontSettingChanged(int index) 465 448 { 449 466 450 Q_UNUSED(index) 467 451 m_appFontChanged = true; … … 470 454 void PreferencesDialog::browserFontSettingToggled(bool on) 471 455 { 456 472 457 Q_UNUSED(on) 473 458 m_browserFontChanged = true; … … 476 461 void PreferencesDialog::browserFontSettingChanged(int index) 477 462 { 463 478 464 Q_UNUSED(index) 479 465 m_browserFontChanged = true; … … 482 468 void PreferencesDialog::updateOptionsPage() 483 469 { 484 QString homepage = m_helpEngine->customValue(QLatin1String("homepage"), 485 QLatin1String("")).toString(); 486 487 if (homepage.isEmpty()) { 488 homepage = m_helpEngine->customValue(QLatin1String("defaultHomepage"), 489 QLatin1String("help")).toString(); 490 } 491 m_ui.homePageLineEdit->setText(homepage); 492 493 int option = m_helpEngine->customValue(QLatin1String("StartOption"), 494 ShowLastPages).toInt(); 470 TRACE_OBJ 471 m_ui.homePageLineEdit->setText(helpEngine.homePage()); 472 473 int option = helpEngine.startOption(); 495 474 m_ui.helpStartComboBox->setCurrentIndex(option); 496 475 … … 502 481 void PreferencesDialog::setBlankPage() 503 482 { 483 504 484 m_ui.homePageLineEdit->setText(QLatin1String("about:blank")); 505 485 } … … 507 487 void PreferencesDialog::setCurrentPage() 508 488 { 489 509 490 QString homepage = CentralWidget::instance()->currentSource().toString(); 510 491 if (homepage.isEmpty()) … … 516 497 void PreferencesDialog::setDefaultPage() 517 498 { 518 QString homepage = m_helpEngine->customValue(QLatin1String("defaultHomepage"), 519 QLatin1String("help")).toString(); 520 m_ui.homePageLineEdit->setText(homepage); 499 TRACE_OBJ 500 m_ui.homePageLineEdit->setText(helpEngine.defaultHomePage()); 521 501 } 522 502 -
trunk/tools/assistant/tools/assistant/preferencesdialog.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 49 49 50 50 class FontPanel; 51 class QHelpEngineCore; 52 53 enum { 54 ShowHomePage = 0, 55 ShowBlankPage = 1, 56 ShowLastPages = 2 57 }; 51 class HelpEngineWrapper; 52 class QFileSystemWatcher; 58 53 59 54 class PreferencesDialog : public QDialog … … 62 57 63 58 public: 64 PreferencesDialog(Q HelpEngineCore *helpEngine, QWidget *parent = 0);59 PreferencesDialog(QWidget *parent = 0); 65 60 ~PreferencesDialog(); 66 61 … … 94 89 95 90 Ui::PreferencesDialogClass m_ui; 96 QHelpEngineCore *m_helpEngine;97 91 bool m_hideFiltersTab; 98 92 bool m_hideDocsTab; … … 108 102 bool m_appFontChanged; 109 103 bool m_browserFontChanged; 104 110 105 }; 111 106 -
trunk/tools/assistant/tools/assistant/qtdocinstaller.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include <QtCore/QDir> 43 44 #include <QtCore/QLibraryInfo> 44 45 #include <QtCore/QDateTime> 46 45 47 #include <QtHelp/QHelpEngineCore> 48 46 49 #include "qtdocinstaller.h" 47 50 48 51 QT_BEGIN_NAMESPACE 49 52 50 QtDocInstaller::QtDocInstaller(const QString &collectionFile) 53 QtDocInstaller::QtDocInstaller(const QList<DocInfo> &docInfos) 54 : m_abort(false), m_docInfos(docInfos) 51 55 { 52 m_abort = false; 53 m_collectionFile = collectionFile; 56 TRACE_OBJ 54 57 } 55 58 56 59 QtDocInstaller::~QtDocInstaller() 57 60 { 61 58 62 if (!isRunning()) 59 63 return; … … 66 70 void QtDocInstaller::installDocs() 67 71 { 72 68 73 start(LowPriority); 69 74 } … … 71 76 void QtDocInstaller::run() 72 77 { 73 QHelpEngineCore *helpEngine = new QHelpEngineCore(m_collectionFile); 74 helpEngine->setupData(); 78 TRACE_OBJ 79 m_qchDir = QLibraryInfo::location(QLibraryInfo::DocumentationPath) 80 + QDir::separator() + QLatin1String("qch"); 81 m_qchFiles = m_qchDir.entryList(QStringList() << QLatin1String("*.qch")); 82 75 83 bool changes = false; 76 77 QStringList docs; 78 docs << QLatin1String("assistant") 79 << QLatin1String("designer") 80 << QLatin1String("linguist") 81 << QLatin1String("qmake") 82 << QLatin1String("qt"); 83 84 foreach (const QString &doc, docs) { 85 changes |= installDoc(doc, helpEngine); 84 foreach (const DocInfo &docInfo, m_docInfos) { 85 changes |= installDoc(docInfo); 86 86 m_mutex.lock(); 87 87 if (m_abort) { 88 delete helpEngine;89 88 m_mutex.unlock(); 90 89 return; … … 92 91 m_mutex.unlock(); 93 92 } 94 delete helpEngine;95 93 emit docsInstalled(changes); 96 94 } 97 95 98 bool QtDocInstaller::installDoc(const QString &name, QHelpEngineCore *helpEngine)96 bool QtDocInstaller::installDoc(const ) 99 97 { 100 QString versionKey = QString(QLatin1String("qtVersion%1$$$%2")). 101 arg(QLatin1String(QT_VERSION_STR)).arg(name); 102 103 QString info = helpEngine->customValue(versionKey, QString()).toString(); 104 QStringList lst = info.split(QLatin1String("|")); 105 98 TRACE_OBJ 99 const QString &component = docInfo.first; 100 const QStringList &info = docInfo.second; 106 101 QDateTime dt; 107 if ( lst.count() && !lst.first().isEmpty())108 dt = QDateTime::fromString( lst.first(), Qt::ISODate);102 if (.first().isEmpty()) 103 dt = QDateTime::fromString(.first(), Qt::ISODate); 109 104 110 105 QString qchFile; 111 if ( lst.count() == 2)112 qchFile = lst.last();106 if (.count() == 2) 107 qchFile = .last(); 113 108 114 QDir dir(QLibraryInfo::location(QLibraryInfo::DocumentationPath) 115 + QDir::separator() + QLatin1String("qch")); 116 117 const QStringList files = dir.entryList(QStringList() << QLatin1String("*.qch")); 118 if (files.isEmpty()) { 119 helpEngine->setCustomValue(versionKey, QDateTime().toString(Qt::ISODate) 120 + QLatin1String("|")); 109 if (m_qchFiles.isEmpty()) { 110 emit qchFileNotFound(component); 121 111 return false; 122 112 } 123 foreach (const QString &f, files) {124 if (f.startsWith( name)) {125 QFileInfo fi( dir.absolutePath() + QDir::separator() + f);126 if (dt.isValid() && fi.lastModified().to String(Qt::ISODate) == dt.toString(Qt::ISODate)113 foreach (const QString &f, iles) { 114 if (f.startsWith()) { 115 QFileInfo fi(ir.absolutePath() + QDir::separator() + f); 116 if (dt.isValid() && fi.lastModified().to) 127 117 && qchFile == fi.absoluteFilePath()) 128 118 return false; 129 130 QString namespaceName = QHelpEngineCore::namespaceName(fi.absoluteFilePath()); 131 if (namespaceName.isEmpty()) 132 continue; 133 134 if (helpEngine->registeredDocumentations().contains(namespaceName)) 135 helpEngine->unregisterDocumentation(namespaceName); 136 137 if (!helpEngine->registerDocumentation(fi.absoluteFilePath())) { 138 emit errorMessage( 139 tr("The file %1 could not be registered successfully!\n\nReason: %2") 140 .arg(fi.absoluteFilePath()).arg(helpEngine->error())); 141 } 142 143 helpEngine->setCustomValue(versionKey, fi.lastModified().toString(Qt::ISODate) 144 + QLatin1String("|") + fi.absoluteFilePath()); 119 emit registerDocumentation(component, fi.absoluteFilePath()); 145 120 return true; 146 121 } 147 122 } 123 124 148 125 return false; 149 126 } -
trunk/tools/assistant/tools/assistant/qtdocinstaller.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 43 43 #define QTDOCINSTALLER 44 44 45 46 47 48 45 49 #include <QtCore/QThread> 46 #include <QtCore/QMutex>47 50 48 51 QT_BEGIN_NAMESPACE 49 52 50 class QHelpEngineCore;53 class ; 51 54 52 55 class QtDocInstaller : public QThread … … 55 58 56 59 public: 57 QtDocInstaller(const QString &collectionFile); 60 typedef QPair<QString, QStringList> DocInfo; 61 QtDocInstaller(const QList<DocInfo> &docInfos); 58 62 ~QtDocInstaller(); 59 63 void installDocs(); 60 64 61 65 signals: 62 void errorMessage(const QString &msg); 66 void qchFileNotFound(const QString &component); 67 void registerDocumentation(const QString &component, 68 const QString &absFileName); 63 69 void docsInstalled(bool newDocsInstalled); 64 70 65 71 private: 66 72 void run(); 67 bool installDoc(const QString &name, 68 QHelpEngineCore *helpEngine); 73 bool installDoc(const DocInfo &docInfo); 69 74 70 75 bool m_abort; 71 QString m_collectionFile;72 76 QMutex m_mutex; 77 78 79 73 80 }; 74 81 -
trunk/tools/assistant/tools/assistant/remotecontrol.cpp
r701 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "remotecontrol.h" 43 44 #include "mainwindow.h" 44 45 #include "centralwidget.h" 46 45 47 46 48 #include <QtCore/QFile> 49 50 47 51 #include <QtCore/QThread> 48 52 #include <QtCore/QTextStream> … … 66 70 : QThread(parent) 67 71 { 72 68 73 } 69 74 70 75 StdInListenerWin::~StdInListenerWin() 71 76 { 77 72 78 terminate(); 73 79 wait(); … … 78 84 void StdInListenerWin::run() 79 85 { 86 80 87 char chBuf[4096]; 81 88 size_t pos = 0; … … 121 128 void StdInListenerWin::run() 122 129 { 130 123 131 bool ok = true; 124 132 char chBuf[4096]; … … 145 153 146 154 while (ok) { 147 ok = ReadFile(hStdinDup, chBuf, 4096, &dwRead, NULL);155 ok = ReadFile(hStdinDup, chBuf, , &dwRead, NULL); 148 156 if (ok && dwRead != 0) 149 emit receivedCommand(QString::fromLocal8Bit(chBuf ));157 emit receivedCommand(QString::fromLocal8Bit(chBuf)); 150 158 } 151 159 } … … 155 163 #endif // defined(Q_OS_WIN) || defined(Q_OS_OS2) 156 164 157 RemoteControl::RemoteControl(MainWindow *mainWindow , QHelpEngine *helpEngine)165 RemoteControl::RemoteControl(MainWindow *mainWindow) 158 166 : QObject(mainWindow) 159 167 , m_mainWindow(mainWindow) 160 , m_helpEngine(helpEngine)161 168 , m_debug(false) 162 169 , m_caching(true) 163 170 , m_syncContents(false) 164 , m_expandTOC(-3) 165 166 { 171 , m_expandTOC(-2) 172 , helpEngine(HelpEngineWrapper::instance()) 173 174 { 175 TRACE_OBJ 167 176 connect(m_mainWindow, SIGNAL(initDone()), this, SLOT(applyCache())); 168 177 #if defined(Q_OS_WIN) || defined(Q_OS_OS2) … … 181 190 void RemoteControl::receivedData() 182 191 { 192 183 193 QByteArray ba; 184 194 while (true) { … … 196 206 void RemoteControl::handleCommandString(const QString &cmdString) 197 207 { 208 198 209 QStringList cmds = cmdString.split(QLatin1Char(';')); 199 210 QStringList::const_iterator it = cmds.constBegin(); 200 QString cmdLine, cmd, arg;201 211 while (it != cmds.constEnd()) { 202 cmdLine = (*it).trimmed(); 203 cmd = cmdLine; 204 arg.clear(); 205 int i = cmdLine.indexOf(QLatin1Char(' ')); 206 if (i > 0) { 207 cmd = cmdLine.left(i); 208 arg = cmdLine.mid(i+1); 209 } 210 cmd = cmd.toLower(); 212 QString cmd, arg; 213 splitInputString(*it, cmd, arg); 211 214 212 215 if (m_debug) … … 214 217 tr("Received Command: %1 %2").arg(cmd).arg(arg)); 215 218 216 if (cmd == QLatin1String("debug")) { 217 if (arg == QLatin1String("on")) 218 m_debug = true; 219 else 220 m_debug = false; 221 } else if (cmd == QLatin1String("show")) { 222 if (arg.toLower() == QLatin1String("contents")) { 223 m_mainWindow->showContents(); 224 } else if (arg.toLower() == QLatin1String("index")) { 225 m_mainWindow->showIndex(); 226 } else if (arg.toLower() == QLatin1String("bookmarks")) { 227 m_mainWindow->showBookmarks(); 228 } else if (arg.toLower() == QLatin1String("search")) { 229 m_mainWindow->showSearch(); 230 } 231 } else if (cmd == QLatin1String("hide")) { 232 if (arg.toLower() == QLatin1String("contents")) { 233 m_mainWindow->hideContents(); 234 } else if (arg.toLower() == QLatin1String("index")) { 235 m_mainWindow->hideIndex(); 236 } else if (arg.toLower() == QLatin1String("bookmarks")) { 237 m_mainWindow->hideBookmarks(); 238 } else if (arg.toLower() == QLatin1String("search")) { 239 m_mainWindow->hideSearch(); 240 } 241 } else if (cmd == QLatin1String("setsource")) { 242 QUrl url(arg); 243 if (url.isValid()) { 244 if (url.isRelative()) 245 url = CentralWidget::instance()->currentSource().resolved(url); 246 if (m_caching) { 247 clearCache(); 248 m_setSource = url; 249 } else { 250 CentralWidget::instance()->setSource(url); 251 } 252 } 253 } else if (cmd == QLatin1String("synccontents")) { 254 if (m_caching) 255 m_syncContents = true; 256 else 257 m_mainWindow->syncContents(); 258 } else if (cmd == QLatin1String("activatekeyword")) { 259 if (m_caching) { 260 clearCache(); 261 m_activateKeyword = arg; 262 } else { 263 m_mainWindow->setIndexString(arg); 264 if (!arg.isEmpty()) 265 m_helpEngine->indexWidget()->activateCurrentItem(); 266 } 267 } else if (cmd == QLatin1String("activateidentifier")) { 268 if (m_caching) { 269 clearCache(); 270 m_activateIdentifier = arg; 271 } else { 272 QMap<QString, QUrl> links = 273 m_helpEngine->linksForIdentifier(arg); 274 if (links.count()) 275 CentralWidget::instance()->setSource(links.constBegin().value()); 276 } 277 } else if (cmd == QLatin1String("expandtoc")) { 278 bool ok = false; 279 int depth = -1; 280 if (!arg.isEmpty()) 281 depth = arg.toInt(&ok); 282 if (!ok) 283 depth = -1; 284 285 if (m_caching) 286 m_expandTOC = depth; 287 else 288 m_mainWindow->expandTOC(depth); 289 } else if (cmd == QLatin1String("setcurrentfilter")) { 290 if (!m_helpEngine->customFilters().contains(arg)) 291 return; 292 if (m_caching) { 293 clearCache(); 294 m_currentFilter = arg; 295 } else { 296 m_helpEngine->setCurrentFilter(arg); 297 } 298 } else { 219 if (cmd == QLatin1String("debug")) 220 handleDebugCommand(arg); 221 else if (cmd == QLatin1String("show")) 222 handleShowOrHideCommand(arg, true); 223 else if (cmd == QLatin1String("hide")) 224 handleShowOrHideCommand(arg, false); 225 else if (cmd == QLatin1String("setsource")) 226 handleSetSourceCommand(arg); 227 else if (cmd == QLatin1String("synccontents")) 228 handleSyncContentsCommand(); 229 else if (cmd == QLatin1String("activatekeyword")) 230 handleActivateKeywordCommand(arg); 231 else if (cmd == QLatin1String("activateidentifier")) 232 handleActivateIdentifierCommand(arg); 233 else if (cmd == QLatin1String("expandtoc")) 234 handleExpandTocCommand(arg); 235 else if (cmd == QLatin1String("setcurrentfilter")) 236 handleSetCurrentFilterCommand(arg); 237 else if (cmd == QLatin1String("register")) 238 handleRegisterCommand(arg); 239 else if (cmd == QLatin1String("unregister")) 240 handleUnregisterCommand(arg); 241 else 299 242 return; 300 } 243 301 244 ++it; 302 245 } … … 305 248 } 306 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 307 384 void RemoteControl::applyCache() 308 385 { 386 309 387 if (m_setSource.isValid()) { 310 388 CentralWidget::instance()->setSource(m_setSource); 311 389 } else if (!m_activateKeyword.isEmpty()) { 312 390 m_mainWindow->setIndexString(m_activateKeyword); 313 m_helpEngine->indexWidget()->activateCurrentItem();391 indexWidget()->activateCurrentItem(); 314 392 } else if (!m_activateIdentifier.isEmpty()) { 315 393 QMap<QString, QUrl> links = 316 m_helpEngine->linksForIdentifier(m_activateIdentifier);317 if ( links.count())394 linksForIdentifier(m_activateIdentifier); 395 if (()) 318 396 CentralWidget::instance()->setSource(links.constBegin().value()); 319 397 } else if (!m_currentFilter.isEmpty()) { 320 m_helpEngine->setCurrentFilter(m_currentFilter);398 setCurrentFilter(m_currentFilter); 321 399 } 322 400 … … 324 402 m_mainWindow->syncContents(); 325 403 326 if (m_expandTOC != -3) 404 Q_ASSERT(m_expandTOC >= -2); 405 if (m_expandTOC != -2) 327 406 m_mainWindow->expandTOC(m_expandTOC); 328 407 … … 332 411 void RemoteControl::clearCache() 333 412 { 413 334 414 m_currentFilter.clear(); 335 415 m_setSource.clear(); -
trunk/tools/assistant/tools/assistant/remotecontrol.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 44 44 45 45 #include <QtCore/QObject> 46 46 47 #include <QtCore/QUrl> 47 48 48 49 QT_BEGIN_NAMESPACE 49 50 51 50 52 class MainWindow; 51 class QHelpEngine;52 53 53 54 class RemoteControl : public QObject … … 56 57 57 58 public: 58 RemoteControl(MainWindow *mainWindow , QHelpEngine *helpEngine);59 RemoteControl(MainWindow *mainWindow); 59 60 60 61 private slots: … … 65 66 private: 66 67 void clearCache(); 68 69 70 71 72 73 74 75 76 77 78 67 79 68 80 private: 69 81 MainWindow *m_mainWindow; 70 QHelpEngine *m_helpEngine;71 82 bool m_debug; 72 83 … … 78 89 int m_expandTOC; 79 90 QString m_currentFilter; 91 80 92 }; 81 93 -
trunk/tools/assistant/tools/assistant/remotecontrol_win.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/assistant/searchwidget.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 41 42 42 43 #include "mainwindow.h" … … 66 67 , searchEngine(engine) 67 68 { 69 68 70 QVBoxLayout *vLayout = new QVBoxLayout(this); 69 71 … … 92 94 SearchWidget::~SearchWidget() 93 95 { 96 94 97 // nothing todo 95 98 } … … 97 100 void SearchWidget::zoomIn() 98 101 { 102 99 103 QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget); 100 104 if (browser && zoomCount != 10) { … … 106 110 void SearchWidget::zoomOut() 107 111 { 112 108 113 QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget); 109 114 if (browser && zoomCount != -5) { … … 115 120 void SearchWidget::resetZoom() 116 121 { 122 117 123 if (zoomCount == 0) 118 124 return; … … 127 133 bool SearchWidget::isAttached() const 128 134 { 135 129 136 return attached; 130 137 } … … 132 139 void SearchWidget::setAttached(bool state) 133 140 { 141 134 142 attached = state; 135 143 } … … 137 145 void SearchWidget::search() const 138 146 { 147 139 148 QList<QHelpSearchQuery> query = searchEngine->queryWidget()->query(); 140 149 searchEngine->search(query); … … 143 152 void SearchWidget::searchingStarted() 144 153 { 154 145 155 qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); 146 156 } … … 148 158 void SearchWidget::searchingFinished(int hits) 149 159 { 160 150 161 Q_UNUSED(hits) 151 162 qApp->restoreOverrideCursor(); … … 154 165 bool SearchWidget::eventFilter(QObject* o, QEvent *e) 155 166 { 167 156 168 QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget); 157 169 if (browser && o == browser->viewport() … … 172 184 void SearchWidget::keyPressEvent(QKeyEvent *keyEvent) 173 185 { 186 174 187 if (keyEvent->key() == Qt::Key_Escape) 175 188 MainWindow::activateCurrentBrowser(); … … 180 193 void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent) 181 194 { 195 182 196 QMenu menu; 183 197 QPoint point = contextMenuEvent->globalPos(); -
trunk/tools/assistant/tools/assistant/searchwidget.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 59 59 60 60 public: 61 SearchWidget(QHelpSearchEngine *engine, QWidget *parent = 0);61 SearchWidget(QHelpSearchEngine *engine, QWidget *parent = 0); 62 62 ~SearchWidget(); 63 63 -
trunk/tools/assistant/tools/assistant/topicchooser.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 39 39 ** 40 40 ****************************************************************************/ 41 42 #include <QtCore/QMap> 43 #include <QtCore/QUrl> 41 #include "tracer.h" 44 42 45 43 #include "topicchooser.h" … … 51 49 : QDialog(parent) 52 50 { 51 53 52 ui.setupUi(this); 54 53 ui.label->setText(tr("Choose a topic for <b>%1</b>:").arg(keyword)); 55 54 56 m_links = links; 57 QMap<QString, QUrl>::const_iterator it = m_links.constBegin(); 58 for (; it != m_links.constEnd(); ++it) 55 QMap<QString, QUrl>::const_iterator it = links.constBegin(); 56 for (; it != links.constEnd(); ++it) { 59 57 ui.listWidget->addItem(it.key()); 58 59 60 60 61 61 if (ui.listWidget->count() != 0) … … 63 63 ui.listWidget->setFocus(); 64 64 65 connect(ui.buttonDisplay, SIGNAL(clicked()), 66 this, SLOT(accept())); 67 connect(ui.buttonCancel, SIGNAL(clicked()), 68 this, SLOT(reject())); 69 connect(ui.listWidget, SIGNAL(itemActivated(QListWidgetItem*)), 70 this, SLOT(accept())); 65 connect(ui.buttonDisplay, SIGNAL(clicked()), this, SLOT(accept())); 66 connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); 67 connect(ui.listWidget, SIGNAL(itemActivated(QListWidgetItem*)), this, 68 SLOT(accept())); 71 69 } 72 70 73 71 QUrl TopicChooser::link() const 74 72 { 73 75 74 QListWidgetItem *item = ui.listWidget->currentItem(); 76 75 if (!item) … … 78 77 79 78 QString title = item->text(); 80 if (title.isEmpty() || !m_links.contains(title))79 if (title.isEmpty()) 81 80 return QUrl(); 82 81 83 return m_links.value(title); 82 const int row = ui.listWidget->row(item); 83 Q_ASSERT(row < m_links.count()); 84 return m_links.at(row); 84 85 } 85 86 -
trunk/tools/assistant/tools/assistant/topicchooser.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 45 45 #include "ui_topicchooser.h" 46 46 47 #include <QUrl> 48 #include <QMap> 49 #include <QString> 47 #include <QtCore/QList> 48 #include <QtCore/QMap> 49 #include <QtCore/QString> 50 #include <QtCore/QUrl> 50 51 51 52 #include <QtGui/QDialog> … … 65 66 private: 66 67 Ui::TopicChooser ui; 67 Q Map<QString,QUrl> m_links;68 QQUrl> m_links; 68 69 }; 69 70 -
trunk/tools/assistant/tools/qcollectiongenerator/main.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 40 40 ****************************************************************************/ 41 41 42 42 43 #include "../shared/helpgenerator.h" 43 44 45 46 47 48 44 49 #include <QtCore/QDir> 45 50 #include <QtCore/QMap> 46 51 #include <QtCore/QFileInfo> 47 #include <QtCore/QCoreApplication>48 52 #include <QtCore/QDateTime> 49 53 #include <QtCore/QBuffer> 50 51 #include < private/qhelpgenerator_p.h>52 #include < private/qhelpprojectdata_p.h>54 #include <QtCore/QTranslator> 55 #include <> 56 #include <> 53 57 #include <QtHelp/QHelpEngineCore> 54 55 58 #include <QtXml/QXmlStreamReader> 56 59 60 57 61 QT_USE_NAMESPACE 62 63 64 65 58 66 59 67 class CollectionConfigReader : public QXmlStreamReader … … 88 96 89 97 QString cacheDirectory() const { return m_cacheDirectory; } 98 90 99 91 100 private: … … 116 125 QStringList m_filesToRegister; 117 126 QString m_cacheDirectory; 127 118 128 }; 119 129 120 130 void CollectionConfigReader::raiseErrorWithLine() 121 131 { 122 raiseError(QObject::tr("Unknown token at line %1.") 123 .arg(lineNumber())); 132 raiseError(QCG::tr("Unknown token at line %1.").arg(lineNumber())); 124 133 } 125 134 … … 140 149 readConfig(); 141 150 else 142 raiseError(QObject::tr("Unknown token at line %1. Expected \"QtHelpCollectionProject\"!") 143 .arg(lineNumber())); 151 raiseError(QCG::tr("Unknown token at line %1. " 152 "Expected \"QtHelpCollectionProject\".") 153 .arg(lineNumber())); 144 154 } 145 155 } … … 163 173 } 164 174 if (!ok && !hasError()) 165 raiseError(Q Latin1String("Missing end tags."));175 raiseError(Q("Missing end tags.")); 166 176 } 167 177 … … 199 209 readAboutDialog(); 200 210 } else if (name() == "cacheDirectory") { 211 212 213 201 214 m_cacheDirectory = readElementText(); 202 215 } else { … … 302 315 } 303 316 if (input.isEmpty() || output.isEmpty()) { 304 raiseError(Q Latin1String("Missing input or output file for help file generation!"));317 raiseError(Q")); 305 318 return; 306 319 } … … 320 333 break; 321 334 } 335 336 337 338 339 340 341 342 322 343 } 323 344 } … … 333 354 bool showVersion = false; 334 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 335 372 for (int i=1; i<argc; ++i) { 336 373 arg = QString::fromLocal8Bit(argv[i]); … … 340 377 collectionFile = fi.absoluteFilePath(); 341 378 } else { 342 error = Q Object::tr("Missing output file name!");379 error = Q"); 343 380 } 344 381 } else if (arg == QLatin1String("-h")) { … … 354 391 355 392 if (showVersion) { 356 fprintf(stdout, "Qt Collection Generator version 1.0 (Qt %s)\n", QT_VERSION_STR); 393 fputs(qPrintable(QCG::tr("Qt Collection Generator version 1.0 (Qt %1)\n") 394 .arg(QT_VERSION_STR)), stdout); 357 395 return 0; 358 396 } 359 397 360 398 if (configFile.isEmpty() && !showHelp) 361 error = Q Object::tr("Missing collection config file!");362 363 QString help = Q Object::tr("\nUsage:\n\n"399 error = Q"); 400 401 QString help = Q::tr("\nUsage:\n\n" 364 402 "qcollectiongenerator <collection-config-file> [options]\n\n" 365 403 " -o <collection-file> Generates a collection file\n" … … 371 409 372 410 if (showHelp) { 373 fp rintf(stdout, "%s", qPrintable(help));411 fp); 374 412 return 0; 375 413 }else if (!error.isEmpty()) { … … 380 418 QFile file(configFile); 381 419 if (!file.open(QIODevice::ReadOnly)) { 382 fp rintf(stderr, "Could not open %s!\n", qPrintable(configFile));420 fp); 383 421 return -1; 384 422 } … … 390 428 } 391 429 392 QCoreApplication app(argc, argv); 393 394 fprintf(stdout, "Reading collection config file...\n"); 430 fputs(qPrintable(QCG::tr("Reading collection config file...\n")), stdout); 395 431 CollectionConfigReader config; 396 432 config.readData(file.readAll()); 397 433 if (config.hasError()) { 398 fprintf(stderr, "Collection config file error: %s\n", qPrintable(config.errorString())); 434 fputs(qPrintable(QCG::tr("Collection config file error: %1\n") 435 .arg(config.errorString())), stderr); 399 436 return -1; 400 437 } … … 402 439 QMap<QString, QString>::const_iterator it = config.filesToGenerate().constBegin(); 403 440 while (it != config.filesToGenerate().constEnd()) { 404 fp rintf(stdout, "Generating help for %s...\n", qPrintable(it.key()));441 fp); 405 442 QHelpProjectData helpData; 406 if (!helpData.readData( basePath + QDir::separator() + it.key())) {443 if (!helpData.readData())) { 407 444 fprintf(stderr, "%s\n", qPrintable(helpData.errorMessage())); 408 445 return -1; … … 410 447 411 448 HelpGenerator helpGenerator; 412 if (!helpGenerator.generate(&helpData, basePath + QDir::separator() + it.value())) {449 if (!helpGenerator.generate(&helpData, ))) { 413 450 fprintf(stderr, "%s\n", qPrintable(helpGenerator.error())); 414 451 return -1; … … 417 454 } 418 455 419 fp rintf(stdout, "Creating collection file...\n");456 fp); 420 457 421 458 QFileInfo colFi(collectionFile); 422 459 if (colFi.exists()) { 423 460 if (!colFi.dir().remove(colFi.fileName())) { 424 fprintf(stderr, "The file %s cannot be overwritten!\n", qPrintable(collectionFile)); 461 fputs(qPrintable(QCG::tr("The file %1 cannot be overwritten.\n") 462 .arg(collectionFile)), stderr); 425 463 return -1; 426 464 } … … 434 472 435 473 foreach (const QString &file, config.filesToRegister()) { 436 if (!helpEngine.registerDocumentation( basePath + QDir::separator() + file)) {474 if (!helpEngine.registerDocumentation()) { 437 475 fprintf(stderr, "%s\n", qPrintable(helpEngine.error())); 438 476 return -1; 439 477 } 440 478 } 479 480 441 481 442 482 if (!config.title().isEmpty()) 443 helpEngine.setCustomValue(QLatin1String("WindowTitle"), config.title());483 , config.title()); 444 484 445 485 if (!config.homePage().isEmpty()) { 446 helpEngine.setCustomValue(QLatin1String("defaultHomepage"), 447 config.homePage()); 448 } 449 450 if (!config.startPage().isEmpty()) 451 helpEngine.setCustomValue(QLatin1String("LastShownPages"), config.startPage()); 452 453 if (!config.currentFilter().isEmpty()) 454 helpEngine.setCustomValue(QLatin1String("CurrentFilter"), config.currentFilter()); 455 456 if (!config.cacheDirectory().isEmpty()) 457 helpEngine.setCustomValue(QLatin1String("CacheDirectory"), config.cacheDirectory()); 458 459 helpEngine.setCustomValue(QLatin1String("EnableFilterFunctionality"), 486 CollectionConfiguration::setDefaultHomePage(helpEngine, 487 config.homePage()); 488 } 489 490 if (!config.startPage().isEmpty()) { 491 CollectionConfiguration::setLastShownPages(helpEngine, 492 QStringList(config.startPage())); 493 } 494 495 if (!config.currentFilter().isEmpty()) { 496 helpEngine.setCurrentFilter(config.currentFilter()); 497 } 498 499 if (!config.cacheDirectory().isEmpty()) { 500 CollectionConfiguration::setCacheDir(helpEngine, config.cacheDirectory(), 501 config.cacheDirRelativeToCollection()); 502 } 503 504 CollectionConfiguration::setFilterFunctionalityEnabled(helpEngine, 460 505 config.enableFilterFunctionality()); 461 helpEngine.setCustomValue(QLatin1String("HideFilterFunctionality"),462 config.hideFilterFunctionality());463 helpEngine.setCustomValue(QLatin1String("EnableDocumentationManager"),506 , 507 config.hideFilterFunctionality()); 508 , 464 509 config.enableDocumentationManager()); 465 helpEngine.setCustomValue(QLatin1String("EnableAddressBar"),510 , 466 511 config.enableAddressBar()); 467 helpEngine.setCustomValue(QLatin1String("HideAddressBar"),468 config.hideAddressBar());469 helpEngine.setCustomValue(QLatin1String("CreationTime"),512 , 513 config.hideAddressBar()); 514 , 470 515 QDateTime::currentDateTime().toTime_t()); 471 516 472 517 if (!config.applicationIcon().isEmpty()) { 473 QFile icon( basePath + QDir::separator() + config.applicationIcon());518 QFile icon()); 474 519 if (!icon.open(QIODevice::ReadOnly)) { 475 fp rintf(stderr, "Cannot open %s!\n", qPrintable(icon.fileName()));520 fp); 476 521 return -1; 477 522 } 478 helpEngine.setCustomValue(QLatin1String("ApplicationIcon"), icon.readAll());523 , icon.readAll()); 479 524 } 480 525 … … 488 533 ++it; 489 534 } 490 helpEngine.setCustomValue(QLatin1String("AboutMenuTexts"), ba);535 , ba); 491 536 } 492 537 493 538 if (!config.aboutIcon().isEmpty()) { 494 QFile icon( basePath + QDir::separator() + config.aboutIcon());539 QFile icon()); 495 540 if (!icon.open(QIODevice::ReadOnly)) { 496 fp rintf(stderr, "Cannot open %s!\n", qPrintable(icon.fileName()));541 fp); 497 542 return -1; 498 543 } 499 helpEngine.setCustomValue(QLatin1String("AboutIcon"), icon.readAll());544 , icon.readAll()); 500 545 } 501 546 … … 513 558 while (it != config.aboutTextFiles().constEnd()) { 514 559 s << it.key(); 515 QFileInfo fi( basePath + QDir::separator() + it.value());560 QFileInfo fi()); 516 561 QFile f(fi.absoluteFilePath()); 517 562 if (!f.open(QIODevice::ReadOnly)) { 518 fp rintf(stderr, "Cannot open %s!\n", qPrintable(f.fileName()));563 fp); 519 564 return -1; 520 565 } … … 538 583 imgData.insert(src, img.readAll()); 539 584 } else { 540 fp rintf(stderr, "Cannot open referenced image file %s!\n",541 qPrintable(img.fileName()));585 fp 586 ); 542 587 } 543 588 } … … 545 590 ++it; 546 591 } 547 helpEngine.setCustomValue(QLatin1String("AboutTexts"), ba);592 , ba); 548 593 if (imgData.count()) { 549 594 QByteArray imageData; … … 552 597 QDataStream out(&buffer); 553 598 out << imgData; 554 helpEngine.setCustomValue(QLatin1String("AboutImages"), imageData);599 , imageData); 555 600 } 556 601 } -
trunk/tools/assistant/tools/qcollectiongenerator/qcollectiongenerator.pro
r2 r846 1 QT += xml network 1 QT += xml \ 2 network 2 3 TEMPLATE = app 3 4 DESTDIR = ../../../../bin 4 5 TARGET = qcollectiongenerator 5 CONFIG += qt warn_on help console 6 CONFIG += qt \ 7 warn_on \ 8 help \ 9 console 6 10 CONFIG -= app_bundle 7 8 target.path=$$[QT_INSTALL_BINS] 11 target.path = $$[QT_INSTALL_BINS] 9 12 INSTALLS += target 10 11 13 SOURCES += ../shared/helpgenerator.cpp \ 12 main.cpp 13 14 HEADERS += ../shared/helpgenerator.h 14 main.cpp \ 15 ../shared/collectionconfiguration.cpp 16 HEADERS += ../shared/helpgenerator.h \ 17 ../shared/collectionconfiguration.h -
trunk/tools/assistant/tools/qhelpconverter/adpreader.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/adpreader.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/conversionwizard.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/conversionwizard.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/filespage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 60 60 this, SLOT(removeAllFiles())); 61 61 62 m_ui.fileLabel->setText(tr("<p><b>Warning:</b> Be aware"63 " when removing images or stylesheets sincethose files "62 m_ui.fileLabel->setText(tr("<p><b>Warning:</b> " 63 " those files " 64 64 "are not directly referenced by the .adp or .dcf " 65 65 "file.</p>")); -
trunk/tools/assistant/tools/qhelpconverter/filespage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/filterpage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 51 51 setSubTitle(tr("Specify the filter attributes for the " 52 52 "documentation. If filter attributes are used, " 53 "also define a custom filter for it. Both ,the "53 "also define a custom filter for it. Both the " 54 54 "filter attributes and the custom filters are " 55 55 "optional.")); … … 128 128 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.customFilterWidget); 129 129 item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsEditable|Qt::ItemIsSelectable); 130 item->setText(0, QLatin1String("unfiltered"));130 item->setText(0, ")); 131 131 item->setText(1, QLatin1String("")); 132 132 m_ui.customFilterWidget->editItem(item, 0); -
trunk/tools/assistant/tools/qhelpconverter/filterpage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/finishpage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 53 53 { 54 54 setTitle(tr("Converting File")); 55 setSubTitle(QLatin1String("Creating the new Qt help files from the " 56 "old .adp file.")); 55 setSubTitle(tr("Creating the new Qt help files from the old ADP file.")); 57 56 setFinalPage(true); 58 57 -
trunk/tools/assistant/tools/qhelpconverter/finishpage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/generalpage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/generalpage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/helpwindow.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 65 65 layout = new QVBoxLayout(frame); 66 66 layout->setMargin(2); 67 QLabel *l = new QLabel( QLatin1String("<center><b>Wizard Assistant</b></center>"));67 QLabel *l = new QLabel(("<center><b>Wizard Assistant</b></center>")); 68 68 layout->addWidget(l); 69 69 m_textEdit = new QTextEdit(); -
trunk/tools/assistant/tools/qhelpconverter/helpwindow.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/identifierpage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/identifierpage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/inputpage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/inputpage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 55 55 56 56 public: 57 InputPage(AdpReader *reader, QWidget *parent = 0);57 InputPage(AdpReader *reader, QWidget *parent = 0); 58 58 59 59 private slots: -
trunk/tools/assistant/tools/qhelpconverter/main.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 41 41 42 42 #include <QtCore/QFileInfo> 43 44 45 43 46 #include <QtGui/QApplication> 44 47 … … 50 53 { 51 54 QApplication app(argc, argv); 55 56 57 58 59 60 61 62 63 64 65 66 52 67 53 68 ConversionWizard w; -
trunk/tools/assistant/tools/qhelpconverter/outputpage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/outputpage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/pathpage.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/pathpage.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/qhcpwriter.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/qhcpwriter.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/qhpwriter.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpconverter/qhpwriter.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/tools/assistant/tools/qhelpgenerator/main.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 45 45 #include <QtCore/QFileInfo> 46 46 #include <QtCore/QCoreApplication> 47 48 49 47 50 48 51 #include <private/qhelpprojectdata_p.h> 49 52 50 53 QT_USE_NAMESPACE 54 55 56 57 51 58 52 59 int main(int argc, char *argv[]) … … 59 66 bool showHelp = false; 60 67 bool showVersion = false; 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 61 85 62 86 for (int i = 1; i < argc; ++i) { … … 67 91 compressedFile = fi.absoluteFilePath(); 68 92 } else { 69 error = Q Object::tr("Missing output file name!");93 error = Q"); 70 94 } 71 95 } else if (arg == QLatin1String("-v")) { … … 73 97 } else if (arg == QLatin1String("-h")) { 74 98 showHelp = true; 99 100 75 101 } else { 76 102 QFileInfo fi(arg); … … 81 107 82 108 if (showVersion) { 83 fprintf(stdout, "Qt Help Generator version 1.0 (Qt %s)\n", QT_VERSION_STR); 109 fputs(qPrintable(QHG::tr("Qt Help Generator version 1.0 (Qt %1)\n") 110 .arg(QT_VERSION_STR)), stdout); 84 111 return 0; 85 112 } 86 113 87 114 if (projectFile.isEmpty() && !showHelp) 88 error = Q Object::tr("Missing Qt help project file!");115 error = Q"); 89 116 90 QString help = Q Object::tr("\nUsage:\n\n"117 QString help = Q::tr("\nUsage:\n\n" 91 118 "qhelpgenerator <help-project-file> [options]\n\n" 92 119 " -o <compressed-file> Generates a Qt compressed help\n" … … 94 121 " If this option is not specified\n" 95 122 " a default name will be used.\n" 123 124 96 125 " -v Displays the version of \n" 97 126 " qhelpgenerator.\n\n"); 98 127 99 128 if (showHelp) { 100 fp rintf(stdout, "%s", qPrintable(help));129 fp); 101 130 return 0; 102 131 }else if (!error.isEmpty()) { … … 107 136 QFile file(projectFile); 108 137 if (!file.open(QIODevice::ReadOnly)) { 109 fp rintf(stderr, "Could not open %s!\n", qPrintable(projectFile));138 fp); 110 139 return -1; 111 140 } 112 141 113 142 if (compressedFile.isEmpty()) { 114 QFileInfo fi(projectFile); 115 compressedFile = basePath + QDir::separator() 116 + fi.baseName() + QLatin1String(".qch"); 143 if (!checkLinks) { 144 QFileInfo fi(projectFile); 145 compressedFile = basePath + QDir::separator() 146 + fi.baseName() + QLatin1String(".qch"); 147 } 117 148 } else { 118 149 // check if the output dir exists -- create if it doesn't … … 121 152 if (!parentDir.exists()) { 122 153 if (!parentDir.mkpath(QLatin1String("."))) { 123 fp rintf(stderr, "Could not create output directory: %s\n",124 qPrintable(parentDir.path()));154 fp 155 ); 125 156 } 126 157 } … … 133 164 } 134 165 135 QCoreApplication app(argc, argv);136 166 HelpGenerator generator; 137 bool success = generator.generate(helpData, compressedFile); 167 bool success = true; 168 if (checkLinks) 169 success = generator.checkLinks(*helpData); 170 if (success && !compressedFile.isEmpty()) 171 success = generator.generate(helpData, compressedFile); 138 172 delete helpData; 139 173 if (!success) { -
trunk/tools/assistant/tools/shared/helpgenerator.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 62 62 } 63 63 64 65 66 67 68 64 69 QString HelpGenerator::error() const 65 70 { … … 69 74 void HelpGenerator::printStatus(const QString &msg) 70 75 { 71 fprintf(stdout, "%s\n",qPrintable(msg));76 qPrintable(msg)); 72 77 } 73 78 74 79 void HelpGenerator::printWarning(const QString &msg) 75 80 { 76 fprintf(stdout, "Warning: %s\n", qPrintable(msg));81 )); 77 82 } 78 83 -
trunk/tools/assistant/tools/shared/helpgenerator.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 58 58 bool generate(QHelpDataInterface *helpData, 59 59 const QString &outputFileName); 60 60 61 QString error() const; 61 62
Note:
See TracChangeset
for help on using the changeset viewer.