From ea318d1431c89e647598c510c4245c6571aa5f46 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 26 Jan 2012 23:32:43 -0600 Subject: Update to latest tqt3 automated conversion --- doc/html/networkprotocol-example.html | 164 +++++++++++++++++----------------- 1 file changed, 82 insertions(+), 82 deletions(-) (limited to 'doc/html/networkprotocol-example.html') diff --git a/doc/html/networkprotocol-example.html b/doc/html/networkprotocol-example.html index 97473a376..087225691 100644 --- a/doc/html/networkprotocol-example.html +++ b/doc/html/networkprotocol-example.html @@ -33,7 +33,7 @@ body { background: #ffffff; color: black; }

-

This example shows how to implement your own TQNetworkProtocol. The +

This example shows how to implement your own TQNetworkProtocol. The protocol that was chosen for this example is NTTP. Please note that this implementation is very simple since it is designed to be an example. It should not be used as a real NNTP implemention. @@ -52,10 +52,10 @@ should not be used as a real NNTP implemention. #ifndef NNTP_H #define NNTP_H -#include <qsocket.h> -#include <qnetworkprotocol.h> +#include <ntqsocket.h> +#include <ntqnetworkprotocol.h> -class Nntp : public TQNetworkProtocol +class Nntp : public TQNetworkProtocol { Q_OBJECT @@ -68,7 +68,7 @@ protected: virtual void operationListChildren( TQNetworkOperation *op ); virtual void operationGet( TQNetworkOperation *op ); - TQSocket *commandSocket; + TQSocket *commandSocket; bool connectionReady; bool readGroups; bool readArticle; @@ -104,27 +104,27 @@ protected slots: *****************************************************************************/ #include "nntp.h" -#include <qurlinfo.h> +#include <ntqurlinfo.h> #include <stdlib.h> -#include <qurloperator.h> -#include <qstringlist.h> -#include <qregexp.h> +#include <ntqurloperator.h> +#include <ntqstringlist.h> +#include <ntqregexp.h> Nntp::Nntp() - : TQNetworkProtocol(), connectionReady( FALSE ), + : TQNetworkProtocol(), connectionReady( FALSE ), readGroups( FALSE ), readArticle( FALSE ) { // create the command socket and connect to its signals - commandSocket = new TQSocket( this ); - connect( commandSocket, SIGNAL( hostFound() ), + commandSocket = new TQSocket( this ); + connect( commandSocket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) ); - connect( commandSocket, SIGNAL( connected() ), + connect( commandSocket, SIGNAL( connected() ), this, SLOT( connected() ) ); - connect( commandSocket, SIGNAL( connectionClosed() ), + connect( commandSocket, SIGNAL( connectionClosed() ), this, SLOT( closed() ) ); - connect( commandSocket, SIGNAL( readyRead() ), + connect( commandSocket, SIGNAL( readyRead() ), this, SLOT( readyRead() ) ); - connect( commandSocket, SIGNAL( error( int ) ), + connect( commandSocket, SIGNAL( error( int ) ), this, SLOT( error( int ) ) ); } @@ -134,77 +134,77 @@ Nntp::~Nntp() delete commandSocket; } -void Nntp::operationListChildren( TQNetworkOperation * ) +void Nntp::operationListChildren( TQNetworkOperation * ) { // create a command - TQString path = url()->path(), cmd; - if ( path.isEmpty() || path == "/" ) { + TQString path = url()->path(), cmd; + if ( path.isEmpty() || path == "/" ) { // if the path is empty or we are in the root dir, // we want to read the list of available newsgroups cmd = "list newsgroups\r\n"; - } else if ( url()->isDir() ) { + } else if ( url()->isDir() ) { // if the path is a directory (in our case a news group) // we want to list the articles of this group - path = path.replace( "/", "" ); + path = path.replace( "/", "" ); cmd = "listgroup " + path + "\r\n"; } else return; // write the command to the socket - commandSocket->writeBlock( cmd.latin1(), cmd.length() ); + commandSocket->writeBlock( cmd.latin1(), cmd.length() ); readGroups = TRUE; } -void Nntp::operationGet( TQNetworkOperation *op ) +void Nntp::operationGet( TQNetworkOperation *op ) { // get the dirPath of the URL (this is our news group) // and the filename (which is the article we want to read) - TQUrl u( op->arg( 0 ) ); - TQString dirPath = u.dirPath(), file = u.fileName(); - dirPath = dirPath.replace( "/", "" ); + TQUrl u( op->arg( 0 ) ); + TQString dirPath = u.dirPath(), file = u.fileName(); + dirPath = dirPath.replace( "/", "" ); // go to the group in which the article is - TQString cmd; + TQString cmd; cmd = "group " + dirPath + "\r\n"; - commandSocket->writeBlock( cmd.latin1(), cmd.length() ); + commandSocket->writeBlock( cmd.latin1(), cmd.length() ); // read the head of the article cmd = "article " + file + "\r\n"; - commandSocket->writeBlock( cmd.latin1(), cmd.length() ); + commandSocket->writeBlock( cmd.latin1(), cmd.length() ); readArticle = TRUE; } -bool Nntp::checkConnection( TQNetworkOperation * ) +bool Nntp::checkConnection( TQNetworkOperation * ) { // we are connected, return TRUE - if ( commandSocket->isOpen() && connectionReady ) + if ( commandSocket->isOpen() && connectionReady ) return TRUE; // seems that there is no chance to connect - if ( commandSocket->isOpen() ) + if ( commandSocket->isOpen() ) return FALSE; // don't call connectToHost() if we are already trying to connect - if ( commandSocket->state() == TQSocket::Connecting ) + if ( commandSocket->state() == TQSocket::Connecting ) return FALSE; // start connecting connectionReady = FALSE; - commandSocket->connectToHost( url()->host(), - url()->port() != -1 ? url()->port() : 119 ); + commandSocket->connectToHost( url()->host(), + url()->port() != -1 ? url()->port() : 119 ); return FALSE; } void Nntp::close() { // close the command socket - if ( commandSocket->isOpen() ) { - commandSocket->writeBlock( "quit\r\n", strlen( "quit\r\n" ) ); - commandSocket->close(); + if ( commandSocket->isOpen() ) { + commandSocket->writeBlock( "quit\r\n", strlen( "quit\r\n" ) ); + commandSocket->close(); } } -int Nntp::supportedOperations() const +int Nntp::supportedOperations() const { // we only support listing children and getting data return OpListChildren | OpGet; @@ -212,24 +212,24 @@ void Nntp::close() void Nntp::hostFound() { - if ( url() ) - emit connectionStateChanged( ConHostFound, tr( "Host %1 found" ).arg( url()->host() ) ); + if ( url() ) + emit connectionStateChanged( ConHostFound, tr( "Host %1 found" ).arg( url()->host() ) ); else emit connectionStateChanged( ConHostFound, tr( "Host found" ) ); } void Nntp::connected() { - if ( url() ) - emit connectionStateChanged( ConConnected, tr( "Connected to host %1" ).arg( url()->host() ) ); + if ( url() ) + emit connectionStateChanged( ConConnected, tr( "Connected to host %1" ).arg( url()->host() ) ); else emit connectionStateChanged( ConConnected, tr( "Connected to host" ) ); } void Nntp::closed() { - if ( url() ) - emit connectionStateChanged( ConClosed, tr( "Connection to %1 closed" ).arg( url()->host() ) ); + if ( url() ) + emit connectionStateChanged( ConClosed, tr( "Connection to %1 closed" ).arg( url()->host() ) ); else emit connectionStateChanged( ConClosed, tr( "Connection closed" ) ); } @@ -251,58 +251,58 @@ void Nntp::readyRead() } // read the new data from the socket - TQCString s; - s.resize( commandSocket->bytesAvailable() + 1 ); - commandSocket->readBlock( s.data(), commandSocket->bytesAvailable() ); + TQCString s; + s.resize( commandSocket->bytesAvailable() + 1 ); + commandSocket->readBlock( s.data(), commandSocket->bytesAvailable() ); if ( !url() ) return; // of the code of the server response was 200, we know that the // server is ready to get commands from us now - if ( s.left( 3 ) == "200" ) + if ( s.left( 3 ) == "200" ) connectionReady = TRUE; } void Nntp::parseGroups() { - if ( !commandSocket->canReadLine() ) + if ( !commandSocket->canReadLine() ) return; // read one line after the other - while ( commandSocket->canReadLine() ) { - TQString s = commandSocket->readLine(); + while ( commandSocket->canReadLine() ) { + TQString s = commandSocket->readLine(); // if the line starts with a dot, all groups or articles have been listed, // so we finished processing the listChildren() command if ( s[ 0 ] == '.' ) { readGroups = FALSE; - operationInProgress()->setState( StDone ); - emit finished( operationInProgress() ); + operationInProgress()->setState( StDone ); + emit finished( operationInProgress() ); return; } // if the code of the server response is 215 or 211 // the next line will be the first group or article (depending on what we read). // So let others know that we start reading now... - if ( s.left( 3 ) == "215" || s.left( 3 ) == "211" ) { - operationInProgress()->setState( StInProgress ); - emit start( operationInProgress() ); + if ( s.left( 3 ) == "215" || s.left( 3 ) == "211" ) { + operationInProgress()->setState( StInProgress ); + emit start( operationInProgress() ); continue; } // parse the line and create a TQUrlInfo object // which describes the child (group or article) - bool tab = s.find( '\t' ) != -1; - TQString group = s.mid( 0, s.find( tab ? '\t' : ' ' ) ); - TQUrlInfo inf; - inf.setName( group ); - TQString path = url()->path(); - inf.setDir( path.isEmpty() || path == "/" ); - inf.setSymLink( FALSE ); - inf.setFile( !inf.isDir() ); - inf.setWritable( FALSE ); - inf.setReadable( TRUE ); + bool tab = s.find( '\t' ) != -1; + TQString group = s.mid( 0, s.find( tab ? '\t' : ' ' ) ); + TQUrlInfo inf; + inf.setName( group ); + TQString path = url()->path(); + inf.setDir( path.isEmpty() || path == "/" ); + inf.setSymLink( FALSE ); + inf.setFile( !inf.isDir() ); + inf.setWritable( FALSE ); + inf.setReadable( TRUE ); // let others know about our new child emit newChild( inf, operationInProgress() ); @@ -312,26 +312,26 @@ void Nntp::parseGroups() void Nntp::parseArticle() { - if ( !commandSocket->canReadLine() ) + if ( !commandSocket->canReadLine() ) return; // read an article one line after the other - while ( commandSocket->canReadLine() ) { - TQString s = commandSocket->readLine(); + while ( commandSocket->canReadLine() ) { + TQString s = commandSocket->readLine(); // if the line starts with a dot, we finished reading something if ( s[ 0 ] == '.' ) { readArticle = FALSE; - operationInProgress()->setState( StDone ); - emit finished( operationInProgress() ); + operationInProgress()->setState( StDone ); + emit finished( operationInProgress() ); return; } - if ( s.right( 1 ) == "\n" ) - s.remove( s.length() - 1, 1 ); + if ( s.right( 1 ) == "\n" ) + s.remove( s.length() - 1, 1 ); // emit the new data of the article which we read - emit data( TQCString( s.ascii() ), operationInProgress() ); + emit data( TQCString( s.ascii() ), operationInProgress() ); } } @@ -340,13 +340,13 @@ void Nntp::error( int code ) if ( code == TQSocket::ErrHostNotFound || code == TQSocket::ErrConnectionRefused ) { // this signal is called if connecting to the server failed - if ( operationInProgress() ) { - TQString msg = tr( "Host not found or couldn't connect to: \n" + url()->host() ); - operationInProgress()->setState( StFailed ); - operationInProgress()->setProtocolDetail( msg ); - operationInProgress()->setErrorCode( (int)ErrHostNotFound ); - clearOperationQueue(); - emit finished( operationInProgress() ); + if ( operationInProgress() ) { + TQString msg = tr( "Host not found or couldn't connect to: \n" + url()->host() ); + operationInProgress()->setState( StFailed ); + operationInProgress()->setProtocolDetail( msg ); + operationInProgress()->setErrorCode( (int)ErrHostNotFound ); + clearOperationQueue(); + emit finished( operationInProgress() ); } } } -- cgit v1.2.1