mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02: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 <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "downloader.h"
|
#include "downloader.h"
|
||||||
|
|
||||||
@ -25,7 +27,7 @@
|
|||||||
#define MAX_REDIRECT_LEVEL 5
|
#define MAX_REDIRECT_LEVEL 5
|
||||||
|
|
||||||
|
|
||||||
Downloader::Downloader()
|
Downloader::Downloader(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
connect(&_manager, SIGNAL(finished(QNetworkReply*)),
|
connect(&_manager, SIGNAL(finished(QNetworkReply*)),
|
||||||
SLOT(downloadFinished(QNetworkReply*)));
|
SLOT(downloadFinished(QNetworkReply*)));
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
#define DOWNLOADER_H
|
#define DOWNLOADER_H
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
|
||||||
|
class QNetworkReply;
|
||||||
|
|
||||||
class Download
|
class Download
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -28,8 +29,8 @@ class Downloader : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Downloader& instance()
|
Downloader(QObject *parent = 0);
|
||||||
{static Downloader i; return i;}
|
|
||||||
bool get(const QList<Download> &list);
|
bool get(const QList<Download> &list);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -56,10 +57,6 @@ private:
|
|||||||
int _level;
|
int _level;
|
||||||
};
|
};
|
||||||
|
|
||||||
Downloader();
|
|
||||||
Downloader(Downloader const&);
|
|
||||||
void operator=(Downloader const&);
|
|
||||||
|
|
||||||
bool doDownload(const Download &dl, const Redirect &redirect = Redirect());
|
bool doDownload(const Download &dl, const Redirect &redirect = Redirect());
|
||||||
bool saveToDisk(const QString &filename, QIODevice *data);
|
bool saveToDisk(const QString &filename, QIODevice *data);
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "powergraph.h"
|
#include "powergraph.h"
|
||||||
#include "pathview.h"
|
#include "pathview.h"
|
||||||
#include "trackinfo.h"
|
#include "trackinfo.h"
|
||||||
|
#include "downloader.h"
|
||||||
#include "filebrowser.h"
|
#include "filebrowser.h"
|
||||||
#include "cpuarch.h"
|
#include "cpuarch.h"
|
||||||
#include "graphtab.h"
|
#include "graphtab.h"
|
||||||
@ -118,10 +119,12 @@ void GUI::createBrowser()
|
|||||||
|
|
||||||
void GUI::loadMaps()
|
void GUI::loadMaps()
|
||||||
{
|
{
|
||||||
|
MapList ml(new Downloader(this));
|
||||||
|
|
||||||
if (QFile::exists(USER_MAP_FILE))
|
if (QFile::exists(USER_MAP_FILE))
|
||||||
_maps = MapList::load(this, USER_MAP_FILE);
|
_maps = ml.load(USER_MAP_FILE, this);
|
||||||
else
|
else
|
||||||
_maps = MapList::load(this, GLOBAL_MAP_FILE);
|
_maps = ml.load(GLOBAL_MAP_FILE, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::loadPOIs()
|
void GUI::loadPOIs()
|
||||||
|
16
src/map.cpp
16
src/map.cpp
@ -5,14 +5,16 @@
|
|||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
|
|
||||||
Map::Map(QObject *parent, const QString &name, const QString &url)
|
Map::Map(const QString &name, const QString &url, Downloader *downloader,
|
||||||
: QObject(parent)
|
QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
_name = name;
|
_name = name;
|
||||||
_url = url;
|
_url = url;
|
||||||
|
|
||||||
connect(&Downloader::instance(), SIGNAL(finished()), this,
|
_downloader = downloader;
|
||||||
SLOT(emitLoaded()));
|
|
||||||
|
|
||||||
|
connect(_downloader, SIGNAL(finished()), this, SLOT(emitLoaded()));
|
||||||
|
|
||||||
QString path = TILES_DIR + QString("/") + _name;
|
QString path = TILES_DIR + QString("/") + _name;
|
||||||
if (!QDir().mkpath(path))
|
if (!QDir().mkpath(path))
|
||||||
@ -49,7 +51,7 @@ void Map::loadTilesAsync(QList<Tile> &list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!dl.empty())
|
if (!dl.empty())
|
||||||
Downloader::instance().get(dl);
|
_downloader->get(dl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::loadTilesSync(QList<Tile> &list)
|
void Map::loadTilesSync(QList<Tile> &list)
|
||||||
@ -71,8 +73,8 @@ void Map::loadTilesSync(QList<Tile> &list)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QEventLoop wait;
|
QEventLoop wait;
|
||||||
connect(&Downloader::instance(), SIGNAL(finished()), &wait, SLOT(quit()));
|
connect(_downloader, SIGNAL(finished()), &wait, SLOT(quit()));
|
||||||
if (Downloader::instance().get(dl))
|
if (_downloader->get(dl))
|
||||||
wait.exec();
|
wait.exec();
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
@ -3,13 +3,15 @@
|
|||||||
|
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
|
||||||
|
class Downloader;
|
||||||
|
|
||||||
class Map : public QObject
|
class Map : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Map(QObject *parent = 0, const QString &name = QString(),
|
Map(const QString &name, const QString &url, Downloader *downloader,
|
||||||
const QString &url = QString());
|
QObject *parent = 0);
|
||||||
|
|
||||||
const QString &name() const {return _name;}
|
const QString &name() const {return _name;}
|
||||||
void loadTiles(QList<Tile> &list, bool block);
|
void loadTiles(QList<Tile> &list, bool block);
|
||||||
@ -30,6 +32,8 @@ private:
|
|||||||
void loadTilesAsync(QList<Tile> &list);
|
void loadTilesAsync(QList<Tile> &list);
|
||||||
void loadTilesSync(QList<Tile> &list);
|
void loadTilesSync(QList<Tile> &list);
|
||||||
|
|
||||||
|
Downloader *_downloader;
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
QString _url;
|
QString _url;
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "maplist.h"
|
#include "maplist.h"
|
||||||
|
|
||||||
|
|
||||||
QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
QList<Map*> MapList::load(const QString &fileName, QObject *parent)
|
||||||
{
|
{
|
||||||
QList<Map*> mapList;
|
QList<Map*> mapList;
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
@ -33,8 +33,8 @@ QList<Map*> MapList::load(QObject *parent, const QString &fileName)
|
|||||||
QByteArray ba1 = list[0].trimmed();
|
QByteArray ba1 = list[0].trimmed();
|
||||||
QByteArray ba2 = list[1].trimmed();
|
QByteArray ba2 = list[1].trimmed();
|
||||||
|
|
||||||
mapList.append(new Map(parent, QString::fromUtf8(ba1.data(), ba1.size()),
|
mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()),
|
||||||
QString::fromLatin1(ba2.data(), ba2.size())));
|
QString::fromLatin1(ba2.data(), ba2.size()), _downloader, parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapList;
|
return mapList;
|
||||||
|
@ -6,12 +6,16 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class Map;
|
class Map;
|
||||||
|
class Downloader;
|
||||||
|
|
||||||
class MapList
|
class MapList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static QList<Map*> load(QObject *parent = 0,
|
MapList(Downloader *downloader) : _downloader(downloader) {}
|
||||||
const QString &fileName = QString());
|
QList<Map*> load(const QString &fileName, QObject *parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Downloader *_downloader;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPLIST_H
|
#endif // MAPLIST_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user