From 775bbe63d946ce2bc2bc384244e8868b624fd7fe Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 1 Jul 2009 20:36:01 +0000 Subject: [PATCH] Add a small control app for the Vision proof of concept provided with JOLIE. Suitable for use on handhelds. svn path=/branches/work/~ervin/qtjolie/; revision=990152 --- private/qtjolie-branch/tests/CMakeLists.txt | 9 + private/qtjolie-branch/tests/visiondriver.cpp | 214 ++++++++++++++++++ .../tests/visiondriverwidget.ui | 115 ++++++++++ 3 files changed, 338 insertions(+) create mode 100644 private/qtjolie-branch/tests/visiondriver.cpp create mode 100644 private/qtjolie-branch/tests/visiondriverwidget.ui diff --git a/private/qtjolie-branch/tests/CMakeLists.txt b/private/qtjolie-branch/tests/CMakeLists.txt index 940bcaed9..a15babe42 100644 --- a/private/qtjolie-branch/tests/CMakeLists.txt +++ b/private/qtjolie-branch/tests/CMakeLists.txt @@ -28,3 +28,12 @@ SODEP_EXECUTABLE_TESTS( calculatorservice trivialyahooclient ) + +set(visiondriver_SRCS + visiondriver.cpp +) +kde4_add_ui_files(visiondriver_SRCS visiondriverwidget.ui) + +kde4_add_executable(visiondriver ${visiondriver_SRCS}) +target_link_libraries(visiondriver ${KDE4_KDEUI_LIBS} ${QT_QTNETWORK_LIBRARY} QtJolie) + diff --git a/private/qtjolie-branch/tests/visiondriver.cpp b/private/qtjolie-branch/tests/visiondriver.cpp new file mode 100644 index 000000000..dfec19244 --- /dev/null +++ b/private/qtjolie-branch/tests/visiondriver.cpp @@ -0,0 +1,214 @@ +/** + * This file is part of the KDE project + * Copyright (C) 2009 Kevin Ottens + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "ui_visiondriverwidget.h" + +using namespace Jolie; + +class MainWindow; + +class PresenterAdaptor : public AbstractAdaptor +{ + Q_OBJECT +public: + PresenterAdaptor(MainWindow *parent); + +private: + Message relay(Server *server, const Message &message); + + MainWindow *m_window; +}; + +class MainWindow : public QWidget +{ + Q_OBJECT +public: + MainWindow() + : m_client(0), m_server(0), m_sessionId(-1) + { + ui.setupUi(this); + + m_server = new Server(9002); + PresenterAdaptor *adaptor = new PresenterAdaptor(this); + m_server->registerAdaptor("/", adaptor); + sleep(2); + + connect(ui.connectButton, SIGNAL(clicked()), SLOT(onConnect())); + connect(ui.previousButton, SIGNAL(clicked()), SLOT(onPrevious())); + connect(ui.nextButton, SIGNAL(clicked()), SLOT(onNext())); + } + + ~MainWindow() + { + if (m_sessionId>=0) { + Message m("/", "closeClientSession"); + m.setData(Value(m_sessionId)); + m_client->callNoReply(m); + sleep(2); + } + + delete m_client; + delete m_server; + } + + void pageChanged(int pageNumber) + { + qDebug() << "New page is:" << pageNumber; + m_currentPage = pageNumber; + updateTextContent(); + } + + void documentChanged(const QString &url) + { + qDebug() << "New document is:" << url; + m_currentDocument = url; + updateTextContent(); + } + +private slots: + void onConnect() + { + if (m_sessionId>=0) { + Message m("/", "closeClientSession"); + m.setData(Value(m_sessionId)); + m_client->callNoReply(m); + sleep(2); + } + + m_sessionId = -1; + delete m_client; + + m_client = new Client(ui.visionHostname->text(), + ui.visionPort->value()); + + QString location = QString::fromUtf8("socket://%1:%2") + .arg(ui.driverHostname->text()) + .arg(ui.driverPort->value()); + Value data; + data.children("location") << Value(location.toUtf8()); + + Message request("/", "startClientSession"); + request.setData(data); + Message reply = m_client->call(request); + + data = reply.data(); + m_sessionId = data.children("sid").first().toInt(); + qDebug() << "Got session ID:" << m_sessionId; + } + + void onPrevious() + { + requestNewPage(m_currentPage-1); + } + + void onNext() + { + requestNewPage(m_currentPage+1); + } + +private: + void updateTextContent() + { + ui.textContent->setHtml( + QString::fromUtf8( + "
%1


" + "

%2



" + ).arg(m_currentDocument).arg(m_currentPage) + ); + } + + void requestNewPage(int page) + { + Value data; + data.children("pageNumber") << Value(page); + data.children("local") << Value(0); + + Message request("/", "goToPage"); + request.setData(data); + m_client->call(request); + } + + Ui::VisionDriverWidget ui; + Client *m_client; + Server *m_server; + int m_sessionId; + + int m_currentPage; + QString m_currentDocument; +}; + +PresenterAdaptor::PresenterAdaptor(MainWindow *parent) + : AbstractAdaptor(parent), m_window(parent) +{ +} + +Message PresenterAdaptor::relay(Server *server, const Message &message) +{ + if ((message.resourcePath()=="/") && (message.operationName()=="goToPage")) { + int pageNumber = 0; + if (message.data().isValid()) { + pageNumber = message.data().toInt(); + } else { + pageNumber = message.data().children("pageNumber").first().toInt(); + } + + m_window->pageChanged(pageNumber); + } else if ((message.resourcePath()=="/") && (message.operationName()=="openDocument")) { + QString url; + if (message.data().isValid()) { + url = QString::fromUtf8(message.data().toByteArray()); + } else { + url = QString::fromUtf8(message.data().children("documentUrl").first().toByteArray()); + } + m_window->documentChanged(url); + } else { + qDebug() << "Got an unknown message:" << message.resourcePath() + << message.operationName(); + } + + return Message(); +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + MainWindow w; + w.show(); + + return app.exec(); +} + +#include "visiondriver.moc" diff --git a/private/qtjolie-branch/tests/visiondriverwidget.ui b/private/qtjolie-branch/tests/visiondriverwidget.ui new file mode 100644 index 000000000..b151777ce --- /dev/null +++ b/private/qtjolie-branch/tests/visiondriverwidget.ui @@ -0,0 +1,115 @@ + + + VisionDriverWidget + + + + 0 + 0 + 729 + 396 + + + + Vision Driver + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + Previous + + + + + + + + + + + localhost + + + + + + + 65535 + + + 9001 + + + + + + + Connect + + + + + + + + + + + + + + localhost + + + + + + + 65535 + + + 9002 + + + + + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + Next + + + + + + + +