File indexing completed on 2024-05-12 04:38:18

0001 /*
0002     SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "environmentpreferences.h"
0008 
0009 #include <QVBoxLayout>
0010 
0011 #include <KConfigSkeleton>
0012 #include <KLocalizedString>
0013 #include <KSharedConfig>
0014 
0015 #include "environmentwidget.h"
0016 
0017 namespace KDevelop
0018 {
0019 
0020 class EnvironmentPreferencesPrivate
0021 {
0022 public:
0023     EnvironmentWidget *preferencesDialog;
0024     KConfigSkeleton* skel;
0025     QString preselectedProfileName;
0026 };
0027 
0028 EnvironmentPreferences::EnvironmentPreferences(const QString& preselectedProfileName, QWidget* parent)
0029     : ConfigPage(nullptr, nullptr, parent)
0030     , d_ptr(new EnvironmentPreferencesPrivate)
0031 {
0032     Q_D(EnvironmentPreferences);
0033 
0034     auto * l = new QVBoxLayout( this );
0035     l->setContentsMargins(0, 0, 0, 0);
0036     d->preferencesDialog = new EnvironmentWidget( this );
0037     l->addWidget( d->preferencesDialog );
0038 
0039     connect(d->preferencesDialog, &EnvironmentWidget::changed,
0040             this, &EnvironmentPreferences::changed);
0041 
0042     d->skel = new KConfigSkeleton(KSharedConfig::openConfig(), this);
0043     setConfigSkeleton(d->skel);
0044 
0045     d->preselectedProfileName = preselectedProfileName;
0046 }
0047 
0048 EnvironmentPreferences::~EnvironmentPreferences() = default;
0049 
0050 void EnvironmentPreferences::apply()
0051 {
0052     Q_D(EnvironmentPreferences);
0053 
0054     d->preferencesDialog->saveSettings(d->skel->config());
0055     ConfigPage::apply();
0056 }
0057 
0058 void EnvironmentPreferences::reset()
0059 {
0060     Q_D(EnvironmentPreferences);
0061 
0062     d->preferencesDialog->loadSettings(d->skel->config());
0063     if (!d->preselectedProfileName.isEmpty()) {
0064         d->preferencesDialog->selectProfile(d->preselectedProfileName);
0065     }
0066     ConfigPage::reset();
0067 }
0068 
0069 void EnvironmentPreferences::defaults()
0070 {
0071     Q_D(EnvironmentPreferences);
0072 
0073     d->preferencesDialog->defaults(d->skel->config());
0074     ConfigPage::defaults();
0075 }
0076 
0077 QString EnvironmentPreferences::name() const
0078 {
0079     return i18n("Environment");
0080 }
0081 
0082 QString EnvironmentPreferences::fullName() const
0083 {
0084     return i18n("Configure Environment Variables");
0085 }
0086 
0087 QIcon EnvironmentPreferences::icon() const
0088 {
0089     return QIcon::fromTheme(QStringLiteral("utilities-terminal"));
0090 }
0091 
0092 }
0093 
0094 #include "moc_environmentpreferences.cpp"