src/qt3support/network/q3networkprotocol.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3Support module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef Q3NETWORKPROTOCOL_H
       
    43 #define Q3NETWORKPROTOCOL_H
       
    44 
       
    45 #include <QtCore/qstring.h>
       
    46 #include <QtCore/qobject.h>
       
    47 #include <Qt3Support/q3dict.h>
       
    48 #include <Qt3Support/q3valuelist.h>
       
    49 
       
    50 QT_BEGIN_HEADER
       
    51 
       
    52 QT_BEGIN_NAMESPACE
       
    53 
       
    54 QT_MODULE(Qt3SupportLight)
       
    55 
       
    56 #ifndef QT_NO_NETWORKPROTOCOL
       
    57 
       
    58 class Q3NetworkProtocol;
       
    59 class Q3NetworkOperation;
       
    60 class QTimer;
       
    61 class Q3UrlOperator;
       
    62 class Q3NetworkProtocolPrivate;
       
    63 class QUrlInfo;
       
    64 template <class T> class Q3ValueList;
       
    65 
       
    66 class Q_COMPAT_EXPORT Q3NetworkProtocolFactoryBase
       
    67 {
       
    68 public:
       
    69     virtual ~Q3NetworkProtocolFactoryBase() {}
       
    70     virtual Q3NetworkProtocol *createObject() = 0;
       
    71 };
       
    72 
       
    73 template< class T >
       
    74 class Q3NetworkProtocolFactory : public Q3NetworkProtocolFactoryBase
       
    75 {
       
    76 public:
       
    77     Q3NetworkProtocol *createObject() {
       
    78 	return new T;
       
    79     }
       
    80 
       
    81 };
       
    82 
       
    83 typedef Q3Dict< Q3NetworkProtocolFactoryBase > Q3NetworkProtocolDict;
       
    84 
       
    85 class Q_COMPAT_EXPORT Q3NetworkProtocol : public QObject
       
    86 {
       
    87     Q_OBJECT
       
    88 
       
    89 public:
       
    90     enum State {
       
    91 	StWaiting = 0,
       
    92 	StInProgress,
       
    93 	StDone,
       
    94 	StFailed,
       
    95 	StStopped
       
    96     };
       
    97 
       
    98     enum Operation {
       
    99 	OpListChildren = 1,
       
   100 	OpMkDir = 2,
       
   101 	OpMkdir = OpMkDir, // ### remove in 4.0
       
   102 	OpRemove = 4,
       
   103 	OpRename = 8,
       
   104 	OpGet = 32,
       
   105 	OpPut = 64
       
   106     };
       
   107 
       
   108     enum ConnectionState {
       
   109 	ConHostFound,
       
   110 	ConConnected,
       
   111 	ConClosed
       
   112     };
       
   113 
       
   114     enum Error {
       
   115 	// no error
       
   116 	NoError = 0,
       
   117 	// general errors
       
   118 	ErrValid,
       
   119 	ErrUnknownProtocol,
       
   120 	ErrUnsupported,
       
   121 	ErrParse,
       
   122 	// errors on connect
       
   123 	ErrLoginIncorrect,
       
   124 	ErrHostNotFound,
       
   125 	// protocol errors
       
   126 	ErrListChildren,
       
   127 	ErrListChlidren = ErrListChildren, // ### remove in 4.0
       
   128 	ErrMkDir,
       
   129 	ErrMkdir = ErrMkDir, // ### remove in 4.0
       
   130 	ErrRemove,
       
   131 	ErrRename,
       
   132 	ErrGet,
       
   133 	ErrPut,
       
   134 	ErrFileNotExisting,
       
   135 	ErrPermissionDenied
       
   136     };
       
   137 
       
   138     Q3NetworkProtocol();
       
   139     virtual ~Q3NetworkProtocol();
       
   140 
       
   141     virtual void setUrl( Q3UrlOperator *u );
       
   142 
       
   143     virtual void setAutoDelete( bool b, int i = 10000 );
       
   144     bool autoDelete() const;
       
   145 
       
   146     static void registerNetworkProtocol( const QString &protocol,
       
   147 					 Q3NetworkProtocolFactoryBase *protocolFactory );
       
   148     static Q3NetworkProtocol *getNetworkProtocol( const QString &protocol );
       
   149     static bool hasOnlyLocalFileSystem();
       
   150 
       
   151     virtual int supportedOperations() const;
       
   152     virtual void addOperation( Q3NetworkOperation *op );
       
   153 
       
   154     Q3UrlOperator *url() const;
       
   155     Q3NetworkOperation *operationInProgress() const;
       
   156     virtual void clearOperationQueue();
       
   157     virtual void stop();
       
   158 
       
   159 Q_SIGNALS:
       
   160     void data( const QByteArray &, Q3NetworkOperation *res );
       
   161     void connectionStateChanged( int state, const QString &data );
       
   162     void finished( Q3NetworkOperation *res );
       
   163     void start( Q3NetworkOperation *res );
       
   164     void newChildren( const Q3ValueList<QUrlInfo> &, Q3NetworkOperation *res );
       
   165     void newChild( const QUrlInfo &, Q3NetworkOperation *res );
       
   166     void createdDirectory( const QUrlInfo &, Q3NetworkOperation *res );
       
   167     void removed( Q3NetworkOperation *res );
       
   168     void itemChanged( Q3NetworkOperation *res );
       
   169     void dataTransferProgress( int bytesDone, int bytesTotal, Q3NetworkOperation *res );
       
   170 
       
   171 protected:
       
   172     virtual void processOperation( Q3NetworkOperation *op );
       
   173     virtual void operationListChildren( Q3NetworkOperation *op );
       
   174     virtual void operationMkDir( Q3NetworkOperation *op );
       
   175     virtual void operationRemove( Q3NetworkOperation *op );
       
   176     virtual void operationRename( Q3NetworkOperation *op );
       
   177     virtual void operationGet( Q3NetworkOperation *op );
       
   178     virtual void operationPut( Q3NetworkOperation *op );
       
   179     virtual void operationPutChunk( Q3NetworkOperation *op );
       
   180     virtual bool checkConnection( Q3NetworkOperation *op );
       
   181 
       
   182 private:
       
   183     Q3NetworkProtocolPrivate *d;
       
   184 
       
   185 private Q_SLOTS:
       
   186     void processNextOperation( Q3NetworkOperation *old );
       
   187     void startOps();
       
   188     void emitNewChildren( const QUrlInfo &i, Q3NetworkOperation *op );
       
   189 
       
   190     void removeMe();
       
   191 
       
   192 private:	// Disabled copy constructor and operator=
       
   193 #if defined(Q_DISABLE_COPY)
       
   194     Q3NetworkProtocol( const Q3NetworkProtocol & );
       
   195     Q3NetworkProtocol &operator=( const Q3NetworkProtocol & );
       
   196 #endif
       
   197 };
       
   198 
       
   199 class Q3NetworkOperationPrivate;
       
   200 
       
   201 class Q_COMPAT_EXPORT Q3NetworkOperation : public QObject
       
   202 {
       
   203     Q_OBJECT
       
   204     friend class Q3UrlOperator;
       
   205 
       
   206 public:
       
   207     Q3NetworkOperation( Q3NetworkProtocol::Operation operation,
       
   208 		    const QString &arg0, const QString &arg1,
       
   209 		    const QString &arg2 );
       
   210     Q3NetworkOperation( Q3NetworkProtocol::Operation operation,
       
   211 		    const QByteArray &arg0, const QByteArray &arg1,
       
   212 		    const QByteArray &arg2 );
       
   213     ~Q3NetworkOperation();
       
   214 
       
   215     void setState( Q3NetworkProtocol::State state );
       
   216     void setProtocolDetail( const QString &detail );
       
   217     void setErrorCode( int ec );
       
   218     void setArg( int num, const QString &arg );
       
   219     void setRawArg( int num, const QByteArray &arg );
       
   220 
       
   221     Q3NetworkProtocol::Operation operation() const;
       
   222     Q3NetworkProtocol::State state() const;
       
   223     QString arg( int num ) const;
       
   224     QByteArray rawArg( int num ) const;
       
   225     QString protocolDetail() const;
       
   226     int errorCode() const;
       
   227 
       
   228     void free();
       
   229 
       
   230 private Q_SLOTS:
       
   231     void deleteMe();
       
   232 
       
   233 private:
       
   234     QByteArray &raw( int num ) const;
       
   235     Q3NetworkOperationPrivate *d;
       
   236 
       
   237 private:	// Disabled copy constructor and operator=
       
   238 #if defined(Q_DISABLE_COPY)
       
   239     Q3NetworkOperation( const Q3NetworkOperation & );
       
   240     Q3NetworkOperation &operator=( const Q3NetworkOperation & );
       
   241 #endif
       
   242 };
       
   243 
       
   244 #endif // QT_NO_NETWORKPROTOCOL
       
   245 
       
   246 QT_END_NAMESPACE
       
   247 
       
   248 QT_END_HEADER
       
   249 
       
   250 #endif // Q3NETWORKPROTOCOL_H