Splashscreen ad support. Wait dialog for ad click/browser start.
[qtmads] / src / qtmadsservice.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 QTMADSSERVICE_H_
22 #define QTMADSSERVICE_H_
23
24 #include "qtmadsadwidget.h"
25
26 #include <QObject>
27 #include <QHash>
28 #include <QVariant>
29 class QHttp;
30
31 class QFile;
32
33 // SERVICE TAGS
34 static QString TAG_SERVICE = "service";
35 static QString TAG_CAMPAIGN = "campaign";
36 static QString TAG_ACCOUNTID = "accountid";
37 static QString TAG_PASSWORD = "password";
38
39 static QString TAG_USERID = "userid";
40 static QString TAG_LANGUAGE = "language";
41 static QString TAG_TRANSACTIONID = "transactionid";
42
43 static QString TAG_ADTYPE = "adtypedefault";
44 static QString TAG_TEXT = "text";
45 static QString TAG_CONTENT_URL = "content_url";
46 static QString TAG_URL = "url";
47 static QString TAG_HTML = "html";
48
49 // AD TAGS
50 static QString TAG_PREFERRED_SIZE = "preferredsize";
51
52 // GENERAL TAGS
53 static QString TAG_KEY = "key";
54 static QString TAG_VALUE = "value";
55
56 class QtmadsService : public QObject
57 {
58     Q_OBJECT
59
60 public:
61         QtmadsService();
62         virtual ~QtmadsService();
63
64     void getAd(QHash<QString,QVariant> &adParameters);
65     void getRemoteImage(QString urlString);
66     bool isInitialized();
67     bool initializeService(QString service, quint32 campaingId = 0, AdType defaultAdType = anyAd);
68     void setDefaultAdType(AdType type);
69     AdType defaultAdType();
70
71     virtual AdType getAdTypeFromString(QString adType);
72     virtual QString getStringFromAdType(AdType adType);
73
74 private:
75     virtual bool parseUrlParameters(const QHash<QString, QVariant> &dynamicParameters, QList<QPair<QString,QString> > &parsedParameters) = 0;
76     virtual bool parseReceivedAd(const QByteArray &response, QHash<QString, QVariant> &parsedAd) = 0;
77     virtual bool parseXmlConfFile(QFile &file);
78
79 public slots:
80         void adRequestFinished(int, bool);
81     void imageRequestFinished(int, bool);
82
83 signals:
84         void adRequestReady(QHash<QString,QVariant> &ad);
85         void adRequestFailed();
86     void imageRequestReady(const QImage *image);
87     void imageRequestFailed();
88
89 protected:
90         QString serviceName;
91         quint32 adGroupId;
92         QString serviceUrl;
93         QString accountId;
94         QString password;
95
96         QString language;
97         QString transactionId;
98
99         AdType defAdType;
100
101         QSize preferredSize;
102
103         QHash<QString,QString> parameterTags;
104
105     QHttp *http;
106
107     qint32 adTrasactionId;
108     qint32 imageTrasactionId;
109
110     bool initialized;
111 };
112
113 #endif /* QTMADSSERVICE_H_ */