|
| 1 | +/* |
| 2 | + * This file is part of OpenModelica. |
| 3 | + * |
| 4 | + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), |
| 5 | + * c/o Linköpings universitet, Department of Computer and Information Science, |
| 6 | + * SE-58183 Linköping, Sweden. |
| 7 | + * |
| 8 | + * All rights reserved. |
| 9 | + * |
| 10 | + * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR |
| 11 | + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. |
| 12 | + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE |
| 13 | + * OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE. |
| 14 | + * |
| 15 | + * The OpenModelica software and the Open Source Modelica |
| 16 | + * Consortium (OSMC) Public License (OSMC-PL) are obtained |
| 17 | + * from OSMC, either from the above address, |
| 18 | + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or |
| 19 | + * http://www.openmodelica.org, and in the OpenModelica distribution. |
| 20 | + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. |
| 21 | + * |
| 22 | + * This program is distributed WITHOUT ANY WARRANTY; without |
| 23 | + * even the implied warranty of MERCHANTABILITY or FITNESS |
| 24 | + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH |
| 25 | + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. |
| 26 | + * |
| 27 | + * See the full OSMC Public License conditions for more details. |
| 28 | + * |
| 29 | + */ |
| 30 | +/* |
| 31 | + * |
| 32 | + * @author Adeel Asghar <adeel.asghar@liu.se> |
| 33 | + * |
| 34 | + * RCS: $Id$ |
| 35 | + * |
| 36 | + */ |
| 37 | + |
| 38 | +#include "CrashReportDialog.h" |
| 39 | + |
| 40 | +/*! |
| 41 | + \class CrashReportDialog |
| 42 | + \brief Interface for sending crash reports. |
| 43 | + */ |
| 44 | +CrashReportDialog::CrashReportDialog() |
| 45 | + : QDialog(0, Qt::WindowTitleHint) |
| 46 | +{ |
| 47 | + setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::crashReport)); |
| 48 | + setAttribute(Qt::WA_DeleteOnClose); |
| 49 | + // set heading |
| 50 | + mpCrashReportHeading = new Label(Helper::crashReport); |
| 51 | + mpCrashReportHeading->setFont(QFont(Helper::systemFontInfo.family(), Helper::headingFontSize)); |
| 52 | + // set seperator line |
| 53 | + mpHorizontalLine = new QFrame(); |
| 54 | + mpHorizontalLine->setFrameShape(QFrame::HLine); |
| 55 | + mpHorizontalLine->setFrameShadow(QFrame::Sunken); |
| 56 | + // Email label and textbox |
| 57 | + mpEmailLabel = new Label(tr("Your Email (in case you want us to contact you regarding this error):")); |
| 58 | + mpEmailTextBox = new QLineEdit; |
| 59 | + // bug description label and textbox |
| 60 | + mpBugDescriptionLabel = new Label(tr("Describe in a few words what you were doing when the error occurred:")); |
| 61 | + mpBugDescriptionTextBox = new QPlainTextEdit; |
| 62 | + // files label and checkboxes |
| 63 | + mpFilesDescriptionLabel = new Label(tr("Following selected files will be sent alongwith the crash report,")); |
| 64 | + QString& tmpPath = OpenModelica::tempDirectory(); |
| 65 | + // omeditcommunication.log file checkbox |
| 66 | + QFileInfo OMEditCommunicationLogFileInfo(QString("%1omeditcommunication.log").arg(tmpPath)); |
| 67 | + mpOMEditCommunicationLogFileCheckBox = new QCheckBox(OMEditCommunicationLogFileInfo.absoluteFilePath()); |
| 68 | + if (OMEditCommunicationLogFileInfo.exists()) { |
| 69 | + mpOMEditCommunicationLogFileCheckBox->setChecked(true); |
| 70 | + } else { |
| 71 | + mpOMEditCommunicationLogFileCheckBox->setChecked(false); |
| 72 | + } |
| 73 | + // omeditcommands.mos file checkbox |
| 74 | + QFileInfo OMEditCommandsMosFileInfo(QString("%1omeditcommands.mos").arg(tmpPath)); |
| 75 | + mpOMEditCommandsMosFileCheckBox = new QCheckBox(OMEditCommandsMosFileInfo.absoluteFilePath()); |
| 76 | + if (OMEditCommandsMosFileInfo.exists()) { |
| 77 | + mpOMEditCommandsMosFileCheckBox->setChecked(true); |
| 78 | + } else { |
| 79 | + mpOMEditCommandsMosFileCheckBox->setChecked(false); |
| 80 | + } |
| 81 | + // openmodelica.omc.output.OMEdit file checkbox |
| 82 | + QFileInfo OMCOutputFileInfo(QString("%1openmodelica.omc.output.%2").arg(tmpPath).arg(Helper::OMCServerName)); |
| 83 | + mpOMCOutputFileCheckBox = new QCheckBox(OMCOutputFileInfo.absoluteFilePath()); |
| 84 | + if (OMCOutputFileInfo.exists()) { |
| 85 | + mpOMCOutputFileCheckBox->setChecked(true); |
| 86 | + } else { |
| 87 | + mpOMCOutputFileCheckBox->setChecked(false); |
| 88 | + } |
| 89 | + // openmodelica.stacktrace.OMEdit file checkbox |
| 90 | + QFileInfo OMStackTraceFileInfo(QString("%1openmodelica.stacktrace.%2").arg(tmpPath).arg(Helper::OMCServerName)); |
| 91 | + mpOMStackTraceFileCheckBox = new QCheckBox(OMStackTraceFileInfo.absoluteFilePath()); |
| 92 | + if (OMStackTraceFileInfo.exists()) { |
| 93 | + mpOMStackTraceFileCheckBox->setChecked(true); |
| 94 | + } else { |
| 95 | + mpOMStackTraceFileCheckBox->setChecked(false); |
| 96 | + } |
| 97 | + // create send report button |
| 98 | + mpSendReportButton = new QPushButton(tr("Send Report")); |
| 99 | + mpSendReportButton->setAutoDefault(true); |
| 100 | + connect(mpSendReportButton, SIGNAL(clicked()), SLOT(sendReport())); |
| 101 | + mpCancelButton = new QPushButton(Helper::cancel); |
| 102 | + connect(mpCancelButton, SIGNAL(clicked()), SLOT(reject())); |
| 103 | + // create buttons box |
| 104 | + mpButtonBox = new QDialogButtonBox(Qt::Horizontal); |
| 105 | + mpButtonBox->addButton(mpSendReportButton, QDialogButtonBox::ActionRole); |
| 106 | + mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole); |
| 107 | + // set grid layout |
| 108 | + QGridLayout *pMainLayout = new QGridLayout; |
| 109 | + pMainLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
| 110 | + pMainLayout->addWidget(mpCrashReportHeading, 0, 0); |
| 111 | + pMainLayout->addWidget(mpHorizontalLine, 1, 0); |
| 112 | + pMainLayout->addWidget(mpEmailLabel, 2, 0); |
| 113 | + pMainLayout->addWidget(mpEmailTextBox, 3, 0); |
| 114 | + pMainLayout->addWidget(mpBugDescriptionLabel, 4, 0); |
| 115 | + pMainLayout->addWidget(mpBugDescriptionTextBox, 5, 0); |
| 116 | + int index = 6; |
| 117 | + if (OMEditCommunicationLogFileInfo.exists() || OMEditCommandsMosFileInfo.exists() || OMCOutputFileInfo.exists() || OMStackTraceFileInfo.exists()) { |
| 118 | + pMainLayout->addWidget(mpFilesDescriptionLabel, index, 0); |
| 119 | + index++; |
| 120 | + } |
| 121 | + if (OMEditCommunicationLogFileInfo.exists()) { |
| 122 | + pMainLayout->addWidget(mpOMEditCommunicationLogFileCheckBox, index, 0); |
| 123 | + index++; |
| 124 | + } |
| 125 | + if (OMEditCommandsMosFileInfo.exists()) { |
| 126 | + pMainLayout->addWidget(mpOMEditCommandsMosFileCheckBox, index, 0); |
| 127 | + index++; |
| 128 | + } |
| 129 | + if (OMCOutputFileInfo.exists()) { |
| 130 | + pMainLayout->addWidget(mpOMCOutputFileCheckBox, index, 0); |
| 131 | + index++; |
| 132 | + } |
| 133 | + if (OMStackTraceFileInfo.exists()) { |
| 134 | + pMainLayout->addWidget(mpOMStackTraceFileCheckBox, index, 0); |
| 135 | + index++; |
| 136 | + } |
| 137 | + pMainLayout->addWidget(mpButtonBox, index, 0, 1, 1, Qt::AlignRight); |
| 138 | + setLayout(pMainLayout); |
| 139 | +} |
| 140 | + |
| 141 | +/*! |
| 142 | + Slot activated when mpSendReportButton clicked signal is raised.\n |
| 143 | + Sends the crash report alongwith selected log files. |
| 144 | + */ |
| 145 | +void CrashReportDialog::sendReport() |
| 146 | +{ |
| 147 | + QHttpMultiPart *pHttpMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); |
| 148 | + // email |
| 149 | + QHttpPart emailHttpPart; |
| 150 | + emailHttpPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"email\"")); |
| 151 | + emailHttpPart.setBody(mpEmailTextBox->text().toUtf8()); |
| 152 | + pHttpMultiPart->append(emailHttpPart); |
| 153 | + // bug description |
| 154 | + QHttpPart bugDescriptionHttpPart; |
| 155 | + bugDescriptionHttpPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"bugdescription\"")); |
| 156 | + bugDescriptionHttpPart.setBody(mpBugDescriptionTextBox->toPlainText().toUtf8()); |
| 157 | + pHttpMultiPart->append(bugDescriptionHttpPart); |
| 158 | + // OMEditCommunicationLogFile |
| 159 | + if (mpOMEditCommunicationLogFileCheckBox->isChecked()) { |
| 160 | + QHttpPart OMEditCommunicationLogFileHttpPart; |
| 161 | + OMEditCommunicationLogFileHttpPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain")); |
| 162 | + OMEditCommunicationLogFileHttpPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"omeditcommunication.log\"; filename=\"omeditcommunication.log\"")); |
| 163 | + QFile *pOMEditCommunicationLogFileFile = new QFile(mpOMEditCommunicationLogFileCheckBox->text()); |
| 164 | + pOMEditCommunicationLogFileFile->open(QIODevice::ReadOnly); |
| 165 | + OMEditCommunicationLogFileHttpPart.setBodyDevice(pOMEditCommunicationLogFileFile); |
| 166 | + pOMEditCommunicationLogFileFile->setParent(pHttpMultiPart); // file will be deleted when we delete pHttpMultiPart |
| 167 | + pHttpMultiPart->append(OMEditCommunicationLogFileHttpPart); |
| 168 | + } |
| 169 | + // OMEditCommandsMosFile |
| 170 | + if (mpOMEditCommandsMosFileCheckBox->isChecked()) { |
| 171 | + QHttpPart OMEditCommandsMosFileHttpPart; |
| 172 | + OMEditCommandsMosFileHttpPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain")); |
| 173 | + OMEditCommandsMosFileHttpPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"omeditcommands.mos\"; filename=\"omeditcommands.mos\"")); |
| 174 | + QFile *pOMEditCommandsMosFile = new QFile(mpOMEditCommandsMosFileCheckBox->text()); |
| 175 | + pOMEditCommandsMosFile->open(QIODevice::ReadOnly); |
| 176 | + OMEditCommandsMosFileHttpPart.setBodyDevice(pOMEditCommandsMosFile); |
| 177 | + pOMEditCommandsMosFile->setParent(pHttpMultiPart); // file will be deleted when we delete pHttpMultiPart |
| 178 | + pHttpMultiPart->append(OMEditCommandsMosFileHttpPart); |
| 179 | + } |
| 180 | + // OMCOutputFile |
| 181 | + if (mpOMCOutputFileCheckBox->isChecked()) { |
| 182 | + QHttpPart OMCOutputFileCheckBoxHttpPart; |
| 183 | + OMCOutputFileCheckBoxHttpPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain")); |
| 184 | + OMCOutputFileCheckBoxHttpPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"openmodelica.omc.output.OMEdit\"; filename=\"openmodelica.omc.output.OMEdit\"")); |
| 185 | + QFile *pOMCOutputFileCheckBoxFile = new QFile(mpOMCOutputFileCheckBox->text()); |
| 186 | + pOMCOutputFileCheckBoxFile->open(QIODevice::ReadOnly); |
| 187 | + OMCOutputFileCheckBoxHttpPart.setBodyDevice(pOMCOutputFileCheckBoxFile); |
| 188 | + pOMCOutputFileCheckBoxFile->setParent(pHttpMultiPart); // file will be deleted when we delete pHttpMultiPart |
| 189 | + pHttpMultiPart->append(OMCOutputFileCheckBoxHttpPart); |
| 190 | + } |
| 191 | + // OMStackTraceFile |
| 192 | + if (mpOMStackTraceFileCheckBox->isChecked()) { |
| 193 | + QHttpPart OMStackTraceFileCheckBoxHttpPart; |
| 194 | + OMStackTraceFileCheckBoxHttpPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain")); |
| 195 | + OMStackTraceFileCheckBoxHttpPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"openmodelica.stacktrace.OMEdit\"; filename=\"openmodelica.stacktrace.OMEdit\"")); |
| 196 | + QFile *pOMStackTraceFile = new QFile(mpOMStackTraceFileCheckBox->text()); |
| 197 | + pOMStackTraceFile->open(QIODevice::ReadOnly); |
| 198 | + OMStackTraceFileCheckBoxHttpPart.setBodyDevice(pOMStackTraceFile); |
| 199 | + pOMStackTraceFile->setParent(pHttpMultiPart); // file will be deleted when we delete pHttpMultiPart |
| 200 | + pHttpMultiPart->append(OMStackTraceFileCheckBoxHttpPart); |
| 201 | + } |
| 202 | + // create the request |
| 203 | + QUrl url("https://dev.openmodelica.org/~adeas/cgi-bin/server.py"); |
| 204 | + QNetworkRequest networkRequest(url); |
| 205 | + QNetworkAccessManager *pNetworkAccessManager = new QNetworkAccessManager; |
| 206 | + QNetworkReply *pNetworkReply = pNetworkAccessManager->post(networkRequest, pHttpMultiPart); |
| 207 | + pNetworkReply->ignoreSslErrors(); |
| 208 | + pHttpMultiPart->setParent(pNetworkReply); // delete the pHttpMultiPart with the pNetworkReply |
| 209 | + connect(pNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), SLOT(reportSent(QNetworkReply*))); |
| 210 | +} |
| 211 | + |
| 212 | +/*! |
| 213 | + Slot activated when QNetworkAccessManager finished signal is raised.\n |
| 214 | + Shows an error message if crash report was not send correctly.\n |
| 215 | + Deletes QNetworkReply object which deletes the QHttpMultiPart and QFile objects attached with it. |
| 216 | + */ |
| 217 | +void CrashReportDialog::reportSent(QNetworkReply *pNetworkReply) |
| 218 | +{ |
| 219 | + if (pNetworkReply->error() != QNetworkReply::NoError) { |
| 220 | + QMessageBox::critical(0, QString(Helper::applicationName).append(" - ").append(Helper::error), |
| 221 | + QString("Following error has occurred while sending crash report \n\n%1").arg(pNetworkReply->errorString()), |
| 222 | + Helper::ok); |
| 223 | + } |
| 224 | + pNetworkReply->deleteLater(); |
| 225 | + accept(); |
| 226 | +} |
0 commit comments