Commit cf0f0b8f authored by Shubham  .'s avatar Shubham .
Browse files

Add widget to add local qch files

parent f33b3b06
......@@ -17,7 +17,7 @@ ki18n_wrap_ui(MaximaBackend_SRCS settings.ui qthelpconfigeditdialog.ui)
add_backend(maximabackend ${MaximaBackend_SRCS})
target_link_libraries(cantor_maximabackend KF5::SyntaxHighlighting)
target_link_libraries(cantor_maximabackend KF5::SyntaxHighlighting KF5::I18n KF5::IconThemes KF5::NewStuff KF5::KIOWidgets Qt5::Help)
if(BUILD_TESTING)
add_executable( testmaxima testmaxima.cpp)
......
......@@ -24,8 +24,23 @@
#include "maximaextensions.h"
#include "maximasession.h"
#include "settings.h"
#include "ui_settings.h"
#include "ui_qthelpconfigeditdialog.h"
#include <QDialog>
#include <QHelpEngineCore>
#include <QPointer>
#include <QToolButton>
#include <QTreeWidgetItem>
#include <KMessageBox>
enum Column
{
NameColumn,
PathColumn,
IconColumn,
GhnsColumn,
ConfigColumn
};
MaximaBackend::MaximaBackend( QObject* parent,const QList<QVariant> args ) : Cantor::Backend( parent,args )
{
......@@ -93,9 +108,16 @@ QUrl MaximaBackend::helpUrl() const
QWidget* MaximaBackend::settingsWidget(QWidget* parent) const
{
QWidget* widget=new QWidget(parent);
Ui::MaximaSettingsBase s;
s.setupUi(widget);
QWidget* widget = new QWidget(parent);
m_settings = new Ui::MaximaSettingsBase;
m_settings->setupUi(widget);
// KNewStuff button (Get New Documentation)
/*auto* knsButton = new KNS3::Button(i18nc("@action:button Allow user to get some API documentation with GHNS", "Get New Documentation"), QStringLiteral("cantor_maxima.knsrc"), m_settings->groupBox2);
m_settings->horizontalLayout_2->insertWidget(1, knsButton);
connect(knsButton, &KNS3::Button::dialogFinished, this, &MaximaBackend::knsUpdate);*/
connect(m_settings->add, &QPushButton::clicked, this, &MaximaBackend::add);
return widget;
}
......@@ -114,5 +136,96 @@ QString MaximaBackend::description() const
"floating point numbers. Maxima can plot functions and data in two and three dimensions.");
}
void MaximaBackend::add()
{
QPointer<QtHelpConfigEditDialog> dialog = new QtHelpConfigEditDialog(nullptr);
if (dialog->exec())
{
QTreeWidgetItem* item = addTableItem(dialog->qchIcon->icon(), dialog->qchName->text(), dialog->qchRequester->text(), QStringLiteral("0"));
m_settings->qchTable->setCurrentItem(item);
}
delete dialog;
}
void MaximaBackend::remove(QTreeWidgetItem*)
{
}
void MaximaBackend::modify(QTreeWidgetItem* item)
{
}
void MaximaBackend::knsUpdate(const KNS3::Entry::List& list)
{
Q_UNUSED(list)
}
bool MaximaBackend::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(nullptr, 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_settings->qchTable->topLevelItemCount(); i++) {
const QTreeWidgetItem* item = m_settings->qchTable->topLevelItem(i);
if (item != modifiedItem){
if (qtHelpNamespace == QHelpEngineCore::namespaceName(item->text(PathColumn))) {
// Open error message, documentation already imported
KMessageBox::error(nullptr, i18n("Documentation already imported"));
return false;
}
}
}
return true;
}
QTreeWidgetItem* MaximaBackend::addTableItem(const QString &icon, const QString &name, const QString &path, const QString &ghnsStatus)
{
auto *item = new QTreeWidgetItem(m_settings->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_settings->qchTable->setItemWidget(item, ConfigColumn, ctrlWidget);
return item;
}
K_PLUGIN_FACTORY_WITH_JSON(maximabackend, "maximabackend.json", registerPlugin<MaximaBackend>();)
#include "maximabackend.moc"
......@@ -16,12 +16,20 @@
---
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"
class QDialog;
class QTreeWidgetItem;
class MaximaBackend : public Cantor::Backend
{
......@@ -41,7 +49,49 @@ class MaximaBackend : public Cantor::Backend
KConfigSkeleton* config() const override;
QString description() const override;
private Q_SLOTS:
void add();
void remove(QTreeWidgetItem*);
void modify(QTreeWidgetItem*);
void knsUpdate(const KNS3::Entry::List&);
private:
void modify();
QTreeWidgetItem* addTableItem(const QString &, const QString &, const QString &, const QString &);
bool checkNamespace(const QString&, QTreeWidgetItem*);
private:
mutable Ui::MaximaSettingsBase* m_settings;
};
// class for qt help file installation
class QtHelpConfigEditDialog : public QDialog, public Ui_QtHelpConfigEditDialog
{
Q_OBJECT
public:
explicit QtHelpConfigEditDialog(QTreeWidgetItem* modifiedItem)
: m_modifiedItem(modifiedItem)
{
setupUi(this);
if (modifiedItem)
{
setWindowTitle(i18nc("@title:window", "Modify Entry"));
}
else
{
setWindowTitle(i18nc("@title:window", "Add New Entry"));
}
qchIcon->setIcon(QStringLiteral("maximabackend"));
}
bool checkQtHelpFile();
//void accept() override;
private:
QTreeWidgetItem* m_modifiedItem;
};
#endif /* _MAXIMABACKEND_H */
......@@ -88,7 +88,7 @@
</property>
<layout class="QVBoxLayout" name="container">
<item>
<widget class="QTreeWidget" name="treeWidget">
<widget class="QTreeWidget" name="qchTable">
<column>
<property name="text">
<string notr="true">1</string>
......@@ -97,13 +97,12 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="add">
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset theme="project_add">
<normaloff>.</normaloff>.</iconset>
<iconset theme="list-add"/>
</property>
</widget>
</item>
......
......@@ -243,7 +243,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
DocumentationPanelWidget::~DocumentationPanelWidget()
{
delete m_index; //this crashes
delete m_index;
delete m_content;
delete m_engine;
delete m_textBrowser;
......
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