plasma-framework/private/qtjolie-branch/tests/sodepprintertest.cpp
Kevin Ottens d712c2d2c9 Qt implementation of SODEP.
svn path=/branches/work/~ervin/sodep/; revision=806026
2008-05-09 21:11:35 +00:00

85 lines
2.3 KiB
C++

/**
* 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>
#include <QtGui/QApplication>
#include <QtGui/QBoxLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtNetwork/QTcpSocket>
#include <sodepmessage.h>
#include <sodepvalue.h>
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);
button->setText("SEND");
layout()->addWidget(button);
connect(button, SIGNAL(clicked()),
this, SLOT(sendMessage()));
m_socket.connectToHost("localhost", 10000);
if (!m_socket.waitForConnected(10000)) {
qDebug("Failed to connect!");
return;
}
qDebug("Connected!");
}
private slots:
void sendMessage()
{
SodepMessage message("/", "printInput");
message.setData(SodepValue(m_lineEdit->text()));
message.writeTo(m_socket);
qDebug("Message sent:");
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
message.writeTo(buffer);
buffer.close();
qDebug(buffer.data().toHex());
}
private:
QLineEdit *m_lineEdit;
QTcpSocket m_socket;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}
#include "sodepprintertest.moc"