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"
|
2018-10-23 13:44:42 +04:00
|
|
|
#include "ui/image/image.h"
|
2019-01-04 15:09:48 +04:00
|
|
|
#include "data/data_file_origin.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) {
|
2018-10-15 14:44:48 +03:00
|
|
|
const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200;
|
2018-10-16 12:05:32 +03:00
|
|
|
const auto zoom = 13 + (scale - 1);
|
|
|
|
const auto w = st::locationSize.width() / scale;
|
|
|
|
const auto h = st::locationSize.height() / scale;
|
2018-10-08 21:14:05 +03:00
|
|
|
|
|
|
|
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)
|
2018-10-23 13:08:50 +04:00
|
|
|
, thumb(Images::Create(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
|
|
|
}
|