File indexing completed on 2024-05-19 04:41:22
0001 /* 0002 SPDX-FileCopyrightText: 2019 Daniel Mensinger <daniel@mensinger-ka.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "mesonoptionsview.h" 0008 0009 #include "mesonconfig.h" 0010 #include "mesonoptionbaseview.h" 0011 #include "mintro/mesonintrospectjob.h" 0012 #include "ui_mesonoptionsview.h" 0013 #include <debug.h> 0014 0015 #include <interfaces/iproject.h> 0016 0017 #include <algorithm> 0018 0019 using namespace std; 0020 0021 MesonOptionsView::MesonOptionsView(QWidget* parent) 0022 : QWidget(parent) 0023 { 0024 m_ui = new Ui::MesonOptionsView; 0025 m_ui->setupUi(this); 0026 setDisabled(true); 0027 } 0028 0029 MesonOptionsView::~MesonOptionsView() 0030 { 0031 m_optViews.clear(); 0032 if (m_ui) { 0033 delete m_ui; 0034 } 0035 } 0036 0037 void MesonOptionsView::clear() 0038 { 0039 setDisabled(true); 0040 m_optViews.clear(); 0041 } 0042 0043 void MesonOptionsView::resetAll() 0044 { 0045 for (auto& i : m_optViews) { 0046 i->reset(); 0047 } 0048 } 0049 0050 KJob* MesonOptionsView::repopulateFromBuildDir(KDevelop::IProject* project, const Meson::BuildDir& buildDir) 0051 { 0052 return repopulate(new MesonIntrospectJob(project, buildDir, { MesonIntrospectJob::BUILDOPTIONS }, 0053 MesonIntrospectJob::BUILD_DIR, this)); 0054 } 0055 0056 KJob* MesonOptionsView::repopulateFromMesonFile(KDevelop::IProject* project, KDevelop::Path mesonExe) 0057 { 0058 return repopulate(new MesonIntrospectJob(project, mesonExe, { MesonIntrospectJob::BUILDOPTIONS }, this)); 0059 } 0060 0061 KJob* MesonOptionsView::repopulate(MesonIntrospectJob* introJob) 0062 { 0063 setDisabled(true); 0064 0065 connect(introJob, &KJob::result, this, [this, introJob]() { 0066 m_optViews.clear(); 0067 m_options = introJob->buildOptions(); 0068 if (!m_options) { 0069 qCWarning(KDEV_Meson) << "Failed to get introspection data"; 0070 return; 0071 } 0072 0073 for (auto i : m_options->options()) { 0074 OPT_VIEW_PTR opt = MesonOptionBaseView::fromOption(i, m_ui->tabWidget); 0075 0076 if (!opt) { 0077 qCWarning(KDEV_Meson) << "Unhandled option type " << i->type(); 0078 continue; 0079 } 0080 0081 QVBoxLayout* layout = nullptr; 0082 0083 switch (i->section()) { 0084 case MesonOptionBase::CORE: 0085 layout = m_ui->l_core; 0086 break; 0087 case MesonOptionBase::BACKEND: 0088 layout = m_ui->l_backend; 0089 break; 0090 case MesonOptionBase::BASE: 0091 layout = m_ui->l_base; 0092 break; 0093 case MesonOptionBase::COMPILER: 0094 layout = m_ui->l_compiler; 0095 break; 0096 case MesonOptionBase::DIRECTORY: 0097 layout = m_ui->l_directory; 0098 break; 0099 case MesonOptionBase::USER: 0100 layout = m_ui->l_user; 0101 break; 0102 case MesonOptionBase::TEST: 0103 layout = m_ui->l_test; 0104 break; 0105 } 0106 0107 if (!layout) { 0108 qCWarning(KDEV_Meson) << "Unknown section " << i->section(); 0109 } 0110 0111 connect(opt.get(), &MesonOptionBaseView::configChanged, this, &MesonOptionsView::emitChanged); 0112 0113 // Insert at count() - 1 to keep the stretch at the bottom 0114 layout->insertWidget(layout->count() - 1, opt.get()); 0115 m_optViews << opt; 0116 } 0117 0118 auto maxEl = max_element(begin(m_optViews), end(m_optViews), 0119 [](auto a, auto b) { return a->nameWidth() < b->nameWidth(); }); 0120 int maxWidth = (**maxEl).nameWidth(); 0121 for_each(begin(m_optViews), end(m_optViews), [maxWidth](auto a) { a->setMinNameWidth(maxWidth); }); 0122 0123 setDisabled(false); 0124 }); 0125 0126 return introJob; 0127 } 0128 0129 void MesonOptionsView::emitChanged() 0130 { 0131 emit configChanged(); 0132 } 0133 0134 MesonOptsPtr MesonOptionsView::options() 0135 { 0136 return m_options; 0137 } 0138 0139 #include "moc_mesonoptionsview.cpp"