Vidalia 0.2.12

CrashReportDialog.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file CrashReportDialog.cpp
00013 ** \brief Dialog that asks the user whether they would like to
00014 ** submit the crash report, along with optional additional details
00015 ** about what they were doing at the time of the crash.
00016 */
00017 
00018 #include "CrashReportDialog.h"
00019 #include "CrashReportUploader.h"
00020 #include "UploadProgressDialog.h"
00021 
00022 #include "stringutil.h"
00023 
00024 #include <QProcess>
00025 #include <QPushButton>
00026 #include <QMessageBox>
00027 #include <QFileInfo>
00028 
00029 
00030 CrashReportDialog::CrashReportDialog(QWidget *parent)
00031   : QDialog(parent)
00032 {
00033   ui.setupUi(this);
00034 
00035   /* Tweak the text displayed on the buttons at the bottom of the dialog */
00036   QPushButton *btn;
00037   btn = ui.buttonBox->button(QDialogButtonBox::Ok);
00038   btn->setText(tr("Restart Vidalia"));
00039 
00040   btn = ui.buttonBox->button(QDialogButtonBox::Cancel);
00041   btn->setText(tr("Don't Restart"));
00042 }
00043 
00044 void
00045 CrashReportDialog::setCrashAnnotations(const QHash<QString,QString> &annotations)
00046 {
00047   _annotations = annotations;
00048 }
00049 
00050 void
00051 CrashReportDialog::setMinidump(const QString &id, const QByteArray &minidump)
00052 {
00053   _minidump = minidump;
00054   _minidumpId = id;
00055 }
00056 
00057 void
00058 CrashReportDialog::submitCrashReport()
00059 {
00060   CrashReportUploader *uploader = new CrashReportUploader();
00061   UploadProgressDialog *progressDialog = new UploadProgressDialog(this);
00062   QMap<QString,QString> parameters;
00063 
00064   connect(uploader, SIGNAL(statusChanged(QString)),
00065           progressDialog, SLOT(setStatus(QString)));
00066   connect(uploader, SIGNAL(uploadProgress(int, int)),
00067           progressDialog, SLOT(setUploadProgress(int, int)));
00068   connect(uploader, SIGNAL(uploadFinished()),
00069           progressDialog, SLOT(accept()));
00070   connect(uploader, SIGNAL(uploadFailed(QString)),
00071           progressDialog, SLOT(uploadFailed(QString)));
00072 
00073   /* Set up the form fields that will be uploaded with the minidump */
00074   QString comments = ui.textDetails->toPlainText();
00075   if (! comments.isEmpty())
00076     parameters.insert("Comments", comments);
00077   parameters.insert("ProductName", "Vidalia");
00078   parameters.insert("Vendor", "Vidalia");
00079   parameters.insert("Version", _annotations.value("BuildVersion"));
00080   parameters.insert("CrashTime", _annotations.value("CrashTime"));
00081   parameters.insert("StartupTime", _annotations.value("StartupTime"));
00082 
00083   /* Start the upload (returns immediately) */
00084   uploader->uploadMinidump(QUrl("https://crashes.vidalia-project.net/submit"),
00085                            _minidumpId, _minidump, parameters);
00086 
00087   /* Displays a modal progress dialog showing the progress of the upload. This
00088    * will return when either the upload completes or the user hits "Cancel". */
00089   if (progressDialog->exec() == QDialog::Rejected)
00090     uploader->cancel(); /* User clicked "Cancel" */
00091 
00092   delete uploader;
00093 }
00094 
00095 void
00096 CrashReportDialog::accept()
00097 {
00098   /* Upload the crash report, unless the user opted out */
00099   if (ui.chkSubmitCrashReport->isChecked())
00100     submitCrashReport();
00101 
00102   /* Attempt to restart Vidalia with the saved arguments */
00103   QString exe  = _annotations.value("RestartExecutable");
00104   QString args = _annotations.value("RestartExecutableArgs");
00105   QStringList argList = string_parse_arguments(args);
00106   if (! QProcess::startDetached(exe, argList, QFileInfo(exe).absolutePath())) {
00107     QMessageBox dlg(QMessageBox::Warning, tr("Unable to restart Vidalia"),
00108                     tr("We were unable to automatically restart Vidalia. "
00109                        "Please restart Vidalia manually."),
00110                     QMessageBox::Ok, this);
00111     dlg.exec();
00112   }
00113 
00114   /* Close the dialog */
00115   QDialog::accept();
00116 }
00117 
00118 void
00119 CrashReportDialog::reject()
00120 {
00121   /* Upload the crash report, unless the user opted out */
00122   if (ui.chkSubmitCrashReport->isChecked())
00123     submitCrashReport();
00124 
00125   /* Close this dialog without restarting Vidalia */
00126   QDialog::reject();
00127 }
00128