TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slaveinterface.h 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* This file is part of the KDE project
  2. Copyright (C) 2000 David Faure <faure@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef __tdeio_slaveinterface_h
  17. #define __tdeio_slaveinterface_h
  18. #include <unistd.h>
  19. #include <sys/types.h>
  20. #include <tqobject.h>
  21. #include <kurl.h>
  22. #include <tdeio/global.h>
  23. #include <tdeio/authinfo.h>
  24. #include <kdatastream.h>
  25. namespace TDEIO {
  26. class Connection;
  27. // better there is one ...
  28. class SlaveInterfacePrivate;
  29. // Definition of enum Command has been moved to global.h
  30. /**
  31. * Identifiers for KIO informational messages.
  32. */
  33. enum Info {
  34. INF_TOTAL_SIZE = 10,
  35. INF_PROCESSED_SIZE = 11,
  36. INF_SPEED,
  37. INF_REDIRECTION = 20,
  38. INF_MIME_TYPE = 21,
  39. INF_ERROR_PAGE = 22,
  40. INF_WARNING = 23,
  41. INF_GETTING_FILE, // Deprecated
  42. INF_NEED_PASSWD = 25,
  43. INF_INFOMESSAGE,
  44. INF_META_DATA,
  45. INF_NETWORK_STATUS,
  46. INF_MESSAGEBOX,
  47. INF_LOCALURL
  48. // add new ones here once a release is done, to avoid breaking binary compatibility
  49. };
  50. /**
  51. * Identifiers for KIO data messages.
  52. */
  53. enum Message {
  54. MSG_DATA = 100,
  55. MSG_DATA_REQ,
  56. MSG_ERROR,
  57. MSG_CONNECTED,
  58. MSG_FINISHED,
  59. MSG_STAT_ENTRY,
  60. MSG_LIST_ENTRIES,
  61. MSG_RENAMED, // unused
  62. MSG_RESUME,
  63. MSG_SLAVE_STATUS,
  64. MSG_SLAVE_ACK,
  65. MSG_NET_REQUEST,
  66. MSG_NET_DROP,
  67. MSG_NEED_SUBURL_DATA,
  68. MSG_CANRESUME,
  69. MSG_AUTH_KEY, // deprecated.
  70. MSG_DEL_AUTH_KEY // deprecated.
  71. // add new ones here once a release is done, to avoid breaking binary compatibility
  72. };
  73. /**
  74. * There are two classes that specifies the protocol between application
  75. * (TDEIO::Job) and tdeioslave. SlaveInterface is the class to use on the application
  76. * end, SlaveBase is the one to use on the slave end.
  77. *
  78. * A call to foo() results in a call to slotFoo() on the other end.
  79. */
  80. class TDEIO_EXPORT SlaveInterface : public TQObject
  81. {
  82. Q_OBJECT
  83. public:
  84. SlaveInterface( Connection *connection );
  85. virtual ~SlaveInterface();
  86. void setConnection( Connection* connection ) { m_pConnection = connection; }
  87. Connection *connection() const { return m_pConnection; }
  88. void setProgressId( int id ) { m_progressId = id; }
  89. int progressId() const { return m_progressId; }
  90. /** Send our answer to the MSG_RESUME (canResume) request
  91. * (to tell the "put" job whether to resume or not)
  92. */
  93. void sendResumeAnswer( bool resume );
  94. void setOffset( TDEIO::filesize_t offset );
  95. TDEIO::filesize_t offset() const;
  96. signals:
  97. ///////////
  98. // Messages sent by the slave
  99. ///////////
  100. void data( const TQByteArray & );
  101. void dataReq( );
  102. void error( int , const TQString & );
  103. void connected();
  104. void finished();
  105. void slaveStatus(pid_t, const TQCString &, const TQString &, bool);
  106. void listEntries( const TDEIO::UDSEntryList& );
  107. void statEntry( const TDEIO::UDSEntry& );
  108. void needSubURLData();
  109. void needProgressId();
  110. void canResume( TDEIO::filesize_t ) ;
  111. ///////////
  112. // Info sent by the slave
  113. //////////
  114. void metaData( const TDEIO::MetaData & );
  115. void totalSize( TDEIO::filesize_t ) ;
  116. void processedSize( TDEIO::filesize_t ) ;
  117. void redirection( const KURL& ) ;
  118. void localURL( const KURL&, bool ) ;
  119. void speed( unsigned long ) ;
  120. void errorPage() ;
  121. void mimeType( const TQString & ) ;
  122. void warning( const TQString & ) ;
  123. void infoMessage( const TQString & ) ;
  124. void connectFinished();
  125. /**
  126. * @deprecated. Obsolete as of 3.1. Replaced by kpassword, a kded module.
  127. */
  128. void authorizationKey( const TQCString&, const TQCString&, bool );
  129. /**
  130. * @deprecated. Obsolete as of 3.1. Replaced by kpassword, a kded module.
  131. */
  132. void delAuthorization( const TQCString& grpkey );
  133. protected:
  134. /////////////////
  135. // Dispatching
  136. ////////////////
  137. virtual bool dispatch();
  138. virtual bool dispatch( int _cmd, const TQByteArray &data );
  139. /**
  140. * Prompt the user for authrization info (login & password).
  141. *
  142. * Use this function to request authorization info from the
  143. * the end user. For example to open an empty password dialog
  144. * using default values:
  145. *
  146. * \code
  147. * TDEIO::AuthInfo authInfo;
  148. * bool result = openPassDlg( authInfo );
  149. * if ( result )
  150. * {
  151. * printf( "Username: %s", result.username.latin1() );
  152. * printf( "Username: %s", result.username.latin1() );
  153. * }
  154. * \endcode
  155. *
  156. * You can also pre-set some values like the username before hand
  157. * if it is known as well as the comment and caption to be displayed:
  158. *
  159. * \code
  160. * authInfo.comment= "Enter username and password to access acmeone";
  161. * authInfo.caption= "Acme Password Dialog";
  162. * authInfo.username= "Wily E. kaiody";
  163. * bool result = openPassDlg( authInfo );
  164. * if ( result )
  165. * {
  166. * printf( "Username: %s", result.username.latin1() );
  167. * printf( "Username: %s", result.username.latin1() );
  168. * }
  169. * \endcode
  170. *
  171. * NOTE: A call to this function can also fail and result
  172. * in a return value of @p false, if the UIServer could not
  173. * be started for whatever reason.
  174. *
  175. * @param info See AuthInfo.
  176. * @return true if user clicks on "OK", false otherwsie.
  177. */
  178. void openPassDlg( TDEIO::AuthInfo& info );
  179. /**
  180. * @deprecated. Use openPassDlg( AuthInfo& ) instead.
  181. */
  182. void openPassDlg( const TQString& prompt, const TQString& user,
  183. const TQString& caption, const TQString& comment,
  184. const TQString& label, bool readOnly ) KDE_DEPRECATED;
  185. /**
  186. * @deprecated. Use openPassDlg( AuthInfo& ) instead.
  187. */
  188. void openPassDlg( const TQString& prompt, const TQString& user, bool readOnly ) KDE_DEPRECATED;
  189. void messageBox( int type, const TQString &text, const TQString &caption,
  190. const TQString &buttonYes, const TQString &buttonNo );
  191. /**
  192. * @since 3.3
  193. */
  194. void messageBox( int type, const TQString &text, const TQString &caption,
  195. const TQString &buttonYes, const TQString &buttonNo, const TQString &dontAskAgainName );
  196. // I need to identify the slaves
  197. void requestNetwork( const TQString &, const TQString &);
  198. void dropNetwork( const TQString &, const TQString &);
  199. /**
  200. * @internal
  201. * KDE 4.0: Remove
  202. */
  203. static void sigpipe_handler(int);
  204. protected slots:
  205. void calcSpeed();
  206. protected:
  207. Connection * m_pConnection;
  208. private:
  209. int m_progressId;
  210. protected:
  211. virtual void virtual_hook( int id, void* data );
  212. private:
  213. SlaveInterfacePrivate *d;
  214. };
  215. }
  216. inline TQDataStream &operator >>(TQDataStream &s, TDEIO::UDSAtom &a )
  217. {
  218. TQ_INT32 l;
  219. s >> a.m_uds;
  220. if ( a.m_uds & TDEIO::UDS_LONG ) {
  221. s >> l;
  222. a.m_long = l;
  223. a.m_str = TQString::null;
  224. } else if ( a.m_uds & TDEIO::UDS_STRING ) {
  225. s >> a.m_str;
  226. a.m_long = 0;
  227. } else {} // DIE!
  228. // assert( 0 );
  229. return s;
  230. }
  231. inline TQDataStream &operator <<(TQDataStream &s, const TDEIO::UDSAtom &a )
  232. {
  233. s << a.m_uds;
  234. if ( a.m_uds & TDEIO::UDS_LONG )
  235. s << (TQ_INT32) a.m_long;
  236. else if ( a.m_uds & TDEIO::UDS_STRING )
  237. s << a.m_str;
  238. else {} // DIE!
  239. // assert( 0 );
  240. return s;
  241. }
  242. TDEIO_EXPORT TQDataStream &operator <<(TQDataStream &s, const TDEIO::UDSEntry &e );
  243. TDEIO_EXPORT TQDataStream &operator >>(TQDataStream &s, TDEIO::UDSEntry &e );
  244. #endif