home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kio / slaveinterface.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.8 KB  |  289 lines

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