blob: d87b9a2776a02a8caff68ff6d8f4e143aaa3933f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "globalsettings.h"
#include "cococommon.h"
#include "cocopluginconstants.h"
#include "cocotr.h"
#include <utils/fancylineedit.h>
#include <utils/filepath.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h>
#include <QProcess>
#include <QRegularExpression>
#include <QSettings>
#include <QStandardPaths>
using namespace Utils;
namespace Coco::Internal {
CocoSettings &cocoSettings()
{
static CocoSettings theCocoSettings;
return theCocoSettings;
}
CocoSettings::CocoSettings()
{
m_errorMessage = Tr::tr("Error: Coco installation directory not set. (This can't happen.)");
setAutoApply(false);
cocoPath.setSettingsKey(Constants::COCO_SETTINGS_GROUP, Constants::COCO_DIR_KEY);
cocoPath.setExpectedKind(Utils::PathChooser::ExistingDirectory);
cocoPath.setPromptDialogTitle(Tr::tr("Coco Installation Directory"));
readSettings();
if (cocoPath().isEmpty()) {
findDefaultDirectory();
writeSettings();
}
setDirectoryVars(cocoPath());
}
FilePath CocoSettings::coverageBrowserPath() const
{
QString browserPath;
if (HostOsInfo::isAnyUnixHost())
browserPath = "bin/coveragebrowser";
else if (HostOsInfo::isMacHost())
browserPath = "coveragebrowser";
else
browserPath = "coveragebrowser.exe";
return cocoPath().resolvePath(browserPath);
}
void CocoSettings::setDirectoryVars(const FilePath &dir)
{
if (isCocoDirectory(dir) && verifyCocoDirectory(dir)) {
cocoPath.setValue(dir);
m_isValid = true;
m_errorMessage.clear();
} else {
cocoPath.setValue(FilePath());
m_isValid = false;
m_errorMessage
= Tr::tr("Error: Coco installation directory not found at \"%1\".").arg(dir.nativePath());
}
writeSettings();
emit updateCocoDir();
}
void CocoSettings::apply()
{
AspectContainer::apply();
setDirectoryVars(cocoPath());
}
static FilePath coverageScannerPath(const FilePath &cocoDir)
{
QString scannerPath;
if (HostOsInfo::isAnyUnixHost() || HostOsInfo::isMacHost())
scannerPath = "bin/coveragescanner";
else
scannerPath = "coveragescanner.exe";
return cocoDir.resolvePath(scannerPath);
}
bool CocoSettings::isCocoDirectory(const Utils::FilePath &cocoDir) const
{
return coverageScannerPath(cocoDir).exists();
}
void CocoSettings::logError(const QString &msg)
{
logFlashing(msg);
m_isValid = false;
m_errorMessage = msg;
}
bool CocoSettings::verifyCocoDirectory(const FilePath &cocoDir)
{
QString coveragescanner = coverageScannerPath(cocoDir).nativePath();
QProcess proc;
proc.setProgram(coveragescanner);
proc.setArguments({"--cs-help"});
proc.start();
if (!proc.waitForStarted()) {
logError(Tr::tr("Error: CoverageScanner at \"%1\" did not start.").arg(coveragescanner));
return false;
}
if (!proc.waitForFinished()) {
logError(Tr::tr("Error: CoverageScanner at \"%1\" did not finish.").arg(coveragescanner));
return false;
}
QString result = QString::fromLatin1(proc.readAll());
static const QRegularExpression linebreak("\n|\r\n|\r");
const QStringList lines = result.split(linebreak, Qt::SkipEmptyParts);
const qsizetype n = lines.size();
if (n >= 2 && lines[n - 2].startsWith("Version:") && lines[n - 1].startsWith("Date:")) {
logSilently(Tr::tr("Valid CoverageScanner found at \"%1\":").arg(coveragescanner));
logSilently(" " + lines[n - 2]);
logSilently(" " + lines[n - 1]);
return true;
} else {
logError(
Tr::tr("Error: CoverageScanner at \"%1\" did not run correctly.").arg(coveragescanner));
for (const QString &l : lines) {
logSilently(l);
}
return false;
}
}
bool CocoSettings::isValid() const
{
return m_isValid;
}
QString CocoSettings::errorMessage() const
{
return m_errorMessage;
}
void CocoSettings::tryPath(const QString &path)
{
if (m_isValid)
return;
const auto fpath = Utils::FilePath::fromString(path);
const QString nativePath = fpath.nativePath();
if (isCocoDirectory(fpath)) {
logSilently(Tr::tr("Found Coco directory \"%1\".").arg(nativePath));
setDirectoryVars(fpath);
} else {
logSilently(Tr::tr("Checked Coco directory \"%1\".").arg(nativePath));
}
}
static QString envVar(const QString &var)
{
return QProcessEnvironment::systemEnvironment().value(var);
}
void CocoSettings::findDefaultDirectory()
{
if (Utils::HostOsInfo::isMacHost())
tryPath("/Applications/SquishCoco");
else if (Utils::HostOsInfo::isAnyUnixHost()) {
tryPath((Utils::FileUtils::homePath() / "SquishCoco").nativePath());
tryPath("/opt/SquishCoco");
} else {
tryPath(envVar("SQUISHCOCO"));
QStringList homeDirs = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
if (!homeDirs.isEmpty())
tryPath(homeDirs[0] + "/squishcoco");
tryPath(envVar("ProgramFiles") + "\\squishcoco");
tryPath(envVar("ProgramFiles(x86)") + "\\squishcoco");
}
}
class GlobalSettingsWidget : public QFrame
{
public:
GlobalSettingsWidget();
void apply();
void cancel();
private:
Utils::TextDisplay m_messageLabel;
};
GlobalSettingsWidget::GlobalSettingsWidget()
{
using namespace Layouting;
Form {
Column {
Row { Tr::tr("Coco Directory"), cocoSettings().cocoPath },
Row { m_messageLabel }
}
}.attachTo(this);
connect(&cocoSettings(), &CocoSettings::updateCocoDir, this, [this] {
m_messageLabel.setText(cocoSettings().errorMessage());
if (cocoSettings().isValid())
m_messageLabel.setIconType(Utils::InfoLabel::None);
else
m_messageLabel.setIconType(Utils::InfoLabel::Error);
});
}
void GlobalSettingsWidget::apply()
{
cocoSettings().apply();
}
void GlobalSettingsWidget::cancel()
{
cocoSettings().cancel();
}
class GlobalSettingsPage : public Core::IOptionsPage
{
public:
GlobalSettingsWidget *widget() override;
void apply() override;
void cancel() override;
void finish() override;
GlobalSettingsPage();
QPointer<GlobalSettingsWidget> m_widget;
};
GlobalSettingsPage::GlobalSettingsPage()
: m_widget(nullptr)
{
setId(Constants::COCO_SETTINGS_PAGE_ID);
setDisplayName(Tr::tr("Coco"));
setCategory("I.Coco"); // Category I contains also the C++ settings.
}
GlobalSettingsWidget *GlobalSettingsPage::widget()
{
if (!m_widget)
m_widget = new GlobalSettingsWidget;
return m_widget;
}
void GlobalSettingsPage::apply()
{
if (m_widget)
m_widget->apply();
}
void GlobalSettingsPage::cancel()
{
if (m_widget)
m_widget->cancel();
}
void GlobalSettingsPage::finish()
{
delete m_widget;
}
void setupCocoSettings()
{
static GlobalSettingsPage theGlobalSettingsPage;
}
} // namespace Coco::Internal
|