source: trunk/include/qnetworkprotocol.h@ 114

Last change on this file since 114 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1/****************************************************************************
2** $Id: qnetworkprotocol.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of QNetworkProtocol class
5**
6** Created : 950429
7**
8** Copyright (C) 1992-2000 Trolltech AS. 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 AS 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
50class QNetworkProtocol;
51class QNetworkOperation;
52class QTimer;
53class QUrlOperator;
54class QNetworkProtocolPrivate;
55template <class T> class QValueList;
56
57class Q_EXPORT QNetworkProtocolFactoryBase
58{
59public:
60 virtual QNetworkProtocol *createObject() = 0;
61
62};
63
64template< class Protocol >
65class QNetworkProtocolFactory : public QNetworkProtocolFactoryBase
66{
67public:
68 QNetworkProtocol *createObject() {
69 return new Protocol;
70 }
71
72};
73
74typedef QDict< QNetworkProtocolFactoryBase > QNetworkProtocolDict;
75
76class Q_EXPORT QNetworkProtocol : public QObject
77{
78 Q_OBJECT
79
80public:
81 enum State {
82 StWaiting = 0,
83 StInProgress,
84 StDone,
85 StFailed,
86 StStopped
87 };
88
89 enum Operation {
90 OpListChildren = 1,
91 OpMkDir = 2,
92 OpMkdir = OpMkDir, // ### remove in 4.0
93 OpRemove = 4,
94 OpRename = 8,
95 OpGet = 32,
96 OpPut = 64
97 };
98
99 enum ConnectionState {
100 ConHostFound,
101 ConConnected,
102 ConClosed
103 };
104
105 enum Error {
106 // no error
107 NoError = 0,
108 // general errors
109 ErrValid,
110 ErrUnknownProtocol,
111 ErrUnsupported,
112 ErrParse,
113 // errors on connect
114 ErrLoginIncorrect,
115 ErrHostNotFound,
116 // protocol errors
117 ErrListChildren,
118 ErrListChlidren = ErrListChildren, // ### remove in 4.0
119 ErrMkDir,
120 ErrMkdir = ErrMkDir, // ### remove in 4.0
121 ErrRemove,
122 ErrRename,
123 ErrGet,
124 ErrPut,
125 ErrFileNotExisting,
126 ErrPermissionDenied
127 };
128
129 QNetworkProtocol();
130 virtual ~QNetworkProtocol();
131
132 virtual void setUrl( QUrlOperator *u );
133
134 virtual void setAutoDelete( bool b, int i = 10000 );
135 bool autoDelete() const;
136
137 static void registerNetworkProtocol( const QString &protocol,
138 QNetworkProtocolFactoryBase *protocolFactory );
139 static QNetworkProtocol *getNetworkProtocol( const QString &protocol );
140 static bool hasOnlyLocalFileSystem();
141
142 virtual int supportedOperations() const;
143 virtual void addOperation( QNetworkOperation *op );
144
145 QUrlOperator *url() const;
146 QNetworkOperation *operationInProgress() const;
147 virtual void clearOperationQueue();
148 virtual void stop();
149
150signals:
151 void data( const QByteArray &, QNetworkOperation *res );
152 void connectionStateChanged( int state, const QString &data );
153 void finished( QNetworkOperation *res );
154 void start( QNetworkOperation *res );
155 void newChildren( const QValueList<QUrlInfo> &, QNetworkOperation *res );
156 void newChild( const QUrlInfo &, QNetworkOperation *res );
157 void createdDirectory( const QUrlInfo &, QNetworkOperation *res );
158 void removed( QNetworkOperation *res );
159 void itemChanged( QNetworkOperation *res );
160 void dataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation *res );
161
162protected:
163 virtual void processOperation( QNetworkOperation *op );
164 virtual void operationListChildren( QNetworkOperation *op );
165 virtual void operationMkDir( QNetworkOperation *op );
166 virtual void operationRemove( QNetworkOperation *op );
167 virtual void operationRename( QNetworkOperation *op );
168 virtual void operationGet( QNetworkOperation *op );
169 virtual void operationPut( QNetworkOperation *op );
170 virtual void operationPutChunk( QNetworkOperation *op );
171 virtual bool checkConnection( QNetworkOperation *op );
172
173private:
174 QNetworkProtocolPrivate *d;
175
176private slots:
177 void processNextOperation( QNetworkOperation *old );
178 void startOps();
179 void emitNewChildren( const QUrlInfo &i, QNetworkOperation *op );
180
181 void removeMe();
182
183private: // Disabled copy constructor and operator=
184#if defined(Q_DISABLE_COPY)
185 QNetworkProtocol( const QNetworkProtocol & );
186 QNetworkProtocol &operator=( const QNetworkProtocol & );
187#endif
188};
189
190class QNetworkOperationPrivate;
191
192class Q_EXPORT QNetworkOperation : public QObject
193{
194 Q_OBJECT
195 friend class QUrlOperator;
196
197public:
198 QNetworkOperation( QNetworkProtocol::Operation operation,
199 const QString &arg0, const QString &arg1,
200 const QString &arg2 );
201 QNetworkOperation( QNetworkProtocol::Operation operation,
202 const QByteArray &arg0, const QByteArray &arg1,
203 const QByteArray &arg2 );
204 ~QNetworkOperation();
205
206 void setState( QNetworkProtocol::State state );
207 void setProtocolDetail( const QString &detail );
208 void setErrorCode( int ec );
209 void setArg( int num, const QString &arg );
210 void setRawArg( int num, const QByteArray &arg );
211
212 QNetworkProtocol::Operation operation() const;
213 QNetworkProtocol::State state() const;
214 QString arg( int num ) const;
215 QByteArray rawArg( int num ) const;
216 QString protocolDetail() const;
217 int errorCode() const;
218
219 void free();
220
221private slots:
222 void deleteMe();
223
224private:
225 QByteArray &raw( int num ) const;
226 QNetworkOperationPrivate *d;
227
228private: // Disabled copy constructor and operator=
229#if defined(Q_DISABLE_COPY)
230 QNetworkOperation( const QNetworkOperation & );
231 QNetworkOperation &operator=( const QNetworkOperation & );
232#endif
233};
234
235#endif // QT_NO_NETWORKPROTOCOL
236
237#endif // QNETWORKPROTOCOL_H
Note: See TracBrowser for help on using the repository browser.