Removed review defect comments and fixed few other comments
[situare] / src / map / mapfetcher.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare 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 General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #ifndef MAPFETCHER_H
23 #define MAPFETCHER_H
24
25 #include <QtCore>
26 #include <QNetworkAccessManager>
27
28 #include "mapfetcher.h"
29
30 class QNetworkReply;
31 class QUrl;
32
33 /**
34 * @brief MapFetcher handles requests to get map tiles.
35 *
36 * @author Jussi Laitinen jussi.laitinen@ixonos.com
37 */
38 class MapFetcher : public QObject
39 {
40     Q_OBJECT
41
42 public:
43     /**
44     * @brief Constructor for MapFetcher.
45     *
46     * @param manager Network access manager
47     * @param parent parent object
48     */
49     MapFetcher(QNetworkAccessManager *manager, QObject *parent = 0);
50
51     ~MapFetcher();
52
53     /**
54     * @brief Fetch image from given URL.
55     *
56     * @param url URL to image
57     */
58     void fetchMapImage(const QUrl &url);
59
60 signals:    
61     /**
62     * @brief Signal which is emitted when a map tile
63     * is received from the server and loaded to pixmap.
64     *
65     * @param url URL to image
66     * @param image image pixmap
67     */
68     void mapImageReceived(const QUrl &url, const QPixmap &image);
69
70     /**
71     * @brief Signal which is emitted when there is error
72     * in network reply.
73     *
74     * @param message error message
75     */
76     void error(const QString &message);
77
78 private slots:
79
80     /**
81     * @brief This slot is called when network manager has finished
82     * the download. Loads image and emits imageReceived signal with
83     * url and image. If there was a error in reply emits error-signal.
84     *
85     * @param reply
86     */
87     void downloadFinished(QNetworkReply *reply);
88
89     /**
90     * @brief This slot is called when next download is started. Takes url
91     * from queue, sends request and puts request to download queue.
92     */
93     void startNextDownload();
94
95 private:
96
97     /**
98     * @brief Loads image from cache if it's available and emits imageReveived
99     * signal with url and image. If image is in cache returns true, false
100     * otherwise.
101     *
102     * @param url
103     * @return bool true if image was loaded from cache, false otherwise
104     */
105     bool loadImageFromCache(const QUrl &url);
106
107     QNetworkAccessManager *m_manager;       ///< Network access manager
108     QList<QNetworkReply*> currentDownloads; ///< List of current downloads
109     QQueue<QUrl> downloadQueue;             ///< Queue of pending requests
110 };
111
112 #endif