From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- .../network/infoprotocol/infoclient/client.cpp | 120 +++++++++ examples/network/infoprotocol/infoclient/client.h | 47 ++++ .../network/infoprotocol/infoclient/clientbase.ui | 276 +++++++++++++++++++++ .../network/infoprotocol/infoclient/infoclient.pro | 11 + examples/network/infoprotocol/infoclient/main.cpp | 21 ++ 5 files changed, 475 insertions(+) create mode 100644 examples/network/infoprotocol/infoclient/client.cpp create mode 100644 examples/network/infoprotocol/infoclient/client.h create mode 100644 examples/network/infoprotocol/infoclient/clientbase.ui create mode 100644 examples/network/infoprotocol/infoclient/infoclient.pro create mode 100644 examples/network/infoprotocol/infoclient/main.cpp (limited to 'examples/network/infoprotocol/infoclient') diff --git a/examples/network/infoprotocol/infoclient/client.cpp b/examples/network/infoprotocol/infoclient/client.cpp new file mode 100644 index 0000000..89bcfd2 --- /dev/null +++ b/examples/network/infoprotocol/infoclient/client.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "client.h" + + +ClientInfo::ClientInfo( QWidget *parent, const char *name ) : + ClientInfoBase( parent, name ), socket( 0 ) +{ + edHost->setText( "localhost" ); + edPort->setText( QString::number( (uint)infoPort ) ); + + connect( infoList, SIGNAL(selected(const QString&)), SLOT(selectItem(const QString&)) ); + connect( btnConnect, SIGNAL(clicked()), SLOT(connectToServer()) ); + connect( btnBack, SIGNAL(clicked()), SLOT(stepBack()) ); + connect( btnQuit, SIGNAL(clicked()), qApp, SLOT(quit()) ); +} + + +void ClientInfo::connectToServer() +{ + delete socket; + socket = new QSocket( this ); + connect( socket, SIGNAL(connected()), SLOT(socketConnected()) ); + connect( socket, SIGNAL(connectionClosed()), SLOT(socketConnectionClosed()) ); + connect( socket, SIGNAL(readyRead()), SLOT(socketReadyRead()) ); + connect( socket, SIGNAL(error(int)), SLOT(socketError(int)) ); + + socket->connectToHost( edHost->text(), edPort->text().toInt() ); +} + +void ClientInfo::selectItem( const QString& item ) +{ + // item in listBox selected, use LIST or GET depending of the node type. + if ( item.endsWith( "/" ) ) { + sendToServer( List, infoPath->text() + item ); + infoPath->setText( infoPath->text() + item ); + } else + sendToServer( Get, infoPath->text() + item ); +} + +void ClientInfo::stepBack() +{ + // go back (up) in path hierarchy + int i = infoPath->text().findRev( '/', -2 ); + if ( i > 0 ) + infoPath->setText( infoPath->text().left( i + 1 ) ); + else + infoPath->setText( "/" ); + infoList->clear(); + sendToServer( List, infoPath->text() ); +} + + +void ClientInfo::socketConnected() +{ + sendToServer( List, "/" ); +} + +void ClientInfo::sendToServer( Operation op, const QString& location ) +{ + QString line; + switch (op) { + case List: + infoList->clear(); + line = "LIST " + location; + break; + case Get: + line = "GET " + location; + break; + } + infoText->clear(); + QTextStream os(socket); + os << line << "\r\n"; +} + +void ClientInfo::socketReadyRead() +{ + QTextStream stream( socket ); + QString line; + while ( socket->canReadLine() ) { + line = stream.readLine(); + if ( line.startsWith( "500" ) || line.startsWith( "550" ) ) { + infoText->append( tr( "error: " ) + line.mid( 4 ) ); + } else if ( line.startsWith( "212+" ) ) { + infoList->insertItem( line.mid( 6 ) + QString( ( line[ 4 ] == 'D' ) ? "/" : "" ) ); + } else if ( line.startsWith( "213+" ) ) { + infoText->append( line.mid( 4 ) ); + } + } +} + + +void ClientInfo::socketConnectionClosed() +{ + infoText->clear(); + infoText->append( tr( "error: Connection closed by the server\n" ) ); +} + +void ClientInfo::socketError( int code ) +{ + infoText->clear(); + infoText->append( tr( "error: Error number %1 occurred\n" ).arg( code ) ); +} + diff --git a/examples/network/infoprotocol/infoclient/client.h b/examples/network/infoprotocol/infoclient/client.h new file mode 100644 index 0000000..a3e09af --- /dev/null +++ b/examples/network/infoprotocol/infoclient/client.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef CLIENT_H +#define CLIENT_H + +#include "clientbase.h" + +class QSocket; +class QTextEdit; +class QLineEdit; +class QListBox; +class QLabel; + +static const Q_UINT16 infoPort = 42417; + +class ClientInfo : public ClientInfoBase +{ + Q_OBJECT +public: + ClientInfo( QWidget *parent = 0, const char *name = 0 ); + +private: + enum Operation { List, Get }; + +private slots: + void connectToServer(); + void selectItem( const QString& item ); + void stepBack(); + void sendToServer( Operation op, const QString& location ); + void socketConnected(); + void socketReadyRead(); + void socketConnectionClosed(); + void socketError( int code ); + +private: + QSocket *socket; +}; + +#endif // CLIENT_H + diff --git a/examples/network/infoprotocol/infoclient/clientbase.ui b/examples/network/infoprotocol/infoclient/clientbase.ui new file mode 100644 index 0000000..3f73c9a --- /dev/null +++ b/examples/network/infoprotocol/infoclient/clientbase.ui @@ -0,0 +1,276 @@ + +ClientInfoBase + + + ClientInfoBase + + + + 0 + 0 + 384 + 488 + + + + Info Client + + + + unnamed + + + 11 + + + 6 + + + + Layout15 + + + + unnamed + + + 0 + + + 6 + + + + btnConnect + + + &Connect + + + + + TextLabel1 + + + Host: + + + + + edHost + + + + 7 + 0 + 1 + 0 + + + + + + + + + TextLabel2_2 + + + Port: + + + + + edPort + + + + + + + Splitter4 + + + Vertical + + + + Layout16 + + + + unnamed + + + 0 + + + 6 + + + + Layout14 + + + + unnamed + + + 0 + + + 6 + + + + btnBack + + + + 1 + 0 + 0 + 0 + + + + &Back + + + go one step back + + + + + infoPath + + + + 3 + 5 + 0 + 0 + + + + / + + + current path + + + + + + + infoList + + + double click to open + + + + + + + Layout3 + + + + unnamed + + + 0 + + + 6 + + + + TextLabel2 + + + Data: + + + + + infoText + + + true + + + + + + + + Layout12 + + + + unnamed + + + 0 + + + 6 + + + + Spacer10 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + btnQuit + + + + 3 + 0 + 0 + 0 + + + + &Quit + + + + + Spacer9 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + + + + diff --git a/examples/network/infoprotocol/infoclient/infoclient.pro b/examples/network/infoprotocol/infoclient/infoclient.pro new file mode 100644 index 0000000..46759dd --- /dev/null +++ b/examples/network/infoprotocol/infoclient/infoclient.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = infoclient + +CONFIG += qt warn_on release + +REQUIRES = network full-config nocrosscompiler + +HEADERS = client.h +SOURCES = main.cpp \ + client.cpp +INTERFACES = clientbase.ui diff --git a/examples/network/infoprotocol/infoclient/main.cpp b/examples/network/infoprotocol/infoclient/main.cpp new file mode 100644 index 0000000..cc4950a --- /dev/null +++ b/examples/network/infoprotocol/infoclient/main.cpp @@ -0,0 +1,21 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include + +#include "client.h" + +int main( int argc, char** argv ) +{ + QApplication app( argc, argv ); + ClientInfo info; + app.setMainWidget( &info ); + info.show(); + return app.exec(); +} -- cgit v1.2.1