2015-02-22 17:59:35 +00:00
|
|
|
// Nel MMORPG framework - Error Reporter
|
2015-02-18 23:20:18 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2015 Laszlo Kis-Adam
|
|
|
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
#include "crash_report_widget.h"
|
|
|
|
#include "crash_report_socket.h"
|
|
|
|
#include "crash_report_data.h"
|
2015-02-18 23:20:18 +00:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QFile>
|
2015-02-20 00:59:04 +00:00
|
|
|
#include <QMessageBox>
|
2015-02-22 21:34:07 +00:00
|
|
|
#include <QFile>
|
2015-03-02 18:52:39 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QHBoxLayout>
|
2015-03-02 20:06:01 +00:00
|
|
|
#include <QCheckBox>
|
2015-02-18 23:20:18 +00:00
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
CCrashReportWidget::CCrashReportWidget( QWidget *parent ) :
|
2015-02-18 23:20:18 +00:00
|
|
|
QWidget( parent )
|
|
|
|
{
|
2015-03-02 18:52:39 +00:00
|
|
|
m_developerMode = false;
|
|
|
|
m_forceSend = false;
|
2015-03-03 01:30:39 +00:00
|
|
|
m_devSendReport = false;
|
2015-03-02 18:52:39 +00:00
|
|
|
|
2015-02-18 23:20:18 +00:00
|
|
|
m_ui.setupUi( this );
|
2015-02-20 00:59:04 +00:00
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
m_socket = new CCrashReportSocket( this );
|
2015-02-20 00:59:04 +00:00
|
|
|
|
2015-02-18 23:20:18 +00:00
|
|
|
QTimer::singleShot( 1, this, SLOT( onLoad() ) );
|
|
|
|
|
|
|
|
connect( m_ui.emailCB, SIGNAL( stateChanged( int ) ), this, SLOT( onCBClicked() ) );
|
2015-02-20 00:59:04 +00:00
|
|
|
|
|
|
|
connect( m_socket, SIGNAL( reportSent() ), this, SLOT( onReportSent() ) );
|
2015-02-20 01:54:05 +00:00
|
|
|
connect( m_socket, SIGNAL( reportFailed() ), this, SLOT( onReportFailed() ) );
|
2015-02-18 23:20:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
CCrashReportWidget::~CCrashReportWidget()
|
2015-02-18 23:20:18 +00:00
|
|
|
{
|
2015-02-20 00:59:04 +00:00
|
|
|
m_socket = NULL;
|
2015-02-18 23:20:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 20:51:17 +00:00
|
|
|
void CCrashReportWidget::setup( const std::vector< std::pair< std::string, std::string > > ¶ms )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < params.size(); i++ )
|
|
|
|
{
|
|
|
|
const std::pair< std::string, std::string > &p = params[ i ];
|
|
|
|
const std::string &k = p.first;
|
|
|
|
const std::string &v = p.second;
|
|
|
|
|
|
|
|
if( k == "log" )
|
|
|
|
{
|
|
|
|
m_fileName = v.c_str();
|
2015-03-03 01:30:39 +00:00
|
|
|
if( !QFile::exists( m_fileName ) )
|
|
|
|
m_fileName.clear();
|
2015-02-22 20:51:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if( k == "host" )
|
|
|
|
{
|
|
|
|
m_socket->setURL( v.c_str() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( k == "title" )
|
|
|
|
{
|
|
|
|
setWindowTitle( v.c_str() );
|
|
|
|
}
|
2015-03-02 18:52:39 +00:00
|
|
|
else
|
|
|
|
if( k == "dev" )
|
|
|
|
{
|
|
|
|
m_developerMode = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( k == "sendreport" )
|
|
|
|
{
|
|
|
|
m_forceSend = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 20:06:01 +00:00
|
|
|
if( m_fileName.isEmpty() )
|
|
|
|
{
|
|
|
|
m_ui.reportLabel->hide();
|
|
|
|
m_ui.reportEdit->hide();
|
|
|
|
}
|
|
|
|
|
2015-03-03 01:30:39 +00:00
|
|
|
|
|
|
|
if( m_socket->url().isEmpty() || m_fileName.isEmpty() )
|
2015-03-02 20:06:01 +00:00
|
|
|
{
|
|
|
|
m_ui.descriptionEdit->hide();
|
|
|
|
m_ui.emailCB->hide();
|
|
|
|
m_ui.emailEdit->hide();
|
|
|
|
m_ui.descrLabel->hide();
|
|
|
|
}
|
|
|
|
|
2015-03-02 18:52:39 +00:00
|
|
|
QHBoxLayout *hbl = new QHBoxLayout( this );
|
|
|
|
|
|
|
|
if( m_developerMode )
|
|
|
|
{
|
2015-03-03 01:30:39 +00:00
|
|
|
if( !m_socket->url().isEmpty() && !m_fileName.isEmpty() )
|
2015-03-02 20:06:01 +00:00
|
|
|
{
|
|
|
|
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() ) );
|
|
|
|
}
|
|
|
|
|
2015-03-02 18:52:39 +00:00
|
|
|
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 );
|
|
|
|
|
2015-03-02 20:06:01 +00:00
|
|
|
m_ui.gridLayout->addLayout( hbl, 7, 0, 1, 3 );
|
2015-03-02 18:52:39 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2015-03-02 20:06:01 +00:00
|
|
|
// If -host is specified, offer the send function
|
2015-03-03 01:37:51 +00:00
|
|
|
if( !m_socket->url().isEmpty() && !m_fileName.isEmpty() )
|
2015-03-02 18:52:39 +00:00
|
|
|
{
|
2015-03-02 20:06:01 +00:00
|
|
|
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 );
|
2015-03-02 18:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_ui.gridLayout->addLayout( hbl, 6, 0, 1, 3 );
|
2015-02-22 20:51:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
void CCrashReportWidget::onLoad()
|
2015-02-18 23:20:18 +00:00
|
|
|
{
|
2015-03-02 20:06:01 +00:00
|
|
|
if( m_fileName.isEmpty() )
|
2015-02-22 20:51:17 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-18 23:20:18 +00:00
|
|
|
QFile f( m_fileName );
|
|
|
|
bool b = f.open( QFile::ReadOnly | QFile::Text );
|
|
|
|
if( !b )
|
|
|
|
{
|
2015-03-03 01:30:39 +00:00
|
|
|
m_fileName.clear();
|
2015-02-22 20:51:17 +00:00
|
|
|
return;
|
2015-02-18 23:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream ss( &f );
|
|
|
|
m_ui.reportEdit->setPlainText( ss.readAll() );
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
void CCrashReportWidget::onSendClicked()
|
2015-02-18 23:20:18 +00:00
|
|
|
{
|
2015-03-03 01:30:39 +00:00
|
|
|
if( m_developerMode && !m_devSendReport )
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_socket->url().isEmpty() || m_fileName.isEmpty() )
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-20 01:44:22 +00:00
|
|
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
2015-02-20 00:59:04 +00:00
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
SCrashReportData data;
|
2015-02-20 00:59:04 +00:00
|
|
|
data.description = m_ui.descriptionEdit->toPlainText();
|
|
|
|
data.report = m_ui.reportEdit->toPlainText();
|
2015-03-03 01:33:04 +00:00
|
|
|
|
|
|
|
if( m_ui.emailCB->isChecked() )
|
|
|
|
data.email = m_ui.emailEdit->text();
|
2015-02-20 00:59:04 +00:00
|
|
|
|
|
|
|
m_socket->sendReport( data );
|
2015-02-18 23:20:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
void CCrashReportWidget::onCancelClicked()
|
2015-02-18 23:20:18 +00:00
|
|
|
{
|
2015-02-22 21:34:07 +00:00
|
|
|
removeAndQuit();
|
2015-02-18 23:20:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
void CCrashReportWidget::onCBClicked()
|
2015-02-18 23:20:18 +00:00
|
|
|
{
|
|
|
|
m_ui.emailEdit->setEnabled( m_ui.emailCB->isChecked() );
|
|
|
|
}
|
|
|
|
|
2015-03-02 20:06:01 +00:00
|
|
|
void CCrashReportWidget::onSendCBClicked()
|
|
|
|
{
|
|
|
|
bool b = m_ui.emailCB->isEnabled();
|
|
|
|
|
|
|
|
if( b )
|
|
|
|
{
|
|
|
|
m_ui.emailCB->setChecked( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ui.emailCB->setEnabled( !b );
|
2015-03-03 01:30:39 +00:00
|
|
|
|
|
|
|
m_devSendReport = !m_devSendReport;
|
2015-03-02 20:06:01 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 18:52:39 +00:00
|
|
|
void CCrashReportWidget::onAlwaysIgnoreClicked()
|
|
|
|
{
|
2015-03-02 19:12:09 +00:00
|
|
|
m_returnValue = ERET_ALWAYS_IGNORE;
|
2015-03-03 01:30:39 +00:00
|
|
|
onSendClicked();
|
2015-03-02 18:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCrashReportWidget::onIgnoreClicked()
|
|
|
|
{
|
2015-03-02 19:12:09 +00:00
|
|
|
m_returnValue = ERET_IGNORE;
|
2015-03-03 01:30:39 +00:00
|
|
|
onSendClicked();
|
2015-03-02 18:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCrashReportWidget::onAbortClicked()
|
|
|
|
{
|
2015-03-02 19:12:09 +00:00
|
|
|
m_returnValue = ERET_ABORT;
|
2015-03-03 01:30:39 +00:00
|
|
|
onSendClicked();
|
2015-03-02 18:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCrashReportWidget::onBreakClicked()
|
|
|
|
{
|
2015-03-02 19:12:09 +00:00
|
|
|
m_returnValue = ERET_BREAK;
|
2015-03-03 01:30:39 +00:00
|
|
|
onSendClicked();
|
2015-03-02 18:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
void CCrashReportWidget::onReportSent()
|
2015-02-20 00:59:04 +00:00
|
|
|
{
|
2015-02-20 01:44:22 +00:00
|
|
|
QApplication::setOverrideCursor( Qt::ArrowCursor );
|
|
|
|
|
2015-02-20 00:59:04 +00:00
|
|
|
QMessageBox::information( this,
|
|
|
|
tr( "Report sent" ),
|
|
|
|
tr( "The report has been sent." ) );
|
2015-02-18 23:20:18 +00:00
|
|
|
|
2015-02-22 21:34:07 +00:00
|
|
|
removeAndQuit();
|
2015-02-20 00:59:04 +00:00
|
|
|
}
|
2015-02-18 23:20:18 +00:00
|
|
|
|
2015-02-22 18:52:01 +00:00
|
|
|
void CCrashReportWidget::onReportFailed()
|
2015-02-20 01:54:05 +00:00
|
|
|
{
|
|
|
|
QApplication::setOverrideCursor( Qt::ArrowCursor );
|
|
|
|
|
|
|
|
QMessageBox::information( this,
|
|
|
|
tr( "Report failed" ),
|
|
|
|
tr( "Failed to send the report..." ) );
|
|
|
|
|
2015-02-22 21:34:07 +00:00
|
|
|
removeAndQuit();
|
2015-02-22 20:51:17 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 21:34:07 +00:00
|
|
|
void CCrashReportWidget::removeAndQuit()
|
|
|
|
{
|
2015-03-03 01:30:39 +00:00
|
|
|
if( !m_fileName.isEmpty() )
|
|
|
|
QFile::remove( m_fileName );
|
|
|
|
|
2015-02-22 21:34:07 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|