2 * Copyright (c) 2009 Eetu Lehmusvuo.
4 * This file is part of QtMAds.
6 * QtMAds is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * QtMAds is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with QtMAds. If not, see <http://www.gnu.org/licenses/>.
23 #include "qtmadsmediaad.h"
29 #include "qtmadsservice.h"
31 QtmadsMediaAd::QtmadsMediaAd(QString serviceName, quint32 adGroupId, AdFit fitting, QWidget *parent)
32 : QtmadsAdWidget(serviceName, imageAd, adGroupId, fitting, parent)
35 QHBoxLayout *layout = new QHBoxLayout(this);
36 this->setLayout(layout);
39 QtmadsMediaAd::~QtmadsMediaAd()
49 ParseState QtmadsMediaAd::parseFromParameters(QHash<QString, QVariant> &ad)
51 ParseState parseSuccess = parseReady;
52 bool textOrImageFound = false;
54 QHash<QString, QVariant>::iterator iter;
56 for(iter = ad.begin(); iter != ad.end() && parseSuccess != parseFailed; iter++){
57 //qDebug() << "key: " << iter.key() << " value: " << iter.value().toString();
58 if(0 == iter.key().compare(TAG_CONTENT_URL)){
59 this->mediaContentUrl = iter.value().toString();
61 if(this->adType() == audioAd){
62 player = Phonon::createPlayer(Phonon::MusicCategory,
63 Phonon::MediaSource(this->mediaContentUrl));
65 Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, player);
66 Phonon::createPath(player, audioOutput);
68 player = Phonon::createPlayer(Phonon::VideoCategory,
69 Phonon::MediaSource(this->mediaContentUrl));
70 this->videoWidget = new Phonon::VideoWidget(this);
71 Phonon::createPath(player, videoWidget);
73 Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
74 Phonon::createPath(player, audioOutput);
76 this->layout()->addWidget(videoWidget);
79 player->setCurrentSource(Phonon::MediaSource(this->mediaContentUrl));
82 connect(player, SIGNAL(stateChanged(Phonon::State newstate, Phonon::State oldstate)),
83 this, SLOT(phononPlayerStateChanged(Phonon::State newstate, Phonon::State oldstate)));
84 connect(player, SIGNAL(finished ()),
85 this, SLOT(phononPlayerStateChanged()));
88 qDebug() << "media play started!";
90 }else if(0 == iter.key().compare(TAG_ADTYPE)){
91 this->setAdType(this->service->getAdTypeFromString(iter.value().toString()));
94 qDebug() << "Unknown tag.";
98 // either text or image should be found from ad
100 parseSuccess = parseFailed;
105 void QtmadsMediaAd::getAdAsHash(QHash<QString, QVariant> &adParams)
107 //adParams.insert("adsize", QVariant(this->sizeHint()));
110 void QtmadsMediaAd::setAsAudioAd(bool isOnlyAudioAd)
112 if(this->service->defaultAdType() == videoAd){
113 // can't be video and audio ad..
116 this->layout()->removeWidget(videoWidget);
123 this->service->setDefaultAdType(audioAd);
126 if(this->service->defaultAdType() != audioAd)
127 this->service->setDefaultAdType(anyAd);
131 void QtmadsMediaAd::setAsVideoAd()
133 if(this->service->defaultAdType() == audioAd){
134 // clear audio ad first..
141 this->service->setDefaultAdType(videoAd);
144 void QtmadsMediaAd::clearAd()
146 this->mediaContentUrl.clear();
149 disconnect(player, SIGNAL(stateChanged(Phonon::State newstate, Phonon::State oldstate)),
150 this, SLOT(phononState(Phonon::State newstate, Phonon::State oldstate)));
151 disconnect(player, SIGNAL(finished ()), this, SLOT(phononState()));