From: Arttu Date: Sat, 7 Nov 2009 11:34:47 +0000 (+0200) Subject: Splashscreen ad support. Wait dialog for ad click/browser start. X-Git-Url: http://vcs.maemo.org/git/?p=qtmads;a=commitdiff_plain Splashscreen ad support. Wait dialog for ad click/browser start. --- diff --git a/core b/core deleted file mode 100644 index 3e3290c..0000000 Binary files a/core and /dev/null differ diff --git a/plugins/confs/ADHERE_adconfigure.xml b/plugins/confs/ADHERE_adconfigure.xml index 4a32e8f..ad087c0 100644 --- a/plugins/confs/ADHERE_adconfigure.xml +++ b/plugins/confs/ADHERE_adconfigure.xml @@ -3,7 +3,7 @@ - + diff --git a/plugins/confs/SOMA_adconfigure.xml b/plugins/confs/SOMA_adconfigure.xml index 4a32e8f..e69de29 100644 --- a/plugins/confs/SOMA_adconfigure.xml +++ b/plugins/confs/SOMA_adconfigure.xml @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/plugins/confs/template.xml b/plugins/confs/template.xml deleted file mode 100644 index 6e3b6df..0000000 --- a/plugins/confs/template.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/confs/template_adconfigure.xml b/plugins/confs/template_adconfigure.xml new file mode 100644 index 0000000..58641a8 --- /dev/null +++ b/plugins/confs/template_adconfigure.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/qtmadsexample/mainwindow.cpp b/qtmadsexample/mainwindow.cpp index 80cad91..8aae89c 100644 --- a/qtmadsexample/mainwindow.cpp +++ b/qtmadsexample/mainwindow.cpp @@ -15,24 +15,46 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - QWidget *widget = new QWidget(this); - QGridLayout *layout = new QGridLayout(widget); + widget = new QWidget(this); + mainLayout = new QGridLayout(widget); - QtmadsBannerAd *adWidget1 = new QtmadsBannerAd("ADHERE", 0, noFit, this); - adWidget1->setAsBannerAd(); - adWidget1->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); - adWidget1->setMaximumSize(QSize(216,36)); - layout->addWidget(adWidget1, 0, 0, 1, 2, Qt::AlignCenter); + splashScreenAd = new QtmadsLabelAd("ADHERE", 0, noFit, this); + splashScreenAd->setAsImageAd(); + mainLayout->addWidget(splashScreenAd); + splashScreenAd->startSingleShotAd(10); + connect(splashScreenAd, SIGNAL(adStopped()),this, SLOT(splashStopped())); + + widget->setLayout(mainLayout); + + this->setCentralWidget(widget); +} + +void MainWindow::splashStopped() +{ + qDebug() << "splashStopped()"; + this->mainLayout->removeWidget(splashScreenAd); + splashScreenAd->clearAd(); + this->init(); +} + +void MainWindow::init() +{ + QtmadsBannerAd *adWidget1 = new QtmadsBannerAd("ADHERE", 0, noFit, this); + adWidget1->setAsBannerAd(); + adWidget1->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); + adWidget1->setMaximumSize(QSize(216,36)); + mainLayout->addWidget(adWidget1, 0, 0, 1, 2, Qt::AlignCenter); QtmadsBannerAd *adWidget2 = new QtmadsBannerAd("ADHERE", 0, noFit, this); adWidget2->setAsBannerAd(); adWidget2->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); adWidget2->setMaximumSize(QSize(216,36)); - layout->addWidget(adWidget2, 0, 2, 1, 2, Qt::AlignCenter); + mainLayout->addWidget(adWidget2, 0, 2, 1, 2, Qt::AlignCenter); QtmadsBannerAd *adWidget3 = new QtmadsBannerAd("ADHERE", 0, noFit, this); adWidget3->setAsTextBannerAd(); @@ -40,32 +62,28 @@ MainWindow::MainWindow(QWidget *parent) adWidget3->setAdFontSize(18); adWidget3->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); adWidget3->setMaximumSize(QSize(216,36)); - layout->addWidget(adWidget3, 1, 0, 1, 2, Qt::AlignCenter); + mainLayout->addWidget(adWidget3, 1, 0, 1, 2, Qt::AlignCenter); QtmadsBannerAd *adWidget4 = new QtmadsBannerAd("ADHERE", 0, noFit, this); adWidget4->setAsTextBannerAd(); adWidget4->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); adWidget4->setMaximumSize(QSize(216,36)); - layout->addWidget(adWidget4, 1, 2, 1, 2, Qt::AlignCenter); + mainLayout->addWidget(adWidget4, 1, 2, 1, 2, Qt::AlignCenter); - QtmadsLabelAd *adWidget5 = new QtmadsLabelAd("ADHERE", 0, noFit, this); + /*QtmadsLabelAd *adWidget5 = new QtmadsLabelAd("ADHERE", 0, noFit, this); adWidget5->setAsImageAd(); - layout->addWidget(adWidget5, 2, 1, 1, 2, Qt::AlignCenter); + mainLayout->addWidget(adWidget5, 2, 1, 1, 2, Qt::AlignCenter); QtmadsMediaAd *audioAd = new QtmadsMediaAd("ADHERE", 0, noFit, this); audioAd->setAsAudioAd(); - layout->addWidget(audioAd); + layout->addWidget(audioAd);*/ adWidget1->startAd(30); adWidget2->startAd(40); adWidget3->startAd(30); adWidget4->startAd(40); - adWidget5->startAd(); - audioAd->startAd(30); - - widget->setLayout(layout); - - this->setCentralWidget(widget); + /*adWidget5->startAd(); + audioAd->startAd(30);*/ } MainWindow::~MainWindow() diff --git a/qtmadsexample/mainwindow.h b/qtmadsexample/mainwindow.h index 3efd45d..b551df0 100644 --- a/qtmadsexample/mainwindow.h +++ b/qtmadsexample/mainwindow.h @@ -7,6 +7,9 @@ #include +class QtmadsLabelAd; +class QGridLayout; + class MainWindow : public QMainWindow { Q_OBJECT @@ -14,6 +17,16 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = 0); ~MainWindow(); + + void init(); + +public slots: + void splashStopped(); + +private: + QWidget *widget; + QGridLayout *mainLayout; + QtmadsLabelAd *splashScreenAd; }; #endif // MAINWINDOW_H diff --git a/qtmadsexample/qrc_resources.cpp b/qtmadsexample/qrc_resources.cpp index abbcef7..05bbcb9 100644 --- a/qtmadsexample/qrc_resources.cpp +++ b/qtmadsexample/qrc_resources.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Resource object code ** -** Created: Wed Oct 28 18:03:00 2009 +** Created: Sat Nov 7 09:25:02 2009 ** by: The Resource Compiler for Qt version 4.5.3 ** ** WARNING! All changes made in this file will be lost! diff --git a/src/ADHERE/ADHERE_adconfigure.xml b/src/ADHERE/ADHERE_adconfigure.xml deleted file mode 100644 index 4a32e8f..0000000 --- a/src/ADHERE/ADHERE_adconfigure.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/ADHERE/ADHERE_servicepluginloader.h b/src/ADHERE/ADHERE_servicepluginloader.h index d5139dd..512386e 100644 --- a/src/ADHERE/ADHERE_servicepluginloader.h +++ b/src/ADHERE/ADHERE_servicepluginloader.h @@ -21,7 +21,7 @@ #ifndef ADHERESERVICEPLUGINLOADER_H_ #define ADHERESERVICEPLUGINLOADER_H_ -#include "qtmadsserviceinterface.h" +#include "qtmadsserviceloaderinterface.h" #include @@ -29,10 +29,10 @@ #include "ADHERE_serviceplugin.h" -class AdhereServicePluginLoader : public QObject, QtmadsServiceInterface +class AdhereServicePluginLoader : public QObject, QtmadsServiceLoaderInterface { Q_OBJECT - Q_INTERFACES(QtmadsServiceInterface) + Q_INTERFACES(QtmadsServiceLoaderInterface) public: AdhereServicePluginLoader(){}; diff --git a/src/SOMA/SOMA_adconfigure.xml b/src/SOMA/SOMA_adconfigure.xml deleted file mode 100644 index 4a32e8f..0000000 --- a/src/SOMA/SOMA_adconfigure.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/SOMA/SOMA_servicepluginloader.h b/src/SOMA/SOMA_servicepluginloader.h index 890d225..20d939d 100644 --- a/src/SOMA/SOMA_servicepluginloader.h +++ b/src/SOMA/SOMA_servicepluginloader.h @@ -21,7 +21,7 @@ #ifndef SOMASERVICEPLUGINLOADER_H_ #define SOMASERVICEPLUGINLOADER_H_ -#include "qtmadsserviceinterface.h" +#include "qtmadsserviceloaderinterface.h" #include @@ -29,10 +29,10 @@ #include "SOMA_serviceplugin.h" -class SomaServicePluginLoader : public QObject, QtmadsServiceInterface +class SomaServicePluginLoader : public QObject, QtmadsServiceLoaderInterface { Q_OBJECT - Q_INTERFACES(QtmadsServiceInterface) + Q_INTERFACES(QtmadsServiceLoaderInterface) public: SomaServicePluginLoader(){}; diff --git a/src/qrc_resources.cpp b/src/qrc_resources.cpp index f891041..2a6d68c 100644 --- a/src/qrc_resources.cpp +++ b/src/qrc_resources.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Resource object code ** -** Created: Wed Oct 28 18:02:54 2009 +** Created: Sat Nov 7 09:18:26 2009 ** by: The Resource Compiler for Qt version 4.5.3 ** ** WARNING! All changes made in this file will be lost! diff --git a/src/qtmadsadwidget.cpp b/src/qtmadsadwidget.cpp index 22e56a9..aefde02 100644 --- a/src/qtmadsadwidget.cpp +++ b/src/qtmadsadwidget.cpp @@ -29,39 +29,70 @@ #include #include #include +#include +#include #include "qtmadsservice.h" -#include "qtmadsserviceinterface.h" +#include "qtmadsserviceloaderinterface.h" QtmadsAdWidget::QtmadsAdWidget(QString serviceName, AdType defaultType, quint32 groupId, AdFit fitting, QWidget *parent) : type(defaultType), adFit(fitting), QWidget(parent) { - this->loadPlugin(serviceName); + this->loadServicePlugin(serviceName); this->service->initializeService(serviceName, groupId, defaultType); adTimer = 0; + msgBox = 0; } QtmadsAdWidget::~QtmadsAdWidget() { this->clearAd(); + emit adStopped(); } void QtmadsAdWidget::startAd(quint32 adChangeIntervalInSecs) { getNewAd(); - + qDebug() << "ee"; if(0 != adChangeIntervalInSecs){ if(adTimer == 0){ adTimer = new QTimer(this); - connect(adTimer, SIGNAL(timeout()), this, SLOT(getNewAd())); }else{ + if(adTimer->isSingleShot()){ + disconnect(adTimer, SIGNAL(timeout()), this, SLOT(singleShotEnded())); + }else{ + disconnect(adTimer, SIGNAL(timeout()), this, SLOT(getNewAd())); + } adTimer->stop(); } + connect(adTimer, SIGNAL(timeout()), this, SLOT(getNewAd())); + adTimer->setSingleShot(false); adTimer->start(adChangeIntervalInSecs*1000); } } +void QtmadsAdWidget::startSingleShotAd(quint32 durationInSecs) +{ + getNewAd(); + + if(0 != durationInSecs){ + if(adTimer == 0){ + adTimer = new QTimer(this); + }else{ + if(adTimer->isSingleShot()){ + disconnect(adTimer, SIGNAL(timeout()), this, SLOT(singleShotEnded())); + }else{ + disconnect(adTimer, SIGNAL(timeout()), this, SLOT(getNewAd())); + } + adTimer->stop(); + } + connect(adTimer, SIGNAL(timeout()), this, SLOT(singleShotEnded())); + adTimer->setSingleShot(true); + adTimer->start(durationInSecs*1000); + } +} + void QtmadsAdWidget::setAdType(AdType adType) { this->type = adType; @@ -117,7 +148,15 @@ void QtmadsAdWidget::adRequestFailed() void QtmadsAdWidget::adClicked(const QUrl &url) { if(url.isValid()){ - qDebug() << "Browser opened to urli: " << url.toString(); + qDebug() << "Browser opened to url: " << url.toString(); + if(msgBox == 0){ + msgBox = new QMessageBox(QMessageBox::NoIcon, tr("Opening ad"), + tr("Opening ad to browser..."), QMessageBox::Cancel, this); + } + // just fixed wait time for now.. + startTimer(10000); + msgBox->exec(); + QDesktopServices::openUrl(url); } } @@ -128,7 +167,26 @@ void QtmadsAdWidget::clearAd() type = noAd; } -bool QtmadsAdWidget::loadPlugin(QString serviceName) +void QtmadsAdWidget::singleShotEnded() +{ + qDebug() << "singleShotEnded()"; + adTimer->stop(); + delete adTimer; + adTimer = 0; + + this->clearAd(); + emit adStopped(); +} + +void QtmadsAdWidget::timerEvent(QTimerEvent *event) +{ + qDebug() << "timerEvent()"; + this->killTimer(event->timerId()); + if(msgBox) + msgBox->close(); +} + +bool QtmadsAdWidget::loadServicePlugin(QString serviceName) { bool pluginFound = false; QDir pluginsDir(qApp->applicationDirPath()); @@ -149,13 +207,14 @@ bool QtmadsAdWidget::loadPlugin(QString serviceName) QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = pluginLoader.instance(); if (plugin) { - QtmadsServiceInterface *plugLoader = qobject_cast(plugin); + QtmadsServiceLoaderInterface *plugLoader = qobject_cast(plugin); this->service = plugLoader->loadService(); - if (this->service) + if (this->service){ pluginFound = true; - else{ + qDebug() << "Plugin loaded"; + }else{ qDebug() << "Plugin load failed: " << pluginLoader.errorString(); - } + } plugLoader = 0; delete plugin; }else{ diff --git a/src/qtmadsadwidget.h b/src/qtmadsadwidget.h index 1dc1b2f..2a7fa35 100644 --- a/src/qtmadsadwidget.h +++ b/src/qtmadsadwidget.h @@ -36,6 +36,7 @@ class QLabel; class QBoxLayout; class QWebView; class QTimer; +class QMessageBox; enum AdType{ anyAd = 1, @@ -72,6 +73,7 @@ public: ~QtmadsAdWidget(); void startAd(quint32 adChangeIntervalInSecs = 0); + void startSingleShotAd(quint32 durationInSecs); //TODO: default getAdAsHash()? virtual void getAdAsHash(QHash &adParams) = 0; @@ -82,20 +84,25 @@ protected: AdType adType(); private: - bool loadPlugin(QString serviceName); + bool loadServicePlugin(QString serviceName); public slots: void getNewAd(); + virtual void clearAd() = 0; + void timerEvent(QTimerEvent */*event*/); +private slots: void adRequestSucceeded(QHash &ad); void adRequestFailed(); void adClicked(const QUrl &url = QUrl()); - virtual void clearAd() = 0; + + void singleShotEnded(); signals: void newAdReady(); void newAdFailed(); + void adStopped(); protected: @@ -108,6 +115,8 @@ protected: private: QTimer *adTimer; + QMessageBox *msgBox; + quint32 adClickedAmount; //TODO: shown on screen diff --git a/src/qtmadsservice.cpp b/src/qtmadsservice.cpp index 47fb5d7..becfedd 100644 --- a/src/qtmadsservice.cpp +++ b/src/qtmadsservice.cpp @@ -47,7 +47,10 @@ bool QtmadsService::initializeService(QString service, quint32 adGroup, AdType d bool parseSuccess = true; // ../plugins/SERVICE_NAME_adconfigure.xml - QFile file(CONF_PATH + this->serviceName + CONF_FILE_POSTFIX ); + QString path("plugins/confs/"); + path.append(this->serviceName); + path.append("_adconfigure.xml"); + QFile file(path); parseSuccess = file.exists(); /*if(!file.exists()){ @@ -64,7 +67,6 @@ bool QtmadsService::initializeService(QString service, quint32 adGroup, AdType d if(parseSuccess){ initialized = true; }else{ - qDebug() << "Ad service configure failed. " << CONF_PATH + this->serviceName + CONF_FILE_POSTFIX ; initialized = false; //TODO: parse failed } @@ -181,7 +183,8 @@ AdType QtmadsService::defaultAdType() bool QtmadsService::parseXmlConfFile(QFile &file) { - qDebug() << "QtmadsService::parseXmlConfFile()"; + //qDebug() << "QtmadsService::parseXmlConfFile()"; + //TODO: apply some sanity to if-hell bool success = false; QXmlStreamReader xmlReader(&file); diff --git a/src/qtmadsservice.h b/src/qtmadsservice.h index 7facb52..9b1cef7 100644 --- a/src/qtmadsservice.h +++ b/src/qtmadsservice.h @@ -30,9 +30,7 @@ class QHttp; class QFile; -static QString CONF_PATH = "plugins/confs/"; -static QString CONF_FILE_POSTFIX = "_adconfigure.xml"; - +// SERVICE TAGS static QString TAG_SERVICE = "service"; static QString TAG_CAMPAIGN = "campaign"; static QString TAG_ACCOUNTID = "accountid"; @@ -42,13 +40,16 @@ static QString TAG_USERID = "userid"; static QString TAG_LANGUAGE = "language"; static QString TAG_TRANSACTIONID = "transactionid"; -static QString TAG_ADTYPE = "adtype"; +static QString TAG_ADTYPE = "adtypedefault"; static QString TAG_TEXT = "text"; static QString TAG_CONTENT_URL = "content_url"; static QString TAG_URL = "url"; static QString TAG_HTML = "html"; + +// AD TAGS static QString TAG_PREFERRED_SIZE = "preferredsize"; +// GENERAL TAGS static QString TAG_KEY = "key"; static QString TAG_VALUE = "value"; diff --git a/src/qtmadsserviceinterface.h b/src/qtmadsserviceinterface.h deleted file mode 100644 index 6b848d5..0000000 --- a/src/qtmadsserviceinterface.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2009 Eetu Lehmusvuo. - * - * This file is part of QtMAds. - * - * QtMAds is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * QtMAds is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with QtMAds. If not, see . - * - */ - -#ifndef QTMADSSERVICEINTERFACE_H_ -#define QTMADSSERVICEINTERFACE_H_ - -#include "qtmadsservice.h" - -//class QtmadsService; - -class QtmadsServiceInterface -{ -public: - virtual ~QtmadsServiceInterface(){}; - virtual QtmadsService* loadService() = 0; -}; - -Q_DECLARE_INTERFACE(QtmadsServiceInterface, "com.qtmads.plugin.QtmadsServiceInterface/1.0"); - -#endif /* QTMADSSERVICEINTERFACE_H_ */ diff --git a/src/qtmadsserviceloaderinterface.h b/src/qtmadsserviceloaderinterface.h new file mode 100644 index 0000000..5ba3889 --- /dev/null +++ b/src/qtmadsserviceloaderinterface.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2009 Eetu Lehmusvuo. + * + * This file is part of QtMAds. + * + * QtMAds is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QtMAds is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with QtMAds. If not, see . + * + */ + +#ifndef QTMADSSERVICELOADERINTERFACE_H_ +#define QTMADSSERVICELOADERNITERFACE_H_ + +#include "qtmadsservice.h" + +class QtmadsServiceLoaderInterface +{ +public: + virtual ~QtmadsServiceLoaderInterface(){}; + virtual QtmadsService* loadService() = 0; +}; + +Q_DECLARE_INTERFACE(QtmadsServiceLoaderInterface, "com.qtmads.plugin.QtmadsServiceLoaderInterface/1.0"); + +#endif diff --git a/src/src.pro b/src/src.pro index 089e7b1..d00a647 100644 --- a/src/src.pro +++ b/src/src.pro @@ -12,12 +12,11 @@ QT += phonon \ network \ webkit \ xml -HEADERS += \ +HEADERS += qtmadsserviceloaderinterface.h \ qtmadsmediaad.h \ qtmadslabelad.h \ qtmadsbannerad.h \ qtmadsadwidget.h \ - qtmadsserviceinterface.h \ qtmadsservice.h SOURCES += qtmadsmediaad.cpp \ qtmadslabelad.cpp \