aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/qt-breakpad/qtcrashhandler/mainwidget.cpp
blob: 5bd1ecadfb73da8145d9aee149bd910ea607bada (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
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#include "mainwidget.h"
#include "ui_mainwidget.h"

#include <app/app_version.h>

#include <QApplication>
#include <QDateTime>
#include <QFile>
#include <QFileInfo>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QPair>
#include <QStringList>
#include <QTemporaryFile>
#include <QUrl>

MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    ui->mainWidgetTopLabel.setText(tr("%1 has crashed").arg(Core::Constants::IDE_DISPLAY_NAME));

    connect(ui->restartButton, &QAbstractButton::clicked, this, &MainWidget::restartApplication);
    connect(ui->quitButton, &QAbstractButton::clicked, this, &MainWidget::quitApplication);
    connect(ui->detailButton, &QAbstractButton::clicked, this, &MainWidget::showDetails);
    connect(ui->commentTextEdit, &QTextEdit::textChanged, this, &MainWidget::commentIsProvided);
    connect(ui->emailLineEdit, &QLineEdit::textEdited, this, &MainWidget::emailAdressChanged);
}

MainWidget::~MainWidget()
{
    delete ui;
}

void MainWidget::setProgressbarMaximum(int maximum)
{
    ui->progressBar->setMaximum(maximum);
}

void MainWidget::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    if (e->type() == QEvent::LanguageChange)
        ui->retranslateUi(this);
}

void MainWidget::updateProgressBar(qint64 progressCount, qint64 fullCount)
{
    ui->progressBar->setValue(static_cast<int>(progressCount));
    ui->progressBar->setMaximum(static_cast<int>(fullCount));
}

void MainWidget::showError(QNetworkReply::NetworkError error)
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (error != QNetworkReply::NoError && reply) {
        ui->commentTextEdit->setReadOnly(true);
        ui->commentTextEdit->setPlainText(reply->errorString());
    }
}

void MainWidget::restartApplication()
{
    if (ui->sendDumpCheckBox->isChecked())
        emit restartCrashedApplicationAndSendDump();
    else
        emit restartCrashedApplication();
}

void MainWidget::quitApplication()
{
    ui->quitButton->setEnabled(false);
    if (ui->sendDumpCheckBox->isChecked())
        emit sendDump();
    else
        QCoreApplication::quit();
}

void MainWidget::commentIsProvided()
{
    m_commentIsProvided = true;
    emit commentChanged(ui->commentTextEdit->toPlainText());
}

void MainWidget::showDetails()
{
    if (m_detailDialog.isNull()) {
        m_detailDialog = new DetailDialog(this);

        QString detailText;

        detailText.append(tr("We specifically send the following information:\n\n"));

        QString dumpPath = QApplication::arguments().at(1);
        QString startupTime = QApplication::arguments().at(2);
        QString applicationName = QApplication::arguments().at(3);
        QString applicationVersion = QApplication::arguments().at(4);
        QString plugins = QApplication::arguments().at(5);
        QString ideRevision = QApplication::arguments().at(6);

        detailText.append(QString("StartupTime: %1\n").arg(startupTime));
        detailText.append(QString("Vendor: %1\n").arg("Qt Project"));
        detailText.append(QString("InstallTime: %1\n").arg("0"));
        detailText.append(QString("Add-ons: %1\n").arg(plugins));
        detailText.append(QString("BuildID: %1\n").arg("0"));
        detailText.append(QString("SecondsSinceLastCrash: %1\n").arg("0"));
        detailText.append(QString("ProductName: %1\n").arg(applicationName));
        detailText.append(QString("URL: %1\n").arg(""));
        detailText.append(QString("Theme: %1\n").arg(""));
        detailText.append(QString("Version: %1\n").arg(applicationVersion));
        detailText.append(QString("CrashTime: %1\n").arg(QString::number(QDateTime::currentDateTime().toTime_t())));

        if (!ui->emailLineEdit->text().isEmpty())
            detailText.append(tr("Email: %1\n").arg(ui->emailLineEdit->text()));

        if (m_commentIsProvided)
            detailText.append(tr("Comments: %1\n").arg(ui->commentTextEdit->toPlainText()));

        detailText.append(
                    tr("In addition, we send a Microsoft Minidump file, which contains information "
                       "about this computer, such as the operating system and CPU, and most "
                       "importantly, it contains the stacktrace, which is an internal structure that "
                       "shows where the program crashed. This information will help us to identify "
                       "the cause of the crash and to fix it."));

        m_detailDialog.data()->setText(detailText);
    }
    if (m_detailDialog->isVisible())
        m_detailDialog->showNormal();
    else
        m_detailDialog->show();
}