Merge with feature-crashreport

This commit is contained in:
kaetemi 2015-03-06 16:01:05 +01:00
parent b63f917cde
commit 870dcf6547
4 changed files with 200 additions and 65 deletions

View file

@ -88,5 +88,11 @@ int main( int argc, char **argv )
w.setup( params );
w.show();
return app.exec();
int ret = app.exec();
if( ret != EXIT_SUCCESS )
return ret;
else
return w.getReturnValue();
}

View file

@ -25,18 +25,24 @@
#include <QFile>
#include <QMessageBox>
#include <QFile>
#include <QPushButton>
#include <QHBoxLayout>
#include <QCheckBox>
CCrashReportWidget::CCrashReportWidget( QWidget *parent ) :
QWidget( parent )
{
m_developerMode = false;
m_forceSend = false;
m_devSendReport = false;
m_returnValue = ERET_NULL;
m_ui.setupUi( this );
m_socket = new CCrashReportSocket( this );
QTimer::singleShot( 1, this, SLOT( onLoad() ) );
connect( m_ui.sendButton, SIGNAL( clicked( bool ) ), this, SLOT( onSendClicked() ) );
connect( m_ui.canceButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) );
connect( m_ui.emailCB, SIGNAL( stateChanged( int ) ), this, SLOT( onCBClicked() ) );
connect( m_socket, SIGNAL( reportSent() ), this, SLOT( onReportSent() ) );
@ -59,6 +65,8 @@ void CCrashReportWidget::setup( const std::vector< std::pair< std::string, std::
if( k == "log" )
{
m_fileName = v.c_str();
if( !QFile::exists( m_fileName ) )
m_fileName.clear();
}
else
if( k == "host" )
@ -70,25 +78,105 @@ void CCrashReportWidget::setup( const std::vector< std::pair< std::string, std::
{
setWindowTitle( v.c_str() );
}
else
if( k == "dev" )
{
m_developerMode = true;
}
else
if( k == "sendreport" )
{
m_forceSend = true;
}
}
if( m_fileName.isEmpty() )
{
m_ui.reportLabel->hide();
m_ui.reportEdit->hide();
}
if( m_socket->url().isEmpty() || m_fileName.isEmpty() )
{
m_ui.descriptionEdit->hide();
m_ui.emailCB->hide();
m_ui.emailEdit->hide();
m_ui.descrLabel->hide();
}
QHBoxLayout *hbl = new QHBoxLayout( this );
if( m_developerMode )
{
if( !m_socket->url().isEmpty() && !m_fileName.isEmpty() )
{
m_ui.emailCB->setEnabled( false );
QCheckBox *cb = new QCheckBox( tr( "Send report" ), this );
m_ui.gridLayout->addWidget( cb, 4, 0, 1, 1 );
m_ui.gridLayout->addWidget( m_ui.emailCB, 5, 0, 1, 1 );
m_ui.gridLayout->addWidget( m_ui.emailEdit, 6, 0, 1, 1 );
connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onSendCBClicked() ) );
}
QPushButton *alwaysIgnoreButton = new QPushButton( tr( "Always Ignore" ), this );
QPushButton *ignoreButton = new QPushButton( tr( "Ignore" ), this );
QPushButton *abortButton = new QPushButton( tr( "Abort" ), this );
QPushButton *breakButton = new QPushButton( tr( "Break" ), this );
hbl->addWidget( alwaysIgnoreButton );
hbl->addWidget( ignoreButton );
hbl->addWidget( abortButton );
hbl->addWidget( breakButton );
m_ui.gridLayout->addLayout( hbl, 7, 0, 1, 3 );
connect( alwaysIgnoreButton, SIGNAL( clicked( bool ) ), this, SLOT( onAlwaysIgnoreClicked() ) );
connect( ignoreButton, SIGNAL( clicked( bool ) ), this, SLOT( onIgnoreClicked() ) );
connect( abortButton, SIGNAL( clicked( bool ) ), this, SLOT( onAbortClicked() ) );
connect( breakButton, SIGNAL( clicked( bool ) ), this, SLOT( onBreakClicked() ) );
}
else
{
// If -host is specified, offer the send function
if( !m_socket->url().isEmpty() && !m_fileName.isEmpty() )
{
QPushButton *sendButton = new QPushButton( tr( "Send report" ), this );
connect( sendButton, SIGNAL( clicked( bool ) ), this, SLOT( onSendClicked() ) );
hbl->addWidget( sendButton );
if( !m_forceSend )
{
QPushButton *cancelButton = new QPushButton( tr( "Don't send report" ), this );
connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) );
hbl->addWidget( cancelButton );
}
}
// Otherwise only offer exit
else
{
QPushButton *exitButton = new QPushButton( tr( "Exit" ), this );
connect( exitButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) );
hbl->addWidget( exitButton );
}
m_ui.gridLayout->addLayout( hbl, 6, 0, 1, 3 );
}
}
void CCrashReportWidget::onLoad()
{
if( !checkSettings() )
{
close();
if( m_fileName.isEmpty() )
return;
}
QFile f( m_fileName );
bool b = f.open( QFile::ReadOnly | QFile::Text );
if( !b )
{
QMessageBox::information( this,
tr( "No log file found" ),
tr( "There was no log file found, therefore nothing to report. Exiting..." ) );
close();
m_fileName.clear();
return;
}
@ -99,13 +187,26 @@ void CCrashReportWidget::onLoad()
void CCrashReportWidget::onSendClicked()
{
m_ui.sendButton->setEnabled( false );
if( m_developerMode && !m_devSendReport )
{
close();
return;
}
if( m_socket->url().isEmpty() || m_fileName.isEmpty() )
{
close();
return;
}
QApplication::setOverrideCursor( Qt::WaitCursor );
SCrashReportData data;
data.description = m_ui.descriptionEdit->toPlainText();
data.report = m_ui.reportEdit->toPlainText();
data.email = m_ui.emailEdit->text();
if( m_ui.emailCB->isChecked() )
data.email = m_ui.emailEdit->text();
m_socket->sendReport( data );
}
@ -120,6 +221,45 @@ void CCrashReportWidget::onCBClicked()
m_ui.emailEdit->setEnabled( m_ui.emailCB->isChecked() );
}
void CCrashReportWidget::onSendCBClicked()
{
bool b = m_ui.emailCB->isEnabled();
if( b )
{
m_ui.emailCB->setChecked( false );
}
m_ui.emailCB->setEnabled( !b );
m_devSendReport = !m_devSendReport;
}
void CCrashReportWidget::onAlwaysIgnoreClicked()
{
m_returnValue = ERET_ALWAYS_IGNORE;
onSendClicked();
}
void CCrashReportWidget::onIgnoreClicked()
{
m_returnValue = ERET_IGNORE;
onSendClicked();
}
void CCrashReportWidget::onAbortClicked()
{
m_returnValue = ERET_ABORT;
onSendClicked();
}
void CCrashReportWidget::onBreakClicked()
{
m_returnValue = ERET_BREAK;
onSendClicked();
}
void CCrashReportWidget::onReportSent()
{
QApplication::setOverrideCursor( Qt::ArrowCursor );
@ -142,30 +282,11 @@ void CCrashReportWidget::onReportFailed()
removeAndQuit();
}
bool CCrashReportWidget::checkSettings()
{
if( m_fileName.isEmpty() )
{
QMessageBox::information( this,
tr( "No log file specified." ),
tr( "No log file specified. Exiting..." ) );
return false;
}
if( m_socket->url().isEmpty() )
{
QMessageBox::information( this,
tr( "No host specified." ),
tr( "No host specified. Exiting..." ) );
return false;
}
return true;
}
void CCrashReportWidget::removeAndQuit()
{
QFile::remove( m_fileName );
if( !m_fileName.isEmpty() )
QFile::remove( m_fileName );
close();
}

View file

@ -31,29 +31,51 @@ class CCrashReportWidget : public QWidget
{
Q_OBJECT
public:
enum EReturnValue
{
ERET_NULL = 0,
ERET_ALWAYS_IGNORE = 21,
ERET_IGNORE = 22,
ERET_ABORT = 23,
ERET_BREAK = 24
};
CCrashReportWidget( QWidget *parent = NULL );
~CCrashReportWidget();
void setFileName( const char *fn ){ m_fileName = fn; }
void setup( const std::vector< std::pair< std::string, std::string > > &params );
EReturnValue getReturnValue() const{ return m_returnValue; }
private Q_SLOTS:
void onLoad();
void onSendClicked();
void onCancelClicked();
void onCBClicked();
void onSendCBClicked();
void onAlwaysIgnoreClicked();
void onIgnoreClicked();
void onAbortClicked();
void onBreakClicked();
void onReportSent();
void onReportFailed();
private:
bool checkSettings();
void removeAndQuit();
Ui::CrashReportWidget m_ui;
QString m_fileName;
CCrashReportSocket *m_socket;
bool m_developerMode;
bool m_forceSend;
bool m_devSendReport;
EReturnValue m_returnValue;
};
#endif

View file

@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>407</height>
<width>406</width>
<height>430</height>
</rect>
</property>
<property name="windowTitle">
@ -18,40 +18,30 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<widget class="QLabel" name="descrLabel">
<property name="text">
<string>What were you doing when the crash occured?</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QPlainTextEdit" name="descriptionEdit"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="reportLabel">
<property name="text">
<string>Contents of the report ( automatically generated )</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPlainTextEdit" name="reportEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
<item row="1" column="0" colspan="3">
<widget class="QPlainTextEdit" name="descriptionEdit"/>
</item>
<item row="4" column="0" colspan="2">
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="emailCB">
<property name="text">
<string>Email me if you have further questions, or updates on this issue</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="5" column="0" colspan="3">
<widget class="QLineEdit" name="emailEdit">
<property name="enabled">
<bool>false</bool>
@ -61,17 +51,13 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="sendButton">
<property name="text">
<string>Send</string>
<item row="3" column="0" colspan="3">
<widget class="QPlainTextEdit" name="reportEdit">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="canceButton">
<property name="text">
<string>Cancel</string>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>