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/network.html | 150 +++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) (limited to 'doc/html/network.html') diff --git a/doc/html/network.html b/doc/html/network.html index 5d395af9c..c7bd4013b 100644 --- a/doc/html/network.html +++ b/doc/html/network.html @@ -53,34 +53,34 @@ body { background: #ffffff; color: black; }

The network module offers classes to make network programming easier and portable. Essentially, there are three sets of classes, first low -level classes like TQSocket, TQServerSocket, TQDns, etc. which +level classes like TQSocket, TQServerSocket, TQDns, etc. which allow you to work in a portable way with TCP/IP sockets. In addition, -there are classes like TQNetworkProtocol, TQNetworkOperation in +there are classes like TQNetworkProtocol, TQNetworkOperation in the TQt base library, which provide an abstract layer for implementing -network protocols and TQUrlOperator which operates on such network +network protocols and TQUrlOperator which operates on such network protocols. Finally the third set of network classes are the passive -ones, specifically TQUrl and TQUrlInfo which do URL parsing and +ones, specifically TQUrl and TQUrlInfo which do URL parsing and similar. -

The first set of classes (TQSocket, TQServerSocket, TQDns, TQFtp, etc.) are included in TQt's "network" module. -

The TQSocket classes are not directly related to the TQNetwork classes, +

The first set of classes (TQSocket, TQServerSocket, TQDns, TQFtp, etc.) are included in TQt's "network" module. +

The TQSocket classes are not directly related to the TQNetwork classes, but TQSocket should and will be used for implementing network protocols, which are directly related to the TQNetwork classes. For -example, the TQFtp class (which implements the FTP protocol) uses +example, the TQFtp class (which implements the FTP protocol) uses TQSockets. But TQSockets don't need to be used for protocol -implementations, e.g. TQLocalFs (which is an implementation of the -local filesystem as network protocol) uses TQDir and doesn't use +implementations, e.g. TQLocalFs (which is an implementation of the +local filesystem as network protocol) uses TQDir and doesn't use TQSocket. Using TQNetworkProtocols you can implement everything which fits into a hierarchical structure and can be accessed using URLs. This could be, for example, a protocol which can read pictures from a digital camera using a serial connection. -

Working Network Protocol independently with TQUrlOperator and TQNetworkOperation +

Working Network Protocol independently with TQUrlOperator and TQNetworkOperation

It is quite easy to just use existing network protocol implementations and operate on URLs. For example, downloading a file from an FTP server to the local filesystem can be done with following code:

-    TQUrlOperator op;
-    op.copy( "ftp://ftp.trolltech.com/qt/source/qt-2.1.0.tar.gz", "file:/tmp", FALSE );
+    TQUrlOperator op;
+    op.copy( "ftp://ftp.trolltech.com/qt/source/qt-2.1.0.tar.gz", "file:/tmp", FALSE );
 

And that's all! Of course an implementation of the FTP protocol has to @@ -90,11 +90,11 @@ later. renaming, etc. For example, to create a folder on a private FTP account do

-    TQUrlOperator op( "ftp://username:password@host.domain.no/home/username" );
-    op.mkdir( "New Directory" );
+    TQUrlOperator op( "ftp://username:password@host.domain.no/home/username" );
+    op.mkdir( "New Directory" );
 
-

To see all available operations, look at the TQUrlOperator class +

To see all available operations, look at the TQUrlOperator class documentation.

Since networking works asynchronously, the function call for an operation will normally return before the operation has been @@ -105,12 +105,12 @@ all the information about the operation.

For example, TQNetworkOperation has a method which returns the state of this operation. Using this you can find out the state of the operation at any time. The object also makes available the arguments -you passed to the TQUrlOperator method, the type of the operation +you passed to the TQUrlOperator method, the type of the operation and some more information. For more details see the class documentation of TQNetworkOperation. -

The TQUrlOperator emits signals to inform you about the progress of -the operations. As you can call many methods which operate on a TQUrlOperator's URL, it queues up all the operations. So you can't know -which operation the TQUrlOperator just processed. Clearly you will +

The TQUrlOperator emits signals to inform you about the progress of +the operations. As you can call many methods which operate on a TQUrlOperator's URL, it queues up all the operations. So you can't know +which operation the TQUrlOperator just processed. Clearly you will want to know which operation just took place, so each signal's last argument is a pointer to the TQNetworkOperation object which was just processed and which caused the signal to be emitted. @@ -119,8 +119,8 @@ this makes sense), and some of them send some signals during processing. All operations send a finished() signal after they are done. To find that out if an operation finished successfully you can use the TQNetworkOperation pointer you got with the finished() -signal. If TQNetworkOperation::state() equals TQNetworkProtocol::StDone the operation finished successfully, if it is -TQNetworkProtocol::StFailed the operation failed. +signal. If TQNetworkOperation::state() equals TQNetworkProtocol::StDone the operation finished successfully, if it is +TQNetworkProtocol::StFailed the operation failed.

Example: A slot which you might connect to the TQUrlOperator::finished( TQNetworkOperation * )

@@ -129,9 +129,9 @@ void MyClass::slotOperationFinished( TQNetworkO
     switch ( op->operation() ) {
     case TQNetworkProtocol::OpMkDir: 
         if ( op->state() == TQNetworkProtocol::StFailed )
-            qDebug( "Couldn't create directory %s", op->arg( 0 ).latin1() );
+            qDebug( "Couldn't create directory %s", op->arg( 0 ).latin1() );
         else
-            qDebug( "Successfully created directory %s", op->arg( 0 ).latin1() );
+            qDebug( "Successfully created directory %s", op->arg( 0 ).latin1() );
         break;
     // ... and so on
     }
@@ -144,49 +144,49 @@ on a FTP server):
 

 TQUrlOperator op;
 
-MyClass::MyClass() : TQObject(), op( "ftp://ftp.trolltech.com" )
+MyClass::MyClass() : TQObject(), op( "ftp://ftp.trolltech.com" )
 {
-    connect( &op, SIGNAL( newChildren( const TQValueList<TQUrlInfo> &, TQNetworkOperation * ) ),
-             this, SLOT( slotInsertEntries( const TQValueList<TQUrlInfo> &, TQNetworkOperation * ) ) );
+    connect( &op, SIGNAL( newChildren( const TQValueList<TQUrlInfo> &, TQNetworkOperation * ) ),
+             this, SLOT( slotInsertEntries( const TQValueList<TQUrlInfo> &, TQNetworkOperation * ) ) );
     connect( &op, SIGNAL( start( TQNetworkOperation * ) ),
              this, SLOT( slotStart( TQNetworkOperation *) ) );
     connect( &op, SIGNAL( finished( TQNetworkOperation * ) ),
              this, SLOT( slotFinished( TQNetworkOperation *) ) );
 }
 
-void MyClass::slotInsertEntries( const TQValueList<TQUrlInfo> &info, TQNetworkOperation * )
+void MyClass::slotInsertEntries( const TQValueList<TQUrlInfo> &info, TQNetworkOperation * )
 {
-    TQValueList<TQUrlInfo>::ConstIterator it = info.begin();
-    for ( ; it != info.end(); ++it ) {
-        const TQUrlInfo &inf = *it;
-        qDebug( "Name: %s, Size: %d, Last Modified: %s",
-            inf.name().latin1(), inf.size(), inf.lastModified().toString().latin1() );
+    TQValueList<TQUrlInfo>::ConstIterator it = info.begin();
+    for ( ; it != info.end(); ++it ) {
+        const TQUrlInfo &inf = *it;
+        qDebug( "Name: %s, Size: %d, Last Modified: %s",
+            inf.name().latin1(), inf.size(), inf.lastModified().toString().latin1() );
     }
 }
 
 void MyClass::slotStart( TQNetworkOperation * )
 {
-    qDebug( "Start reading '%s'", op.toString().latin1() );
+    qDebug( "Start reading '%s'", op.toString().latin1() );
 }
 
 void MyClass::slotFinished( TQNetworkOperation *operation )
 {
     if ( operation->operation() == TQNetworkProtocol::OpListChildren ) {
         if ( operation->state() == TQNetworkProtocol::StFailed )
-            qDebug( "Couldn't read '%s'! Following error occurred: %s",
+            qDebug( "Couldn't read '%s'! Following error occurred: %s",
                 op.toString().latin1(), operation->protocolDetail().latin1() );
         else
-            qDebug( "Finished reading '%s'!", op.toString().latin1() );
+            qDebug( "Finished reading '%s'!", op.toString().latin1() );
     }
 }
 
 
-

These examples demonstrate now how to use the TQUrlOperator and TQNetworkOperations. The network extension also contains useful example +

These examples demonstrate now how to use the TQUrlOperator and TQNetworkOperations. The network extension also contains useful example code.

Implementing your own Network Protocol

-

TQNetworkProtocol provides a base class for implementations +

TQNetworkProtocol provides a base class for implementations of network protocols and an architecture for the a dynamic registration and de-registration of network protocols. If you use this architecture you don't need to care about asynchronous programming, as @@ -199,7 +199,7 @@ hierarchical structure and accessed via URLs, can be implemented as network protocol and easily used in TQt. This is not limited to filesystems only!

To implement a network protocol create a class derived from -TQNetworkProtocol. +TQNetworkProtocol.

Other classes will use this network protocol implementation to operate on it. So you should reimplement following protected members

@@ -214,9 +214,9 @@ to operate on it. So you should reimplement following protected members
 

Some notes on reimplementing these methods: You always get a pointer to a TQNetworkOperation as argument. This pointer holds all the information about the operation in the current state. If you start -processing such an operation, set the state to TQNetworkProtocol::StInProgress. If you finished processing the -operation, set the state to TQNetworkProtocol::StDone if it was -successful or TQNetworkProtocol::StFailed if an error occurred. If +processing such an operation, set the state to TQNetworkProtocol::StInProgress. If you finished processing the +operation, set the state to TQNetworkProtocol::StDone if it was +successful or TQNetworkProtocol::StFailed if an error occurred. If an error occurred you must set an error code (see TQNetworkOperation::setErrorCode()) and if you know some details (e.g. an error message) you can also set this message to the operation @@ -269,10 +269,10 @@ to the user.

And remember, always emit the finished() signal at the end! -

For more details about these signals' arguments look at the TQNetworkProtocol class documentation. +

For more details about these signals' arguments look at the TQNetworkProtocol class documentation.

Here is a list of which TQNetworkOperation arguments you can get and which you must set in which function: -

(To get the URL on which you should work, use the TQNetworkProtocol::url() method which returns a pointer to the URL +

(To get the URL on which you should work, use the TQNetworkProtocol::url() method which returns a pointer to the URL operator. Using that you can get the path, host, name filter, etc.)

-

That's all. The connection to the TQUrlOperator and so on is done +

That's all. The connection to the TQUrlOperator and so on is done automatically. Additionally, if the error was really bad so that no more operations can be done in the current state (e.g. if the host couldn't be found), call TQNetworkProtocol::clearOperationStack() before emitting finished(). -

Ideally you should use one of the predefined error codes of TQNetworkProtocol. If this is not possible, you can add own error codes +

Ideally you should use one of the predefined error codes of TQNetworkProtocol. If this is not possible, you can add own error codes - they are just normal ints. Just be careful that the value of the error code doesn't conflict with an existing one.

An example to look at is in qt/examples/network/ftpclient. This is the implementation of a fairly complete FTP client, which supports uploading and downloading files, making directories, etc., all done using TQUrlOperators. -

You might also like to look at TQFtp (in qt/src/network/qftp.cpp) or at +

You might also like to look at TQFtp (in qt/src/network/qftp.cpp) or at the example in qt/examples/network/networkprotocol/nntp.cpp.

-- cgit v1.2.3