Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgErrorReport.cpp
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "DlgErrorReport.h"
8#include <QCheckBox>
9#include <QCommonStyle>
10#include <QCoreApplication>
11#include <QFile>
12#include <QHBoxLayout>
13#include <QLabel>
14#include <QPushButton>
15#include <QTextStream>
16#include <QVBoxLayout>
17
18const QString ERROR_REPORT_FILE ("engauge_error_report.xml");
19const int MAX_BTN_WIDTH = 80;
20
22 QWidget *parent) :
23 QDialog (parent),
24 m_xmlOriginal (xml),
25 m_xmlAnonymized (xml)
26{
27 QVBoxLayout *layout = new QVBoxLayout;
28 layout->setSizeConstraint (QLayout::SetFixedSize);
29 setLayout (layout);
30
31 QCommonStyle style;
32 setModal(true);
33 setWindowTitle (tr ("Error Report"));
34 setWindowIcon(style.standardIcon (QStyle::SP_MessageBoxCritical));
35
36 QLabel *lblPreview = new QLabel (tr ("An unrecoverable error has occurred. Would you like to send an error report to "
37 "the Engauge developers?\n\n"
38 "The original document can be sent as part of the error report, which increases the "
39 "chances of finding and fixing the problem(s). However, if any information is private "
40 "then an anonymized version of the document will be sent."));
41 lblPreview->setWordWrap(true);
42 layout->addWidget (lblPreview);
43
44 m_chkOriginal = new QCheckBox (tr ("Include original document information, otherwize anonymize the information"));
45 m_chkOriginal->setChecked (true);
46 updateFile ();
47 layout->addWidget (m_chkOriginal);
48 connect (m_chkOriginal, SIGNAL (stateChanged (int)), this, SLOT (slotDocumentCheckboxChanged (int)));
49
50 QHBoxLayout *layoutButtons = new QHBoxLayout;
51
52 QWidget *panelButtons = new QWidget;
53 panelButtons->setLayout (layoutButtons);
54 layout->addWidget (panelButtons);
55
56 m_btnSend = new QPushButton(tr ("Send"));
57 m_btnSend->setMaximumWidth (MAX_BTN_WIDTH);
58 layoutButtons->addWidget (m_btnSend);
59 connect (m_btnSend, SIGNAL (released ()), this, SLOT (slotSend()));
60
61 m_btnCancel = new QPushButton(tr ("Cancel"));
62 m_btnCancel->setMaximumWidth (MAX_BTN_WIDTH);
63 layoutButtons->addWidget (m_btnCancel);
64 connect (m_btnCancel, SIGNAL (released ()), this, SLOT (reject ()));
65}
66
67DlgErrorReport::~DlgErrorReport()
68{
69 removeFile();
70}
71
72QString DlgErrorReport::errorFile () const
73{
74 return QCoreApplication::applicationDirPath() + "/" + ERROR_REPORT_FILE;
75}
76
77void DlgErrorReport::removeFile() const
78{
79 QFile::remove (errorFile ());
80}
81
82void DlgErrorReport::saveFile (const QString &xml) const
83{
84 QFile file (errorFile());
85 if (file.open (QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
86
87 QTextStream out (&file);
88 out << xml;
89
90 file.close();
91 }
92}
93
94void DlgErrorReport::slotDocumentCheckboxChanged(int /* state */)
95{
96 updateFile();
97}
98
99void DlgErrorReport::slotSend()
100{
101 // This is the one path that allows information to be sent to the server
102 if (m_chkOriginal->isChecked()) {
103 m_xmlToUpload = m_xmlOriginal;
104 } else {
105 m_xmlToUpload = m_xmlAnonymized;
106 }
107
108 done (QDialog::Accepted);
109
110 close();
111}
112
113void DlgErrorReport::updateFile()
114{
115 if (m_chkOriginal->isChecked()) {
116 saveFile (m_xmlOriginal);
117 } else {
118 saveFile (m_xmlAnonymized);
119 }
120}
121
123{
124 return m_xmlToUpload;
125}
QString xmlToUpload() const
Xml to be uploaded. Includes document if user has approved.
DlgErrorReport(const QString &xmlWithImage, QWidget *parent=0)
Single constructor. With the original data, the extra context improves debugging. With anonymization,...