00001
00002
00003
00004
00005
00006
00007 #include "DlgErrorReport.h"
00008 #include <QCheckBox>
00009 #include <QCommonStyle>
00010 #include <QCoreApplication>
00011 #include <QFile>
00012 #include <QHBoxLayout>
00013 #include <QLabel>
00014 #include <QPushButton>
00015 #include <QTextStream>
00016 #include <QVBoxLayout>
00017
00018 const QString ERROR_REPORT_FILE ("engauge_error_report.xml");
00019 const int MAX_BTN_WIDTH = 80;
00020
00021 DlgErrorReport::DlgErrorReport(const QString &xml,
00022 QWidget *parent) :
00023 QDialog (parent),
00024 m_xmlOriginal (xml),
00025 m_xmlAnonymized (xml)
00026 {
00027 QVBoxLayout *layout = new QVBoxLayout;
00028 layout->setSizeConstraint (QLayout::SetFixedSize);
00029 setLayout (layout);
00030
00031 QCommonStyle style;
00032 setModal(true);
00033 setWindowTitle (tr ("Error Report"));
00034 setWindowIcon(style.standardIcon (QStyle::SP_MessageBoxCritical));
00035
00036 QLabel *lblPreview = new QLabel (tr ("An unrecoverable error has occurred. Would you like to send an error report to "
00037 "the Engauge developers?\n\n"
00038 "The original document can be sent as part of the error report, which increases the "
00039 "chances of finding and fixing the problem(s). However, if any information is private "
00040 "then an anonymized version of the document will be sent."));
00041 lblPreview->setWordWrap(true);
00042 layout->addWidget (lblPreview);
00043
00044 m_chkOriginal = new QCheckBox (tr ("Include original document information, otherwise anonymize the information"));
00045 m_chkOriginal->setChecked (true);
00046 updateFile ();
00047 layout->addWidget (m_chkOriginal);
00048 connect (m_chkOriginal, SIGNAL (stateChanged (int)), this, SLOT (slotDocumentCheckboxChanged (int)));
00049
00050 QHBoxLayout *layoutButtons = new QHBoxLayout;
00051
00052 QWidget *panelButtons = new QWidget;
00053 panelButtons->setLayout (layoutButtons);
00054 layout->addWidget (panelButtons);
00055
00056 m_btnSend = new QPushButton(tr ("Send"));
00057 m_btnSend->setMaximumWidth (MAX_BTN_WIDTH);
00058 layoutButtons->addWidget (m_btnSend);
00059 connect (m_btnSend, SIGNAL (released ()), this, SLOT (slotSend()));
00060
00061 m_btnCancel = new QPushButton(tr ("Cancel"));
00062 m_btnCancel->setMaximumWidth (MAX_BTN_WIDTH);
00063 layoutButtons->addWidget (m_btnCancel);
00064 connect (m_btnCancel, SIGNAL (released ()), this, SLOT (reject ()));
00065 }
00066
00067 DlgErrorReport::~DlgErrorReport()
00068 {
00069 removeFile();
00070 }
00071
00072 QString DlgErrorReport::errorFile () const
00073 {
00074 return QCoreApplication::applicationDirPath() + "/" + ERROR_REPORT_FILE;
00075 }
00076
00077 void DlgErrorReport::removeFile() const
00078 {
00079 QFile::remove (errorFile ());
00080 }
00081
00082 void DlgErrorReport::saveFile (const QString &xml) const
00083 {
00084 QFile file (errorFile());
00085 if (file.open (QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
00086
00087 QTextStream out (&file);
00088 out << xml;
00089
00090 file.close();
00091 }
00092 }
00093
00094 void DlgErrorReport::slotDocumentCheckboxChanged(int )
00095 {
00096 updateFile();
00097 }
00098
00099 void DlgErrorReport::slotSend()
00100 {
00101
00102 if (m_chkOriginal->isChecked()) {
00103 m_xmlToUpload = m_xmlOriginal;
00104 } else {
00105 m_xmlToUpload = m_xmlAnonymized;
00106 }
00107
00108 done (QDialog::Accepted);
00109
00110 close();
00111 }
00112
00113 void DlgErrorReport::updateFile()
00114 {
00115 if (m_chkOriginal->isChecked()) {
00116 saveFile (m_xmlOriginal);
00117 } else {
00118 saveFile (m_xmlAnonymized);
00119 }
00120 }
00121
00122 QString DlgErrorReport::xmlToUpload() const
00123 {
00124 return m_xmlToUpload;
00125 }