[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r3858: Restart Vidalia with the original arguments when the crash r (vidalia/branches/breakpad/src/crashreporter)



Author: edmanm
Date: 2009-06-15 17:24:20 -0400 (Mon, 15 Jun 2009)
New Revision: 3858

Modified:
   vidalia/branches/breakpad/src/crashreporter/CMakeLists.txt
   vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.cpp
   vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.h
   vidalia/branches/breakpad/src/crashreporter/main.cpp
Log:

Restart Vidalia with the original arguments when the crash reporter is
finished, and stub in a method for uploading the minidump. Also change
the annotations file parser to use QTextStream::atEnd() instead of
QFile::atEnd(). Turns out QTextStream buffers multiple lines in one
call to readLine(), so QFile::atEnd() could return true before we had
iterated through every line.


Modified: vidalia/branches/breakpad/src/crashreporter/CMakeLists.txt
===================================================================
--- vidalia/branches/breakpad/src/crashreporter/CMakeLists.txt	2009-06-15 20:38:44 UTC (rev 3857)
+++ vidalia/branches/breakpad/src/crashreporter/CMakeLists.txt	2009-06-15 21:24:20 UTC (rev 3858)
@@ -52,6 +52,7 @@
   ${QT_QTCORE_LIBRARY}
   ${QT_QTGUI_LIBRARY}
   ${QT_QTNETWORK_LIBRARY}
+  common
 )
 if (WIN32)
   target_link_libraries(crashreporter

Modified: vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.cpp
===================================================================
--- vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.cpp	2009-06-15 20:38:44 UTC (rev 3857)
+++ vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.cpp	2009-06-15 21:24:20 UTC (rev 3858)
@@ -17,13 +17,15 @@
 */
 
 #include "CrashReportDialog.h"
+#include "stringutil.h"
 
+#include <QProcess>
 #include <QPushButton>
+#include <QMessageBox>
+#include <QFileInfo>
 
 
-CrashReportDialog::CrashReportDialog(const QByteArray &minidump,
-                                     const QHash<QString,QString> &annotations,
-                                     QWidget *parent)
+CrashReportDialog::CrashReportDialog(QWidget *parent)
   : QDialog(parent)
 {
   ui.setupUi(this);
@@ -37,3 +39,55 @@
   btn->setText(tr("Don't Restart"));
 }
 
+void
+CrashReportDialog::setCrashAnnotations(const QHash<QString,QString> &annotations)
+{
+  _annotations = annotations;
+}
+
+void
+CrashReportDialog::setMinidump(const QByteArray &minidump)
+{
+  _minidump = minidump;
+}
+
+void
+CrashReportDialog::submitCrashReport() const
+{
+  /* Upload the crash report to crashes.vidalia-project.net */
+}
+
+void
+CrashReportDialog::accept()
+{
+  /* Upload the crash report, unless the user opted out */
+  if (ui.chkSubmitCrashReport->isChecked())
+    submitCrashReport();
+
+  /* Attempt to restart Vidalia with the saved arguments */
+  QString exe  = _annotations.value("RestartExecutable");
+  QString args = _annotations.value("RestartExecutableArgs");
+  QStringList argList = string_parse_arguments(args);
+  if (! QProcess::startDetached(exe, argList, QFileInfo(exe).absolutePath())) {
+    QMessageBox dlg(QMessageBox::Warning, tr("Unable to restart Vidalia"),
+                    tr("We were unable to automatically restart Vidalia. "
+                       "Please restart Vidalia manually."),
+                    QMessageBox::Ok, this);
+    dlg.exec();
+  }
+
+  /* Close the dialog */
+  QDialog::accept();
+}
+
+void
+CrashReportDialog::reject()
+{
+  /* Upload the crash report, unless the user opted out */
+  if (ui.chkSubmitCrashReport->isChecked())
+    submitCrashReport();
+
+  /* Close this dialog without restarting Vidalia */
+  QDialog::reject();
+}
+

Modified: vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.h
===================================================================
--- vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.h	2009-06-15 20:38:44 UTC (rev 3857)
+++ vidalia/branches/breakpad/src/crashreporter/CrashReportDialog.h	2009-06-15 21:24:20 UTC (rev 3858)
@@ -19,9 +19,9 @@
 #include "ui_CrashReportDialog.h"
 
 #include <QHash>
+#include <QByteArray>
 
 class QString;
-class QByteArray;
 
 
 class CrashReportDialog : public QDialog
@@ -31,12 +31,55 @@
 public:
   /** Default constructor.
    */
-  CrashReportDialog(const QByteArray &minidump,
-                    const QHash<QString,QString> &annotations,
-                    QWidget *parent = 0);
+  CrashReportDialog(QWidget *parent = 0);
 
+  /** Sets the crash <b>annotations</b> key-value pairs associated with
+   * the generated minidump.
+   */
+  void setCrashAnnotations(const QHash<QString,QString> &annotations);
+
+  /** Sets the <b>minidump</b> contents generated by the crashed
+   * applications exception handler.
+   */
+  void setMinidump(const QByteArray &minidump);
+
+  /** Uploads the generated minidump, user comments, and any additional
+   * crash annotations generated by the exception handler to the crash
+   * reporting server.
+   * \sa setMinidump()
+   * \sa setCrashAnnotations()
+   */
+  void submitCrashReport() const;
+
+public slots:
+  /** Called when the user clicks the "Restart Vidalia" button on the
+   * dialog. If the "Submit my crash report..." checkbox is checked, it
+   * will first attempt to submit the crash report. After that is complete,
+   * it will try to restart the Vidalia process with any arguments specified
+   * in the crash annotations file.
+   * \sa setCrashAnnotations()
+   */
+  virtual void accept();
+
+  /** Called when the user clicks the "Don't Restart" button on the
+   * dialog. If the "Submit my crash report.." checkbox is checked, it
+   * will attempt to submit the crash report and then exit without
+   * restarting Vidalia.
+   */
+  virtual void reject();
+
 private:
-  /** Qt Designer created object. */
+  /** Contents of the generated minidump.
+   */
+  QByteArray _minidump;
+
+  /** Set of parsed key-value pairs generated by the crashed application's
+   * exception handler and written alongside the minidump.
+   */
+  QHash<QString,QString> _annotations;
+
+  /** Qt Designer created object.
+   */
   Ui::CrashReportDialog ui;
 };
 

Modified: vidalia/branches/breakpad/src/crashreporter/main.cpp
===================================================================
--- vidalia/branches/breakpad/src/crashreporter/main.cpp	2009-06-15 20:38:44 UTC (rev 3857)
+++ vidalia/branches/breakpad/src/crashreporter/main.cpp	2009-06-15 21:24:20 UTC (rev 3858)
@@ -72,7 +72,7 @@
   /* The annotations file should be UTF-8 encoded */
   QTextStream reader(&infile);
   reader.setCodec(QTextCodec::codecForName("utf-8"));
-  while (! infile.atEnd()) {
+  while (! reader.atEnd()) {
     QString line = reader.readLine().trimmed();
     if (line.isEmpty())
       continue;
@@ -91,6 +91,7 @@
 main(int argc, char *argv[])
 {
   QApplication app(argc, argv);
+  CrashReportDialog crashDialog;
   QFileInfo minidumpFile, extraInfoFile;
   QString minidumpFileName, extraInfoFileName, errorMessage;
   QHash<QString,QString> annotations;
@@ -149,11 +150,10 @@
   }
 
   /* Display the crash reporting dialog */
-  {
-    CrashReportDialog dlg(minidump, annotations);
-    dlg.show();
-    return app.exec();
-  }
+  crashDialog.setMinidump(minidump);
+  crashDialog.setCrashAnnotations(annotations);
+  crashDialog.show();
+  return app.exec();
 
 err:
   /* We encountered an error trying to load the minidump or extra crash