/***************************************************************************
                          slp.h  -  description
                             -------------------
    begin                : Fr Nov 14 11:06:28 CET 2003
    copyright            : (C) 2003 by Adrian Schroeter
    email                : adrian@suse.de
                           2009 Friedrich W. H. Kossebau
                           kossebau@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KIO_SLP_H
#define KIO_SLP_H

// SLP
#include <slp.h>
// KDE
#include <KIO/SlaveBase>
// Qt
#include <QtCore/QStringList>


enum ProtocolType { ServiceProtocol, MDNSProtocol, SLPProtocol, UnknownProtocol };


class ServicesSlave : public QObject, public KIO::SlaveBase
{
  Q_OBJECT

private:
    static SLPBoolean onAttributesFound( SLPHandle hslp, const char* attrlist, SLPError errorCode, void* kio_slave );
    static SLPBoolean onServiceFound( SLPHandle hslp, const char* _srvurl, unsigned short lifetime, SLPError errorCode, void* kio_slave );
    static SLPBoolean onServiceTypesFound( SLPHandle hslp, const char* serviceTypes, SLPError errorCode, void* kio_slave );

public:
  ServicesSlave( const QByteArray& protocol, const QByteArray& pool_socket, const QByteArray& app_socket );
  virtual ~ServicesSlave();

public: // KIO::SlaveBase API
    virtual void mimetype( const KUrl& url );
    virtual void stat( const KUrl& url );
    virtual void get( const KUrl& url );
    virtual void listDir( const KUrl& url );

public:
//     void addEntry( const QString& kioUrl, const QString& srvurl = QString(),
//                    const QString& mdnsName = QString() );
    void addServiceTypeEntry( const QString& serviceType );
    void addServiceEntry( const QString& serviceType, const QString& siteNParameter, const QString& serviceName );
    QString& attributeHtml();

private:
    void feedEntryAsDir( KIO::UDSEntry* entry,
                         const QString& name, const QString& iconName, const QString& destUrl );
    void feedEntryAsFile( KIO::UDSEntry* entry,
                          const QString& name, const QString& iconName, const QString& mimeTypeName,
                          const QString& displayName, const QString& destUrl );
    void overwriteWithConfig( QString* serviceType, QString* name, QString* iconName  );

private:
    bool isSlpOk();

private: // data
    SLPHandle   mSLP;
    QString     mAttributeHtml;

    QHash<QString,bool> mNativeProtocolAllowed;

    QString     mDefaultIconName;
    QString     scope;
    QStringList EnforceNativeServiceList;
    QStringList PositiveServiceList;
    QStringList NegativeServiceList;
    QStringList mCurrentServiceTypesList;
    bool        mKnownProtocolsOnly;
    bool        PositiveOnly;

    ProtocolType mProtocolMode;
};


inline QString& ServicesSlave::attributeHtml() { return mAttributeHtml; }

#endif
