Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
DlgErrorReport.cpp
1 #include "DlgErrorReport.h"
2 #include <QCheckBox>
3 #include <QCommonStyle>
4 #include <QCoreApplication>
5 #include <QFile>
6 #include <QHBoxLayout>
7 #include <QLabel>
8 #include <QPushButton>
9 #include <QTextStream>
10 #include <QVBoxLayout>
11 
12 const QString ERROR_REPORT_FILE ("engauge_error_report.xml");
13 const int MAX_BTN_WIDTH = 80;
14 
15 DlgErrorReport::DlgErrorReport(const QString &xmlWithoutDocument,
16  const QString &xmlWithDocument,
17  QWidget *parent) :
18  QDialog (parent),
19  m_xmlWithoutDocument (xmlWithoutDocument),
20  m_xmlWithDocument (xmlWithDocument)
21 {
22  QVBoxLayout *layout = new QVBoxLayout;
23  layout->setSizeConstraint (QLayout::SetFixedSize);
24  setLayout (layout);
25 
26  QCommonStyle style;
27  setModal(true);
28  setWindowTitle (tr ("Error Report"));
29  setWindowIcon(style.standardIcon (QStyle::SP_MessageBoxCritical));
30 
31  QLabel *lblPreview = new QLabel (tr ("An unrecoverable error has occurred. Would you like to send an error report to "
32  "the Engauge developers?\n\n"
33  "Adding document information to the error report greatly increases the chances of finding "
34  "and fixing the problems. However, document information should not be included if your document "
35  "contains any information that should remain private."));
36  lblPreview->setWordWrap(true);
37  layout->addWidget (lblPreview);
38 
39  m_chkWithDocument = new QCheckBox ("Include document information");
40  m_chkWithDocument->setChecked (true);
41  updateFile ();
42  layout->addWidget (m_chkWithDocument);
43  connect (m_chkWithDocument, SIGNAL (stateChanged (int)), this, SLOT (slotDocumentCheckboxChanged (int)));
44 
45  QHBoxLayout *layoutButtons = new QHBoxLayout;
46 
47  QWidget *panelButtons = new QWidget;
48  panelButtons->setLayout (layoutButtons);
49  layout->addWidget (panelButtons);
50 
51  m_btnSend = new QPushButton(tr ("Send"));
52  m_btnSend->setMaximumWidth (MAX_BTN_WIDTH);
53  layoutButtons->addWidget (m_btnSend);
54  connect (m_btnSend, SIGNAL (released ()), this, SLOT (slotSend()));
55 
56  m_btnCancel = new QPushButton(tr ("Cancel"));
57  m_btnCancel->setMaximumWidth (MAX_BTN_WIDTH);
58  layoutButtons->addWidget (m_btnCancel);
59  connect (m_btnCancel, SIGNAL (released ()), this, SLOT (reject ()));
60 }
61 
62 DlgErrorReport::~DlgErrorReport()
63 {
64  removeFile();
65 }
66 
67 QString DlgErrorReport::errorFile () const
68 {
69  return QCoreApplication::applicationDirPath() + "/" + ERROR_REPORT_FILE;
70 }
71 
72 void DlgErrorReport::removeFile() const
73 {
74  QFile::remove (errorFile ());
75 }
76 
77 void DlgErrorReport::saveFile (const QString &xml) const
78 {
79  QFile file (errorFile());
80  if (file.open (QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
81 
82  QTextStream out (&file);
83  out << xml;
84 
85  file.close();
86  }
87 }
88 
89 void DlgErrorReport::slotDocumentCheckboxChanged(int /* state */)
90 {
91  updateFile();
92 }
93 
94 void DlgErrorReport::slotSend()
95 {
96  // This is the one path that allows information to be sent to the server
97  if (m_chkWithDocument->isChecked()) {
98  m_xmlToUpload = m_xmlWithDocument;
99  } else {
100  m_xmlToUpload = m_xmlWithoutDocument;
101  }
102 
103  done (QDialog::Accepted);
104 
105  close();
106 }
107 
108 void DlgErrorReport::updateFile()
109 {
110  if (m_chkWithDocument->isChecked()) {
111  saveFile (m_xmlWithDocument);
112  } else {
113  saveFile (m_xmlWithoutDocument);
114  }
115 }
116 
118 {
119  return m_xmlToUpload;
120 }
QString xmlToUpload() const
Xml to be uploaded. Includes document if user has approved.
DlgErrorReport(const QString &xmlWithoutDocument, const QString &xmlWithDocument, QWidget *parent=0)
Single constructor. With the Document, the extra context improves debugging. Without the Document...