Ejemplo n.º 1
0
AmpacheService::AmpacheService( AmpacheServiceFactory* parent, const QString & name, const QString &url, const QString &username, const QString &password )
    : ServiceBase( name,  parent )
    , m_authenticated( false )
    , m_server ( QString() )
    , m_sessionId ( QString() )
    , m_collection( 0 )
{
    DEBUG_BLOCK


    setShortDescription( i18n( "Use Amarok as a seamless frontend to your Ampache server." ) );
    setIcon( KIcon( "view-services-ampache-amarok" ) );

    //we are using http queries later on, so we require
    KUrl kurl;
    if( url.contains( "//" ) )
    {
        kurl.setUrl( url, KUrl::TolerantMode );
        if( kurl.protocol() != "http" && kurl.protocol() != "https" )
        {
            kurl.setProtocol( "http" );
        }
    }
    else
    {
        kurl.setProtocol( "http" );
        kurl.setAuthority( url );
    }

    m_server = kurl.url();

    // We need to check the version of Ampache we are attempting to authenticate against, as this changes how we deal with it

    QString versionString = "<server>/server/xml.server.php?action=ping";

    versionString.replace(QString("<server>"), m_server);

    debug() << "Verifying Ampache Version Using: " << versionString;

    m_username = username;
    m_password = password;

    m_xmlVersionJob = KIO::storedGet( versionString, KIO::Reload, KIO::HideProgressInfo );
    connect( m_xmlVersionJob, SIGNAL(result(KJob *)), this, SLOT( authenticate(KJob *) ) );
}