Commit 320384f1 authored by Shubham  .'s avatar Shubham .
Browse files

Change the logic, move the common qthelp widget code to src/backends

parent 80e03223
......@@ -26,7 +26,7 @@ set(cantor_SRCS
main.cpp
cantor.cpp
backendchoosedialog.cpp
)
)
install(FILES cantor.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
......
......@@ -14,6 +14,16 @@ add_subdirectory(maxima)
add_subdirectory(octave)
add_subdirectory(scilab)
set(cantor_HELP
qthelpconfig.cpp
)
ki18n_wrap_ui(cantor_HELP qthelpconfig.ui)
ki18n_wrap_ui(cantor_HELP qthelpconfigeditdialog.ui)
add_library(cantor_help STATIC ${cantor_HELP})
target_link_libraries(cantor_help KF5::SyntaxHighlighting KF5::I18n KF5::IconThemes KF5::NewStuff KF5::KIOWidgets Qt5::Help)
if(NOT WIN32)
add_subdirectory(sage)
endif(NOT WIN32)
......
......@@ -17,7 +17,7 @@ ki18n_wrap_ui(MaximaBackend_SRCS settings.ui)
add_backend(maximabackend ${MaximaBackend_SRCS})
target_link_libraries(cantor_maximabackend KF5::SyntaxHighlighting KF5::I18n KF5::IconThemes KF5::NewStuff KF5::KIOWidgets Qt5::Help)
target_link_libraries(cantor_maximabackend cantor_help)
if(BUILD_TESTING)
add_executable( testmaxima testmaxima.cpp)
......
......@@ -17,7 +17,6 @@
---
Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
Copyright (C) 2019 Alexander Semke <alexander.semke@web.de>
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#include "maximabackend.h"
......@@ -25,6 +24,8 @@
#include "maximasession.h"
#include "settings.h"
#include "../qthelpconfig.h"
MaximaBackend::MaximaBackend( QObject* parent,const QList<QVariant> args ) : Cantor::Backend( parent,args )
{
//initialize the supported extensions
......@@ -94,6 +95,10 @@ QWidget* MaximaBackend::settingsWidget(QWidget* parent) const
QWidget* widget = new QWidget(parent);
Ui::MaximaSettingsBase s;
s.setupUi(widget);
QtHelpConfig* docWidget = new QtHelpConfig();
s.verticalLayout->addWidget(docWidget);
return widget;
}
......
......@@ -16,14 +16,11 @@
---
Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#ifndef _MAXIMABACKEND_H
#define _MAXIMABACKEND_H
#include <KNS3/Button>
#include "backend.h"
#include "ui_settings.h"
#include "ui_qthelpconfigeditdialog.h"
......
......@@ -11,6 +11,43 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="QCheckBox" name="kcfg_integratePlots">
<property name="toolTip">
<string>If enabled, plots will be shown inside of the worksheet. Otherwise, plots will be shown in an external window.</string>
</property>
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KUrlRequester" name="kcfg_localDoc">
<property name="toolTip">
<string>If empty, the &quot;Show help&quot; action will show the default online documentation. Otherwise, the specified URL will be opened.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lVariableManagement">
<property name="text">
<string>Variable Management:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>96</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="toolTip">
......@@ -26,10 +63,10 @@
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="KUrlRequester" name="kcfg_localDoc">
<property name="toolTip">
<string>If empty, the &quot;Show help&quot; action will show the default online documentation. Otherwise, the specified URL will be opened.</string>
<item row="1" column="0">
<widget class="QLabel" name="label2">
<property name="text">
<string>Documentation:</string>
</property>
</widget>
</item>
......@@ -50,16 +87,6 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="kcfg_integratePlots">
<property name="toolTip">
<string>If enabled, plots will be shown inside of the worksheet. Otherwise, plots will be shown in an external window.</string>
</property>
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="kcfg_variableManagement">
<property name="toolTip">
......@@ -70,32 +97,8 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label2">
<property name="text">
<string>Documentation:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lVariableManagement">
<property name="text">
<string>Variable Management:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>96</height>
</size>
</property>
</spacer>
<layout class="QVBoxLayout" name="verticalLayout"/>
</item>
</layout>
</widget>
......
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#include <QDebug>
#include <QHeaderView>
#include <QHelpEngineCore>
#include <QPointer>
#include <QToolButton>
#include <KLocalizedString>
#include <KMessageBox>
#include <KNS3/Button>
#include "qthelpconfig.h"
#include "ui_qthelpconfigeditdialog.h"
#include "ui_qthelpconfig.h"
enum Column
{
NameColumn,
PathColumn,
IconColumn,
GhnsColumn,
ConfigColumn
};
class QtHelpConfigEditDialog : public QDialog, public Ui_QtHelpConfigEditDialog
{
Q_OBJECT
public:
explicit QtHelpConfigEditDialog(QTreeWidgetItem* modifiedItem, QtHelpConfig* parent = nullptr)
: QDialog(parent)
, m_modifiedItem(modifiedItem)
, m_config(parent)
{
setupUi(this);
if (modifiedItem) {
setWindowTitle(i18nc("@title:window", "Modify Entry"));
} else {
setWindowTitle(i18nc("@title:window", "Add New Entry"));
}
qchIcon->setIcon(QStringLiteral("qtlogo"));
}
bool checkQtHelpFile();
void accept() override;
private:
QTreeWidgetItem* m_modifiedItem;
QtHelpConfig* m_config;
};
bool QtHelpConfigEditDialog::checkQtHelpFile()
{
//verify if the file is valid and if there is a name
if(qchName->text().isEmpty()){
KMessageBox::error(this, i18n("Name cannot be empty."));
return false;
}
return m_config->checkNamespace(qchRequester->text(), m_modifiedItem);
}
void QtHelpConfigEditDialog::accept()
{
if (!checkQtHelpFile())
return;
QDialog::accept();
}
QtHelpConfig::QtHelpConfig()
{
m_configWidget = new Ui::QtHelpConfigUI;
m_configWidget->setupUi(this);
m_configWidget->addButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
connect(m_configWidget->addButton, &QPushButton::clicked, this, &QtHelpConfig::add);
// Table
m_configWidget->qchTable->setColumnHidden(IconColumn, true);
m_configWidget->qchTable->setColumnHidden(GhnsColumn, true);
m_configWidget->qchTable->model()->setHeaderData(ConfigColumn, Qt::Horizontal, QVariant());
m_configWidget->qchTable->header()->setSectionsMovable(false);
m_configWidget->qchTable->header()->setStretchLastSection(false);
m_configWidget->qchTable->header()->setSectionResizeMode(NameColumn, QHeaderView::Stretch);
m_configWidget->qchTable->header()->setSectionResizeMode(PathColumn, QHeaderView::Stretch);
m_configWidget->qchTable->header()->setSectionResizeMode(ConfigColumn, QHeaderView::Fixed);
// Add GHNS button // shift this code to backend specific
auto* knsButton = new KNS3::Button(i18nc("@action:button Allow user to get some API documentation with GHNS", "Get New Documentation"), QStringLiteral("kdevelop-qthelp.knsrc"), m_configWidget->boxQchManage);
m_configWidget->tableCtrlLayout->insertWidget(1, knsButton);
connect(knsButton, &KNS3::Button::dialogFinished, this, &QtHelpConfig::knsUpdate);
reset();
}
QtHelpConfig::~QtHelpConfig()
{
delete m_configWidget;
}
void QtHelpConfig::apply()
{
QStringList iconList, nameList, pathList, ghnsList;
for (int i = 0; i < m_configWidget->qchTable->topLevelItemCount(); i++) {
const QTreeWidgetItem* item = m_configWidget->qchTable->topLevelItem(i);
nameList << item->text(0);
pathList << item->text(1);
iconList << item->text(2);
ghnsList << item->text(3);
}
//qtHelpWriteConfig(iconList, nameList, pathList, ghnsList, searchDir, loadQtDoc);
//static_cast<QtHelpPlugin*>(plugin())->readConfig();*/
}
void QtHelpConfig::reset()
{
m_configWidget->qchTable->clear();
QStringList iconList, nameList, pathList, ghnsList;
//QString searchDir;
//bool loadQtDoc;
//qtHelpReadConfig(iconList, nameList, pathList, ghnsList, searchDir, loadQtDoc);
const int size = qMin(qMin(iconList.size(), nameList.size()), pathList.size());
for(int i = 0; i < size; ++i) {
QString ghnsStatus = ghnsList.size()>i ? ghnsList.at(i) : QStringLiteral("0");
addTableItem(iconList.at(i), nameList.at(i), pathList.at(i), ghnsStatus);
}
}
void QtHelpConfig::defaults()
{
if(m_configWidget->qchTable->topLevelItemCount() > 0) {
m_configWidget->qchTable->clear();
}
}
void QtHelpConfig::add()
{
QPointer<QtHelpConfigEditDialog> dialog = new QtHelpConfigEditDialog(nullptr, this);
if (dialog->exec()) {
QTreeWidgetItem* item = addTableItem(dialog->qchIcon->icon(), dialog->qchName->text(), dialog->qchRequester->text(), QStringLiteral("0"));
m_configWidget->qchTable->setCurrentItem(item);
}
delete dialog;
}
void QtHelpConfig::modify(QTreeWidgetItem* item)
{
if (!item)
return;
QPointer<QtHelpConfigEditDialog> dialog = new QtHelpConfigEditDialog(item, this);
if (item->text(GhnsColumn) != QLatin1String("0"))
{
dialog->qchRequester->setText(i18n("Documentation provided by GHNS"));
dialog->qchRequester->setEnabled(false);
}
else
{
dialog->qchRequester->setText(item->text(PathColumn));
dialog->qchRequester->setEnabled(true);
}
dialog->qchName->setText(item->text(NameColumn));
dialog->qchIcon->setIcon(item->text(IconColumn));
if (dialog->exec()) {
item->setIcon(NameColumn, QIcon(dialog->qchIcon->icon()));
item->setText(NameColumn, dialog->qchName->text());
item->setText(IconColumn, dialog->qchIcon->icon());
if(item->text(GhnsColumn) == QLatin1String("0")) {
item->setText(PathColumn, dialog->qchRequester->text());
}
}
delete dialog;
}
bool QtHelpConfig::checkNamespace(const QString& filename, QTreeWidgetItem* modifiedItem)
{
QString qtHelpNamespace = QHelpEngineCore::namespaceName(filename);
if (qtHelpNamespace.isEmpty()) {
// Open error message (not valid Qt Compressed Help file)
KMessageBox::error(this, i18n("Qt Compressed Help file is not valid."));
return false;
}
// verify if it's the namespace it's not already in the list
for(int i=0; i < m_configWidget->qchTable->topLevelItemCount(); i++) {
const QTreeWidgetItem* item = m_configWidget->qchTable->topLevelItem(i);
if (item != modifiedItem){
if (qtHelpNamespace == QHelpEngineCore::namespaceName(item->text(PathColumn))) {
// Open error message, documentation already imported
KMessageBox::error(this, i18n("Documentation already imported"));
return false;
}
}
}
return true;
}
void QtHelpConfig::remove(QTreeWidgetItem* item)
{
if (!item)
return;
delete item;
}
void QtHelpConfig::knsUpdate(const KNS3::Entry::List& list)
{
if (list.isEmpty())
return;
for (const KNS3::Entry& e : list) {
if(e.status() == KNS3::Entry::Installed) {
// For zipped/tarred QCH files KNewStuff also adds the directory as installed file, first file entry is assumed to be QCH file though
if (e.installedFiles().size() >= 1) {
QString filename = e.installedFiles().at(0);
if(checkNamespace(filename, nullptr)){
QTreeWidgetItem* item = addTableItem(QStringLiteral("documentation"), e.name(), filename, QStringLiteral("1"));
m_configWidget->qchTable->setCurrentItem(item);
} else {
qDebug() << "namespace error";
}
}
} else if(e.status() == KNS3::Entry::Deleted) {
// cmp. note above for installed files
if (e.uninstalledFiles().size() >= 1) {
for(int i=0; i < m_configWidget->qchTable->topLevelItemCount(); i++) {
QTreeWidgetItem* item = m_configWidget->qchTable->topLevelItem(i);
if (e.uninstalledFiles().at(0) == item->text(PathColumn)) {
delete item;
break;
}
}
}
}
}
}
QTreeWidgetItem * QtHelpConfig::addTableItem(const QString &icon, const QString &name,
const QString &path, const QString &ghnsStatus)
{
auto *item = new QTreeWidgetItem(m_configWidget->qchTable);
item->setIcon(NameColumn, QIcon::fromTheme(icon));
item->setText(NameColumn, name);
item->setToolTip(NameColumn, name);
item->setText(PathColumn, path);
item->setToolTip(PathColumn, path);
item->setText(IconColumn, icon);
item->setText(GhnsColumn, ghnsStatus);
auto* ctrlWidget = new QWidget(item->treeWidget());
ctrlWidget->setLayout(new QHBoxLayout(ctrlWidget));
auto *modifyBtn = new QToolButton(item->treeWidget());
modifyBtn->setIcon(QIcon::fromTheme(QStringLiteral("document-edit")));
modifyBtn->setToolTip(i18nc("@info:tooltip", "Modify"));
connect(modifyBtn, &QPushButton::clicked, this, [=](){
modify(item);
});
auto *removeBtn = new QToolButton(item->treeWidget());
removeBtn->setIcon(QIcon::fromTheme(QStringLiteral("entry-delete")));
removeBtn->setToolTip(i18nc("@info:tooltip", "Delete"));
if (item->text(GhnsColumn) != QLatin1String("0")) {
// KNS3 currently does not provide API to uninstall entries
// just removing the files results in wrong installed states in the KNS3 dialog
// TODO: add API to KNS to remove files without UI interaction
removeBtn->setEnabled(false);
removeBtn->setToolTip(i18nc("@info:tooltip", "Please uninstall this via GHNS."));
} else {
connect(removeBtn, &QPushButton::clicked, this, [=](){
remove(item);
});
}
ctrlWidget->layout()->addWidget(modifyBtn);
ctrlWidget->layout()->addWidget(removeBtn);
m_configWidget->qchTable->setItemWidget(item, ConfigColumn, ctrlWidget);
return item;
}
#include "qthelpconfig.moc"
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#ifndef QTHELPCONFIG_H
#define QTHELPCONFIG_H
#include <QWidget>
#include <KNS3/Entry>
class QTreeWidgetItem;
namespace Ui
{
class QtHelpConfigUI;
}
class QtHelpConfig : public QWidget
{
public:
explicit QtHelpConfig();
~QtHelpConfig();
bool checkNamespace(const QString &filename, QTreeWidgetItem* modifiedItem);
private Q_SLOTS:
void add();
void remove(QTreeWidgetItem* item);
void modify(QTreeWidgetItem* item);
void knsUpdate(const KNS3::Entry::List& list);
public Q_SLOTS:
void apply();
void defaults();
void reset();
private:
QTreeWidgetItem * addTableItem(const QString &icon, const QString &name,
const QString &path, const QString &ghnsStatus);
Ui::QtHelpConfigUI* m_configWidget;
};
#endif // QTHELPCONFIG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QtHelpConfigUI</class>
<widget class="QWidget" name="QtHelpConfigUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>443</height>
</rect>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="boxQchManage">
<property name="title">
<string comment="@title:group">Install Additional Documentation Files</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeWidget" name="qchTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>