2017-09-26 11:49:16 +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.
|
2017-09-26 11:49:16 +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
|
2017-09-26 11:49:16 +00:00
|
|
|
*/
|
|
|
|
#include "data/data_photo.h"
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "history/history_media_types.h"
|
2017-10-05 15:35:52 +00:00
|
|
|
#include "auth_session.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "messenger.h"
|
|
|
|
|
|
|
|
PhotoData::PhotoData(const PhotoId &id, const uint64 &access, int32 date, const ImagePtr &thumb, const ImagePtr &medium, const ImagePtr &full)
|
|
|
|
: id(id)
|
|
|
|
, access(access)
|
|
|
|
, date(date)
|
|
|
|
, thumb(thumb)
|
|
|
|
, medium(medium)
|
|
|
|
, full(full) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::automaticLoad(const HistoryItem *item) {
|
|
|
|
full->automaticLoad(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::automaticLoadSettingsChanged() {
|
|
|
|
full->automaticLoadSettingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::download() {
|
|
|
|
full->loadEvenCancelled();
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().notifyPhotoLayoutChanged(this);
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::loaded() const {
|
|
|
|
bool wasLoading = loading();
|
|
|
|
if (full->loaded()) {
|
|
|
|
if (wasLoading) {
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().notifyPhotoLayoutChanged(this);
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::loading() const {
|
|
|
|
return full->loading();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::displayLoading() const {
|
2017-12-25 14:17:00 +00:00
|
|
|
return full->loading()
|
|
|
|
? full->displayLoading()
|
|
|
|
: (uploading() && !waitingForAlbum());
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::cancel() {
|
|
|
|
full->cancel();
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().notifyPhotoLayoutChanged(this);
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float64 PhotoData::progress() const {
|
|
|
|
if (uploading()) {
|
|
|
|
if (uploadingData->size > 0) {
|
|
|
|
return float64(uploadingData->offset) / uploadingData->size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return full->progress();
|
|
|
|
}
|
|
|
|
|
2017-12-25 14:17:00 +00:00
|
|
|
void PhotoData::setWaitingForAlbum() {
|
|
|
|
if (uploading()) {
|
|
|
|
uploadingData->waitingForAlbum = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::waitingForAlbum() const {
|
|
|
|
return uploading() && uploadingData->waitingForAlbum;
|
|
|
|
}
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
int32 PhotoData::loadOffset() const {
|
|
|
|
return full->loadOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoData::uploading() const {
|
2017-12-25 14:17:00 +00:00
|
|
|
return (uploadingData != nullptr);
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoData::forget() {
|
|
|
|
thumb->forget();
|
|
|
|
replyPreview->forget();
|
|
|
|
medium->forget();
|
|
|
|
full->forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr PhotoData::makeReplyPreview() {
|
|
|
|
if (replyPreview->isNull() && !thumb->isNull()) {
|
|
|
|
if (thumb->loaded()) {
|
|
|
|
int w = thumb->width(), h = thumb->height();
|
|
|
|
if (w <= 0) w = 1;
|
|
|
|
if (h <= 0) h = 1;
|
|
|
|
replyPreview = ImagePtr(w > h ? thumb->pix(w * st::msgReplyBarSize.height() / h, st::msgReplyBarSize.height()) : thumb->pix(st::msgReplyBarSize.height()), "PNG");
|
|
|
|
} else {
|
|
|
|
thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return replyPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoOpenClickHandler::onClickImpl() const {
|
2017-12-15 16:25:47 +00:00
|
|
|
Messenger::Instance().showPhoto(this);
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoSaveClickHandler::onClickImpl() const {
|
|
|
|
auto data = photo();
|
|
|
|
if (!data->date) return;
|
|
|
|
|
|
|
|
data->download();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoCancelClickHandler::onClickImpl() const {
|
|
|
|
auto data = photo();
|
|
|
|
if (!data->date) return;
|
|
|
|
|
|
|
|
if (data->uploading()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
if (const auto item = App::histItemById(context())) {
|
2018-01-11 13:07:29 +00:00
|
|
|
App::main()->cancelUploadLayer(item);
|
2017-09-26 11:49:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data->cancel();
|
|
|
|
}
|
|
|
|
}
|