KDE PIM support for the p≡p engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

84 lines
3.0 KiB

/*
SPDX-FileCopyrightText: 2017-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "pepcomposerconfigurewidget.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KUrlRequester>
#include <QCheckBox>
#include <QLabel>
#include <QVBoxLayout>
pEpComposerConfigureWidget::pEpComposerConfigureWidget(QWidget *parent)
: MessageComposer::PluginEditorConfigureBaseWidget(parent)
, mpEpEditorCheck(new QCheckBox(i18n("Use pep editor instead of composer"), this))
, mEditorRequester(new KUrlRequester(this))
{
auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins({});
mainLayout->setObjectName(QStringLiteral("mainlayout"));
mpEpEditorCheck->setObjectName(QStringLiteral("enabled"));
mpEpEditorCheck->setChecked(false);
mainLayout->addWidget(mpEpEditorCheck);
auto hbox = new QHBoxLayout;
auto label = new QLabel(QStringLiteral("Specify editor:"), this);
label->setObjectName(QStringLiteral("urlrequesterlabel"));
hbox->addWidget(label);
mEditorRequester->setObjectName(QStringLiteral("mEditorRequester"));
hbox->addWidget(mEditorRequester);
mEditorRequester->setMimeTypeFilters(
{QStringLiteral("application/x-executable"), QStringLiteral("application/x-shellscript"), QStringLiteral("application/x-desktop")});
mEditorRequester->setMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly);
mEditorRequester->setEnabled(false);
mainLayout->addLayout(hbox);
label = new QLabel(i18n("<b>%f</b> will be replaced with the "
"filename to edit.<br />"
"<b>%w</b> will be replaced with the window id.<br />"
"<b>%l</b> will be replaced with the line number."),
this);
label->setObjectName(QStringLiteral("explanationlabel"));
label->setEnabled(false); // see above
mainLayout->addWidget(label);
mainLayout->addStretch(1);
connect(mpEpEditorCheck, &QAbstractButton::toggled, label, &QWidget::setEnabled);
connect(mpEpEditorCheck, &QAbstractButton::toggled, mEditorRequester, &QWidget::setEnabled);
}
pEpComposerConfigureWidget::~pEpComposerConfigureWidget()
{
}
void pEpComposerConfigureWidget::loadSettings()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(QStringLiteral("pEp Composer"));
mpEpEditorCheck->setChecked(group.readEntry("Enabled", false));
mEditorRequester->setText(group.readEntry("ComposerPath", QStringLiteral("kwrite %f")));
}
void pEpComposerConfigureWidget::saveSettings()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(QStringLiteral("pEp Composer"));
group.writeEntry("Enabled", mpEpEditorCheck->isChecked());
group.writeEntry("ComposerPath", mEditorRequester->text());
}
void pEpComposerConfigureWidget::resetSettings()
{
mpEpEditorCheck->setChecked(false);
mEditorRequester->setText(QStringLiteral("kwrite %f"));
}