<typesystem package="com.trolltech.qt.network" default-superclass="com.trolltech.qt.QtJambiObject">
  <inject-code>
    com.trolltech.qt.Utilities.loadQtLibrary("QtNetwork");
  </inject-code>
  
  <namespace-type name="QSsl">
    <include file-name="qssl.h" location="global" />
  </namespace-type>
  
  <enum-type name="QAbstractSocket::NetworkLayerProtocol" />
  <enum-type name="QAbstractSocket::SocketError" />
  <enum-type name="QAbstractSocket::SocketState" />
  <enum-type name="QAbstractSocket::SocketType" />
  <enum-type name="QFtp::Command" />
  <enum-type name="QFtp::Error" />
  <enum-type name="QFtp::State" />
  <enum-type name="QFtp::TransferMode" />
  <enum-type name="QFtp::TransferType" />
  <enum-type name="QHostAddress::SpecialAddress" />
  <enum-type name="QHttp::Error" />
  <enum-type name="QHttp::State" />
  <enum-type name="QHttp::ConnectionMode" />
  <enum-type name="QNetworkInterface::InterfaceFlag" flags="QNetworkInterface::InterfaceFlags" />
  <enum-type name="QNetworkProxy::ProxyType" />
  <enum-type name="QUdpSocket::BindFlag" flags="QUdpSocket::BindMode" />
  <enum-type name="QUrlInfo::PermissionSpec" />
  <enum-type name="QHostInfo::HostInfoError" />    
  <enum-type name="QSsl::KeyType" />
  <enum-type name="QSsl::EncodingFormat" />
  <enum-type name="QSsl::KeyAlgorithm"/>
  <enum-type name="QSsl::AlternateNameEntryType"/>
  <enum-type name="QSsl::SslProtocol" />
      
  <template name="network.read_char*_long_long">
        public final int read(byte data[]) {
            if (data.length == 0) return 0;
            
            com.trolltech.qt.QNativePointer np = new com.trolltech.qt.QNativePointer(com.trolltech.qt.QNativePointer.Type.Byte, data.length);
            int len = (int) read(np, data.length);
            for (int i=0; i&lt;len; ++i) data[i] = np.byteAt(i);
            
            return len;
        }      
  </template>
   
  <object-type name="QAbstractSocket">
    <modify-function signature="proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)">
        <access modifier="private" />
        <rename to="proxyAuthenticationRequiredPrivate" />
    </modify-function>  
    <inject-code>
        public Signal2&lt;QNetworkProxy, QAuthenticator> proxyAuthenticationRequired = new Signal2&lt;QNetworkProxy, QAuthenticator>();
        private boolean inEmission = false;
        
        @SuppressWarnings("unused")
        private void emitProxyAuthenticationRequiredPrivate(QNetworkProxy proxy, QAuthenticator authenticator) 
        {
            if (!inEmission) {           
                inEmission = true;
                proxyAuthenticationRequiredPrivate.emit(proxy, authenticator.nativePointer());
                inEmission = false;
            }
        }
        
        @SuppressWarnings("unused")
        private void emitProxyAuthenticationRequired(QNetworkProxy proxy, QNativePointer authenticator) 
        {
            if (!inEmission) {
                inEmission = true;
                proxyAuthenticationRequired.emit(proxy, QAuthenticator.fromNativePointer(authenticator));
                inEmission = false;
            }
        }
    </inject-code>
    <modify-function signature="QAbstractSocket(QAbstractSocket::SocketType, QObject *)">
        <inject-code class="java" position="end">
            proxyAuthenticationRequired.connect(this, "emitProxyAuthenticationRequiredPrivate(QNetworkProxy, QAuthenticator)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
            proxyAuthenticationRequiredPrivate.connect(this, "emitProxyAuthenticationRequired(QNetworkProxy,QNativePointer)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
        </inject-code>
    </modify-function>

    <modify-function signature="connectToHostImplementation(QString, unsigned short, QFlags&lt;QIODevice::OpenModeFlag&gt;)" access="private"/>
    <modify-function signature="localPort()const" access="private" rename="localPort_private"/>
    <modify-function signature="peerPort()const" access="private" rename="peerPort_private"/>
    <modify-function signature="setLocalPort(unsigned short)" access="private"/>
    <modify-function signature="setPeerPort(unsigned short)" access="private"/>
    <modify-function signature="connectToHost(QString, unsigned short, QFlags&lt;QIODevice::OpenModeFlag&gt;)" access = "private"/>
    <modify-function signature="connectToHost(QHostAddress, unsigned short, QFlags&lt;QIODevice::OpenModeFlag&gt;)" access="private"/>

    <inject-code>
    public final void connectToHost(String host, int port, com.trolltech.qt.core.QIODevice.OpenMode mode) {
        connectToHost(host, (char) port, mode);
    }
    public final void connectToHost(QHostAddress host, int port, com.trolltech.qt.core.QIODevice.OpenMode mode) {
        connectToHost(host, (char) port, mode);
    }
    protected final void connectToHostImplementation(String host, int port, com.trolltech.qt.core.QIODevice.OpenMode mode) {
        connectToHostImplementation(host, (char) port, mode);
    }
    public final int localPort() { return localPort_private(); }
    public final int peerPort() { return peerPort_private(); }
    protected final void setLocalPort(int port) { 
        setLocalPort((char) port);
    }
    protected final void setPeerPort(int port) {
        setPeerPort((char) port);
    }
    </inject-code>
  </object-type>
  <object-type name="QFtp">
    <modify-function signature="read(char*,long long)">
        <access modifier="private" />
    </modify-function>
    <inject-code>
        <insert-template name="network.read_char*_long_long" />
    </inject-code>
  </object-type>
  <object-type name="QHttp">
    <modify-function signature="proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)">
        <access modifier="private" />
        <rename to="proxyAuthenticationRequiredPrivate" />
    </modify-function>  
    <inject-code>
        public Signal2&lt;QNetworkProxy, QAuthenticator> proxyAuthenticationRequired = new Signal2&lt;QNetworkProxy, QAuthenticator>();        
        private boolean inEmission = false;
        
        @SuppressWarnings("unused")
        private void emitProxyAuthenticationRequiredPrivate(QNetworkProxy proxy, QAuthenticator authenticator) 
        {
            if (!inEmission) {           
                inEmission = true;
                proxyAuthenticationRequiredPrivate.emit(proxy, authenticator.nativePointer());
                inEmission = false;
            }
        }
        
        @SuppressWarnings("unused")
        private void emitProxyAuthenticationRequired(QNetworkProxy proxy, QNativePointer authenticator) 
        {
            if (!inEmission) {
                inEmission = true;
                proxyAuthenticationRequired.emit(proxy, QAuthenticator.fromNativePointer(authenticator));
                inEmission = false;
            }
        }
    </inject-code>
    <modify-function signature="authenticationRequired(QString,unsigned short,QAuthenticator*)">
        <access modifier="private" />
        <rename to="authenticationRequiredPrivate" />
    </modify-function>
    <inject-code>
        public Signal3&lt;String, Integer, QAuthenticator> authenticationRequired = new Signal3&lt;String, Integer, QAuthenticator>();
        private boolean inEmissionAuthenticationRequired = false;
        
        @SuppressWarnings("unused")
        private void emitAuthenticationRequiredPrivate(String hostName, int port, QAuthenticator authenticator) {
            if (!inEmissionAuthenticationRequired) {
                inEmissionAuthenticationRequired = true;
                authenticationRequiredPrivate.emit(hostName, (char) port, authenticator.nativePointer());
                inEmissionAuthenticationRequired = false;
            }                        
        }
        
        @SuppressWarnings("unused")
        private void emitAuthenticationRequired(String hostName, char port, QNativePointer authenticator) {
            if (!inEmissionAuthenticationRequired) {
                inEmissionAuthenticationRequired = true;
                authenticationRequired.emit(hostName, (int) port, QAuthenticator.fromNativePointer(authenticator));
                inEmissionAuthenticationRequired = false;
            }
        }
    </inject-code>        
    <template name="QHttp.constructor.injection">
        proxyAuthenticationRequired.connect(this, "emitProxyAuthenticationRequiredPrivate(QNetworkProxy, QAuthenticator)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
        proxyAuthenticationRequiredPrivate.connect(this, "emitProxyAuthenticationRequired(QNetworkProxy,QNativePointer)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
        authenticationRequired.connect(this, "emitAuthenticationRequiredPrivate(String, int, QAuthenticator)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
        authenticationRequiredPrivate.connect(this, "emitAuthenticationRequired(String, char, QNativePointer)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
    </template>        
    <modify-function signature="QHttp(QObject *)">
        <inject-code class="java" position="end">
            <insert-template name="QHttp.constructor.injection" />
        </inject-code>
    </modify-function>  
    <modify-function signature="QHttp(const QString &amp;, unsigned short, QObject *)" access="private">
        <inject-code class="java" position="end">
            <insert-template name="QHttp.constructor.injection" />
        </inject-code>
    </modify-function>
    <modify-function signature="QHttp(const QString &amp;, QHttp::ConnectionMode, unsigned short, QObject *)" access="private">
        <inject-code class="java" position="end">
            <insert-template name="QHttp.constructor.injection" />
        </inject-code>
    </modify-function>        
    <modify-function signature="read(char*,long long)">
        <access modifier="private" />
    </modify-function>  
    <inject-code>
        <insert-template name="network.read_char*_long_long" />
    </inject-code>  
    <modify-function signature="setSocket(QTcpSocket*)">
        <modify-argument index="1">
            <reference-count action="set" variable-name="__rcSocket" />
        </modify-argument>
    </modify-function>
    <modify-function signature="closeConnection()" remove="all"/>

    <modify-function signature="setHost(QString, unsigned short)" access="private"/>
    <modify-function signature="setHost(QString, QHttp::ConnectionMode, unsigned short)" access="private"/>

    <inject-code>
    public QHttp(String hostname, int port) { 
        this(hostname, (char) port); 
    }
    public QHttp(String hostname, int port, com.trolltech.qt.core.QObject parent) { 
        this(hostname, (char) port, parent); 
    }
    public QHttp(String hostname, QHttp.ConnectionMode mode, int port) {
        this(hostname, mode, (char) port);
    }
    public QHttp(String hostname, QHttp.ConnectionMode mode, int port, com.trolltech.qt.core.QObject parent) {
	this(hostname, mode, (char) port, parent);
    }
    public final int setHost(String hostname, QHttp.ConnectionMode mode, int port) {
        return setHost(hostname, mode, (char) port);
    }
    public final int setHost(String hostname, int port) {
        return setHost(hostname, (char) port);
    }
    </inject-code>

  </object-type>
  <object-type name="QTcpServer">
    <extra-includes>
        <include file-name="com.trolltech.qt.QNativePointer" location="java" />
    </extra-includes>
    <modify-function signature="listen(QHostAddress,unsigned short)" access="private">
        <modify-argument index="1">
            <replace-default-expression with="new com.trolltech.qt.network.QHostAddress(com.trolltech.qt.network.QHostAddress.SpecialAddress.Any)" />
        </modify-argument>
    </modify-function>
    <inject-code>
    public final boolean listen(QHostAddress address, int port) { 
        return listen(address, (char) port);
    }
    </inject-code>

    <modify-function signature="serverPort()const" access="private" rename="serverPort_private"/>
    <inject-code>
    public final int serverPort() { return serverPort_private(); }
    </inject-code>

    <modify-function signature="waitForNewConnection(int,bool*)">
        <access modifier="private" />
        <modify-argument index="1">
            <remove-default-expression />
        </modify-argument>
        <modify-argument index="2">
            <remove-default-expression />
        </modify-argument>        
    </modify-function>
    <inject-code>
        public enum Result {
            Success,
            Failure,
            TimedOut
        }
        public final Result waitForNewConnection(int msec) {
            QNativePointer np = new QNativePointer(QNativePointer.Type.Boolean);
            boolean success = waitForNewConnection(msec, np);
            
            return (np.booleanValue() 
                      ? Result.TimedOut
                      : (success ? Result.Success : Result.Failure));                        
        }
        
        public final Result waitForNewConnection() {
            return waitForNewConnection(0);
        }
    </inject-code>    
  </object-type>
  
  <object-type name="QTcpSocket">
    <modify-function signature="QTcpSocket(QObject *)">
        <inject-code class="java" position="end">
            proxyAuthenticationRequired.connect(this, "emitProxyAuthenticationRequiredPrivate(QNetworkProxy, QAuthenticator)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
	        AbstractSignal sig = (AbstractSignal) QtJambiInternal.fetchField(this, QAbstractSocket.class, "proxyAuthenticationRequiredPrivate");	
            sig.connect(this, "emitProxyAuthenticationRequired(QNetworkProxy,QNativePointer)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
        </inject-code>
    </modify-function>  
  </object-type>
  <object-type name="QUdpSocket">  
    <extra-includes>
        <include file-name="com.trolltech.qt.QNativePointer" location="java" />
    </extra-includes>        
    <modify-function signature="QUdpSocket(QObject *)">
        <inject-code class="java" position="end">
            proxyAuthenticationRequired.connect(this, "emitProxyAuthenticationRequiredPrivate(QNetworkProxy, QAuthenticator)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
	        AbstractSignal sig = (AbstractSignal) QtJambiInternal.fetchField(this, QAbstractSocket.class, "proxyAuthenticationRequiredPrivate");	
            sig.connect(this, "emitProxyAuthenticationRequired(QNetworkProxy,QNativePointer)", com.trolltech.qt.core.Qt.ConnectionType.DirectConnection);
        </inject-code>
    </modify-function>      
    <modify-function signature="readDatagram(char*,long long,QHostAddress*,unsigned short*)">
        <access modifier="private" />
    </modify-function>

    <modify-function signature="bind(QHostAddress, unsigned short)"
      access="private"
      rename="bind_private"/>

    <modify-function signature="bind(unsigned short)"
      access="private"
      rename="bind_private"/>

    <modify-function signature="bind(QHostAddress,unsigned short,QFlags&lt;QUdpSocket::BindFlag&gt;)"
      access="private"
      rename="bind_private"/>

    <modify-function signature="bind(unsigned short, QFlags&lt;QUdpSocket::BindFlag&gt;)"
      access="private"
      rename="bind_private"/>

    <inject-code>
      public final boolean bind(QHostAddress address, int port) { 
          return bind_private(address, (char) port); 
      }
      public final boolean bind(int port) { 
          return bind_private((char) port); 
      }
      public final boolean bind(QHostAddress address, int port, BindMode mode) {
          return bind_private(address, (char) port, mode);
      }
      public final boolean bind(int port, BindMode mode) {
          return bind_private((char) port, mode);
      }
    </inject-code>

    <inject-code>
        public static class HostInfo {
            public HostInfo() {
                address = new QHostAddress();
                port = 0;
            }
            public QHostAddress address;
            public int port;
        }
        public final int readDatagram(byte data[], HostInfo info) {
            QNativePointer np = new QNativePointer(QNativePointer.Type.Byte, data.length);
            QNativePointer address = info != null &amp;&amp; info.address != null ? info.address.nativePointer() : null;
            QNativePointer port = new QNativePointer(QNativePointer.Type.Char);
            
            int len = (int) readDatagram(np, data.length, address, port);
            if (info != null) info.port = port.charValue();       
            for (int i=0; i&lt;len; ++i) data[i] = np.byteAt(i);
            
            return len;
        }
    </inject-code>
    
    <modify-function signature="writeDatagram(const char*,long long,QHostAddress,unsigned short)">
        <access modifier="private" />
    </modify-function>
    <inject-code>
        public int writeDatagram(byte data[], QHostAddress address, int port) {
            QNativePointer np = com.trolltech.qt.QtJambiInternal.byteArrayToNativePointer(data);
            return (int) writeDatagram(np, data.length, address, (char) port);
        }
    </inject-code>

    <modify-function signature="writeDatagram(QByteArray, QHostAddress, unsigned short)"
      access="private"/>
    <inject-code>
        public int writeDatagram(com.trolltech.qt.core.QByteArray data, QHostAddress address, int port) {
            return (int) writeDatagram(data, address, (char) port);
        }
    </inject-code>
  </object-type>

  <object-type name="QHttpHeader">
    <modify-function signature="operator=(QHttpHeader)" remove="all"/>
  </object-type>

  <value-type name="QHostAddress">
    <modify-function signature="QHostAddress(unsigned char*)" remove="all"/>
    <modify-function signature="setAddress(unsigned char*)" remove="all"/>
    <modify-function signature="operator=(QString)" remove="all"/>
    <modify-function signature="operator=(QHostAddress)" remove="all"/>
  </value-type>  

  <value-type name="QHostInfo">
        <modify-function signature="operator=(QHostInfo)" remove="all"/>
        <modify-function signature="lookupHost(QString,QObject*,const char*)" remove="all"/>
  </value-type>

  <value-type name="QHttpRequestHeader">
    <modify-function signature="operator=(QHttpRequestHeader)" remove="all"/>
  </value-type>

  <value-type name="QHttpResponseHeader">
    <modify-function signature="operator=(QHttpResponseHeader)" remove="all"/>
  </value-type>

  <value-type name="QNetworkAddressEntry">
    <modify-function signature="operator=(QNetworkAddressEntry)" remove="all"/>
  </value-type>
  
  <value-type name="QNetworkInterface">
    <modify-function signature="operator=(QNetworkInterface)" remove="all"/>
  </value-type>
  
  <value-type name="QNetworkProxy">
    <modify-function signature="operator=(QNetworkProxy)" remove="all"/>
    <modify-function signature="QNetworkProxy(QNetworkProxy::ProxyType,QString,unsigned short,QString,QString)" access="private"/>
    <modify-function signature="setPort(unsigned short)" access="private"/>
    <modify-function signature="port()const" access="private" rename="port_private"/>
    
    <inject-code>
    public QNetworkProxy(QNetworkProxy.ProxyType type, String host, int port) {
        this(type, host, (char) port);
    }
    public QNetworkProxy(QNetworkProxy.ProxyType type, String host, int port, String username) {
        this(type, host, (char) port, username);
    }
    public QNetworkProxy(QNetworkProxy.ProxyType type, String host, int port, String username, String password) {
        this(type, host, (char) port, username, password);
    }
    public final void setPort(int port) { setPort((char) port); }
    public final int port() { return port_private(); }
    </inject-code>

  </value-type>

  <value-type name="QUrlInfo">
    <modify-function signature="operator=(QUrlInfo)" remove="all"/>
  </value-type>

  <value-type name="QIPv6Address">
    <modify-function signature="operator[](int)const">
        <remove/>
    </modify-function>
    <modify-function signature="operator[](int)">
        <remove/>
    </modify-function>    
  </value-type>
  
  <value-type name="QAuthenticator">
    <modify-function signature="operator=(QAuthenticator)" remove="all"/>
  </value-type>
  
  <suppress-warning text="*unmatched parameter type 'QList&lt;QSslError&gt; const&amp;'" />
  <suppress-warning text="*unmatched parameter type 'sockaddr const*" />
  <suppress-warning text="WARNING(MetaJavaBuilder) :: Class 'QUrlInfo' has equals operators but no qHash() function" />
  <suppress-warning text="WARNING(MetaJavaBuilder) :: Class 'QUrl' has equals operators but no qHash() function" />
  <suppress-warning text="WARNING(MetaJavaBuilder) :: Class 'QAuthenticator' has equals operators but no qHash() function" />
  
</typesystem>
