mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Port CrashReporter to QNetwork-classes
This commit is contained in:
@@ -23,7 +23,6 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QHttp>
|
|
||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ CrashReporter::CrashReporter( const QStringList& args )
|
|||||||
ui.progressBar->setValue( 0 );
|
ui.progressBar->setValue( 0 );
|
||||||
ui.progressLabel->setPalette( Qt::gray );
|
ui.progressLabel->setPalette( Qt::gray );
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QFont f = ui.bottomLabel->font();
|
QFont f = ui.bottomLabel->font();
|
||||||
f.setPointSize( 10 );
|
f.setPointSize( 10 );
|
||||||
ui.bottomLabel->setFont( f );
|
ui.bottomLabel->setFont( f );
|
||||||
@@ -55,12 +54,9 @@ CrashReporter::CrashReporter( const QStringList& args )
|
|||||||
ui.progressLabel->setIndent( 1 );
|
ui.progressLabel->setIndent( 1 );
|
||||||
ui.bottomLabel->setDisabled( true );
|
ui.bottomLabel->setDisabled( true );
|
||||||
ui.bottomLabel->setIndent( 1 );
|
ui.bottomLabel->setIndent( 1 );
|
||||||
#endif //Q_WS_MAC
|
#endif //Q_OS_MAC
|
||||||
|
|
||||||
m_http = new QHttp( "oops.tomahawk-player.org", 80, this );
|
m_request = new QNetworkRequest( QUrl( "http://oops.tomahawk-player.org/addreport.php" ) );
|
||||||
|
|
||||||
connect( m_http, SIGNAL( done( bool ) ), SLOT( onDone() ), Qt::QueuedConnection );
|
|
||||||
connect( m_http, SIGNAL( dataSendProgress( int, int ) ), SLOT( onProgress( int, int ) ) );
|
|
||||||
|
|
||||||
m_dir = args.value( 1 );
|
m_dir = args.value( 1 );
|
||||||
m_minidump = m_dir + '/' + args.value( 2 ) + ".dmp";
|
m_minidump = m_dir + '/' + args.value( 2 ) + ".dmp";
|
||||||
@@ -79,7 +75,8 @@ CrashReporter::CrashReporter( const QStringList& args )
|
|||||||
|
|
||||||
CrashReporter::~CrashReporter()
|
CrashReporter::~CrashReporter()
|
||||||
{
|
{
|
||||||
delete m_http;
|
delete m_request;
|
||||||
|
delete m_reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -138,16 +135,23 @@ CrashReporter::send()
|
|||||||
body += "\r\n";
|
body += "\r\n";
|
||||||
body += "--thkboundary--\r\n";
|
body += "--thkboundary--\r\n";
|
||||||
|
|
||||||
QHttpRequestHeader header( "POST", "/addreport.php" );
|
|
||||||
header.setContentType( "multipart/form-data; boundary=thkboundary" );
|
|
||||||
header.setValue( "HOST", "oops.tomahawk-player.org" );
|
|
||||||
|
|
||||||
m_http->request( header, body );
|
QNetworkAccessManager* nam = new QNetworkAccessManager( this );
|
||||||
|
m_request->setHeader( QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=thkboundary" );
|
||||||
|
m_reply = nam->post( *m_request, body );
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
|
connect( m_reply, SIGNAL( finished() ), SLOT( onDone() ), Qt::QueuedConnection );
|
||||||
|
connect( m_reply, SIGNAL( uploadProgress( qint64, qint64 ) ), SLOT( onProgress( qint64, qint64 ) ) );
|
||||||
|
#else
|
||||||
|
connect( m_reply, &QNetworkReply::finished, this, &CrashReporter::onDone );
|
||||||
|
connect( m_reply, &QNetworkReply::uploadProgress, this, &CrashReporter::onProgress );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CrashReporter::onProgress( int done, int total )
|
CrashReporter::onProgress( qint64 done, qint64 total )
|
||||||
{
|
{
|
||||||
if ( total )
|
if ( total )
|
||||||
{
|
{
|
||||||
@@ -163,15 +167,15 @@ CrashReporter::onProgress( int done, int total )
|
|||||||
void
|
void
|
||||||
CrashReporter::onDone()
|
CrashReporter::onDone()
|
||||||
{
|
{
|
||||||
QByteArray data = m_http->readAll();
|
QByteArray data = m_reply->readAll();
|
||||||
ui.progressBar->setValue( ui.progressBar->maximum() );
|
ui.progressBar->setValue( ui.progressBar->maximum() );
|
||||||
ui.button->setText( tr( "Close" ) );
|
ui.button->setText( tr( "Close" ) );
|
||||||
|
|
||||||
QString const response = QString::fromUtf8( data );
|
QString const response = QString::fromUtf8( data );
|
||||||
|
|
||||||
if ( m_http->error() != QHttp::NoError || !response.startsWith( "CrashID=" ) )
|
if ( ( m_reply->error() != QNetworkReply::NoError ) || !response.startsWith( "CrashID=" ) )
|
||||||
{
|
{
|
||||||
onFail( m_http->error(), m_http->errorString() );
|
onFail( m_reply->error(), m_reply->errorString() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ui.progressLabel->setText( tr( "Sent! <b>Many thanks</b>." ) );
|
ui.progressLabel->setText( tr( "Sent! <b>Many thanks</b>." ) );
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
|
||||||
#include "ui_CrashReporter.h"
|
#include "ui_CrashReporter.h"
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ class CrashReporter : public QDialog
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CrashReporter( const QStringList& argv );
|
CrashReporter( const QStringList& argv );
|
||||||
~CrashReporter( );
|
virtual ~CrashReporter( );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CrashReporter ui;
|
Ui::CrashReporter ui;
|
||||||
@@ -39,14 +41,15 @@ private:
|
|||||||
QString m_minidump;
|
QString m_minidump;
|
||||||
QString m_dir;
|
QString m_dir;
|
||||||
QString m_product_name;
|
QString m_product_name;
|
||||||
class QHttp* m_http;
|
QNetworkRequest* m_request;
|
||||||
|
QNetworkReply* m_reply;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void send();
|
void send();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDone();
|
void onDone();
|
||||||
void onProgress( int done, int total );
|
void onProgress( qint64 done, qint64 total );
|
||||||
void onFail( int error, const QString& errorString );
|
void onFail( int error, const QString& errorString );
|
||||||
void onSendButton();
|
void onSendButton();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user