First version. ADHERE service support with label, banner and media ads.
[qtmads] / src / qtmadsad.h
1 /*
2  * Copyright (c) 2009 Eetu Lehmusvuo.
3  *
4  * This file is part of QtMAds.
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  */
20
21 #ifndef QTMADSAD_H_
22 #define QTMADSAD_H_
23
24 #include <QtGui/QWidget>
25
26 #include <QUrl>
27 #include <QMainWindow>
28
29 #include <Phonon/AudioOutput>
30 #include <Phonon/MediaObject>
31 #include <Phonon/BackendCapabilities>
32 #include <Phonon/ObjectDescriptionModel>
33
34 class QtmadsService;
35 class QLabel;
36 class QBoxLayout;
37 class QWebView;
38 class QTimer;
39
40 enum AdType{
41     anyAd = 1,
42     txtAd,
43     imageAd,
44     txtBannerAd,
45     imageBannerAd,
46     audioAd,
47     videoAd
48 };
49
50 enum AdFit{
51     noFit = 1,
52     fitWidgetToAd,
53     fitAdToWidget
54 };
55
56 static QString PLUGINS_PATH = "../plugins";
57
58 class QtmadsAd : public QObject
59 {
60     Q_OBJECT
61
62 public:
63     QtmadsAd(QString service, AdType defaultType = anyAd, quint32 id = 0, AdFit fitting = noFit);
64     ~QtmadsAd();
65
66     void startAd(quint32 adChangeIntervalInSecs = 0);
67     void getHash(QHash<QString, QVariant> &adParams);
68
69     void setAsTextAd(const QFont &font, bool isOnlyTextAd = true, Qt::Alignment alignment = Qt::AlignCenter);
70     void setAsImageAd(bool isOnlyImageAd = true);
71     void setAsBannerAd(bool isOnlyImageAd = true);
72     void setAsTextBannerAd(bool isOnlyTextBannerAd = true);
73     void setAsAudioAd(bool isOnlyAudioAd = true);
74     void setAsVideoAd();
75
76 private:
77     bool loadPlugin(QString serviceName);
78
79 public slots:
80     void getNewAd();
81
82     void adRequestSucceeded(QHash<QString, QVariant> &ad);
83     void adRequestFailed();
84     void imageRequestSucceeded(QImage *img);
85     void imageRequestFailed();
86     void readyToShow();
87     void showFailed();
88
89     void adClicked(const QUrl &url = QUrl());
90     void clear();
91
92     void phononPlayerStateChanged(Phonon::State newstate, Phonon::State oldstate);
93
94 signals:
95     void newAdReady();
96     void newAdFailed();
97
98 private:
99     QBoxLayout *layout;
100     QLabel *label;
101     QWebView *htmlView;
102
103     QtmadsService *service;
104
105     Phonon::MediaObject *player;
106
107     QTimer *adTimer;
108
109     AdFit adFit;
110     AdType adType;
111     qint32 adID;
112     QString text;
113     QImage *image;
114     QString imageUrl;
115     QString mediaContentUrl;
116
117     // banner url that is opened when ad is clicked
118     QUrl adUrl;
119     QFont adFont;
120
121     QString htmlContent;
122
123     Qt::Alignment textAlignment;
124
125     quint32 adClickedAmount;
126
127     qint32 shownOnScreenStart;
128     qint32 shownOnScreenEnd;
129     qint32 shownTime;
130 };
131
132 #endif // QTMADSAD_H_