Commit 381d6357 authored by Alexander Semke's avatar Alexander Semke
Browse files

Refactored the logic in the documentation panel widget to used the

documentation files that were saved in the settings and not those that
were hard-coded in the code and some additional minor cleanup.
parent 3dc7eead
......@@ -16,7 +16,7 @@
---
Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
Copyright (C) 2019 Alexander Semke <alexander.semke@web.de>
Copyright (C) 2019-2020 Alexander Semke <alexander.semke@web.de>
*/
#include "maximabackend.h"
......@@ -91,7 +91,7 @@ QUrl MaximaBackend::helpUrl() const
QWidget* MaximaBackend::settingsWidget(QWidget* parent) const
{
return new MaximaSettingsWidget(parent);
return new MaximaSettingsWidget(parent, id());
}
KConfigSkeleton* MaximaBackend::config() const
......
......@@ -15,22 +15,20 @@
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#include "maximasettingswidget.h"
#include "maximabackend.h"
#include "../qthelpconfig.h"
#include <QDebug>
#include <KConfigGroup>
#include <KSharedConfig>
MaximaSettingsWidget::MaximaSettingsWidget(QWidget *parent) : QWidget(parent)
MaximaSettingsWidget::MaximaSettingsWidget(QWidget* parent, const QString& id) : QWidget(parent)
{
setupUi(this);
// Add QtHelp widget
QtHelpConfig* docWidget = new QtHelpConfig(QLatin1String("maxima"));
QtHelpConfig* docWidget = new QtHelpConfig(id);
auto hboxLayout = new QHBoxLayout(tabDocumentation);
hboxLayout->addWidget(docWidget);
}
......@@ -15,13 +15,13 @@
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#ifndef _MAXIMASETTINGSWIDGET_H
#define _MAXIMASETTINGSWIDGET_H
#include "../qthelpconfig.h"
#include "ui_settings.h"
class MaximaSettingsWidget : public QWidget, public Ui::MaximaSettingsBase
......@@ -29,7 +29,7 @@ class MaximaSettingsWidget : public QWidget, public Ui::MaximaSettingsBase
Q_OBJECT
public:
explicit MaximaSettingsWidget(QWidget* parent = nullptr);
explicit MaximaSettingsWidget(QWidget* parent = nullptr, const QString& id = QString());
};
#endif /* _MAXIMASETTINGSWIDGET_H */
......@@ -283,8 +283,8 @@ void QtHelpConfig::loadSettings()
const KConfigGroup group = KSharedConfig::openConfig()->group(m_backend);
QStringList nameList = group.readEntry(QLatin1String("Names"), QStringList());
QStringList pathList = group.readEntry(QLatin1String("Icons"), QStringList());
QStringList iconList = group.readEntry(QLatin1String("Paths"), QStringList());
QStringList pathList = group.readEntry(QLatin1String("Paths"), QStringList());
QStringList iconList = group.readEntry(QLatin1String("Icons"), QStringList());
QStringList ghnsList = group.readEntry(QLatin1String("Ghns"), QStringList());
// iterate through Name Location pairs and update the QTreeWidget
......@@ -318,8 +318,6 @@ void QtHelpConfig::saveSettings()
group.writeEntry(QLatin1String("Paths"), pathList);
group.writeEntry(QLatin1String("Icons"), iconList);
group.writeEntry(QLatin1String("Ghns"), ghnsList);
qDebug() << "settings changed";
}
#include "qthelpconfig.moc"
......@@ -23,6 +23,8 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QAction>
#include <QCompleter>
......@@ -51,14 +53,6 @@
DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(parent)
{
m_previousQch = QString();
// Maintain a map of backend -> doc files
m_helpFiles.insert(QLatin1String("Maxima"), {QLatin1String("Maxima_v5.42"), QLatin1String("Maxima_v5.44")});
m_helpFiles.insert(QLatin1String("Python"), {QLatin1String("Python_v3.8.4"), QLatin1String("NumPy_v1.19")});
m_helpFiles.insert(QLatin1String("Octave"), {QLatin1String("Octave_v5.2.0")});
m_helpFiles.insert(QLatin1String("Julia"), {QLatin1String("Julia_v1.5")});
m_textBrowser = new QWebEngineView(this);
m_textBrowser->page()->action(QWebEnginePage::ViewSource)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::OpenLinkInNewTab)->setVisible(false);
......@@ -264,16 +258,22 @@ void DocumentationPanelWidget::updateBackend(const QString& newBackend, const QS
return;
m_backend = newBackend;
m_initializing = true;
// show all available documentation files for the new backend
m_initializing = true;
m_documentationSelector->clear();
m_documentationSelector->addItems(m_helpFiles[m_backend]);
const KConfigGroup group = KSharedConfig::openConfig()->group(m_backend.toLower());
docNames = group.readEntry(QLatin1String("Names"), QStringList());
docPaths = group.readEntry(QLatin1String("Paths"), QStringList());
if (!docNames.isEmpty())
m_documentationSelector->addItems(docNames);
m_initializing = false;
//select the first available documentation file which will trigger the re-initialization of QHelpEngine
//TODO: restore from the saved state the previously selected documentation in m_documentationSelector for the current backend
m_documentationSelector->setCurrentIndex(0);
if (!docNames.isEmpty())
m_documentationSelector->setCurrentIndex(0);
updateDocumentation();
}
......@@ -297,21 +297,29 @@ void DocumentationPanelWidget::updateDocumentation()
}
//unregister the previous help engine qch files
if(m_previousQch != QString())
if(!m_previousQch.isEmpty())
{
const QString& fileNamespace = QHelpEngineCore::namespaceName(m_previousQch);
if(m_engine->registeredDocumentations().contains(fileNamespace))
m_engine->unregisterDocumentation(m_previousQch);
}
if (docNames.isEmpty())
{
m_textBrowser->hide();
return;
}
else
m_textBrowser->show();
//initialize the Qt Help engine and provide the proper help collection file for the current backend
//and for the currently selected documentation for this backend
const QString& docSelected = m_documentationSelector->currentText();
const QString& fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation,
QLatin1String("documentation/") + m_backend + QLatin1String("/") +
docSelected + QLatin1String("/help.qhc"));
int index = m_documentationSelector->currentIndex();
if (index < docPaths.size())
qchFileName = docPaths.at(index);
m_engine = new QHelpEngine(fileName, this);
const QString& qhcFileName = qchFileName.replace(QLatin1String("qch"), QLatin1String("qhc"));
m_engine = new QHelpEngine(qhcFileName, this);
/*if(!m_engine->setupData())
qWarning() << "Couldn't setup QtHelp Engine: " << m_engine->error();*/
......@@ -354,11 +362,7 @@ void DocumentationPanelWidget::updateDocumentation()
m_textBrowser->page()->profile()->installUrlSchemeHandler("qthelp", new QtHelpSchemeHandler(m_engine));
// register the compressed help file (qch)
const QString& qchFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation,
QLatin1String("documentation/") + m_backend + QLatin1String("/") + docSelected +
QLatin1String("/help.qch"));
m_previousQch = qchFileName;
const QString& nameSpace = QHelpEngineCore::namespaceName(qchFileName);
if(!m_engine->registeredDocumentations().contains(nameSpace))
{
......
......@@ -73,6 +73,8 @@ class DocumentationPanelWidget : public QWidget
QHelpIndexWidget* m_index = nullptr;
QHelpContentWidget* m_content = nullptr;
QString m_backend;
QStringList docNames;
QStringList docPaths;
bool m_initializing = false;
// member variables for find in page text widget
......
Markdown is supported
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