summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriya Hidayat <ariya.hidayat@nokia.com>2009-04-23 12:13:35 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-04-23 13:36:07 (GMT)
commit2e8ece735d6a31f4657192e77b9dc53fb2a03e9c (patch)
treec6a32986881db8d446bf970fc4766218fc078863
parenteb48c652475a11d32e8ce5fd7d42cea827656f10 (diff)
downloadQt-2e8ece735d6a31f4657192e77b9dc53fb2a03e9c.zip
Qt-2e8ece735d6a31f4657192e77b9dc53fb2a03e9c.tar.gz
Qt-2e8ece735d6a31f4657192e77b9dc53fb2a03e9c.tar.bz2
Added Google Chat client as a new WebKit example
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
-rw-r--r--demos/qtdemo/xml/examples.xml1
-rw-r--r--doc/src/examples.qdoc1
-rw-r--r--doc/src/examples/googlechat.qdoc51
-rw-r--r--doc/src/images/googlechat-example.pngbin0 -> 52624 bytes
-rw-r--r--examples/webkit/googlechat/form.ui214
-rw-r--r--examples/webkit/googlechat/googlechat.cpp163
-rw-r--r--examples/webkit/googlechat/googlechat.h71
-rw-r--r--examples/webkit/googlechat/googlechat.pro11
-rw-r--r--examples/webkit/googlechat/main.cpp51
-rw-r--r--examples/webkit/webkit.pro3
10 files changed, 565 insertions, 1 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/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
new file mode 100644
index 0000000..0338445
--- /dev/null
+++ b/doc/src/images/googlechat-example.png
Binary files differ
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