1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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)
|
---|
|
---|