diff options
Diffstat (limited to 'examples/network/infoprotocol/infoclient')
-rw-r--r-- | examples/network/infoprotocol/infoclient/client.cpp | 120 | ||||
-rw-r--r-- | examples/network/infoprotocol/infoclient/client.h | 47 | ||||
-rw-r--r-- | examples/network/infoprotocol/infoclient/clientbase.ui | 276 | ||||
-rw-r--r-- | examples/network/infoprotocol/infoclient/infoclient.pro | 11 | ||||
-rw-r--r-- | examples/network/infoprotocol/infoclient/main.cpp | 21 |
5 files changed, 475 insertions, 0 deletions
diff --git a/examples/network/infoprotocol/infoclient/client.cpp b/examples/network/infoprotocol/infoclient/client.cpp new file mode 100644 index 000000000..24861ab55 --- /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 TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qsocket.h> +#include <qapplication.h> +#include <qtextedit.h> +#include <qlineedit.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include <qtextstream.h> +#include <qlistbox.h> + +#include "client.h" + + +ClientInfo::ClientInfo( TQWidget *parent, const char *name ) : + ClientInfoBase( parent, name ), socket( 0 ) +{ + edHost->setText( "localhost" ); + edPort->setText( TQString::number( (uint)infoPort ) ); + + connect( infoList, SIGNAL(selected(const TQString&)), SLOT(selectItem(const TQString&)) ); + connect( btnConnect, SIGNAL(clicked()), SLOT(connectToServer()) ); + connect( btnBack, SIGNAL(clicked()), SLOT(stepBack()) ); + connect( btnQuit, SIGNAL(clicked()), qApp, SLOT(tquit()) ); +} + + +void ClientInfo::connectToServer() +{ + delete socket; + socket = new TQSocket( 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 TQString& 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 TQString& location ) +{ + TQString line; + switch (op) { + case List: + infoList->clear(); + line = "LIST " + location; + break; + case Get: + line = "GET " + location; + break; + } + infoText->clear(); + TQTextStream os(socket); + os << line << "\r\n"; +} + +void ClientInfo::socketReadyRead() +{ + TQTextStream stream( socket ); + TQString 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 ) + TQString( ( 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 000000000..50a31bdad --- /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 TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef CLIENT_H +#define CLIENT_H + +#include "clientbase.h" + +class TQSocket; +class TQTextEdit; +class TQLineEdit; +class TQListBox; +class TQLabel; + +static const Q_UINT16 infoPort = 42417; + +class ClientInfo : public ClientInfoBase +{ + Q_OBJECT +public: + ClientInfo( TQWidget *parent = 0, const char *name = 0 ); + +private: + enum Operation { List, Get }; + +private slots: + void connectToServer(); + void selectItem( const TQString& item ); + void stepBack(); + void sendToServer( Operation op, const TQString& location ); + void socketConnected(); + void socketReadyRead(); + void socketConnectionClosed(); + void socketError( int code ); + +private: + TQSocket *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 000000000..6d5ea21d6 --- /dev/null +++ b/examples/network/infoprotocol/infoclient/clientbase.ui @@ -0,0 +1,276 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>ClientInfoBase</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>ClientInfoBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>384</width> + <height>488</height> + </rect> + </property> + <property name="caption"> + <string>Info Client</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>Layout15</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQPushButton"> + <property name="name"> + <cstring>btnConnect</cstring> + </property> + <property name="text"> + <string>&Connect</string> + </property> + </widget> + <widget class="TQLabel"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="text"> + <string>Host:</string> + </property> + </widget> + <widget class="TQLineEdit"> + <property name="name"> + <cstring>edHost</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="TQLabel"> + <property name="name"> + <cstring>TextLabel2_2</cstring> + </property> + <property name="text"> + <string>Port:</string> + </property> + </widget> + <widget class="TQLineEdit"> + <property name="name"> + <cstring>edPort</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="TQSplitter"> + <property name="name"> + <cstring>Splitter4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>Layout16</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>Layout14</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQPushButton"> + <property name="name"> + <cstring>btnBack</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Back</string> + </property> + <property name="toolTip" stdset="0"> + <string>go one step back</string> + </property> + </widget> + <widget class="TQLabel"> + <property name="name"> + <cstring>infoPath</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>/</string> + </property> + <property name="toolTip" stdset="0"> + <string>current path</string> + </property> + </widget> + </hbox> + </widget> + <widget class="TQListBox"> + <property name="name"> + <cstring>infoList</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>double click to open</string> + </property> + </widget> + </vbox> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>Layout3</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="TQLabel"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>Data:</string> + </property> + </widget> + <widget class="TQTextEdit"> + <property name="name"> + <cstring>infoText</cstring> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </vbox> + </widget> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>Layout12</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name" stdset="0"> + <cstring>Spacer10</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQPushButton"> + <property name="name"> + <cstring>btnQuit</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Quit</string> + </property> + </widget> + <spacer> + <property name="name" stdset="0"> + <cstring>Spacer9</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/examples/network/infoprotocol/infoclient/infoclient.pro b/examples/network/infoprotocol/infoclient/infoclient.pro new file mode 100644 index 000000000..46759dd23 --- /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 000000000..502026958 --- /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 TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qapplication.h> + +#include "client.h" + +int main( int argc, char** argv ) +{ + TQApplication app( argc, argv ); + ClientInfo info; + app.setMainWidget( &info ); + info.show(); + return app.exec(); +} |