mirror of https://github.com/procxx/kepka.git
rpcClear for mediaview, ImageLink changed to Location
This commit is contained in:
parent
5b345cbc2d
commit
0e49c13968
|
@ -49,8 +49,8 @@ namespace {
|
||||||
PhotosData photosData;
|
PhotosData photosData;
|
||||||
DocumentsData documentsData;
|
DocumentsData documentsData;
|
||||||
|
|
||||||
typedef QHash<QString, ImageLinkData*> ImageLinksData;
|
typedef QHash<LocationCoords, LocationData*> LocationsData;
|
||||||
ImageLinksData imageLinksData;
|
LocationsData locationsData;
|
||||||
|
|
||||||
typedef QHash<WebPageId, WebPageData*> WebPagesData;
|
typedef QHash<WebPageId, WebPageData*> WebPagesData;
|
||||||
WebPagesData webPagesData;
|
WebPagesData webPagesData;
|
||||||
|
@ -1671,27 +1671,14 @@ namespace App {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageLinkData *imageLink(const QString &imageLink) {
|
LocationData *location(const LocationCoords &coords) {
|
||||||
ImageLinksData::const_iterator i = imageLinksData.constFind(imageLink);
|
LocationsData::const_iterator i = locationsData.constFind(coords);
|
||||||
if (i == imageLinksData.cend()) {
|
if (i == locationsData.cend()) {
|
||||||
i = imageLinksData.insert(imageLink, new ImageLinkData(imageLink));
|
i = locationsData.insert(coords, new LocationData(coords));
|
||||||
}
|
}
|
||||||
return i.value();
|
return i.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageLinkData *imageLinkSet(const QString &imageLink, ImageLinkType type) {
|
|
||||||
ImageLinksData::const_iterator i = imageLinksData.constFind(imageLink);
|
|
||||||
ImageLinkData *result;
|
|
||||||
if (i == imageLinksData.cend()) {
|
|
||||||
result = new ImageLinkData(imageLink);
|
|
||||||
imageLinksData.insert(imageLink, result);
|
|
||||||
result->type = type;
|
|
||||||
} else {
|
|
||||||
result = i.value();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void forgetMedia() {
|
void forgetMedia() {
|
||||||
lastPhotos.clear();
|
lastPhotos.clear();
|
||||||
lastPhotosMap.clear();
|
lastPhotosMap.clear();
|
||||||
|
@ -1701,7 +1688,7 @@ namespace App {
|
||||||
for (DocumentsData::const_iterator i = ::documentsData.cbegin(), e = ::documentsData.cend(); i != e; ++i) {
|
for (DocumentsData::const_iterator i = ::documentsData.cbegin(), e = ::documentsData.cend(); i != e; ++i) {
|
||||||
i.value()->forget();
|
i.value()->forget();
|
||||||
}
|
}
|
||||||
for (ImageLinksData::const_iterator i = imageLinksData.cbegin(), e = imageLinksData.cend(); i != e; ++i) {
|
for (LocationsData::const_iterator i = ::locationsData.cbegin(), e = ::locationsData.cend(); i != e; ++i) {
|
||||||
i.value()->thumb->forget();
|
i.value()->thumb->forget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,8 +134,7 @@ namespace App {
|
||||||
DocumentData *documentSet(const DocumentId &document, DocumentData *convert, const uint64 &access, int32 date, const QVector<MTPDocumentAttribute> &attributes, const QString &mime, const ImagePtr &thumb, int32 dc, int32 size, const StorageImageLocation &thumbLocation);
|
DocumentData *documentSet(const DocumentId &document, DocumentData *convert, const uint64 &access, int32 date, const QVector<MTPDocumentAttribute> &attributes, const QString &mime, const ImagePtr &thumb, int32 dc, int32 size, const StorageImageLocation &thumbLocation);
|
||||||
WebPageData *webPage(const WebPageId &webPage);
|
WebPageData *webPage(const WebPageId &webPage);
|
||||||
WebPageData *webPageSet(const WebPageId &webPage, WebPageData *convert, const QString &, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill);
|
WebPageData *webPageSet(const WebPageId &webPage, WebPageData *convert, const QString &, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill);
|
||||||
ImageLinkData *imageLink(const QString &imageLink);
|
LocationData *location(const LocationCoords &coords);
|
||||||
ImageLinkData *imageLinkSet(const QString &imageLink, ImageLinkType type);
|
|
||||||
void forgetMedia();
|
void forgetMedia();
|
||||||
|
|
||||||
MTPPhoto photoFromUserPhoto(MTPint userId, MTPint date, const MTPUserProfilePhoto &photo);
|
MTPPhoto photoFromUserPhoto(MTPint userId, MTPint date, const MTPUserProfilePhoto &photo);
|
||||||
|
|
|
@ -955,13 +955,13 @@ void CustomTextLink::onClick(Qt::MouseButton button) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationLink::onClick(Qt::MouseButton button) const {
|
void LocationLink::onClick(Qt::MouseButton button) const {
|
||||||
if (!psLaunchMaps(_lat, _lon)) {
|
if (!psLaunchMaps(_coords)) {
|
||||||
QDesktopServices::openUrl(_text);
|
QDesktopServices::openUrl(_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationLink::setup() {
|
void LocationLink::setup() {
|
||||||
QString latlon = _lat + ',' + _lon;
|
QString latlon(qsl("%1,%2").arg(_coords.lat).arg(_coords.lon));
|
||||||
_text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16");
|
_text = qsl("https://maps.google.com/maps?q=") + latlon + qsl("&ll=") + latlon + qsl("&z=16");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -424,12 +424,29 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LocationCoords {
|
||||||
|
LocationCoords() : lat(0), lon(0) {
|
||||||
|
}
|
||||||
|
LocationCoords(float64 lat, float64 lon) : lat(lat), lon(lon) {
|
||||||
|
}
|
||||||
|
float64 lat, lon;
|
||||||
|
};
|
||||||
|
inline bool operator==(const LocationCoords &a, const LocationCoords &b) {
|
||||||
|
return (a.lat == b.lat) && (a.lon == b.lon);
|
||||||
|
}
|
||||||
|
inline bool operator<(const LocationCoords &a, const LocationCoords &b) {
|
||||||
|
return (a.lat < b.lat) || ((a.lat == b.lat) && (a.lon < b.lon));
|
||||||
|
}
|
||||||
|
inline uint qHash(const LocationCoords &t, uint seed = 0) {
|
||||||
|
return qHash(QtPrivate::QHashCombine().operator()(qHash(t.lat), t.lon), seed);
|
||||||
|
}
|
||||||
|
|
||||||
class LocationLink : public ITextLink {
|
class LocationLink : public ITextLink {
|
||||||
TEXT_LINK_CLASS(LocationLink)
|
TEXT_LINK_CLASS(LocationLink)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LocationLink(const QString &lat, const QString &lon) : _lat(lat), _lon(lon) {
|
LocationLink(const LocationCoords &coords) : _coords(coords) {
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +467,8 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
QString _lat, _lon, _text;
|
LocationCoords _coords;
|
||||||
|
QString _text;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5612,10 +5612,10 @@ HistoryWebPage::~HistoryWebPage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
ImageLinkManager manager;
|
LocationManager manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkManager::init() {
|
void LocationManager::init() {
|
||||||
if (manager) delete manager;
|
if (manager) delete manager;
|
||||||
manager = new QNetworkAccessManager();
|
manager = new QNetworkAccessManager();
|
||||||
App::setProxySettings(*manager);
|
App::setProxySettings(*manager);
|
||||||
|
@ -5635,11 +5635,11 @@ void ImageLinkManager::init() {
|
||||||
black = new ImagePtr(p, "PNG");
|
black = new ImagePtr(p, "PNG");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkManager::reinit() {
|
void LocationManager::reinit() {
|
||||||
if (manager) App::setProxySettings(*manager);
|
if (manager) App::setProxySettings(*manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkManager::deinit() {
|
void LocationManager::deinit() {
|
||||||
if (manager) {
|
if (manager) {
|
||||||
delete manager;
|
delete manager;
|
||||||
manager = 0;
|
manager = 0;
|
||||||
|
@ -5664,33 +5664,27 @@ void deinitImageLinkManager() {
|
||||||
manager.deinit();
|
manager.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkManager::getData(ImageLinkData *data) {
|
void LocationManager::getData(LocationData *data) {
|
||||||
if (!manager) {
|
if (!manager) {
|
||||||
DEBUG_LOG(("App Error: getting image link data without manager init!"));
|
DEBUG_LOG(("App Error: getting image link data without manager init!"));
|
||||||
return failed(data);
|
return failed(data);
|
||||||
}
|
}
|
||||||
QString url;
|
|
||||||
switch (data->type) {
|
int32 w = st::locationSize.width(), h = st::locationSize.height();
|
||||||
case GoogleMapsLink: {
|
int32 zoom = 13, scale = 1;
|
||||||
int32 w = st::locationSize.width(), h = st::locationSize.height();
|
if (cScale() == dbisTwo || cRetina()) {
|
||||||
int32 zoom = 13, scale = 1;
|
scale = 2;
|
||||||
if (cScale() == dbisTwo || cRetina()) {
|
} else {
|
||||||
scale = 2;
|
w = convertScale(w);
|
||||||
} else {
|
h = convertScale(h);
|
||||||
w = convertScale(w);
|
|
||||||
h = convertScale(h);
|
|
||||||
}
|
|
||||||
url = qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + data->id.mid(9) + qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|").arg(zoom).arg(w).arg(h).arg(scale) + data->id.mid(9) + qsl("&sensor=false");
|
|
||||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
|
|
||||||
imageLoadings[reply] = data;
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
failed(data);
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
|
QString coords = qsl("%1,%2").arg(data->coords.lat).arg(data->coords.lon);
|
||||||
|
QString url = qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords + qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|").arg(zoom).arg(w).arg(h).arg(scale) + coords + qsl("&sensor=false");
|
||||||
|
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
|
||||||
|
imageLoadings[reply] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkManager::onFinished(QNetworkReply *reply) {
|
void LocationManager::onFinished(QNetworkReply *reply) {
|
||||||
if (!manager) return;
|
if (!manager) return;
|
||||||
if (reply->error() != QNetworkReply::NoError) return onFailed(reply);
|
if (reply->error() != QNetworkReply::NoError) return onFailed(reply);
|
||||||
|
|
||||||
|
@ -5700,9 +5694,9 @@ void ImageLinkManager::onFinished(QNetworkReply *reply) {
|
||||||
if (status == 301 || status == 302) {
|
if (status == 301 || status == 302) {
|
||||||
QString loc = reply->header(QNetworkRequest::LocationHeader).toString();
|
QString loc = reply->header(QNetworkRequest::LocationHeader).toString();
|
||||||
if (!loc.isEmpty()) {
|
if (!loc.isEmpty()) {
|
||||||
QMap<QNetworkReply*, ImageLinkData*>::iterator i = dataLoadings.find(reply);
|
QMap<QNetworkReply*, LocationData*>::iterator i = dataLoadings.find(reply);
|
||||||
if (i != dataLoadings.cend()) {
|
if (i != dataLoadings.cend()) {
|
||||||
ImageLinkData *d = i.value();
|
LocationData *d = i.value();
|
||||||
if (serverRedirects.constFind(d) == serverRedirects.cend()) {
|
if (serverRedirects.constFind(d) == serverRedirects.cend()) {
|
||||||
serverRedirects.insert(d, 1);
|
serverRedirects.insert(d, 1);
|
||||||
} else if (++serverRedirects[d] > MaxHttpRedirects) {
|
} else if (++serverRedirects[d] > MaxHttpRedirects) {
|
||||||
|
@ -5713,7 +5707,7 @@ void ImageLinkManager::onFinished(QNetworkReply *reply) {
|
||||||
dataLoadings.insert(manager->get(QNetworkRequest(loc)), d);
|
dataLoadings.insert(manager->get(QNetworkRequest(loc)), d);
|
||||||
return;
|
return;
|
||||||
} else if ((i = imageLoadings.find(reply)) != imageLoadings.cend()) {
|
} else if ((i = imageLoadings.find(reply)) != imageLoadings.cend()) {
|
||||||
ImageLinkData *d = i.value();
|
LocationData *d = i.value();
|
||||||
if (serverRedirects.constFind(d) == serverRedirects.cend()) {
|
if (serverRedirects.constFind(d) == serverRedirects.cend()) {
|
||||||
serverRedirects.insert(d, 1);
|
serverRedirects.insert(d, 1);
|
||||||
} else if (++serverRedirects[d] > MaxHttpRedirects) {
|
} else if (++serverRedirects[d] > MaxHttpRedirects) {
|
||||||
|
@ -5732,8 +5726,8 @@ void ImageLinkManager::onFinished(QNetworkReply *reply) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageLinkData *d = 0;
|
LocationData *d = 0;
|
||||||
QMap<QNetworkReply*, ImageLinkData*>::iterator i = dataLoadings.find(reply);
|
QMap<QNetworkReply*, LocationData*>::iterator i = dataLoadings.find(reply);
|
||||||
if (i != dataLoadings.cend()) {
|
if (i != dataLoadings.cend()) {
|
||||||
d = i.value();
|
d = i.value();
|
||||||
dataLoadings.erase(i);
|
dataLoadings.erase(i);
|
||||||
|
@ -5744,9 +5738,7 @@ void ImageLinkManager::onFinished(QNetworkReply *reply) {
|
||||||
DEBUG_LOG(("JSON Error: Bad json received in onFinished() for image link"));
|
DEBUG_LOG(("JSON Error: Bad json received in onFinished() for image link"));
|
||||||
return onFailed(reply);
|
return onFailed(reply);
|
||||||
}
|
}
|
||||||
switch (d->type) {
|
failed(d);
|
||||||
case GoogleMapsLink: failed(d); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (App::main()) App::main()->update();
|
if (App::main()) App::main()->update();
|
||||||
} else {
|
} else {
|
||||||
|
@ -5777,11 +5769,11 @@ void ImageLinkManager::onFinished(QNetworkReply *reply) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkManager::onFailed(QNetworkReply *reply) {
|
void LocationManager::onFailed(QNetworkReply *reply) {
|
||||||
if (!manager) return;
|
if (!manager) return;
|
||||||
|
|
||||||
ImageLinkData *d = 0;
|
LocationData *d = 0;
|
||||||
QMap<QNetworkReply*, ImageLinkData*>::iterator i = dataLoadings.find(reply);
|
QMap<QNetworkReply*, LocationData*>::iterator i = dataLoadings.find(reply);
|
||||||
if (i != dataLoadings.cend()) {
|
if (i != dataLoadings.cend()) {
|
||||||
d = i.value();
|
d = i.value();
|
||||||
dataLoadings.erase(i);
|
dataLoadings.erase(i);
|
||||||
|
@ -5792,19 +5784,19 @@ void ImageLinkManager::onFailed(QNetworkReply *reply) {
|
||||||
imageLoadings.erase(i);
|
imageLoadings.erase(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_LOG(("Network Error: failed to get data for image link %1, error %2").arg(d ? d->id : 0).arg(reply->errorString()));
|
DEBUG_LOG(("Network Error: failed to get data for image link %1,%2 error %3").arg(d ? d->coords.lat : 0).arg(d ? d->coords.lon : 0).arg(reply->errorString()));
|
||||||
if (d) {
|
if (d) {
|
||||||
failed(d);
|
failed(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkManager::failed(ImageLinkData *data) {
|
void LocationManager::failed(LocationData *data) {
|
||||||
data->loading = false;
|
data->loading = false;
|
||||||
data->thumb = *black;
|
data->thumb = *black;
|
||||||
serverRedirects.remove(data);
|
serverRedirects.remove(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageLinkData::load() {
|
void LocationData::load() {
|
||||||
if (!thumb->isNull()) return thumb->load(false, false);
|
if (!thumb->isNull()) return thumb->load(false, false);
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
|
|
||||||
|
@ -5812,7 +5804,7 @@ void ImageLinkData::load() {
|
||||||
manager.getData(this);
|
manager.getData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryImageLink::HistoryImageLink(const QString &url, const QString &title, const QString &description) : HistoryMedia(),
|
HistoryLocation::HistoryLocation(const LocationCoords &coords, const QString &title, const QString &description) : HistoryMedia(),
|
||||||
_title(st::msgMinWidth),
|
_title(st::msgMinWidth),
|
||||||
_description(st::msgMinWidth) {
|
_description(st::msgMinWidth) {
|
||||||
if (!title.isEmpty()) {
|
if (!title.isEmpty()) {
|
||||||
|
@ -5822,16 +5814,11 @@ _description(st::msgMinWidth) {
|
||||||
_description.setText(st::webPageDescriptionFont, textClean(description), _webpageDescriptionOptions);
|
_description.setText(st::webPageDescriptionFont, textClean(description), _webpageDescriptionOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegularExpressionMatch m = QRegularExpression(qsl("^location:(-?\\d+(?:\\.\\d+)?),(-?\\d+(?:\\.\\d+)?)$")).match(url);
|
_link.reset(new LocationLink(coords));
|
||||||
if (m.hasMatch()) {
|
_data = App::location(coords);
|
||||||
_link.reset(new LocationLink(m.captured(1), m.captured(2)));
|
|
||||||
_data = App::imageLinkSet(url, GoogleMapsLink);
|
|
||||||
} else {
|
|
||||||
_link.reset(new TextLink(url));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryImageLink::initDimensions(const HistoryItem *parent) {
|
void HistoryLocation::initDimensions(const HistoryItem *parent) {
|
||||||
bool bubble = parent->hasBubble();
|
bool bubble = parent->hasBubble();
|
||||||
|
|
||||||
int32 tw = fullWidth(), th = fullHeight();
|
int32 tw = fullWidth(), th = fullHeight();
|
||||||
|
@ -5862,7 +5849,7 @@ void HistoryImageLink::initDimensions(const HistoryItem *parent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 HistoryImageLink::resize(int32 width, const HistoryItem *parent) {
|
int32 HistoryLocation::resize(int32 width, const HistoryItem *parent) {
|
||||||
bool bubble = parent->hasBubble();
|
bool bubble = parent->hasBubble();
|
||||||
|
|
||||||
_width = qMin(width, _maxw);
|
_width = qMin(width, _maxw);
|
||||||
|
@ -5903,7 +5890,7 @@ int32 HistoryImageLink::resize(int32 width, const HistoryItem *parent) {
|
||||||
return _height;
|
return _height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryImageLink::draw(Painter &p, const HistoryItem *parent, const QRect &r, bool selected, uint64 ms) const {
|
void HistoryLocation::draw(Painter &p, const HistoryItem *parent, const QRect &r, bool selected, uint64 ms) const {
|
||||||
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
||||||
int32 skipx = 0, skipy = 0, width = _width, height = _height;
|
int32 skipx = 0, skipy = 0, width = _width, height = _height;
|
||||||
bool bubble = parent->hasBubble();
|
bool bubble = parent->hasBubble();
|
||||||
|
@ -5967,7 +5954,7 @@ void HistoryImageLink::draw(Painter &p, const HistoryItem *parent, const QRect &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryImageLink::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x, int32 y, const HistoryItem *parent) const {
|
void HistoryLocation::getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x, int32 y, const HistoryItem *parent) const {
|
||||||
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
if (_width < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
||||||
int32 skipx = 0, skipy = 0, width = _width, height = _height;
|
int32 skipx = 0, skipy = 0, width = _width, height = _height;
|
||||||
bool bubble = parent->hasBubble();
|
bool bubble = parent->hasBubble();
|
||||||
|
@ -6009,40 +5996,20 @@ void HistoryImageLink::getState(TextLinkPtr &lnk, HistoryCursorState &state, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString HistoryImageLink::inDialogsText() const {
|
const QString HistoryLocation::inDialogsText() const {
|
||||||
if (_data) {
|
return lang(lng_maps_point);
|
||||||
switch (_data->type) {
|
|
||||||
case GoogleMapsLink: return lang(lng_maps_point);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString HistoryImageLink::inHistoryText() const {
|
const QString HistoryLocation::inHistoryText() const {
|
||||||
if (_data) {
|
return qsl("[ ") + lang(lng_maps_point) + qsl(" : ") + _link->text() + qsl(" ]");
|
||||||
switch (_data->type) {
|
|
||||||
case GoogleMapsLink: return qsl("[ ") + lang(lng_maps_point) + qsl(" : ") + _link->text() + qsl(" ]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return qsl("[ Link : ") + _link->text() + qsl(" ]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 HistoryImageLink::fullWidth() const {
|
int32 HistoryLocation::fullWidth() const {
|
||||||
if (_data) {
|
return st::locationSize.width();
|
||||||
switch (_data->type) {
|
|
||||||
case GoogleMapsLink: return st::locationSize.width();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return st::minPhotoSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 HistoryImageLink::fullHeight() const {
|
int32 HistoryLocation::fullHeight() const {
|
||||||
if (_data) {
|
return st::locationSize.height();
|
||||||
switch (_data->type) {
|
|
||||||
case GoogleMapsLink: return st::locationSize.height();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return st::minPhotoSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViaInlineBotLink::onClick(Qt::MouseButton button) const {
|
void ViaInlineBotLink::onClick(Qt::MouseButton button) const {
|
||||||
|
@ -6285,14 +6252,14 @@ void HistoryMessage::initMedia(const MTPMessageMedia *media, QString ¤tTex
|
||||||
const MTPGeoPoint &point(media->c_messageMediaGeo().vgeo);
|
const MTPGeoPoint &point(media->c_messageMediaGeo().vgeo);
|
||||||
if (point.type() == mtpc_geoPoint) {
|
if (point.type() == mtpc_geoPoint) {
|
||||||
const MTPDgeoPoint &d(point.c_geoPoint());
|
const MTPDgeoPoint &d(point.c_geoPoint());
|
||||||
_media = new HistoryImageLink(qsl("location:%1,%2").arg(d.vlat.v).arg(d.vlong.v));
|
_media = new HistoryLocation(LocationCoords(d.vlat.v, d.vlong.v));
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case mtpc_messageMediaVenue: {
|
case mtpc_messageMediaVenue: {
|
||||||
const MTPDmessageMediaVenue &d(media->c_messageMediaVenue());
|
const MTPDmessageMediaVenue &d(media->c_messageMediaVenue());
|
||||||
if (d.vgeo.type() == mtpc_geoPoint) {
|
if (d.vgeo.type() == mtpc_geoPoint) {
|
||||||
const MTPDgeoPoint &g(d.vgeo.c_geoPoint());
|
const MTPDgeoPoint &g(d.vgeo.c_geoPoint());
|
||||||
_media = new HistoryImageLink(qsl("location:%1,%2").arg(g.vlat.v).arg(g.vlong.v), qs(d.vtitle), qs(d.vaddress));
|
_media = new HistoryLocation(LocationCoords(g.vlat.v, g.vlong.v), qs(d.vtitle), qs(d.vaddress));
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case mtpc_messageMediaPhoto: {
|
case mtpc_messageMediaPhoto: {
|
||||||
|
|
|
@ -120,7 +120,7 @@ enum HistoryMediaType {
|
||||||
MediaTypeFile,
|
MediaTypeFile,
|
||||||
MediaTypeGif,
|
MediaTypeGif,
|
||||||
MediaTypeSticker,
|
MediaTypeSticker,
|
||||||
MediaTypeImageLink,
|
MediaTypeLocation,
|
||||||
MediaTypeWebPage,
|
MediaTypeWebPage,
|
||||||
MediaTypeMusicFile,
|
MediaTypeMusicFile,
|
||||||
MediaTypeVoiceFile,
|
MediaTypeVoiceFile,
|
||||||
|
@ -1973,59 +1973,54 @@ void initImageLinkManager();
|
||||||
void reinitImageLinkManager();
|
void reinitImageLinkManager();
|
||||||
void deinitImageLinkManager();
|
void deinitImageLinkManager();
|
||||||
|
|
||||||
enum ImageLinkType {
|
struct LocationData {
|
||||||
InvalidImageLink = 0,
|
LocationData(const LocationCoords &coords) : coords(coords), loading(false) {
|
||||||
GoogleMapsLink
|
|
||||||
};
|
|
||||||
struct ImageLinkData {
|
|
||||||
ImageLinkData(const QString &id) : id(id), type(InvalidImageLink), loading(false) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString id;
|
LocationCoords coords;
|
||||||
ImagePtr thumb;
|
ImagePtr thumb;
|
||||||
ImageLinkType type;
|
|
||||||
bool loading;
|
bool loading;
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
};
|
};
|
||||||
|
|
||||||
class ImageLinkManager : public QObject {
|
class LocationManager : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ImageLinkManager() : manager(0), black(0) {
|
LocationManager() : manager(0), black(0) {
|
||||||
}
|
}
|
||||||
void init();
|
void init();
|
||||||
void reinit();
|
void reinit();
|
||||||
void deinit();
|
void deinit();
|
||||||
|
|
||||||
void getData(ImageLinkData *data);
|
void getData(LocationData *data);
|
||||||
|
|
||||||
~ImageLinkManager() {
|
~LocationManager() {
|
||||||
deinit();
|
deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onFinished(QNetworkReply *reply);
|
void onFinished(QNetworkReply *reply);
|
||||||
void onFailed(QNetworkReply *reply);
|
void onFailed(QNetworkReply *reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void failed(ImageLinkData *data);
|
void failed(LocationData *data);
|
||||||
|
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *manager;
|
||||||
QMap<QNetworkReply*, ImageLinkData*> dataLoadings, imageLoadings;
|
QMap<QNetworkReply*, LocationData*> dataLoadings, imageLoadings;
|
||||||
QMap<ImageLinkData*, int32> serverRedirects;
|
QMap<LocationData*, int32> serverRedirects;
|
||||||
ImagePtr *black;
|
ImagePtr *black;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HistoryImageLink : public HistoryMedia {
|
class HistoryLocation : public HistoryMedia {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HistoryImageLink(const QString &url, const QString &title = QString(), const QString &description = QString());
|
HistoryLocation(const LocationCoords &coords, const QString &title = QString(), const QString &description = QString());
|
||||||
HistoryMediaType type() const {
|
HistoryMediaType type() const {
|
||||||
return MediaTypeImageLink;
|
return MediaTypeLocation;
|
||||||
}
|
}
|
||||||
HistoryMedia *clone() const {
|
HistoryMedia *clone() const {
|
||||||
return new HistoryImageLink(*this);
|
return new HistoryLocation(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initDimensions(const HistoryItem *parent);
|
void initDimensions(const HistoryItem *parent);
|
||||||
|
@ -2049,7 +2044,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImageLinkData *_data;
|
LocationData *_data;
|
||||||
Text _title, _description;
|
Text _title, _description;
|
||||||
TextLinkPtr _link;
|
TextLinkPtr _link;
|
||||||
|
|
||||||
|
|
|
@ -1494,6 +1494,6 @@ bool linuxMoveFile(const char *from, const char *to) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psLaunchMaps(const QString &lat, const QString &lon) {
|
bool psLaunchMaps(const LocationCoords &coords) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,4 +195,4 @@ public:
|
||||||
|
|
||||||
bool linuxMoveFile(const char *from, const char *to);
|
bool linuxMoveFile(const char *from, const char *to);
|
||||||
|
|
||||||
bool psLaunchMaps(const QString &lat, const QString &lon);
|
bool psLaunchMaps(const LocationCoords &coords);
|
||||||
|
|
|
@ -910,8 +910,8 @@ QByteArray psPathBookmark(const QString &path) {
|
||||||
return objc_pathBookmark(path);
|
return objc_pathBookmark(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psLaunchMaps(const QString &lat, const QString &lon) {
|
bool psLaunchMaps(const LocationCoords &coords) {
|
||||||
return QDesktopServices::openUrl(qsl("https://maps.apple.com/?q=Point&z=16&ll=%1,%2").arg(lat).arg(lon));
|
return QDesktopServices::openUrl(qsl("https://maps.apple.com/?q=Point&z=16&ll=%1,%2").arg(coords.lat).arg(coords.lon));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString strNotificationAboutThemeChange() {
|
QString strNotificationAboutThemeChange() {
|
||||||
|
|
|
@ -224,4 +224,4 @@ QString strNeedToReload();
|
||||||
QString strNeedToRefresh1();
|
QString strNeedToRefresh1();
|
||||||
QString strNeedToRefresh2();
|
QString strNeedToRefresh2();
|
||||||
|
|
||||||
bool psLaunchMaps(const QString &lat, const QString &lon);
|
bool psLaunchMaps(const LocationCoords &coords);
|
||||||
|
|
|
@ -3660,6 +3660,6 @@ bool InitToastManager() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psLaunchMaps(const QString &lat, const QString &lon) {
|
bool psLaunchMaps(const LocationCoords &coords) {
|
||||||
return QDesktopServices::openUrl(qsl("bingmaps:?lvl=16&collection=point.") + lat + '_' + lon + '_' + qsl("Point"));
|
return QDesktopServices::openUrl(qsl("bingmaps:?lvl=16&collection=point.%1_%2_Point").arg(coords.lat).arg(coords.lon));
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,4 +195,4 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool psLaunchMaps(const QString &lat, const QString &lon);
|
bool psLaunchMaps(const LocationCoords &coords);
|
||||||
|
|
|
@ -521,6 +521,12 @@ void Window::clearWidgets() {
|
||||||
intro->rpcClear();
|
intro->rpcClear();
|
||||||
intro = 0;
|
intro = 0;
|
||||||
}
|
}
|
||||||
|
if (_mediaView) {
|
||||||
|
if (!_mediaView->isHidden()) {
|
||||||
|
_mediaView->hide();
|
||||||
|
}
|
||||||
|
_mediaView->rpcClear();
|
||||||
|
}
|
||||||
title->updateBackButton();
|
title->updateBackButton();
|
||||||
updateGlobalMenu();
|
updateGlobalMenu();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue