diff --git a/src/downloader.cpp b/src/downloader.cpp index 1f4de54c..34ae5d07 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include "config.h" #include "downloader.h" @@ -25,7 +27,7 @@ #define MAX_REDIRECT_LEVEL 5 -Downloader::Downloader() +Downloader::Downloader(QObject *parent) : QObject(parent) { connect(&_manager, SIGNAL(finished(QNetworkReply*)), SLOT(downloadFinished(QNetworkReply*))); diff --git a/src/downloader.h b/src/downloader.h index 507652e8..b92646b4 100644 --- a/src/downloader.h +++ b/src/downloader.h @@ -2,13 +2,14 @@ #define DOWNLOADER_H #include -#include -#include #include +#include #include #include +class QNetworkReply; + class Download { public: @@ -28,8 +29,8 @@ class Downloader : public QObject Q_OBJECT public: - static Downloader& instance() - {static Downloader i; return i;} + Downloader(QObject *parent = 0); + bool get(const QList &list); signals: @@ -56,10 +57,6 @@ private: int _level; }; - Downloader(); - Downloader(Downloader const&); - void operator=(Downloader const&); - bool doDownload(const Download &dl, const Redirect &redirect = Redirect()); bool saveToDisk(const QString &filename, QIODevice *data); diff --git a/src/gui.cpp b/src/gui.cpp index ffc32e24..a152bcdb 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -36,6 +36,7 @@ #include "powergraph.h" #include "pathview.h" #include "trackinfo.h" +#include "downloader.h" #include "filebrowser.h" #include "cpuarch.h" #include "graphtab.h" @@ -118,10 +119,12 @@ void GUI::createBrowser() void GUI::loadMaps() { + MapList ml(new Downloader(this)); + if (QFile::exists(USER_MAP_FILE)) - _maps = MapList::load(this, USER_MAP_FILE); + _maps = ml.load(USER_MAP_FILE, this); else - _maps = MapList::load(this, GLOBAL_MAP_FILE); + _maps = ml.load(GLOBAL_MAP_FILE, this); } void GUI::loadPOIs() diff --git a/src/map.cpp b/src/map.cpp index f86ad550..0bd18db1 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -5,14 +5,16 @@ #include "map.h" -Map::Map(QObject *parent, const QString &name, const QString &url) - : QObject(parent) +Map::Map(const QString &name, const QString &url, Downloader *downloader, + QObject *parent) : QObject(parent) { _name = name; _url = url; - connect(&Downloader::instance(), SIGNAL(finished()), this, - SLOT(emitLoaded())); + _downloader = downloader; + + + connect(_downloader, SIGNAL(finished()), this, SLOT(emitLoaded())); QString path = TILES_DIR + QString("/") + _name; if (!QDir().mkpath(path)) @@ -49,7 +51,7 @@ void Map::loadTilesAsync(QList &list) } if (!dl.empty()) - Downloader::instance().get(dl); + _downloader->get(dl); } void Map::loadTilesSync(QList &list) @@ -71,8 +73,8 @@ void Map::loadTilesSync(QList &list) return; QEventLoop wait; - connect(&Downloader::instance(), SIGNAL(finished()), &wait, SLOT(quit())); - if (Downloader::instance().get(dl)) + connect(_downloader, SIGNAL(finished()), &wait, SLOT(quit())); + if (_downloader->get(dl)) wait.exec(); for (int i = 0; i < list.size(); i++) { diff --git a/src/map.h b/src/map.h index cbd84333..e565a72c 100644 --- a/src/map.h +++ b/src/map.h @@ -3,13 +3,15 @@ #include "tile.h" +class Downloader; + class Map : public QObject { Q_OBJECT public: - Map(QObject *parent = 0, const QString &name = QString(), - const QString &url = QString()); + Map(const QString &name, const QString &url, Downloader *downloader, + QObject *parent = 0); const QString &name() const {return _name;} void loadTiles(QList &list, bool block); @@ -30,6 +32,8 @@ private: void loadTilesAsync(QList &list); void loadTilesSync(QList &list); + Downloader *_downloader; + QString _name; QString _url; }; diff --git a/src/maplist.cpp b/src/maplist.cpp index de65739a..f58d4d0f 100644 --- a/src/maplist.cpp +++ b/src/maplist.cpp @@ -4,7 +4,7 @@ #include "maplist.h" -QList MapList::load(QObject *parent, const QString &fileName) +QList MapList::load(const QString &fileName, QObject *parent) { QList mapList; QFileInfo fi(fileName); @@ -33,8 +33,8 @@ QList MapList::load(QObject *parent, const QString &fileName) QByteArray ba1 = list[0].trimmed(); QByteArray ba2 = list[1].trimmed(); - mapList.append(new Map(parent, QString::fromUtf8(ba1.data(), ba1.size()), - QString::fromLatin1(ba2.data(), ba2.size()))); + mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()), + QString::fromLatin1(ba2.data(), ba2.size()), _downloader, parent)); } return mapList; diff --git a/src/maplist.h b/src/maplist.h index bb505da1..b11edff7 100644 --- a/src/maplist.h +++ b/src/maplist.h @@ -6,12 +6,16 @@ #include class Map; +class Downloader; class MapList { public: - static QList load(QObject *parent = 0, - const QString &fileName = QString()); + MapList(Downloader *downloader) : _downloader(downloader) {} + QList load(const QString &fileName, QObject *parent = 0); + +private: + Downloader *_downloader; }; #endif // MAPLIST_H