Commit 59cf8728 authored by Shubham  .'s avatar Shubham .
Browse files

Change the logic to save the settings

parent ed286943
......@@ -29,7 +29,7 @@ MaximaSettingsWidget::MaximaSettingsWidget(QWidget *parent) : QWidget(parent)
setupUi(this);
// Add QtHelp widget
QtHelpConfig* docWidget = new QtHelpConfig();
QtHelpConfig* docWidget = new QtHelpConfig(QLatin1String("maxima"));
static_cast<QGridLayout*>(this->layout())->addWidget(docWidget, 6, 0, 1, 3);
loadSettings(); // load previously saved settings from read KConfig
......
......@@ -23,7 +23,7 @@
#include "../qthelpconfig.h"
#include "ui_settings.h"
#include <QDebug>
class MaximaSettingsWidget : public QWidget, public Ui::MaximaSettingsBase
{
Q_OBJECT
......
......@@ -26,6 +26,6 @@ PythonSettingsWidget::PythonSettingsWidget(QWidget *parent) : QWidget(parent)
setupUi(this);
// Add QtHelp widget
QtHelpConfig* docWidget = new QtHelpConfig();
QtHelpConfig* docWidget = new QtHelpConfig(QLatin1String("python"));
static_cast<QGridLayout*>(this->layout())->addWidget(docWidget, 8, 0, 1, 5);
}
......@@ -91,8 +91,13 @@ void QtHelpConfigEditDialog::accept()
QDialog::accept();
}
QtHelpConfig::QtHelpConfig()
QtHelpConfig::QtHelpConfig(const QString& backend)
{
m_backend = backend;
// load settings for Install Additional Help Files widget
loadSettings();
m_configWidget = new Ui::QtHelpConfigUI;
m_configWidget->setupUi(this);
m_configWidget->addButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
......@@ -271,23 +276,49 @@ QTreeWidgetItem * QtHelpConfig::addTableItem(const QString &icon, const QString
return item;
}
void QtHelpConfig::loadSettings()
{
// load settings for current backend and then update the QTreeWidget
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 ghnsList = group.readEntry(QLatin1String("Ghns"), QStringList());;
// iterate through Name Location pairs and update the QTreeWidget
for(int i = 0; i < nameList.size(); i++)
{
QTreeWidgetItem* item = addTableItem(iconList.at(i), nameList.at(i), pathList.at(i), ghnsList.at(i));
m_configWidget->qchTable->setCurrentItem(item);
}
}
void QtHelpConfig::saveSettings()
{
qDebug() << "settings changed";
KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_Documentation"));
// create seperate group for sepearte backends
KConfigGroup group = KSharedConfig::openConfig()->group(m_backend);
QStringList name;
QStringList path;
QStringList nameList;
QStringList pathList;
QStringList iconList;
QStringList ghnsList;
for (int i = 0; i < m_configWidget->qchTable->topLevelItemCount(); i++)
{
const QTreeWidgetItem* item = m_configWidget->qchTable->topLevelItem(i);
name << item->text(0);
path << item->text(1);
nameList << item->text(0);
pathList << item->text(1);
iconList << item->text(2);
ghnsList << item->text(3);
}
group.writeEntry(QLatin1String("Names"), name);
group.writeEntry(QLatin1String("Paths"), path);
group.writeEntry(QLatin1String("Names"), nameList);
group.writeEntry(QLatin1String("Paths"), pathList);
group.writeEntry(QLatin1String("Icons"), iconList);
group.writeEntry(QLatin1String("Ghns"), ghnsList);
qDebug() << "settings changed";
}
#include "qthelpconfig.moc"
......@@ -36,7 +36,7 @@ class QtHelpConfig : public QWidget
Q_OBJECT
public:
explicit QtHelpConfig();
explicit QtHelpConfig(const QString&);
~QtHelpConfig();
bool checkNamespace(const QString &filename, QTreeWidgetItem* modifiedItem);
......@@ -51,6 +51,7 @@ class QtHelpConfig : public QWidget
void knsUpdate(const KNS3::Entry::List& list);
public Q_SLOTS:
void loadSettings();
void saveSettings();
private:
......@@ -58,6 +59,7 @@ class QtHelpConfig : public QWidget
const QString &path, const QString &ghnsStatus);
Ui::QtHelpConfigUI* m_configWidget;
QString m_backend;
};
#endif // QTHELPCONFIG_H
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