Commit 92d48af3 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Refactored the QtHelp loading so that it is not synchronous

As it was being done at the moment, we were calling synchronously the qmake
process from the plugin constructor. This was bad and had problems, like
the one discussed in the bug.
Some logic for the lookup is being removed as well, but it seemed like an
overkill to me, the first qmake should be already working. If that's not
the case we can iterate over it.

BUG: 310703
parent 1bce6b2f
......@@ -29,30 +29,6 @@
#include <KIcon>
#include <KDebug>
QString qtDocsLocation(const QString& qmake)
{
QString ret;
KProcess p;
p.setOutputChannelMode(KProcess::MergedChannels);
p.setProgram(qmake, QStringList("-query") << "QT_INSTALL_DOCS");
p.start();
if(p.waitForFinished(5000))
{
QByteArray b = p.readAllStandardOutput();
ret.prepend(b.trimmed());
}
else
kDebug() << "failed to execute qmake to retrieve the docs";
kDebug() << "qtdoc=" << ret;
Q_ASSERT(qmake.isEmpty() || !ret.isEmpty());
return QDir::fromNativeSeparators(ret);
}
QtHelpQtDoc::QtHelpQtDoc(QObject *parent, const QVariantList &args)
: QtHelpProviderAbstract(parent, "qthelpcollection.qhc", args)
{
......@@ -63,49 +39,47 @@ QtHelpQtDoc::QtHelpQtDoc(QObject *parent, const QVariantList &args)
void QtHelpQtDoc::registerDocumentations()
{
QStringList qmakes;
QStringList tmp;
KStandardDirs::findAllExe(tmp, "qmake");
qmakes += tmp;
KStandardDirs::findAllExe(tmp, "qmake-qt4");
qmakes += tmp;
QString dirName;
foreach(const QString& qmake, qmakes) {
/// check both in doc/ and doc/qch/
dirName=qtDocsLocation(qmake)+"/qch/";
QString fileName=dirName+"qt.qch";
if(QFile::exists(fileName)) {
kDebug() << "checking doc: " << fileName;
break;
} else
dirName.clear();
dirName=qtDocsLocation(qmake);
fileName=dirName+"/qt.qch";
if(QFile::exists(fileName)) {
kDebug() << "checking doc: " << fileName;
break;
} else
dirName.clear();
qmakes << KStandardDirs::findExe("qmake")
<< KStandardDirs::findExe("qmake-qt4");
if(!qmakes.isEmpty()) {
KProcess *p = new KProcess;
p->setOutputChannelMode(KProcess::MergedChannels);
p->setProgram(qmakes.first(), QStringList("-query") << "QT_INSTALL_DOCS");
p->start();
connect(p, SIGNAL(finished(int)), SLOT(lookupDone(int)));
}
}
void QtHelpQtDoc::lookupDone(int code)
{
if(code==0) {
KProcess* p = qobject_cast<KProcess*>(sender());
QString path = QDir::fromNativeSeparators(QString::fromLatin1(p->readAllStandardOutput()));
loadDirectory(path+"/qch/");
}
sender()->deleteLater();
}
void QtHelpQtDoc::loadDirectory(const QString& path)
{
if(path.isEmpty()) {
kDebug() << "no QtHelp found at all";
return;
}
if(!dirName.isEmpty()) {
QDir d(dirName);
foreach(const QString& file, d.entryList(QDir::Files)) {
QString fileName=dirName+'/'+file;
QString fileNamespace = QHelpEngineCore::namespaceName(fileName);
if (!fileNamespace.isEmpty() && !m_engine.registeredDocumentations().contains(fileNamespace)) {
kDebug() << "loading doc" << fileName << fileNamespace;
if(m_engine.registerDocumentation(fileName))
kDebug() << "documentation added successfully" << fileName;
else
kDebug() << "error >> " << fileName << m_engine.error();
}
QDir d(path);
foreach(const QString& file, d.entryList(QDir::Files)) {
QString fileName=path+'/'+file;
QString fileNamespace = QHelpEngineCore::namespaceName(fileName);
if (!fileNamespace.isEmpty() && !m_engine.registeredDocumentations().contains(fileNamespace)) {
kDebug() << "loading doc" << fileName << fileNamespace;
if(!m_engine.registerDocumentation(fileName))
kDebug() << "error >> " << fileName << m_engine.error();
}
kDebug() << "registered" << m_engine.error() << m_engine.registeredDocumentations();
}
else
kDebug() << "no QtHelp found at all";
kDebug() << "registered" << m_engine.error() << m_engine.registeredDocumentations();
}
QIcon QtHelpQtDoc::icon() const
......
......@@ -31,6 +31,12 @@ class QtHelpQtDoc : public QtHelpProviderAbstract
virtual QIcon icon() const;
virtual QString name() const;
void registerDocumentations();
private:
void loadDirectory(const QString& path);
private slots:
void lookupDone(int code);
};
#endif // QTHELPQTDOC_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment