diff --git a/documentation/qthelp/qthelpconfig.cpp b/documentation/qthelp/qthelpconfig.cpp --- a/documentation/qthelp/qthelpconfig.cpp +++ b/documentation/qthelp/qthelpconfig.cpp @@ -120,6 +120,15 @@ connect(m_configWidget->loadQtDocsCheckBox, &QCheckBox::toggled, this, static_cast(&QtHelpConfig::changed)); connect(m_configWidget->qchSearchDirButton, &QPushButton::clicked, this, &QtHelpConfig::chooseSearchDir); connect(m_configWidget->qchSearchDir,&QLineEdit::textChanged, this, &QtHelpConfig::searchDirChanged); + + // Set availability information for QtHelp + if(plugin->qtHelpAvailable()) { + m_configWidget->labelAvailabilityQtDocs->setVisible(false); + } else { + m_configWidget->labelAvailabilityQtDocs->setText( + i18n("The command \"qmake -query\" could not provide a path to a QtHelp file (QCH).")); + m_configWidget->loadQtDocsCheckBox->setEnabled(false); + } l->addWidget( w ); reset(); selectionChanged(); @@ -377,10 +386,10 @@ QString QtHelpConfig::name() const { - return i18n("QtHelp Documentation"); + return i18n("API Documentation"); } QIcon QtHelpConfig::icon() const { - return QIcon::fromTheme(QStringLiteral("qtlogo")); + return QIcon::fromTheme(QStringLiteral("help-contents")); } diff --git a/documentation/qthelp/qthelpconfig.ui b/documentation/qthelp/qthelpconfig.ui --- a/documentation/qthelp/qthelpconfig.ui +++ b/documentation/qthelp/qthelpconfig.ui @@ -7,7 +7,7 @@ 0 0 560 - 404 + 443 @@ -17,7 +17,7 @@ - Manage QtHelp Documentation + Manage API Documentation @@ -149,10 +149,29 @@ + + + + + + + Manage QtHelp Documentation + + - Load Qt documentation + Load Qt API Documentation + + + + + + + true + + + @@ -174,13 +193,6 @@ - - - QPushButton - QPushButton -
kpushbutton.h
-
-
diff --git a/documentation/qthelp/qthelpplugin.h b/documentation/qthelp/qthelpplugin.h --- a/documentation/qthelp/qthelpplugin.h +++ b/documentation/qthelp/qthelpplugin.h @@ -40,7 +40,8 @@ QList providers() override; QList qtHelpProviderLoaded(); - bool qtHelpQtDocLoaded(); + bool qtHelpQtDocLoaded() const; + bool qtHelpAvailable() const; int configPages() const override; KDevelop::ConfigPage* configPage(int number, QWidget* parent) override; @@ -57,6 +58,7 @@ static QtHelpPlugin *s_plugin; QList m_qtHelpProviders; QtHelpQtDoc* m_qtDoc; + bool m_loadSystemQtDoc; }; #endif // QTHELPPLUGIN_H diff --git a/documentation/qthelp/qthelpplugin.cpp b/documentation/qthelp/qthelpplugin.cpp --- a/documentation/qthelp/qthelpplugin.cpp +++ b/documentation/qthelp/qthelpplugin.cpp @@ -38,7 +38,8 @@ QtHelpPlugin::QtHelpPlugin(QObject* parent, const QVariantList& args) : KDevelop::IPlugin("kdevqthelp", parent) , m_qtHelpProviders() - , m_qtDoc(0) + , m_qtDoc(new QtHelpQtDoc(this, QVariantList())) + , m_loadSystemQtDoc(false) { KDEV_USE_EXTENSION_INTERFACE( KDevelop::IDocumentationProviderProvider ) @@ -56,24 +57,22 @@ void QtHelpPlugin::readConfig() { QStringList iconList, nameList, pathList, ghnsList; - bool loadQtDoc; QString searchDir; - qtHelpReadConfig(iconList, nameList, pathList, ghnsList, searchDir, loadQtDoc); + qtHelpReadConfig(iconList, nameList, pathList, ghnsList, searchDir, m_loadSystemQtDoc); searchHelpDirectory(pathList, nameList, iconList, searchDir); loadQtHelpProvider(pathList, nameList, iconList); - loadQtDocumentation(loadQtDoc); + loadQtDocumentation(m_loadSystemQtDoc); emit changedProvidersList(); } void QtHelpPlugin::loadQtDocumentation(bool loadQtDoc) { - if(m_qtDoc && !loadQtDoc){ - delete m_qtDoc; - m_qtDoc = 0; - } else if(!m_qtDoc && loadQtDoc) { - m_qtDoc = new QtHelpQtDoc(this, QVariantList()); + if(!loadQtDoc){ + m_qtDoc->unloadDocumentation(); + } else if(loadQtDoc) { + m_qtDoc->loadDocumentation(); } } @@ -147,7 +146,7 @@ foreach(QtHelpProvider* provider, m_qtHelpProviders) { list.append(provider); } - if(m_qtDoc){ + if(m_loadSystemQtDoc){ list.append(m_qtDoc); } return list; @@ -158,8 +157,14 @@ return m_qtHelpProviders; } -bool QtHelpPlugin::qtHelpQtDocLoaded(){ - return m_qtDoc; +bool QtHelpPlugin::qtHelpQtDocLoaded() const +{ + return m_loadSystemQtDoc; +} + +bool QtHelpPlugin::qtHelpAvailable() const +{ + return !m_qtDoc->qchFile().isEmpty(); } KDevelop::ConfigPage* QtHelpPlugin::configPage(int number, QWidget* parent) diff --git a/documentation/qthelp/qthelpqtdoc.h b/documentation/qthelp/qthelpqtdoc.h --- a/documentation/qthelp/qthelpqtdoc.h +++ b/documentation/qthelp/qthelpqtdoc.h @@ -1,6 +1,7 @@ /* This file is part of KDevelop Copyright 2009 Aleix Pol Copyright 2010 Benjamin Port + Copyright 2016 Andreas Cord-Landwehr This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -26,14 +27,18 @@ class QtHelpQtDoc : public QtHelpProviderAbstract { Q_OBJECT - public: + public: QtHelpQtDoc(QObject *parent, const QVariantList &args); QIcon icon() const override; QString name() const override; void registerDocumentations(); + void loadDocumentation(); + void unloadDocumentation(); + /** @return local path to QCH file if it exists, otherwise returns an empty string **/ + QString qchFile() const; private: - void loadDirectory(const QString& path); + QString m_path; private slots: void lookupDone(int code); diff --git a/documentation/qthelp/qthelpqtdoc.cpp b/documentation/qthelp/qthelpqtdoc.cpp --- a/documentation/qthelp/qthelpqtdoc.cpp +++ b/documentation/qthelp/qthelpqtdoc.cpp @@ -2,6 +2,7 @@ Copyright 2009 Aleix Pol Copyright 2009 David Nolden Copyright 2010 Benjamin Port + Copyright 2016 Andreas Cord-Landwehr This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -47,6 +48,7 @@ QtHelpQtDoc::QtHelpQtDoc(QObject *parent, const QVariantList &args) : QtHelpProviderAbstract(parent, "qthelpcollection.qhc", args) + , m_path(QString()) { Q_UNUSED(args); registerDocumentations(); @@ -69,36 +71,58 @@ if(code==0) { KProcess* p = qobject_cast(sender()); - QString path = QDir::fromNativeSeparators(QString::fromLatin1(p->readAllStandardOutput().trimmed())); - qCDebug(QTHELP) << "Detected doc path:" << path; - - if (!path.isEmpty()) { - loadDirectory(path); - loadDirectory(path+"/qch/"); - } + m_path = QDir::fromNativeSeparators(QString::fromLatin1(p->readAllStandardOutput().trimmed())); + qCDebug(QTHELP) << "Detected doc path:" << m_path; } sender()->deleteLater(); } -void QtHelpQtDoc::loadDirectory(const QString& path) +void QtHelpQtDoc::loadDocumentation() { - QDir d(path); - if(path.isEmpty() || !d.exists()) { - qCDebug(QTHELP) << "no QtHelp found at all"; + if(m_path.isEmpty()) { return; } - foreach(const QString& file, d.entryList(QDir::Files)) { - QString fileName=path+'/'+file; - QString fileNamespace = QHelpEngineCore::namespaceName(fileName); + QString fileName = qchFile(); + if(fileName.isEmpty()) { + qCWarning(QTHELP) << "could not find QCH file in directory" << m_path; + return; + } + + QString fileNamespace = QHelpEngineCore::namespaceName(fileName); + if (!fileNamespace.isEmpty() && !m_engine.registeredDocumentations().contains(fileNamespace)) { + qCDebug(QTHELP) << "loading doc" << fileName << fileNamespace; + if(!m_engine.registerDocumentation(fileName)) + qCCritical(QTHELP) << "error >> " << fileName << m_engine.error(); + } +} + +void QtHelpQtDoc::unloadDocumentation() +{ + QString fileName = qchFile(); + QString fileNamespace = QHelpEngineCore::namespaceName(fileName); + if(!fileName.isEmpty() && !m_engine.registeredDocumentations().contains(fileNamespace)) { + m_engine.unregisterDocumentation(fileName); + } +} + +QString QtHelpQtDoc::qchFile() const +{ + QVector paths; + paths << m_path << m_path+"/qch/"; + foreach (const auto &path, paths) { + QDir d(path); + if(path.isEmpty() || !d.exists()) { + continue; + } - if (!fileNamespace.isEmpty() && !m_engine.registeredDocumentations().contains(fileNamespace)) { - qCDebug(QTHELP) << "loading doc" << fileName << fileNamespace; - if(!m_engine.registerDocumentation(fileName)) - qCDebug(QTHELP) << "error >> " << fileName << m_engine.error(); + foreach(const QString& file, d.entryList(QDir::Files)) { + QString fileName=path+'/'+file; + return fileName; } } - qCDebug(QTHELP) << "registered" << m_engine.error() << m_engine.registeredDocumentations(); + qCDebug(QTHELP) << "no QCH file found at all"; + return QString(); } QIcon QtHelpQtDoc::icon() const