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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "systemsettings.h"
#include "coreconstants.h"
#include "coreplugintr.h"
#include "editormanager/editormanager_p.h"
#include "dialogs/ioptionspage.h"
#include "fileutils.h"
#include "icore.h"
#include "vcsmanager.h"
#ifdef ENABLE_CRASHREPORTING
#include "coreplugin.h"
#endif
#include <utils/algorithm.h>
#include <utils/appinfo.h>
#include <utils/checkablemessagebox.h>
#include <utils/elidinglabel.h>
#include <utils/environment.h>
#include <utils/environmentdialog.h>
#include <utils/hostosinfo.h>
#include <utils/itemviews.h>
#include <utils/layoutbuilder.h>
#include <utils/pathchooser.h>
#include <utils/terminalcommand.h>
#include <utils/treemodel.h>
#include <utils/unixutils.h>
#include <QComboBox>
#include <QDesktopServices>
#include <QDialog>
#include <QDialogButtonBox>
#include <QGuiApplication>
#include <QLineEdit>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QToolButton>
using namespace Utils;
using namespace Layouting;
namespace Core::Internal {
#ifdef CRASHREPORTING_USES_CRASHPAD
// TODO: move to somewhere in Utils
static QString formatSize(qint64 size)
{
QStringList units{Tr::tr("Bytes"), Tr::tr("KiB"), Tr::tr("MiB"), Tr::tr("GiB"), Tr::tr("TiB")};
double outputSize = size;
int i;
for (i = 0; i < units.size() - 1; ++i) {
if (outputSize < 1024)
break;
outputSize /= 1024;
}
return i == 0 ? QString("%0 %1").arg(outputSize).arg(units[i]) // Bytes
: QString("%0 %1").arg(outputSize, 0, 'f', 2).arg(units[i]); // KB, MB, GB, TB
}
#endif // CRASHREPORTING_USES_CRASHPAD
SystemSettings &systemSettings()
{
static SystemSettings theSettings;
return theSettings;
}
SystemSettings::SystemSettings()
: m_startupSystemEnvironment(Environment::systemEnvironment())
{
const EnvironmentItems changes = EnvironmentItem::fromStringList(
ICore::settings()->value(kEnvironmentChanges).toStringList());
setEnvironmentChanges(changes);
m_envVarSeparators = NameValueDictionary(
ICore::settings()
->value(kEnvVarSeparators, defaultEnvVarSeparators().toStringList())
.toStringList());
setAutoApply(false);
useDbusFileManagers.setSettingsKey("General/SupportDbusFileManagers");
useDbusFileManagers.setDefaultValue(true);
useDbusFileManagers.setLabelPlacement(BoolAspect::LabelPlacement::Compact);
useDbusFileManagers.setLabelText(Tr::tr("Use freedesktop.org file manager D-Bus interface"));
useDbusFileManagers.setToolTip(
Tr::tr(
"Uses the <a href=\"%1\">freedesktop.org D-Bus interface</a> for <i>Open in File "
"Manager</i>, if available. Otherwise falls back onto the \"External file browser\" "
"above.")
.arg("https://freedesktop.org/wiki/Specifications/file-manager-interface"));
patchCommand.setSettingsKey("General/PatchCommand");
patchCommand.setDefaultValue("patch");
patchCommand.setExpectedKind(PathChooser::ExistingCommand);
patchCommand.setHistoryCompleter("General.PatchCommand.History");
patchCommand.setLabelText(Tr::tr("Patch command:"));
patchCommand.setToolTip(Tr::tr("Command used for reverting diff chunks."));
autoSaveModifiedFiles.setSettingsKey("EditorManager/AutoSaveEnabled");
autoSaveModifiedFiles.setDefaultValue(true);
autoSaveModifiedFiles.setLabelText(Tr::tr("Auto-save modified files"));
autoSaveModifiedFiles.setLabelPlacement(BoolAspect::LabelPlacement::Compact);
autoSaveModifiedFiles.setToolTip(
Tr::tr("Automatically creates temporary copies of modified files. "
"If %1 is restarted after a crash or power failure, it asks whether to "
"recover the auto-saved content.")
.arg(QGuiApplication::applicationDisplayName()));
autoSaveInterval.setSettingsKey("EditorManager/AutoSaveInterval");
autoSaveInterval.setSuffix(Tr::tr("min"));
autoSaveInterval.setRange(1, 1000000);
autoSaveInterval.setDefaultValue(5);
autoSaveInterval.setLabelText(Tr::tr("Interval:"));
autoSaveAfterRefactoring.setSettingsKey("EditorManager/AutoSaveAfterRefactoring");
autoSaveAfterRefactoring.setDefaultValue(true);
autoSaveAfterRefactoring.setLabelPlacement(BoolAspect::LabelPlacement::Compact);
autoSaveAfterRefactoring.setLabelText(Tr::tr("Auto-save files after refactoring"));
autoSaveAfterRefactoring.setToolTip(
Tr::tr("Automatically saves all open files affected by a refactoring operation,\n"
"provided they were unmodified before the refactoring."));
autoSuspendEnabled.setSettingsKey("EditorManager/AutoSuspendEnabled");
autoSuspendEnabled.setDefaultValue(true);
autoSuspendEnabled.setLabelText(Tr::tr("Auto-suspend unmodified files"));
autoSuspendEnabled.setLabelPlacement(BoolAspect::LabelPlacement::Compact);
autoSuspendEnabled.setToolTip(
Tr::tr("Automatically free resources of old documents that are not visible and not "
"modified. They stay visible in the list of open documents."));
autoSuspendMinDocumentCount.setSettingsKey("EditorManager/AutoSuspendMinDocuments");
autoSuspendMinDocumentCount.setRange(1, 500);
autoSuspendMinDocumentCount.setDefaultValue(10);
autoSuspendMinDocumentCount.setLabelText(Tr::tr("Files to keep open:"));
autoSuspendMinDocumentCount.setToolTip(
Tr::tr("Minimum number of open documents that should be kept in memory. Increasing this "
"number will lead to greater resource usage when not manually closing documents."));
warnBeforeOpeningBigFiles.setSettingsKey("EditorManager/WarnBeforeOpeningBigTextFiles");
warnBeforeOpeningBigFiles.setDefaultValue(true);
warnBeforeOpeningBigFiles.setLabelPlacement(BoolAspect::LabelPlacement::Compact);
warnBeforeOpeningBigFiles.setLabelText(Tr::tr("Warn before opening text files greater than"));
bigFileSizeLimitInMB.setSettingsKey("EditorManager/BigTextFileSizeLimitInMB");
bigFileSizeLimitInMB.setSuffix(Tr::tr("MB"));
bigFileSizeLimitInMB.setRange(1, 500);
bigFileSizeLimitInMB.setDefaultValue(5);
maxRecentFiles.setSettingsKey("EditorManager/MaxRecentFiles");
maxRecentFiles.setRange(1, 99);
maxRecentFiles.setDefaultValue(8);
reloadSetting.setSettingsKey("EditorManager/ReloadBehavior");
reloadSetting.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);
reloadSetting.addOption(Tr::tr("Always Ask"));
reloadSetting.addOption(Tr::tr("Reload All Unchanged Editors"));
reloadSetting.addOption(Tr::tr("Ignore Modifications"));
reloadSetting.setDefaultValue(IDocument::ReloadUnmodified);
reloadSetting.setLabelText(Tr::tr("When files are externally modified:"));
askBeforeExit.setSettingsKey("AskBeforeExit");
askBeforeExit.setLabelText(Tr::tr("Ask for confirmation before exiting"));
askBeforeExit.setLabelPlacement(BoolAspect::LabelPlacement::Compact);
#ifdef ENABLE_CRASHREPORTING
enableCrashReporting.setSettingsKey("CrashReportingEnabled");
enableCrashReporting.setLabelPlacement(BoolAspect::LabelPlacement::Compact);
enableCrashReporting.setLabelText(Tr::tr("Enable crash reporting"));
enableCrashReporting.setToolTip(
"<p>"
+ Tr::tr("Allow crashes to be automatically reported. Collected reports are "
"used for the sole purpose of fixing bugs.")
+ "</p><p>"
+ Tr::tr("Crash reports are saved in \"%1\".").arg(appInfo().crashReports.toUserOutput()));
#endif // ENABLE_CRASHREPORTING
readSettings();
autoSaveInterval.setEnabler(&autoSaveModifiedFiles);
autoSuspendMinDocumentCount.setEnabler(&autoSuspendEnabled);
bigFileSizeLimitInMB.setEnabler(&warnBeforeOpeningBigFiles);
autoSaveModifiedFiles.addOnChanged(this, &EditorManagerPrivate::updateAutoSave);
autoSaveInterval.addOnChanged(this, &EditorManagerPrivate::updateAutoSave);
}
QString SystemSettings::msgCrashpadInformation()
{
#if ENABLE_CRASHREPORTING
#if CRASHREPORTING_USES_CRASHPAD
const QString backend = "Google Crashpad";
const QString url
= "https://chromium.googlesource.com/crashpad/crashpad/+/master/doc/overview_design.md";
#else
const QString backend = "Google Breakpad";
const QString url
= "https://chromium.googlesource.com/breakpad/breakpad/+/HEAD/docs/client_design.md";
#endif
//: %1 = application name, %2 crash backend name (Google Crashpad or Google Breakpad)
return Tr::tr(
"%1 uses %2 for collecting crashes and sending them to Sentry "
"for processing. %2 may capture arbitrary contents from crashed process’ "
"memory, including user sensitive information, URLs, and whatever other content "
"users have trusted %1 with. The collected crash reports are however only used "
"for the sole purpose of fixing bugs.")
.arg(QGuiApplication::applicationDisplayName(), backend)
+ "<br><br>" + Tr::tr("More information:") + "<br><a href='" + url
+ "'>"
//: %1 = crash backend name (Google Crashpad or Google Breakpad)
+ Tr::tr("%1 Overview").arg(backend)
+ "</a>"
"<br><a href='https://sentry.io/security/'>"
+ Tr::tr("%1 security policy").arg("Sentry.io") + "</a>";
#else
return {};
#endif
}
class EnvVarSeparatorItem : public TreeItem
{
public:
EnvVarSeparatorItem(const QString &var, const QString &sep) : m_var(var), m_sep(sep) {}
QString var() const { return m_var; }
QString sep() const { return m_sep; }
private:
QVariant data(int column, int role) const override
{
if (role != Qt::DisplayRole && role != Qt::EditRole)
return {};
return column == 0 ? m_var : m_sep;
}
bool setData(int column, const QVariant &data, int) override
{
if (column == 0) {
m_var = data.toString();
return true;
}
if (column == 1) {
m_sep = data.toString();
return true;
}
return false;
}
Qt::ItemFlags flags(int column) const override
{
return TreeItem::flags(column) | Qt::ItemIsEditable;
}
QString m_var;
QString m_sep;
};
class EnvVarSeparatorsDialog : public QDialog
{
public:
EnvVarSeparatorsDialog(const NameValueDictionary &separators, QWidget *parent) : QDialog(parent)
{
const QString explanation = Tr::tr(
"For environment variables with list semantics that do not use the standard path list\n"
"separator, you need to configure the respective separators here if you plan to\n"
"aggregate them from several places (for instance from the Kit and from the project).");
m_model.setHeader({Tr::tr("Variable"), Tr::tr("Separator")});
for (auto it = separators.begin(); it != separators.end(); ++it)
m_model.rootItem()->appendChild(new EnvVarSeparatorItem(it.key(), it.value()));
const auto view = new TreeView(this);
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setModel(&m_model);
const auto addButton = new QPushButton("&Add");
connect(addButton, &QPushButton::clicked, this, [this] {
m_model.rootItem()->appendChild(new EnvVarSeparatorItem("CUSTOM_VAR", {}));
});
const auto removeButton = new QPushButton("&Remove");
connect(removeButton, &QPushButton::clicked, this, [this, view] {
const QModelIndexList selected = view->selectionModel()->selectedRows();
if (selected.size() == 1)
m_model.rootItem()->removeChildAt(selected.first().row());
});
const auto updateRemoveButtonState = [view, removeButton] {
removeButton->setEnabled(view->selectionModel()->hasSelection());
};
connect(view->selectionModel(), &QItemSelectionModel::selectionChanged,
this, updateRemoveButtonState);
updateRemoveButtonState();
const auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
Column {
explanation,
Row {
Column { view },
Column { addButton, removeButton, st }
},
buttonBox
}.attachTo(this);
}
NameValueDictionary separators() const
{
NameValueDictionary seps;
const TreeItem * const root = m_model.rootItem();
for (int i = 0; i < root->childCount(); ++i) {
const auto item = static_cast<EnvVarSeparatorItem *>(root->childAt(i));
seps.set(item->var(), item->sep());
}
return seps;
}
private:
TreeModel<TreeItem, EnvVarSeparatorItem> m_model;
};
class SystemSettingsWidget : public IOptionsPageWidget
{
public:
SystemSettingsWidget()
: m_fileSystemCaseSensitivityChooser(HostOsInfo::isMacHost() ? new QComboBox : nullptr)
, m_externalFileBrowserEdit(new QLineEdit)
, m_terminalComboBox(new QComboBox)
, m_terminalOpenArgs(new QLineEdit)
, m_terminalExecuteArgs(new QLineEdit)
, m_environmentChangesLabel(new Utils::ElidingLabel)
, m_envVarSeparatorsLabel(new QLabel)
#ifdef CRASHREPORTING_USES_CRASHPAD
, m_crashReportsMenuButton(new QPushButton(Tr::tr("Manage"), this))
, m_crashReportsSizeText(new QLabel(this))
#endif
{
SystemSettings &s = systemSettings();
m_terminalExecuteArgs->setToolTip(
Tr::tr("Command line arguments used for \"Run in terminal\"."));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(5);
m_environmentChangesLabel->setSizePolicy(sizePolicy);
m_envVarSeparatorsLabel->setSizePolicy(sizePolicy);
QSizePolicy termSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
termSizePolicy.setHorizontalStretch(3);
m_terminalComboBox->setSizePolicy(termSizePolicy);
m_terminalComboBox->setMinimumSize(QSize(100, 0));
m_terminalComboBox->setEditable(true);
m_terminalOpenArgs->setToolTip(
Tr::tr("Command line arguments used for \"%1\".").arg(FileUtils::msgTerminalHereAction()));
auto resetFileBrowserButton = new QPushButton(Tr::tr("Reset"));
resetFileBrowserButton->setToolTip(Tr::tr("Reset to default."));
auto helpExternalFileBrowserButton = new QToolButton;
helpExternalFileBrowserButton->setText(Tr::tr("?"));
#ifdef ENABLE_CRASHREPORTING
auto helpCrashReportingButton = new QToolButton(this);
helpCrashReportingButton->setText(Tr::tr("?"));
connect(helpCrashReportingButton, &QAbstractButton::clicked, this, [this] {
showHelpDialog(Tr::tr("Crash Reporting"), SystemSettings::msgCrashpadInformation());
});
#endif
auto resetTerminalButton = new QPushButton(Tr::tr("Reset"));
resetTerminalButton->setToolTip(Tr::tr("Reset to default.", "Terminal"));
auto environmentButton = new QPushButton(Tr::tr("Change..."));
environmentButton->setSizePolicy(QSizePolicy::Fixed,
environmentButton->sizePolicy().verticalPolicy());
const auto envVarSeparatorsButton = new QPushButton(Tr::tr("Change..."));
envVarSeparatorsButton->setSizePolicy(environmentButton->sizePolicy());
Grid grid;
grid.addRow({Tr::tr("Environment:"),
Span(3, m_environmentChangesLabel), environmentButton});
grid.addRow({Tr::tr("Variable separators:"),
Span(3, m_envVarSeparatorsLabel), envVarSeparatorsButton});
if (HostOsInfo::isAnyUnixHost()) {
grid.addRow({Tr::tr("Terminal:"),
m_terminalComboBox,
m_terminalOpenArgs,
m_terminalExecuteArgs,
resetTerminalButton});
}
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost()) {
grid.addRow({Tr::tr("External file browser:"),
Span(3, m_externalFileBrowserEdit),
resetFileBrowserButton,
helpExternalFileBrowserButton});
}
#ifdef QTC_SUPPORT_DBUSFILEMANAGER
grid.addRow({s.useDbusFileManagers});
#endif
grid.addRow({Span(4, s.patchCommand)});
if (HostOsInfo::isMacHost()) {
auto fileSystemCaseSensitivityLabel = new QLabel(Tr::tr("File system case sensitivity:"));
fileSystemCaseSensitivityLabel->setToolTip(
Tr::tr("Influences how file names are matched to decide if they are the same."));
grid.addRow({fileSystemCaseSensitivityLabel,
m_fileSystemCaseSensitivityChooser});
}
grid.addRow({s.reloadSetting});
grid.addRow({s.autoSaveModifiedFiles, Row{s.autoSaveInterval, st}});
grid.addRow({s.autoSuspendEnabled, Row{s.autoSuspendMinDocumentCount, st}});
grid.addRow({s.autoSaveAfterRefactoring});
grid.addRow({s.warnBeforeOpeningBigFiles, Row{s.bigFileSizeLimitInMB, st}});
grid.addRow({Tr::tr("Maximum number of entries in \"Recent Files\":"),
Row{s.maxRecentFiles, st}});
grid.addRow({s.askBeforeExit});
#ifdef ENABLE_CRASHREPORTING
Row crashDetails;
#ifdef CRASHREPORTING_USES_CRASHPAD
m_crashReportsMenuButton->setToolTip(s.enableCrashReporting.toolTip());
m_crashReportsSizeText->setToolTip(s.enableCrashReporting.toolTip());
auto crashReportsMenu = new QMenu(m_crashReportsMenuButton);
m_crashReportsMenuButton->setMenu(crashReportsMenu);
crashDetails.addItems({m_crashReportsMenuButton, m_crashReportsSizeText});
#endif // CRASHREPORTING_USES_CRASHPAD
crashDetails.addItem(helpCrashReportingButton);
if (qtcEnvironmentVariableIsSet("QTC_SHOW_CRASHBUTTON")) {
auto crashButton = new QPushButton("CRASH!!!");
connect(crashButton, &QPushButton::clicked, [] {
// do a real crash
volatile int *a = reinterpret_cast<volatile int *>(NULL);
*a = 1;
});
crashDetails.addItem(crashButton);
}
crashDetails.addItem(st);
grid.addRow({s.enableCrashReporting, crashDetails});
#endif
Column {
Group {
title(Tr::tr("System")),
Column { grid, st }
}
}.attachTo(this);
if (HostOsInfo::isAnyUnixHost()) {
const QVector<TerminalCommand> availableTerminals
= TerminalCommand::availableTerminalEmulators();
for (const TerminalCommand &term : availableTerminals)
m_terminalComboBox->addItem(term.command.toUserOutput(), QVariant::fromValue(term));
updateTerminalUi(TerminalCommand::terminalEmulator());
connect(m_terminalComboBox, &QComboBox::currentIndexChanged, this, [this](int index) {
updateTerminalUi(m_terminalComboBox->itemData(index).value<TerminalCommand>());
});
}
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost()) {
m_externalFileBrowserEdit->setText(UnixUtils::fileBrowser(ICore::settings()));
}
#if defined(ENABLE_CRASHREPORTING) && defined(CRASHREPORTING_USES_CRASHPAD)
const FilePaths reportsPaths
= {ICore::crashReportsPath() / "completed",
ICore::crashReportsPath() / "reports",
ICore::crashReportsPath() / "attachments",
ICore::crashReportsPath() / "pending",
ICore::crashReportsPath() / "new"};
auto openLocationAction = new QAction(Tr::tr("Go to Crash Reports"));
connect(openLocationAction, &QAction::triggered, this, [reportsPaths] {
const FilePath path = reportsPaths.first().parentDir();
if (!QDesktopServices::openUrl(path.toUrl())) {
qWarning() << "Failed to open path:" << path;
}
});
crashReportsMenu->addAction(openLocationAction);
auto clearAction = new QAction(Tr::tr("Clear Crash Reports"));
crashReportsMenu->addAction(clearAction);
const auto updateClearCrashWidgets = [this, reportsPaths] {
qint64 size = 0;
FilePath::iterateDirectories(
reportsPaths,
[&size](const FilePath &item) {
size += item.fileSize();
return IterationPolicy::Continue;
},
FileFilter({}, QDir::Files, QDirIterator::Subdirectories));
m_crashReportsMenuButton->setEnabled(size > 0);
m_crashReportsSizeText->setText(formatSize(size));
};
updateClearCrashWidgets();
connect(
clearAction,
&QAction::triggered,
this,
[updateClearCrashWidgets, reportsPaths] {
FilePath::iterateDirectories(
reportsPaths,
[](const FilePath &item) {
item.removeRecursively();
return IterationPolicy::Continue;
},
FileFilter({}, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot));
updateClearCrashWidgets();
});
#endif // ENABLE_CRASHREPORTING && CRASHREPORTING_USES_CRASHPAD
if (HostOsInfo::isAnyUnixHost()) {
connect(resetTerminalButton,
&QAbstractButton::clicked,
this,
&SystemSettingsWidget::resetTerminal);
if (!HostOsInfo::isMacHost()) {
connect(resetFileBrowserButton,
&QAbstractButton::clicked,
this,
&SystemSettingsWidget::resetFileBrowser);
connect(helpExternalFileBrowserButton,
&QAbstractButton::clicked,
this,
&SystemSettingsWidget::showHelpForFileBrowser);
}
}
if (HostOsInfo::isMacHost()) {
Qt::CaseSensitivity defaultSensitivity
= OsSpecificAspects::fileNameCaseSensitivity(HostOsInfo::hostOs());
if (defaultSensitivity == Qt::CaseSensitive) {
m_fileSystemCaseSensitivityChooser->addItem(Tr::tr("Case Sensitive (Default)"),
Qt::CaseSensitive);
} else {
m_fileSystemCaseSensitivityChooser->addItem(Tr::tr("Case Sensitive"), Qt::CaseSensitive);
}
if (defaultSensitivity == Qt::CaseInsensitive) {
m_fileSystemCaseSensitivityChooser->addItem(Tr::tr("Case Insensitive (Default)"),
Qt::CaseInsensitive);
} else {
m_fileSystemCaseSensitivityChooser->addItem(Tr::tr("Case Insensitive"),
Qt::CaseInsensitive);
}
const Qt::CaseSensitivity sensitivity = EditorManagerPrivate::readFileSystemSensitivity(
ICore::settings());
if (sensitivity == Qt::CaseSensitive)
m_fileSystemCaseSensitivityChooser->setCurrentIndex(0);
else
m_fileSystemCaseSensitivityChooser->setCurrentIndex(1);
}
updatePath();
m_environmentChangesLabel->setElideMode(Qt::ElideRight);
m_environmentChanges = systemSettings().environmentChanges();
m_envVarSeparators = systemSettings().envVarSeparators();
updateEnvironmentChangesLabel();
updateEnvVarSeparatorsLabel();
connect(environmentButton, &QPushButton::clicked, this, [this, environmentButton] {
std::optional<EnvironmentItems> changes
= runEnvironmentItemsDialog(environmentButton, m_environmentChanges);
if (!changes)
return;
m_environmentChanges = *changes;
updateEnvironmentChangesLabel();
updatePath();
});
connect(envVarSeparatorsButton, &QPushButton::clicked, [this] {
EnvVarSeparatorsDialog dlg(m_envVarSeparators, this);
if (dlg.exec() == QDialog::Accepted) {
m_envVarSeparators = dlg.separators();
updateEnvVarSeparatorsLabel();
}
});
connect(VcsManager::instance(), &VcsManager::configurationChanged,
this, &SystemSettingsWidget::updatePath);
setOnCancel([] { systemSettings().cancel(); });
}
private:
void apply() final;
void showHelpForFileBrowser();
void resetFileBrowser();
void resetTerminal();
void updateTerminalUi(const Utils::TerminalCommand &term);
void updatePath();
void updateEnvironmentChangesLabel();
void updateEnvVarSeparatorsLabel();
void showHelpDialog(const QString &title, const QString &helpText);
QComboBox *m_fileSystemCaseSensitivityChooser;
QLineEdit *m_externalFileBrowserEdit;
QComboBox *m_terminalComboBox;
QLineEdit *m_terminalOpenArgs;
QLineEdit *m_terminalExecuteArgs;
Utils::ElidingLabel *m_environmentChangesLabel;
QLabel * const m_envVarSeparatorsLabel;
#ifdef CRASHREPORTING_USES_CRASHPAD
QPushButton *m_crashReportsMenuButton;
QLabel *m_crashReportsSizeText;
#endif
QPointer<QMessageBox> m_dialog;
EnvironmentItems m_environmentChanges;
NameValueDictionary m_envVarSeparators;
};
void SystemSettingsWidget::apply()
{
systemSettings().apply();
systemSettings().writeSettings();
QtcSettings *settings = ICore::settings();
if (HostOsInfo::isAnyUnixHost()) {
TerminalCommand::setTerminalEmulator({
FilePath::fromUserInput(m_terminalComboBox->lineEdit()->text()),
m_terminalOpenArgs->text(),
m_terminalExecuteArgs->text()
});
if (!HostOsInfo::isMacHost()) {
UnixUtils::setFileBrowser(settings, m_externalFileBrowserEdit->text());
}
}
if (HostOsInfo::isMacHost()) {
const Qt::CaseSensitivity sensitivity = EditorManagerPrivate::readFileSystemSensitivity(
settings);
const Qt::CaseSensitivity selectedSensitivity = Qt::CaseSensitivity(
m_fileSystemCaseSensitivityChooser->currentData().toInt());
if (selectedSensitivity != sensitivity) {
EditorManagerPrivate::writeFileSystemSensitivity(settings, selectedSensitivity);
ICore::askForRestart(
Tr::tr("The file system case sensitivity change will take effect after restart."));
}
}
systemSettings().setEnvironmentChanges(m_environmentChanges);
systemSettings().setEnvVarSeparators(m_envVarSeparators);
}
void SystemSettingsWidget::resetTerminal()
{
if (HostOsInfo::isAnyUnixHost())
m_terminalComboBox->setCurrentIndex(0);
}
void SystemSettingsWidget::updateTerminalUi(const TerminalCommand &term)
{
m_terminalComboBox->lineEdit()->setText(term.command.toUserOutput());
m_terminalOpenArgs->setText(term.openArgs);
m_terminalExecuteArgs->setText(term.executeArgs);
}
void SystemSettingsWidget::resetFileBrowser()
{
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
m_externalFileBrowserEdit->setText(UnixUtils::defaultFileBrowser());
}
void SystemSettingsWidget::updatePath()
{
Environment env;
env.appendToPath(VcsManager::additionalToolsPath());
systemSettings().patchCommand.setEnvironment(env);
}
void SystemSettingsWidget::updateEnvironmentChangesLabel()
{
const QString shortSummary = Utils::EnvironmentItem::toStringList(m_environmentChanges)
.join("; ");
m_environmentChangesLabel->setText(shortSummary.isEmpty() ? Tr::tr("No changes to apply.")
: shortSummary);
}
void SystemSettingsWidget::updateEnvVarSeparatorsLabel()
{
const int count = m_envVarSeparators.size();
const QString summary = QCoreApplication::translate(
"QtC::Core", "%n custom separators configured", nullptr, count);
m_envVarSeparatorsLabel->setText(summary);
}
void SystemSettingsWidget::showHelpDialog(const QString &title, const QString &helpText)
{
if (m_dialog) {
if (m_dialog->windowTitle() != title)
m_dialog->setText(helpText);
if (m_dialog->text() != helpText)
m_dialog->setText(helpText);
m_dialog->show();
ICore::raiseWindow(m_dialog);
return;
}
auto mb = new QMessageBox(QMessageBox::Information, title, helpText, QMessageBox::Close, this);
mb->setWindowModality(Qt::NonModal);
m_dialog = mb;
mb->show();
}
void SystemSettingsWidget::showHelpForFileBrowser()
{
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
showHelpDialog(Tr::tr("Variables"), UnixUtils::fileBrowserHelpText());
}
EnvironmentItems SystemSettings::environmentChanges() const
{
return m_environmentChanges;
}
void SystemSettings::setEnvironmentChanges(const EnvironmentItems &changes)
{
if (m_environmentChanges == changes)
return;
m_environmentChanges = changes;
Environment systemEnv = m_startupSystemEnvironment;
systemEnv.modify(changes);
Environment::setSystemEnvironment(systemEnv);
ICore::settings()->setValueWithDefault(kEnvironmentChanges,
EnvironmentItem::toStringList(changes));
if (ICore::instance())
emit ICore::instance()->systemEnvironmentChanged();
}
void SystemSettings::setEnvVarSeparators(const Utils::NameValueDictionary &separators)
{
if (m_envVarSeparators == separators)
return;
m_envVarSeparators = separators;
ICore::settings()->setValueWithDefault(
kEnvVarSeparators,
m_envVarSeparators.toStringList(),
defaultEnvVarSeparators().toStringList());
if (ICore::instance())
emit ICore::instance()->systemEnvironmentChanged();
}
NameValueDictionary SystemSettings::defaultEnvVarSeparators()
{
return NameValueDictionary(
NameValuePairs{std::make_pair<QString, QString>("CFLAGS", " "),
std::make_pair<QString, QString>("CXXFLAGS", " ")});
}
// SystemSettingsPage
class SystemSettingsPage final : public IOptionsPage
{
public:
SystemSettingsPage()
{
setId(Constants::SETTINGS_ID_SYSTEM);
setDisplayName(Tr::tr("System"));
setCategory(Constants::SETTINGS_CATEGORY_CORE);
setWidgetCreator([] { return new SystemSettingsWidget; });
}
};
const SystemSettingsPage settingsPage;
} // Core::Internal
|