~ubuntu-branches/ubuntu/saucy/goldencheetah/saucy

« back to all changes in this revision

Viewing changes to src/GcCrashDialog.cpp

  • Committer: Package Import Robot
  • Author(s): KURASHIKI Satoru
  • Date: 2013-08-18 07:02:45 UTC
  • mfrom: (4.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130818070245-zgdvb47e1k3mtgil
Tags: 3.0-3
debian/control: remove needless dependency. (Closes: #719571)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2013 Mark Liversedge (liversedge@gmail.com)
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License as published by the Free
 
6
 * Software Foundation; either version 2 of the License, or (at your option)
 
7
 * any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
12
 * more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc., 51
 
16
 * Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 */
 
18
 
 
19
#include "GcCrashDialog.h"
 
20
#include "Settings.h"
 
21
#include "GcUpgrade.h"
 
22
#include <QtGui>
 
23
#include <QWebFrame>
 
24
 
 
25
#include "DBAccess.h"
 
26
#include "MetricAggregator.h"
 
27
#include <QtSql>
 
28
 
 
29
#define GCC_VERSION QString("%1.%2.%3").arg(__GNUC__).arg(__GNUC_MINOR__).arg(__GNUC_PATCHLEVEL__)
 
30
 
 
31
#ifdef GC_HAVE_QWTPLOT3D
 
32
#include "qwt3d_global.h"
 
33
#endif
 
34
 
 
35
#ifdef GC_HAVE_ICAL
 
36
#include "ICalendar.h"
 
37
#endif
 
38
 
 
39
#ifdef GC_HAVE_D2XX
 
40
#include "D2XX.h"
 
41
#endif
 
42
 
 
43
#ifdef GC_HAVE_LIBOAUTH
 
44
#include <oauth.h>
 
45
#endif
 
46
 
 
47
#ifdef GC_HAVE_LUCENE
 
48
#include "Lucene.h"
 
49
#endif
 
50
 
 
51
#ifdef GC_HAVE_WFAPI
 
52
#include "WFApi.h"
 
53
#endif
 
54
 
 
55
GcCrashDialog::GcCrashDialog(QDir home) : QDialog(NULL, Qt::Dialog), home(home)
 
56
{
 
57
    setAttribute(Qt::WA_DeleteOnClose, true); // caller must delete me, once they've extracted the name
 
58
    setWindowTitle(QString(tr("%1 Crash Recovery").arg(home.dirName())));
 
59
 
 
60
    QVBoxLayout *layout = new QVBoxLayout(this);
 
61
 
 
62
    QHBoxLayout *toprow = new QHBoxLayout;
 
63
 
 
64
    QPushButton *critical = new QPushButton(style()->standardIcon(QStyle::SP_MessageBoxCritical), "", this); 
 
65
    critical->setFixedSize(128,128);
 
66
    critical->setFlat(true);
 
67
    critical->setIconSize(QSize(120,120));
 
68
    critical->setAutoFillBackground(false);
 
69
    critical->setFocusPolicy(Qt::NoFocus);
 
70
 
 
71
    QLabel *header = new QLabel(this);
 
72
    header->setWordWrap(true);
 
73
    header->setTextFormat(Qt::RichText);
 
74
    header->setText(tr("<b>GoldenCheetah appears to have PREVIOUSLY crashed for this athlete. "
 
75
                       "</b><br><br>The report below gives some diagnostic information "
 
76
                       "that will be useful to the developers. Feel free to post this with a "
 
77
                       "short description of what was occurring when the crash happened to the "
 
78
                       "<href a=\"https://groups.google.com/forum/?fromgroups=#!forum/golden-cheetah-users\">"
 
79
                       "GoldenCheetah forums</href><br>"
 
80
                       "<b><br>We respect privacy - this log does NOT contain ids, passwords or personal information.</b><br>"
 
81
                       "<b><br>When this dialog is closed the athlete will be opened.</b>"));
 
82
 
 
83
    toprow->addWidget(critical);
 
84
    toprow->addWidget(header);
 
85
    layout->addLayout(toprow);
 
86
 
 
87
    report = new QWebView(this);
 
88
    report->setContentsMargins(0,0,0,0);
 
89
    report->page()->view()->setContentsMargins(0,0,0,0);
 
90
    report->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
91
    report->setAcceptDrops(false);
 
92
 
 
93
    QFont defaultFont; // mainwindow sets up the defaults.. we need to apply
 
94
    report->settings()->setFontSize(QWebSettings::DefaultFontSize, defaultFont.pointSize()+1);
 
95
    report->settings()->setFontFamily(QWebSettings::StandardFont, defaultFont.family());
 
96
 
 
97
    layout->addWidget(report);
 
98
 
 
99
    QHBoxLayout *lastRow = new QHBoxLayout;
 
100
    QPushButton *saveAsButton = new QPushButton(tr("Save Crash Report..."), this);
 
101
    connect(saveAsButton, SIGNAL(clicked()), this, SLOT(saveAs()));
 
102
    QPushButton *OKButton = new QPushButton(tr("Close"), this);
 
103
    connect(OKButton, SIGNAL(clicked()), this, SLOT(accept()));
 
104
 
 
105
    lastRow->addWidget(saveAsButton);
 
106
    lastRow->addStretch();
 
107
    lastRow->addWidget(OKButton);
 
108
    layout->addLayout(lastRow);
 
109
 
 
110
    setHTML();
 
111
}
 
112
 
 
113
QString GcCrashDialog::versionHTML()
 
114
{
 
115
    // -- OS ----
 
116
    QString os = "";
 
117
 
 
118
    #ifdef Q_OS_LINUX
 
119
    os = "Linux";
 
120
    #endif
 
121
 
 
122
    #ifdef WIN32
 
123
    os = "Win";
 
124
    #endif
 
125
 
 
126
    #ifdef Q_OS_MAC
 
127
    os = QString("Mac OS X 10.%1").arg(QSysInfo::MacintoshVersion - 2);
 
128
    if (QSysInfo::MacintoshVersion == QSysInfo::MV_SNOWLEOPARD)
 
129
        os += " Snow Leopard";
 
130
    else if (QSysInfo::MacintoshVersion == QSysInfo::MV_LION)
 
131
        os += " Lion";
 
132
    else if (QSysInfo::MacintoshVersion == 10)
 
133
        os += " Mountain Lion";
 
134
 
 
135
    #endif
 
136
 
 
137
    // -- SCHEMA VERSION ----
 
138
    QString schemaVersion = QString("%1").arg(DBSchemaVersion);
 
139
 
 
140
    // -- SRMIO ----
 
141
    QString srmio = "none";
 
142
 
 
143
    #ifdef GC_HAVE_SRMIO
 
144
    srmio = "yes";
 
145
    #endif
 
146
 
 
147
    // -- D2XX ----
 
148
    QString d2xx = "none";
 
149
 
 
150
    #ifdef GC_HAVE_D2XX
 
151
    d2xx = "yes";
 
152
    #endif
 
153
 
 
154
    // -- LIBOAUTH ----
 
155
    QString oauth = "none";
 
156
 
 
157
    #ifdef GC_HAVE_LIBOAUTH
 
158
    oauth = LIBOAUTH_VERSION;
 
159
    #endif
 
160
 
 
161
    // -- QWTPLOT3D ----
 
162
    QString qwtplot3d = "none";
 
163
 
 
164
    #ifdef GC_HAVE_QWTPLOT3D
 
165
    qwtplot3d = QString::number(QWT3D_MAJOR_VERSION) + "."
 
166
            + QString::number(QWT3D_MINOR_VERSION) + "."
 
167
            + QString::number(QWT3D_PATCH_VERSION);
 
168
    #endif
 
169
 
 
170
    // -- KML ----
 
171
    QString kml = "none";
 
172
 
 
173
    #ifdef GC_HAVE_KML
 
174
    kml = "yes";
 
175
    #endif
 
176
 
 
177
    // -- ICAL ----
 
178
    QString ical = "none";
 
179
 
 
180
    #ifdef GC_HAVE_ICAL
 
181
    ical = ICAL_VERSION;
 
182
    #endif
 
183
 
 
184
    // -- USBXPRESS ----
 
185
    QString usbxpress = "none";
 
186
    #ifdef GC_HAVE_USBXPRESS
 
187
    usbxpress = "yes";
 
188
    #endif
 
189
 
 
190
    // -- LIBUSB ----
 
191
    QString libusb = "none";
 
192
    #ifdef GC_HAVE_LIBUSB
 
193
    libusb = "yes";
 
194
    #endif
 
195
 
 
196
    // -- VLC ----
 
197
    QString vlc = "none";
 
198
    #ifdef GC_HAVE_VLC
 
199
    vlc = "yes";
 
200
    #endif
 
201
 
 
202
    // -- LUCENE ----
 
203
    QString clucene = "none";
 
204
    #ifdef GC_HAVE_LUCENE
 
205
    clucene = _CL_VERSION;
 
206
    #endif
 
207
 
 
208
    // -- LION SUPPORT ----
 
209
    #ifdef Q_OS_MAC
 
210
    QString lionSupport = "no";
 
211
    #ifdef GC_HAVE_LION
 
212
    lionSupport = "yes";
 
213
    #endif
 
214
    #endif
 
215
 
 
216
    #ifdef GC_HAVE_WFAPI
 
217
    QString wfapi = WFApi::getInstance()->apiVersion();
 
218
    #else
 
219
    QString wfapi = QString("none");
 
220
    #endif
 
221
 
 
222
    QString gc_version = tr(
 
223
            "<p>Build date: %1 %2"
 
224
            "<br>Build id: %3"
 
225
            "<br>Version: %4"
 
226
            "<br>DB Schema: %5"
 
227
            "<br>OS: %6"
 
228
            "<br>")
 
229
            .arg(__DATE__)
 
230
            .arg(__TIME__)
 
231
            .arg(GcUpgrade::version())
 
232
#ifdef GC_VERSION
 
233
            .arg(GC_VERSION)
 
234
#else
 
235
            .arg("(developer build)")
 
236
#endif
 
237
            .arg(schemaVersion)
 
238
            .arg(os);
 
239
 
 
240
    QString lib_version = tr(
 
241
            "<table>"
 
242
            "<tr><td colspan=\"2\">QT</td><td>%1</td></tr>"
 
243
            "<tr><td colspan=\"2\">QWT</td><td>%2</td></tr>"
 
244
            "<tr><td colspan=\"2\">GCC</td><td>%3</td></tr>"
 
245
            "<tr><td colspan=\"2\">SRMIO</td><td>%4</td></tr>"
 
246
            "<tr><td colspan=\"2\">OAUTH</td><td>%5</td></tr>"
 
247
            "<tr><td colspan=\"2\">D2XX</td><td>%6</td></tr>"
 
248
            "<tr><td colspan=\"2\">QWTPLOT3D</td><td>%7</td></tr>"
 
249
            "<tr><td colspan=\"2\">KML</td><td>%8</td></tr>"
 
250
            "<tr><td colspan=\"2\">ICAL</td><td>%9</td></tr>"
 
251
            "<tr><td colspan=\"2\">USBXPRESS</td><td>%10</td></tr>"
 
252
            "<tr><td colspan=\"2\">LIBUSB</td><td>%11</td></tr>"
 
253
            "<tr><td colspan=\"2\">Wahoo API</td><td>%12</td></tr>"
 
254
            "<tr><td colspan=\"2\">VLC</td><td>%13</td></tr>"
 
255
            "<tr><td colspan=\"2\">LUCENE</td><td>%14</td></tr>"
 
256
            #ifdef Q_OS_MAC
 
257
            "<tr><td colspan=\"2\">LION SUPPORT</td><td>%15</td></tr>"
 
258
            #endif
 
259
            "</table>"
 
260
            )
 
261
            .arg(QT_VERSION_STR)
 
262
            .arg(QWT_VERSION_STR)
 
263
            .arg(GCC_VERSION)
 
264
            .arg(srmio)
 
265
            .arg(oauth)
 
266
            .arg(d2xx)
 
267
            .arg(qwtplot3d)
 
268
            .arg(kml)
 
269
            .arg(ical)
 
270
            .arg(usbxpress)
 
271
            .arg(libusb)
 
272
            .arg(wfapi)
 
273
            .arg(vlc)
 
274
            .arg(clucene)
 
275
            #ifdef Q_OS_MAC
 
276
            .arg(lionSupport)
 
277
            #endif
 
278
            ;
 
279
 
 
280
    QString versionText = QString("<center>"  + gc_version  + lib_version + "</center>");
 
281
 
 
282
    return versionText;
 
283
}
 
284
 
 
285
void
 
286
GcCrashDialog::setHTML()
 
287
{
 
288
    QString text;
 
289
 
 
290
    // the cyclist...
 
291
    text += QString("<center><h3>Cyclist: \"%1\"</h3></center><br>").arg(home.dirName());
 
292
 
 
293
    // version info
 
294
    text += "<center><h3>Version Info</h3></center>";
 
295
    text += versionHTML();
 
296
 
 
297
    // metric log...
 
298
    text += "<center><h3>Metric Log</h3></center>";
 
299
    text += "<center><table border=0 cellspacing=10 width=\"90%\">";
 
300
    QFile metriclog(home.absolutePath() + "/" + "metric.log");
 
301
    if (metriclog.open(QIODevice::ReadOnly)) {
 
302
 
 
303
        // read in line by line and add to diag file
 
304
        QTextStream in(&metriclog);
 
305
        while (!in.atEnd()) {
 
306
            QString lines = in.readLine();
 
307
            foreach(QString line, lines.split('\r')) {
 
308
                text += "<tr><td align=\"center\">" + line + "</td></tr>";
 
309
            }
 
310
        }
 
311
 
 
312
        metriclog.close();
 
313
    }
 
314
    text += "</table></center>";
 
315
 
 
316
    // files...
 
317
    text += "<center><h3>Athlete Directory</h3></center>";
 
318
    text += "<center><table border=0 cellspacing=10 width=\"90%\">";
 
319
    foreach(QString file, home.entryList(QDir::NoFilter, QDir::Time)) {
 
320
        text += QString("<tr><td align=\"right\"> %1</td><td align=\"left\">%2</td></tr>")
 
321
                .arg(file)
 
322
                .arg(QFileInfo(home.absolutePath() + "/" + file).lastModified().toString());
 
323
    }
 
324
    text += "</table></center>";
 
325
 
 
326
 
 
327
    // settings...
 
328
    text += "<center><h3>All Settings</h3></center>";
 
329
    text += "<center><table border=0 cellspacing=10 width=\"90%\">";
 
330
    foreach(QString key, appsettings->allKeys()) {
 
331
 
 
332
        // RESPECT PRIVACY
 
333
        // we do not disclose user names and passwords or key ids
 
334
        if (key.endsWith("/user") || key.endsWith("/pass") || key.endsWith("/key")) continue;
 
335
 
 
336
        // we do not disclose personally identifiable information
 
337
        if (key.endsWith("/dob") || key.endsWith("/weight") ||
 
338
            key.endsWith("/sex") || key.endsWith("/bio")) continue;
 
339
 
 
340
 
 
341
        text += QString("<tr><td align=\"right\" width=\"50%\"> %1</td><td align=\"left\">"
 
342
                        "<span style=\"max-width:50%;\">%2</span></td></tr>")
 
343
                .arg(key)
 
344
                .arg(appsettings->value(NULL, key).toString().leftJustified(60, ' ', true));
 
345
    }
 
346
    text += "</table></center>";
 
347
 
 
348
 
 
349
        report->page()->mainFrame()->setHtml(text);
 
350
}
 
351
 
 
352
void
 
353
GcCrashDialog::saveAs()
 
354
{
 
355
    QString fileName = QFileDialog::getSaveFileName( this, tr("Save Diagnostics"), QDir::homePath(), tr("Text File (*.txt)"));
 
356
 
 
357
    // now write to it
 
358
    QFile file(fileName);
 
359
    file.resize(0);
 
360
    QTextStream out(&file);
 
361
    out.setCodec("UTF-8");
 
362
 
 
363
    if (file.open(QIODevice::WriteOnly)) {
 
364
 
 
365
        // write the texts
 
366
        out << report->page()->mainFrame()->toPlainText();
 
367
 
 
368
    }
 
369
    file.close();
 
370
}