Engauge Digitizer  2
DlgErrorReportNetworking.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 "DlgErrorReportNetworking.h"
8 #include <QCheckBox>
9 #include <QCommonStyle>
10 #include <QFile>
11 #include <QHBoxLayout>
12 #include <QLabel>
13 #include <QPushButton>
14 #include <QTextStream>
15 #include <QVBoxLayout>
16 
17 const int MAX_BTN_WIDTH = 80;
18 
20  QWidget *parent) :
22  m_xmlOriginal (xml),
23  m_xmlAnonymized (xml)
24 {
25  QVBoxLayout *layout = new QVBoxLayout;
26  layout->setSizeConstraint (QLayout::SetFixedSize);
27  setLayout (layout);
28 
29  QCommonStyle style;
30  setModal(true);
31  setWindowTitle (tr ("Error Report"));
32  setWindowIcon(style.standardIcon (QStyle::SP_MessageBoxCritical));
33 
34  QLabel *lblMessage = new QLabel (tr ("An unrecoverable error has occurred. Would you like to send an error report to "
35  "the Engauge developers?\n\n"
36  "The original document can be sent as part of the error report, which increases the "
37  "chances of finding and fixing the problem(s). However, if any information is private "
38  "then an anonymized version of the document will be sent."));
39  lblMessage->setWordWrap(true);
40  layout->addWidget (lblMessage);
41 
42  m_chkOriginal = new QCheckBox (tr ("Include original document information, otherwise anonymize the information"));
43  m_chkOriginal->setChecked (true);
44  updateFile ();
45  layout->addWidget (m_chkOriginal);
46  connect (m_chkOriginal, SIGNAL (stateChanged (int)), this, SLOT (slotDocumentCheckboxChanged (int)));
47 
48  QHBoxLayout *layoutButtons = new QHBoxLayout;
49 
50  QWidget *panelButtons = new QWidget;
51  panelButtons->setLayout (layoutButtons);
52  layout->addWidget (panelButtons);
53 
54  m_btnSend = new QPushButton(tr ("Send"));
55  m_btnSend->setMaximumWidth (MAX_BTN_WIDTH);
56  layoutButtons->addWidget (m_btnSend);
57  connect (m_btnSend, SIGNAL (released ()), this, SLOT (slotSend()));
58 
59  m_btnCancel = new QPushButton(tr ("Cancel"));
60  m_btnCancel->setMaximumWidth (MAX_BTN_WIDTH);
61  layoutButtons->addWidget (m_btnCancel);
62  connect (m_btnCancel, SIGNAL (released ()), this, SLOT (reject ()));
63 }
64 
65 DlgErrorReportNetworking::~DlgErrorReportNetworking()
66 {
67  removeFile();
68 }
69 
70 void DlgErrorReportNetworking::removeFile() const
71 {
72  QFile::remove (errorFile ());
73 }
74 
75 void DlgErrorReportNetworking::slotDocumentCheckboxChanged(int /* state */)
76 {
77  updateFile();
78 }
79 
80 void DlgErrorReportNetworking::slotSend()
81 {
82  // This is the one path that allows information to be sent to the server
83  if (m_chkOriginal->isChecked()) {
84  m_xmlToUpload = m_xmlOriginal;
85  } else {
86  m_xmlToUpload = m_xmlAnonymized;
87  }
88 
89  done (QDialog::Accepted);
90 
91  close();
92 }
93 
94 void DlgErrorReportNetworking::updateFile()
95 {
96  if (m_chkOriginal->isChecked()) {
97  saveFile (m_xmlOriginal);
98  } else {
99  saveFile (m_xmlAnonymized);
100  }
101 }
102 
104 {
105  return m_xmlToUpload;
106 }
QString errorFile() const
File name for output file containing error report.
QString xmlToUpload() const
Xml to be uploaded. Includes document if user has approved.
void saveFile(const QString &xml) const
Save xml into output file named by errorFile.
DlgErrorReportNetworking(const QString &xmlWithImage, QWidget *parent=0)
Single constructor. With the original data, the extra context improves debugging. With anonymization...
Base class for dialogs that handle the error report.