/***************************************************************************
                         servicelistingurl.cpp  -  description
                             -------------------
    copyright            : 2009 Friedrich W. H. Kossebau
    email                : 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                                      *
 *                                                                         *
 ***************************************************************************/

#include "servicelistingurl.h"

// KDE
#include <KProtocolInfo>


QRegExp* ServiceListingUrl::matcher = 0;

const char* const ServiceListingUrl::ProtocolName[] =
{
    "service",
    "mdns",
    "slp",
    ""
};

QString ServiceListingUrl::toKdeProtocolName( const QString& serviceTypeName )
{
    QString result = serviceTypeName;

    bool isSecondTry = false;
    while( true )
    {
        if ( KProtocolInfo::isKnownProtocol(result) )
            break;

        if( isSecondTry )
        {
            result.clear();
            break;
        }

        // remove the abstract type
        // TODO: perhaps this should be always been done, or will KDE ever support this? How?
        const int indexOfDoubleColon = result.indexOf( ':' );
        if (indexOfDoubleColon == -1)
        {
            result.clear();
            break;
        }
        result.remove( 0, indexOfDoubleColon+1 );
        isSecondTry = true;
    }

    return result;
}


