mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52:09 +01:00
Fixed QNetworkManager related crashes on program termination.
This commit is contained in:
parent
a253ac1796
commit
93313da01d
@ -1,5 +1,7 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#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*)));
|
||||
|
@ -2,13 +2,14 @@
|
||||
#define DOWNLOADER_H
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
|
||||
|
||||
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<Download> &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);
|
||||
|
||||
|
@ -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()
|
||||
|
16
src/map.cpp
16
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<Tile> &list)
|
||||
}
|
||||
|
||||
if (!dl.empty())
|
||||
Downloader::instance().get(dl);
|
||||
_downloader->get(dl);
|
||||
}
|
||||
|
||||
void Map::loadTilesSync(QList<Tile> &list)
|
||||
@ -71,8 +73,8 @@ void Map::loadTilesSync(QList<Tile> &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++) {
|
||||
|
@ -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<Tile> &list, bool block);
|
||||
@ -30,6 +32,8 @@ private:
|
||||
void loadTilesAsync(QList<Tile> &list);
|
||||
void loadTilesSync(QList<Tile> &list);
|
||||
|
||||
Downloader *_downloader;
|
||||
|
||||
QString _name;
|
||||
QString _url;
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
||||
QList<Map*> MapList::load(const QString &fileName, QObject *parent)
|
||||
{
|
||||
QList<Map*> mapList;
|
||||
QFileInfo fi(fileName);
|
||||
@ -33,8 +33,8 @@ QList<Map*> 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;
|
||||
|
@ -6,12 +6,16 @@
|
||||
#include <QObject>
|
||||
|
||||
class Map;
|
||||
class Downloader;
|
||||
|
||||
class MapList
|
||||
{
|
||||
public:
|
||||
static QList<Map*> load(QObject *parent = 0,
|
||||
const QString &fileName = QString());
|
||||
MapList(Downloader *downloader) : _downloader(downloader) {}
|
||||
QList<Map*> load(const QString &fileName, QObject *parent = 0);
|
||||
|
||||
private:
|
||||
Downloader *_downloader;
|
||||
};
|
||||
|
||||
#endif // MAPLIST_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user