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
|
|
|
*/
|
|
|
|
#include "history/history_location_manager.h"
|
|
|
|
|
|
|
|
#include "mainwidget.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2016-09-27 13:37:18 +00:00
|
|
|
|
2017-02-03 10:17:40 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kCoordPrecision = 8;
|
2017-03-06 08:08:59 +00:00
|
|
|
constexpr auto kMaxHttpRedirects = 5;
|
2017-02-03 10:17:40 +00:00
|
|
|
|
2018-10-08 18:14:05 +00: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 10:17:40 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
QString LocationClickHandler::copyToClipboardText() const {
|
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
|
2016-09-27 13:37:18 +00:00
|
|
|
QString LocationClickHandler::copyToClipboardContextItemText() const {
|
|
|
|
return lang(lng_context_copy_link);
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void LocationClickHandler::onClick(ClickContext context) const {
|
2016-09-27 13:37:18 +00:00
|
|
|
if (!psLaunchMaps(_coords)) {
|
|
|
|
QDesktopServices::openUrl(_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationClickHandler::setup() {
|
2017-02-03 10:17:40 +00:00
|
|
|
auto latlon = _coords.latAsString() + ',' + _coords.lonAsString();
|
2016-09-27 13:37:18 +00:00
|
|
|
_text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16");
|
|
|
|
}
|
|
|
|
|
2018-10-08 18:14:05 +00:00
|
|
|
LocationData::LocationData(const LocationCoords &coords)
|
|
|
|
: coords(coords)
|
|
|
|
, thumb(ComputeLocation(coords)) {
|
2016-09-27 13:37:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void LocationData::load(Data::FileOrigin origin) {
|
2018-10-08 18:14:05 +00:00
|
|
|
thumb->load(origin, false, false);
|
2016-09-27 13:37:18 +00:00
|
|
|
}
|