2009-02-07 17:27:29 +01:00
|
|
|
/**
|
|
|
|
* This file is part of the KDE project
|
|
|
|
* Copyright (C) 2008 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/QBuffer>
|
2012-02-02 10:35:53 +01:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
2009-02-07 17:27:29 +01:00
|
|
|
#include <QtNetwork/QTcpSocket>
|
|
|
|
|
2009-04-25 16:06:25 +02:00
|
|
|
#include <QtJolie/Message>
|
|
|
|
#include <QtJolie/Value>
|
|
|
|
#include "../qtjolie/sodephelpers_p.h"
|
2009-02-07 17:27:29 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
using namespace Jolie;
|
|
|
|
|
2009-02-07 17:27:29 +01:00
|
|
|
class MainWindow : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
MainWindow()
|
|
|
|
{
|
|
|
|
setLayout(new QHBoxLayout());
|
|
|
|
m_lineEdit = new QLineEdit(this);
|
|
|
|
layout()->addWidget(m_lineEdit);
|
|
|
|
|
|
|
|
QPushButton *button = new QPushButton(this);
|
2009-05-30 10:44:34 +02:00
|
|
|
button->setText(QString::fromUtf8("SEND"));
|
2009-02-07 17:27:29 +01:00
|
|
|
layout()->addWidget(button);
|
|
|
|
connect(button, SIGNAL(clicked()),
|
|
|
|
this, SLOT(sendMessage()));
|
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
m_socket.connectToHost(QString::fromUtf8("localhost"), 10000);
|
2009-02-07 17:27:29 +01:00
|
|
|
if (!m_socket.waitForConnected(10000)) {
|
|
|
|
qDebug("Failed to connect!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qDebug("Connected!");
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void sendMessage()
|
|
|
|
{
|
2009-04-25 15:50:35 +02:00
|
|
|
Message message("/", "printInput");
|
2009-05-30 10:44:34 +02:00
|
|
|
message.setData(Value(m_lineEdit->text().toUtf8()));
|
2009-02-08 16:35:56 +01:00
|
|
|
sodepWrite(m_socket, message);
|
2009-02-07 17:27:29 +01:00
|
|
|
|
|
|
|
qDebug("Message sent:");
|
|
|
|
QBuffer buffer;
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
2009-02-08 16:35:56 +01:00
|
|
|
sodepWrite(buffer, message);
|
2009-02-07 17:27:29 +01:00
|
|
|
buffer.close();
|
2009-05-30 10:44:34 +02:00
|
|
|
qDebug("%s", buffer.data().toHex().constData());
|
2009-02-07 17:27:29 +01:00
|
|
|
|
|
|
|
qDebug("Message received:");
|
|
|
|
buffer.setData(QByteArray());
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
2009-02-08 16:35:56 +01:00
|
|
|
message = sodepReadMessage(m_socket);
|
|
|
|
sodepWrite(buffer, message);
|
2009-02-07 17:27:29 +01:00
|
|
|
buffer.close();
|
2009-05-30 10:44:34 +02:00
|
|
|
qDebug("%s", buffer.data().toHex().constData());
|
2009-02-07 17:27:29 +01:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
QLineEdit *m_lineEdit;
|
|
|
|
QTcpSocket m_socket;
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
MainWindow w;
|
|
|
|
w.show();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "testprinter.moc"
|