summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2012-04-10 12:48:01 +0200
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2012-04-10 15:31:45 +0200
commit143c4d3e13a430b951f4f4f8c28db14303f80605 (patch)
tree2b89637b93fc7d81c674106008566010f986d67c /tests/manual
parenta7ed81b557d593a8ddb43b71bf4bbf3b44ead070 (diff)
parente5337ad1b1fb02873ce7b5ca8db45f6fd8063352 (diff)
Merge remote-tracking branch 'origin/master' into api_changes
Conflicts: configure src/widgets/styles/qwindowsxpstyle.cpp tests/auto/gui/kernel/qwindow/qwindow.pro tests/auto/gui/kernel/qwindow/tst_qwindow.cpp Change-Id: I624b6d26abce9874c610c04954c1c45bc074bef3
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/cmake/CMakeLists.txt3
-rw-r--r--tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt6
-rw-r--r--tests/manual/cmake/pass(needsquoting)6/mywidget.cpp1
-rw-r--r--tests/manual/cmake/pass1/CMakeLists.txt3
-rw-r--r--tests/manual/cmake/pass3/mywidget.cpp1
-rw-r--r--tests/manual/qhttpnetworkconnection/main.cpp2
-rw-r--r--tests/manual/qnetworkaccessmanager/qget/downloadmanager.cpp166
-rw-r--r--tests/manual/qnetworkaccessmanager/qget/qget.cpp206
-rw-r--r--tests/manual/qnetworkaccessmanager/qget/qget.h77
-rw-r--r--tests/manual/qnetworkaccessmanager/qget/qget.pro2
-rw-r--r--tests/manual/qnetworkaccessmanager/qget/transferitem.cpp162
-rw-r--r--tests/manual/windowmodality/dialog.ui326
-rw-r--r--tests/manual/windowmodality/main.cpp301
-rw-r--r--tests/manual/windowmodality/modality.pro3
-rw-r--r--tests/manual/windowmodality/widget.ui286
15 files changed, 1351 insertions, 194 deletions
diff --git a/tests/manual/cmake/CMakeLists.txt b/tests/manual/cmake/CMakeLists.txt
index 241454e763..f7b16946c1 100644
--- a/tests/manual/cmake/CMakeLists.txt
+++ b/tests/manual/cmake/CMakeLists.txt
@@ -83,7 +83,8 @@ else()
message("CMake version older than 2.8.7. Not running test \"pass1\"")
endif()
expect_pass(pass2)
-expect_pass(pass3)
+# Modules do not currently find their own dependencies.
+# expect_pass(pass3)
expect_fail(fail4)
expect_fail(fail5)
expect_pass("pass(needsquoting)6")
diff --git a/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt b/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt
index 63f675df18..7b9561c588 100644
--- a/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt
+++ b/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt
@@ -9,14 +9,14 @@ find_package(Qt5Widgets REQUIRED)
include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
-add_definitions(${Qt5Core_DEFINITIONS})
+add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
qt5_wrap_cpp(moc_files mywidget.h)
qt5_wrap_ui(ui_files mywidget.ui)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
add_executable(mywidget mywidget.cpp ${moc_files} ${ui_files})
-target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES})
+target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Core_LIBRARIES})
diff --git a/tests/manual/cmake/pass(needsquoting)6/mywidget.cpp b/tests/manual/cmake/pass(needsquoting)6/mywidget.cpp
index d1b2669980..7f8923810d 100644
--- a/tests/manual/cmake/pass(needsquoting)6/mywidget.cpp
+++ b/tests/manual/cmake/pass(needsquoting)6/mywidget.cpp
@@ -50,6 +50,7 @@ MyWidget::MyWidget(QWidget *parent)
int main(int argc, char **argv)
{
+ QApplication app(argc, argv);
MyWidget myWidget;
return 0;
}
diff --git a/tests/manual/cmake/pass1/CMakeLists.txt b/tests/manual/cmake/pass1/CMakeLists.txt
index cbe3afc7c4..970ca33078 100644
--- a/tests/manual/cmake/pass1/CMakeLists.txt
+++ b/tests/manual/cmake/pass1/CMakeLists.txt
@@ -43,6 +43,9 @@ endmacro()
add_executable(two two.cpp)
add_executable(three three.cpp)
+qt5_use_package(two Core)
qt5_use_package(two Test)
qt5_use_package(three Widgets)
+qt5_use_package(three Gui)
+qt5_use_package(three Core)
qt5_use_package(three Test)
diff --git a/tests/manual/cmake/pass3/mywidget.cpp b/tests/manual/cmake/pass3/mywidget.cpp
index d1b2669980..7f8923810d 100644
--- a/tests/manual/cmake/pass3/mywidget.cpp
+++ b/tests/manual/cmake/pass3/mywidget.cpp
@@ -50,6 +50,7 @@ MyWidget::MyWidget(QWidget *parent)
int main(int argc, char **argv)
{
+ QApplication app(argc, argv);
MyWidget myWidget;
return 0;
}
diff --git a/tests/manual/qhttpnetworkconnection/main.cpp b/tests/manual/qhttpnetworkconnection/main.cpp
index 2d861530d3..8099e616f7 100644
--- a/tests/manual/qhttpnetworkconnection/main.cpp
+++ b/tests/manual/qhttpnetworkconnection/main.cpp
@@ -72,7 +72,7 @@ void tst_qhttpnetworkconnection::bigRemoteFile()
qDebug() << "Finished!" << endl;
qDebug() << "Time:" << t.elapsed() << "msec";
qDebug() << "Bytes:" << size;
- qDebug() << "Speed:" << (size / 1024) / (t.elapsed() / 1000) << "KB/sec";
+ qDebug() << "Speed:" << (size / qreal(1024)) / (t.elapsed() / qreal(1000)) << "KB/sec";
}
QTEST_MAIN(tst_qhttpnetworkconnection)
diff --git a/tests/manual/qnetworkaccessmanager/qget/downloadmanager.cpp b/tests/manual/qnetworkaccessmanager/qget/downloadmanager.cpp
new file mode 100644
index 0000000000..e3ba3ca88f
--- /dev/null
+++ b/tests/manual/qnetworkaccessmanager/qget/downloadmanager.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qget.h"
+#include <QAuthenticator>
+#include <QCoreApplication>
+#include <QDebug>
+#include <QSslError>
+
+DownloadManager::DownloadManager()
+ : queueMode (Parallel)
+{
+ connect(&nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
+ connect(&nam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
+ connect(&nam, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
+#ifndef QT_NO_SSL
+ connect(&nam, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&)));
+#endif
+}
+
+DownloadManager::~DownloadManager()
+{
+
+}
+
+void DownloadManager::get(const QUrl &url, const QString &user, const QString &password)
+{
+ DownloadItem *dl = new DownloadItem(QNetworkRequest(url), user, password, nam);
+ transfers.append(dl);
+ connect(dl, SIGNAL(downloadFinished(TransferItem*)), SLOT(downloadFinished(TransferItem*)));
+}
+
+void DownloadManager::upload(const QUrl &url, const QString &user, const QString &password, const QString &filename, const QString &contentType, TransferItem::Method method)
+{
+ QScopedPointer<QFile> file(new QFile(filename));
+ if (!file->open(QFile::ReadOnly)) {
+ qDebug() << "Can't open input file" << file->fileName() << file->errorString();
+ return;
+ }
+ QNetworkRequest request(url);
+ if (!contentType.isEmpty())
+ request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
+ UploadItem *ul = new UploadItem(request, user, password, nam, file.take(), method);
+ transfers.append(ul);
+ connect(ul, SIGNAL(downloadFinished(TransferItem*)), SLOT(downloadFinished(TransferItem*)));
+}
+
+void DownloadManager::finished(QNetworkReply *reply)
+{
+}
+
+void DownloadManager::downloadFinished(TransferItem *item)
+{
+ qDebug() << "finished " << item->reply->url() << " with http status: " << item->reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ if (item->reply->error() != QNetworkReply::NoError)
+ qDebug() << "and error: " << item->reply->error() << item->reply->errorString();
+ transfers.removeOne(item);
+ item->deleteLater();
+ checkForAllDone();
+}
+
+void DownloadManager::checkForAllDone()
+{
+ if (transfers.isEmpty()) {
+ qDebug() << "All Done.";
+ QCoreApplication::quit();
+ }
+
+ foreach (TransferItem *item, transfers) {
+ if (!item->reply) {
+ item->start();
+ //by default multiple downloads are processed in parallel.
+ //but in serial mode, only start one transfer at a time.
+ if (queueMode == Serial)
+ break;
+ }
+ }
+
+}
+
+void DownloadManager::authenticationRequired(QNetworkReply *reply, QAuthenticator *auth)
+{
+ qDebug() << "authenticationRequired" << reply;
+ TransferItem *transfer = findTransfer(reply);
+ //provide the credentials exactly once, so that it fails if credentials are incorrect.
+ if (transfer && !transfer->user.isEmpty() || !transfer->password.isEmpty()) {
+ auth->setUser(transfer->user);
+ auth->setPassword(transfer->password);
+ transfer->user.clear();
+ transfer->password.clear();
+ }
+}
+
+void DownloadManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
+{
+ //provide the credentials exactly once, so that it fails if credentials are incorrect.
+ if (!proxyUser.isEmpty() || !proxyPassword.isEmpty()) {
+ auth->setUser(proxyUser);
+ auth->setPassword(proxyPassword);
+ proxyUser.clear();
+ proxyPassword.clear();
+ }
+}
+
+#ifndef QT_NO_SSL
+void DownloadManager::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
+{
+ qDebug() << "sslErrors";
+ foreach (const QSslError &error, errors) {
+ qDebug() << error.errorString();
+ qDebug() << error.certificate().toPem();
+ }
+}
+#endif
+
+TransferItem *DownloadManager::findTransfer(QNetworkReply *reply)
+{
+ foreach (TransferItem *item, transfers) {
+ if (item->reply == reply)
+ return item;
+ }
+ return 0;
+}
+
+void DownloadManager::setQueueMode(QueueMode mode)
+{
+ queueMode = mode;
+}
diff --git a/tests/manual/qnetworkaccessmanager/qget/qget.cpp b/tests/manual/qnetworkaccessmanager/qget/qget.cpp
index 44fb62150b..cd98eff935 100644
--- a/tests/manual/qnetworkaccessmanager/qget/qget.cpp
+++ b/tests/manual/qnetworkaccessmanager/qget/qget.cpp
@@ -41,9 +41,7 @@
#include "qget.h"
-#include <QSslError>
#include <QNetworkProxy>
-#include <QAuthenticator>
#include <QDebug>
#include <QCoreApplication>
#include <QList>
@@ -52,156 +50,6 @@
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
-DownloadManager::DownloadManager()
-{
- connect(&nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
- connect(&nam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
- connect(&nam, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
-#ifndef QT_NO_SSL
- connect(&nam, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&)));
-#endif
-}
-
-DownloadManager::~DownloadManager()
-{
-
-}
-
-void DownloadManager::get(const QUrl& url)
-{
- //currently multiple downloads are processed in parallel.
- //could add an option for serial using the downloads list as a queue
- //which would require DownloadItem to hold a request rather than a reply
- QNetworkReply* reply = nam.get(QNetworkRequest(url));
- DownloadItem *dl = new DownloadItem(reply, nam);
- downloads.append(dl);
- connect(dl, SIGNAL(downloadFinished(DownloadItem*)), SLOT(downloadFinished(DownloadItem*)));
-}
-
-void DownloadManager::finished(QNetworkReply* reply)
-{
-}
-
-void DownloadManager::downloadFinished(DownloadItem *item)
-{
- downloads.removeOne(item);
- item->deleteLater();
- checkForAllDone();
-}
-
-void DownloadManager::checkForAllDone()
-{
- if (downloads.isEmpty()) {
- qDebug() << "All Done.";
- QCoreApplication::quit();
- }
-}
-
-void DownloadManager::authenticationRequired(QNetworkReply* reply, QAuthenticator* auth)
-{
- //provide the credentials exactly once, so that it fails if credentials are incorrect.
- if (!httpUser.isEmpty() || !httpPassword.isEmpty()) {
- auth->setUser(httpUser);
- auth->setPassword(httpPassword);
- httpUser.clear();
- httpPassword.clear();
- }
-}
-
-void DownloadManager::proxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* auth)
-{
- //provide the credentials exactly once, so that it fails if credentials are incorrect.
- if (!proxyUser.isEmpty() || !proxyPassword.isEmpty()) {
- auth->setUser(proxyUser);
- auth->setPassword(proxyPassword);
- proxyUser.clear();
- proxyPassword.clear();
- }
-}
-
-#ifndef QT_NO_SSL
-void DownloadManager::sslErrors(QNetworkReply* reply, const QList<QSslError>& errors)
-{
- qDebug() << "sslErrors";
- foreach (const QSslError& error, errors) {
- qDebug() << error.errorString();
- qDebug() << error.certificate().toPem();
- }
-}
-#endif
-
-DownloadItem::DownloadItem(QNetworkReply* r, QNetworkAccessManager& manager) : reply(r), nam(manager)
-{
- reply->setParent(this);
- connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
- connect(reply, SIGNAL(finished()), this, SLOT(finished()));
-}
-
-DownloadItem::~DownloadItem()
-{
-}
-
-void DownloadItem::readyRead()
-{
- if (!file.isOpen()) {
- qDebug() << reply->header(QNetworkRequest::ContentTypeHeader) << reply->header(QNetworkRequest::ContentLengthHeader);
- QString path = reply->url().path();
- path = path.mid(path.lastIndexOf('/') + 1);
- if (path.isEmpty())
- path = QLatin1String("index.html");
- file.setFileName(path);
- for (int i=1;i<1000;i++) {
- if (!file.exists() && file.open(QIODevice::WriteOnly | QIODevice::Truncate))
- break;
- file.setFileName(QString(QLatin1String("%1.%2")).arg(path).arg(i));
- }
- if (!file.isOpen()) {
- qDebug() << "couldn't open output file";
- reply->abort();
- return;
- }
- qDebug() << reply->url() << " -> " << file.fileName();
- }
- file.write(reply->readAll());
-}
-
-void DownloadItem::finished()
-{
- if (reply->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) {
- QUrl url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
- url = reply->url().resolved(url);
- qDebug() << reply->url() << "redirected to " << url;
- if (redirects.contains(url)) {
- qDebug() << "redirect loop detected";
- } else if (redirects.count() > 10) {
- qDebug() << "too many redirects";
- } else {
- //follow redirect
- if (file.isOpen()) {
- if (!file.seek(0) || !file.resize(0)) {
- file.close();
- file.remove();
- }
- }
- reply->deleteLater();
- reply = nam.get(QNetworkRequest(url));
- reply->setParent(this);
- connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
- connect(reply, SIGNAL(finished()), this, SLOT(finished()));
- redirects.append(url);
- return;
- }
- }
- if (file.isOpen()) {
- file.write(reply->readAll());
- file.close();
- }
- qDebug() << "finished " << reply->url() << " with http status: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- if (reply->error() != QNetworkReply::NoError)
- qDebug() << "and error: " << reply->error() << reply->errorString();
- emit downloadFinished(this);
-}
-
void printShortUsage()
{
qDebug() << QCoreApplication::applicationName() << " [options] [list of urls]" << endl
@@ -215,8 +63,8 @@ void printUsage()
<< "Get one or more urls using QNetworkAccessManager" << endl
<< "Options:"
<< "--help This message" << endl
- << "--http-user=<username> Set username to use for http 401 challenges" << endl
- << "--http-password=<password> Set password to use for http 401 challenges" << endl
+ << "--user=<username> Set username to use for authentication" << endl
+ << "--password=<password> Set password to use for authentication" << endl
<< "--proxy-user=<username> Set username to use for proxy authentication" << endl
<< "--proxy-password=<password> Set password to use for proxy authentication" << endl
<< "--proxy=on Use system proxy (default)" << endl
@@ -225,7 +73,11 @@ void printUsage()
<< " ,http HTTP proxy (default)" << endl
<< " ,socks SOCKS5 proxy" << endl
<< " ,ftp FTP proxy" << endl
- << " ,httpcaching HTTP caching proxy (no CONNECT method)" << endl;
+ << " ,httpcaching HTTP caching proxy (no CONNECT method)" << endl
+ << "--post=filename upload the file to the next url using HTTP POST" << endl
+ << "--put=filename upload the file to the next url using HTTP PUT" << endl
+ << "--content-type=<MIME> set content-type header for upload" << endl
+ << "--serial don't run requests in parallel" << endl;
}
int main(int argc, char *argv[])
@@ -240,18 +92,23 @@ int main(int argc, char *argv[])
QNetworkProxyFactory::setUseSystemConfiguration(true);
DownloadManager dl;
+ QString uploadFileName;
+ QString contentType;
+ QString httpUser;
+ QString httpPassword;
+ TransferItem::Method method = TransferItem::Get;
//arguments match wget where possible
foreach (QString str, app.arguments().mid(1)) {
if (str == "--help")
printUsage();
- else if (str.startsWith("--http-user="))
- dl.setHttpUser(str.mid(12));
- else if (str.startsWith("--http-passwd="))
- dl.setHttpPassword(str.mid(14));
+ else if (str.startsWith("--user="))
+ httpUser = str.mid(7);
+ else if (str.startsWith("--password="))
+ httpPassword = str.mid(11);
else if (str.startsWith("--proxy-user="))
dl.setProxyUser(str.mid(13));
- else if (str.startsWith("--proxy-passwd="))
- dl.setProxyPassword(str.mid(15));
+ else if (str.startsWith("--proxy-password="))
+ dl.setProxyPassword(str.mid(17));
else if (str == "--proxy=off")
QNetworkProxyFactory::setUseSystemConfiguration(false);
else if (str == "--proxy=on")
@@ -294,10 +151,33 @@ int main(int argc, char *argv[])
qDebug() << "proxy:" << proxy.hostName() << proxy.port() << proxy.type();
dl.setProxy(proxy);
}
+ else if (str.startsWith("--put=")) {
+ method = TransferItem::Put;
+ uploadFileName = str.mid(6);
+ }
+ else if (str.startsWith("--post=")) {
+ method = TransferItem::Post;
+ uploadFileName = str.mid(7);
+ }
+ else if (str.startsWith("--content-type="))
+ contentType=str.mid(15);
+ else if (str == "--serial")
+ dl.setQueueMode(DownloadManager::Serial);
else if (str.startsWith("-"))
qDebug() << "unsupported option" << str;
- else
- dl.get(QUrl::fromUserInput(str));
+ else {
+ QUrl url(QUrl::fromUserInput(str));
+ switch (method) {
+ case TransferItem::Put:
+ case TransferItem::Post:
+ dl.upload(url, httpUser, httpPassword, uploadFileName, contentType, method);
+ break;
+ case TransferItem::Get:
+ dl.get(url, httpUser, httpPassword);
+ break;
+ }
+ method = TransferItem::Get; //default for urls without a request type before it
+ }
}
QMetaObject::invokeMethod(&dl, "checkForAllDone", Qt::QueuedConnection);
return app.exec();
diff --git a/tests/manual/qnetworkaccessmanager/qget/qget.h b/tests/manual/qnetworkaccessmanager/qget/qget.h
index 40d75a3903..bad4f5e4d2 100644
--- a/tests/manual/qnetworkaccessmanager/qget/qget.h
+++ b/tests/manual/qnetworkaccessmanager/qget/qget.h
@@ -46,25 +46,50 @@
#include <QNetworkReply>
#include <QFile>
-class DownloadItem : public QObject
+class TransferItem : public QObject
{
Q_OBJECT
public:
- DownloadItem(QNetworkReply* r, QNetworkAccessManager& nam);
- ~DownloadItem();
+ enum Method {Get,Put,Post};
+ TransferItem(const QNetworkRequest &r, const QString &u, const QString &p, QNetworkAccessManager &n, Method m);
+ void start();
+signals:
+ void downloadFinished(TransferItem *self);
+public slots:
+ void progress(qint64,qint64);
+public:
+ Method method;
+ QNetworkRequest request;
+ QNetworkReply *reply;
+ QNetworkAccessManager &nam;
+ QFile *inputFile;
+ QFile *outputFile;
+ QList<QUrl> redirects;
+ QString user;
+ QString password;
+};
- QNetworkReply* networkReply() { return reply; }
+class DownloadItem : public TransferItem
+{
+ Q_OBJECT
+public:
+ DownloadItem(const QNetworkRequest &r, const QString &user, const QString &password, QNetworkAccessManager &nam);
+ ~DownloadItem();
-signals:
- void downloadFinished(DownloadItem *self);
private slots:
void readyRead();
void finished();
private:
- QNetworkAccessManager& nam;
- QNetworkReply* reply;
- QFile file;
- QList<QUrl> redirects;
+};
+
+class UploadItem : public TransferItem
+{
+ Q_OBJECT
+public:
+ UploadItem(const QNetworkRequest &r, const QString &user, const QString &password, QNetworkAccessManager &nam, QFile *f, TransferItem::Method method);
+ ~UploadItem();
+private slots:
+ void finished();
};
class DownloadManager : public QObject
@@ -73,31 +98,31 @@ class DownloadManager : public QObject
public:
DownloadManager();
~DownloadManager();
- void get(const QUrl& url);
- void setProxy(const QNetworkProxy& proxy) { nam.setProxy(proxy); }
- void setHttpUser(const QString& user) { httpUser = user; }
- void setHttpPassword(const QString& password) { httpPassword = password; }
- void setProxyUser(const QString& user) { proxyUser = user; }
- void setProxyPassword(const QString& password) { proxyPassword = password; }
+ void get(const QUrl &url, const QString &user, const QString &password);
+ void upload(const QUrl &url, const QString &user, const QString &password, const QString &filename, const QString &contentType, TransferItem::Method method);
+ void setProxy(const QNetworkProxy &proxy) { nam.setProxy(proxy); }
+ void setProxyUser(const QString &user) { proxyUser = user; }
+ void setProxyPassword(const QString &password) { proxyPassword = password; }
+ enum QueueMode { Parallel, Serial };
+ void setQueueMode(QueueMode mode);
public slots:
void checkForAllDone();
private slots:
- void finished(QNetworkReply* reply);
- void authenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator);
- void proxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* authenticator);
-#ifndef QT_NO_SSL
- void sslErrors(QNetworkReply* reply, const QList<QSslError>& errors);
-#endif
- void downloadFinished(DownloadItem *item);
+ void finished(QNetworkReply *reply);
+ void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
+ void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
+ void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
+ void downloadFinished(TransferItem *item);
private:
+ TransferItem *findTransfer(QNetworkReply *reply);
+
QNetworkAccessManager nam;
- QList<DownloadItem*> downloads;
- QString httpUser;
- QString httpPassword;
+ QList<TransferItem*> transfers;
QString proxyUser;
QString proxyPassword;
+ QueueMode queueMode;
};
#endif // QGET_H
diff --git a/tests/manual/qnetworkaccessmanager/qget/qget.pro b/tests/manual/qnetworkaccessmanager/qget/qget.pro
index 1f2b497171..8a632f8d4e 100644
--- a/tests/manual/qnetworkaccessmanager/qget/qget.pro
+++ b/tests/manual/qnetworkaccessmanager/qget/qget.pro
@@ -3,4 +3,6 @@ QT = core network
CONFIG += console
SOURCES += qget.cpp
+SOURCES += transferitem.cpp
+SOURCES += downloadmanager.cpp
HEADERS += qget.h
diff --git a/tests/manual/qnetworkaccessmanager/qget/transferitem.cpp b/tests/manual/qnetworkaccessmanager/qget/transferitem.cpp
new file mode 100644
index 0000000000..1565292e6d
--- /dev/null
+++ b/tests/manual/qnetworkaccessmanager/qget/transferitem.cpp
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qget.h"
+#include <QDebug>
+
+TransferItem::TransferItem(const QNetworkRequest &r, const QString &u, const QString &p, QNetworkAccessManager &n, Method m)
+ : method(m), request(r), reply(0), nam(n), inputFile(0), outputFile(0), user(u), password(p)
+{
+}
+
+void TransferItem::progress(qint64 sent, qint64 total)
+{
+ if (total > 0)
+ qDebug() << (sent*100/total) << "%";
+ else
+ qDebug() << sent << "B";
+}
+
+void TransferItem::start()
+{
+ switch (method) {
+ case Get:
+ reply = nam.get(request);
+ connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(progress(qint64,qint64)));
+ break;
+ case Put:
+ reply = nam.put(request, inputFile);
+ connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(progress(qint64,qint64)));
+ break;
+ case Post:
+ reply = nam.post(request, inputFile);
+ connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(progress(qint64,qint64)));
+ break;
+ }
+ connect(reply, SIGNAL(finished()), this, SLOT(finished()));
+}
+
+DownloadItem::DownloadItem(const QNetworkRequest &r, const QString &user, const QString &password, QNetworkAccessManager &manager)
+ : TransferItem(r, user, password, manager, Get)
+{
+}
+
+DownloadItem::~DownloadItem()
+{
+}
+
+void DownloadItem::readyRead()
+{
+ if (!outputFile)
+ outputFile = new QFile(this);
+ if (!outputFile->isOpen()) {
+ qDebug() << reply->header(QNetworkRequest::ContentTypeHeader) << reply->header(QNetworkRequest::ContentLengthHeader);
+ QString path = reply->url().path();
+ path = path.mid(path.lastIndexOf('/') + 1);
+ if (path.isEmpty())
+ path = QLatin1String("index.html");
+ outputFile->setFileName(path);
+ for (int i=1;i<1000;i++) {
+ if (!outputFile->exists() && outputFile->open(QIODevice::WriteOnly | QIODevice::Truncate))
+ break;
+ outputFile->setFileName(QString(QLatin1String("%1.%2")).arg(path).arg(i));
+ }
+ if (!outputFile->isOpen()) {
+ qDebug() << "couldn't open output file";
+ reply->abort();
+ return;
+ }
+ qDebug() << reply->url() << " -> " << outputFile->fileName();
+ }
+ outputFile->write(reply->readAll());
+}
+
+void DownloadItem::finished()
+{
+ if (reply->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) {
+ QUrl url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
+ url = reply->url().resolved(url);
+ qDebug() << reply->url() << "redirected to " << url;
+ if (redirects.contains(url)) {
+ qDebug() << "redirect loop detected";
+ } else if (redirects.count() > 10) {
+ qDebug() << "too many redirects";
+ } else {
+ //follow redirect
+ if (outputFile->isOpen()) {
+ if (!outputFile->seek(0) || !outputFile->resize(0)) {
+ outputFile->close();
+ outputFile->remove();
+ }
+ }
+ reply->deleteLater();
+ reply = nam.get(QNetworkRequest(url));
+ reply->setParent(this);
+ connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ connect(reply, SIGNAL(finished()), this, SLOT(finished()));
+ redirects.append(url);
+ return;
+ }
+ }
+ if (outputFile && outputFile->isOpen()) {
+ outputFile->write(reply->readAll());
+ outputFile->close();
+ }
+ emit downloadFinished(this);
+}
+
+UploadItem::UploadItem(const QNetworkRequest &r, const QString &user, const QString &password, QNetworkAccessManager &n, QFile *f, TransferItem::Method method)
+ : TransferItem(r,user, password, n,method)
+{
+ inputFile = f;
+ f->setParent(this);
+ qDebug() << f->fileName() << f->isOpen() << f->size();
+}
+
+UploadItem::~UploadItem()
+{
+}
+
+void UploadItem::finished()
+{
+ emit downloadFinished(this);
+}
diff --git a/tests/manual/windowmodality/dialog.ui b/tests/manual/windowmodality/dialog.ui
new file mode 100644
index 0000000000..0254311566
--- /dev/null
+++ b/tests/manual/windowmodality/dialog.ui
@@ -0,0 +1,326 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>515</width>
+ <height>480</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Select the type of dialog to create:</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="3">
+ <widget class="QCheckBox" name="useThisAsParentCheckBox">
+ <property name="text">
+ <string>Use this window as parent for newly created dialogs</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QPushButton" name="modelessCustomDialogButton">
+ <property name="text">
+ <string>Custom Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QPushButton" name="modelessColorDialogButton">
+ <property name="text">
+ <string>Color Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="QPushButton" name="modelessFontDialogButton">
+ <property name="text">
+ <string>Font Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QPushButton" name="windowModalCustomDialogButton">
+ <property name="text">
+ <string>Custom Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QPushButton" name="windowModalColorDialogButton">
+ <property name="text">
+ <string>Color Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="2">
+ <widget class="QPushButton" name="windowModalFileDialogButton">
+ <property name="text">
+ <string>File Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QPushButton" name="windowModalFontDialogButton">
+ <property name="text">
+ <string>Font Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QPushButton" name="windowModalPageSetupDialogButton">
+ <property name="text">
+ <string>Page Setup Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="2">
+ <widget class="QPushButton" name="windowModalPrintDialogButton">
+ <property name="text">
+ <string>Print Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0">
+ <widget class="QPushButton" name="applicationModalCustomDialogButton">
+ <property name="text">
+ <string>Custom Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="1">
+ <widget class="QPushButton" name="applicationModalColorDialogButton">
+ <property name="text">
+ <string>Color Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="2">
+ <widget class="QPushButton" name="applicationModalFileDialogButton">
+ <property name="text">
+ <string>File Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="0">
+ <widget class="QPushButton" name="applicationModalFontDialogButton">
+ <property name="text">
+ <string>Font Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="1">
+ <widget class="QPushButton" name="applicationModalPageSetupDialogButton">
+ <property name="text">
+ <string>Page Setup Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="2">
+ <widget class="QPushButton" name="applicationModalPrintDialogButton">
+ <property name="text">
+ <string>Print Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="12" column="0" colspan="3">
+ <widget class="QLabel" name="applicationModalNoteLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Native Application Modal Dialogs use static API instead of exec()</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="0" colspan="3">
+ <widget class="QCheckBox" name="applicationModalUseExecCheckBox">
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Application Modal Dialogs use exec()</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0" colspan="3">
+ <widget class="QLabel" name="windowModalNoteLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Native Window Modal Dialogs use open()</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0" colspan="3">
+ <widget class="QLabel" name="applicationModalDialogsLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Application Modal Dialogs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" colspan="2">
+ <widget class="QLabel" name="windowModalDialogsLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Window Modal Dialogs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="3">
+ <widget class="QLabel" name="modelessDialogsLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Modeless (Non-Modal) Dialogs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="3">
+ <widget class="QCheckBox" name="createSiblingDialogCheckBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Create new dialogs as siblings of this dialog</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>131</width>
+ <height>31</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="okButton">
+ <property name="text">
+ <string>Close</string>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>okButton</sender>
+ <signal>clicked()</signal>
+ <receiver>Dialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>397</x>
+ <y>338</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>96</x>
+ <y>254</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>useThisAsParentCheckBox</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>createSiblingDialogCheckBox</receiver>
+ <slot>setDisabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>260</x>
+ <y>39</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>260</x>
+ <y>60</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/tests/manual/windowmodality/main.cpp b/tests/manual/windowmodality/main.cpp
new file mode 100644
index 0000000000..35584b5c68
--- /dev/null
+++ b/tests/manual/windowmodality/main.cpp
@@ -0,0 +1,301 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "ui_dialog.h"
+#include "ui_widget.h"
+
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+#include <QtWidgets/QColorDialog>
+#include <QtWidgets/QFileDialog>
+#include <QtWidgets/QFontDialog>
+#include <QtPrintSupport/QPageSetupDialog>
+#include <QtPrintSupport/QPrintDialog>
+
+enum DialogType
+{
+ CustomDialogType,
+ ColorDialogType,
+ FileDialogType,
+ FontDialogType,
+ PageSetupDialogType,
+ PrintDialogType
+};
+
+class CustomDialog : public QDialog, public Ui::Dialog
+{
+ Q_OBJECT
+public:
+ CustomDialog(QWidget *parent = 0)
+ : QDialog(parent)
+ {
+ setupUi(this);
+
+ // hide the "Create new dialogs as siblings of this dialog" button when
+ // we don't have a parent of our own (they would be parentless anyway)
+ if (!parent) {
+ createSiblingDialogCheckBox->setChecked(false);
+ createSiblingDialogCheckBox->setVisible(false);
+ }
+ }
+
+private slots:
+ void on_modelessCustomDialogButton_clicked()
+ { newDialog(CustomDialogType, Qt::NonModal); }
+ void on_modelessColorDialogButton_clicked()
+ { newDialog(ColorDialogType, Qt::NonModal); }
+ void on_modelessFontDialogButton_clicked()
+ { newDialog(FontDialogType, Qt::NonModal); }
+
+ void on_windowModalCustomDialogButton_clicked()
+ { newDialog(CustomDialogType, Qt::WindowModal); }
+ void on_windowModalColorDialogButton_clicked()
+ { newDialog(ColorDialogType, Qt::WindowModal); }
+ void on_windowModalFileDialogButton_clicked()
+ { newDialog(FileDialogType, Qt::WindowModal); }
+ void on_windowModalFontDialogButton_clicked()
+ { newDialog(FontDialogType, Qt::WindowModal); }
+ void on_windowModalPageSetupDialogButton_clicked()
+ { newDialog(PageSetupDialogType, Qt::WindowModal); }
+ void on_windowModalPrintDialogButton_clicked()
+ { newDialog(PrintDialogType, Qt::WindowModal); }
+
+ void on_applicationModalCustomDialogButton_clicked()
+ { newDialog(CustomDialogType, Qt::ApplicationModal); }
+ void on_applicationModalColorDialogButton_clicked()
+ { newDialog(ColorDialogType, Qt::ApplicationModal); }
+ void on_applicationModalFileDialogButton_clicked()
+ { newDialog(FileDialogType, Qt::ApplicationModal); }
+ void on_applicationModalFontDialogButton_clicked()
+ { newDialog(FontDialogType, Qt::ApplicationModal); }
+ void on_applicationModalPageSetupDialogButton_clicked()
+ { newDialog(PageSetupDialogType, Qt::ApplicationModal); }
+ void on_applicationModalPrintDialogButton_clicked()
+ { newDialog(PrintDialogType, Qt::ApplicationModal); }
+
+private:
+ void newDialog(DialogType dialogType, Qt::WindowModality windowModality)
+ {
+ QWidget *parent = 0;
+ if (useThisAsParentCheckBox->isChecked())
+ parent = this;
+ else if (createSiblingDialogCheckBox->isChecked())
+ parent = parentWidget();
+
+ QDialog *dialog;
+ switch (dialogType) {
+ case CustomDialogType:
+ dialog = new CustomDialog(parent);
+ break;
+ case ColorDialogType:
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
+ QColorDialog::getColor(Qt::white, parent);
+ return;
+ }
+ dialog = new QColorDialog(parent);
+ break;
+ case FileDialogType:
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
+ QFileDialog::getOpenFileName(parent);
+ return;
+ }
+ dialog = new QFileDialog(parent);
+ break;
+ case FontDialogType:
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
+ bool unused = false;
+ QFontDialog::getFont(&unused, parent);
+ return;
+ }
+ dialog = new QFontDialog(parent);
+ break;
+ case PageSetupDialogType:
+ dialog = new QPageSetupDialog(parent);
+ break;
+ case PrintDialogType:
+ dialog = new QPrintDialog(parent);
+ break;
+ }
+
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->setWindowModality(windowModality);
+
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked())
+ dialog->exec();
+ else if (windowModality == Qt::WindowModal)
+ dialog->open();
+ else
+ dialog->show();
+ }
+ bool event(QEvent *event)
+ {
+ if (event->type() == QEvent::WindowBlocked)
+ setPalette(Qt::darkGray);
+ else if (event->type() == QEvent::WindowUnblocked)
+ setPalette(QPalette());
+ return QWidget::event(event);
+ }
+};
+
+class Widget : public QWidget, public Ui::Widget
+{
+ Q_OBJECT
+public:
+ Widget(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ setupUi(this);
+ }
+
+private slots:
+ void on_windowButton_clicked()
+ { (new Widget)->show(); }
+ void on_groupLeaderButton_clicked()
+ {
+ Widget *w = new Widget;
+ w->setAttribute(Qt::WA_GroupLeader);
+ w->show();
+ }
+
+ void on_modelessCustomDialogButton_clicked()
+ { newDialog(CustomDialogType, Qt::NonModal); }
+ void on_modelessColorDialogButton_clicked()
+ { newDialog(ColorDialogType, Qt::NonModal); }
+ void on_modelessFontDialogButton_clicked()
+ { newDialog(FontDialogType, Qt::NonModal); }
+
+ void on_windowModalCustomDialogButton_clicked()
+ { newDialog(CustomDialogType, Qt::WindowModal); }
+ void on_windowModalColorDialogButton_clicked()
+ { newDialog(ColorDialogType, Qt::WindowModal); }
+ void on_windowModalFileDialogButton_clicked()
+ { newDialog(FileDialogType, Qt::WindowModal); }
+ void on_windowModalFontDialogButton_clicked()
+ { newDialog(FontDialogType, Qt::WindowModal); }
+ void on_windowModalPageSetupDialogButton_clicked()
+ { newDialog(PageSetupDialogType, Qt::WindowModal); }
+ void on_windowModalPrintDialogButton_clicked()
+ { newDialog(PrintDialogType, Qt::WindowModal); }
+
+ void on_applicationModalCustomDialogButton_clicked()
+ { newDialog(CustomDialogType, Qt::ApplicationModal); }
+ void on_applicationModalColorDialogButton_clicked()
+ { newDialog(ColorDialogType, Qt::ApplicationModal); }
+ void on_applicationModalFileDialogButton_clicked()
+ { newDialog(FileDialogType, Qt::ApplicationModal); }
+ void on_applicationModalFontDialogButton_clicked()
+ { newDialog(FontDialogType, Qt::ApplicationModal); }
+ void on_applicationModalPageSetupDialogButton_clicked()
+ { newDialog(PageSetupDialogType, Qt::ApplicationModal); }
+ void on_applicationModalPrintDialogButton_clicked()
+ { newDialog(PrintDialogType, Qt::ApplicationModal); }
+
+private:
+ void newDialog(DialogType dialogType, Qt::WindowModality windowModality)
+ {
+ QWidget *parent = 0;
+ if (useThisAsParentCheckBox->isChecked())
+ parent = this;
+
+ QDialog *dialog;
+ switch (dialogType) {
+ case CustomDialogType:
+ dialog = new CustomDialog(parent);
+ break;
+ case ColorDialogType:
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
+ QColorDialog::getColor(Qt::white, parent);
+ return;
+ }
+ dialog = new QColorDialog(parent);
+ break;
+ case FileDialogType:
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
+ QFileDialog::getOpenFileName(parent);
+ return;
+ }
+ dialog = new QFileDialog(parent);
+ break;
+ case FontDialogType:
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
+ bool unused = false;
+ QFontDialog::getFont(&unused, parent);
+ return;
+ }
+ dialog = new QFontDialog(parent);
+ break;
+ case PageSetupDialogType:
+ dialog = new QPageSetupDialog(parent);
+ break;
+ case PrintDialogType:
+ dialog = new QPrintDialog(parent);
+ break;
+ }
+
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->setWindowModality(windowModality);
+
+ if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked())
+ dialog->exec();
+ else if (windowModality == Qt::WindowModal)
+ dialog->open();
+ else
+ dialog->show();
+ }
+ bool event(QEvent *event)
+ {
+ if (event->type() == QEvent::WindowBlocked)
+ setPalette(Qt::darkGray);
+ else if (event->type() == QEvent::WindowUnblocked)
+ setPalette(QPalette());
+ return QWidget::event(event);
+ }
+};
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ Widget widget;
+ widget.show();
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/tests/manual/windowmodality/modality.pro b/tests/manual/windowmodality/modality.pro
new file mode 100644
index 0000000000..973579c508
--- /dev/null
+++ b/tests/manual/windowmodality/modality.pro
@@ -0,0 +1,3 @@
+SOURCES = main.cpp
+FORMS = widget.ui dialog.ui
+QT += widgets printsupport
diff --git a/tests/manual/windowmodality/widget.ui b/tests/manual/windowmodality/widget.ui
new file mode 100644
index 0000000000..26d218b79e
--- /dev/null
+++ b/tests/manual/windowmodality/widget.ui
@@ -0,0 +1,286 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Widget</class>
+ <widget class="QWidget" name="Widget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>622</width>
+ <height>462</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Select the type of window to create:</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="2" column="0" colspan="3">
+ <widget class="QLabel" name="topLevelWindowsLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Top-level Windows</string>
+ </property>
+ </widget>
+ </item>
+ <item row="15" column="0" colspan="3">
+ <widget class="QLabel" name="applicationModalNoteLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Note: Native Application Modal Dialogs use static API instead of exec()</string>
+ </property>
+ </widget>
+ </item>
+ <item row="14" column="2">
+ <widget class="QPushButton" name="applicationModalPrintDialogButton">
+ <property name="text">
+ <string>Print Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QPushButton" name="windowButton">
+ <property name="text">
+ <string>Window</string>
+ </property>
+ </widget>
+ </item>
+ <item row="13" column="1">
+ <widget class="QPushButton" name="applicationModalColorDialogButton">
+ <property name="text">
+ <string>Color Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="0">
+ <widget class="QPushButton" name="windowModalFontDialogButton">
+ <property name="text">
+ <string>Font Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="14" column="0">
+ <widget class="QPushButton" name="applicationModalFontDialogButton">
+ <property name="text">
+ <string>Font Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="2">
+ <widget class="QPushButton" name="modelessFontDialogButton">
+ <property name="text">
+ <string>Font Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="14" column="1">
+ <widget class="QPushButton" name="applicationModalPageSetupDialogButton">
+ <property name="text">
+ <string>Page Setup Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0">
+ <widget class="QPushButton" name="windowModalCustomDialogButton">
+ <property name="text">
+ <string>Custom Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="1">
+ <widget class="QPushButton" name="windowModalPageSetupDialogButton">
+ <property name="text">
+ <string>Page Setup Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QPushButton" name="modelessColorDialogButton">
+ <property name="text">
+ <string>Color Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="13" column="2">
+ <widget class="QPushButton" name="applicationModalFileDialogButton">
+ <property name="text">
+ <string>File Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0" colspan="3">
+ <widget class="QLabel" name="windowModalDialogsLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Window Modal Dialogs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" colspan="3">
+ <widget class="QLabel" name="modelessDialogsLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Modeless (Non-Modal) Dialogs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="0" colspan="2">
+ <widget class="QLabel" name="applicationModalDialogsLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Application Modal Dialogs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QPushButton" name="groupLeaderButton">
+ <property name="text">
+ <string>Window (Group Leader)</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="2">
+ <widget class="QPushButton" name="windowModalPrintDialogButton">
+ <property name="text">
+ <string>Print Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0" colspan="3">
+ <widget class="QLabel" name="windowModalNoteLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Note: Window Modal Dialogs use open()</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <widget class="QPushButton" name="windowModalColorDialogButton">
+ <property name="text">
+ <string>Color Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="12" column="0" colspan="3">
+ <widget class="QCheckBox" name="applicationModalUseExecCheckBox">
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Application Modal Dialogs use exec()</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="2">
+ <widget class="QPushButton" name="windowModalFileDialogButton">
+ <property name="text">
+ <string>File Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="13" column="0">
+ <widget class="QPushButton" name="applicationModalCustomDialogButton">
+ <property name="text">
+ <string>Custom Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QPushButton" name="modelessCustomDialogButton">
+ <property name="text">
+ <string>Custom Dialog</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="3">
+ <widget class="QCheckBox" name="useThisAsParentCheckBox">
+ <property name="text">
+ <string>Use this window as parent for newly created dialogs</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>