Vidalia 0.2.10

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