From b44ca15776227c8d04e88e1c343a87fd6c54fee0 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 15 Oct 2010 13:42:45 +0200 Subject: tst_qnetworkreply: New auto test for unreachable IPs This test fails right now and we should fix the underlying issue :-) Task-number: QT-4155 --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 306b5f8..88714e6 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -291,6 +291,8 @@ private Q_SLOTS: void qtbug12908compressedHttpReply(); + void getFromUnreachableIp(); + // NOTE: This test must be last! void parentingRepliesToTheApp(); }; @@ -4301,6 +4303,19 @@ void tst_QNetworkReply::qtbug12908compressedHttpReply() QCOMPARE(reply->error(), QNetworkReply::NoError); } +void tst_QNetworkReply::getFromUnreachableIp() +{ + QNetworkAccessManager manager; + + QNetworkRequest request(QUrl("http://255.255.255.255/42/23/narf/narf/narf")); + QNetworkReplyPtr reply = manager.get(request); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(reply->error() != QNetworkReply::NoError); +} // NOTE: This test must be last testcase in tst_qnetworkreply! void tst_QNetworkReply::parentingRepliesToTheApp() -- cgit v0.12 From 534ba3c7314820604ba5aeeffa6051c91e7c1d09 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 15 Oct 2010 13:48:51 +0200 Subject: Cocoa: fix child window issues (QTBUG 13867, 14420, 13126) The main problem behind these issues is the fact that when two windows exists in a parent-child relationship (using the [NSWindow addChild] API), Cocoa will automatically hide both windows even when just hiding one of them. This turns out really bad when the child is a tool window, because those will automatically be hidden when the application becomes deactivated. And as such, the parent will hide as well, tool or not. So after a LOT of investigation, involving manually trying to level windows rather than using the addChild API, the conclusing is that we cannot do it; Cocoa and Qt just tries to outsmart each other. So instead, we now say that only normal windows and dialogs can be part of a parent-child relationship (which seems to be how Apple intended it as well). The rest, and in particular tool windows, we just ignore. This will differ from some other platforms, but at the same time, since tool windows are on a level above other windows on mac from before, and the docs specifies that this can be different from platform to platform, we see it as acceptable. Rev-By: prasanth Rev-By: msorvig --- src/gui/kernel/qwidget_mac.mm | 47 ++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 1e2aa9f..b3b9183 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -2794,19 +2794,36 @@ void QWidgetPrivate::transferChildren() #ifdef QT_MAC_USE_COCOA void QWidgetPrivate::setSubWindowStacking(bool set) { + // This will set/remove a visual relationship between parent and child on screen. + // The reason for doing this is to ensure that a child always stacks infront of + // its parent. Unfortunatly is turns out that [NSWindow addChildWindow] has + // several unwanted side-effects, one of them being the moving of a child when + // moving the parent, which we choose to accept. A way tougher side-effect is + // that Cocoa will hide the parent if you hide the child. And in the case of + // a tool window, since it will normally hide when you deactivate the + // application, Cocoa will hide the parent upon deactivate as well. The result often + // being no more visible windows on screen. So, to make a long story short, we only + // allow parent-child relationships between windows that both are on the NSNormalWindowLevel + // (because Cocoa will also use the window level to decide upon strange behaviour). + Q_Q(QWidget); - if (!q->isWindow() || !q->testAttribute(Qt::WA_WState_Created)) + if (!q->isWindow()) + return; + NSWindow *qwin = [qt_mac_nativeview_for(q) window]; + if (!qwin) + return; + if (set && [qwin level] != NSNormalWindowLevel) + return; + if (set && ![qwin isVisible]) return; if (QWidget *parent = q->parentWidget()) { - if (parent->testAttribute(Qt::WA_WState_Created)) { + if (NSWindow *pwin = [qt_mac_nativeview_for(parent) window]) { if (set) { - if (parent->isVisible()) { - NSWindow *childwin = qt_mac_window_for(q); - [qt_mac_window_for(parent) addChildWindow:childwin ordered:NSWindowAbove]; - } + if ([pwin isVisible] && [pwin level] == NSNormalWindowLevel && ![qwin parentWindow]) + [pwin addChildWindow:qwin ordered:NSWindowAbove]; } else { - [qt_mac_window_for(parent) removeChildWindow:qt_mac_window_for(q)]; + [pwin removeChildWindow:qwin]; } } } @@ -2814,12 +2831,14 @@ void QWidgetPrivate::setSubWindowStacking(bool set) QList widgets = q->findChildren(); for (int i=0; iisWindow() && child->testAttribute(Qt::WA_WState_Created) && child->isVisibleTo(q)) { - if (set) { - NSWindow *childwin = qt_mac_window_for(child); - [qt_mac_window_for(q) addChildWindow:childwin ordered:NSWindowAbove]; - } else { - [qt_mac_window_for(q) removeChildWindow:qt_mac_window_for(child)]; + if (child && child->isWindow()) { + if (NSWindow *cwin = [qt_mac_nativeview_for(child) window]) { + if (set) { + if ([cwin isVisible] && [cwin level] == NSNormalWindowLevel && ![cwin parentWindow]) + [qwin addChildWindow:cwin ordered:NSWindowAbove]; + } else { + [qwin removeChildWindow:qt_mac_window_for(child)]; + } } } } @@ -3442,7 +3461,6 @@ void QWidgetPrivate::show_sys() #else // sync the opacity value back (in case of a fade). [window setAlphaValue:q->windowOpacity()]; - setSubWindowStacking(true); QWidget *top = 0; if (QApplicationPrivate::tryModalHelper(q, &top)) { @@ -3461,6 +3479,7 @@ void QWidgetPrivate::show_sys() [modalWin orderFront:window]; } } + setSubWindowStacking(true); #endif if (q->windowType() == Qt::Popup) { if (q->focusWidget()) -- cgit v0.12 From 82e03a66d18a27ea06dfa35f1e236bbe9ef972f7 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 15 Oct 2010 15:02:26 +0200 Subject: Change git commit template Add "pending" to Reviewed-by to prevent accidental git push --- .commit-template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.commit-template b/.commit-template index 589ca89..6e0e3a4 100644 --- a/.commit-template +++ b/.commit-template @@ -5,6 +5,6 @@ # ---[ Fields ]-----------------[ uncomment and edit as applicable ]---| #Task-number: -#Reviewed-by: +Reviewed-by: pending # ==================================[ please wrap at 72 characters ]===| -- cgit v0.12 From 7b32da4af8b6f305185d1c22d1425164b00e5391 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 15 Oct 2010 15:23:33 +0200 Subject: Cocoa: small update to 534ba3c7314820604ba5aeeffa6051c91e7c1d09 Rather than checking window level directly, we check the Qt window type. This has the advantage that we also include dialogs that are modal. --- src/gui/kernel/qwidget_mac.mm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index b3b9183..997419b 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -2803,8 +2803,8 @@ void QWidgetPrivate::setSubWindowStacking(bool set) // a tool window, since it will normally hide when you deactivate the // application, Cocoa will hide the parent upon deactivate as well. The result often // being no more visible windows on screen. So, to make a long story short, we only - // allow parent-child relationships between windows that both are on the NSNormalWindowLevel - // (because Cocoa will also use the window level to decide upon strange behaviour). + // allow parent-child relationships between windows that both are either a plain window + // or a dialog. Q_Q(QWidget); if (!q->isWindow()) @@ -2812,7 +2812,8 @@ void QWidgetPrivate::setSubWindowStacking(bool set) NSWindow *qwin = [qt_mac_nativeview_for(q) window]; if (!qwin) return; - if (set && [qwin level] != NSNormalWindowLevel) + Qt::WindowType qtype = q->windowType(); + if (set && !(qtype == Qt::Window || qtype == Qt::Dialog)) return; if (set && ![qwin isVisible]) return; @@ -2820,7 +2821,8 @@ void QWidgetPrivate::setSubWindowStacking(bool set) if (QWidget *parent = q->parentWidget()) { if (NSWindow *pwin = [qt_mac_nativeview_for(parent) window]) { if (set) { - if ([pwin isVisible] && [pwin level] == NSNormalWindowLevel && ![qwin parentWindow]) + Qt::WindowType ptype = parent->window()->windowType(); + if ([pwin isVisible] && (ptype == Qt::Window || ptype == Qt::Dialog) && ![qwin parentWindow]) [pwin addChildWindow:qwin ordered:NSWindowAbove]; } else { [pwin removeChildWindow:qwin]; @@ -2834,7 +2836,8 @@ void QWidgetPrivate::setSubWindowStacking(bool set) if (child && child->isWindow()) { if (NSWindow *cwin = [qt_mac_nativeview_for(child) window]) { if (set) { - if ([cwin isVisible] && [cwin level] == NSNormalWindowLevel && ![cwin parentWindow]) + Qt::WindowType ctype = child->window()->windowType(); + if ([cwin isVisible] && (ctype == Qt::Window || ctype == Qt::Dialog) && ![cwin parentWindow]) [qwin addChildWindow:cwin ordered:NSWindowAbove]; } else { [qwin removeChildWindow:qt_mac_window_for(child)]; -- cgit v0.12 From b498c15ebbf120819f73fe761388fd63c2de4b23 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 15 Oct 2010 17:01:37 +0200 Subject: QNAM HTTP: Fix error signal emission for unreachable IPs This commit fixes getFromUnreachableIp() Reviewed-by: Thiago Macieira Task-Number: QTBUG-10679 --- src/network/access/qhttpnetworkconnectionchannel.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 6437f6f..d10f951 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -105,12 +105,22 @@ void QHttpNetworkConnectionChannel::init() QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(_q_readyRead()), Qt::DirectConnection); + + // The disconnected() and error() signals may already come + // while calling connectToHost(). + // In case of a cached hostname or an IP this + // will then emit a signal to the user of QNetworkReply + // but cannot be caught because the user did not have a chance yet + // to connect to QNetworkReply's signals. + qRegisterMetaType("QAbstractSocket::SocketError"); QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(_q_disconnected()), - Qt::DirectConnection); + Qt::QueuedConnection); QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(_q_error(QAbstractSocket::SocketError)), - Qt::DirectConnection); + Qt::QueuedConnection); + + #ifndef QT_NO_NETWORKPROXY QObject::connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(_q_proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), -- cgit v0.12