diff options
28 files changed, 799 insertions, 129 deletions
diff --git a/demos/qtdemo/xml/examples.xml b/demos/qtdemo/xml/examples.xml index 07c2691..667f9f2 100644 --- a/demos/qtdemo/xml/examples.xml +++ b/demos/qtdemo/xml/examples.xml @@ -217,6 +217,7 @@ <example filename="formextractor" name="Form Extractor" /> <example filename="previewer" name="HTML Previewer" /> <example filename="fancybrowser" name="Fancy Browser" /> + <example filename="googlechat" name="Google Chat" /> </category> <category dirname="xml" name="XML"> <example filename="saxbookmarks" name="SAX Bookmarks" /> diff --git a/doc/doc.pri b/doc/doc.pri index 46df3cb..a4c77fe 100644 --- a/doc/doc.pri +++ b/doc/doc.pri @@ -4,7 +4,7 @@ win32 { QT_WINCONFIG = release/ - CONFIG(debug, debug|release) { + !CONFIG(release, debug|release) { QT_WINCONFIG = debug/ } } diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc index 2b7aea3..efe9b2f 100644 --- a/doc/src/examples.qdoc +++ b/doc/src/examples.qdoc @@ -348,6 +348,7 @@ \list \o \l{webkit/previewer}{Previewer}\raisedaster \o \l{webkit/formextractor}{Form Extractor} + \o \l{webkit/googlechat}{Google Chat} \o \l{webkit/fancybrowser}{Fancy Browser} \endlist diff --git a/doc/src/examples/googlechat.qdoc b/doc/src/examples/googlechat.qdoc new file mode 100644 index 0000000..f2d61cf --- /dev/null +++ b/doc/src/examples/googlechat.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 webkit/googlechat + \title Google Chat Example + + The Google Chat example shows how to use implement a simple Google Chat + client with QtWebKit. + + \image googlechat-example.png + +*/ diff --git a/doc/src/images/googlechat-example.png b/doc/src/images/googlechat-example.png Binary files differnew file mode 100644 index 0000000..0338445 --- /dev/null +++ b/doc/src/images/googlechat-example.png diff --git a/examples/webkit/googlechat/form.ui b/examples/webkit/googlechat/form.ui new file mode 100644 index 0000000..3b9fb82 --- /dev/null +++ b/examples/webkit/googlechat/form.ui @@ -0,0 +1,214 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>286</width> + <height>413</height> + </rect> + </property> + <property name="windowTitle"> + <string>Google Talk Client</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>0</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QStackedWidget" name="stackedWidget"> + <property name="currentIndex"> + <number>1</number> + </property> + <widget class="QWidget" name="page_3"> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <spacer name="verticalSpacer_4"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>170</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="statusLabel"> + <property name="text"> + <string>TextLabel</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QProgressBar" name="progressBar"> + <property name="value"> + <number>24</number> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer_5"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>169</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <widget class="QWidget" name="page"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>119</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="userNameLabel"> + <property name="text"> + <string>Google username:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="userNameEdit"/> + </item> + <item> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>17</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="passwordLabel"> + <property name="text"> + <string>Password:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="passwordEdit"> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>118</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="loginButton"> + <property name="text"> + <string>Login</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QWidget" name="page_2"> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="spacing"> + <number>0</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QWebView" name="webView"> + <property name="url"> + <url> + <string>about:blank</string> + </url> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>QWebView</class> + <extends>QWidget</extends> + <header>QtWebKit/QWebView</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/examples/webkit/googlechat/googlechat.cpp b/examples/webkit/googlechat/googlechat.cpp new file mode 100644 index 0000000..9ac2cd2 --- /dev/null +++ b/examples/webkit/googlechat/googlechat.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** 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 <QtGui> +#include <QtWebKit> + +#include "googlechat.h" + +#define GOOGLECHAT_URL "http://talkgadget.google.com/talkgadget/m" + +GoogleChat::GoogleChat(): QWidget() { + form.setupUi(this); + setFixedSize(320, 480); + + form.userNameEdit->setFocus(); + connect(form.userNameEdit, SIGNAL(textChanged(QString)), SLOT(adjustLoginButton())); + connect(form.userNameEdit, SIGNAL(returnPressed()), SLOT(inputPassword())); + + connect(form.passwordEdit, SIGNAL(textChanged(QString)), SLOT(adjustLoginButton())); + connect(form.passwordEdit, SIGNAL(returnPressed()), SLOT(doLogin())); + + form.loginButton->setEnabled(false); + connect(form.loginButton, SIGNAL(clicked()), SLOT(doLogin())); + + connect(form.webView, SIGNAL(loadFinished(bool)), SLOT(initialPage(bool))); + connect(form.webView, SIGNAL(loadProgress(int)), + form.progressBar, SLOT(setValue(int))); + form.webView->setUrl((QUrl(GOOGLECHAT_URL))); + form.webView->setContextMenuPolicy(Qt::PreventContextMenu); + + showStatus("Wait..."); +} + +void GoogleChat::showStatus(const QString &msg) { + form.statusLabel->setText(msg); + form.stackedWidget->setCurrentIndex(0); +} + +void GoogleChat::showError(const QString &msg) { + form.progressBar->hide(); + showStatus(QString("Error: %1").arg(msg)); +} + +QString GoogleChat::evalJS(const QString &js) { + QWebFrame *frame = form.webView->page()->mainFrame(); + return frame->evaluateJavaScript(js).toString(); +} + +void GoogleChat::adjustLoginButton() { + userName = form.userNameEdit->text(); + password = form.passwordEdit->text(); + bool ok = !userName.isEmpty() && !password.isEmpty(); + form.loginButton->setEnabled(ok); +} + +void GoogleChat::inputPassword() { + if (!form.userNameEdit->text().isEmpty()) + form.passwordEdit->setFocus(); +} + +void GoogleChat::doLogin() { + userName = form.userNameEdit->text(); + password = form.passwordEdit->text(); + bool ok = !userName.isEmpty() && !password.isEmpty(); + if (!ok) + return; + + form.progressBar->setValue(0); + form.progressBar->show(); + connect(form.webView, SIGNAL(loadFinished(bool)), SLOT(loginPage(bool))); + connect(form.webView, SIGNAL(loadProgress(int)), + form.progressBar, SLOT(setValue(int))); + showStatus("Logging in..."); + + QString userEmail = userName + "@gmail.com"; + evalJS(QString("document.getElementById('Email').value = \"%1\";").arg(userEmail)); + evalJS(QString("document.getElementById('Passwd').value = \"%1\";").arg(password)); + evalJS("document.getElementById('gaia_loginform').submit();"); +} + +void GoogleChat::initialPage(bool ok) { + if (ok) { + QString s1 = evalJS("document.getElementById('Email').name"); + QString s2 = evalJS("document.getElementById('Passwd').name"); + QString s3 = evalJS("document.getElementById('gaia_loginform').id"); + if (s1 == "Email" && s2 == "Passwd" && s3 == "gaia_loginform") { + form.stackedWidget->setCurrentIndex(1); + form.webView->disconnect(); + return; + } + } + + showError("SERVICE unavailable."); +} + +void GoogleChat::hideElements() +{ + evalJS("var e = document.getElementsByClassName('footer-footer')[0]; e.parentElement.removeChild(e)"); + evalJS("var e = document.getElementsByClassName('title-bar-bg title-bar')[0]; e.parentElement.removeChild(e)"); + QTimer::singleShot(2000, this, SLOT(hideElements())); +} + +void GoogleChat::loginPage(bool ok) { + QString location = form.webView->url().toString(); + if (!ok) { + if (location.indexOf("CheckCookie")) + return; + showError("Service unavailable"); + } else { + // check for any error message + QString c = evalJS("document.getElementsByClassName('errormsg').length"); + if (c == "0") { + form.stackedWidget->setCurrentIndex(2); + QTimer::singleShot(500, this, SLOT(hideElements())); + return; + } + + QString err = "Unknown login failure."; + if (c == "1") { + err = evalJS("document.getElementsByClassName('errormsg')[0].textContent"); + err = err.simplified(); + } + showError(err); + } +} diff --git a/examples/webkit/googlechat/googlechat.h b/examples/webkit/googlechat/googlechat.h new file mode 100644 index 0000000..c92632c --- /dev/null +++ b/examples/webkit/googlechat/googlechat.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 <QWidget> + +#include "ui_form.h" + +class GoogleChat: public QWidget +{ + Q_OBJECT + +public: + GoogleChat(); + +protected: + void showStatus(const QString &msg); + void showError(const QString &msg); + QString evalJS(const QString &js); + +private slots: + + void adjustLoginButton(); + void inputPassword(); + void doLogin(); + void initialPage(bool ok); + void loginPage(bool ok); + void hideElements(); + +private: + Ui::Form form; + QString userName; + QString password; +}; diff --git a/examples/webkit/googlechat/googlechat.pro b/examples/webkit/googlechat/googlechat.pro new file mode 100644 index 0000000..14b7085 --- /dev/null +++ b/examples/webkit/googlechat/googlechat.pro @@ -0,0 +1,11 @@ +QT += webkit +HEADERS = googlechat.h +SOURCES = main.cpp \ + googlechat.cpp +FORMS = form.ui + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlechat +sources.files = $$SOURCES $$HEADERS $$FORMS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlechat +INSTALLS += target sources diff --git a/examples/webkit/googlechat/main.cpp b/examples/webkit/googlechat/main.cpp new file mode 100644 index 0000000..26feeea --- /dev/null +++ b/examples/webkit/googlechat/main.cpp @@ -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 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 <QtGui> +#include "googlechat.h" + +int main(int argc, char * argv[]) +{ + QApplication app(argc, argv); + GoogleChat *chat = new GoogleChat; + chat->show(); + return app.exec(); +} diff --git a/examples/webkit/webkit.pro b/examples/webkit/webkit.pro index a49830a..225816a 100644 --- a/examples/webkit/webkit.pro +++ b/examples/webkit/webkit.pro @@ -1,7 +1,8 @@ TEMPLATE = subdirs SUBDIRS += formextractor \ previewer \ - fancybrowser + fancybrowser \ + googlechat # install target.path = $$[QT_INSTALL_EXAMPLES]/webkit diff --git a/src/corelib/tools/qbytearraymatcher.cpp b/src/corelib/tools/qbytearraymatcher.cpp index cd4cf90..211d190 100644 --- a/src/corelib/tools/qbytearraymatcher.cpp +++ b/src/corelib/tools/qbytearraymatcher.cpp @@ -120,6 +120,7 @@ QByteArrayMatcher::QByteArrayMatcher() : d(0) { p.p = 0; + p.l = 0; qMemSet(p.q_skiptable, 0, sizeof(p.q_skiptable)); } @@ -170,7 +171,7 @@ QByteArrayMatcher::~QByteArrayMatcher() QByteArrayMatcher &QByteArrayMatcher::operator=(const QByteArrayMatcher &other) { q_pattern = other.q_pattern; - qMemCopy(p.q_skiptable, other.p.q_skiptable, sizeof(p.q_skiptable)); + qMemCopy(&p, &other.p, sizeof(p)); return *this; } diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/tools/qbytearraymatcher.h index d7f2366..633e92c 100644 --- a/src/corelib/tools/qbytearraymatcher.h +++ b/src/corelib/tools/qbytearraymatcher.h @@ -67,7 +67,12 @@ public: int indexIn(const QByteArray &ba, int from = 0) const; int indexIn(const char *str, int len, int from = 0) const; - inline QByteArray pattern() const { return q_pattern; } + inline QByteArray pattern() const + { + if (q_pattern.isNull()) + return QByteArray((const char*)p.p, p.l); + return q_pattern; + } private: QByteArrayMatcherPrivate *d; diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index 921be22..c6addc1 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -136,27 +136,25 @@ void QActionPrivate::redoGrab(QShortcutMap &map) void QActionPrivate::redoGrabAlternate(QShortcutMap &map) { Q_Q(QAction); - for (int i = 0; i < alternateShortcutIds.size(); ++i) - if (int id = alternateShortcutIds.at(i)) + foreach (int id, alternateShortcutIds) + if (id) map.removeShortcut(id, q); alternateShortcutIds.clear(); if (alternateShortcuts.isEmpty()) return; - for (int i = 0; i < alternateShortcuts.size(); ++i) { - const QKeySequence &alternate = alternateShortcuts.at(i); + foreach (const QKeySequence& alternate, alternateShortcuts) { if (!alternate.isEmpty()) alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext)); else alternateShortcutIds.append(0); } - if (!enabled) { - for (int i = 0; i < alternateShortcutIds.size(); ++i) - map.setShortcutEnabled(false, alternateShortcutIds.at(i), q); + foreach (int id, alternateShortcutIds) + map.setShortcutEnabled(false, id, q); } if (!autorepeat) { - for (int i = 0; i < alternateShortcutIds.size(); ++i) - map.setShortcutAutoRepeat(false, alternateShortcutIds.at(i), q); + foreach (int id, alternateShortcutIds) + map.setShortcutAutoRepeat(false, id, q); } } @@ -165,26 +163,10 @@ void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map) Q_Q(QAction); if (shortcutId) map.setShortcutEnabled(enable, shortcutId, q); - for (int i = 0; i < alternateShortcutIds.size(); ++i) - if (int id = alternateShortcutIds.at(i)) + foreach (int id, alternateShortcutIds) + if (id) map.setShortcutEnabled(enable, id, q); } - -void QActionPrivate::removeAll(QShortcutMap &map) -{ - Q_Q(QAction); - if (shortcutId) { - map.removeShortcut(shortcutId, q); - shortcutId = 0; - } - - for (int i = 0; i < alternateShortcutIds.size(); ++i) - if (int id = alternateShortcutIds.at(i)) - map.removeShortcut(id, q); - - alternateShortcutIds.clear(); -} - #endif // QT_NO_SHORTCUT @@ -633,8 +615,8 @@ QAction::~QAction() #ifndef QT_NO_SHORTCUT if (d->shortcutId && qApp) { qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this); - for (int i = 0; i < d->alternateShortcutIds.size(); ++i) - qApp->d_func()->shortcutMap.removeShortcut(d->alternateShortcutIds.at(i), this); + foreach (int id, d->alternateShortcutIds) + qApp->d_func()->shortcutMap.removeShortcut(id, this); } #endif } @@ -1067,12 +1049,7 @@ void QAction::setVisible(bool b) d->visible = b; d->enabled = b && !d->forceDisabled && (!d->group || d->group->isEnabled()) ; #ifndef QT_NO_SHORTCUT - if (b) { - d->redoGrab(qApp->d_func()->shortcutMap); - d->redoGrabAlternate(qApp->d_func()->shortcutMap); - } else { - d->removeAll(qApp->d_func()->shortcutMap); - } + d->setShortcutEnabled(d->enabled, qApp->d_func()->shortcutMap); #endif d->sendDataChanged(); } diff --git a/src/gui/kernel/qaction_p.h b/src/gui/kernel/qaction_p.h index a5b3731..0617ef5 100644 --- a/src/gui/kernel/qaction_p.h +++ b/src/gui/kernel/qaction_p.h @@ -111,7 +111,6 @@ public: void redoGrab(QShortcutMap &map); void redoGrabAlternate(QShortcutMap &map); void setShortcutEnabled(bool enable, QShortcutMap &map); - void removeAll(QShortcutMap &map); static QShortcutMap *globalMap; #endif // QT_NO_SHORTCUT diff --git a/src/gui/kernel/qshortcut.cpp b/src/gui/kernel/qshortcut.cpp index f3c93c6..50b6e59 100644 --- a/src/gui/kernel/qshortcut.cpp +++ b/src/gui/kernel/qshortcut.cpp @@ -385,21 +385,19 @@ bool QShortcut::event(QEvent *e) { Q_D(QShortcut); bool handled = false; - if (e->type() == QEvent::Shortcut) { + if (d->sc_enabled && e->type() == QEvent::Shortcut) { QShortcutEvent *se = static_cast<QShortcutEvent *>(e); if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){ - if (d->sc_enabled) { #ifndef QT_NO_WHATSTHIS - if (QWhatsThis::inWhatsThisMode()) { - QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis); - handled = true; - } else + if (QWhatsThis::inWhatsThisMode()) { + QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis); + handled = true; + } else #endif - if (se->isAmbiguous()) - emit activatedAmbiguously(); - else - emit activated(); - } + if (se->isAmbiguous()) + emit activatedAmbiguously(); + else + emit activated(); handled = true; } } diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index 415d71e..ed9654b 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -359,6 +359,8 @@ bool QShortcutMap::tryShortcutEvent(QObject *o, QKeyEvent *e) else e->ignore(); + int identicalMatches = d->identicals.count(); + switch(result) { case QKeySequence::NoMatch: return stateWasAccepted; @@ -368,8 +370,9 @@ bool QShortcutMap::tryShortcutEvent(QObject *o, QKeyEvent *e) default: break; } - - return true; + // If nextState is QKeySequence::ExactMatch && identicals.count == 0 + // we've only found disabled shortcuts + return identicalMatches > 0 || result == QKeySequence::PartialMatch; } /*! \internal @@ -491,7 +494,9 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e) // We don't need partials, if we have identicals if (d->identicals.size()) break; - partialFound = true; + // We only care about enabled partials, so we don't consume + // key events when all partials are disabled! + partialFound |= (*it).enabled; } } ++it; diff --git a/tests/auto/qaction/tst_qaction.cpp b/tests/auto/qaction/tst_qaction.cpp index 1b73f06..1ec21f2 100644 --- a/tests/auto/qaction/tst_qaction.cpp +++ b/tests/auto/qaction/tst_qaction.cpp @@ -46,7 +46,6 @@ #include <qevent.h> #include <qaction.h> #include <qmenu.h> -#include <qlineedit.h> //TESTED_CLASS= //TESTED_FILES= @@ -75,7 +74,6 @@ private slots: void setStandardKeys(); void alternateShortcuts(); void enabledVisibleInteraction(); - void invisibleActionWithComplexShortcut(); void task200823_tooltip(); void task229128TriggeredSignalWithoutActiongroup(); void task229128TriggeredSignalWhenInActiongroup(); @@ -367,36 +365,5 @@ void tst_QAction::task229128TriggeredSignalWhenInActiongroup() QCOMPARE(actionSpy.count(), 1); } -void tst_QAction::invisibleActionWithComplexShortcut() -{ - QAction action(0); - action.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E, Qt::Key_1)); - - QLineEdit edit; - edit.addAction(&action); - edit.show(); - QTest::qWait(100); - - QSignalSpy spy(&action, SIGNAL(triggered())); - - action.setVisible(true); - QTest::keyPress(&edit, Qt::Key_E, Qt::ControlModifier); - QTest::keyRelease(&edit, Qt::Key_E, Qt::ControlModifier); - QTest::keyPress(&edit, Qt::Key_1, Qt::NoModifier); - QTest::keyRelease(&edit, Qt::Key_1, Qt::NoModifier); - QCOMPARE(spy.count(), 1); - QCOMPARE(edit.text(), QLatin1String("")); - - edit.clear(); - spy.clear(); - action.setVisible(false); - QTest::keyPress(&edit, Qt::Key_E, Qt::ControlModifier); - QTest::keyRelease(&edit, Qt::Key_E, Qt::ControlModifier); - QTest::keyPress(&edit, Qt::Key_1, Qt::NoModifier); - QTest::keyRelease(&edit, Qt::Key_1, Qt::NoModifier); - QCOMPARE(spy.count(), 0); - QCOMPARE(edit.text(), QLatin1String("1")); -} - QTEST_MAIN(tst_QAction) #include "tst_qaction.moc" diff --git a/tests/auto/qbytearraymatcher/qbytearraymatcher.pro b/tests/auto/qbytearraymatcher/qbytearraymatcher.pro new file mode 100644 index 0000000..1618c3e --- /dev/null +++ b/tests/auto/qbytearraymatcher/qbytearraymatcher.pro @@ -0,0 +1,4 @@ +load(qttest_p4) +SOURCES += tst_qbytearraymatcher.cpp + +QT = core diff --git a/tests/auto/qbytearraymatcher/tst_qbytearraymatcher.cpp b/tests/auto/qbytearraymatcher/tst_qbytearraymatcher.cpp new file mode 100644 index 0000000..c3f2fd9 --- /dev/null +++ b/tests/auto/qbytearraymatcher/tst_qbytearraymatcher.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite 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 <QtTest/QtTest> + +#include <qbytearraymatcher.h> + +class tst_QByteArrayMatcher : public QObject +{ + Q_OBJECT + +private slots: + void interface(); + void task251958(); +}; + +static QByteArrayMatcher matcher1; + +void tst_QByteArrayMatcher::interface() +{ + const char needle[] = "abc123"; + QByteArray haystack(500, 'a'); + haystack.insert(6, "123"); + haystack.insert(31, "abc"); + haystack.insert(42, "abc123"); + haystack.insert(84, "abc123"); + + matcher1 = QByteArrayMatcher(QByteArray(needle)); + QByteArrayMatcher matcher2; + matcher2.setPattern(QByteArray(needle)); + + QByteArrayMatcher matcher3 = QByteArrayMatcher(QByteArray(needle)); + QByteArrayMatcher matcher4(needle, sizeof(needle - 1)); + QByteArrayMatcher matcher5(matcher2); + QByteArrayMatcher matcher6; + matcher6 = matcher3; + + QCOMPARE(matcher1.indexIn(haystack), 42); + QCOMPARE(matcher2.indexIn(haystack), 42); + QCOMPARE(matcher3.indexIn(haystack), 42); + QCOMPARE(matcher4.indexIn(haystack), 42); + QCOMPARE(matcher5.indexIn(haystack), 42); + QCOMPARE(matcher6.indexIn(haystack), 42); + + QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length()), 42); + + QCOMPARE(matcher1.indexIn(haystack, 43), 84); + QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length(), 43), 84); + QCOMPARE(matcher1.indexIn(haystack, 85), -1); + QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length(), 85), -1); + + QByteArrayMatcher matcher7(QByteArray("123")); + QCOMPARE(matcher7.indexIn(haystack), 6); + + matcher7 = QByteArrayMatcher(QByteArray("abc")); + QCOMPARE(matcher7.indexIn(haystack), 31); + + matcher7.setPattern(matcher4.pattern()); + QCOMPARE(matcher7.indexIn(haystack), 42); +} + + +static QByteArrayMatcher matcher; + +void tst_QByteArrayMatcher::task251958() +{ + const char p_data[] = { 0x0, 0x0, 0x1 }; + QByteArray pattern(p_data, sizeof(p_data)); + + QByteArray haystack(8, '\0'); + haystack[7] = 0x1; + + matcher = QByteArrayMatcher(pattern); + QCOMPARE(matcher.indexIn(haystack, 0), 5); + QCOMPARE(matcher.indexIn(haystack, 1), 5); + QCOMPARE(matcher.indexIn(haystack, 2), 5); + + matcher.setPattern(pattern); + QCOMPARE(matcher.indexIn(haystack, 0), 5); + QCOMPARE(matcher.indexIn(haystack, 1), 5); + QCOMPARE(matcher.indexIn(haystack, 2), 5); +} + +QTEST_APPLESS_MAIN(tst_QByteArrayMatcher) +#include "tst_qbytearraymatcher.moc" diff --git a/tests/auto/qlocalsocket/test/test.pro b/tests/auto/qlocalsocket/test/test.pro index 8ce7c50..7befdf9 100644 --- a/tests/auto/qlocalsocket/test/test.pro +++ b/tests/auto/qlocalsocket/test/test.pro @@ -1,7 +1,5 @@ load(qttest_p4) -include(../src/src.pri) - DEFINES += QLOCALSERVER_DEBUG DEFINES += QLOCALSOCKET_DEBUG !wince*: { @@ -14,14 +12,16 @@ DEFINES += QLOCALSOCKET_DEBUG QT = core network SOURCES += ../tst_qlocalsocket.cpp -TARGET = ../tst_qlocalsocket -win32 { +TARGET = tst_qlocalsocket +CONFIG(debug_and_release) { CONFIG(debug, debug|release) { - TARGET = ../../debug/tst_qlocalsocket -} else { - TARGET = ../../release/tst_qlocalsocket + DESTDIR = ../debug + } else { + DESTDIR = ../release } +} else { + DESTDIR = .. } wince* { diff --git a/tests/auto/qshortcut/tst_qshortcut.cpp b/tests/auto/qshortcut/tst_qshortcut.cpp index cd80204..69ebf74 100644 --- a/tests/auto/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/qshortcut/tst_qshortcut.cpp @@ -987,16 +987,17 @@ void tst_QShortcut::keypressConsumption() cut1->setEnabled(false); cut2->setEnabled(false); - edit->clear(); + // Make sure keypresses is passed on, since all multiple keysequences + // with Ctrl+I are disabled sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit QCOMPARE( currentResult, NoResult ); QCOMPARE( ambigResult, NoResult ); - QVERIFY(edit->toPlainText().isEmpty()); + QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>")); sendKeyEvents(edit, Qt::Key_A, 'a'); // Send key to edit QCOMPARE( currentResult, NoResult ); QCOMPARE( ambigResult, NoResult ); - QVERIFY(edit->toPlainText().isEmpty()); + QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>a")); clearAllShortcuts(); } diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index 1b0e671..633747a 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -277,7 +277,11 @@ CentralWidget *CentralWidget::instance() void CentralWidget::newTab() { HelpViewer* viewer = currentHelpViewer(); +#if !defined(QT_NO_WEBKIT) + if (viewer && viewer->hasLoadFinished()) +#else if (viewer) +#endif setSourceInNewTab(viewer->source()); } diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index f7225fa..5ce6e14 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -269,7 +269,10 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *, } HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) - : QWebView(parent), helpEngine(engine), parentWidget(parent) + : QWebView(parent) + , helpEngine(engine) + , parentWidget(parent) + , loadFinished(false) { setAcceptDrops(false); @@ -295,10 +298,12 @@ HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) connect(page(), SIGNAL(linkHovered(QString, QString, QString)), this, SIGNAL(highlighted(QString))); connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); + connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool))); } void HelpViewer::setSource(const QUrl &url) { + loadFinished = false; if (url.toString() == QLatin1String("help")) { load(QUrl(QLatin1String("qthelp://com.trolltech.com." "assistantinternal_1.0.0/assistant/assistant.html"))); @@ -385,6 +390,11 @@ void HelpViewer::mousePressEvent(QMouseEvent *event) QWebView::mousePressEvent(event); } +void HelpViewer::setLoadFinished(bool ok) +{ + loadFinished = ok; +} + #else // !defined(QT_NO_WEBKIT) HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent) diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h index eea7340..c66b69c 100644 --- a/tools/assistant/tools/assistant/helpviewer.h +++ b/tools/assistant/tools/assistant/helpviewer.h @@ -92,6 +92,8 @@ public: { return pageAction(QWebPage::Forward)->isEnabled(); } inline bool isBackwardAvailable() const { return pageAction(QWebPage::Back)->isEnabled(); } + inline bool hasLoadFinished() const + { return loadFinished; } public Q_SLOTS: void home(); @@ -111,10 +113,12 @@ protected: private Q_SLOTS: void actionChanged(); + void setLoadFinished(bool ok); private: QHelpEngine *helpEngine; CentralWidget* parentWidget; + bool loadFinished; }; #else diff --git a/tools/assistant/tools/assistant/indexwindow.cpp b/tools/assistant/tools/assistant/indexwindow.cpp index 0beb5ee..a2c0950 100644 --- a/tools/assistant/tools/assistant/indexwindow.cpp +++ b/tools/assistant/tools/assistant/indexwindow.cpp @@ -197,6 +197,8 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) url = tc.link(); } else if (links.count() == 1) { url = links.constBegin().value(); + } else { + return; } if (url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive)) diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index bcafacc..c1e9027 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -134,10 +134,10 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) dock->setWidget(m_searchWidget); addDockWidget(Qt::LeftDockWidgetArea, dock); - connect(m_searchWidget, SIGNAL(requestShowLink(const QUrl&)), - m_centralWidget, SLOT(setSource(const QUrl&))); - connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(const QUrl&)), - m_centralWidget, SLOT(setSourceInNewTab(const QUrl&))); + 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"); @@ -228,6 +228,18 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) else if (m_cmdLine->bookmarks() == CmdLineParser::Activate) showBookmarks(); + if (!m_cmdLine->currentFilter().isEmpty()) { + const QString &curFilter = m_cmdLine->currentFilter(); + m_helpEngine->setCurrentFilter(curFilter); + int idx = m_filterCombo->findText(curFilter); + if (idx >= 0) { + bool blocked = m_filterCombo->signalsBlocked(); + m_filterCombo->blockSignals(true); + m_filterCombo->setCurrentIndex(idx); + m_filterCombo->blockSignals(blocked); + } + } + if (usesDefaultCollection()) QTimer::singleShot(0, this, SLOT(lookForNewQtDocumentation())); else @@ -304,6 +316,7 @@ bool MainWindow::initHelpDB() hc.addCustomFilter(tr("Unfiltered"), QStringList()); hc.setCustomValue(unfiltered, 1); } + m_helpEngine->blockSignals(true); m_helpEngine->setCurrentFilter(tr("Unfiltered")); m_helpEngine->blockSignals(false); @@ -318,10 +331,10 @@ bool MainWindow::initHelpDB() void MainWindow::lookForNewQtDocumentation() { m_qtDocInstaller = new QtDocInstaller(m_helpEngine->collectionFile()); - connect(m_qtDocInstaller, SIGNAL(errorMessage(const QString&)), - this, SLOT(displayInstallationError(const QString&))); - connect(m_qtDocInstaller, SIGNAL(docsInstalled(bool)), - this, SLOT(qtDocumentationInstalled(bool))); + connect(m_qtDocInstaller, SIGNAL(errorMessage(QString)), this, + SLOT(displayInstallationError(QString))); + connect(m_qtDocInstaller, SIGNAL(docsInstalled(bool)), this, + SLOT(qtDocumentationInstalled(bool))); QString versionKey = QString(QLatin1String("qtVersion%1$$$qt")). arg(QLatin1String(QT_VERSION_STR)); @@ -353,8 +366,8 @@ void MainWindow::checkInitState() if (!m_connectedInitSignals) { connect(m_helpEngine->contentModel(), SIGNAL(contentsCreated()), this, SLOT(checkInitState())); - connect(m_helpEngine->indexModel(), SIGNAL(indexCreated()), - this, SLOT(checkInitState())); + connect(m_helpEngine->indexModel(), SIGNAL(indexCreated()), this, + SLOT(checkInitState())); m_connectedInitSignals = true; } } else { @@ -601,8 +614,8 @@ void MainWindow::setupFilterToolbar() connect(m_helpEngine, SIGNAL(setupFinished()), this, SLOT(setupFilterCombo())); - connect(m_filterCombo, SIGNAL(activated(const QString&)), this, - SLOT(filterDocumentation(const QString&))); + connect(m_filterCombo, SIGNAL(activated(QString)), this, + SLOT(filterDocumentation(QString))); setupFilterCombo(); } @@ -626,12 +639,12 @@ void MainWindow::setupAddressToolbar() toolBarMenu()->addAction(addressToolBar->toggleViewAction()); // address lineedit - connect(m_addressLineEdit, SIGNAL(returnPressed()), - this, SLOT(gotoAddress())); - connect(m_centralWidget, SIGNAL(currentViewerChanged()), - this, SLOT(showNewAddress())); - connect(m_centralWidget, SIGNAL(sourceChanged(const QUrl&)), - this, SLOT(showNewAddress(const QUrl&))); + connect(m_addressLineEdit, SIGNAL(returnPressed()), this, + SLOT(gotoAddress())); + connect(m_centralWidget, SIGNAL(currentViewerChanged()), this, + SLOT(showNewAddress())); + connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this, + SLOT(showNewAddress(QUrl))); } void MainWindow::updateAboutMenuText() @@ -712,10 +725,10 @@ void MainWindow::showPreferences() { PreferencesDialog dia(m_helpEngine, this); - connect(&dia, SIGNAL(updateApplicationFont()), - this, SLOT(updateApplicationFont())); - connect(&dia, SIGNAL(updateBrowserFont()), - m_centralWidget, SLOT(updateBrowserFont())); + connect(&dia, SIGNAL(updateApplicationFont()), this, + SLOT(updateApplicationFont())); + connect(&dia, SIGNAL(updateBrowserFont()), m_centralWidget, + SLOT(updateBrowserFont())); dia.showDialog(); } @@ -950,8 +963,7 @@ QWidget* MainWindow::setupBookmarkWidget() { m_bookmarkManager = new BookmarkManager(m_helpEngine); m_bookmarkWidget = new BookmarkWidget(m_bookmarkManager, this); - connect(m_bookmarkWidget, SIGNAL(addBookmark()), - this, SLOT(addBookmark())); + connect(m_bookmarkWidget, SIGNAL(addBookmark()), this, SLOT(addBookmark())); return m_bookmarkWidget; } diff --git a/tools/qdoc3/qdoc3.pro b/tools/qdoc3/qdoc3.pro index 3268585..2bba8fb 100644 --- a/tools/qdoc3/qdoc3.pro +++ b/tools/qdoc3/qdoc3.pro @@ -99,10 +99,3 @@ SOURCES += apigenerator.cpp \ webxmlgenerator.cpp \ yyindent.cpp - -win32 { - QT_WINCONFIG = release - CONFIG(debug, debug|release) { - QT_WINCONFIG = debug - } -} |