File indexing completed on 2024-05-05 04:39:18
0001 /* 0002 SPDX-FileCopyrightText: 2018 Anton Anikin <anton@anikin.xyz> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "globalconfigpage.h" 0008 #include "ui_globalconfigpage.h" 0009 0010 #include "checksdb.h" 0011 #include "globalsettings.h" 0012 #include "checksetselectionmanager.h" 0013 0014 namespace Clazy 0015 { 0016 0017 GlobalConfigPage::GlobalConfigPage(CheckSetSelectionManager* checkSetSelectionManager, 0018 const QSharedPointer<const ChecksDB>& db, 0019 KDevelop::IPlugin* plugin, QWidget* parent) 0020 : ConfigPage(plugin, GlobalSettings::self(), parent) 0021 , m_checkSetSelectionManager(checkSetSelectionManager) 0022 { 0023 ui = new Ui::GlobalConfigPage(); 0024 ui->setupUi(this); 0025 ui->checksets->setCheckSetSelectionManager(checkSetSelectionManager, db); 0026 0027 auto checkPaths = [&]() { 0028 ChecksDB db(ui->kcfg_docsPath->url()); 0029 ui->checksInfoLabel->setText(i18np("1 check detected", "%1 checks detected", db.checks().size())); 0030 0031 JobGlobalParameters params(ui->kcfg_executablePath->url(), ui->kcfg_docsPath->url()); 0032 if (!params.isValid()) { 0033 ui->errorWidget->setText(params.error()); 0034 ui->errorWidget->setVisible(true); 0035 return; 0036 } 0037 0038 if (!db.isValid()) { 0039 ui->errorWidget->setText(db.error()); 0040 ui->errorWidget->setVisible(true); 0041 return; 0042 } 0043 0044 ui->errorWidget->setVisible(false); 0045 }; 0046 0047 connect(ui->kcfg_executablePath, &KUrlRequester::textChanged, this, checkPaths); 0048 connect(ui->kcfg_docsPath, &KUrlRequester::textChanged, this, checkPaths); 0049 0050 checkPaths(); 0051 ui->kcfg_executablePath->setPlaceholderText(ui->kcfg_executablePath->toolTip()); 0052 ui->kcfg_docsPath->setPlaceholderText(ui->kcfg_docsPath->toolTip()); 0053 0054 auto checkJobs = [&]() { 0055 const bool jobsEnabled = ui->kcfg_parallelJobsEnabled->checkState() == Qt::Checked; 0056 const bool autoEnabled = ui->kcfg_parallelJobsAutoCount->checkState() == Qt::Checked; 0057 0058 ui->kcfg_parallelJobsAutoCount->setEnabled(jobsEnabled); 0059 0060 ui->kcfg_parallelJobsFixedCount->setEnabled(jobsEnabled && !autoEnabled); 0061 ui->parallelJobsFixedCountLabel->setEnabled(jobsEnabled && !autoEnabled); 0062 }; 0063 0064 connect(ui->kcfg_parallelJobsEnabled, &QCheckBox::stateChanged, this, checkJobs); 0065 connect(ui->kcfg_parallelJobsAutoCount, &QCheckBox::stateChanged, this, checkJobs); 0066 connect(ui->checksets, &CheckSetManageWidget::changed, 0067 this, &GlobalConfigPage::changed); 0068 0069 checkJobs(); 0070 } 0071 0072 KDevelop::ConfigPage::ConfigPageType GlobalConfigPage::configPageType() const 0073 { 0074 return KDevelop::ConfigPage::AnalyzerConfigPage; 0075 } 0076 0077 QString GlobalConfigPage::name() const 0078 { 0079 return i18nc("@title:tab", "Clazy"); 0080 } 0081 0082 QString GlobalConfigPage::fullName() const 0083 { 0084 return i18nc("@title:tab", "Configure Clazy Settings"); 0085 } 0086 0087 QIcon GlobalConfigPage::icon() const 0088 { 0089 return QIcon::fromTheme(QStringLiteral("clazy")); 0090 } 0091 0092 void GlobalConfigPage::apply() 0093 { 0094 ConfigPage::apply(); 0095 ui->checksets->store(); 0096 } 0097 0098 void GlobalConfigPage::defaults() 0099 { 0100 ConfigPage::defaults(); 0101 ui->checksets->reload(); 0102 } 0103 0104 void GlobalConfigPage::reset() 0105 { 0106 ConfigPage::reset(); 0107 ui->checksets->reload(); 0108 } 0109 0110 } 0111 0112 #include "moc_globalconfigpage.cpp"