slaveinterface.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 2000 David Faure <faure@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef __kio_slaveinterface_h 00021 #define __kio_slaveinterface_h 00022 00023 #include <unistd.h> 00024 #include <sys/types.h> 00025 00026 #include <tqobject.h> 00027 00028 #include <kurl.h> 00029 #include <kio/global.h> 00030 #include <kio/authinfo.h> 00031 #include <kdatastream.h> 00032 00033 namespace KIO { 00034 00035 class Connection; 00036 // better there is one ... 00037 class SlaveInterfacePrivate; 00038 00039 // Definition of enum Command has been moved to global.h 00040 00044 enum Info { 00045 INF_TOTAL_SIZE = 10, 00046 INF_PROCESSED_SIZE = 11, 00047 INF_SPEED, 00048 INF_REDIRECTION = 20, 00049 INF_MIME_TYPE = 21, 00050 INF_ERROR_PAGE = 22, 00051 INF_WARNING = 23, 00052 INF_GETTING_FILE, // Deprecated 00053 INF_NEED_PASSWD = 25, 00054 INF_INFOMESSAGE, 00055 INF_META_DATA, 00056 INF_NETWORK_STATUS, 00057 INF_MESSAGEBOX 00058 // add new ones here once a release is done, to avoid breaking binary compatibility 00059 }; 00060 00064 enum Message { 00065 MSG_DATA = 100, 00066 MSG_DATA_REQ, 00067 MSG_ERROR, 00068 MSG_CONNECTED, 00069 MSG_FINISHED, 00070 MSG_STAT_ENTRY, 00071 MSG_LIST_ENTRIES, 00072 MSG_RENAMED, // unused 00073 MSG_RESUME, 00074 MSG_SLAVE_STATUS, 00075 MSG_SLAVE_ACK, 00076 MSG_NET_REQUEST, 00077 MSG_NET_DROP, 00078 MSG_NEED_SUBURL_DATA, 00079 MSG_CANRESUME, 00080 MSG_AUTH_KEY, // deprecated. 00081 MSG_DEL_AUTH_KEY // deprecated. 00082 // add new ones here once a release is done, to avoid breaking binary compatibility 00083 }; 00084 00092 class KIO_EXPORT SlaveInterface : public TQObject 00093 { 00094 Q_OBJECT 00095 00096 public: 00097 SlaveInterface( Connection *connection ); 00098 virtual ~SlaveInterface(); 00099 00100 void setConnection( Connection* connection ) { m_pConnection = connection; } 00101 Connection *connection() const { return m_pConnection; } 00102 00103 void setProgressId( int id ) { m_progressId = id; } 00104 int progressId() const { return m_progressId; } 00105 00109 void sendResumeAnswer( bool resume ); 00110 00111 void setOffset( KIO::filesize_t offset ); 00112 KIO::filesize_t offset() const; 00113 00114 signals: 00116 // Messages sent by the slave 00118 00119 void data( const TQByteArray & ); 00120 void dataReq( ); 00121 void error( int , const TQString & ); 00122 void connected(); 00123 void finished(); 00124 void slaveStatus(pid_t, const TQCString &, const TQString &, bool); 00125 void listEntries( const KIO::UDSEntryList& ); 00126 void statEntry( const KIO::UDSEntry& ); 00127 void needSubURLData(); 00128 void needProgressId(); 00129 00130 void canResume( KIO::filesize_t ) ; 00131 00133 // Info sent by the slave 00135 void metaData( const KIO::MetaData & ); 00136 void totalSize( KIO::filesize_t ) ; 00137 void processedSize( KIO::filesize_t ) ; 00138 void redirection( const KURL& ) ; 00139 00140 void speed( unsigned long ) ; 00141 void errorPage() ; 00142 void mimeType( const TQString & ) ; 00143 void warning( const TQString & ) ; 00144 void infoMessage( const TQString & ) ; 00145 void connectFinished(); 00146 00150 void authorizationKey( const TQCString&, const TQCString&, bool ); 00151 00155 void delAuthorization( const TQCString& grpkey ); 00156 00157 protected: 00159 // Dispatching 00161 00162 virtual bool dispatch(); 00163 virtual bool dispatch( int _cmd, const TQByteArray &data ); 00164 00204 void openPassDlg( KIO::AuthInfo& info ); 00205 00209 void openPassDlg( const TQString& prompt, const TQString& user, 00210 const TQString& caption, const TQString& comment, 00211 const TQString& label, bool readOnly ) KDE_DEPRECATED; 00212 00216 void openPassDlg( const TQString& prompt, const TQString& user, bool readOnly ) KDE_DEPRECATED; 00217 00218 void messageBox( int type, const TQString &text, const TQString &caption, 00219 const TQString &buttonYes, const TQString &buttonNo ); 00220 00224 void messageBox( int type, const TQString &text, const TQString &caption, 00225 const TQString &buttonYes, const TQString &buttonNo, const TQString &dontAskAgainName ); 00226 00227 // I need to identify the slaves 00228 void requestNetwork( const TQString &, const TQString &); 00229 void dropNetwork( const TQString &, const TQString &); 00230 00235 static void sigpipe_handler(int); 00236 00237 protected slots: 00238 void calcSpeed(); 00239 00240 protected: 00241 Connection * m_pConnection; 00242 00243 private: 00244 int m_progressId; 00245 protected: 00246 virtual void virtual_hook( int id, void* data ); 00247 private: 00248 SlaveInterfacePrivate *d; 00249 }; 00250 00251 } 00252 00253 inline TQDataStream &operator >>(TQDataStream &s, KIO::UDSAtom &a ) 00254 { 00255 TQ_INT32 l; 00256 s >> a.m_uds; 00257 00258 if ( a.m_uds & KIO::UDS_LONG ) { 00259 s >> l; 00260 a.m_long = l; 00261 a.m_str = TQString::null; 00262 } else if ( a.m_uds & KIO::UDS_STRING ) { 00263 s >> a.m_str; 00264 a.m_long = 0; 00265 } else {} // DIE! 00266 // assert( 0 ); 00267 00268 return s; 00269 } 00270 00271 inline TQDataStream &operator <<(TQDataStream &s, const KIO::UDSAtom &a ) 00272 { 00273 s << a.m_uds; 00274 00275 if ( a.m_uds & KIO::UDS_LONG ) 00276 s << (TQ_INT32) a.m_long; 00277 else if ( a.m_uds & KIO::UDS_STRING ) 00278 s << a.m_str; 00279 else {} // DIE! 00280 // assert( 0 ); 00281 00282 return s; 00283 } 00284 00285 KIO_EXPORT TQDataStream &operator <<(TQDataStream &s, const KIO::UDSEntry &e ); 00286 KIO_EXPORT TQDataStream &operator >>(TQDataStream &s, KIO::UDSEntry &e ); 00287 00288 #endif