From d482a92858f181c76229dc977ee9c159ba36515f Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 17 Sep 2015 15:56:30 +0200 Subject: Polish the HTTP example. - Remove unneeded member variables. - Use new connection syntax. - Streamline code. - Add a QCheckBox for launching the file after download and make the default file name and download directory configureable. - Make status messages more verbose. - Set Password echo mode on authentication dialog. - Extract the progress dialog to a separate class that is directly connected to the QNetworkReply, which is created on demand. Set set minimum and duration on it. This fixes a crash that currently occurs when clicking "Abort" on the SSL error dialog and "Cancel" on the progress dialog that is then re-shown due to its internal force timer/minimum duration handling. - Resize according to screen size. Task-number: QTBUG-48332 Change-Id: Ia2611e63fe96d6f49e4cdd06049a206ddb2c2864 Reviewed-by: David Faure --- examples/network/http/httpwindow.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'examples/network/http/httpwindow.h') diff --git a/examples/network/http/httpwindow.h b/examples/network/http/httpwindow.h index f1dc2e1f80..cc632e5bab 100644 --- a/examples/network/http/httpwindow.h +++ b/examples/network/http/httpwindow.h @@ -41,39 +41,46 @@ #ifndef HTTPWINDOW_H #define HTTPWINDOW_H -#include +#include #include #include QT_BEGIN_NAMESPACE -class QDialogButtonBox; class QFile; class QLabel; class QLineEdit; -class QProgressDialog; class QPushButton; class QSslError; class QAuthenticator; class QNetworkReply; - +class QCheckBox; QT_END_NAMESPACE +class ProgressDialog : public QProgressDialog { + Q_OBJECT + +public: + explicit ProgressDialog(const QUrl &url, QWidget *parent = Q_NULLPTR); + +public slots: + void networkReplyProgress(qint64 bytesRead, qint64 totalBytes); +}; + class HttpWindow : public QDialog { Q_OBJECT public: - HttpWindow(QWidget *parent = 0); + explicit HttpWindow(QWidget *parent = Q_NULLPTR); - void startRequest(QUrl url); + void startRequest(const QUrl &requestedUrl); private slots: void downloadFile(); void cancelDownload(); void httpFinished(); void httpReadyRead(); - void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes); void enableDownloadButton(); void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *); #ifndef QT_NO_SSL @@ -81,19 +88,19 @@ private slots: #endif private: + QFile *openFileForWrite(const QString &fileName); + QLabel *statusLabel; - QLabel *urlLabel; QLineEdit *urlLineEdit; - QProgressDialog *progressDialog; QPushButton *downloadButton; - QPushButton *quitButton; - QDialogButtonBox *buttonBox; + QCheckBox *launchCheckBox; + QLineEdit *defaultFileLineEdit; + QLineEdit *downloadDirectoryLineEdit; QUrl url; QNetworkAccessManager qnam; QNetworkReply *reply; QFile *file; - int httpGetId; bool httpRequestAborted; }; -- cgit v1.2.3