mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
Merge pull request #212 from tomahawk-player/crashreporter-qnetwork
Port CrashReporter to QNetwork-classes
This commit is contained in:
@@ -147,8 +147,6 @@ if( NOT BUILD_WITH_QT4 )
|
||||
|
||||
set(QT_RCC_EXECUTABLE "${Qt5Core_RCC_EXECUTABLE}")
|
||||
#FIXME: CrashReporter depends on deprecated QHttp
|
||||
set(WITH_CRASHREPORTER OFF)
|
||||
set(WITH_BREAKPAD OFF)
|
||||
set(WITH_KDE4 OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
@@ -23,7 +23,6 @@
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QHttp>
|
||||
|
||||
#include "utils/TomahawkUtils.h"
|
||||
|
||||
@@ -31,7 +30,8 @@
|
||||
#define RESPATH ":/data/"
|
||||
|
||||
|
||||
CrashReporter::CrashReporter( const QStringList& args )
|
||||
CrashReporter::CrashReporter( const QUrl& url, const QStringList& args )
|
||||
: m_url( url )
|
||||
{
|
||||
setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) );
|
||||
|
||||
@@ -41,7 +41,7 @@ CrashReporter::CrashReporter( const QStringList& args )
|
||||
ui.progressBar->setValue( 0 );
|
||||
ui.progressLabel->setPalette( Qt::gray );
|
||||
|
||||
#ifdef Q_WS_MAC
|
||||
#ifdef Q_OS_MAC
|
||||
QFont f = ui.bottomLabel->font();
|
||||
f.setPointSize( 10 );
|
||||
ui.bottomLabel->setFont( f );
|
||||
@@ -55,12 +55,9 @@ CrashReporter::CrashReporter( const QStringList& args )
|
||||
ui.progressLabel->setIndent( 1 );
|
||||
ui.bottomLabel->setDisabled( true );
|
||||
ui.bottomLabel->setIndent( 1 );
|
||||
#endif //Q_WS_MAC
|
||||
#endif //Q_OS_MAC
|
||||
|
||||
m_http = new QHttp( "oops.tomahawk-player.org", 80, this );
|
||||
|
||||
connect( m_http, SIGNAL( done( bool ) ), SLOT( onDone() ), Qt::QueuedConnection );
|
||||
connect( m_http, SIGNAL( dataSendProgress( int, int ) ), SLOT( onProgress( int, int ) ) );
|
||||
m_request = new QNetworkRequest( m_url );
|
||||
|
||||
m_dir = args.value( 1 );
|
||||
m_minidump = m_dir + '/' + args.value( 2 ) + ".dmp";
|
||||
@@ -79,7 +76,8 @@ CrashReporter::CrashReporter( const QStringList& args )
|
||||
|
||||
CrashReporter::~CrashReporter()
|
||||
{
|
||||
delete m_http;
|
||||
delete m_request;
|
||||
delete m_reply;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,16 +136,23 @@ CrashReporter::send()
|
||||
body += "\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, Qt::QueuedConnection );
|
||||
connect( m_reply, &QNetworkReply::uploadProgress, this, &CrashReporter::onProgress );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CrashReporter::onProgress( int done, int total )
|
||||
CrashReporter::onProgress( qint64 done, qint64 total )
|
||||
{
|
||||
if ( total )
|
||||
{
|
||||
@@ -163,15 +168,15 @@ CrashReporter::onProgress( int done, int total )
|
||||
void
|
||||
CrashReporter::onDone()
|
||||
{
|
||||
QByteArray data = m_http->readAll();
|
||||
QByteArray data = m_reply->readAll();
|
||||
ui.progressBar->setValue( ui.progressBar->maximum() );
|
||||
ui.button->setText( tr( "Close" ) );
|
||||
|
||||
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
|
||||
ui.progressLabel->setText( tr( "Sent! <b>Many thanks</b>." ) );
|
||||
|
@@ -21,6 +21,8 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QFile>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "ui_CrashReporter.h"
|
||||
|
||||
@@ -30,8 +32,8 @@ class CrashReporter : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CrashReporter( const QStringList& argv );
|
||||
~CrashReporter( );
|
||||
CrashReporter( const QUrl& url, const QStringList& argv );
|
||||
virtual ~CrashReporter( );
|
||||
|
||||
private:
|
||||
Ui::CrashReporter ui;
|
||||
@@ -39,14 +41,16 @@ private:
|
||||
QString m_minidump;
|
||||
QString m_dir;
|
||||
QString m_product_name;
|
||||
class QHttp* m_http;
|
||||
QNetworkRequest* m_request;
|
||||
QNetworkReply* m_reply;
|
||||
QUrl m_url;
|
||||
|
||||
public slots:
|
||||
void send();
|
||||
|
||||
private slots:
|
||||
void onDone();
|
||||
void onProgress( int done, int total );
|
||||
void onProgress( qint64 done, qint64 total );
|
||||
void onFail( int error, const QString& errorString );
|
||||
void onSendButton();
|
||||
};
|
||||
|
@@ -45,7 +45,7 @@ int main( int argc, char* argv[] )
|
||||
return 1;
|
||||
}
|
||||
|
||||
CrashReporter reporter( app.arguments() );
|
||||
CrashReporter reporter( QUrl( "http://oops.tomahawk-player.org/addreport.php" ), app.arguments() );
|
||||
reporter.show();
|
||||
|
||||
return app.exec();
|
||||
|
Reference in New Issue
Block a user