Changeset View
Changeset View
Standalone View
Standalone View
plugins/meson/settings/mesonoptionsview.cpp
- This file was added.
1 | /* This file is part of KDevelop | ||||
---|---|---|---|---|---|
2 | Copyright 2019 Daniel Mensinger <daniel@mensinger-ka.de> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "mesonoptionsview.h" | ||||
21 | #include "mesonconfig.h" | ||||
22 | #include "mesonintrospectjob.h" | ||||
23 | #include "mesonoptionbaseview.h" | ||||
24 | #include "ui_mesonoptionsview.h" | ||||
25 | #include <algorithm> | ||||
26 | #include <debug.h> | ||||
27 | #include <interfaces/iproject.h> | ||||
28 | | ||||
29 | using namespace std; | ||||
30 | | ||||
31 | MesonOptionsView::MesonOptionsView(QWidget* parent) | ||||
32 | : QWidget(parent) | ||||
33 | { | ||||
34 | m_ui = new Ui::MesonOptionsView; | ||||
35 | m_ui->setupUi(this); | ||||
36 | setDisabled(true); | ||||
37 | } | ||||
38 | | ||||
39 | MesonOptionsView::~MesonOptionsView() | ||||
40 | { | ||||
41 | m_optViews.clear(); | ||||
42 | if (m_ui) { | ||||
43 | delete m_ui; | ||||
44 | } | ||||
45 | } | ||||
46 | | ||||
47 | void MesonOptionsView::clear() | ||||
48 | { | ||||
49 | setDisabled(true); | ||||
50 | m_optViews.clear(); | ||||
51 | } | ||||
52 | | ||||
53 | void MesonOptionsView::resetAll() | ||||
54 | { | ||||
55 | for (auto& i : m_optViews) { | ||||
56 | i->reset(); | ||||
57 | } | ||||
58 | } | ||||
59 | | ||||
60 | KJob* MesonOptionsView::repopulateFromBuildDir(KDevelop::Path projectPath, Meson::BuildDir const& buildDir) | ||||
61 | { | ||||
62 | return repopulate(new MesonIntrospectJob(projectPath, buildDir, { MesonIntrospectJob::BUILDOPTIONS }, | ||||
63 | MesonIntrospectJob::BUILD_DIR, this)); | ||||
64 | } | ||||
65 | | ||||
66 | KJob* MesonOptionsView::repopulateFromMesonFile(KDevelop::Path projectPath, KDevelop::Path mesonExe) | ||||
67 | { | ||||
68 | return repopulate(new MesonIntrospectJob(projectPath, mesonExe, { MesonIntrospectJob::BUILDOPTIONS }, this)); | ||||
69 | } | ||||
70 | | ||||
71 | KJob* MesonOptionsView::repopulate(MesonIntrospectJob* introJob) | ||||
72 | { | ||||
73 | setDisabled(true); | ||||
74 | | ||||
75 | connect(introJob, &KJob::result, this, [this, introJob]() { | ||||
76 | m_optViews.clear(); | ||||
77 | m_options = introJob->buildOptions(); | ||||
78 | if (!m_options) { | ||||
79 | qCWarning(KDEV_Meson) << "Failed to get introspection data"; | ||||
80 | return; | ||||
81 | } | ||||
82 | | ||||
83 | for (auto i : m_options->options()) { | ||||
84 | OPT_VIEW_PTR opt = nullptr; | ||||
85 | switch (i->type()) { | ||||
86 | case MesonOptionBase::ARRAY: | ||||
87 | opt = make_shared<MesonOptionArrayView>(i, m_ui->tabWidget); | ||||
88 | break; | ||||
89 | case MesonOptionBase::BOOLEAN: | ||||
90 | opt = make_shared<MesonOptionBoolView>(i, m_ui->tabWidget); | ||||
91 | break; | ||||
92 | case MesonOptionBase::COMBO: | ||||
93 | opt = make_shared<MesonOptionComboView>(i, m_ui->tabWidget); | ||||
94 | break; | ||||
95 | case MesonOptionBase::INTEGER: | ||||
96 | opt = make_shared<MesonOptionIntegerView>(i, m_ui->tabWidget); | ||||
97 | break; | ||||
98 | case MesonOptionBase::STRING: | ||||
99 | opt = make_shared<MesonOptionStringView>(i, m_ui->tabWidget); | ||||
100 | break; | ||||
101 | } | ||||
102 | | ||||
103 | if (!opt) { | ||||
104 | qCWarning(KDEV_Meson) << "Unhandled option type " << i->type(); | ||||
105 | continue; | ||||
106 | } | ||||
107 | | ||||
108 | QVBoxLayout* layout = nullptr; | ||||
109 | | ||||
110 | switch (i->section()) { | ||||
111 | case MesonOptionBase::CORE: | ||||
112 | layout = m_ui->l_core; | ||||
113 | break; | ||||
114 | case MesonOptionBase::BACKEND: | ||||
115 | layout = m_ui->l_backend; | ||||
116 | break; | ||||
117 | case MesonOptionBase::BASE: | ||||
118 | layout = m_ui->l_base; | ||||
119 | break; | ||||
120 | case MesonOptionBase::COMPILER: | ||||
121 | layout = m_ui->l_compiler; | ||||
122 | break; | ||||
123 | case MesonOptionBase::DIRECTORY: | ||||
124 | layout = m_ui->l_directory; | ||||
125 | break; | ||||
126 | case MesonOptionBase::USER: | ||||
127 | layout = m_ui->l_user; | ||||
128 | break; | ||||
129 | case MesonOptionBase::TEST: | ||||
130 | layout = m_ui->l_test; | ||||
131 | break; | ||||
132 | } | ||||
133 | | ||||
134 | if (!layout) { | ||||
135 | qCWarning(KDEV_Meson) << "Unknown section " << i->section(); | ||||
136 | } | ||||
137 | | ||||
138 | connect(opt.get(), &MesonOptionBaseView::configChanged, this, &MesonOptionsView::emitChanged); | ||||
139 | | ||||
140 | // Insert at count() - 1 to keep the stretch at the bottom | ||||
141 | layout->insertWidget(layout->count() - 1, opt.get()); | ||||
142 | m_optViews << opt; | ||||
143 | } | ||||
144 | | ||||
145 | auto maxEl = max_element(begin(m_optViews), end(m_optViews), | ||||
146 | [](auto a, auto b) { return a->nameWidth() < b->nameWidth(); }); | ||||
147 | int maxWidth = (**maxEl).nameWidth(); | ||||
148 | for_each(begin(m_optViews), end(m_optViews), [maxWidth](auto a) { a->setMinNameWidth(maxWidth); }); | ||||
149 | | ||||
150 | setDisabled(false); | ||||
151 | }); | ||||
152 | | ||||
153 | return introJob; | ||||
154 | } | ||||
155 | | ||||
156 | void MesonOptionsView::emitChanged() | ||||
157 | { | ||||
158 | emit configChanged(); | ||||
159 | } | ||||
160 | | ||||
161 | MESON_OPT_PTR MesonOptionsView::options() | ||||
162 | { | ||||
163 | return m_options; | ||||
164 | } | ||||
165 | |