2016-09-27 13:37:18 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-27 13:37:18 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-27 13:37:18 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
void initLocationManager();
|
|
|
|
void deinitLocationManager();
|
|
|
|
|
2017-02-03 10:17:40 +00:00
|
|
|
class LocationCoords {
|
|
|
|
public:
|
|
|
|
LocationCoords() = default;
|
2018-06-26 13:58:29 +00:00
|
|
|
explicit LocationCoords(const MTPDgeoPoint &point)
|
|
|
|
: _lat(point.vlat.v)
|
|
|
|
, _lon(point.vlong.v)
|
|
|
|
, _access(point.vaccess_hash.v) {
|
2016-09-27 13:37:18 +00:00
|
|
|
}
|
2017-02-03 10:17:40 +00:00
|
|
|
|
|
|
|
QString latAsString() const {
|
|
|
|
return asString(_lat);
|
2016-09-27 13:37:18 +00:00
|
|
|
}
|
2017-02-03 10:17:40 +00:00
|
|
|
QString lonAsString() const {
|
|
|
|
return asString(_lon);
|
2016-09-27 13:37:18 +00:00
|
|
|
}
|
2017-02-03 10:17:40 +00:00
|
|
|
MTPGeoPoint toMTP() const {
|
2018-06-26 13:58:29 +00:00
|
|
|
return MTP_geoPoint(
|
|
|
|
MTP_double(_lon),
|
|
|
|
MTP_double(_lat),
|
|
|
|
MTP_long(_access));
|
2017-02-03 10:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static QString asString(float64 value) {
|
|
|
|
static constexpr auto kPrecision = 6;
|
|
|
|
return QString::number(value, 'f', kPrecision);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline bool operator==(const LocationCoords &a, const LocationCoords &b) {
|
|
|
|
return (a._lat == b._lat) && (a._lon == b._lon);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline bool operator<(const LocationCoords &a, const LocationCoords &b) {
|
|
|
|
return (a._lat < b._lat) || ((a._lat == b._lat) && (a._lon < b._lon));
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline uint qHash(const LocationCoords &t, uint seed = 0) {
|
2016-09-27 13:37:18 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2017-02-03 10:17:40 +00:00
|
|
|
return qHash(QtPrivate::QHashCombine().operator()(qHash(t._lat), t._lon), seed);
|
2016-09-27 13:37:18 +00:00
|
|
|
#else // OS_MAC_OLD
|
2017-02-03 10:17:40 +00:00
|
|
|
uint h1 = qHash(t._lat, seed);
|
|
|
|
uint h2 = qHash(t._lon, seed);
|
|
|
|
return ((h1 << 16) | (h1 >> 16)) ^ h2 ^ seed;
|
2016-09-27 13:37:18 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2017-02-03 10:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float64 _lat = 0;
|
|
|
|
float64 _lon = 0;
|
2018-06-26 13:58:29 +00:00
|
|
|
uint64 _access = 0;
|
2017-02-03 10:17:40 +00:00
|
|
|
|
|
|
|
};
|
2016-09-27 13:37:18 +00:00
|
|
|
|
|
|
|
struct LocationData {
|
|
|
|
LocationData(const LocationCoords &coords) : coords(coords), loading(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
LocationCoords coords;
|
|
|
|
ImagePtr thumb;
|
|
|
|
bool loading;
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void load(Data::FileOrigin origin);
|
2016-09-27 13:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class LocationClickHandler : public ClickHandler {
|
|
|
|
public:
|
|
|
|
LocationClickHandler(const LocationCoords &coords) : _coords(coords) {
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2016-09-27 13:37:18 +00:00
|
|
|
|
|
|
|
QString tooltip() const override {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString dragText() const override {
|
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
QString copyToClipboardText() const override;
|
2016-09-27 13:37:18 +00:00
|
|
|
QString copyToClipboardContextItemText() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void setup();
|
|
|
|
LocationCoords _coords;
|
|
|
|
QString _text;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class LocationManager : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
void init();
|
|
|
|
void reinit();
|
|
|
|
void deinit();
|
|
|
|
|
|
|
|
void getData(LocationData *data);
|
|
|
|
|
|
|
|
~LocationManager() {
|
|
|
|
deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onFinished(QNetworkReply *reply);
|
|
|
|
void onFailed(QNetworkReply *reply);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void failed(LocationData *data);
|
|
|
|
|
|
|
|
QNetworkAccessManager *manager = nullptr;
|
|
|
|
QMap<QNetworkReply*, LocationData*> dataLoadings, imageLoadings;
|
|
|
|
QMap<LocationData*, int32> serverRedirects;
|
2016-10-18 11:48:03 +00:00
|
|
|
ImagePtr *notLoadedPlaceholder = nullptr;
|
2016-09-27 13:37:18 +00:00
|
|
|
|
|
|
|
};
|