forked from qt-creator/qt-creator
Add Crashpad to Qt Creator and Qt Design Studio
Fixes: QDS-2748 Change-Id: I87e25682f066d167eebfd7b78c46c166e5062e11 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "coreconstants.h"
|
||||
#include "coreplugin.h"
|
||||
#include "editormanager/editormanager_p.h"
|
||||
#include "dialogs/restartdialog.h"
|
||||
#include "fileutils.h"
|
||||
#include "icore.h"
|
||||
#include "iversioncontrol.h"
|
||||
@@ -35,6 +36,7 @@
|
||||
#include "vcsmanager.h"
|
||||
|
||||
#include <app/app_version.h>
|
||||
#include <coreplugin.h>
|
||||
#include <utils/checkablemessagebox.h>
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <utils/environment.h>
|
||||
@@ -50,9 +52,28 @@
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
static const char crashReportingEnabledKey[] = "CrashReportingEnabled";
|
||||
static const char showCrashButtonKey[] = "ShowCrashButton";
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
// TODO: move to somewhere in Utils
|
||||
static QString formatSize(qint64 size)
|
||||
{
|
||||
QStringList units {QObject::tr("Bytes"), QObject::tr("KB"), QObject::tr("MB"),
|
||||
QObject::tr("GB"), QObject::tr("TB")};
|
||||
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
|
||||
}
|
||||
|
||||
class SystemSettingsWidget : public IOptionsPageWidget
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Core::Internal::SystemSettingsWidget)
|
||||
@@ -113,6 +134,46 @@ public:
|
||||
m_ui.maxRecentFilesSpinBox->setMinimum(1);
|
||||
m_ui.maxRecentFilesSpinBox->setMaximum(99);
|
||||
m_ui.maxRecentFilesSpinBox->setValue(EditorManagerPrivate::maxRecentFiles());
|
||||
#ifdef ENABLE_CRASHPAD
|
||||
if (ICore::settings()->value(showCrashButtonKey).toBool()) {
|
||||
auto crashButton = new QPushButton("CRASH!!!");
|
||||
crashButton->show();
|
||||
connect(crashButton, &QPushButton::clicked, []() {
|
||||
// do a real crash
|
||||
volatile int* a = reinterpret_cast<volatile int *>(NULL); *a = 1;
|
||||
});
|
||||
}
|
||||
|
||||
m_ui.enableCrashReportingCheckBox->setChecked(
|
||||
ICore::settings()->value(crashReportingEnabledKey).toBool());
|
||||
connect(m_ui.helpCrashReportingButton, &QAbstractButton::clicked, this, [this] {
|
||||
showHelpDialog(tr("Crash Reporting"), CorePlugin::msgCrashpadInformation());
|
||||
});
|
||||
connect(m_ui.enableCrashReportingCheckBox,
|
||||
QOverload<int>::of(&QCheckBox::stateChanged), this, [this] {
|
||||
const QString restartText = tr("The change will take effect after restart.");
|
||||
Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText);
|
||||
restartDialog.exec();
|
||||
if (restartDialog.result() == QDialog::Accepted)
|
||||
apply();
|
||||
});
|
||||
|
||||
updateClearCrashWidgets();
|
||||
connect(m_ui.clearCrashReportsButton, &QPushButton::clicked, this, [&] {
|
||||
QDir crashReportsDir(ICore::crashReportsPath());
|
||||
crashReportsDir.setFilter(QDir::Files);
|
||||
const QStringList crashFiles = crashReportsDir.entryList();
|
||||
for (QString file : crashFiles)
|
||||
crashReportsDir.remove(file);
|
||||
updateClearCrashWidgets();
|
||||
});
|
||||
#else
|
||||
m_ui.enableCrashReportingCheckBox->setVisible(false);
|
||||
m_ui.helpCrashReportingButton->setVisible(false);
|
||||
m_ui.clearCrashReportsButton->setVisible(false);
|
||||
m_ui.crashReportsSizeText->setVisible(false);
|
||||
#endif
|
||||
|
||||
m_ui.askBeforeExitCheckBox->setChecked(
|
||||
static_cast<Core::Internal::MainWindow *>(ICore::mainWindow())->askConfirmationBeforeExit());
|
||||
|
||||
@@ -182,8 +243,9 @@ private:
|
||||
void updateTerminalUi(const Utils::TerminalCommand &term);
|
||||
void updatePath();
|
||||
void updateEnvironmentChangesLabel();
|
||||
void updateClearCrashWidgets();
|
||||
|
||||
void variableHelpDialogCreator(const QString &helpText);
|
||||
void showHelpDialog(const QString &title, const QString &helpText);
|
||||
Ui::SystemSettings m_ui;
|
||||
QPointer<QMessageBox> m_dialog;
|
||||
EnvironmentItems m_environmentChanges;
|
||||
@@ -211,6 +273,11 @@ void SystemSettingsWidget::apply()
|
||||
m_ui.warnBeforeOpeningBigFiles->isChecked());
|
||||
EditorManagerPrivate::setBigFileSizeLimit(m_ui.bigFilesLimitSpinBox->value());
|
||||
EditorManagerPrivate::setMaxRecentFiles(m_ui.maxRecentFilesSpinBox->value());
|
||||
#ifdef ENABLE_CRASHPAD
|
||||
ICore::settings()->setValue(crashReportingEnabledKey,
|
||||
m_ui.enableCrashReportingCheckBox->isChecked());
|
||||
#endif
|
||||
|
||||
static_cast<Core::Internal::MainWindow *>(ICore::mainWindow())->setAskConfirmationBeforeExit(
|
||||
m_ui.askBeforeExitCheckBox->isChecked());
|
||||
|
||||
@@ -263,9 +330,12 @@ void SystemSettingsWidget::updateEnvironmentChangesLabel()
|
||||
: shortSummary);
|
||||
}
|
||||
|
||||
void SystemSettingsWidget::variableHelpDialogCreator(const QString &helpText)
|
||||
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);
|
||||
|
||||
@@ -273,20 +343,31 @@ void SystemSettingsWidget::variableHelpDialogCreator(const QString &helpText)
|
||||
ICore::raiseWindow(m_dialog);
|
||||
return;
|
||||
}
|
||||
QMessageBox *mb = new QMessageBox(QMessageBox::Information,
|
||||
tr("Variables"),
|
||||
helpText,
|
||||
QMessageBox::Close,
|
||||
this);
|
||||
auto mb = new QMessageBox(QMessageBox::Information, title, helpText, QMessageBox::Close, this);
|
||||
mb->setWindowModality(Qt::NonModal);
|
||||
m_dialog = mb;
|
||||
mb->show();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CRASHPAD
|
||||
void SystemSettingsWidget::updateClearCrashWidgets()
|
||||
{
|
||||
QDir crashReportsDir(ICore::crashReportsPath());
|
||||
crashReportsDir.setFilter(QDir::Files);
|
||||
qint64 size = 0;
|
||||
const QStringList crashFiles = crashReportsDir.entryList();
|
||||
for (QString file : crashFiles)
|
||||
size += QFileInfo(crashReportsDir, file).size();
|
||||
|
||||
m_ui.clearCrashReportsButton->setEnabled(!crashFiles.isEmpty());
|
||||
m_ui.crashReportsSizeText->setText(formatSize(size));
|
||||
}
|
||||
#endif
|
||||
|
||||
void SystemSettingsWidget::showHelpForFileBrowser()
|
||||
{
|
||||
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
|
||||
variableHelpDialogCreator(UnixUtils::fileBrowserHelpText());
|
||||
showHelpDialog(tr("Variables"), UnixUtils::fileBrowserHelpText());
|
||||
}
|
||||
|
||||
SystemSettings::SystemSettings()
|
||||
|
||||
Reference in New Issue
Block a user