1 /**************************************************************************** 2 ** $Id: qt/qnetworkprotocol.h 3.3.8 edited Jan 11 14:38 $ 3 ** 4 ** Definition of QNetworkProtocol class 5 ** 6 ** Created : 950429 7 ** 8 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 9 ** 10 ** This file is part of the kernel module of the Qt GUI Toolkit. 11 ** 12 ** This file may be distributed under the terms of the Q Public License 13 ** as defined by Trolltech ASA of Norway and appearing in the file 14 ** LICENSE.QPL included in the packaging of this file. 15 ** 16 ** This file may be distributed and/or modified under the terms of the 17 ** GNU General Public License version 2 as published by the Free Software 18 ** Foundation and appearing in the file LICENSE.GPL included in the 19 ** packaging of this file. 20 ** 21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 22 ** licenses may use this file in accordance with the Qt Commercial License 23 ** Agreement provided with the Software. 24 ** 25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 27 ** 28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 29 ** information about Qt Commercial License Agreements. 30 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 31 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 32 ** 33 ** Contact info@trolltech.com if any conditions of this licensing are 34 ** not clear to you. 35 ** 36 **********************************************************************/ 37 38 #ifndef QNETWORKPROTOCOL_H 39 #define QNETWORKPROTOCOL_H 40 41 #ifndef QT_H 42 #include "qurlinfo.h" 43 #include "qstring.h" 44 #include "qdict.h" 45 #include "qobject.h" 46 #endif // QT_H 47 48 #ifndef QT_NO_NETWORKPROTOCOL 49 50 #if __GNUC__ - 0 > 3 51 #pragma GCC system_header 52 #endif 53 54 class QNetworkProtocol; 55 class QNetworkOperation; 56 class QTimer; 57 class QUrlOperator; 58 class QNetworkProtocolPrivate; 59 template <class T> class QValueList; 60 61 class Q_EXPORT QNetworkProtocolFactoryBase 62 { 63 public: 64 virtual QNetworkProtocol *createObject() = 0; 65 66 }; 67 68 template< class T > 69 class QNetworkProtocolFactory : public QNetworkProtocolFactoryBase 70 { 71 public: createObject()72 QNetworkProtocol *createObject() { 73 return new T; 74 } 75 76 }; 77 78 typedef QDict< QNetworkProtocolFactoryBase > QNetworkProtocolDict; 79 80 class Q_EXPORT QNetworkProtocol : public QObject 81 { 82 Q_OBJECT 83 84 public: 85 enum State { 86 StWaiting = 0, 87 StInProgress, 88 StDone, 89 StFailed, 90 StStopped 91 }; 92 93 enum Operation { 94 OpListChildren = 1, 95 OpMkDir = 2, 96 OpMkdir = OpMkDir, // ### remove in 4.0 97 OpRemove = 4, 98 OpRename = 8, 99 OpGet = 32, 100 OpPut = 64 101 }; 102 103 enum ConnectionState { 104 ConHostFound, 105 ConConnected, 106 ConClosed 107 }; 108 109 enum Error { 110 // no error 111 NoError = 0, 112 // general errors 113 ErrValid, 114 ErrUnknownProtocol, 115 ErrUnsupported, 116 ErrParse, 117 // errors on connect 118 ErrLoginIncorrect, 119 ErrHostNotFound, 120 // protocol errors 121 ErrListChildren, 122 ErrListChlidren = ErrListChildren, // ### remove in 4.0 123 ErrMkDir, 124 ErrMkdir = ErrMkDir, // ### remove in 4.0 125 ErrRemove, 126 ErrRename, 127 ErrGet, 128 ErrPut, 129 ErrFileNotExisting, 130 ErrPermissionDenied 131 }; 132 133 QNetworkProtocol(); 134 virtual ~QNetworkProtocol(); 135 136 virtual void setUrl( QUrlOperator *u ); 137 138 virtual void setAutoDelete( bool b, int i = 10000 ); 139 bool autoDelete() const; 140 141 static void registerNetworkProtocol( const QString &protocol, 142 QNetworkProtocolFactoryBase *protocolFactory ); 143 static QNetworkProtocol *getNetworkProtocol( const QString &protocol ); 144 static bool hasOnlyLocalFileSystem(); 145 146 virtual int supportedOperations() const; 147 virtual void addOperation( QNetworkOperation *op ); 148 149 QUrlOperator *url() const; 150 QNetworkOperation *operationInProgress() const; 151 virtual void clearOperationQueue(); 152 virtual void stop(); 153 154 signals: 155 void data( const QByteArray &, QNetworkOperation *res ); 156 void connectionStateChanged( int state, const QString &data ); 157 void finished( QNetworkOperation *res ); 158 void start( QNetworkOperation *res ); 159 void newChildren( const QValueList<QUrlInfo> &, QNetworkOperation *res ); 160 void newChild( const QUrlInfo &, QNetworkOperation *res ); 161 void createdDirectory( const QUrlInfo &, QNetworkOperation *res ); 162 void removed( QNetworkOperation *res ); 163 void itemChanged( QNetworkOperation *res ); 164 void dataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation *res ); 165 166 protected: 167 virtual void processOperation( QNetworkOperation *op ); 168 virtual void operationListChildren( QNetworkOperation *op ); 169 virtual void operationMkDir( QNetworkOperation *op ); 170 virtual void operationRemove( QNetworkOperation *op ); 171 virtual void operationRename( QNetworkOperation *op ); 172 virtual void operationGet( QNetworkOperation *op ); 173 virtual void operationPut( QNetworkOperation *op ); 174 virtual void operationPutChunk( QNetworkOperation *op ); 175 virtual bool checkConnection( QNetworkOperation *op ); 176 177 private: 178 QNetworkProtocolPrivate *d; 179 180 private slots: 181 void processNextOperation( QNetworkOperation *old ); 182 void startOps(); 183 void emitNewChildren( const QUrlInfo &i, QNetworkOperation *op ); 184 185 void removeMe(); 186 187 private: // Disabled copy constructor and operator= 188 #if defined(Q_DISABLE_COPY) 189 QNetworkProtocol( const QNetworkProtocol & ); 190 QNetworkProtocol &operator=( const QNetworkProtocol & ); 191 #endif 192 }; 193 194 class QNetworkOperationPrivate; 195 196 class Q_EXPORT QNetworkOperation : public QObject 197 { 198 Q_OBJECT 199 friend class QUrlOperator; 200 201 public: 202 QNetworkOperation( QNetworkProtocol::Operation operation, 203 const QString &arg0, const QString &arg1, 204 const QString &arg2 ); 205 QNetworkOperation( QNetworkProtocol::Operation operation, 206 const QByteArray &arg0, const QByteArray &arg1, 207 const QByteArray &arg2 ); 208 ~QNetworkOperation(); 209 210 void setState( QNetworkProtocol::State state ); 211 void setProtocolDetail( const QString &detail ); 212 void setErrorCode( int ec ); 213 void setArg( int num, const QString &arg ); 214 void setRawArg( int num, const QByteArray &arg ); 215 216 QNetworkProtocol::Operation operation() const; 217 QNetworkProtocol::State state() const; 218 QString arg( int num ) const; 219 QByteArray rawArg( int num ) const; 220 QString protocolDetail() const; 221 int errorCode() const; 222 223 void free(); 224 225 private slots: 226 void deleteMe(); 227 228 private: 229 QByteArray &raw( int num ) const; 230 QNetworkOperationPrivate *d; 231 232 private: // Disabled copy constructor and operator= 233 #if defined(Q_DISABLE_COPY) 234 QNetworkOperation( const QNetworkOperation & ); 235 QNetworkOperation &operator=( const QNetworkOperation & ); 236 #endif 237 }; 238 239 #endif // QT_NO_NETWORKPROTOCOL 240 241 #endif // QNETWORKPROTOCOL_H 242