Changeset 846 for trunk/tools/assistant


Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
1 deleted
149 edited
28 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/assistant/assistant.pro

    r2 r846  
    44SUBDIRS += lib/fulltextsearch \
    55           lib \
    6            tools \
    7            compat \
    8            compat/lib \
     6           tools
  • trunk/tools/assistant/lib/fulltextsearch/fulltextsearch.pro

    r631 r846  
    3232    CONFIG -= exceptions_off
    3333    CONFIG += exceptions
    34     !win32|win32-g++ {
     34    !win32|win32-g++ {
    3535        QMAKE_CFLAGS -= -fno-exceptions
    3636        QMAKE_CXXFLAGS -= -fno-exceptions
     
    4949# the following define could be set globally in case we need it elsewhere
    5050solaris* {
    51     DEFINES += Q_SOLARIS_VERSION=$$system(uname -r | sed -e 's/5\.//')
     51    DEFINES += Q_SOLARIS_VERSION=$$system(uname -r | sed -e 's/5\.//')
    5252}
  • trunk/tools/assistant/lib/fulltextsearch/qanalyzer.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qanalyzer_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qclucene-config_p.h

    r769 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
     
    315315#endif
    316316
    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
    325323
    326324#if defined(__MINGW32__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)
  • trunk/tools/assistant/lib/fulltextsearch/qclucene_global_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
     
    3737#include <QtCore/QString>
    3838
    39 #if !defined(_MSC_VER)
     39#if !defined(_MSC_VER)
    4040#   if !defined(TCHAR)
    4141#       if defined(_CL_HAVE_WCHAR_H) && defined(_CL_HAVE_WCHAR_T) && !defined(_ASCII)
  • trunk/tools/assistant/lib/fulltextsearch/qdocument.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qdocument_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qfield.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qfield_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qfilter.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qfilter_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qhits.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qhits_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qindexreader.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qindexreader_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qindexwriter.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
     
    8989
    9090    d->writer->addIndexes(readerArray);
    91     delete readerArray;
     91    delete
    9292}
    9393
  • trunk/tools/assistant/lib/fulltextsearch/qindexwriter_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qquery.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qquery_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qqueryparser.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qqueryparser_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qreader.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qreader_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qsearchable.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qsearchable_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qsort.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
     
    8585    for (int i = 0; i < fieldNames.count(); ++i)
    8686        delete [] nameArray[i];
    87     delete nameArray;
     87    delete nameArray;
    8888}
    8989
  • trunk/tools/assistant/lib/fulltextsearch/qsort_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
     
    6565{
    6666public:
    67         QCLuceneSort();
    68         QCLuceneSort(const QStringList &fieldNames);
    69     QCLuceneSort(const QString &field, bool reverse = false);
     67QCLuceneSort();
     68QCLuceneSort(const QStringList &fieldNames);
     69    QCLuceneSort(const QString &field, bool reverse = false);
    7070
    7171    virtual ~QCLuceneSort();
     
    7373    QString toString() const;
    7474    void setSort(const QStringList &fieldNames);
    75         void setSort(const QString &field, bool reverse = false);
     75void setSort(const QString &field, bool reverse = false);
    7676
    7777protected:
  • trunk/tools/assistant/lib/fulltextsearch/qterm.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qterm_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qtoken.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qtoken_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qtokenizer.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qtokenizer_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qtokenstream.cpp

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/fulltextsearch/qtokenstream_p.h

    r651 r846  
    44** All rights reserved.
    55**
    6 ** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     6** Portion Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    77** All rights reserved.
    88**
  • trunk/tools/assistant/lib/lib.pro

    r561 r846  
    2424    QtXml
    2525LIBS_PRIVATE += -l$$qclucene
    26 
    2726RESOURCES += helpsystem.qrc
    2827SOURCES += qhelpenginecore.cpp \
     
    4241    qhelpsearchindexreader_default.cpp \
    4342    qhelpsearchindexreader.cpp \
     43
    4444    qhelp_global.cpp
    4545
     
    6464    qhelpsearchindexwriter_default_p.h \
    6565    qhelpsearchindexreader_default_p.h \
    66     qhelpsearchindexreader_p.h
     66    qhelpsearchindexreader_p.h \
     67    qclucenefieldnames_p.h
    6768
    6869# access to clucene
  • trunk/tools/assistant/lib/qhelp_global.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4040****************************************************************************/
    4141
     42
    4243#include <QtCore/QRegExp>
    4344#include <QtCore/QMutexLocker>
     
    5657
    5758    return QString::fromLatin1("%1-%2-%3").
    58         arg(name).arg(long(pointer)).arg(counter);
     59        arg(name).arg((pointer)).arg(counter);
    5960}
    6061
    6162QString QHelpGlobal::documentTitle(const QString &content)
    6263{
    63     QString title = QObject::tr("Untitled");
     64    QString title = Q"Untitled");
    6465    if (!content.isEmpty()) {
    6566        int start = content.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7;
     
    8788QString QHelpGlobal::codecFromHtmlData(const QByteArray &data)
    8889{
    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);
    9192    if (start > 0) {
    92         int end;
    9393        QRegExp r(QLatin1String("charset=([^\"\\s]+)"));
    9494        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();
    9799            if (r.indexIn(meta) != -1)
    98100                return r.cap(1);
    99             start = content.indexOf(QLatin1String("<meta"), end,
     101            start = .indexOf(QLatin1String("<meta"), end,
    100102                                    Qt::CaseInsensitive);
    101103        }
     
    106108QString QHelpGlobal::codecFromXmlData(const QByteArray &data)
    107109{
    108     QString content = QString::fromUtf8(data.constData(), data.size());
     110    QString ));
    109111    const QRegExp encodingExp(QLatin1String("^\\s*<\\?xml version="
    110112        "\"\\d\\.\\d\" encoding=\"([^\"]+)\"\\?>.*"));
    111     return encodingExp.exactMatch(content) ? encodingExp.cap(1) : QString();
     113    return encodingExp.exactMatch() ? encodingExp.cap(1) : QString();
    112114}
  • trunk/tools/assistant/lib/qhelp_global.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpcollectionhandler.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    115115    }
    116116
     117
     118
     119
    117120    m_query.exec(QLatin1String("SELECT COUNT(*) FROM sqlite_master WHERE TYPE=\'table\'"
    118121                               "AND Name=\'NamespaceTable\'"));
     
    163166        return false;
    164167    }
     168
     169
     170
    165171
    166172    if (!createTables(copyQuery)) {
     
    309315    m_query.bindValue(0, filterName);
    310316    m_query.exec();
    311     while (m_query.next()) {
     317   
    312318        nameId = m_query.value(0).toInt();
    313         break;
    314     }
    315319
    316320    m_query.exec(QLatin1String("SELECT Id, Name FROM FilterAttributeTable"));
     
    585589
    586590        QSqlQuery query(db);
     591
     592
    587593        db.exec(QLatin1String("CREATE INDEX IF NOT EXISTS NameIndex ON IndexTable(Name)"));
    588594        db.exec(QLatin1String("CREATE INDEX IF NOT EXISTS FileNameIndex ON FileNameTable(Name)"));
  • trunk/tools/assistant/lib/qhelpcollectionhandler_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    7777    typedef QList<DocInfo> DocInfoList;
    7878
    79     QHelpCollectionHandler(const QString &collectionFile, QObject *parent = 0);
     79    explicit QHelpCollectionHandler(const QString &collectionFile,
     80        QObject *parent = 0);
    8081    ~QHelpCollectionHandler();
    8182
  • trunk/tools/assistant/lib/qhelpcontentwidget.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    371371        d->rootItem = 0;
    372372    }
    373     reset();
     373    if (!onShutDown)
     374        reset();
    374375}
    375376
  • trunk/tools/assistant/lib/qhelpcontentwidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpdatainterface.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpdatainterface_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpdbreader.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    206206        "AND c.Name=? AND c.NamespaceId=d.Id AND d.Name=?"));
    207207    m_query->bindValue(0, filePath);
    208     m_query->bindValue(1, QLatin1String("./") + filePath);
     208    m_query->bindValue(1, Q);
    209209    m_query->bindValue(2, virtualFolder);
    210210    m_query->bindValue(3, m_namespace);
  • trunk/tools/assistant/lib/qhelpdbreader_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpengine.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    7676    QHelpEngineCorePrivate::init(collectionFile, helpEngineCore);
    7777
    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()));
    8687}
    8788
  • trunk/tools/assistant/lib/qhelpengine.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6363
    6464public:
    65     QHelpEngine(const QString &collectionFile, QObject *parent = 0);
     65    QHelpEngine(const QString &collectionFile, QObject *parent = 0);
    6666    ~QHelpEngine();
    6767
  • trunk/tools/assistant/lib/qhelpengine_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpenginecore.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    120120            QHelpGlobal::uniquifyConnectionName(info.fileName, this), this);
    121121        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!")
    123123                .arg(absFileName, reader->errorMessage()));
    124124            continue;
     
    407407/*!
    408408    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.
    411412
    412413    \sa customFilters(), removeCustomFilter()
     
    706707
    707708/*!
    708     Returns a description of the last error that occured.
     709    Returns a description of the last error that occured.
    709710*/
    710711QString QHelpEngineCore::error() const
  • trunk/tools/assistant/lib/qhelpenginecore.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6666   
    6767public:
    68     QHelpEngineCore(const QString &collectionFile, QObject *parent = 0);
     68    QHelpEngineCore(const QString &collectionFile, QObject *parent = 0);
    6969    virtual ~QHelpEngineCore();
    7070
  • trunk/tools/assistant/lib/qhelpgenerator.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4848#include <QtCore/QDir>
    4949#include <QtCore/QDebug>
     50
    5051#include <QtCore/QVariant>
    5152#include <QtCore/QDateTime>
     
    190191        return false;
    191192    }
     193
     194
     195
    192196
    193197    addProgress(1.0);
     
    538542
    539543        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()) {
    541546            fileDataList.append(qCompress(data));
    542547
     
    552557            ++tableFileId;
    553558        } else {
    554             fileId = d->fileMap.value(fileName);
     559            fileId = fileMapIt.value();
     560            QSet<int> &fileFilterSet = d->fileFilterMap[fileId];
     561            QSet<int> &tmpFileFilterSet = tmpFileFilterMap[fileId];
    555562            foreach (const int &filter, filterAtts) {
    556                 if (!d->fileFilterMap.value(fileId).contains(filter)
    557                     && !tmpFileFilterMap.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);
    560567                }
    561568            }
     
    563570    }
    564571
    565     if (tmpFileFilterMap.count()) {
     572    if (()) {
    566573        d->query->exec(QLatin1String("BEGIN"));
    567574        QMap<int, QSet<int> >::const_iterator it = tmpFileFilterMap.constBegin();
     
    626633        attributeMap.insert(d->query->value(1).toString(),
    627634            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());
    630636    }
    631637
     
    675681}
    676682
    677 bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords,
     683bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords,
    678684                                    const QStringList &filterAttributes)
    679685{
     
    705711    int i = 0;
    706712    d->query->exec(QLatin1String("BEGIN"));
     713
    707714    foreach (const QHelpDataIndexItem &itm, keywords) {
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
    708725        pos = itm.reference.indexOf(QLatin1Char('#'));
    709726        fileName = itm.reference.left(pos);
     
    717734            fName = fName.mid(2);
    718735
    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();
    721739        else
    722740            fileId = 1;
     
    750768
    751769    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())
    753771        return true;
    754772    return false;
     
    825843}
    826844
     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
    827908QT_END_NAMESPACE
     909
  • trunk/tools/assistant/lib/qhelpgenerator_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    7575    bool generate(QHelpDataInterface *helpData,
    7676        const QString &outputFileName);
     77
    7778    QString error() const;
    7879
     
    9798    bool registerVirtualFolder(const QString &folderName, const QString &ns);
    9899    bool insertFilterAttributes(const QStringList &attributes);
    99     bool insertKeywords(const QList<QHelpDataIndexItem> keywords,
     100    bool insertKeywords(const QList<QHelpDataIndexItem> keywords,
    100101        const QStringList &filterAttributes);
    101102    bool insertFiles(const QStringList &files, const QString &rootPath,
  • trunk/tools/assistant/lib/qhelpindexwidget.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    245245    d->indexProvider->stopCollecting();
    246246    d->indices.clear();
    247     filter(QString());
     247    if (!onShutDown)
     248        filter(QString());
    248249}
    249250
  • trunk/tools/assistant/lib/qhelpindexwidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpprojectdata.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4242#include "qhelpprojectdata_p.h"
    4343
     44
    4445#include <QtCore/QDir>
    4546#include <QtCore/QFileInfo>
     
    4748#include <QtCore/QMap>
    4849#include <QtCore/QRegExp>
     50
    4951#include <QtCore/QVariant>
    5052#include <QtXml/QXmlStreamReader>
     
    7779    void raiseUnknownTokenError();
    7880    void addMatchingFiles(const QString &pattern);
     81
    7982
    8083    QMap<QString, QStringList> dirEntriesCache;
     
    8386void QHelpProjectDataPrivate::raiseUnknownTokenError()
    8487{
    85     raiseError(QObject::tr("Unknown token."));
     88    raiseError(Q"Unknown token."));
    8689}
    8790
     
    9699                readProject();
    97100            else
    98                 raiseError(QObject::tr("Unknown token. Expected \"QtHelpProject\"!"));
     101                raiseError(QCoreApplication::translate("QHelpProject",
     102                               "Unknown token. Expected \"QtHelpProject\"!"));
    99103        }
    100104    }
    101105
    102106    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())
    104109            .arg(errorString()));
    105110    }
     
    113118            if (name() == QLatin1String("virtualFolder")) {
    114119                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."));
    117123            } else if (name() == QLatin1String("namespace")) {
    118124                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."));
    121128            } else if (name() == QLatin1String("customFilter")) {
    122129                readCustomFilter();
     
    126133                QString n = attributes().value(QLatin1String("name")).toString();
    127134                if (!metaData.contains(n))
    128                     metaData[n] = attributes().value(QLatin1String("value")).toString();
     135                    metaData[n]
     136                        = attributes().value(QLatin1String("value")).toString();
    129137                else
    130                     metaData.insert(n, attributes().value(QLatin1String("value")).toString());
     138                    metaData.insert(n, attributes().
     139                                    value(QLatin1String("value")).toString());
    131140            } else {
    132141                raiseUnknownTokenError();
     
    134143        } else if (isEndElement() && name() == QLatin1String("QtHelpProject")) {
    135144            if (namespaceName.isEmpty())
    136                 raiseError(QObject::tr("Missing namespace in QtHelpProject."));
     145                raiseError(QCoreApplication::translate("QHelpProject",
     146                              "Missing namespace in QtHelpProject."));
    137147            else if (virtualFolder.isEmpty())
    138                 raiseError(QObject::tr("Missing virtual folder in QtHelpProject"));
     148                raiseError(QCoreApplication::translate("QHelpProject",
     149                               "Missing virtual folder in QtHelpProject"));
    139150            break;
    140151        }
     
    224235                    || (attributes().value(QLatin1String("name")).toString().isEmpty()
    225236                    && 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()));
    232245            } else {
    233246                raiseUnknownTokenError();
     
    306319}
    307320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
    308339/*!
    309340    \internal
     
    347378    QFile file(fileName);
    348379    if (!file.open(QIODevice::ReadOnly)) {
    349         d->errorMsg = QObject::tr("The input file %1 could not be opened!")
    350             .arg(fileName);
     380        d->errorMsg = Q
     381            .arg(fileName);
    351382        return false;
    352383    }
  • trunk/tools/assistant/lib/qhelpprojectdata_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchengine.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    264264
    265265    After starting the indexing process the signal indexingStarted() is emitted and
    266     on the end of the indexing process the indexingFinished() is emited. To stop
     266    on the end of the indexing process the indexingFinished() is emited. To stop
    267267    the indexing one can call cancelIndexing().
    268268
     
    270270    thru its index for a given term. To do this one may use the possibility of creating the
    271271    QHelpSearchQuery list by self or reuse the QHelpSearchQueryWidget which has the inbuild
    272     functionality to set up a proper search querys list that get's passed to the search engines
     272    functionality to set up a proper search quers list that get's passed to the search engines
    273273    search() function.
    274274
    275275    After the list of querys has been passed to the search engine, the signal searchingStarted()
    276     is emited and after the search has finished the searchingFinished() signal is emited. The
     276    is emitted. The
    277277    search process can be stopped by calling cancelSearching().
    278278
     
    319319    The QHelpEngine's setupFinished() signal is automatically connected to the
    320320    QHelpSearchEngine's indexing function, so that new documentation will be indexed
    321     after the signal is emited.
     321    after the signal is emited.
    322322*/
    323323QHelpSearchEngine::QHelpSearchEngine(QHelpEngineCore *helpEngine, QObject *parent)
     
    435435
    436436/*!
    437     Starts the search process using the given list of querys \a queryList
     437    Starts the search process using the given list of quers \a queryList
    438438    build by the search field name and the values to search for.
    439439*/
  • trunk/tools/assistant/lib/qhelpsearchengine.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    8181
    8282public:
    83     QHelpSearchEngine(QHelpEngineCore *helpEngine, QObject *parent = 0);
     83    explicit QHelpSearchEngine(QHelpEngineCore *helpEngine,
     84        QObject *parent = 0);
    8485    ~QHelpSearchEngine();
    8586
  • trunk/tools/assistant/lib/qhelpsearchindex_default.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchindex_default_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchindexreader.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4040****************************************************************************/
    4141
     42
     43
     44
     45
    4246#include "qhelpenginecore.h"
    43 #include "fulltextsearch/qsearchable_p.h"
    44 #include "fulltextsearch/qqueryparser_p.h"
    45 #include "fulltextsearch/qindexreader_p.h"
     47
    4648#include "qhelpsearchindexreader_clucene_p.h"
    4749
     
    5052#include <QtCore/QString>
    5153#include <QtCore/QFileInfo>
     54
    5255#include <QtCore/QStringList>
    5356#include <QtCore/QTextStream>
     
    108111        try {
    109112#endif
    110             QCLuceneBooleanQuery booleanQuery;
     113            QCLuceneBooleanQuery booleanQueryTitle;
     114            QCLuceneBooleanQuery booleanQueryContent;
    111115            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) {
    113123                emit searchingFinished(0);
    114124                return;
    115125            }
    116126
    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) {
    123153                    emit searchingFinished(0);
    124154                    return;
    125155                }
    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)));
    144159                }
    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);
    146171
    147172            QSet<QString> pathSet;
     
    149174            const QStringList namespaceList = engine.registeredDocumentations();
    150175
    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();
    158194                }
    159                 document.clear();
    160 
    161                 mutex.lock();
    162                 if (m_cancel) {
    163                     mutex.unlock();
    164                     emit searchingFinished(0);
    165                     return;
    166                 }
    167                 mutex.unlock();
    168195            }
    169196
     
    185212}
    186213
    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);
     214bool 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
     265bool 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())
    198280        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
     284bool 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
     291bool 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
     310bool 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
     326bool 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
     352bool 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
     368bool 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
     385bool 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
     403bool 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);
    301412    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;
    325413}
    326414
     
    328416    QList<QHelpSearchEngine::SearchHit> &hitList, const QList<QHelpSearchQuery> &queryList)
    329417{
    330     foreach (const QHelpSearchQuery query, queryList) {
     418    foreach (const QHelpSearchQuery query, queryList) {
    331419        if (query.fieldName != QHelpSearchQuery::DEFAULT)
    332420            continue;
     
    336424        QCLuceneStandardAnalyzer analyzer;
    337425        QCLuceneQuery *parsedQuery = QCLuceneQueryParser::parse(
    338             joinedQuery, QLatin1String("content"), analyzer);
     426            joinedQuery, , analyzer);
    339427
    340428        if (parsedQuery) {
     
    343431        }
    344432
    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);
    347436
    348437        QString term;
     
    350439        QStringList searchTerms;
    351440        while (index != -1) {
    352             nextIndex = joinedQuery.indexOf(QLatin1String("content:"), index + 1);
     441            nextIndex = joinedQuery.indexOf(, index + 1);
    353442            term = joinedQuery.mid(index + length, nextIndex - (length + index)).simplified();
    354443            if (term.startsWith(QLatin1String("\""))
  • trunk/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5454//
    5555
    56 #include "qhelpsearchindexreader_p.h"
     56#include <QtCore/QList>
     57#include <QtCore/QString>
     58#include <QtCore/QStringList>
    5759
    5860#include "fulltextsearch/qanalyzer_p.h"
    5961#include "fulltextsearch/qquery_p.h"
     62
    6063
    6164QT_BEGIN_NAMESPACE
     
    7477private:
    7578    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);
    8279    void boostSearchHits(const QHelpEngineCore &engine, QList<QHelpSearchEngine::SearchHit> &hitList,
    8380        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
    84107};
    85108
  • trunk/tools/assistant/lib/qhelpsearchindexreader_default.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchindexreader_default_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6161
    6262QT_BEGIN_NAMESPACE
    63 
    64 struct Entry;
    65 struct PosEntry;
    6663
    6764namespace fulltextsearch {
  • trunk/tools/assistant/lib/qhelpsearchindexreader_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4040****************************************************************************/
    4141
     42
    4243#include "qhelpenginecore.h"
    4344#include "qhelp_global.h"
     
    407408
    408409            if(!parsedData.isEmpty()) {
    409                 document->add(new QCLuceneField(QLatin1String("content"),
     410                document->add(new QCLuceneField(,
    410411                    parsedData,QCLuceneField::INDEX_TOKENIZED));
    411                 document->add(new QCLuceneField(QLatin1String("path"), fileName,
     412                document->add(new QCLuceneField(, fileName,
    412413                    QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
    413                 document->add(new QCLuceneField(QLatin1String("title"), parsedTitle,
     414                document->add(new QCLuceneField(, parsedTitle,
    414415                    QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
    415                 document->add(new QCLuceneField(QLatin1String("titleTokenized"), parsedTitle,
     416                document->add(new QCLuceneField(, parsedTitle,
    416417                    QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
    417                 document->add(new QCLuceneField(QLatin1String("namespace"), namespaceName,
     418                document->add(new QCLuceneField(, namespaceName,
    418419                    QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
    419                 document->add(new QCLuceneField(QLatin1String("attribute"), attributes,
     420                document->add(new QCLuceneField(, attributes,
    420421                    QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
    421422                return true;
     
    716717                    if (indexMap.contains(namespaceName)) {
    717718                        // 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));
    721720                        QCLuceneIndexSearcher indexSearcher(indexPath);
    722721                        QCLuceneHits hits = indexSearcher.search(query);
     
    852851
    853852    QCLuceneIndexReader reader = QCLuceneIndexReader::open(indexPath);
    854     reader.deleteDocuments(QCLuceneTerm(QLatin1String("namespace"),
    855         namespaceName));
     853    reader.deleteDocuments(QCLuceneTerm(NamespaceField, namespaceName));
    856854
    857855    reader.close();
  • trunk/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchindexwriter_default.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchindexwriter_default_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchquerywidget.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4242#include "qhelpsearchquerywidget.h"
    4343
    44 #include <QtCore/QDebug>
    45 
    4644#include <QtCore/QAbstractListModel>
    4745#include <QtCore/QObject>
     
    102100
    103101    QHelpSearchQueryWidgetPrivate()
    104         : QObject(), simpleSearch(true),
    105           searchCompleter(new CompleterModel(this), this)
     102        : QObject()
     103        , simpleSearch(true)
     104        , searchCompleter(new CompleterModel(this), this)
    106105    {
    107106        searchButton = 0;
     
    135134        atLeastLabel->setText(QHelpSearchQueryWidget::tr("with <B>at least one</B> of the words:"));
    136135#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 string
    151         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;
    164136    }
    165137
     
    223195    }
    224196
    225     void nextOrPrevQuery(int maxOrMinIndex, int addend,
    226                          QToolButton *thisButton, QToolButton *otherButton)
     197    void nextOrPrevQuery(int maxOrMinIndex, int addend,
     198        QToolButton *otherButton)
    227199    {
    228200        QueryHistory *queryHist;
     
    234206            queryHist = &complexQueries;
    235207            lineEdits << allQuery << atLeastQuery << similarQuery
    236                     << withoutQuery << exactQuery;
     208                << withoutQuery << exactQuery;
    237209        }
    238210        foreach (QLineEdit *lineEdit, lineEdits)
     
    279251    void enableOrDisableToolButtons()
    280252    {
    281         const QueryHistory &queryHist =
    282                 simpleSearch ? simpleQueries : complexQueries;
     253        const QueryHistory &queryHist =
     254            : complexQueries;
    283255        prevQueryButton->setEnabled(queryHist.curQuery > 0);
    284         nextQueryButton->setEnabled(queryHist.curQuery <
    285                                     queryHist.queries.size() - 1);
     256        nextQueryButton->setEnabled(queryHist.curQuery
     257            queryHist.queries.size() - 1);
    286258    }
    287259
     
    307279#if !defined(QT_CLUCENE_SUPPORT)
    308280        queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
    309                                           QStringList(defaultQuery->text())));
     281            QStringList(defaultQuery->text())));
    310282
    311283#else
    312284        if (defaultQuery->isEnabled()) {
    313285            queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
    314                                               buildTermList(escapeString(defaultQuery->text()))));
     286                ))));
    315287        } else {
    316288            const QRegExp exp(QLatin1String("\\s+"));
    317             QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts);
     289            QStringList lst = similarQuery->text().split(exp,
     290                QString::SkipEmptyParts);
    318291            if (!lst.isEmpty()) {
    319292                QStringList fuzzy;
    320293                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));
    323297            }
    324298
     
    327301                QStringList without;
    328302                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));
    331306            }
    332307
    333308            if (!exactQuery->text().isEmpty()) {
    334309                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)));
    337313            }
    338314
     
    341317                QStringList all;
    342318                foreach (const QString &term, lst)
    343                     all.append(escapeString(term));
     319                    all.append();
    344320                queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all));
    345321            }
     
    349325                QStringList atLeast;
    350326                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));
    353330            }
    354331        }
     
    364341    void nextQuery()
    365342    {
    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);
    368346    }
    369347
     
    416394
    417395    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.
    420399*/
    421400
     
    545524}
    546525
    547 /*! \reimp
     526/*!
     527    \reimp
    548528*/
    549529void QHelpSearchQueryWidget::focusInEvent(QFocusEvent *focusEvent)
  • trunk/tools/assistant/lib/qhelpsearchquerywidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/lib/qhelpsearchresultwidget.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    305305            }
    306306        }
    307         hitsLabel->setText(tr("%1 - %2 of %3 Hits").arg(first).arg(last).arg(count));
     307        hitsLabel->setText(t));
    308308    }
    309309
  • trunk/tools/assistant/lib/qhelpsearchresultwidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/assistant/aboutdialog.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
     42
    4143
    4244#include <QtCore/QBuffer>
     
    5759    : QTextBrowser(parent)
    5860{
     61
    5962    setFrameStyle(QFrame::NoFrame);
    6063    QPalette p;
     
    6568void AboutLabel::setText(const QString &text, const QByteArray &resources)
    6669{
     70
    6771    QDataStream in(resources);
    6872    in >> m_resourceMap;
    69    
     73
    7074    QTextBrowser::setText(text);
    7175}
     
    7377QSize AboutLabel::minimumSizeHint() const
    7478{
     79
    7580    QTextDocument *doc = document();
    7681    doc->adjustSize();
     
    8085QVariant AboutLabel::loadResource(int type, const QUrl &name)
    8186{
     87
    8288    if (type == 2 || type == 3) {
    8389        if (m_resourceMap.contains(name.toString())) {
     
    9096void AboutLabel::setSource(const QUrl &url)
    9197{
    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    )))) {
    95101        if (!QDesktopServices::openUrl(url)) {
    96102            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"));
    99104        }
    100105    }
     
    102107
    103108AboutDialog::AboutDialog(QWidget *parent)
    104     : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint|Qt::WindowTitleHint|Qt::WindowSystemMenuHint)
     109    : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint |
     110        Qt::WindowTitleHint|Qt::WindowSystemMenuHint)
    105111{
     112
    106113    m_pixmapLabel = 0;
    107114    m_aboutLabel = new AboutLabel();
    108    
     115
    109116    m_closeButton = new QPushButton();
    110117    m_closeButton->setText(tr("&Close"));
    111     connect(m_closeButton, SIGNAL(clicked()),
    112         this, SLOT(close()));
     118    connect(m_closeButton, SIGNAL(clicked()), this, SLOT(close()));
    113119
    114120    m_layout = new QGridLayout(this);
    115121    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);
    117124    m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 0, 1, 1);
    118125    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);
    120127}
    121128
    122129void AboutDialog::setText(const QString &text, const QByteArray &resources)
    123130{
     131
    124132    m_aboutLabel->setText(text, resources);
    125133    updateSize();
     
    128136void AboutDialog::setPixmap(const QPixmap &pixmap)
    129137{
     138
    130139    if (!m_pixmapLabel) {
    131140        m_pixmapLabel = new QLabel();
     
    138147QString AboutDialog::documentTitle() const
    139148{
     149
    140150    return m_aboutLabel->documentTitle();
    141151}
     
    143153void AboutDialog::updateSize()
    144154{
    145     QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
     155    TRACE_OBJ
     156    QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos())
     157        .size();
    146158    int limit = qMin(screenSize.width()/2, 500);
    147159
     
    155167    if (width > limit)
    156168        width = limit;
    157    
     169
    158170    QFontMetrics fm(qApp->font("QWorkspaceTitleBar"));
    159171    int windowTitleWidth = qMin(fm.width(windowTitle()) + 50, limit);
     
    163175    layout()->activate();
    164176    int height = (layout()->hasHeightForWidth())
    165                      ? layout()->totalHeightForWidth(width)
    166                      : layout()->totalMinimumSize().height();
     177        ? layout()->totalHeightForWidth(width)
     178        : layout()->totalMinimumSize().height();
    167179    setFixedSize(width, height);
    168180    QCoreApplication::removePostedEvents(this, QEvent::LayoutRequest);
  • trunk/tools/assistant/tools/assistant/aboutdialog.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** 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 
     1include(../../../shared/fontpanel/fontpanel.pri)
    32TEMPLATE = app
    43LANGUAGE = C++
    54TARGET = assistant
     5
     6
     7
     8
     9
     10
     11
     12
     13
     14
    615
     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
    744contains(QT_CONFIG, webkit) {
    8     QT += webkit
     45    HEADERS += helpviewer_qwv.h
     46} else {
     47   HEADERS += helpviewer_qtb.h
     48 }
     49win32|os2:HEADERS += remotecontrol_win.h
     50
     51SOURCES += 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
    980}
    1081
    11 CONFIG += qt warn_on help
     82FORMS += bookmarkdialog.ui \
     83    bookmarkmanagerwidget.ui \
     84    bookmarkwidget.ui \
     85    filternamedialog.ui \
     86    installdialog.ui \
     87    preferencesdialog.ui \
     88    topicchooser.ui
    1289
    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
     90RESOURCES += assistant.qrc \
     91    assistant_images.qrc
    6992
    7093win32 {
  • trunk/tools/assistant/tools/assistant/assistant.rc

    r651 r846  
    1919            VALUE "FileDescription", "Qt Assistant"
    2020            VALUE "FileVersion", "1.0.0.0"
    21             VALUE "LegalCopyright", "Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)."
     21            VALUE "LegalCopyright", "Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies)."
    2222            VALUE "InternalName", "assistant.exe"
    2323            VALUE "OriginalFilename", "assistant.exe"
  • trunk/tools/assistant/tools/assistant/assistant_images.qrc

    r2 r846  
    55        <file>images/assistant.png</file>
    66        <file>images/wrap.png</file>
     7
    78#mac
    89        <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">
    23 <class>BookmarkDialog</class>
    3  <widget class="QDialog" name="BookmarkDialog" >
    4   <property name="geometry" >
     4 <widget class="QDialog" name="BookmarkDialog">
     5  <property name="geometry">
    56   <rect>
    67    <x>0</x>
    78    <y>0</y>
    89    <width>450</width>
    9     <height>135</height>
     10    <height>13</height>
    1011   </rect>
    1112  </property>
    12   <property name="sizePolicy" >
    13    <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
     13  <property name="sizePolicy">
     14   <sizepolicy >
    1415    <horstretch>0</horstretch>
    1516    <verstretch>0</verstretch>
    1617   </sizepolicy>
    1718  </property>
    18   <property name="windowTitle" >
     19  <property name="windowTitle">
    1920   <string>Add Bookmark</string>
    2021  </property>
    21   <layout class="QVBoxLayout" name="verticalLayout_3" >
     22  <layout class="QVBoxLayout" name="verticalLayout_3">
    2223   <item>
    23     <layout class="QHBoxLayout" name="horizontalLayout" >
     24    <layout class="QHBoxLayout" name="horizontalLayout">
    2425     <item>
    25       <layout class="QVBoxLayout" name="verticalLayout_2" >
     26      <layout class="QVBoxLayout" name="verticalLayout_2">
    2627       <item>
    27         <widget class="QLabel" name="label" >
    28          <property name="text" >
     28        <widget class="QLabel" name="label">
     29         <property name="text">
    2930          <string>Bookmark:</string>
    3031         </property>
     
    3233       </item>
    3334       <item>
    34         <widget class="QLabel" name="label_2" >
    35          <property name="text" >
     35        <widget class="QLabel" name="label_2">
     36         <property name="text">
    3637          <string>Add in Folder:</string>
    3738         </property>
     
    4142     </item>
    4243     <item>
    43       <layout class="QVBoxLayout" name="verticalLayout" >
     44      <layout class="QVBoxLayout" name="verticalLayout">
    4445       <item>
    45         <widget class="QLineEdit" name="bookmarkEdit" />
     46        <widget class="QLineEdit" name="bookmarkEdit"/>
    4647       </item>
    4748       <item>
    48         <widget class="QComboBox" name="bookmarkFolders" />
     49        <widget class="QComboBox" name="bookmarkFolders"/>
    4950       </item>
    5051      </layout>
     
    5354   </item>
    5455   <item>
    55     <layout class="QHBoxLayout" name="horizontalLayout_3" >
     56    <layout class="QHBoxLayout" name="horizontalLayout_3">
    5657     <item>
    57       <widget class="QToolButton" name="toolButton" >
    58        <property name="minimumSize" >
     58      <widget class="QToolButton" name="toolButton">
     59       <property name="minimumSize">
    5960        <size>
    6061         <width>25</width>
     
    6263        </size>
    6364       </property>
    64        <property name="text" >
     65       <property name="text">
    6566        <string>+</string>
    6667       </property>
     
    6869     </item>
    6970     <item>
    70       <widget class="Line" name="line" >
    71        <property name="orientation" >
     71      <widget class="Line" name="line">
     72       <property name="orientation">
    7273        <enum>Qt::Horizontal</enum>
    7374       </property>
     
    7778   </item>
    7879   <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 >
    8283       <horstretch>0</horstretch>
    8384       <verstretch>0</verstretch>
    8485      </sizepolicy>
    8586     </property>
     87
     88
     89
     90
     91
     92
     93
     94
     95
    8696    </widget>
    8797   </item>
    8898   <item>
    89     <layout class="QHBoxLayout" name="horizontalLayout_4" >
     99    <layout class="QHBoxLayout" name="horizontalLayout_4">
    90100     <item>
    91       <widget class="QPushButton" name="newFolderButton" >
    92        <property name="text" >
     101      <widget class="QPushButton" name="newFolderButton">
     102       <property name="text">
    93103        <string>New Folder</string>
    94104       </property>
     
    96106     </item>
    97107     <item>
    98       <widget class="QDialogButtonBox" name="buttonBox" >
    99        <property name="orientation" >
     108      <widget class="QDialogButtonBox" name="buttonBox">
     109       <property name="orientation">
    100110        <enum>Qt::Horizontal</enum>
    101111       </property>
    102        <property name="standardButtons" >
     112       <property name="standardButtons">
    103113        <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
    104114       </property>
     
    117127   <slot>accept()</slot>
    118128   <hints>
    119     <hint type="sourcelabel" >
     129    <hint type="sourcelabel">
    120130     <x>248</x>
    121131     <y>254</y>
    122132    </hint>
    123     <hint type="destinationlabel" >
     133    <hint type="destinationlabel">
    124134     <x>157</x>
    125135     <y>274</y>
     
    133143   <slot>reject()</slot>
    134144   <hints>
    135     <hint type="sourcelabel" >
     145    <hint type="sourcelabel">
    136146     <x>316</x>
    137147     <y>260</y>
    138148    </hint>
    139     <hint type="destinationlabel" >
     149    <hint type="destinationlabel">
    140150     <x>286</x>
    141151     <y>274</y>
  • trunk/tools/assistant/tools/assistant/bookmarkmanager.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "bookmarkmanager.h"
     44
     45
     46
     47
     48
    4349#include "centralwidget.h"
     50
    4451
    4552#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>
    5253#include <QtGui/QKeyEvent>
    53 #include <QtGui/QLineEdit>
    5454#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>
    6155#include <QtGui/QSortFilterProxyModel>
    6256
    6357QT_BEGIN_NAMESPACE
    6458
    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
     61void 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
     75BookmarkManager::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
     93void BookmarkManager::BookmarkTreeView::subclassKeyPressEvent(QKeyEvent *event)
     94{
     95    TRACE_OBJ
     96    QTreeView::keyPressEvent(event);
     97}
     98
     99void 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
     108QMutex BookmarkManager::mutex;
     109BookmarkManager* BookmarkManager::bookmarkManager = 0;
     110
     111// -- public
     112
     113BookmarkManager* 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
     124void BookmarkManager::destroy()
     125{
     126    TRACE_OBJ
     127    delete bookmarkManager;
     128    bookmarkManager = 0;
     129}
     130
     131QWidget* BookmarkManager::bookmarkDockWidget() const
     132{
     133    TRACE_OBJ
     134    if (bookmarkWidget)
     135        return bookmarkWidget;
     136    return 0;
     137}
     138
     139void BookmarkManager::takeBookmarksMenu(QMenu* menu)
     140{
     141    TRACE_OBJ
     142    bookmarkMenu = menu;
     143    refeshBookmarkMenu();
     144}
     145
     146// -- public slots
     147
     148void 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
     157BookmarkManager::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,
    102172        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,
    112184        SLOT(customContextMenuRequested(QPoint)));
    113185
    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 &current)
    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
     196BookmarkManager::~BookmarkManager()
     197{
     198    TRACE_OBJ
     199    delete bookmarkManagerWidget;
     200    HelpEngineWrapper::instance().setBookmarks(bookmarkModel->bookmarks());
     201    delete bookmarkModel;
     202}
     203
     204void 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
     226bool 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);
    275236        switch (ke->key()) {
    276237            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());
    286239            }   break;
    287240
    288241            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;
    303257        }
    304258    }
    305259
    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
     279void 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        }
    346292    } 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
     298void 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
     307void 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
     328void BookmarkManager::addBookmark()
     329{
     330    TRACE_OBJ
     331    if (CentralWidget *widget = CentralWidget::instance())
     332        addBookmark(widget->currentTitle(), widget->currentSource().toString());
     333}
     334
     335void BookmarkManager::removeBookmark()
     336{
     337    TRACE_OBJ
     338    removeItem(bookmarkTreeView->currentIndex());
     339}
     340
     341void 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
     357void 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
     380void 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
     391void 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
     400void 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
     419void BookmarkManager::customContextMenuRequested(const QPoint &point)
     420{
     421    TRACE_OBJ
     422    QModelIndex index = bookmarkTreeView->indexAt(point);
    378423    if (!index.isValid())
    379424        return;
    380425
    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;
    392432    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"));
    402439    } else {
    403440        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
     456void 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
     464void BookmarkManager::managerWidgetAboutToClose()
     465{
     466    delete bookmarkManagerWidget;
     467    bookmarkManagerWidget = 0;
     468}
     469
     470void 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);
    409479        }
    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));
    708481    } 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);
    912487    }
    913488}
  • trunk/tools/assistant/tools/assistant/bookmarkmanager.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
    41 
    4241#ifndef BOOKMARKMANAGER_H
    4342#define BOOKMARKMANAGER_H
    4443
    45 #include "ui_bookmarkdialog.h"
     44#include <QtCore/QMutex>
     45#include <QtGui/QTreeView>
    4646
    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"
    5848
    5949QT_BEGIN_NAMESPACE
    6050
    61 class QEvent;
    62 class QLineEdit;
    63 class QTreeView;
    64 class QToolButton;
    65 class QStandardItem;
    66 class QHelpEngineCore;
    67 class QAbstractItemModel;
     51class BookmarkManagerWidget;
     52class BookmarkModel;
     53class BookmarkFilterModel;
     54class QKeyEvent;
    6855class QSortFilterProxyModel;
    69 
    70 class BookmarkManager;
    71 
    72 class BookmarkDialog : public QDialog
    73 {
    74     Q_OBJECT
    75 
    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_OBJECT
    108 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 QWidget
    117 {
    118     Q_OBJECT
    119 
    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 QStandardItemModel
    154 {
    155     Q_OBJECT
    156 
    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 };
    16456
    16557class BookmarkManager : public QObject
    16658{
    16759    Q_OBJECT
     60
     61
     62
     63
    16864
    16965public:
    170     BookmarkManager(QHelpEngineCore* helpEngine);
     66    static BookmarkManager* instance();
     67    static void destroy();
     68
     69    QWidget* bookmarkDockWidget() const;
     70    void takeBookmarksMenu(QMenu* menu);
     71
     72public slots:
     73    void addBookmark(const QString &title, const QString &url);
     74
     75signals:
     76    void escapePressed();
     77    void setSource(const QUrl &url);
     78    void setSourceInNewTab(const QUrl &url);
     79
     80private:
     81    BookmarkManager();
    17182    ~BookmarkManager();
    17283
    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);
    17588
    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();
     89private slots:
     90    void setupFinished();
    18591
    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
     106private:
     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
     123class BookmarkManager::BookmarkWidget : public QWidget
     124{
     125    Q_OBJECT
     126public:
     127    BookmarkWidget(QWidget *parent = 0)
     128        : QWidget(parent) { ui.setupUi(this); }
     129    virtual ~BookmarkWidget() {}
     130
     131    Ui::BookmarkWidget ui;
    188132
    189133signals:
    190     void bookmarksChanged();
     134    void focusInEvent();
     135
     136private:
     137    void focusInEvent(QFocusEvent *event);
     138};
     139
     140class BookmarkManager::BookmarkTreeView : public QTreeView
     141{
     142    Q_OBJECT
     143public:
     144    BookmarkTreeView(QWidget *parent = 0);
     145    ~BookmarkTreeView() {}
     146
     147    void subclassKeyPressEvent(QKeyEvent *event);
    191148
    192149private 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);
    211151};
    212152
    213153QT_END_NAMESPACE
    214154
    215 #endif
     155#endif
  • trunk/tools/assistant/tools/assistant/centralwidget.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "centralwidget.h"
    43 #include "helpviewer.h"
     44#include "findwidget.h"
     45#include "helpenginewrapper.h"
    4446#include "searchwidget.h"
    4547#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
    5056#include <QtCore/QTimer>
    5157
     58
     59
     60
    5261#include <QtGui/QMenu>
    53 #include <QtGui/QLabel>
    54 #include <QtGui/QLayout>
    5562#include <QtGui/QPrinter>
    56 #include <QtGui/QLineEdit>
    57 #include <QtGui/QCheckBox>
    5863#include <QtGui/QTabBar>
    5964#include <QtGui/QTabWidget>
     65
    6066#include <QtGui/QToolButton>
    61 #include <QtGui/QMouseEvent>
    62 #include <QtGui/QSpacerItem>
    63 #include <QtGui/QTextCursor>
     67#include <QtGui/QPageSetupDialog>
    6468#include <QtGui/QPrintDialog>
    65 #include <QtGui/QApplication>
    66 #include <QtGui/QTextDocumentFragment>
    6769#include <QtGui/QPrintPreviewDialog>
    68 #include <QtGui/QPageSetupDialog>
    69 
    70 #include <QtHelp/QHelpEngine>
     70
    7171#include <QtHelp/QHelpSearchEngine>
    7272
     
    7777        const QPoint &point)
    7878    {
     79
    7980        QTabBar *tabBar = qFindChild<QTabBar*>(widget);
    8081        for (int i = 0; i < tabBar->count(); ++i) {
     
    8788}
    8889
    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         ">&nbsp;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
     92CentralWidget::CentralWidget(MainWindow *parent)
    20993    : QWidget(parent)
    21094    , lastTabPage(0)
    211     , collectionFile(engine->collectionFile())
    212     , findBar(0)
    21395    , tabWidget(0)
    21496    , findWidget(0)
    215     , helpEngine(engine)
    21697    , printer(0)
    21798    , usesDefaultCollection(parent->usesDefaultCollection())
    21899    , m_searchWidget(0)
    219100{
     101
    220102    globalActionList.clear();
    221103    staticCentralWidget = this;
     
    254136    vboxLayout->addWidget(tabWidget);
    255137
    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()));
    270147
    271148    QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget);
     
    289166CentralWidget::~CentralWidget()
    290167{
     168
    291169#ifndef QT_NO_PRINTER
    292170    delete printer;
    293171#endif
    294172
    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;
    302175    bool searchAttached = m_searchWidget->isAttached();
    303176
     
    306179        HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
    307180        if (viewer && viewer->source().isValid()) {
    308             currentPages += viewer->source().toString() + separator;
    309             zoomCount += QString::number(viewer->zoom()) + separator;
     181            currentPages ;
     182            zoom;
    310183        }
    311184    }
    312185
    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);
    321191}
    322192
    323193CentralWidget *CentralWidget::instance()
    324194{
     195
    325196    return staticCentralWidget;
    326197}
     
    328199void CentralWidget::newTab()
    329200{
     201
    330202    HelpViewer *viewer = currentHelpViewer();
    331203#if !defined(QT_NO_WEBKIT)
     
    339211void CentralWidget::zoomIn()
    340212{
    341     HelpViewer *viewer = currentHelpViewer();
    342     if (viewer)
    343         viewer->zoomIn();
     213    TRACE_OBJ
     214    HelpViewer *viewer = currentHelpViewer();
     215    if (viewer)
     216        viewer->scaleUp();
    344217
    345218    if (tabWidget->currentWidget() == m_searchWidget)
     
    349222void CentralWidget::zoomOut()
    350223{
    351     HelpViewer *viewer = currentHelpViewer();
    352     if (viewer)
    353         viewer->zoomOut();
     224    TRACE_OBJ
     225    HelpViewer *viewer = currentHelpViewer();
     226    if (viewer)
     227        viewer->scaleDown();
    354228
    355229    if (tabWidget->currentWidget() == m_searchWidget)
     
    357231}
    358232
    359 void CentralWidget::findNext()
    360 {
    361     find(findWidget->editFind->text(), true);
    362 }
    363 
    364233void CentralWidget::nextPage()
    365234{
     235
    366236    int index = tabWidget->currentIndex() + 1;
    367237    if (index >= tabWidget->count())
     
    372242void CentralWidget::resetZoom()
    373243{
    374     HelpViewer *viewer = currentHelpViewer();
    375     if (viewer)
    376         viewer->resetZoom();
     244   
     245    if ()
     246        viewer->reset();
    377247
    378248    if (tabWidget->currentWidget() == m_searchWidget)
     
    382252void CentralWidget::previousPage()
    383253{
     254
    384255    int index = tabWidget->currentIndex() -1;
    385256    if (index < 0)
     
    388259}
    389260
    390 void CentralWidget::findPrevious()
    391 {
    392     find(findWidget->editFind->text(), false);
    393 }
    394 
    395261void CentralWidget::closeTab()
    396262{
     263
    397264    HelpViewer *viewer = currentHelpViewer();
    398265    if (!viewer|| tabWidget->count() == 1)
     
    405272void CentralWidget::setSource(const QUrl &url)
    406273{
     274
    407275    HelpViewer *viewer = currentHelpViewer();
    408276    HelpViewer *lastViewer =
     
    410278
    411279    if (!viewer && !lastViewer) {
    412         viewer = new HelpViewer(helpEngine, this);
     280        viewer = new HelpViewer(this);
    413281        viewer->installEventFilter(this);
    414282        lastTabPage = tabWidget->addTab(viewer, QString());
     
    428296void CentralWidget::setupWidget()
    429297{
    430     int option = helpEngine->customValue(QLatin1String("StartOption"),
    431         ShowLastPages).toInt();
    432 
     298   
     299    ();
     300    int option = helpEngine.startOption();
    433301    if (option != ShowLastPages) {
    434302        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)
    442306            homePage = QLatin1String("about:blank");
    443307        setSource(homePage);
     
    449313void CentralWidget::setLastShownPages()
    450314{
    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();
    456318    const int pageCount = lastShownPageList.count();
    457319    if (pageCount == 0) {
     
    462324        return;
    463325    }
    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
    487330    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        ;
    492335    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);
    496348}
    497349
    498350bool CentralWidget::hasSelection() const
    499351{
     352
    500353    const HelpViewer *viewer = currentHelpViewer();
    501354    return viewer ? viewer->hasSelection() : false;
     
    504357QUrl CentralWidget::currentSource() const
    505358{
     359
    506360    const HelpViewer *viewer = currentHelpViewer();
    507361    if (viewer)
     
    513367QString CentralWidget::currentTitle() const
    514368{
     369
    515370    const HelpViewer *viewer = currentHelpViewer();
    516371    if (viewer)
     
    522377void CentralWidget::copySelection()
    523378{
     379
    524380    HelpViewer *viewer = currentHelpViewer();
    525381    if (viewer)
     
    529385void CentralWidget::showTextSearch()
    530386{
    531     findBar->show();
    532     findWidget->editFind->selectAll();
    533     findWidget->editFind->setFocus(Qt::ShortcutFocusReason);
     387    TRACE_OBJ
     388    findWidget->show();
    534389}
    535390
    536391void CentralWidget::initPrinter()
    537392{
     393
    538394#ifndef QT_NO_PRINTER
    539395    if (!printer)
     
    544400void CentralWidget::print()
    545401{
     402
    546403#ifndef QT_NO_PRINTER
    547404    HelpViewer *viewer = currentHelpViewer();
     
    551408    initPrinter();
    552409
    553     QPrintDialog *dlg = new QPrintDialog(printer, this);
     410    QPrintDialog g(printer, this);
    554411#if defined(QT_NO_WEBKIT)
    555412    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) {
    562419        viewer->print(printer);
    563420    }
    564     delete dlg;
    565421#endif
    566422}
     
    568424void CentralWidget::printPreview()
    569425{
     426
    570427#ifndef QT_NO_PRINTER
    571428    initPrinter();
     
    579436void CentralWidget::printPreview(QPrinter *p)
    580437{
     438
    581439#ifndef QT_NO_PRINTER
    582440    HelpViewer *viewer = currentHelpViewer();
     
    588446void CentralWidget::pageSetup()
    589447{
     448
    590449#ifndef QT_NO_PRINTER
    591450    initPrinter();
     
    597456bool CentralWidget::isHomeAvailable() const
    598457{
     458
    599459    return currentHelpViewer() ? true : false;
    600460}
     
    602462void CentralWidget::home()
    603463{
     464
    604465    HelpViewer *viewer = currentHelpViewer();
    605466    if (viewer)
     
    609470bool CentralWidget::isForwardAvailable() const
    610471{
     472
    611473    const HelpViewer *viewer = currentHelpViewer();
    612474    if (viewer)
     
    618480void CentralWidget::forward()
    619481{
     482
    620483    HelpViewer *viewer = currentHelpViewer();
    621484    if (viewer)
     
    625488bool CentralWidget::isBackwardAvailable() const
    626489{
     490
    627491    const HelpViewer *viewer = currentHelpViewer();
    628492    if (viewer)
     
    634498void CentralWidget::backward()
    635499{
     500
    636501    HelpViewer *viewer = currentHelpViewer();
    637502    if (viewer)
     
    642507QList<QAction*> CentralWidget::globalActions() const
    643508{
     509
    644510    return globalActionList;
    645511}
     
    647513void CentralWidget::setGlobalActions(const QList<QAction*> &actions)
    648514{
     515
    649516    globalActionList = actions;
    650517}
     
    652519void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom)
    653520{
    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);
    663528    viewer->installEventFilter(this);
    664529    viewer->setSource(url);
     
    666531    tabWidget->setCurrentIndex(tabWidget->addTab(viewer,
    667532        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 #else
    677     setBrowserFontFor(viewer, font);
    678     viewer->setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom);
    679 #endif
    680 
    681533    connectSignals();
    682534}
     
    684536HelpViewer *CentralWidget::newEmptyTab()
    685537{
    686     HelpViewer *viewer = new HelpViewer(helpEngine, this);
     538    TRACE_OBJ
     539    HelpViewer *viewer = new HelpViewer(this);
    687540    viewer->installEventFilter(this);
    688541    viewer->setFocus(Qt::OtherFocusReason);
     
    696549}
    697550
    698 void CentralWidget::findCurrentText(const QString &text)
    699 {
    700     find(text, true);
    701 }
    702 
    703551void CentralWidget::connectSignals()
    704552{
     553
    705554    const HelpViewer *viewer = currentHelpViewer();
    706555    if (viewer) {
     
    717566        connect(viewer, SIGNAL(sourceChanged(QUrl)), this,
    718567            SLOT(setTabTitle(QUrl)));
    719     }
    720 }
    721 
    722 HelpViewer *CentralWidget::currentHelpViewer() const
    723 {
     568        connect(viewer, SIGNAL(printRequested()), this, SLOT(print()));
     569    }
     570}
     571
     572HelpViewer* CentralWidget::viewerAt(int index) const
     573{
     574    TRACE_OBJ
     575    return qobject_cast<HelpViewer*>(tabWidget->widget(index));
     576}
     577
     578HelpViewer* CentralWidget::currentHelpViewer() const
     579{
     580    TRACE_OBJ
    724581    return qobject_cast<HelpViewer*>(tabWidget->currentWidget());
    725582}
     
    727584void CentralWidget::activateTab(bool onlyHelpViewer)
    728585{
     586
    729587    if (currentHelpViewer()) {
    730588        currentHelpViewer()->setFocus();
     
    740598void CentralWidget::setTabTitle(const QUrl &url)
    741599{
     600
    742601    Q_UNUSED(url)
    743602#if !defined(QT_NO_WEBKIT)
     
    761620void CentralWidget::currentPageChanged(int index)
    762621{
     622
    763623    const HelpViewer *viewer = currentHelpViewer();
    764624    if (viewer)
     
    776636void CentralWidget::showTabBarContextMenu(const QPoint &point)
    777637{
     638
    778639    HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, point);
    779640    if (!viewer)
     
    823684
    824685    if (pickedAction == newBookmark)
    825         emit addNewBookmark(viewer->documentTitle(), viewer->source().toString());
     686        emit addBookmark(viewer->documentTitle(), viewer->source().toString());
    826687}
    827688
    828689bool CentralWidget::eventFilter(QObject *object, QEvent *e)
    829690{
     691
    830692    if (e->type() == QEvent::KeyPress) {
    831693        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
     
    833695            default: {
    834696                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                 }
    843697            }   break;
    844698
     
    883737void CentralWidget::keyPressEvent(QKeyEvent *e)
    884738{
     739
    885740    const QString &text = e->text();
    886741    if (text.startsWith(QLatin1Char('/'))) {
    887         if (!findBar->isVisible()) {
    888             findBar->show();
    889             findWidget->editFind->clear();
     742        if (!findWidget->isVisible()) {
     743            findWidget->showAndClear();
    890744        } else {
    891             findWidget->editFind->selectAll();
     745            findWidget->();
    892746        }
    893         findWidget->editFind->setFocus();
    894         return;
    895     }
    896     QWidget::keyPressEvent(e);
     747    } else {
     748        QWidget::keyPressEvent(e);
     749    }
     750}
     751
     752void CentralWidget::findNext()
     753{
     754    TRACE_OBJ
     755    find(findWidget->text(), true);
     756}
     757
     758void CentralWidget::findPrevious()
     759{
     760    TRACE_OBJ
     761    find(findWidget->text(), false);
    897762}
    898763
    899764void CentralWidget::find(const QString &ttf, bool forward)
    900765{
    901     QPalette p = findWidget->editFind->palette();
    902     p.setColor(QPalette::Active, QPalette::Base, Qt::white);
    903 
     766    TRACE_OBJ
    904767    bool found = false;
    905 
    906768#if defined(QT_NO_WEBKIT)
    907769    found = findInTextBrowser(ttf, forward);
     
    910772#endif
    911773
    912     if (!found && !ttf.isEmpty())
    913         p.setColor(QPalette::Active, QPalette::Base, QColor(255, 102, 102));
     774    if (!found && ttf.isEmpty())
     775       
    914776
    915777    if (!findWidget->isVisible())
    916778        findWidget->show();
    917     findWidget->editFind->setPalette(p);
     779    findWidget->);
    918780}
    919781
    920782bool CentralWidget::findInWebPage(const QString &ttf, bool forward)
    921783{
     784
    922785#if !defined(QT_NO_WEBKIT)
    923786    if (HelpViewer *viewer = currentHelpViewer()) {
     
    928791                options |= QWebPage::FindBackward;
    929792
    930             if (findWidget->checkCase->isChecked())
     793            if (findWidget->c())
    931794                options |= QWebPage::FindCaseSensitively;
    932795
    933796            found = viewer->findText(ttf, options);
    934             findWidget->labelWrapped->hide();
     797            findWidget->);
    935798
    936799            if (!found) {
     
    938801                found = viewer->findText(ttf, options);
    939802                if (found)
    940                     findWidget->labelWrapped->show();
     803                    findWidget->);
    941804            }
    942805        }
    943806        // force highlighting of all other matches, also when empty (clear)
    944807        options = QWebPage::HighlightAllOccurrences;
     808
     809
    945810        viewer->findText(QLatin1String(""), options);
    946811        viewer->findText(ttf, options);
     
    950815    // this needs to stay, case for active search results page
    951816    return findInTextBrowser(ttf, forward);
     817
     818
     819
    952820#endif
    953821    return false;
     
    956824bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward)
    957825{
     826
    958827    QTextBrowser *browser = qobject_cast<QTextBrowser*>(currentHelpViewer());
    959828    if (tabWidget->currentWidget() == m_searchWidget)
     
    979848        options |= QTextDocument::FindBackward;
    980849
    981     if (findWidget->checkCase->isChecked())
     850    if (findWidget->c())
    982851        options |= QTextDocument::FindCaseSensitively;
    983852
    984     if (findWidget->checkWholeWords->isChecked())
    985         options |= QTextDocument::FindWholeWords;
    986 
    987     findWidget->labelWrapped->hide();
     853    findWidget->setTextWrappedVisible(false);
    988854
    989855    bool found = true;
     
    998864            newCursor = cursor;
    999865        } else {
    1000             findWidget->labelWrapped->show();
     866            findWidget->);
    1001867        }
    1002868    }
     
    1007873void CentralWidget::updateBrowserFont()
    1008874{
    1009     QFont font;
    1010     bool searchAttached = searchWidgetAttached();
     875   
     876    bool searchAttached = searchWidgetAttached();
    1011877    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
     891bool CentralWidget::searchWidgetAttached() const
     892{
     893    TRACE_OBJ
     894    return m_searchWidget && m_searchWidget->isAttached();
    1020895}
    1021896
    1022897void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine)
    1023898{
     899
    1024900    if (m_searchWidget)
    1025901        return;
     
    1031907        SLOT(setSourceFromSearchInNewTab(QUrl)));
    1032908
    1033     QFont font;
    1034     getBrowserFontFor(m_searchWidget, &font);
    1035     setBrowserFontFor(m_searchWidget, font);
     909    ;
     910   
     911    );
    1036912}
    1037913
    1038914void CentralWidget::activateSearchWidget(bool updateLastTabPage)
    1039915{
     916
    1040917    if (!m_searchWidget)
    1041         createSearchWidget(helpEngine->searchEngine());
     918        createSearchWidget(searchEngine());
    1042919
    1043920    if (!m_searchWidget->isAttached()) {
     
    1055932void CentralWidget::removeSearchWidget()
    1056933{
     934
    1057935    if (searchWidgetAttached()) {
    1058936        tabWidget->removeTab(0);
     
    1063941int CentralWidget::availableHelpViewer() const
    1064942{
     943
    1065944    int count = tabWidget->count();
    1066945    if (searchWidgetAttached())
     
    1071950bool CentralWidget::enableTabCloseAction() const
    1072951{
     952
    1073953    int minTabCount = 1;
    1074954    if (searchWidgetAttached())
     
    1080960QString CentralWidget::quoteTabTitle(const QString &title) const
    1081961{
     962
    1082963    QString s = title;
    1083964    return s.replace(QLatin1Char('&'), QLatin1String("&&"));
     
    1087968CentralWidget::setSourceFromSearch(const QUrl &url)
    1088969{
     970
    1089971    setSource(url);
    1090972#if defined(QT_NO_WEBKIT)
     
    1099981CentralWidget::setSourceFromSearchInNewTab(const QUrl &url)
    1100982{
     983
    1101984    setSourceInNewTab(url);
    1102985#if defined(QT_NO_WEBKIT)
     
    1111994CentralWidget::highlightSearchTerms()
    1112995{
     996
    1113997    HelpViewer *viewer = currentHelpViewer();
    1114998    if (!viewer)
    1115999        return;
    11161000
    1117     QHelpSearchEngine *searchEngine = helpEngine->searchEngine();
     1001    QHelpSearchEngine *searchEngine =
     1002        HelpEngineWrapper::instance().searchEngine();
    11181003    QList<QHelpSearchQuery> queryList = searchEngine->query();
    11191004
     
    11271012            case QHelpSearchQuery::ATLEAST:
    11281013                foreach (QString term, query.wordList)
    1129                     terms.append(term.remove(QLatin1String("\"")));
     1014                    terms.append(term.remove(QLatin1)));
    11301015            }
    11311016        }
     
    11751060}
    11761061
     1062
     1063
     1064
     1065
     1066
     1067
     1068
     1069
     1070
     1071
     1072
     1073
     1074
     1075
     1076
     1077
     1078
     1079
     1080
     1081
     1082
     1083
     1084
     1085
    11771086void CentralWidget::closeTabAt(int index)
    11781087{
     1088
    11791089    HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(index));
    11801090    tabWidget->removeTab(index);
     
    11841094QMap<int, QString> CentralWidget::currentSourceFileList() const
    11851095{
     1096
    11861097    QMap<int, QString> sourceList;
    1187     for (int i = 1; i < tabWidget->count(); ++i) {
     1098    for (int i = ; i < tabWidget->count(); ++i) {
    11881099        HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
    11891100        if (viewer && viewer->source().isValid())
     
    11931104}
    11941105
    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 SearchWidget
    1200 #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 #endif
    1208     } 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 #else
    1226     if (widget && widget->font() != font)
    1227         widget->setFont(font);
    1228 #endif
    1229 }
    1230 
    12311106QT_END_NAMESPACE
  • trunk/tools/assistant/tools/assistant/centralwidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
    41 
    4241#ifndef CENTRALWIDGET_H
    4342#define CENTRALWIDGET_H
    4443
    4544#include <QtCore/QUrl>
    46 #include <QtCore/QPoint>
    47 #include <QtCore/QObject>
    48 
    4945#include <QtGui/QWidget>
    50 
    51 #include "searchwidget.h"
    5246
    5347QT_BEGIN_NAMESPACE
    5448
    55 class QEvent;
    56 class QLabel;
    57 class QAction;
    58 class QCheckBox;
    59 class QLineEdit;
    60 class QTextBrowser;
    61 class QToolButton;
    62 
     49class FindWidget;
    6350class HelpViewer;
     51
     52
    6453class 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 };
     54class SearchWidget;
    10655
    10756class CentralWidget : public QWidget
     
    11059
    11160public:
    112     CentralWidget(QHelpEngine *engine, MainWindow *parent);
     61    CentralWidget(MainWindow *parent);
    11362    ~CentralWidget();
    11463
     
    12271    QList<QAction*> globalActions() const;
    12372    void setGlobalActions(const QList<QAction*> &actions);
     73
     74
    12475    HelpViewer *currentHelpViewer() const;
    125     void activateTab(bool onlyHelpViewer = false);
    12676
    127     bool searchWidgetAttached() const {
    128         return m_searchWidget && m_searchWidget->isAttached();
    129     }
     77    bool searchWidgetAttached() const;
    13078    void createSearchWidget(QHelpSearchEngine *searchEngine);
    13179    void activateSearchWidget(bool updateLastTabPage = false);
     
    13583    bool enableTabCloseAction() const;
    13684
     85
    13786    void closeTabAt(int index);
    13887    QMap<int, QString> currentSourceFileList() const;
     
    14392    void zoomIn();
    14493    void zoomOut();
    145     void findNext();
    14694    void nextPage();
    14795    void resetZoom();
    14896    void previousPage();
    149     void findPrevious();
    15097    void copySelection();
    15198    void showTextSearch();
     
    156103    void setSource(const QUrl &url);
    157104    void setSourceInNewTab(const QUrl &url, qreal zoom = 0.0);
    158     void findCurrentText(const QString &text);
    159105    HelpViewer *newEmptyTab();
    160106    void home();
    161107    void forward();
    162108    void backward();
     109
     110
     111
     112
     113
     114
    163115
    164116signals:
     
    169121    void forwardAvailable(bool available);
    170122    void backwardAvailable(bool available);
    171     void addNewBookmark(const QString &title, const QString &url);
     123    void addBookmark(const QString &title, const QString &url);
    172124
    173125protected:
     
    188140    void connectSignals();
    189141    bool eventFilter(QObject *object, QEvent *e);
    190     void find(const QString &ttf, bool forward);
    191142    bool findInWebPage(const QString &ttf, bool forward);
    192143    bool findInTextBrowser(const QString &ttf, bool forward);
     
    195146    void setLastShownPages();
    196147
    197     void getBrowserFontFor(QWidget* viewer, QFont *font);
    198     void setBrowserFontFor(QWidget *widget, const QFont &font);
    199 
    200148private:
    201149    int lastTabPage;
    202     QString collectionFile;
    203150    QList<QAction*> globalActionList;
    204151
    205     QWidget *findBar;
    206152    QTabWidget *tabWidget;
    207153    FindWidget *findWidget;
    208     QHelpEngine *helpEngine;
    209154    QPrinter *printer;
    210155    bool usesDefaultCollection;
  • trunk/tools/assistant/tools/assistant/cmdlineparser.cpp

    r697 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include <QtCore/QFileInfo>
     44
    4345#include <QtGui/QMessageBox>
    4446
     
    4749QT_BEGIN_NAMESPACE
    4850
    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(
     51static const char helpMessage[] = QT_TRANSLATE_NOOP("CmdLineParser",
    6452        "Usage: assistant [Options]\n\n"
    6553        "-collectionFile file       Uses the specified collection\n"
     
    8674        "-setCurrentFilter filter   Set the filter as the active filter.\n"
    8775        "-remove-search-index       Removes the full text search index.\n"
     76
    8877        "-quiet                     Does not display any error or\n"
    8978        "                           status message.\n"
    9079        "-help                      Displays this help.\n"
    9180        );
    92 }
    93 
    94 CmdLineParser::Result CmdLineParser::parse(const QStringList &arguments)
    95 {
    96     QString error;
     81
     82
     83CmdLineParser::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
     105CmdLineParser::Result CmdLineParser::parse()
     106{
     107    TRACE_OBJ
    97108    bool showHelp = false;
    98109
    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"))
    133117            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"))
    223131            m_removeSearchIndex = true;
    224         } else if (arg == QLatin1String("-quiet")) {
    225             continue;
    226         } else if (arg == QLatin1String("-help")) {
     132       
     133            ue;
     134       
    227135            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);
    238142        return Error;
    239143    } else if (showHelp) {
    240         showMessage(m_helpMessage, false);
     144        showMessage(, false);
    241145        return Help;
    242146    }
     
    244148}
    245149
     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
    246266QString CmdLineParser::getFileName(const QString &fileName)
    247267{
     268
    248269    QFileInfo fi(fileName);
    249270    if (!fi.exists())
     
    254275void CmdLineParser::showMessage(const QString &msg, bool error)
    255276{
     277
    256278    if (m_quiet)
    257279        return;
    258280#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
    259     QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>");
     281    QString QLatin1String("</pre>");
    260282    if (error)
    261         QMessageBox::critical(0, QObject::tr("Qt Assistant"), s);
     283        QMessageBox::critical(0, );
    262284    else
    263         QMessageBox::information(0, QObject::tr("Qt Assistant"), s);
     285        QMessageBox::information(0, );
    264286#else
    265287    fprintf(error ? stderr : stdout, "%s\n", qPrintable(msg));
     
    269291void CmdLineParser::setCollectionFile(const QString &file)
    270292{
     293
    271294    m_collectionFile = file;
    272295}
     
    274297QString CmdLineParser::collectionFile() const
    275298{
     299
    276300    return m_collectionFile;
    277301}
    278302
     303
     304
     305
     306
     307
     308
     309
    279310QUrl CmdLineParser::url() const
    280311{
     312
    281313    return m_url;
    282314}
     
    284316bool CmdLineParser::enableRemoteControl() const
    285317{
     318
    286319    return m_enableRemoteControl;
    287320}
     
    289322CmdLineParser::ShowState CmdLineParser::contents() const
    290323{
     324
    291325    return m_contents;
    292326}
     
    294328CmdLineParser::ShowState CmdLineParser::index() const
    295329{
     330
    296331    return m_index;
    297332}
     
    299334CmdLineParser::ShowState CmdLineParser::bookmarks() const
    300335{
     336
    301337    return m_bookmarks;
    302338}
     
    304340CmdLineParser::ShowState CmdLineParser::search() const
    305341{
     342
    306343    return m_search;
    307344}
     
    309346QString CmdLineParser::currentFilter() const
    310347{
     348
    311349    return m_currentFilter;
    312350}
     
    314352bool CmdLineParser::removeSearchIndex() const
    315353{
     354
    316355    return m_removeSearchIndex;
    317356}
    318357
     358
     359
     360
     361
     362
     363
    319364CmdLineParser::RegisterState CmdLineParser::registerRequest() const
    320365{
     366
    321367    return m_register;
    322368}
     
    324370QString CmdLineParser::helpFile() const
    325371{
     372
    326373    return m_helpFile;
    327374}
  • trunk/tools/assistant/tools/assistant/cmdlineparser.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4343#define CMDLINEPARSER_H
    4444
     45
    4546#include <QtCore/QStringList>
    4647#include <QtCore/QUrl>
     
    5051class CmdLineParser
    5152{
     53
    5254public:
    5355    enum Result {Ok, Help, Error};
     
    5557    enum RegisterState {None, Register, Unregister};
    5658
    57     CmdLineParser();
    58     Result parse(const QStringList &arguments);
     59    CmdLineParser();
     60    Result parse();
    5961
    6062    void setCollectionFile(const QString &file);
    6163    QString collectionFile() const;
     64
    6265    QString cloneFile() const;
    6366    QUrl url() const;
     
    6972    QString currentFilter() const;
    7073    bool removeSearchIndex() const;
     74
    7175    RegisterState registerRequest() const;
    7276    QString helpFile() const;
    73 
    74     bool copy() const { return m_copy; }
    7577
    7678    void showMessage(const QString &msg, bool error);
     
    7880private:
    7981    QString getFileName(const QString &fileName);
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
    8094
    81     QString m_helpMessage;
     95    QStringList m_arguments;
     96    int m_pos;
    8297    QString m_collectionFile;
    8398    QString m_cloneFile;
     
    93108    QString m_currentFilter;
    94109    bool m_removeSearchIndex;
    95     bool m_copy;
     110    bool m_;
    96111    bool m_quiet;
     112
    97113};
    98114
  • trunk/tools/assistant/tools/assistant/contentwindow.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "contentwindow.h"
    4344#include "centralwidget.h"
     45
     46
    4447
    4548#include <QtGui/QLayout>
     
    4750#include <QtGui/QMenu>
    4851
    49 #include <QtHelp/QHelpEngine>
    5052#include <QtHelp/QHelpContentWidget>
    5153
    5254QT_BEGIN_NAMESPACE
    5355
    54 ContentWindow::ContentWindow(QHelpEngine *helpEngine)
    55     : m_helpEngine(helpEngine)
    56     , m_contentWidget(0)
     56ContentWindow::ContentWindow()
     57    : m_contentWidget(HelpEngineWrapper::instance().contentWidget())
    5758    , m_expandDepth(-2)
    5859{
    59     m_contentWidget = m_helpEngine->contentWidget();
     60   
    6061    m_contentWidget->viewport()->installEventFilter(this);
    6162    m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu);
     
    7778ContentWindow::~ContentWindow()
    7879{
     80
    7981}
    8082
    8183bool ContentWindow::syncToContent(const QUrl& url)
    8284{
     85
    8386    QModelIndex idx = m_contentWidget->indexOf(url);
    8487    if (!idx.isValid())
     
    9093void ContentWindow::expandTOC()
    9194{
     95
     96
    9297    if (m_expandDepth > -2) {
    9398        expandToDepth(m_expandDepth);
     
    98103void ContentWindow::expandToDepth(int depth)
    99104{
     105
     106
    100107    m_expandDepth = depth;
    101108    if (depth == -1)
    102109        m_contentWidget->expandAll();
     110
     111
    103112    else
    104         m_contentWidget->expandToDepth(depth);
     113        m_contentWidget->expandToDepth(depth);
    105114}
    106115
    107116void ContentWindow::focusInEvent(QFocusEvent *e)
    108117{
     118
    109119    if (e->reason() != Qt::MouseFocusReason)
    110120        m_contentWidget->setFocus();
     
    113123void ContentWindow::keyPressEvent(QKeyEvent *e)
    114124{
     125
    115126    if (e->key() == Qt::Key_Escape)
    116127        emit escapePressed();
     
    119130bool ContentWindow::eventFilter(QObject *o, QEvent *e)
    120131{
     132
    121133    if (m_contentWidget && o == m_contentWidget->viewport()
    122134        && e->type() == QEvent::MouseButtonRelease) {
    123135        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();
    125141        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)) {
    129143            if ((button == Qt::LeftButton && (me->modifiers() & Qt::ControlModifier))
    130144                || (button == Qt::MidButton)) {
     
    133147                if (contentModel) {
    134148                    QHelpContentItem *itm = contentModel->contentItemAt(index);
    135                     if (itm && !isPdfFile(itm))
     149                    if (itm && ))
    136150                        CentralWidget::instance()->setSourceInNewTab(itm->url());
    137151                }
     
    147161void ContentWindow::showContextMenu(const QPoint &pos)
    148162{
     163
    149164    if (!m_contentWidget->indexAt(pos).isValid())
    150165        return;
     
    158173    QAction *curTab = menu.addAction(tr("Open Link"));
    159174    QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
    160     if (isPdfFile(itm))
     175    if ())
    161176        newTab->setEnabled(false);
    162177   
     
    172187void ContentWindow::itemClicked(const QModelIndex &index)
    173188{
     189
    174190    QHelpContentModel *contentModel =
    175191        qobject_cast<QHelpContentModel*>(m_contentWidget->model());
    176192
    177193    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        }
    181199    }
    182200}
    183201
    184 bool ContentWindow::isPdfFile(QHelpContentItem *item) const
    185 {
    186     const QString &path = item->url().path();
    187     return path.endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive);
    188 }
    189 
    190202QT_END_NAMESPACE
  • trunk/tools/assistant/tools/assistant/contentwindow.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5858
    5959public:
    60     ContentWindow(QHelpEngine *helpEngine);
     60    ContentWindow();
    6161    ~ContentWindow();
    6262
     
    7979    bool isPdfFile(QHelpContentItem *item) const;
    8080
    81     QHelpEngine *m_helpEngine;
    82     QHelpContentWidget *m_contentWidget;
     81    QHelpContentWidget * const m_contentWidget;
    8382    int m_expandDepth;
    8483};
  • trunk/tools/assistant/tools/assistant/doc/assistant.qdoc

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    77** This file is part of the documentation of the Qt Toolkit.
    88**
    9 ** $QT_BEGIN_LICENSE:LGPL$
     9** $QT_BEGIN_LICENSE:L$
    1010** Commercial Usage
    1111** Licensees holding valid Qt Commercial licenses may use this file in
    1212** 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.
    3521**
    3622** If you have questions regarding the use of this file, please contact
  • trunk/tools/assistant/tools/assistant/doc/assistant.qdocconf

    r769 r846  
    1313              "<td width=\"30%\" align=\"left\">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>\n" \
    1414              "<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" \
    1616              "</tr></table></div></address>"
  • trunk/tools/assistant/tools/assistant/filternamedialog.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include <QtGui/QPushButton>
     
    4950    : QDialog(parent)
    5051{
     52
    5153    m_ui.setupUi(this);
    5254    connect(m_ui.buttonBox->button(QDialogButtonBox::Ok),
     
    6264QString FilterNameDialog::filterName() const
    6365{
     66
    6467    return m_ui.lineEdit->text();
    6568}
     
    6770void FilterNameDialog::updateOkButton()
    6871{
     72
    6973    m_ui.buttonBox->button(QDialogButtonBox::Ok)
    7074        ->setDisabled(m_ui.lineEdit->text().isEmpty());
  • trunk/tools/assistant/tools/assistant/filternamedialog.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/assistant/helpviewer.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
     42
     43
    4144
    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>
    4450
    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>
    5651#include <QtGui/QDesktopServices>
    57 
    58 #include <QtHelp/QHelpEngine>
    59 
    60 #include <QNetworkAccessManager>
    61 #include <QNetworkReply>
    62 #include <QNetworkRequest>
    6352
    6453QT_BEGIN_NAMESPACE
    6554
    66 #if !defined(QT_NO_WEBKIT)
     55const QLatin1String AbstractHelpViewer::DocPath("qthelp://com.trolltech.");
    6756
    68 class HelpNetworkReply : public QNetworkReply
    69 {
    70 public:
    71     HelpNetworkReply(const QNetworkRequest &request, const QByteArray &fileData,
    72         const QString &mimeType);
     57const QString AbstractHelpViewer::AboutBlank =
     58    QCoreApplication::translate("HelpViewer", "<title>about:blank</title>");
    7359
    74     virtual void abort();
     60const QString AbstractHelpViewer::LocalHelpFile = QLatin1String("qthelp://"
     61    "com.trolltech.com.assistantinternal-1.0.0/assistant/assistant.html");
    7562
    76     virtual qint64 bytesAvailable() const
    77         { return data.length() + QNetworkReply::bytesAvailable(); }
     63const 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>");
    7867
    79 protected:
    80     virtual qint64 readData(char *data, qint64 maxlen);
    81 
    82 private:
    83     QByteArray data;
    84     qint64 origLen;
     68struct 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 }
    85103};
    86104
    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
    93106
    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)
     107AbstractHelpViewer::AbstractHelpViewer()
    133108{
    134109}
    135110
    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)
     111AbstractHelpViewer::~AbstractHelpViewer()
    188112{
    189113}
    190114
    191 QWebPage *HelpPage::createWindow(QWebPage::WebWindowType)
     115)
    192116{
    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()
    204120        || scheme == QLatin1String("file")
    205121        || scheme == QLatin1String("qrc")
    206122        || scheme == QLatin1String("data")
    207123        || scheme == QLatin1String("qthelp")
    208         || scheme == QLatin1String("about"))
    209         return true;
    210     return false;
     124        || scheme == QLatin1String("about");
    211125}
    212126
    213 void HelpPage::triggerAction(WebAction action, bool checked)
     127)
    214128{
    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();
    222131}
    223132
    224 bool HelpPage::acceptNavigationRequest(QWebFrame *,
    225     const QNetworkRequest &request, QWebPage::NavigationType type)
     133QString AbstractHelpViewer::mimeFromUrl(const QUrl &url)
    226134{
    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();
    230139
    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;
    264145    }
    265 
    266     QDesktopServices::openUrl(url);
    267     return false;
     146    return QLatin1String("");
    268147}
    269148
    270 HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent)
    271     : QWebView(parent)
    272     , helpEngine(engine)
    273     , parentWidget(parent)
    274     , loadFinished(false)
     149bool AbstractHelpViewer::launchWithExternalApp(const QUrl &url)
    275150{
    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;
    277157
    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;
    279163
    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;
    281169
    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()));
    422173        }
    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);
    495176    }
    496177    return false;
    497178}
    498179
    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 
    627180QT_END_NAMESPACE
  • trunk/tools/assistant/tools/assistant/helpviewer.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
    41 
    4241#ifndef HELPVIEWER_H
    4342#define HELPVIEWER_H
    4443
    45 #include <QtCore/QUrl>
    46 #include <QtCore/QVariant>
    47 #include <QtGui/QTextBrowser>
    48 #include <QtGui/QAction>
     44#include <QtCore/QString>
    4945
    50 #if !defined(QT_NO_WEBKIT)
    51 #include <QWebView>
    52 #endif
     46#include <QtGui/QFont>
    5347
    5448QT_BEGIN_NAMESPACE
    5549
    56 class QHelpEngine;
    57 class CentralWidget;
     50class Q;
     51class ;
    5852
    59 class QPoint;
    60 class QString;
    61 class QKeyEvent;
    62 class QMouseEvent;
    63 class QContextMenuEvent;
     53class
     54{
     55public:
     56;
     57;
    6458
    65 #if !defined(QT_NO_WEBKIT)
     59    virtual QFont viewerFont() const = 0;
     60    virtual void setViewerFont(const QFont &font) = 0;
    6661
    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;
    7067
    71 public:
    72     HelpViewer(QHelpEngine *helpEngine, CentralWidget *parent);
    73     void setSource(const QUrl &url);
     68    virtual bool handleForwardBackwardMouseButtons(QMouseEvent *e) = 0;
    7469
    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;
    7774
    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);
    12479};
    125 
    126 #else
    127 
    128 class HelpViewer : public QTextBrowser
    129 {
    130     Q_OBJECT
    131 
    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() const
    143     { 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 #endif
    17380
    17481QT_END_NAMESPACE
    17582
    176 #endif
     83#endif
  • trunk/tools/assistant/tools/assistant/indexwindow.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "indexwindow.h"
    4344#include "centralwidget.h"
     45
     46
    4447#include "topicchooser.h"
    4548
     
    5255#include <QtGui/QListWidgetItem>
    5356
    54 #include <QtHelp/QHelpEngine>
    5557#include <QtHelp/QHelpIndexWidget>
    5658
    5759QT_BEGIN_NAMESPACE
    5860
    59 IndexWindow::IndexWindow(QHelpEngine *helpEngine, QWidget *parent)
     61IndexWindow::IndexWindow(QWidget *parent)
    6062    : 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
    6567    QVBoxLayout *layout = new QVBoxLayout(this);
    6668    QLabel *l = new QLabel(tr("&Look for:"));
    6769    layout->addWidget(l);
    6870
    69     m_searchLineEdit = new QLineEdit();
    7071    l->setBuddy(m_searchLineEdit);
    7172    connect(m_searchLineEdit, SIGNAL(textChanged(QString)), this,
     
    7576    layout->addWidget(m_searchLineEdit);
    7677
    77     m_indexWidget = m_helpEngine->indexWidget();
     78    ();
    7879    m_indexWidget->installEventFilter(this);
    79     connect(m_helpEngine->indexModel(), SIGNAL(indexCreationStarted()), this,
     80    connect(indexModel(), SIGNAL(indexCreationStarted()), this,
    8081        SLOT(disableSearchLineEdit()));
    81     connect(m_helpEngine->indexModel(), SIGNAL(indexCreated()), this,
     82    connect(indexModel(), SIGNAL(indexCreated()), this,
    8283        SLOT(enableSearchLineEdit()));
    8384    connect(m_indexWidget, SIGNAL(linkActivated(QUrl,QString)), this,
     
    9495IndexWindow::~IndexWindow()
    9596{
     97
    9698}
    9799
    98100void IndexWindow::filterIndices(const QString &filter)
    99101{
     102
    100103    if (filter.contains(QLatin1Char('*')))
    101104        m_indexWidget->filterIndices(filter, filter);
     
    106109bool IndexWindow::eventFilter(QObject *obj, QEvent *e)
    107110{
     111
    108112    if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) {
    109113        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
     
    171175void IndexWindow::enableSearchLineEdit()
    172176{
     177
    173178    m_searchLineEdit->setDisabled(false);
    174179    filterIndices(m_searchLineEdit->text());
     
    177182void IndexWindow::disableSearchLineEdit()
    178183{
     184
    179185    m_searchLineEdit->setDisabled(true);
    180186}
     
    182188void IndexWindow::setSearchLineEditText(const QString &text)
    183189{
     190
    184191    m_searchLineEdit->setText(text);
    185192}
     
    187194void IndexWindow::focusInEvent(QFocusEvent *e)
    188195{
     196
    189197    if (e->reason() != Qt::MouseFocusReason) {
    190198        m_searchLineEdit->selectAll();
     
    195203void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index)
    196204{
     205
    197206    QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(indexWidget->model());
    198207    if (model) {
     
    211220        }
    212221
    213         if (url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive))
     222        if ())
    214223            CentralWidget::instance()->setSource(url);
    215224        else
  • trunk/tools/assistant/tools/assistant/indexwindow.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5050
    5151class QHelpIndexWidget;
    52 class QHelpEngine;
    5352class QModelIndex;
    5453
     
    5857
    5958public:
    60     IndexWindow(QHelpEngine *helpEngine, QWidget *parent = 0);
     59    IndexWindow(QWidget *parent = 0);
    6160    ~IndexWindow();
    6261
     
    8584    QLineEdit *m_searchLineEdit;
    8685    QHelpIndexWidget *m_indexWidget;
    87     QHelpEngine *m_helpEngine;
    8886};
    8987
  • trunk/tools/assistant/tools/assistant/installdialog.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "installdialog.h"
     
    6768    : QDialog(parent), m_helpEngine(helpEngine), m_host(host), m_port(port)
    6869{
     70
    6971    m_ui.setupUi(this);
    7072   
     
    9597InstallDialog::~InstallDialog()
    9698{
     99
    97100}
    98101
    99102QStringList InstallDialog::installedDocumentations() const
    100103{
     104
    101105    return m_installedDocumentations;
    102106}
     
    104108void InstallDialog::init()
    105109{
     110
    106111    m_ui.statusLabel->setText(tr("Downloading documentation info..."));
    107112    m_ui.progressBar->show();
     
    123128void InstallDialog::updateInstallButton()
    124129{
     130
    125131    QListWidgetItem *item = 0;
    126132    for (int i=0; i<m_ui.listWidget->count(); ++i) {
     
    137143void InstallDialog::updateDocItemList()
    138144{
     145
    139146    QStringList registeredDocs = m_helpEngine->registeredDocumentations();
    140147    QListWidgetItem *item = 0;
     
    152159void InstallDialog::cancelDownload()
    153160{
     161
    154162    m_ui.statusLabel->setText(tr("Download canceled."));
    155163    m_httpAborted = true;
     
    163171void InstallDialog::install()
    164172{
     173
    165174    QListWidgetItem *item = 0;
    166175    for (int i=0; i<m_ui.listWidget->count(); ++i) {
     
    175184void InstallDialog::downloadNextFile()
    176185{
     186
    177187    if (!m_itemsToInstall.count()) {
    178188        m_ui.cancelButton->setEnabled(false);
     
    227237void InstallDialog::httpRequestFinished(int requestId, bool error)
    228238{
     239
    229240    if (requestId == m_docInfoId  && m_buffer) {       
    230241        m_ui.progressBar->hide();
     
    297308void InstallDialog::installFile(const QString &fileName)
    298309{
     310
    299311    if (m_helpEngine->registerDocumentation(fileName)) {
    300312        m_installedDocumentations
     
    309321void InstallDialog::readResponseHeader(const QHttpResponseHeader &responseHeader)
    310322{
     323
    311324    if (responseHeader.statusCode() != 200) {
    312325        QMessageBox::information(this, m_windowTitle,
     
    322335void InstallDialog::updateDataReadProgress(int bytesRead, int totalBytes)
    323336{
     337
    324338    if (m_httpAborted)
    325339        return;
     
    331345void InstallDialog::browseDirectories()
    332346{
     347
    333348    QString dir = QFileDialog::getExistingDirectory(this, m_windowTitle,
    334349        m_ui.pathLineEdit->text());
  • trunk/tools/assistant/tools/assistant/installdialog.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6262
    6363public:
    64     InstallDialog(QHelpEngineCore *helpEngine, QWidget *parent = 0,
     64    InstallDialog(QHelpEngineCore *helpEngine, QWidget *parent = 0,
    6565        const QString &host = QString(), int port = -1);
    6666    ~InstallDialog();
  • trunk/tools/assistant/tools/assistant/main.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include <QtCore/QDir>
    4344#include <QtCore/QFileInfo>
     45
    4446#include <QtCore/QLocale>
     47
     48
    4549#include <QtCore/QTranslator>
    46 #include <QtCore/QLibraryInfo>
    4750#include <QtCore/QUrl>
    48 #include <QtCore/QStringList>
    4951
    5052#include <QtGui/QApplication>
    5153#include <QtGui/QDesktopServices>
    5254
    53 #include <QtHelp/QHelpEngineCore>
     55#include <QtHelp/QHelpEngine>
     56#include <QtHelp/QHelpSearchEngine>
    5457
    5558#include <QtNetwork/QLocalSocket>
     
    5760#include <QtSql/QSqlDatabase>
    5861
     62
     63
    5964#include "mainwindow.h"
    6065#include "cmdlineparser.h"
     66
     67
    6168
    6269QT_USE_NAMESPACE
     
    6774#endif
    6875
     76
     77
    6978void
    7079updateLastPagesOnUnregister(QHelpEngineCore& helpEngine, const QString& nsName)
    7180{
    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);
    8684    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);
    9588
    9689        for (int i = currentPages.count(); --i >= 0;) {
    9790            if (QUrl(currentPages.at(i)).host() == nsName) {
    98                 zoomList.remove(i);
     91                zoomList.remove(i);
    9992                currentPages.removeAt(i);
    10093                lastPage = (lastPage == (i + 1)) ? 1 : lastPage;
     
    10295        }
    10396
    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        );
    107100    }
    108101}
     
    111104updateUserCollection(QHelpEngineCore& user, const QHelpEngineCore& caller)
    112105{
    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))
    119108        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);
    160110    return true;
    161111}
    162112
    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;
     113void 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    }
    177122}
    178123
    179124QString indexFilesFolder(const QString &collectionFile)
    180125{
     126
    181127    QString indexFilesFolder = QLatin1String(".fulltextsearch");
    182128    if (!collectionFile.isEmpty()) {
     
    188134}
    189135
    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 */
     141QString 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
     155bool 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
     190bool 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
     210bool 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
     228bool 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.
    194234    const char * cmdModeArgs[] = {
    195         "-help", "-register", "-unregister", "-remove-search-index"
     235        "-help", "-register", "-unregister", "-remove-search-index",
     236        "-rebuild-search-index"
    196237    };
    197     bool useGui = true;
    198238    for (int i = 1; i < argc; ++i) {
    199239        for (size_t j = 0; j < sizeof cmdModeArgs/sizeof *cmdModeArgs; ++j) {
    200240            if(strcmp(argv[i], cmdModeArgs[j]) == 0) {
    201                 useGui = false;
     241                ui = false;
    202242                break;
    203243            }
    204244        }
    205245    }
    206     QApplication a(argc, argv, useGui);
    207246#else
    208     QApplication a(argc, argv);
     247    Q_UNUSED(argc)
     248    Q_UNUSED(argv)
    209249#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
    210318    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();
    214324    if (res == CmdLineParser::Help)
    215325        return 0;
     
    217327        return -1;
    218328
    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
    220374    if (cmd.registerRequest() != CmdLineParser::None) {
    221         if (cmdCollectionFile.isEmpty())
    222             cmdCollectionFile = MainWindow::defaultHelpCollectionFileName();
    223         QHelpEngineCore help(cmdCollectionFile);
    224         help.setupData();
     375       
     376            c();
     377       
     378        );
    225379        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        }
    251398    }
    252399
    253400    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;
    345415    }
    346416
    347417    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();
    376428    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  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "mainwindow.h"
     44
     45
    4346#include "centralwidget.h"
    44 #include "helpviewer.h"
    4547#include "indexwindow.h"
    4648#include "topicchooser.h"
    4749#include "contentwindow.h"
    4850#include "preferencesdialog.h"
    49 #include "bookmarkmanager.h"
     51#include "er.h"
    5052#include "remotecontrol.h"
    5153#include "cmdlineparser.h"
     
    5456#include "qtdocinstaller.h"
    5557
     58
     59
    5660#include <QtCore/QDir>
    5761#include <QtCore/QTimer>
     62
    5863#include <QtCore/QDebug>
     64
     65
    5966#include <QtCore/QResource>
    6067#include <QtCore/QByteArray>
     
    7784#include <QtGui/QDesktopServices>
    7885#include <QtGui/QToolButton>
    79 
    80 #include <QtHelp/QHelpEngine>
     86#include <QtGui/QFileDialog>
     87
     88#include <QtHelp/QHelpEngineCore>
    8189#include <QtHelp/QHelpSearchEngine>
    8290#include <QtHelp/QHelpContentModel>
     
    8795MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
    8896    : QMainWindow(parent)
     97
    8998    , m_filterCombo(0)
    9099    , m_toolBarMenu(0)
     
    94103    , m_connectedInitSignals(false)
    95104{
     105
     106
    96107    setToolButtonStyle(Qt::ToolButtonFollowStyle);
    97108
     109
    98110    if (usesDefaultCollection()) {
    99111        MainWindow::collectionFileDirectory(true);
    100         m_helpEngine = new QHelpEngine(MainWindow::defaultHelpCollectionFileName(),
    101             this);
     112        collectionFile = MainWindow::defaultHelpCollectionFileName();
    102113    } 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);
    107120    setCentralWidget(m_centralWidget);
    108121
    109     m_indexWindow = new IndexWindow(m_helpEngine);
     122    m_indexWindow = new IndexWindow();
    110123    QDockWidget *indexDock = new QDockWidget(tr("Index"), this);
    111124    indexDock->setObjectName(QLatin1String("IndexWindow"));
     
    113126    addDockWidget(Qt::LeftDockWidgetArea, indexDock);
    114127
    115     m_contentWindow = new ContentWindow(m_helpEngine);
     128    m_contentWindow = new ContentWindow;
    116129    QDockWidget *contentDock = new QDockWidget(tr("Contents"), this);
    117130    contentDock->setObjectName(QLatin1String("ContentWindow"));
     
    119132    addDockWidget(Qt::LeftDockWidgetArea, contentDock);
    120133
    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();
    127152    connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted()));
    128153    connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished()));
     
    137162    statusBar()->show();
    138163
    139     if (initHelpDB()) {
     164    if (initHelpDB()) {
    140165        setupFilterToolbar();
    141166        setupAddressToolbar();
    142167
    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();
    155171        if (iconArray.size() > 0) {
    156172            QPixmap pix;
     
    166182        // on x11.
    167183        show();
    168         QByteArray ba(m_helpEngine->customValue(QLatin1String("MainWindow")).toByteArray());
     184        QByteArray ba(());
    169185        if (!ba.isEmpty())
    170186            restoreState(ba);
    171187
    172         ba = m_helpEngine->customValue(QLatin1String("MainWindowGeometry")).toByteArray();
     188        ba = y();
    173189        if (!ba.isEmpty()) {
    174190            restoreGeometry(ba);
    175191        } else {
    176192            tabifyDockWidget(contentDock, indexDock);
    177             tabifyDockWidget(indexDock, bookmarkDock);
     193            if (bookmarkDock)
     194                tabifyDockWidget(indexDock, bookmarkDock);
    178195            contentDock->raise();
    179196            resize(QSize(800, 600));
    180197        }
    181198
    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);
    191206        } else {
    192207            updateApplicationFont();
     
    197212        QTimer::singleShot(0, this, SLOT(insertLastPages()));
    198213        if (m_cmdLine->enableRemoteControl())
    199             (void)new RemoteControl(this, m_helpEngine);
     214            (void)new RemoteControl(this);
    200215
    201216        if (m_cmdLine->contents() == CmdLineParser::Show)
     
    210225
    211226        if (m_cmdLine->bookmarks() == CmdLineParser::Show)
    212             showBookmarks();
     227            showBookmarks();
    213228        else if (m_cmdLine->bookmarks() == CmdLineParser::Hide)
    214             hideBookmarks();
     229            hideBookmarks();
    215230
    216231        if (m_cmdLine->search() == CmdLineParser::Show)
     
    224239            showIndex();
    225240        else if (m_cmdLine->bookmarks() == CmdLineParser::Activate)
    226             showBookmarks();
     241            showBookmarks();
    227242
    228243        if (!m_cmdLine->currentFilter().isEmpty()) {
    229244            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);
    232247        }
    233248
     
    236251        else
    237252            checkInitState();
     253
     254
     255
     256
     257
    238258    }
    239259    setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
     
    242262MainWindow::~MainWindow()
    243263{
     264
    244265    if (m_qtDocInstaller)
    245266        delete m_qtDocInstaller;
     
    248269bool MainWindow::usesDefaultCollection() const
    249270{
     271
    250272    return m_cmdLine->collectionFile().isEmpty();
    251273}
     
    253275void MainWindow::closeEvent(QCloseEvent *e)
    254276{
    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());
    260281    QMainWindow::closeEvent(e);
    261282}
    262283
    263 bool MainWindow::initHelpDB()
    264 {
    265     if (!m_helpEngine->setupData())
     284bool MainWindow::initHelpDB(bool registerInternalDoc)
     285{
     286    TRACE_OBJ
     287    HelpEngineWrapper &helpEngineWrapper = HelpEngineWrapper::instance();
     288    if (!helpEngineWrapper.setupData())
    266289        return false;
    267290
     291
     292
     293
     294
     295
    268296    bool assistantInternalDocRegistered = false;
    269297    QString intern(QLatin1String("com.trolltech.com.assistantinternal-"));
    270     foreach (const QString &ns, m_helpEngine->registeredDocumentations()) {
     298    foreach (const QString &ns, registeredDocumentations()) {
    271299        if (ns.startsWith(intern)) {
    272300            intern = ns;
     
    276304    }
    277305
    278     const QString &collectionFile = m_helpEngine->collectionFile();
    279 
     306    const QString &collectionFile = helpEngineWrapper.collectionFile();
    280307    QFileInfo fi(collectionFile);
    281308    QString helpFile;
     
    294321            file.close();
    295322        }
    296         QHelpEngineCore hc(fi.absoluteFilePath());
    297         hc.setupData();
    298         hc.unregisterDocumentation(intern);
    299         hc.registerDocumentation(helpFile);
     323        helpEngineWrapper.unregisterDocumentation(intern);
     324        helpEngineWrapper.registerDocumentation(helpFile);
    300325        needsSetup = true;
    301326    }
    302327
    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 
    318328    if (needsSetup)
    319         m_helpEngine->setupData();
     329        setupData();
    320330    return true;
    321331}
     
    323333void MainWindow::lookForNewQtDocumentation()
    324334{
    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);
    328348    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)
    334355        statusBar()->showMessage(tr("Looking for Qt Documentation..."));
    335356    m_qtDocInstaller->installDocs();
    336357}
    337358
    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();
     359void MainWindow::qtDocumentationInstalled()
     360{
     361    TRACE_OBJ
    347362    statusBar()->clearMessage();
    348363    checkInitState();
     
    351366void MainWindow::checkInitState()
    352367{
     368
     369
    353370    if (!m_cmdLine->enableRemoteControl())
    354371        return;
    355372
    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()) {
    358376        if (!m_connectedInitSignals) {
    359             connect(m_helpEngine->contentModel(), SIGNAL(contentsCreated()),
     377            connect(contentModel(), SIGNAL(contentsCreated()),
    360378                this, SLOT(checkInitState()));
    361             connect(m_helpEngine->indexModel(), SIGNAL(indexCreated()), this,
     379            connect(indexModel(), SIGNAL(indexCreated()), this,
    362380                SLOT(checkInitState()));
    363381            m_connectedInitSignals = true;
     
    365383    } else {
    366384        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);
    369387        }
    370388        emit initDone();
     
    372390}
    373391
    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 
    397392void MainWindow::insertLastPages()
    398393{
     394
    399395    if (m_cmdLine->url().isValid())
    400396        m_centralWidget->setSource(m_cmdLine->url());
     
    408404void MainWindow::setupActions()
    409405{
     406
    410407    QString resourcePath = QLatin1String(":/trolltech/assistant/images/");
    411408#ifdef Q_OS_MAC
     
    418415    QMenu *menu = menuBar()->addMenu(tr("&File"));
    419416
     417
     418
     419
     420
     421
    420422    m_pageSetupAction = menu->addAction(tr("Page Set&up..."), m_centralWidget,
    421423        SLOT(pageSetup()));
     
    430432    menu->addSeparator();
    431433
    432     m_newTabAction = menu->addAction(tr("New &Tab"), m_centralWidget, SLOT(newTab()));
    433     m_newTabAction->setShortcut(QKeySequence::AddTab);
    434 
    435434    m_closeTabAction = menu->addAction(tr("&Close Tab"), m_centralWidget,
    436435        SLOT(closeTab()));
    437436    m_closeTabAction->setShortcuts(QKeySequence::Close);
    438437
    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
    440444    tmp->setShortcut(QKeySequence::Quit);
    441     tmp->setMenuRole(QAction::QuitRole);
     445#endif
    442446
    443447    menu = menuBar()->addMenu(tr("&Edit"));
     
    493497    m_viewMenu->addAction(tr("Index"), this, SLOT(showIndex()),
    494498        QKeySequence(tr("ALT+I")));
    495     m_viewMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarks()),
     499    m_viewMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarks()),
    496500        QKeySequence(tr("ALT+O")));
    497501    m_viewMenu->addAction(tr("Search"), this, SLOT(showSearchWidget()),
     
    529533        << QKeySequence(Qt::CTRL + Qt::Key_PageUp));
    530534
    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")));
    535537
    536538    menu = menuBar()->addMenu(tr("&Help"));
     
    539541
    540542#ifdef Q_WS_X11
     543
     544
    541545    m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon()));
    542546    m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon()));
     
    548552    m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon()));
    549553    m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon()));
     554
     555
    550556    m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon()));
     557
    551558#endif
    552559
     
    593600    connect(m_centralWidget, SIGNAL(highlighted(QString)), statusBar(),
    594601        SLOT(showMessage(QString)));
    595     connect(m_centralWidget, SIGNAL(addNewBookmark(QString,QString)), this,
    596         SLOT(addNewBookmark(QString,QString)));
    597 
    598     // bookmarks
    599     connect(m_bookmarkWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
    600         SLOT(setSource(QUrl)));
    601     connect(m_bookmarkWidget, SIGNAL(escapePressed()), this,
    602         SLOT(activateCurrentCentralWidgetTab()));
    603602
    604603    // index window
     
    625624QMenu *MainWindow::toolBarMenu()
    626625{
     626
    627627    if (!m_toolBarMenu) {
    628628        m_viewMenu->addSeparator();
     
    634634void MainWindow::setupFilterToolbar()
    635635{
    636     if (!m_helpEngine->
    637             customValue(QLatin1String("EnableFilterFunctionality"), true).toBool())
     636    TRACE_OBJ
     637    HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
     638    if (!helpEngine.filterFunctionalityEnabled())
    638639        return;
    639640
     
    648649    filterToolBar->addWidget(m_filterCombo);
    649650
    650     const QLatin1String hideFilter("HideFilterFunctionality");
    651     if (m_helpEngine->customValue(hideFilter, true).toBool())
     651    if (!helpEngine.filterToolbarVisible())
    652652        filterToolBar->hide();
    653653    toolBarMenu()->addAction(filterToolBar->toggleViewAction());
    654654
    655     connect(m_helpEngine, SIGNAL(setupFinished()), this,
    656         SLOT(setupFilterCombo()));
     655    connect(helpEngine, SIGNAL(setupFinished()), this,
     656        SLOT(setupFilterCombo()));
    657657    connect(m_filterCombo, SIGNAL(activated(QString)), this,
    658658        SLOT(filterDocumentation(QString)));
    659     connect(m_helpEngine, SIGNAL(currentFilterChanged(QString)), this,
     659    connect(helpEngine, SIGNAL(currentFilterChanged(QString)), this,
    660660        SLOT(currentFilterChanged(QString)));
    661661
     
    665665void MainWindow::setupAddressToolbar()
    666666{
    667     if (!m_helpEngine->customValue(QLatin1String("EnableAddressBar"), true).toBool())
     667    TRACE_OBJ
     668    HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
     669    if (!helpEngine.addressBarEnabled())
    668670        return;
    669671
     
    677679    addressToolBar->addWidget(m_addressLineEdit);
    678680
    679     if (m_helpEngine->customValue(QLatin1String("HideAddressBar"), true).toBool())
     681    if (())
    680682        addressToolBar->hide();
    681683    toolBarMenu()->addAction(addressToolBar->toggleViewAction());
     
    692694void MainWindow::updateAboutMenuText()
    693695{
    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;
    715715            }
    716             if (!trStr.isEmpty())
    717                 m_aboutAction->setText(trStr);
    718716        }
     717
     718
    719719    }
    720720}
     
    722722void MainWindow::showNewAddress()
    723723{
     724
    724725    showNewAddress(m_centralWidget->currentSource());
    725726}
     
    727728void MainWindow::showNewAddress(const QUrl &url)
    728729{
     730
    729731    m_addressLineEdit->setText(url.toString());
    730732}
    731733
    732 void MainWindow::addBookmark()
    733 {
    734     addNewBookmark(m_centralWidget->currentTitle(),
    735         m_centralWidget->currentSource().toString());
    736 }
    737 
    738734void MainWindow::gotoAddress()
    739735{
     736
    740737    m_centralWidget->setSource(m_addressLineEdit->text());
    741738}
     
    743740void MainWindow::updateNavigationItems()
    744741{
     742
    745743    bool hasCurrentViewer = m_centralWidget->isHomeAvailable();
    746744    m_copyAction->setEnabled(m_centralWidget->hasSelection());
     
    756754void MainWindow::updateTabCloseAction()
    757755{
     756
    758757    m_closeTabAction->setEnabled(m_centralWidget->enableTabCloseAction());
    759758}
     
    762761                                  const QString &keyword)
    763762{
     763
    764764    TopicChooser tc(this, keyword, links);
    765765    if (tc.exec() == QDialog::Accepted) {
     
    770770void MainWindow::showPreferences()
    771771{
    772     PreferencesDialog dia(m_helpEngine, this);
    773 
     772   
     773    PreferencesDialog dia(this);
    774774    connect(&dia, SIGNAL(updateApplicationFont()), this,
    775775        SLOT(updateApplicationFont()));
    776776    connect(&dia, SIGNAL(updateBrowserFont()), m_centralWidget,
    777777        SLOT(updateBrowserFont()));
    778 
    779778    dia.showDialog();
    780779}
     
    782781void MainWindow::syncContents()
    783782{
     783
    784784    qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
    785785    const QUrl url = m_centralWidget->currentSource();
     
    793793void MainWindow::copyAvailable(bool yes)
    794794{
     795
    795796    m_copyAction->setEnabled(yes);
    796797}
    797798
    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 
    806799void MainWindow::showAboutDialog()
    807800{
     801
     802
    808803    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;
    829821            }
    830822        }
     
    835827    QByteArray iconArray;
    836828    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();
    842831        QPixmap pix;
    843832        pix.loadFromData(iconArray);
     
    848837    } else {
    849838        QByteArray resources;
    850         aboutDia.setText(QString::fromLatin1("<center>"
     839        aboutDia.setText(("<center>"
    851840            "<h3>%1</h3>"
    852841            "<p>Version %2</p></center>"
    853             "<p>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).</p>")
     842            "<p>Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).</p>")
    854843            .arg(tr("Qt Assistant")).arg(QLatin1String(QT_VERSION_STR)),
    855844            resources);
     
    862851}
    863852
     853
     854
     855
     856
     857
     858
     859
     860
     861
    864862void MainWindow::showContents()
    865863{
     864
    866865    activateDockWidget(m_contentWindow);
    867866}
    868867
     868
     869
     870
     871
     872
     873
     874
     875
     876
     877
     878
     879
     880
     881
     882
    869883void MainWindow::showIndex()
    870884{
     885
    871886    activateDockWidget(m_indexWindow);
    872887}
    873888
    874 void MainWindow::showBookmarks()
    875 {
    876     activateDockWidget(m_bookmarkWidget);
     889void MainWindow::hideIndex()
     890{
     891    TRACE_OBJ
     892    m_indexWindow->parentWidget()->hide();
     893}
     894
     895void MainWindow::setBookmarksVisible(bool visible)
     896{
     897    TRACE_OBJ
     898    if (visible)
     899        showBookmarksDockWidget();
     900    else
     901        hideBookmarksDockWidget();
     902}
     903
     904void MainWindow::showBookmarksDockWidget()
     905{
     906    TRACE_OBJ
     907    if (m_bookmarkWidget)
     908        activateDockWidget(m_bookmarkWidget);
     909}
     910
     911void MainWindow::hideBookmarksDockWidget()
     912{
     913    TRACE_OBJ
     914    if (m_bookmarkWidget)
     915        m_bookmarkWidget->parentWidget()->hide();
     916}
     917
     918void MainWindow::setSearchVisible(bool visible)
     919{
     920    TRACE_OBJ
     921    if (visible)
     922        showSearch();
     923    else
     924        hideSearch();
     925}
     926
     927void MainWindow::showSearch()
     928{
     929    TRACE_OBJ
     930    m_centralWidget->activateSearchWidget();
     931}
     932
     933void MainWindow::hideSearch()
     934{
     935    TRACE_OBJ
     936    m_centralWidget->removeSearchWidget();
    877937}
    878938
    879939void MainWindow::activateDockWidget(QWidget *w)
    880940{
     941
    881942    w->parentWidget()->show();
    882943    w->parentWidget()->raise();
     
    884945}
    885946
    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 
    901947void MainWindow::setIndexString(const QString &str)
    902948{
     949
    903950    m_indexWindow->setSearchLineEditText(str);
    904951}
     
    906953void MainWindow::activateCurrentBrowser()
    907954{
     955
    908956    CentralWidget *cw = CentralWidget::instance();
    909957    if (cw) {
     
    914962void MainWindow::activateCurrentCentralWidgetTab()
    915963{
     964
    916965    m_centralWidget->activateTab();
    917966}
    918967
    919 void MainWindow::showSearch()
    920 {
    921     m_centralWidget->activateSearchWidget();
    922 }
    923 
    924968void MainWindow::showSearchWidget()
    925969{
     970
    926971    m_centralWidget->activateSearchWidget(true);
    927972}
    928973
    929 void MainWindow::hideSearch()
    930 {
    931     m_centralWidget->removeSearchWidget();
    932 }
    933 
    934974void MainWindow::updateApplicationFont()
    935975{
     976
     977
    936978    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);
    941985}
    942986
    943987void MainWindow::setupFilterCombo()
    944988{
     989
     990
    945991    QString curFilter = m_filterCombo->currentText();
    946992    if (curFilter.isEmpty())
    947         curFilter = m_helpEngine->currentFilter();
     993        curFilter = currentFilter();
    948994    m_filterCombo->clear();
    949     m_filterCombo->addItems(m_helpEngine->customFilters());
     995    m_filterCombo->addItems(customFilters());
    950996    int idx = m_filterCombo->findText(curFilter);
    951997    if (idx < 0)
     
    9561002void MainWindow::filterDocumentation(const QString &customFilter)
    9571003{
    958     m_helpEngine->setCurrentFilter(customFilter);
     1004    TRACE_OBJ
     1005    HelpEngineWrapper::instance().setCurrentFilter(customFilter);
    9591006}
    9601007
    9611008void MainWindow::expandTOC(int depth)
    9621009{
     1010
     1011
    9631012    m_contentWindow->expandToDepth(depth);
    9641013}
     
    9661015void MainWindow::indexingStarted()
    9671016{
     1017
    9681018    if (!m_progressWidget) {
    9691019        m_progressWidget = new QWidget();
     
    9911041void MainWindow::indexingFinished()
    9921042{
     1043
    9931044    statusBar()->removeWidget(m_progressWidget);
    9941045    delete m_progressWidget;
     
    9961047}
    9971048
    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 
    10061049QString MainWindow::collectionFileDirectory(bool createDir, const QString &cacheDir)
    10071050{
     1051
    10081052    QString collectionPath =
    10091053        QDesktopServices::storageLocation(QDesktopServices::DataLocation);
     
    10311075QString MainWindow::defaultHelpCollectionFileName()
    10321076{
    1033     return collectionFileDirectory() + QDir::separator() +
     1077    TRACE_OBJ
     1078    // forces creation of the default collection file path
     1079    return collectionFileDirectory(true) + QDir::separator() +
    10341080        QString(QLatin1String("qthelpcollection_%1.qhc")).
    10351081        arg(QLatin1String(QT_VERSION_STR));
     
    10381084void MainWindow::currentFilterChanged(const QString &filter)
    10391085{
     1086
    10401087    const int index = m_filterCombo->findText(filter);
    10411088    Q_ASSERT(index != -1);
     
    10431090}
    10441091
     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
    10451138QT_END_NAMESPACE
  • trunk/tools/assistant/tools/assistant/mainwindow.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4949
    5050class QAction;
     51
    5152class QLineEdit;
    5253class QComboBox;
     
    5859class CentralWidget;
    5960class ContentWindow;
    60 class BookmarkManager;
    61 class BookmarkWidget;
    6261class CmdLineParser;
    6362class QtDocInstaller;
     
    6867
    6968public:
    70     MainWindow(CmdLineParser *cmdLine, QWidget *parent = 0);
     69    MainWindow(CmdLineParser *cmdLine, QWidget *parent = 0);
    7170    ~MainWindow();
    7271
     
    7776
    7877public:
    79     void hideContents();
    80     void hideIndex();
    81     void hideBookmarks();
    82     void hideSearch();
    8378    void setIndexString(const QString &str);
    8479    void expandTOC(int depth);
     
    8984
    9085public slots:
    91     void showContents();
    92     void showIndex();
    93     void showBookmarks();
    94     void showSearch();
     86    void s);
     87    void s);
     88    void s);
     89    void s);
    9590    void showSearchWidget();
    9691    void syncContents();
     
    9994
    10095private slots:
     96
     97
     98
    10199    void insertLastPages();
    102     void addBookmark();
    103100    void gotoAddress();
    104101    void showPreferences();
     
    109106    void updateTabCloseAction();
    110107    void showNewAddress(const QUrl &url);
    111     void addNewBookmark(const QString &title, const QString &url);
    112108    void showTopicChooser(const QMap<QString, QUrl> &links, const QString &keyword);
    113109    void updateApplicationFont();
     
    117113    void indexingStarted();
    118114    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);
    121119    void checkInitState();
    122 
    123     void updateBookmarkMenu();
    124     void showBookmark(QAction *action);
     120    void documentationRemoved(const QString &namespaceName);
     121    void documentationUpdated(const QString &namespaceName);
    125122
    126123private:
    127     bool initHelpDB();
     124    bool initHelpDB();
    128125    void setupActions();
    129126    void closeEvent(QCloseEvent *e);
     
    133130    void setupAddressToolbar();
    134131    QMenu *toolBarMenu();
    135     QWidget *setupBookmarkWidget();
     132    void hideContents();
     133    void hideIndex();
     134    void hideSearch();
    136135
    137     QHelpEngine *m_helpEngine;
     136private slots:
     137    void showBookmarksDockWidget();
     138    void hideBookmarksDockWidget();
     139
     140private:
     141    QWidget *m_bookmarkWidget;
     142
     143private:
    138144    CentralWidget *m_centralWidget;
    139145    IndexWindow *m_indexWindow;
    140146    ContentWindow *m_contentWindow;
    141     BookmarkWidget *m_bookmarkWidget;
    142     BookmarkManager *m_bookmarkManager;
    143147    QLineEdit *m_addressLineEdit;
    144148    QComboBox *m_filterCombo;
     
    162166    QMenu *m_viewMenu;
    163167    QMenu *m_toolBarMenu;
    164     QMenu *m_bookmarkMenu;
    165     QAction *m_bookmarkMenuAction;
    166168
    167169    CmdLineParser *m_cmdLine;
  • trunk/tools/assistant/tools/assistant/preferencesdialog.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
    41 
    4241#include "preferencesdialog.h"
     42
     43
    4344#include "filternamedialog.h"
     45
     46
    4447#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>
    5156#include <QtGui/QHeaderView>
    52 #include <QtGui/QFileDialog>
     57#include <QtGui/Q>
    5358#include <QtGui/QMessageBox>
    54 #include <QtGui/QMenu>
    55 #include <QtGui/QFontDatabase>
    56 #include <QtGui/QApplication>
    57 #include <QtGui/QDesktopWidget>
    5859
    5960#include <QtHelp/QHelpEngineCore>
     
    6162QT_BEGIN_NAMESPACE
    6263
    63 PreferencesDialog::PreferencesDialog(QHelpEngineCore *helpEngine, QWidget *parent)
     64PreferencesDialog::PreferencesDialog(QWidget *parent)
    6465    : QDialog(parent)
    65     , m_helpEngine(helpEngine)
    6666    , m_appFontChanged(false)
    6767    , m_browserFontChanged(false)
    68 {
     68    , helpEngine(HelpEngineWrapper::instance())
     69{
     70    TRACE_OBJ
    6971    m_ui.setupUi(this);
    7072
     
    7476        this, SLOT(reject()));
    7577
    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();
    8180
    8281    if (!m_hideFiltersTab) {
     
    107106            SLOT(removeDocumentation()));
    108107
    109         m_docsBackup = m_helpEngine->registeredDocumentations();
     108        m_docsBackup = registeredDocumentations();
    110109        m_ui.registeredDocsListWidget->addItems(m_docsBackup);
    111110    } else {
     
    115114    updateFontSettingsPage();
    116115    updateOptionsPage();
     116
     117
     118
    117119}
    118120
    119121PreferencesDialog::~PreferencesDialog()
    120122{
    121     QLatin1String key("");
     123   
    122124    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();
    131129    }
    132130
    133131    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());
    146135        emit updateBrowserFont();
    147136    }
     
    150139    if (homePage.isEmpty())
    151140        homePage = QLatin1String("help");
    152     m_helpEngine->setCustomValue(QLatin1String("homepage"), homePage);
     141    homePage);
    153142
    154143    int option = m_ui.helpStartComboBox->currentIndex();
    155     m_helpEngine->setCustomValue(QLatin1String("StartOption"), option);
     144    option);
    156145}
    157146
    158147void PreferencesDialog::showDialog()
    159148{
     149
    160150    if (exec() != Accepted)
    161151        m_appFontChanged = m_browserFontChanged = false;
     
    164154void PreferencesDialog::updateFilterPage()
    165155{
    166     if (!m_helpEngine)
    167         return;
    168 
     156    TRACE_OBJ
    169157    m_ui.filterWidget->clear();
    170158    m_ui.attributeWidget->clear();
    171159
    172     QHelpEngineCore help(m_helpEngine->collectionFile(), 0);
    173     help.setupData();
    174160    m_filterMapBackup.clear();
    175     const QStringList filters = help.customFilters();
     161    const QStringList .customFilters();
    176162    foreach (const QString &filter, filters) {
    177         QStringList atts = help.filterAttributes(filter);
     163        if (filter == HelpEngineWrapper::TrUnfiltered)
     164            continue;
     165        QStringList atts = helpEngine.filterAttributes(filter);
    178166        m_filterMapBackup.insert(filter, atts);
    179167        if (!m_filterMap.contains(filter))
     
    183171    m_ui.filterWidget->addItems(m_filterMap.keys());
    184172
    185     foreach (const QString &a, help.filterAttributes())
     173    foreach (const QString &a, help.filterAttributes())
    186174        new QTreeWidgetItem(m_ui.attributeWidget, QStringList() << a);
    187175
    188     if (m_filterMap.keys().count())
     176    if (())
    189177        m_ui.filterWidget->setCurrentRow(0);
    190178}
     
    192180void PreferencesDialog::updateAttributes(QListWidgetItem *item)
    193181{
     182
    194183    QStringList checkedList;
    195184    if (item)
     
    207196void PreferencesDialog::updateFilterMap()
    208197{
     198
    209199    if (!m_ui.filterWidget->currentItem())
    210200        return;
     
    225215void PreferencesDialog::addFilter()
    226216{
     217
    227218    FilterNameDialog dia(this);
    228219    if (dia.exec() == QDialog::Rejected)
     
    242233void PreferencesDialog::removeFilter()
    243234{
     235
    244236    QListWidgetItem *item =
    245237        m_ui.filterWidget ->takeItem(m_ui.filterWidget->currentRow());
     
    256248void PreferencesDialog::addDocumentationLocal()
    257249{
     250
    258251    const QStringList fileNames = QFileDialog::getOpenFileNames(this,
    259252        tr("Add Documentation"), QString(), tr("Qt Compressed Help Files (*.qch)"));
     
    276269        }
    277270
    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        }
    282276    }
    283277
     
    308302void PreferencesDialog::removeDocumentation()
    309303{
     304
    310305    bool foundBefore = false;
    311306    CentralWidget* widget = CentralWidget::instance();
     
    339334void PreferencesDialog::applyChanges()
    340335{
     336
    341337    bool filtersWereChanged = false;
    342338    if (!m_hideFiltersTab) {
     
    371367    if (filtersWereChanged) {
    372368        foreach (const QString &filter, m_removedFilters)
    373             m_helpEngine->removeCustomFilter(filter);
     369            removeCustomFilter(filter);
    374370        QMapIterator<QString, QStringList> it(m_filterMap);
    375371        while (it.hasNext()) {
    376372            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();
    395384
    396385    accept();
     
    399388void PreferencesDialog::updateFontSettingsPage()
    400389{
     390
    401391    m_browserFontPanel = new FontPanel(this);
    402392    m_browserFontPanel->setCheckable(true);
     
    412402    m_appFontPanel->setTitle(customSettings);
    413403
    414     QLatin1String key = QLatin1String("appFont");
    415     QFont font = qVariantValue<QFont>(m_helpEngine->customValue(key));
     404    QFont font = helpEngine.appFont();
    416405    m_appFontPanel->setSelectedFont(font);
    417406
    418     key = QLatin1String("appWritingSystem");
    419     QFontDatabase::WritingSystem system = static_cast<QFontDatabase::WritingSystem>
    420         (m_helpEngine->customValue(key).toInt());
     407    QFontDatabase::WritingSystem system = helpEngine.appWritingSystem();
    421408    m_appFontPanel->setWritingSystem(system);
    422409
    423     key = QLatin1String("useAppFont");
    424     m_appFontPanel->setChecked(m_helpEngine->customValue(key).toBool());
     410    m_appFontPanel->setChecked(helpEngine.usesAppFont());
    425411
    426412    m_browserFontPanel->setTitle(customSettings);
    427413
    428     key = QLatin1String("browserFont");
    429     font = qVariantValue<QFont>(m_helpEngine->customValue(key));
     414    font = helpEngine.browserFont();
    430415    m_browserFontPanel->setSelectedFont(font);
    431416
    432     key = QLatin1String("browserWritingSystem");
    433     system = static_cast<QFontDatabase::WritingSystem>
    434         (m_helpEngine->customValue(key).toInt());
     417    system = helpEngine.browserWritingSystem();
    435418    m_browserFontPanel->setWritingSystem(system);
    436419
    437     key = QLatin1String("useBrowserFont");
    438     m_browserFontPanel->setChecked(m_helpEngine->customValue(key).toBool());
     420    m_browserFontPanel->setChecked(helpEngine.usesBrowserFont());
    439421
    440422    connect(m_appFontPanel, SIGNAL(toggled(bool)), this,
     
    458440void PreferencesDialog::appFontSettingToggled(bool on)
    459441{
     442
    460443    Q_UNUSED(on)
    461444    m_appFontChanged = true;
     
    464447void PreferencesDialog::appFontSettingChanged(int index)
    465448{
     449
    466450    Q_UNUSED(index)
    467451    m_appFontChanged = true;
     
    470454void PreferencesDialog::browserFontSettingToggled(bool on)
    471455{
     456
    472457    Q_UNUSED(on)
    473458    m_browserFontChanged = true;
     
    476461void PreferencesDialog::browserFontSettingChanged(int index)
    477462{
     463
    478464    Q_UNUSED(index)
    479465    m_browserFontChanged = true;
     
    482468void PreferencesDialog::updateOptionsPage()
    483469{
    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();
    495474    m_ui.helpStartComboBox->setCurrentIndex(option);
    496475
     
    502481void PreferencesDialog::setBlankPage()
    503482{
     483
    504484    m_ui.homePageLineEdit->setText(QLatin1String("about:blank"));
    505485}
     
    507487void PreferencesDialog::setCurrentPage()
    508488{
     489
    509490    QString homepage = CentralWidget::instance()->currentSource().toString();
    510491    if (homepage.isEmpty())
     
    516497void PreferencesDialog::setDefaultPage()
    517498{
    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());
    521501}
    522502
  • trunk/tools/assistant/tools/assistant/preferencesdialog.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4949
    5050class FontPanel;
    51 class QHelpEngineCore;
    52 
    53 enum {
    54     ShowHomePage = 0,
    55     ShowBlankPage = 1,
    56     ShowLastPages = 2
    57 };
     51class HelpEngineWrapper;
     52class QFileSystemWatcher;
    5853
    5954class PreferencesDialog : public QDialog
     
    6257
    6358public:
    64     PreferencesDialog(QHelpEngineCore *helpEngine, QWidget *parent = 0);
     59    PreferencesDialog(QWidget *parent = 0);
    6560    ~PreferencesDialog();
    6661
     
    9489
    9590    Ui::PreferencesDialogClass m_ui;
    96     QHelpEngineCore *m_helpEngine;
    9791    bool m_hideFiltersTab;
    9892    bool m_hideDocsTab;
     
    108102    bool m_appFontChanged;
    109103    bool m_browserFontChanged;
     104
    110105};
    111106
  • trunk/tools/assistant/tools/assistant/qtdocinstaller.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include <QtCore/QDir>
    4344#include <QtCore/QLibraryInfo>
    4445#include <QtCore/QDateTime>
     46
    4547#include <QtHelp/QHelpEngineCore>
     48
    4649#include "qtdocinstaller.h"
    4750
    4851QT_BEGIN_NAMESPACE
    4952
    50 QtDocInstaller::QtDocInstaller(const QString &collectionFile)
     53QtDocInstaller::QtDocInstaller(const QList<DocInfo> &docInfos)
     54    : m_abort(false), m_docInfos(docInfos)
    5155{
    52     m_abort = false;
    53     m_collectionFile = collectionFile;
     56    TRACE_OBJ
    5457}
    5558
    5659QtDocInstaller::~QtDocInstaller()
    5760{
     61
    5862    if (!isRunning())
    5963        return;
     
    6670void QtDocInstaller::installDocs()
    6771{
     72
    6873    start(LowPriority);
    6974}
     
    7176void QtDocInstaller::run()
    7277{
    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
    7583    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);
    8686        m_mutex.lock();
    8787        if (m_abort) {
    88             delete helpEngine;
    8988            m_mutex.unlock();
    9089            return;
     
    9291        m_mutex.unlock();
    9392    }
    94     delete helpEngine;
    9593    emit docsInstalled(changes);
    9694}
    9795
    98 bool QtDocInstaller::installDoc(const QString &name, QHelpEngineCore *helpEngine)
     96bool QtDocInstaller::installDoc(const )
    9997{
    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;
    106101    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);
    109104
    110105    QString qchFile;
    111     if (lst.count() == 2)
    112         qchFile = lst.last();
     106    if (.count() == 2)
     107        qchFile = .last();
    113108
    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);
    121111        return false;
    122112    }
    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().toString(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)
    127117                && qchFile == fi.absoluteFilePath())
    128118                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());
    145120            return true;
    146121        }
    147122    }
     123
     124
    148125    return false;
    149126}
  • trunk/tools/assistant/tools/assistant/qtdocinstaller.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4343#define QTDOCINSTALLER
    4444
     45
     46
     47
     48
    4549#include <QtCore/QThread>
    46 #include <QtCore/QMutex>
    4750
    4851QT_BEGIN_NAMESPACE
    4952
    50 class QHelpEngineCore;
     53class ;
    5154
    5255class QtDocInstaller : public QThread
     
    5558
    5659public:
    57     QtDocInstaller(const QString &collectionFile);
     60    typedef QPair<QString, QStringList> DocInfo;
     61    QtDocInstaller(const QList<DocInfo> &docInfos);
    5862    ~QtDocInstaller();
    5963    void installDocs();
    6064
    6165signals:
    62     void errorMessage(const QString &msg);
     66    void qchFileNotFound(const QString &component);
     67    void registerDocumentation(const QString &component,
     68                               const QString &absFileName);
    6369    void docsInstalled(bool newDocsInstalled);
    6470
    6571private:
    6672    void run();
    67     bool installDoc(const QString &name,
    68         QHelpEngineCore *helpEngine);
     73    bool installDoc(const DocInfo &docInfo);
    6974
    7075    bool m_abort;
    71     QString m_collectionFile;
    7276    QMutex m_mutex;
     77
     78
     79
    7380};
    7481
  • trunk/tools/assistant/tools/assistant/remotecontrol.cpp

    r701 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "remotecontrol.h"
    4344#include "mainwindow.h"
    4445#include "centralwidget.h"
     46
    4547
    4648#include <QtCore/QFile>
     49
     50
    4751#include <QtCore/QThread>
    4852#include <QtCore/QTextStream>
     
    6670    : QThread(parent)
    6771{
     72
    6873}
    6974
    7075StdInListenerWin::~StdInListenerWin()
    7176{
     77
    7278    terminate();
    7379    wait();
     
    7884void StdInListenerWin::run()
    7985{
     86
    8087    char chBuf[4096];
    8188    size_t pos = 0;
     
    121128void StdInListenerWin::run()
    122129{
     130
    123131    bool ok = true;
    124132    char chBuf[4096];
     
    145153
    146154    while (ok) {
    147         ok = ReadFile(hStdinDup, chBuf, 4096, &dwRead, NULL);
     155        ok = ReadFile(hStdinDup, chBuf, , &dwRead, NULL);
    148156        if (ok && dwRead != 0)
    149             emit receivedCommand(QString::fromLocal8Bit(chBuf));
     157            emit receivedCommand(QString::fromLocal8Bit(chBuf));
    150158    }
    151159}
     
    155163#endif // defined(Q_OS_WIN) || defined(Q_OS_OS2)
    156164
    157 RemoteControl::RemoteControl(MainWindow *mainWindow, QHelpEngine *helpEngine)
     165RemoteControl::RemoteControl(MainWindow *mainWindow)
    158166    : QObject(mainWindow)
    159167    , m_mainWindow(mainWindow)
    160     , m_helpEngine(helpEngine)
    161168    , m_debug(false)
    162169    , m_caching(true)
    163170    , m_syncContents(false)
    164     , m_expandTOC(-3)
    165 
    166 {
     171    , m_expandTOC(-2)
     172    , helpEngine(HelpEngineWrapper::instance())
     173
     174{
     175    TRACE_OBJ
    167176    connect(m_mainWindow, SIGNAL(initDone()), this, SLOT(applyCache()));
    168177#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
     
    181190void RemoteControl::receivedData()
    182191{
     192
    183193    QByteArray ba;
    184194    while (true) {
     
    196206void RemoteControl::handleCommandString(const QString &cmdString)
    197207{
     208
    198209    QStringList cmds = cmdString.split(QLatin1Char(';'));
    199210    QStringList::const_iterator it = cmds.constBegin();
    200     QString cmdLine, cmd, arg;
    201211    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);
    211214
    212215        if (m_debug)
     
    214217                tr("Received Command: %1 %2").arg(cmd).arg(arg));
    215218
    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
    299242            return;
    300         }
     243
    301244        ++it;
    302245    }
     
    305248}
    306249
     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
    307384void RemoteControl::applyCache()
    308385{
     386
    309387    if (m_setSource.isValid()) {
    310388        CentralWidget::instance()->setSource(m_setSource);
    311389    } else if (!m_activateKeyword.isEmpty()) {
    312390        m_mainWindow->setIndexString(m_activateKeyword);
    313         m_helpEngine->indexWidget()->activateCurrentItem();
     391        indexWidget()->activateCurrentItem();
    314392    } else if (!m_activateIdentifier.isEmpty()) {
    315393        QMap<QString, QUrl> links =
    316             m_helpEngine->linksForIdentifier(m_activateIdentifier);
    317         if (links.count())
     394            linksForIdentifier(m_activateIdentifier);
     395        if (())
    318396            CentralWidget::instance()->setSource(links.constBegin().value());
    319397    } else if (!m_currentFilter.isEmpty()) {
    320         m_helpEngine->setCurrentFilter(m_currentFilter);
     398        setCurrentFilter(m_currentFilter);
    321399    }
    322400
     
    324402        m_mainWindow->syncContents();
    325403
    326     if (m_expandTOC != -3)
     404    Q_ASSERT(m_expandTOC >= -2);
     405    if (m_expandTOC != -2)
    327406        m_mainWindow->expandTOC(m_expandTOC);
    328407
     
    332411void RemoteControl::clearCache()
    333412{
     413
    334414    m_currentFilter.clear();
    335415    m_setSource.clear();
  • trunk/tools/assistant/tools/assistant/remotecontrol.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4444
    4545#include <QtCore/QObject>
     46
    4647#include <QtCore/QUrl>
    4748
    4849QT_BEGIN_NAMESPACE
    4950
     51
    5052class MainWindow;
    51 class QHelpEngine;
    5253
    5354class RemoteControl : public QObject
     
    5657
    5758public:
    58     RemoteControl(MainWindow *mainWindow, QHelpEngine *helpEngine);
     59    RemoteControl(MainWindow *mainWindow);
    5960
    6061private slots:
     
    6566private:
    6667    void clearCache();
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
    6779
    6880private:
    6981    MainWindow *m_mainWindow;
    70     QHelpEngine *m_helpEngine;
    7182    bool m_debug;
    7283
     
    7889    int m_expandTOC;
    7990    QString m_currentFilter;
     91
    8092};
    8193
  • trunk/tools/assistant/tools/assistant/remotecontrol_win.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/assistant/searchwidget.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
     41
    4142
    4243#include "mainwindow.h"
     
    6667    , searchEngine(engine)
    6768{
     69
    6870    QVBoxLayout *vLayout = new QVBoxLayout(this);
    6971
     
    9294SearchWidget::~SearchWidget()
    9395{
     96
    9497    // nothing todo
    9598}
     
    97100void SearchWidget::zoomIn()
    98101{
     102
    99103    QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
    100104    if (browser && zoomCount != 10) {
     
    106110void SearchWidget::zoomOut()
    107111{
     112
    108113    QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
    109114    if (browser && zoomCount != -5) {
     
    115120void SearchWidget::resetZoom()
    116121{
     122
    117123    if (zoomCount == 0)
    118124        return;
     
    127133bool SearchWidget::isAttached() const
    128134{
     135
    129136    return attached;
    130137}
     
    132139void SearchWidget::setAttached(bool state)
    133140{
     141
    134142    attached = state;
    135143}
     
    137145void SearchWidget::search() const
    138146{
     147
    139148    QList<QHelpSearchQuery> query = searchEngine->queryWidget()->query();
    140149    searchEngine->search(query);
     
    143152void SearchWidget::searchingStarted()
    144153{
     154
    145155    qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
    146156}
     
    148158void SearchWidget::searchingFinished(int hits)
    149159{
     160
    150161    Q_UNUSED(hits)
    151162    qApp->restoreOverrideCursor();
     
    154165bool SearchWidget::eventFilter(QObject* o, QEvent *e)
    155166{
     167
    156168    QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
    157169    if (browser && o == browser->viewport()
     
    172184void SearchWidget::keyPressEvent(QKeyEvent *keyEvent)
    173185{
     186
    174187    if (keyEvent->key() == Qt::Key_Escape)
    175188        MainWindow::activateCurrentBrowser();
     
    180193void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
    181194{
     195
    182196    QMenu menu;
    183197    QPoint point = contextMenuEvent->globalPos();
  • trunk/tools/assistant/tools/assistant/searchwidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5959
    6060public:
    61     SearchWidget(QHelpSearchEngine *engine, QWidget *parent = 0);
     61    SearchWidget(QHelpSearchEngine *engine, QWidget *parent = 0);
    6262    ~SearchWidget();
    6363
  • trunk/tools/assistant/tools/assistant/topicchooser.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    3939**
    4040****************************************************************************/
    41 
    42 #include <QtCore/QMap>
    43 #include <QtCore/QUrl>
     41#include "tracer.h"
    4442
    4543#include "topicchooser.h"
     
    5149    : QDialog(parent)
    5250{
     51
    5352    ui.setupUi(this);
    5453    ui.label->setText(tr("Choose a topic for <b>%1</b>:").arg(keyword));
    5554
    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) {
    5957        ui.listWidget->addItem(it.key());
     58
     59
    6060   
    6161    if (ui.listWidget->count() != 0)
     
    6363    ui.listWidget->setFocus();
    6464
    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()));
    7169}
    7270
    7371QUrl TopicChooser::link() const
    7472{
     73
    7574    QListWidgetItem *item = ui.listWidget->currentItem();
    7675    if (!item)
     
    7877
    7978    QString title = item->text();
    80     if (title.isEmpty() || !m_links.contains(title))
     79    if (title.isEmpty())
    8180        return QUrl();
    8281
    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);
    8485}
    8586
  • trunk/tools/assistant/tools/assistant/topicchooser.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4545#include "ui_topicchooser.h"
    4646
    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>
    5051
    5152#include <QtGui/QDialog>
     
    6566private:
    6667    Ui::TopicChooser ui;
    67     QMap<QString, QUrl> m_links;
     68    QQUrl> m_links;
    6869};
    6970
  • trunk/tools/assistant/tools/qcollectiongenerator/main.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4040****************************************************************************/
    4141
     42
    4243#include "../shared/helpgenerator.h"
    4344
     45
     46
     47
     48
    4449#include <QtCore/QDir>
    4550#include <QtCore/QMap>
    4651#include <QtCore/QFileInfo>
    47 #include <QtCore/QCoreApplication>
    4852#include <QtCore/QDateTime>
    4953#include <QtCore/QBuffer>
    50 
    51 #include <private/qhelpgenerator_p.h>
    52 #include <private/qhelpprojectdata_p.h>
     54#include <QtCore/QTranslator>
     55#include <>
     56#include <>
    5357#include <QtHelp/QHelpEngineCore>
    54 
    5558#include <QtXml/QXmlStreamReader>
    5659
     60
    5761QT_USE_NAMESPACE
     62
     63
     64
     65
    5866
    5967class CollectionConfigReader : public QXmlStreamReader
     
    8896
    8997    QString cacheDirectory() const { return m_cacheDirectory; }
     98
    9099
    91100private:
     
    116125    QStringList m_filesToRegister;
    117126    QString m_cacheDirectory;
     127
    118128};
    119129
    120130void CollectionConfigReader::raiseErrorWithLine()
    121131{
    122     raiseError(QObject::tr("Unknown token at line %1.")
    123                     .arg(lineNumber()));
     132    raiseError(QCG::tr("Unknown token at line %1.").arg(lineNumber()));
    124133}
    125134
     
    140149                readConfig();
    141150            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()));
    144154        }
    145155    }
     
    163173    }
    164174    if (!ok && !hasError())
    165         raiseError(QLatin1String("Missing end tags."));
     175        raiseError(Q("Missing end tags."));
    166176}
    167177
     
    199209                readAboutDialog();
    200210            } else if (name() == "cacheDirectory") {
     211
     212
     213
    201214                m_cacheDirectory = readElementText();
    202215            } else {
     
    302315    }
    303316    if (input.isEmpty() || output.isEmpty()) {
    304         raiseError(QLatin1String("Missing input or output file for help file generation!"));
     317        raiseError(Q"));
    305318        return;
    306319    }
     
    320333            break;
    321334        }
     335
     336
     337
     338
     339
     340
     341
     342
    322343    }
    323344}
     
    333354    bool showVersion = false;
    334355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
    335372    for (int i=1; i<argc; ++i) {
    336373        arg = QString::fromLocal8Bit(argv[i]);
     
    340377                collectionFile = fi.absoluteFilePath();
    341378            } else {
    342                 error = QObject::tr("Missing output file name!");
     379                error = Q");
    343380            }
    344381        } else if (arg == QLatin1String("-h")) {
     
    354391
    355392    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);
    357395        return 0;
    358396    }
    359397
    360398    if (configFile.isEmpty() && !showHelp)
    361         error = QObject::tr("Missing collection config file!");
    362 
    363     QString help = QObject::tr("\nUsage:\n\n"
     399        error = Q");
     400
     401    QString help = Q::tr("\nUsage:\n\n"
    364402        "qcollectiongenerator <collection-config-file> [options]\n\n"
    365403        "  -o <collection-file>   Generates a collection file\n"
     
    371409
    372410    if (showHelp) {
    373         fprintf(stdout, "%s", qPrintable(help));
     411        fp);
    374412        return 0;
    375413    }else if (!error.isEmpty()) {
     
    380418    QFile file(configFile);
    381419    if (!file.open(QIODevice::ReadOnly)) {
    382         fprintf(stderr, "Could not open %s!\n", qPrintable(configFile));
     420        fp);
    383421        return -1;
    384422    }
     
    390428    }
    391429
    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);
    395431    CollectionConfigReader config;
    396432    config.readData(file.readAll());
    397433    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);
    399436        return -1;
    400437    }
     
    402439    QMap<QString, QString>::const_iterator it = config.filesToGenerate().constBegin();
    403440    while (it != config.filesToGenerate().constEnd()) {
    404         fprintf(stdout, "Generating help for %s...\n", qPrintable(it.key()));
     441        fp);
    405442        QHelpProjectData helpData;
    406         if (!helpData.readData(basePath + QDir::separator() + it.key())) {
     443        if (!helpData.readData())) {
    407444            fprintf(stderr, "%s\n", qPrintable(helpData.errorMessage()));
    408445            return -1;
     
    410447
    411448        HelpGenerator helpGenerator;
    412         if (!helpGenerator.generate(&helpData, basePath + QDir::separator() + it.value())) {
     449        if (!helpGenerator.generate(&helpData, ))) {
    413450            fprintf(stderr, "%s\n", qPrintable(helpGenerator.error()));
    414451            return -1;
     
    417454    }
    418455
    419     fprintf(stdout, "Creating collection file...\n");
     456    fp);
    420457
    421458    QFileInfo colFi(collectionFile);
    422459    if (colFi.exists()) {
    423460        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);
    425463            return -1;
    426464        }
     
    434472
    435473    foreach (const QString &file, config.filesToRegister()) {
    436         if (!helpEngine.registerDocumentation(basePath + QDir::separator() + file)) {
     474        if (!helpEngine.registerDocumentation()) {
    437475            fprintf(stderr, "%s\n", qPrintable(helpEngine.error()));
    438476            return -1;
    439477        }
    440478    }
     479
     480
    441481
    442482    if (!config.title().isEmpty())
    443         helpEngine.setCustomValue(QLatin1String("WindowTitle"), config.title());
     483        , config.title());
    444484
    445485    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,
    460505        config.enableFilterFunctionality());
    461     helpEngine.setCustomValue(QLatin1String("HideFilterFunctionality"),
    462         config.hideFilterFunctionality());
    463     helpEngine.setCustomValue(QLatin1String("EnableDocumentationManager"),
     506    ,
     507        config.hideFilterFunctionality());
     508    ,
    464509        config.enableDocumentationManager());
    465     helpEngine.setCustomValue(QLatin1String("EnableAddressBar"),
     510    ,
    466511        config.enableAddressBar());
    467     helpEngine.setCustomValue(QLatin1String("HideAddressBar"),
    468         config.hideAddressBar());
    469     helpEngine.setCustomValue(QLatin1String("CreationTime"),
     512    ,
     513        config.hideAddressBar());
     514    ,
    470515        QDateTime::currentDateTime().toTime_t());
    471516
    472517    if (!config.applicationIcon().isEmpty()) {
    473         QFile icon(basePath + QDir::separator() + config.applicationIcon());
     518        QFile icon());
    474519        if (!icon.open(QIODevice::ReadOnly)) {
    475             fprintf(stderr, "Cannot open %s!\n", qPrintable(icon.fileName()));
     520            fp);
    476521            return -1;
    477522        }
    478         helpEngine.setCustomValue(QLatin1String("ApplicationIcon"), icon.readAll());
     523        , icon.readAll());
    479524    }
    480525
     
    488533            ++it;
    489534        }
    490         helpEngine.setCustomValue(QLatin1String("AboutMenuTexts"), ba);
     535        , ba);
    491536    }
    492537
    493538    if (!config.aboutIcon().isEmpty()) {
    494         QFile icon(basePath + QDir::separator() + config.aboutIcon());
     539        QFile icon());
    495540        if (!icon.open(QIODevice::ReadOnly)) {
    496             fprintf(stderr, "Cannot open %s!\n", qPrintable(icon.fileName()));
     541            fp);
    497542            return -1;
    498543        }
    499         helpEngine.setCustomValue(QLatin1String("AboutIcon"), icon.readAll());
     544        , icon.readAll());
    500545    }
    501546
     
    513558        while (it != config.aboutTextFiles().constEnd()) {
    514559            s << it.key();
    515             QFileInfo fi(basePath + QDir::separator() + it.value());
     560            QFileInfo fi());
    516561            QFile f(fi.absoluteFilePath());
    517562            if (!f.open(QIODevice::ReadOnly)) {
    518                 fprintf(stderr, "Cannot open %s!\n", qPrintable(f.fileName()));
     563                fp);
    519564                return -1;
    520565            }
     
    538583                            imgData.insert(src, img.readAll());
    539584                    } else {
    540                         fprintf(stderr, "Cannot open referenced image file %s!\n",
    541                             qPrintable(img.fileName()));
     585                        fp
     586                            );
    542587                    }
    543588                }
     
    545590            ++it;
    546591        }
    547         helpEngine.setCustomValue(QLatin1String("AboutTexts"), ba);
     592        , ba);
    548593        if (imgData.count()) {
    549594            QByteArray imageData;
     
    552597            QDataStream out(&buffer);
    553598            out << imgData;
    554             helpEngine.setCustomValue(QLatin1String("AboutImages"), imageData);
     599            , imageData);
    555600        }
    556601    }
  • trunk/tools/assistant/tools/qcollectiongenerator/qcollectiongenerator.pro

    r2 r846  
    1 QT += xml network
     1QT += xml \
     2    network
    23TEMPLATE = app
    34DESTDIR = ../../../../bin
    45TARGET = qcollectiongenerator
    5 CONFIG += qt warn_on help console
     6CONFIG += qt \
     7    warn_on \
     8    help \
     9    console
    610CONFIG -= app_bundle
    7 
    8 target.path=$$[QT_INSTALL_BINS]
     11target.path = $$[QT_INSTALL_BINS]
    912INSTALLS += target
    10 
    1113SOURCES += ../shared/helpgenerator.cpp \
    12            main.cpp
    13 
    14 HEADERS += ../shared/helpgenerator.h
     14    main.cpp \
     15    ../shared/collectionconfiguration.cpp
     16HEADERS += ../shared/helpgenerator.h \
     17    ../shared/collectionconfiguration.h
  • trunk/tools/assistant/tools/qhelpconverter/adpreader.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/adpreader.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/conversionwizard.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/conversionwizard.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/filespage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6060        this, SLOT(removeAllFiles()));
    6161
    62     m_ui.fileLabel->setText(tr("<p><b>Warning:</b> Be aware "
    63         "when removing images or stylesheets since those files "
     62    m_ui.fileLabel->setText(tr("<p><b>Warning:</b> "
     63        " those files "
    6464        "are not directly referenced by the .adp or .dcf "
    6565        "file.</p>"));
  • trunk/tools/assistant/tools/qhelpconverter/filespage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/filterpage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5151    setSubTitle(tr("Specify the filter attributes for the "
    5252        "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 "
    5454        "filter attributes and the custom filters are "
    5555        "optional."));
     
    128128    QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.customFilterWidget);
    129129    item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsEditable|Qt::ItemIsSelectable);
    130     item->setText(0, QLatin1String("unfiltered"));
     130    item->setText(0, "));
    131131    item->setText(1, QLatin1String(""));
    132132    m_ui.customFilterWidget->editItem(item, 0);
  • trunk/tools/assistant/tools/qhelpconverter/filterpage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/finishpage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5353{
    5454    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."));
    5756    setFinalPage(true);
    5857
  • trunk/tools/assistant/tools/qhelpconverter/finishpage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/generalpage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/generalpage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/helpwindow.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6565    layout = new QVBoxLayout(frame);
    6666    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>"));
    6868    layout->addWidget(l);
    6969    m_textEdit = new QTextEdit();
  • trunk/tools/assistant/tools/qhelpconverter/helpwindow.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/identifierpage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/identifierpage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/inputpage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/inputpage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5555
    5656public:
    57     InputPage(AdpReader *reader, QWidget *parent = 0);
     57    InputPage(AdpReader *reader, QWidget *parent = 0);
    5858   
    5959private slots:
  • trunk/tools/assistant/tools/qhelpconverter/main.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4141
    4242#include <QtCore/QFileInfo>
     43
     44
     45
    4346#include <QtGui/QApplication>
    4447
     
    5053{
    5154    QApplication app(argc, argv);
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
    5267
    5368    ConversionWizard w;
  • trunk/tools/assistant/tools/qhelpconverter/outputpage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/outputpage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/pathpage.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/pathpage.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/qhcpwriter.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/qhcpwriter.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/qhpwriter.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpconverter/qhpwriter.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/assistant/tools/qhelpgenerator/main.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4545#include <QtCore/QFileInfo>
    4646#include <QtCore/QCoreApplication>
     47
     48
     49
    4750
    4851#include <private/qhelpprojectdata_p.h>
    4952
    5053QT_USE_NAMESPACE
     54
     55
     56
     57
    5158
    5259int main(int argc, char *argv[])
     
    5966    bool showHelp = false;
    6067    bool showVersion = false;
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
    6185
    6286    for (int i = 1; i < argc; ++i) {
     
    6791                compressedFile = fi.absoluteFilePath();
    6892            } else {
    69                 error = QObject::tr("Missing output file name!");
     93                error = Q");
    7094            }
    7195        } else if (arg == QLatin1String("-v")) {
     
    7397        } else if (arg == QLatin1String("-h")) {
    7498            showHelp = true;
     99
     100
    75101        } else {
    76102            QFileInfo fi(arg);
     
    81107
    82108    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);
    84111        return 0;
    85112    }
    86113
    87114    if (projectFile.isEmpty() && !showHelp)
    88         error = QObject::tr("Missing Qt help project file!");
     115        error = Q");
    89116
    90     QString help = QObject::tr("\nUsage:\n\n"
     117    QString help = Q::tr("\nUsage:\n\n"
    91118        "qhelpgenerator <help-project-file> [options]\n\n"
    92119        "  -o <compressed-file>   Generates a Qt compressed help\n"
     
    94121        "                         If this option is not specified\n"
    95122        "                         a default name will be used.\n"
     123
     124
    96125        "  -v                     Displays the version of \n"
    97126        "                         qhelpgenerator.\n\n");
    98127
    99128    if (showHelp) {
    100         fprintf(stdout, "%s", qPrintable(help));
     129        fp);
    101130        return 0;
    102131    }else if (!error.isEmpty()) {
     
    107136    QFile file(projectFile);
    108137    if (!file.open(QIODevice::ReadOnly)) {
    109         fprintf(stderr, "Could not open %s!\n", qPrintable(projectFile));
     138        fp);
    110139        return -1;
    111140    }
    112141
    113142    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        }
    117148    } else {
    118149        // check if the output dir exists -- create if it doesn't
     
    121152        if (!parentDir.exists()) {
    122153            if (!parentDir.mkpath(QLatin1String("."))) {
    123                 fprintf(stderr, "Could not create output directory: %s\n",
    124                         qPrintable(parentDir.path()));
     154                fp
     155                        );
    125156            }
    126157        }
     
    133164    }
    134165
    135     QCoreApplication app(argc, argv);
    136166    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);
    138172    delete helpData;
    139173    if (!success) {
  • trunk/tools/assistant/tools/shared/helpgenerator.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6262}
    6363
     64
     65
     66
     67
     68
    6469QString HelpGenerator::error() const
    6570{
     
    6974void HelpGenerator::printStatus(const QString &msg)
    7075{
    71     fprintf(stdout, "%s\n", qPrintable(msg));
     76    qPrintable(msg));
    7277}
    7378
    7479void HelpGenerator::printWarning(const QString &msg)
    7580{
    76     fprintf(stdout, "Warning: %s\n", qPrintable(msg));
     81    ));
    7782}
    7883
  • trunk/tools/assistant/tools/shared/helpgenerator.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5858    bool generate(QHelpDataInterface *helpData,
    5959        const QString &outputFileName);
     60
    6061    QString error() const;
    6162
Note: See TracChangeset for help on using the changeset viewer.