Integrated fetching of the maps from OSM server
[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 *
37 *
38 * @class MapFetcher mapfetcher.h "map/mapfetcher.h"
39 */
40 class MapFetcher : public QObject
41 {
42     Q_OBJECT
43
44 public:
45     /**
46     * @brief Constructor for MapFetcher.
47     *
48     * @fn MapFetcher
49     * @param parent parent object
50     */
51     MapFetcher(QNetworkAccessManager *manager, QObject *parent = 0);
52
53     ~MapFetcher();
54
55     /**
56     * @brief Fetch image from given URL.
57     *
58     * @fn fetchMapImage
59     * @param url URL to image
60     */
61     void fetchMapImage(const QUrl &url);
62
63 signals:    
64     /**
65     * @brief Signal which is emitted when a map tile
66     * is received from the server and loaded to pixmap.
67     *
68     * @fn mapImageReceived
69     * @param url URL to image
70     * @param image image pixmap
71     */
72     void mapImageReceived(const QUrl &url, const QPixmap &image);
73
74     /**
75     * @brief Signal which is emitted when there is error
76     * in network reply.
77     *
78     * @fn error
79     * @param message error message
80     */
81     void error(const QString &message);
82
83 public slots:
84
85     /**
86     * @brief This slot is called when network manager has finished
87     * the download.
88     *
89     * @fn downloadFinished
90     * @param reply
91     */
92     void downloadFinished(QNetworkReply *reply);
93
94     /**
95     * @brief This slot is called when next download is started.
96     *
97     * @fn startNextDownload
98     */
99     void startNextDownload();
100
101 private:
102
103     QNetworkAccessManager *m_manager;
104     QList<QNetworkReply*> currentDownloads;
105     QQueue<QUrl> downloadQueue;
106 };
107
108 #endif