66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
#include "kateaiconfigpage.h"
|
|
|
|
#include <KConfigGroup>
|
|
#include <KLocalizedString>
|
|
#include <KSharedConfig>
|
|
|
|
#include <QVBoxLayout>
|
|
#include <QLabel>
|
|
#include <qlabel.h>
|
|
|
|
KateAiConfigPage::KateAiConfigPage(QWidget *parent, KateAiPlugin *plugin)
|
|
: KTextEditor::ConfigPage(parent)
|
|
, m_plugin(plugin)
|
|
{
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
QHBoxLayout* lineLayout = new QHBoxLayout(this);
|
|
QLabel* lineEditLabel = new QLabel(i18n("Url for the WebSockets ExLlama Ai server:"), this);
|
|
lineEditLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
|
|
lineLayout->addWidget(lineEditLabel);
|
|
lineLayout->addWidget(&lineUrl);
|
|
layout->addLayout(lineLayout);
|
|
|
|
btnCompletion.setText(i18n("Use the Ai to generate a completion"));
|
|
btnInstruct.setText(i18n("Use the Ai to insert a response to a instruction"));
|
|
layout->addWidget(&btnCompletion);
|
|
layout->addWidget(&btnInstruct);
|
|
layout->addStretch();
|
|
|
|
reset();
|
|
}
|
|
|
|
QString KateAiConfigPage::name() const
|
|
{
|
|
return i18n("Ai");
|
|
}
|
|
|
|
QString KateAiConfigPage::fullName() const
|
|
{
|
|
return i18n("Ai Settings");
|
|
}
|
|
|
|
QIcon KateAiConfigPage::icon() const
|
|
{
|
|
return QIcon::fromTheme(QStringLiteral("text-x-generic"));
|
|
}
|
|
|
|
void KateAiConfigPage::apply()
|
|
{
|
|
KConfigGroup config(KSharedConfig::openConfig(), "Ai");
|
|
config.writeEntry("Url", lineUrl.text());
|
|
config.writeEntry("Instruct", btnInstruct.isChecked());
|
|
|
|
config.sync();
|
|
m_plugin->readConfig();
|
|
}
|
|
|
|
void KateAiConfigPage::reset()
|
|
{
|
|
KConfigGroup config(KSharedConfig::openConfig(), "Ai");
|
|
lineUrl.setText(config.readEntry("Url", "ws://localhost:8642"));
|
|
btnInstruct.setChecked(config.readEntry("Instruct", false));
|
|
btnCompletion.setChecked(!btnInstruct.isChecked());
|
|
}
|