2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
6 Sami Rämö - sami.ramo@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 #include <QNetworkAccessManager>
29 #include "mapfetcher.h"
35 * @brief MapFetcher handles requests to get map tiles.
37 * @author Jussi Laitinen jussi.laitinen@ixonos.com
39 class MapFetcher : public QObject
45 * @brief Constructor for MapFetcher.
47 * @param manager Network access manager
48 * @param parent parent object
50 MapFetcher(QNetworkAccessManager *manager, QObject *parent = 0);
52 /*******************************************************************************
53 * CLASS SPECIFIC MEMBER FUNCTIONS AND SLOTS
54 ******************************************************************************/
57 * @brief Enqueue fetching of map image
59 * Image fetching is triggered after events have been processed
60 * so the UI stays responsive.
62 * @param url URL of the image to be fetched
64 void enqueueFetchMapImage(QUrl url);
68 * @brief Loads image from cache if it's available and emits imageReveived
69 * signal with url and image. If image is in cache returns true, false
73 * @return bool true if image was loaded from cache, false otherwise
75 bool loadImageFromCache(const QUrl &url);
80 * @brief This slot is called when network manager has finished
81 * the download. Loads image and emits imageReceived signal with
82 * url and image. If there was a error in reply emits error-signal.
86 void downloadFinished(QNetworkReply *reply);
89 * @brief Fetch next map image.
91 * Next queued request is taken from the queue and fetching is started
96 * @brief This slot is called when next download is started. Takes url
97 * from queue, sends request and puts request to download queue.
99 void startNextDownload();
101 /*******************************************************************************
103 ******************************************************************************/
106 * @brief Signal which is emitted when a map tile
107 * is received from the server and loaded to pixmap.
109 * @param url URL to image
110 * @param image image pixmap
112 void mapImageReceived(const QUrl &url, const QPixmap &image);
115 * @brief Signal which is emitted when there is error
118 * @param message error message
120 void error(const QString &message);
122 /*******************************************************************************
124 ******************************************************************************/
126 static const int MAX_PARALLEL_DOWNLOADS = 2; ///< Max simultaneous parallel downloads
127 static const int DOWNLOAD_QUEUE_SIZE = 50; ///< Max downloads waiting in queue
129 QList<QNetworkReply*> m_currentDownloads; ///< List of current downloads
130 QQueue<QUrl> m_downloadQueue; ///< Queue of pending requests
131 QList<QUrl> m_fetchMapImagesList; ///< "Queue" for map image fetching requests
132 bool m_isFetchMapImagesTimerRunning; ///< is the singleshot timer already running
133 QNetworkAccessManager *m_manager; ///< Network access manager