summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/qtdemo/xml/examples.xml1
-rw-r--r--doc/src/examples.qdoc1
-rw-r--r--doc/src/examples/googlesuggest.qdoc51
-rw-r--r--doc/src/images/googlesuggest-example.pngbin0 -> 18809 bytes
-rw-r--r--examples/network/googlesuggest/googlesuggest.cpp223
-rw-r--r--examples/network/googlesuggest/googlesuggest.h80
-rw-r--r--examples/network/googlesuggest/googlesuggest.pro9
-rw-r--r--examples/network/googlesuggest/main.cpp52
-rw-r--r--examples/network/googlesuggest/searchbox.cpp69
-rw-r--r--examples/network/googlesuggest/searchbox.h64
-rw-r--r--examples/network/network.pro1
-rw-r--r--src/network/socket/qlocalsocket_win.cpp2
-rw-r--r--tests/auto/qlocalsocket/tst_qlocalsocket.cpp22
-rw-r--r--tools/assistant/tools/assistant/mainwindow.cpp25
-rw-r--r--tools/assistant/tools/assistant/mainwindow.h3
-rw-r--r--tools/assistant/tools/assistant/searchwidget.cpp62
16 files changed, 596 insertions, 69 deletions
diff --git a/demos/qtdemo/xml/examples.xml b/demos/qtdemo/xml/examples.xml
index 667f9f2..96a3e80 100644
--- a/demos/qtdemo/xml/examples.xml
+++ b/demos/qtdemo/xml/examples.xml
@@ -118,6 +118,7 @@
<example filename="threadedfortuneserver" name="Threaded Fort. Server" />
<example filename="torrent" name="Torrent Client" />
<example filename="securesocketclient" name="Secure Socket Client" />
+ <example filename="googlesuggest" name="Google Suggest" />
</category>
<category dirname="opengl" name="OpenGL">
<example filename="2dpainting" name="2D Painting" />
diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc
index efe9b2f..29c6c0b 100644
--- a/doc/src/examples.qdoc
+++ b/doc/src/examples.qdoc
@@ -209,6 +209,7 @@
\o \l{network/loopback}{Loopback}
\o \l{network/threadedfortuneserver}{Threaded Fortune Server}\raisedaster
\o \l{network/torrent}{Torrent}
+ \o \l{network/googlesuggest}{Google Suggest}
\endlist
\section1 OpenGL
diff --git a/doc/src/examples/googlesuggest.qdoc b/doc/src/examples/googlesuggest.qdoc
new file mode 100644
index 0000000..a9b09f9
--- /dev/null
+++ b/doc/src/examples/googlesuggest.qdoc
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example network/googlesuggest
+ \title Google Suggest Example
+
+ The Google Suggest example shows how to use the network access manager
+ to get the list of suggested search terms from Google.
+
+ \image googlesuggest-example.png
+
+*/
diff --git a/doc/src/images/googlesuggest-example.png b/doc/src/images/googlesuggest-example.png
new file mode 100644
index 0000000..4ef072a
--- /dev/null
+++ b/doc/src/images/googlesuggest-example.png
Binary files differ
diff --git a/examples/network/googlesuggest/googlesuggest.cpp b/examples/network/googlesuggest/googlesuggest.cpp
new file mode 100644
index 0000000..285a018
--- /dev/null
+++ b/examples/network/googlesuggest/googlesuggest.cpp
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtGui>
+#include <QtNetwork>
+
+#include "googlesuggest.h"
+
+#define GSUGGEST_URL "http://google.com/complete/search?output=toolbar&q=%1"
+
+GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), editor(parent)
+{
+ popup = new QTreeWidget;
+ popup->setColumnCount(2);
+ popup->setUniformRowHeights(true);
+ popup->setRootIsDecorated(false);
+ popup->setEditTriggers(QTreeWidget::NoEditTriggers);
+ popup->setSelectionBehavior(QTreeWidget::SelectRows);
+ popup->setFrameStyle(QFrame::Box | QFrame::Plain);
+ popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ popup->header()->hide();
+ popup->installEventFilter(this);
+ popup->setMouseTracking(true);
+
+ connect(popup, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
+ SLOT(doneCompletion()));
+
+ popup->setWindowFlags(Qt::Popup);
+ popup->setFocusPolicy(Qt::NoFocus);
+ popup->setFocusProxy(parent);
+
+ timer = new QTimer(this);
+ timer->setSingleShot(true);
+ timer->setInterval(500);
+ connect(timer, SIGNAL(timeout()), SLOT(autoSuggest()));
+ connect(editor, SIGNAL(textEdited(QString)), timer, SLOT(start()));
+
+ connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(handleNetworkData(QNetworkReply*)));
+
+}
+
+GSuggestCompletion::~GSuggestCompletion()
+{
+ delete popup;
+}
+
+bool GSuggestCompletion::eventFilter(QObject *obj, QEvent *ev)
+{
+ if (obj != popup)
+ return false;
+
+ if (ev->type() == QEvent::MouseButtonPress) {
+ popup->hide();
+ editor->setFocus();
+ return true;
+ }
+
+ if (ev->type() == QEvent::KeyPress) {
+
+ bool consumed = false;
+ int key = static_cast<QKeyEvent*>(ev)->key();
+ switch (key) {
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ doneCompletion();
+ consumed = true;
+
+ case Qt::Key_Escape:
+ editor->setFocus();
+ popup->hide();
+ consumed = true;
+
+ case Qt::Key_Up:
+ case Qt::Key_Down:
+ case Qt::Key_Home:
+ case Qt::Key_End:
+ case Qt::Key_PageUp:
+ case Qt::Key_PageDown:
+ break;
+
+ default:
+ editor->setFocus();
+ editor->event(ev);
+ popup->hide();
+ break;
+ }
+
+ return consumed;
+ }
+
+ return false;
+}
+
+void GSuggestCompletion::showCompletion(const QStringList &choices, const QStringList &hits)
+{
+
+ if (choices.isEmpty() || choices.count() != hits.count())
+ return;
+
+ const QPalette &pal = editor->palette();
+ QColor color = pal.color(QPalette::Disabled, QPalette::WindowText);
+
+ popup->setUpdatesEnabled(false);
+ popup->clear();
+ for (int i = 0; i < choices.count(); ++i) {
+ QTreeWidgetItem * item;
+ item = new QTreeWidgetItem(popup);
+ item->setText(0, choices[i]);
+ item->setText(1, hits[i]);
+ item->setTextAlignment(1, Qt::AlignRight);
+ item->setTextColor(1, color);
+ }
+ popup->setCurrentItem(popup->topLevelItem(0));
+ popup->resizeColumnToContents(0);
+ popup->resizeColumnToContents(1);
+ popup->adjustSize();
+ popup->setUpdatesEnabled(true);
+
+ int h = popup->sizeHintForRow(0) * qMin(7, choices.count()) + 3;
+ popup->resize(popup->width(), h);
+
+ popup->move(editor->mapToGlobal(QPoint(0, editor->height())));
+ popup->setFocus();
+ popup->show();
+}
+
+void GSuggestCompletion::doneCompletion()
+{
+ timer->stop();
+ popup->hide();
+ editor->setFocus();
+ QTreeWidgetItem *item = popup->currentItem();
+ if (item) {
+ editor->setText(item->text(0));
+ QKeyEvent *e;
+ e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
+ QApplication::postEvent(editor, e);
+ e = new QKeyEvent(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier);
+ QApplication::postEvent(editor, e);
+ }
+}
+
+void GSuggestCompletion::preventSuggest()
+{
+ timer->stop();
+}
+
+void GSuggestCompletion::autoSuggest()
+{
+ QString str = editor->text();
+ QString url = QString(GSUGGEST_URL).arg(str);
+ networkManager.get(QNetworkRequest(QString(url)));
+}
+
+void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply)
+{
+ QUrl url = networkReply->url();
+ if (!networkReply->error()) {
+ QStringList choices;
+ QStringList hits;
+
+ QString response(networkReply->readAll());
+ QXmlStreamReader xml(response);
+ while (!xml.atEnd()) {
+ xml.readNext();
+ if (xml.tokenType() == QXmlStreamReader::StartElement)
+ if (xml.name() == "suggestion") {
+ QStringRef str = xml.attributes().value("data");
+ choices << str.toString();
+ }
+ if (xml.tokenType() == QXmlStreamReader::StartElement)
+ if (xml.name() == "num_queries") {
+ QStringRef str = xml.attributes().value("int");
+ hits << str.toString();
+ }
+ }
+
+ showCompletion(choices, hits);
+ }
+
+ networkReply->deleteLater();
+}
diff --git a/examples/network/googlesuggest/googlesuggest.h b/examples/network/googlesuggest/googlesuggest.h
new file mode 100644
index 0000000..0267709
--- /dev/null
+++ b/examples/network/googlesuggest/googlesuggest.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GOOGLESUGGEST_H
+#define GOOGLESUGGEST_H
+
+#include <QObject>
+#include <QNetworkAccessManager>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QNetworkReply;
+class QTimer;
+class QTreeWidget;
+QT_END_NAMESPACE
+
+class GSuggestCompletion : public QObject
+{
+ Q_OBJECT
+
+public:
+ GSuggestCompletion(QLineEdit *parent = 0);
+ ~GSuggestCompletion();
+ bool eventFilter(QObject *obj, QEvent *ev);
+ void showCompletion(const QStringList &choices, const QStringList &hits);
+
+public slots:
+
+ void doneCompletion();
+ void preventSuggest();
+ void autoSuggest();
+ void handleNetworkData(QNetworkReply *networkReply);
+
+private:
+ QLineEdit *editor;
+ QTreeWidget *popup;
+ QTimer *timer;
+ QNetworkAccessManager networkManager;
+};
+
+#endif // GOOGLESUGGEST_H
+
diff --git a/examples/network/googlesuggest/googlesuggest.pro b/examples/network/googlesuggest/googlesuggest.pro
new file mode 100644
index 0000000..afd600f
--- /dev/null
+++ b/examples/network/googlesuggest/googlesuggest.pro
@@ -0,0 +1,9 @@
+QT += network
+SOURCES = main.cpp searchbox.cpp googlesuggest.cpp
+HEADERS = searchbox.h googlesuggest.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlesuggest
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlesuggest
+INSTALLS += target sources
diff --git a/examples/network/googlesuggest/main.cpp b/examples/network/googlesuggest/main.cpp
new file mode 100644
index 0000000..f8d9bc5
--- /dev/null
+++ b/examples/network/googlesuggest/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "searchbox.h"
+
+int main(int argc, char * argv[])
+{
+ QApplication app(argc, argv);
+ SearchBox *searchEdit = new SearchBox;
+ searchEdit->show();
+ return app.exec();
+}
diff --git a/examples/network/googlesuggest/searchbox.cpp b/examples/network/googlesuggest/searchbox.cpp
new file mode 100644
index 0000000..cd7b122
--- /dev/null
+++ b/examples/network/googlesuggest/searchbox.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDesktopServices>
+#include <QUrl>
+
+#include "searchbox.h"
+#include "googlesuggest.h"
+
+#define GSEARCH_URL "http://www.google.com/search?q=%1"
+
+
+SearchBox::SearchBox(QWidget *parent): QLineEdit(parent)
+{
+ completer = new GSuggestCompletion(this);
+
+ connect(this, SIGNAL(returnPressed()), SLOT(doSearch()));
+
+ setWindowTitle("Search with Google");
+
+ adjustSize();
+ resize(400, height());
+ setFocus();
+}
+
+void SearchBox::doSearch()
+{
+ completer->preventSuggest();
+ QString url = QString(GSEARCH_URL).arg(text());
+ QDesktopServices::openUrl(QUrl(url));
+}
diff --git a/examples/network/googlesuggest/searchbox.h b/examples/network/googlesuggest/searchbox.h
new file mode 100644
index 0000000..75ceffd
--- /dev/null
+++ b/examples/network/googlesuggest/searchbox.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SEARCHBOX_H
+#define SEARCHBOX_H
+
+#include <QLineEdit>
+
+class GSuggestCompletion;
+
+class SearchBox: public QLineEdit
+{
+ Q_OBJECT
+
+public:
+ SearchBox(QWidget *parent = 0);
+
+protected slots:
+ void doSearch();
+
+private:
+ GSuggestCompletion *completer;
+};
+
+
+#endif // SEARCHBOX_H
diff --git a/examples/network/network.pro b/examples/network/network.pro
index 13b3116..8c45745 100644
--- a/examples/network/network.pro
+++ b/examples/network/network.pro
@@ -11,6 +11,7 @@ SUBDIRS = blockingfortuneclient \
http \
loopback \
threadedfortuneserver \
+ googlesuggest \
torrent
contains(QT_CONFIG, openssl):SUBDIRS += securesocketclient
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index e759d0b..39c9284 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -298,7 +298,7 @@ qint64 QLocalSocketPrivate::bytesAvailable()
if (PeekNamedPipe(handle, NULL, 0, NULL, &bytes, NULL)) {
return bytes;
} else {
- if (ERROR_BROKEN_PIPE == GetLastError() && !pipeClosed) {
+ if (!pipeClosed) {
pipeClosed = true;
QTimer::singleShot(0, q, SLOT(_q_pipeClosed()));
}
diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
index f741b96..deabda6 100644
--- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
@@ -95,6 +95,7 @@ private slots:
void longPath();
void waitForDisconnect();
+ void waitForDisconnectByServer();
void removeServer();
@@ -112,6 +113,8 @@ tst_QLocalSocket::tst_QLocalSocket()
#endif
))
qWarning() << "lackey executable doesn't exists!";
+
+ QLocalServer::removeServer("tst_localsocket");
}
tst_QLocalSocket::~tst_QLocalSocket()
@@ -783,6 +786,25 @@ void tst_QLocalSocket::waitForDisconnect()
QVERIFY(timer.elapsed() < 2000);
}
+void tst_QLocalSocket::waitForDisconnectByServer()
+{
+ QString name = "tst_localsocket";
+ LocalServer server;
+ QVERIFY(server.listen(name));
+ LocalSocket socket;
+ QSignalSpy spy(&socket, SIGNAL(disconnected()));
+ QVERIFY(spy.isValid());
+ socket.connectToServer(name);
+ QVERIFY(socket.waitForConnected(3000));
+ QVERIFY(server.waitForNewConnection(3000));
+ QLocalSocket *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ serverSocket->close();
+ QVERIFY(serverSocket->state() == QLocalSocket::UnconnectedState);
+ QVERIFY(socket.waitForDisconnected(3000));
+ QCOMPARE(spy.count(), 1);
+}
+
void tst_QLocalSocket::removeServer()
{
// this is a hostile takeover, but recovering from a crash results in the same
diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp
index c1e9027..2e39186 100644
--- a/tools/assistant/tools/assistant/mainwindow.cpp
+++ b/tools/assistant/tools/assistant/mainwindow.cpp
@@ -88,7 +88,6 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
: QMainWindow(parent)
, m_toolBarMenu(0)
, m_cmdLine(cmdLine)
- , m_searchWidget(0)
, m_progressWidget(0)
, m_qtDocInstaller(0)
, m_connectedInitSignals(false)
@@ -125,20 +124,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted()));
connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished()));
-#ifdef QT_CLUCENE_SUPPORT
m_centralWidget->createSearchWidget(searchEngine);
-#else
- QDockWidget *dock = new QDockWidget(tr("Search"), this);
- dock->setObjectName(QLatin1String("SearchWindow"));
- m_searchWidget = new SearchWidget(searchEngine, this);
- dock->setWidget(m_searchWidget);
- addDockWidget(Qt::LeftDockWidgetArea, dock);
-
- connect(m_searchWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
- SLOT(setSource(QUrl)));
- connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)),
- m_centralWidget, SLOT(setSourceInNewTab(QUrl)));
-#endif
QString defWindowTitle = tr("Qt Assistant");
setWindowTitle(defWindowTitle);
@@ -882,19 +868,12 @@ void MainWindow::activateCurrentCentralWidgetTab()
void MainWindow::showSearch()
{
- if (m_searchWidget)
- activateDockWidget(m_searchWidget);
- else
- m_centralWidget->activateSearch();
+ m_centralWidget->activateSearch();
}
void MainWindow::hideSearch()
{
- if (m_searchWidget) {
- m_searchWidget->parentWidget()->parentWidget()->hide();
- } else {
- m_centralWidget->removeSearchWidget();
- }
+ m_centralWidget->removeSearchWidget();
}
void MainWindow::updateApplicationFont()
diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h
index c716b1c..1bd8005 100644
--- a/tools/assistant/tools/assistant/mainwindow.h
+++ b/tools/assistant/tools/assistant/mainwindow.h
@@ -62,8 +62,6 @@ class BookmarkWidget;
class CmdLineParser;
class QtDocInstaller;
-class SearchWidget;
-
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -159,7 +157,6 @@ private:
QMenu *m_toolBarMenu;
CmdLineParser *m_cmdLine;
- SearchWidget *m_searchWidget;
QWidget *m_progressWidget;
QtDocInstaller *m_qtDocInstaller;
diff --git a/tools/assistant/tools/assistant/searchwidget.cpp b/tools/assistant/tools/assistant/searchwidget.cpp
index 000c73d..677e18e 100644
--- a/tools/assistant/tools/assistant/searchwidget.cpp
+++ b/tools/assistant/tools/assistant/searchwidget.cpp
@@ -70,16 +70,18 @@ SearchWidget::SearchWidget(QHelpSearchEngine *engine, QWidget *parent)
QHelpSearchQueryWidget *queryWidget = searchEngine->queryWidget();
vLayout->addWidget(queryWidget);
- vLayout->addWidget(resultWidget);
-
+ vLayout->addWidget(resultWidget);
+
setFocusProxy(queryWidget);
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
- connect(resultWidget, SIGNAL(requestShowLink(const QUrl&)),
- this, SIGNAL(requestShowLink(const QUrl&)));
+ connect(resultWidget, SIGNAL(requestShowLink(QUrl)), this,
+ SIGNAL(requestShowLink(QUrl)));
- connect(searchEngine, SIGNAL(searchingStarted()), this, SLOT(searchingStarted()));
- connect(searchEngine, SIGNAL(searchingFinished(int)), this, SLOT(searchingFinished(int)));
+ connect(searchEngine, SIGNAL(searchingStarted()), this,
+ SLOT(searchingStarted()));
+ connect(searchEngine, SIGNAL(searchingFinished(int)), this,
+ SLOT(searchingFinished(int)));
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
browser->viewport()->installEventFilter(this);
@@ -92,10 +94,6 @@ SearchWidget::~SearchWidget()
void SearchWidget::zoomIn()
{
-#ifndef QT_CLUCENE_SUPPORT
- return;
-#endif
-
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
if (browser && zoomCount != 10) {
zoomCount++;
@@ -105,10 +103,6 @@ void SearchWidget::zoomIn()
void SearchWidget::zoomOut()
{
-#ifndef QT_CLUCENE_SUPPORT
- return;
-#endif
-
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
if (browser && zoomCount != -5) {
zoomCount--;
@@ -118,10 +112,6 @@ void SearchWidget::zoomOut()
void SearchWidget::resetZoom()
{
-#ifndef QT_CLUCENE_SUPPORT
- return;
-#endif
-
if (zoomCount == 0)
return;
@@ -152,7 +142,8 @@ void SearchWidget::searchingFinished(int hits)
bool SearchWidget::eventFilter(QObject* o, QEvent *e)
{
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
- if (browser && o == browser->viewport() && e->type() == QEvent::MouseButtonRelease){
+ if (browser && o == browser->viewport()
+ && e->type() == QEvent::MouseButtonRelease){
QMouseEvent *me = static_cast<QMouseEvent*>(e);
QUrl link = resultWidget->linkAt(me->pos());
if (!link.isEmpty() || link.isValid()) {
@@ -179,7 +170,6 @@ void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
QMenu menu;
QPoint point = contextMenuEvent->globalPos();
-#ifdef QT_CLUCENE_SUPPORT
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
if (!browser)
return;
@@ -190,22 +180,25 @@ void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
QUrl link = browser->anchorAt(point);
- QAction *copyAction = menu.addAction(tr("&Copy") +
- QString(QLatin1String("\t") + QString(QKeySequence(Qt::CTRL | Qt::Key_C))));
+ QKeySequence keySeq(QKeySequence::Copy);
+ QAction *copyAction = menu.addAction(tr("&Copy") + QLatin1String("\t") +
+ keySeq.toString(QKeySequence::NativeText));
copyAction->setEnabled(QTextCursor(browser->textCursor()).hasSelection());
QAction *copyAnchorAction = menu.addAction(tr("Copy &Link Location"));
copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid());
- QAction *newTabAction = menu.addAction(tr("Open Link in New Tab") +
- QString(QLatin1String("\t") + QString(QKeySequence(Qt::CTRL))) +
+ keySeq = QKeySequence(Qt::CTRL);
+ QAction *newTabAction = menu.addAction(tr("Open Link in New Tab") +
+ QLatin1String("\t") + keySeq.toString(QKeySequence::NativeText) +
QLatin1String("LMB"));
newTabAction->setEnabled(!link.isEmpty() && link.isValid());
menu.addSeparator();
- QAction *selectAllAction = menu.addAction(tr("Select All") +
- QString(QLatin1String("\t") + QString(QKeySequence(Qt::CTRL | Qt::Key_A))));
+ keySeq = QKeySequence::SelectAll;
+ QAction *selectAllAction = menu.addAction(tr("Select All") +
+ QLatin1String("\t") + keySeq.toString(QKeySequence::NativeText));
QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos()));
if (usedAction == copyAction) {
@@ -222,25 +215,10 @@ void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
}
else if (usedAction == newTabAction) {
emit requestShowLinkInNewTab(link);
- }
+ }
else if (usedAction == selectAllAction) {
browser->selectAll();
}
-#else
- point = resultWidget->mapFromGlobal(point);
- QUrl link = resultWidget->linkAt(point);
- if (link.isEmpty() || !link.isValid())
- return;
-
- QAction *curTab = menu.addAction(tr("Open Link"));
- QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
-
- QAction *action = menu.exec(mapToGlobal(contextMenuEvent->pos()));
- if (curTab == action)
- emit requestShowLink(link);
- else if (newTab == action)
- emit requestShowLinkInNewTab(link);
-#endif
}
QT_END_NAMESPACE