#include "qcustomwebpage.h"
#include "phononwebplayer.h"

#include <QDebug>
#include <Phonon>
#include <QWebFrame>
#include "playerjs.h"

QCustomWebPage::QCustomWebPage()
{
}

QObject* QCustomWebPage::createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues){

    qDebug() << QString("Debugging plugin : %1 at url %2").arg(classid).arg(url.toString());

    if(!paramNames.contains("src",Qt::CaseInsensitive)){
        qDebug() << "Params src not found";
        return 0;
    }

    QUrl src(QString(paramValues.at(paramNames.indexOf("src"))));
    //qDebug() << QString("SRC param found : ").append(src.toString());

    if(!src.isValid())
        return 0;

    //Create Request for Media file
    QNetworkRequest request;
    request.setUrl((url.isRelative() ? this->currentFrame()->url().resolved(src) : src));
    QNetworkReply *reply =  networkAccessManager()->get(request);

    //Create PhononWebPlayer plugin
    PhononWebPlayer *player = new PhononWebPlayer(reply,"QBuffer");
    return player;

}
