1dc1b2fa90891305e0e269d5309cfa69a575511a
[qtmads] / src / qtmadsadwidget.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 QTMADSADWIDGET_H
22 #define QTMADSADWIDGET_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         noAd
50 };
51
52 enum AdFit{
53     noFit = 1,
54     fitWidgetToAd,
55     fitAdToWidget
56 };
57
58 enum ParseState{
59     parseReady = 1,
60     parseFailed,
61     parseWaiting
62 };
63
64 static QString PLUGINS_PATH = "../plugins";
65
66 class QtmadsAdWidget : public QWidget
67 {
68     Q_OBJECT
69
70 public:
71     QtmadsAdWidget(QString service, AdType defaultType = anyAd, quint32 id = 0, AdFit fitting = noFit, QWidget *parent = 0);
72     ~QtmadsAdWidget();
73
74     void startAd(quint32 adChangeIntervalInSecs = 0);
75
76     //TODO: default getAdAsHash()?
77     virtual void getAdAsHash(QHash<QString, QVariant> &adParams) = 0;
78     virtual ParseState parseFromParameters(QHash<QString, QVariant> &ad) = 0;
79
80 protected:
81     void setAdType(AdType adType);
82     AdType adType();
83
84 private:
85     bool loadPlugin(QString serviceName);
86
87 public slots:
88     void getNewAd();
89
90     void adRequestSucceeded(QHash<QString, QVariant> &ad);
91         void adRequestFailed();
92
93     void adClicked(const QUrl &url = QUrl());
94     virtual void clearAd() = 0;
95
96 signals:
97     void newAdReady();
98     void newAdFailed();
99
100 protected:
101
102     QtmadsService *service;
103
104     AdFit adFit;
105     AdType type;
106     qint32 adID;
107
108 private:
109     QTimer *adTimer;
110
111         quint32 adClickedAmount;
112
113         //TODO: shown on screen
114         qint32 shownOnScreenStart;
115         qint32 shownOnScreenEnd;
116         qint32 shownTime;
117 };
118
119 #endif // QTMADSADWIDGET_H