1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

Merge pull request #212 from tomahawk-player/crashreporter-qnetwork

Port CrashReporter to QNetwork-classes
This commit is contained in:
Uwe L. Korn
2013-09-02 01:05:59 -07:00
4 changed files with 31 additions and 24 deletions

View File

@@ -147,8 +147,6 @@ if( NOT BUILD_WITH_QT4 )
set(QT_RCC_EXECUTABLE "${Qt5Core_RCC_EXECUTABLE}") set(QT_RCC_EXECUTABLE "${Qt5Core_RCC_EXECUTABLE}")
#FIXME: CrashReporter depends on deprecated QHttp #FIXME: CrashReporter depends on deprecated QHttp
set(WITH_CRASHREPORTER OFF)
set(WITH_BREAKPAD OFF)
set(WITH_KDE4 OFF) set(WITH_KDE4 OFF)
endif() endif()
endif() endif()

View File

@@ -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"
@@ -31,7 +30,8 @@
#define RESPATH ":/data/" #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" ) ); setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) );
@@ -41,7 +41,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 +55,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( m_url );
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 +76,8 @@ CrashReporter::CrashReporter( const QStringList& args )
CrashReporter::~CrashReporter() CrashReporter::~CrashReporter()
{ {
delete m_http; delete m_request;
delete m_reply;
} }
@@ -138,16 +136,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, Qt::QueuedConnection );
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 +168,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>." ) );

View File

@@ -21,6 +21,8 @@
#include <QDialog> #include <QDialog>
#include <QFile> #include <QFile>
#include <QNetworkReply>
#include <QNetworkRequest>
#include "ui_CrashReporter.h" #include "ui_CrashReporter.h"
@@ -30,8 +32,8 @@ class CrashReporter : public QDialog
Q_OBJECT Q_OBJECT
public: public:
CrashReporter( const QStringList& argv ); CrashReporter( const QUrl& url, const QStringList& argv );
~CrashReporter( ); virtual ~CrashReporter( );
private: private:
Ui::CrashReporter ui; Ui::CrashReporter ui;
@@ -39,14 +41,16 @@ 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;
QUrl m_url;
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();
}; };

View File

@@ -45,7 +45,7 @@ int main( int argc, char* argv[] )
return 1; return 1;
} }
CrashReporter reporter( app.arguments() ); CrashReporter reporter( QUrl( "http://oops.tomahawk-player.org/addreport.php" ), app.arguments() );
reporter.show(); reporter.show();
return app.exec(); return app.exec();