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
This commit is contained in:
parent
32a979e7de
commit
775bbe63d9
@ -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)
|
||||
|
||||
|
214
private/qtjolie-branch/tests/visiondriver.cpp
Normal file
214
private/qtjolie-branch/tests/visiondriver.cpp
Normal file
@ -0,0 +1,214 @@
|
||||
/**
|
||||
* This file is part of the KDE project
|
||||
* Copyright (C) 2009 Kevin Ottens <ervin@kde.org>
|
||||
*
|
||||
* 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 <QtCore/QDebug>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QBoxLayout>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QTextBrowser>
|
||||
|
||||
#include <QtJolie/AbstractAdaptor>
|
||||
#include <QtJolie/Client>
|
||||
#include <QtJolie/Message>
|
||||
#include <QtJolie/Server>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#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(
|
||||
"<div>%1</div><br/><br/>"
|
||||
"<div align=\"center\"><h1>%2</h1></div><br/><br/>"
|
||||
).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"
|
115
private/qtjolie-branch/tests/visiondriverwidget.ui
Normal file
115
private/qtjolie-branch/tests/visiondriverwidget.ui
Normal file
@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VisionDriverWidget</class>
|
||||
<widget class="QWidget" name="VisionDriverWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>729</width>
|
||||
<height>396</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Vision Driver</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="previousButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Previous</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="visionHostname">
|
||||
<property name="text">
|
||||
<string notr="true">localhost</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="visionPort">
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>9001</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="connectButton">
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textContent"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="driverHostname">
|
||||
<property name="text">
|
||||
<string notr="true">localhost</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="driverPort">
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>9002</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="nextButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Next</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user