2016-09-27 16:37:18 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-27 16:37:18 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-27 16:37:18 +03:00
|
|
|
*/
|
|
|
|
#include "history/history_location_manager.h"
|
|
|
|
|
|
|
|
#include "mainwidget.h"
|
2017-04-13 11:27:10 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 13:23:56 +03:00
|
|
|
#include "platform/platform_specific.h"
|
2016-09-27 16:37:18 +03:00
|
|
|
|
2017-02-03 13:17:40 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kCoordPrecision = 8;
|
2017-03-06 11:08:59 +03:00
|
|
|
constexpr auto kMaxHttpRedirects = 5;
|
2017-02-03 13:17:40 +03:00
|
|
|
|
2018-10-08 21:14:05 +03:00
|
|
|
GeoPointLocation ComputeLocation(const LocationCoords &coords) {
|
|
|
|
int32 w = st::locationSize.width(), h = st::locationSize.height();
|
|
|
|
int32 zoom = 15, scale = 1;
|
|
|
|
if (cScale() == dbisTwo || cRetina()) {
|
|
|
|
scale = 2;
|
|
|
|
zoom = 16;
|
|
|
|
} else {
|
|
|
|
w = convertScale(w);
|
|
|
|
h = convertScale(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = GeoPointLocation();
|
|
|
|
result.lat = coords.lat();
|
|
|
|
result.lon = coords.lon();
|
|
|
|
result.access = coords.accessHash();
|
|
|
|
result.width = w;
|
|
|
|
result.height = h;
|
|
|
|
result.zoom = zoom;
|
|
|
|
result.scale = scale;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-03 13:17:40 +03:00
|
|
|
} // namespace
|
|
|
|
|
2018-01-25 13:10:52 +03:00
|
|
|
QString LocationClickHandler::copyToClipboardText() const {
|
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
|
2016-09-27 16:37:18 +03:00
|
|
|
QString LocationClickHandler::copyToClipboardContextItemText() const {
|
|
|
|
return lang(lng_context_copy_link);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:13:48 +03:00
|
|
|
void LocationClickHandler::onClick(ClickContext context) const {
|
2016-09-27 16:37:18 +03:00
|
|
|
if (!psLaunchMaps(_coords)) {
|
|
|
|
QDesktopServices::openUrl(_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationClickHandler::setup() {
|
2017-02-03 13:17:40 +03:00
|
|
|
auto latlon = _coords.latAsString() + ',' + _coords.lonAsString();
|
2016-09-27 16:37:18 +03:00
|
|
|
_text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16");
|
|
|
|
}
|
|
|
|
|
2018-10-08 21:14:05 +03:00
|
|
|
LocationData::LocationData(const LocationCoords &coords)
|
|
|
|
: coords(coords)
|
|
|
|
, thumb(ComputeLocation(coords)) {
|
2016-09-27 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
2018-07-14 00:25:47 +03:00
|
|
|
void LocationData::load(Data::FileOrigin origin) {
|
2018-10-08 21:14:05 +03:00
|
|
|
thumb->load(origin, false, false);
|
2016-09-27 16:37:18 +03:00
|
|
|
}
|