--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QTMADSSERVICE_H_
+#define QTMADSSERVICE_H_
+
+#include "qtmadsadwidget.h"
+
+#include <QObject>
+#include <QHash>
+#include <QVariant>
+class QHttp;
+
+class QFile;
+
+static QString CONF_PATH = "plugins/confs/";
+static QString CONF_FILE_POSTFIX = "_adconfigure.xml";
+
+static QString TAG_SERVICE = "service";
+static QString TAG_CAMPAIGN = "campaign";
+static QString TAG_ACCOUNTID = "accountid";
+static QString TAG_PASSWORD = "password";
+
+static QString TAG_USERID = "userid";
+static QString TAG_LANGUAGE = "language";
+static QString TAG_TRANSACTIONID = "transactionid";
+
+static QString TAG_ADTYPE = "adtype";
+static QString TAG_TEXT = "text";
+static QString TAG_CONTENT_URL = "content_url";
+static QString TAG_URL = "url";
+static QString TAG_HTML = "html";
+static QString TAG_PREFERRED_SIZE = "preferredsize";
+
+static QString TAG_KEY = "key";
+static QString TAG_VALUE = "value";
+
+class QtmadsService : public QObject
+{
+ Q_OBJECT
+
+public:
+ QtmadsService();
+ virtual ~QtmadsService();
+
+ void getAd(QHash<QString,QVariant> &adParameters);
+ void getRemoteImage(QString urlString);
+ bool isInitialized();
+ bool initializeService(QString service, quint32 campaingId = 0, AdType defaultAdType = anyAd);
+ void setDefaultAdType(AdType type);
+ AdType defaultAdType();
+
+ virtual AdType getAdTypeFromString(QString adType);
+ virtual QString getStringFromAdType(AdType adType);
+
+private:
+ virtual bool parseUrlParameters(const QHash<QString, QVariant> &dynamicParameters, QList<QPair<QString,QString> > &parsedParameters) = 0;
+ virtual bool parseReceivedAd(const QByteArray &response, QHash<QString, QVariant> &parsedAd) = 0;
+ virtual bool parseXmlConfFile(QFile &file);
+
+public slots:
+ void adRequestFinished(int, bool);
+ void imageRequestFinished(int, bool);
+
+signals:
+ void adRequestReady(QHash<QString,QVariant> &ad);
+ void adRequestFailed();
+ void imageRequestReady(const QImage *image);
+ void imageRequestFailed();
+
+protected:
+ QString serviceName;
+ quint32 adGroupId;
+ QString serviceUrl;
+ QString accountId;
+ QString password;
+
+ QString language;
+ QString transactionId;
+
+ AdType defAdType;
+
+ QSize preferredSize;
+
+ QHash<QString,QString> parameterTags;
+
+ QHttp *http;
+
+ qint32 adTrasactionId;
+ qint32 imageTrasactionId;
+
+ bool initialized;
+};
+
+#endif /* QTMADSSERVICE_H_ */