--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <QDebug>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QImage>
+#include "imagefetcher.h"
+
+ImageFetcher::ImageFetcher(QNetworkAccessManager *manager, QObject *parent)
+ : QObject(parent)
+ , m_manager(manager)
+{
+ connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(
+ downloadFinished(QNetworkReply*)));
+}
+
+void ImageFetcher::fetchImage(const QUrl &url)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (url.isEmpty() || !url.isValid())
+ return;
+
+ if (m_downloadQueue.size() >= DOWNLOAD_QUEUE_SIZE)
+ m_downloadQueue.dequeue();
+
+ m_downloadQueue.enqueue(url);
+
+ if (m_currentDownloads.size() < MAX_PARALLEL_DOWNLOADS)
+ startNextDownload();
+}
+
+void ImageFetcher::startNextDownload()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (m_downloadQueue.isEmpty())
+ return;
+
+ QUrl url = m_downloadQueue.dequeue();
+
+ QNetworkRequest request(url);
+ request.setRawHeader("User-Agent", "Situare");
+ QNetworkReply *reply = m_manager->get(request);
+
+ m_currentDownloads.append(reply);
+}
+
+void ImageFetcher::downloadFinished(QNetworkReply *reply)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (reply->error() == QNetworkReply::NoError) {
+ QImage image;
+ QUrl url = reply->url();
+
+ if (!image.load(reply, 0))
+ image = QImage();
+
+ //emit imageReceived(url, QPixmap::fromImage(image));
+ emit imageReceived(url, image);
+ }
+ else {
+ emit error(reply->errorString());
+ }
+
+ m_currentDownloads.removeAll(reply);
+ reply->deleteLater();
+ startNextDownload();
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#ifndef IMAGEFETCHER_H
+#define IMAGEFETCHER_H
+
+#include <QtCore>
+#include <QNetworkAccessManager>
+
+class QNetworkReply;
+class QUrl;
+
+/**
+* @brief ImageFetcher handles requests to get images.
+*
+* @author Henri Lampela
+*/
+class ImageFetcher : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ /**
+ * @brief Default constructor
+ *
+ * @param manager QNetworkAccessManager
+ * @param parent Parent object
+ */
+ ImageFetcher(QNetworkAccessManager *manager, QObject *parent = 0);
+
+/*******************************************************************************
+ * CLASS SPECIFIC MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public slots:
+
+ /**
+ * @brief Fecth image from given url
+ *
+ * @param url Image url
+ */
+ void fetchImage(const QUrl &url);
+
+private slots:
+
+ /**
+ * @brief This slot is called when network manager has finished
+ * the download. Loads image and emits imageReceived signal with
+ * url and image. If there was a error in reply emits error-signal.
+ *
+ * @param reply
+ */
+ void downloadFinished(QNetworkReply *reply);
+
+ /**
+ * @brief This slot is called when next download is started. Takes url
+ * from queue, sends request and puts request to download queue.
+ */
+ void startNextDownload();
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+ /**
+ * @brief Signal which is emitted when image
+ * is received from the server and loaded to pixmap.
+ *
+ * @param url URL to image
+ * @param image image QImage
+ */
+ //void imageReceived(const QUrl &url, const QPixmap &image);
+ void imageReceived(const QUrl &url, const QImage &image);
+
+ /**
+ * @brief Signal which is emitted when there is error
+ * in network reply.
+ *
+ * @param message error message
+ */
+ void error(const QString &message);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+ static const int MAX_PARALLEL_DOWNLOADS = 2; ///< Max simultaneous parallel downloads
+ static const int DOWNLOAD_QUEUE_SIZE = 50; ///< Max downloads waiting in queue
+
+ QList<QNetworkReply*> m_currentDownloads; ///< List of current downloads
+ QQueue<QUrl> m_downloadQueue; ///< Queue of pending requests
+ QNetworkAccessManager *m_manager; ///< Network access manager
+
+};
+
+#endif // IMAGEFETCHER_H
const QString SESSION_KEY = "session_key";
const QString SESSION_SECRET = "ss";
-const QString USER_AGENT = "User-Agent";
-const QString AGENT = "Agent";
-
// Locales
const QString LOCALE = "locale";
const QString EN_LOCALE = "en_EN";
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(requestFinished(QNetworkReply*)));
+ m_imageFetcher = new ImageFetcher(new QNetworkAccessManager(this), this);
+ connect(this, SIGNAL(fetchImage(QUrl)), m_imageFetcher, SLOT(fetchImage(QUrl)));
+ connect(m_imageFetcher, SIGNAL(imageReceived(QUrl,QImage)), this,
+ SLOT(imageReceived(QUrl, QImage)));
+
m_credentials = m_facebookAuthentication.loginCredentials();
}
}
emit userDataChanged(user, friendsList);
}
+
+void SituareService::imageReceived(const QUrl &url, const QImage &image)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << "Image URL: " << url << " size :" << image.size();
+ //ToDo: where now?
+}
#include "../facebookservice/facebookauthentication.h"
#include "../facebookservice/facebookcredentials.h"
#include "../user/user.h"
+#include "imagefetcher.h"
class QNetworkAccessManager;
class QNetworkReply;
*/
void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
+private slots:
+
+ /**
+ * @brief Slot for received images
+ *
+ * @param url Image url
+ * @param image Received image
+ */
+ void imageReceived(const QUrl &url, const QImage &image);
+
/*******************************************************************************
* SIGNALS
******************************************************************************/
void error(const QString &error);
/**
+ * @brief Signal for image fetching
+ *
+ * @param url Image url
+ */
+ void fetchImage(const QUrl &url);
+
+ /**
* @brief Signals when address data is retrieved
*
* @param address Street address
QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
FacebookAuthentication m_facebookAuthentication; ///< Pointer to FacebookAuthentication
QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
+ ImageFetcher *m_imageFetcher;
};
#endif // SITUARESERVICE_H
ui/mapviewscreen.cpp \
ui/listviewscreen.cpp \
situareservice/situareservice.cpp \
+ situareservice/imagefetcher.cpp \
cookiehandler/cookiehandler.cpp \
facebookservice/facebookcredentials.cpp \
facebookservice/facebookauthentication.cpp \
ui/updatelocation/texteditautoresizer.h \
situareservice/situareservice.h \
situareservice/situarecommon.h \
+ situareservice/imagefetcher.h \
cookiehandler/cookiehandler.h \
facebookservice/facebookcredentials.h \
facebookservice/facebookauthentication.h \