1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Assistant of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "tracer.h"
#include "helpenginewrapper.h"
#include "../shared/collectionconfiguration.h"
#include <QtCore/QDateTime>
#include <QtCore/QFileInfo>
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
#include <QtCore/QTimer>
#include <QtHelp/QHelpContentModel>
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpIndexModel>
#include <QtHelp/QHelpSearchEngine>
QT_BEGIN_NAMESPACE
namespace {
const QString Unfiltered;
const QString AppFontKey(QLatin1String("appFont"));
const QString AppWritingSystemKey(QLatin1String("appWritingSystem"));
const QString BookmarksKey(QLatin1String("Bookmarks"));
const QString BrowserFontKey(QLatin1String("browserFont"));
const QString BrowserWritingSystemKey(QLatin1String("browserWritingSystem"));
const QString HomePageKey(QLatin1String("homepage"));
const QString MainWindowKey(QLatin1String("MainWindow"));
const QString MainWindowGeometryKey(QLatin1String("MainWindowGeometry"));
const QString SearchWasAttachedKey(QLatin1String("SearchWasAttached"));
const QString StartOptionKey(QLatin1String("StartOption"));
const QString UseAppFontKey(QLatin1String("useAppFont"));
const QString UseBrowserFontKey(QLatin1String("useBrowserFont"));
const QString VersionKey(QString(QLatin1String("qtVersion%1$$$%2")).
arg(QLatin1String(QT_VERSION_STR)));
} // anonymous namespace
class TimeoutForwarder : public QObject
{
Q_OBJECT
public:
TimeoutForwarder(const QString &fileName);
private slots:
void forward();
private:
friend class HelpEngineWrapperPrivate;
const QString m_fileName;
};
class HelpEngineWrapperPrivate : public QObject
{
Q_OBJECT
friend class HelpEngineWrapper;
friend class TimeoutForwarder;
private slots:
void qchFileChanged(const QString &fileName);
signals:
void documentationRemoved(const QString &namespaceName);
void documentationUpdated(const QString &namespaceName);
private:
HelpEngineWrapperPrivate(const QString &collectionFile);
void initFileSystemWatchers();
void checkDocFilesWatched();
void qchFileChanged(const QString &fileName, bool fromTimeout);
static const int UpdateGracePeriod = 2000;
QHelpEngine * const m_helpEngine;
QFileSystemWatcher * const m_qchWatcher;
typedef QPair<QDateTime, QSharedPointer<TimeoutForwarder> > RecentSignal;
QMap<QString, RecentSignal> m_recentQchUpdates;
};
const QString HelpEngineWrapper::TrUnfiltered = HelpEngineWrapper::tr("Unfiltered");
HelpEngineWrapper *HelpEngineWrapper::helpEngineWrapper = 0;
HelpEngineWrapper &HelpEngineWrapper::instance(const QString &collectionFile)
{
TRACE_OBJ
/*
* Note that this Singleton cannot be static, because it has to be
* deleted before the QApplication.
*/
if (helpEngineWrapper == 0)
helpEngineWrapper = new HelpEngineWrapper(collectionFile);
return *helpEngineWrapper;
}
void HelpEngineWrapper::removeInstance()
{
TRACE_OBJ
delete helpEngineWrapper;
helpEngineWrapper = 0;
}
HelpEngineWrapper::HelpEngineWrapper(const QString &collectionFile)
: d(new HelpEngineWrapperPrivate(collectionFile))
{
TRACE_OBJ
/*
* Otherwise we will waste time if several new docs are found,
* because we will start to index them, only to be interrupted
* by the next request. Also, there is a nasty SQLITE bug that will
* cause the application to hang for minutes in that case.
* This call is reverted by initalDocSetupDone(), which must be
* called after the new docs have been installed.
*/
disconnect(d->m_helpEngine, SIGNAL(setupFinished()),
searchEngine(), SLOT(indexDocumentation()));
connect(d, SIGNAL(documentationRemoved(QString)),
this, SIGNAL(documentationRemoved(QString)));
connect(d, SIGNAL(documentationUpdated(QString)),
this, SIGNAL(documentationUpdated(QString)));
connect(d->m_helpEngine, SIGNAL(currentFilterChanged(QString)),
this, SLOT(handleCurrentFilterChanged(QString)));
connect(d->m_helpEngine, SIGNAL(setupFinished()),
this, SIGNAL(setupFinished()));
}
HelpEngineWrapper::~HelpEngineWrapper()
{
TRACE_OBJ
const QStringList &namespaces = d->m_helpEngine->registeredDocumentations();
foreach (const QString &nameSpace, namespaces) {
const QString &docFile
= d->m_helpEngine->documentationFileName(nameSpace);
d->m_qchWatcher->removePath(docFile);
}
delete d;
}
void HelpEngineWrapper::initialDocSetupDone()
{
TRACE_OBJ
connect(d->m_helpEngine, SIGNAL(setupFinished()),
searchEngine(), SLOT(indexDocumentation()));
setupData();
}
QHelpSearchEngine *HelpEngineWrapper::searchEngine() const
{
TRACE_OBJ
return d->m_helpEngine->searchEngine();
}
QHelpContentModel *HelpEngineWrapper::contentModel() const
{
TRACE_OBJ
return d->m_helpEngine->contentModel();
}
QHelpIndexModel *HelpEngineWrapper::indexModel() const
{
TRACE_OBJ
return d->m_helpEngine->indexModel();
}
QHelpContentWidget *HelpEngineWrapper::contentWidget()
{
TRACE_OBJ
return d->m_helpEngine->contentWidget();
}
QHelpIndexWidget *HelpEngineWrapper::indexWidget()
{
TRACE_OBJ
return d->m_helpEngine->indexWidget();
}
const QStringList HelpEngineWrapper::registeredDocumentations() const
{
TRACE_OBJ
return d->m_helpEngine->registeredDocumentations();
}
const QString HelpEngineWrapper::collectionFile() const
{
TRACE_OBJ
return d->m_helpEngine->collectionFile();
}
bool HelpEngineWrapper::registerDocumentation(const QString &docFile)
{
TRACE_OBJ
d->checkDocFilesWatched();
if (!d->m_helpEngine->registerDocumentation(docFile))
return false;
d->m_qchWatcher->addPath(docFile);
d->checkDocFilesWatched();
return true;
}
bool HelpEngineWrapper::unregisterDocumentation(const QString &namespaceName)
{
TRACE_OBJ
d->checkDocFilesWatched();
const QString &file = d->m_helpEngine->documentationFileName(namespaceName);
if (!d->m_helpEngine->unregisterDocumentation(namespaceName))
return false;
d->m_qchWatcher->removePath(file);
d->checkDocFilesWatched();
return true;
}
bool HelpEngineWrapper::setupData()
{
TRACE_OBJ
return d->m_helpEngine->setupData();
}
bool HelpEngineWrapper::addCustomFilter(const QString &filterName,
const QStringList &attributes)
{
TRACE_OBJ
return d->m_helpEngine->addCustomFilter(filterName, attributes);
}
bool HelpEngineWrapper::removeCustomFilter(const QString &filterName)
{
TRACE_OBJ
return d->m_helpEngine->removeCustomFilter(filterName);
}
void HelpEngineWrapper::setCurrentFilter(const QString ¤tFilter)
{
TRACE_OBJ
const QString &filter
= currentFilter == TrUnfiltered ? Unfiltered : currentFilter;
d->m_helpEngine->setCurrentFilter(filter);
}
const QString HelpEngineWrapper::currentFilter() const
{
TRACE_OBJ
const QString &filter = d->m_helpEngine->currentFilter();
return filter == Unfiltered ? TrUnfiltered : filter;
}
const QStringList HelpEngineWrapper::customFilters() const
{
TRACE_OBJ
QStringList filters = d->m_helpEngine->customFilters();
filters.removeOne(Unfiltered);
filters.prepend(TrUnfiltered);
return filters;
}
QUrl HelpEngineWrapper::findFile(const QUrl &url) const
{
TRACE_OBJ
return d->m_helpEngine->findFile(url);
}
QByteArray HelpEngineWrapper::fileData(const QUrl &url) const
{
TRACE_OBJ
return d->m_helpEngine->fileData(url);
}
QMap<QString, QUrl> HelpEngineWrapper::linksForIdentifier(const QString &id) const
{
TRACE_OBJ
return d->m_helpEngine->linksForIdentifier(id);
}
const QStringList HelpEngineWrapper::filterAttributes() const
{
TRACE_OBJ
return d->m_helpEngine->filterAttributes();
}
const QStringList HelpEngineWrapper::filterAttributes(const QString &filterName) const
{
TRACE_OBJ
return d->m_helpEngine->filterAttributes(filterName);
}
QString HelpEngineWrapper::error() const
{
TRACE_OBJ
return d->m_helpEngine->error();
}
const QStringList HelpEngineWrapper::qtDocInfo(const QString &component) const
{
TRACE_OBJ
return d->m_helpEngine->customValue(VersionKey.arg(component)).toString().
split(CollectionConfiguration::ListSeparator);
}
void HelpEngineWrapper::setQtDocInfo(const QString &component,
const QStringList &doc)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(VersionKey.arg(component),
doc.join(CollectionConfiguration::ListSeparator));
}
const QStringList HelpEngineWrapper::lastShownPages() const
{
TRACE_OBJ
return CollectionConfiguration::lastShownPages(*d->m_helpEngine);
}
void HelpEngineWrapper::setLastShownPages(const QStringList &lastShownPages)
{
TRACE_OBJ
CollectionConfiguration::setLastShownPages(*d->m_helpEngine, lastShownPages);
}
const QStringList HelpEngineWrapper::lastZoomFactors() const
{
TRACE_OBJ
return CollectionConfiguration::lastZoomFactors(*d->m_helpEngine);
}
void HelpEngineWrapper::setLastZoomFactors(const QStringList &lastZoomFactors)
{
TRACE_OBJ
CollectionConfiguration::setLastZoomFactors(*d->m_helpEngine, lastZoomFactors);
}
const QString HelpEngineWrapper::cacheDir() const
{
TRACE_OBJ
return CollectionConfiguration::cacheDir(*d->m_helpEngine);
}
bool HelpEngineWrapper::cacheDirIsRelativeToCollection() const
{
TRACE_OBJ
return CollectionConfiguration::cacheDirIsRelativeToCollection(*d->m_helpEngine);
}
void HelpEngineWrapper::setCacheDir(const QString &cacheDir,
bool relativeToCollection)
{
TRACE_OBJ
CollectionConfiguration::setCacheDir(*d->m_helpEngine, cacheDir,
relativeToCollection);
}
bool HelpEngineWrapper::filterFunctionalityEnabled() const
{
TRACE_OBJ
return CollectionConfiguration::filterFunctionalityEnabled(*d->m_helpEngine);
}
void HelpEngineWrapper::setFilterFunctionalityEnabled(bool enabled)
{
TRACE_OBJ
CollectionConfiguration::setFilterFunctionalityEnabled(*d->m_helpEngine,
enabled);
}
bool HelpEngineWrapper::filterToolbarVisible() const
{
TRACE_OBJ
return CollectionConfiguration::filterToolbarVisible(*d->m_helpEngine);
}
void HelpEngineWrapper::setFilterToolbarVisible(bool visible)
{
TRACE_OBJ
CollectionConfiguration::setFilterToolbarVisible(*d->m_helpEngine, visible);
}
bool HelpEngineWrapper::addressBarEnabled() const
{
TRACE_OBJ
return CollectionConfiguration::addressBarEnabled(*d->m_helpEngine);
}
void HelpEngineWrapper::setAddressBarEnabled(bool enabled)
{
TRACE_OBJ
CollectionConfiguration::setAddressBarEnabled(*d->m_helpEngine, enabled);
}
bool HelpEngineWrapper::addressBarVisible() const
{
TRACE_OBJ
return CollectionConfiguration::addressBarVisible(*d->m_helpEngine);
}
void HelpEngineWrapper::setAddressBarVisible(bool visible)
{
TRACE_OBJ
CollectionConfiguration::setAddressBarVisible(*d->m_helpEngine, visible);
}
bool HelpEngineWrapper::documentationManagerEnabled() const
{
TRACE_OBJ
return CollectionConfiguration::documentationManagerEnabled(*d->m_helpEngine);
}
void HelpEngineWrapper::setDocumentationManagerEnabled(bool enabled)
{
TRACE_OBJ
CollectionConfiguration::setDocumentationManagerEnabled(*d->m_helpEngine,
enabled);
}
const QByteArray HelpEngineWrapper::aboutMenuTexts() const
{
TRACE_OBJ
return CollectionConfiguration::aboutMenuTexts(*d->m_helpEngine);
}
void HelpEngineWrapper::setAboutMenuTexts(const QByteArray &texts)
{
TRACE_OBJ
CollectionConfiguration::setAboutMenuTexts(*d->m_helpEngine, texts);
}
const QByteArray HelpEngineWrapper::aboutIcon() const
{
TRACE_OBJ
return CollectionConfiguration::aboutIcon(*d->m_helpEngine);
}
void HelpEngineWrapper::setAboutIcon(const QByteArray &icon)
{
TRACE_OBJ
CollectionConfiguration::setAboutIcon(*d->m_helpEngine, icon);
}
const QByteArray HelpEngineWrapper::aboutImages() const
{
TRACE_OBJ
return CollectionConfiguration::aboutImages(*d->m_helpEngine);
}
void HelpEngineWrapper::setAboutImages(const QByteArray &images)
{
TRACE_OBJ
CollectionConfiguration::setAboutImages(*d->m_helpEngine, images);
}
const QByteArray HelpEngineWrapper::aboutTexts() const
{
TRACE_OBJ
return CollectionConfiguration::aboutTexts(*d->m_helpEngine);
}
void HelpEngineWrapper::setAboutTexts(const QByteArray &texts)
{
TRACE_OBJ
CollectionConfiguration::setAboutTexts(*d->m_helpEngine, texts);
}
const QString HelpEngineWrapper::windowTitle() const
{
TRACE_OBJ
return CollectionConfiguration::windowTitle(*d->m_helpEngine);
}
void HelpEngineWrapper::setWindowTitle(const QString &windowTitle)
{
TRACE_OBJ
CollectionConfiguration::setWindowTitle(*d->m_helpEngine, windowTitle);
}
const QByteArray HelpEngineWrapper::applicationIcon() const
{
TRACE_OBJ
return CollectionConfiguration::applicationIcon(*d->m_helpEngine);
}
void HelpEngineWrapper::setApplicationIcon(const QByteArray &icon)
{
TRACE_OBJ
CollectionConfiguration::setApplicationIcon(*d->m_helpEngine, icon);
}
const QByteArray HelpEngineWrapper::mainWindow() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(MainWindowKey).toByteArray();
}
void HelpEngineWrapper::setMainWindow(const QByteArray &mainWindow)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(MainWindowKey, mainWindow);
}
const QByteArray HelpEngineWrapper::mainWindowGeometry() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(MainWindowGeometryKey).toByteArray();
}
void HelpEngineWrapper::setMainWindowGeometry(const QByteArray &geometry)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(MainWindowGeometryKey, geometry);
}
const QByteArray HelpEngineWrapper::bookmarks() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(BookmarksKey).toByteArray();
}
void HelpEngineWrapper::setBookmarks(const QByteArray &bookmarks)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(BookmarksKey, bookmarks);
}
int HelpEngineWrapper::lastTabPage() const
{
TRACE_OBJ
return CollectionConfiguration::lastTabPage(*d->m_helpEngine);
}
void HelpEngineWrapper::setLastTabPage(int lastPage)
{
TRACE_OBJ
CollectionConfiguration::setLastTabPage(*d->m_helpEngine, lastPage);
}
bool HelpEngineWrapper::searchWasAttached() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(SearchWasAttachedKey).toBool();
}
void HelpEngineWrapper::setSearchWasAttached(bool attached)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(SearchWasAttachedKey, attached);
}
int HelpEngineWrapper::startOption() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(StartOptionKey, ShowLastPages).toInt();
}
void HelpEngineWrapper::setStartOption(int option)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(StartOptionKey, option);
}
const QString HelpEngineWrapper::homePage() const
{
TRACE_OBJ
const QString &homePage
= d->m_helpEngine->customValue(HomePageKey).toString();
if (!homePage.isEmpty())
return homePage;
return defaultHomePage();
}
void HelpEngineWrapper::setHomePage(const QString &page)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(HomePageKey, page);
}
const QString HelpEngineWrapper::defaultHomePage() const
{
TRACE_OBJ
return CollectionConfiguration::defaultHomePage(*d->m_helpEngine);
}
void HelpEngineWrapper::setDefaultHomePage(const QString &page)
{
TRACE_OBJ
CollectionConfiguration::setDefaultHomePage(*d->m_helpEngine, page);
}
bool HelpEngineWrapper::hasFontSettings() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(UseAppFontKey).isValid();
}
bool HelpEngineWrapper::usesAppFont() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(UseAppFontKey).toBool();
}
void HelpEngineWrapper::setUseAppFont(bool useAppFont)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(UseAppFontKey, useAppFont);
}
bool HelpEngineWrapper::usesBrowserFont() const
{
TRACE_OBJ
return d->m_helpEngine->customValue(UseBrowserFontKey, false).toBool();
}
void HelpEngineWrapper::setUseBrowserFont(bool useBrowserFont)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(UseBrowserFontKey, useBrowserFont);
}
const QFont HelpEngineWrapper::appFont() const
{
TRACE_OBJ
return qVariantValue<QFont>(d->m_helpEngine->customValue(AppFontKey));
}
void HelpEngineWrapper::setAppFont(const QFont &font)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(AppFontKey, font);
}
QFontDatabase::WritingSystem HelpEngineWrapper::appWritingSystem() const
{
TRACE_OBJ
return static_cast<QFontDatabase::WritingSystem>(
d->m_helpEngine->customValue(AppWritingSystemKey).toInt());
}
void HelpEngineWrapper::setAppWritingSystem(QFontDatabase::WritingSystem system)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(AppWritingSystemKey, system);
}
const QFont HelpEngineWrapper::browserFont() const
{
TRACE_OBJ
return qVariantValue<QFont>(d->m_helpEngine->customValue(BrowserFontKey));
}
void HelpEngineWrapper::setBrowserFont(const QFont &font)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(BrowserFontKey, font);
}
QFontDatabase::WritingSystem HelpEngineWrapper::browserWritingSystem() const
{
TRACE_OBJ
return static_cast<QFontDatabase::WritingSystem>(
d->m_helpEngine->customValue(BrowserWritingSystemKey).toInt());
}
void HelpEngineWrapper::setBrowserWritingSystem(QFontDatabase::WritingSystem system)
{
TRACE_OBJ
d->m_helpEngine->setCustomValue(BrowserWritingSystemKey, system);
}
void HelpEngineWrapper::handleCurrentFilterChanged(const QString &filter)
{
const QString &filterToReport
= filter == Unfiltered ? TrUnfiltered : filter;
emit currentFilterChanged(filterToReport);
}
TimeoutForwarder::TimeoutForwarder(const QString &fileName)
: m_fileName(fileName)
{
TRACE_OBJ
}
void TimeoutForwarder::forward()
{
TRACE_OBJ
HelpEngineWrapper::instance().d->qchFileChanged(m_fileName, true);
}
HelpEngineWrapperPrivate::HelpEngineWrapperPrivate(const QString &collectionFile)
: m_helpEngine(new QHelpEngine(collectionFile, this)),
m_qchWatcher(new QFileSystemWatcher(this))
{
TRACE_OBJ
if (!m_helpEngine->customFilters().contains(Unfiltered))
m_helpEngine->addCustomFilter(Unfiltered, QStringList());
initFileSystemWatchers();
}
void HelpEngineWrapperPrivate::initFileSystemWatchers()
{
TRACE_OBJ
foreach(const QString &ns, m_helpEngine->registeredDocumentations()) {
const QString &docFile = m_helpEngine->documentationFileName(ns);
m_qchWatcher->addPath(docFile);
connect(m_qchWatcher, SIGNAL(fileChanged(QString)),
this, SLOT(qchFileChanged(QString)));
}
checkDocFilesWatched();
}
void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName)
{
TRACE_OBJ
qchFileChanged(fileName, false);
}
void HelpEngineWrapperPrivate::checkDocFilesWatched()
{
TRACE_OBJ
const int watchedFilesCount = m_qchWatcher->files().count();
const int docFilesCount = m_helpEngine->registeredDocumentations().count();
if (watchedFilesCount != docFilesCount) {
qWarning("Strange: Have %d docs, but %d are being watched",
watchedFilesCount, docFilesCount);
}
}
void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName,
bool fromTimeout)
{
TRACE_OBJ
/*
* We don't use QHelpEngineCore::namespaceName(fileName), because the file
* may not exist anymore or contain a different namespace.
*/
QString ns;
foreach (const QString &curNs, m_helpEngine->registeredDocumentations()) {
if (m_helpEngine->documentationFileName(curNs) == fileName) {
ns = curNs;
break;
}
}
/*
* We can't do an assertion here, because QFileSystemWatcher may send the
* signal more than once.
*/
if (ns.isEmpty()) {
m_recentQchUpdates.remove(fileName);
return;
}
/*
* Since the QFileSystemWatcher typically sends the signal more than once,
* we repeatedly delay our reaction a bit until we think the last signal
* was sent.
*/
QMap<QString, RecentSignal>::Iterator it = m_recentQchUpdates.find(fileName);
const QDateTime &now = QDateTime::currentDateTime();
// Case 1: This is the first recent signal for the file.
if (it == m_recentQchUpdates.end()) {
QSharedPointer<TimeoutForwarder> forwarder(new TimeoutForwarder(fileName));
m_recentQchUpdates.insert(fileName, RecentSignal(now, forwarder));
QTimer::singleShot(UpdateGracePeriod, forwarder.data(), SLOT(forward()));
return;
}
// Case 2: The last signal for this file has not expired yet.
if (it.value().first > now.addMSecs(-UpdateGracePeriod)) {
if (!fromTimeout)
it.value().first = now;
else
QTimer::singleShot(UpdateGracePeriod, it.value().second.data(),
SLOT(forward()));
return;
}
// Case 3: The last signal for this file has expired.
if (m_helpEngine->unregisterDocumentation(ns)) {
if (!QFileInfo(fileName).exists()
|| !m_helpEngine->registerDocumentation(fileName)) {
m_qchWatcher->removePath(fileName);
emit documentationRemoved(ns);
} else {
emit documentationUpdated(ns);
}
m_helpEngine->setupData();
}
m_recentQchUpdates.erase(it);
}
QT_END_NAMESPACE
#include "helpenginewrapper.moc"
|