1 /***************************************************************************
2  *   Copyright (C) 2007 by Kai Winter   *
3  *   kaiwinter@gmx.de   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef MAPNETWORK_H
21 #define MAPNETWORK_H
22 
23 #include <QObject>
24 #include <QDebug>
25 #include <QList>
26 #include <QQueue>
27 #include <QPixmap>
28 #include <QMutex>
29 #include <QUrl>
30 
31 #include "IImageManager.h"
32 /**
33     @author Kai Winter <kaiwinter@gmx.de>
34 */
35 class ImageManager;
36 class MapNetwork : QObject
37 {
38     Q_OBJECT
39     public:
40         MapNetwork(IImageManager* parent);
41         ~MapNetwork();
42 
43         void load(const QString& hash, const QString& host, const QString& url);
44 
45         /*!
46          * checks if the given url is already loading
47          * @param url the url of the image
48          * @return boolean, if the image is already loading
49          */
50         bool isLoading(QString hash);
51 
52         /*!
53          * Aborts all current loading threads.
54          * This is useful when changing the zoom-factor, though newly needed images loads faster
55         */
56         void abortLoading();
57 
58     private:
59         IImageManager* parent;
60         QNetworkAccessManager* m_networkManager;
61         QMap<QNetworkReply*, LoadingRequest*> loadingMap;
62         QMap<QTimer*, QNetworkReply*> timeoutMap;
63         QQueue<LoadingRequest*> loadingRequests;
64 
65         MapNetwork& operator=(const MapNetwork& rhs);
66         MapNetwork(const MapNetwork& old);
67         void launchRequest();
68         void launchRequest(QUrl url, LoadingRequest* R);
69 
70 
71     private slots:
72         void requestFinished(QNetworkReply* reply);
73         void timeout();
74 };
75 
76 #endif
77