mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Simplify Image, remove ImageSource.
This commit is contained in:
@@ -24,11 +24,26 @@ constexpr int kNotifyDeletePhotoAfterMs = 60000;
|
||||
|
||||
CachedUserpics::CachedUserpics(Type type)
|
||||
: _type(type)
|
||||
, _clearTimer([=] { onClear(); }) {
|
||||
, _clearTimer([=] { clear(); }) {
|
||||
QDir().mkpath(cWorkingDir() + qsl("tdata/temp"));
|
||||
}
|
||||
|
||||
QString CachedUserpics::get(const InMemoryKey &key, PeerData *peer) {
|
||||
CachedUserpics::~CachedUserpics() {
|
||||
if (_someSavedFlag) {
|
||||
crl::time result = 0;
|
||||
for (const auto &item : std::as_const(_images)) {
|
||||
QFile(item.path).remove();
|
||||
}
|
||||
|
||||
// This works about 1200ms on Windows for a folder with one image O_o
|
||||
// psDeleteDir(cWorkingDir() + qsl("tdata/temp"));
|
||||
}
|
||||
}
|
||||
|
||||
QString CachedUserpics::get(
|
||||
const InMemoryKey &key,
|
||||
not_null<PeerData*> peer,
|
||||
std::shared_ptr<Data::CloudImageView> &view) {
|
||||
auto ms = crl::now();
|
||||
auto i = _images.find(key);
|
||||
if (i != _images.cend()) {
|
||||
@@ -46,16 +61,15 @@ QString CachedUserpics::get(const InMemoryKey &key, PeerData *peer) {
|
||||
}
|
||||
v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(rand_value<uint64>(), 16) + qsl(".png");
|
||||
if (key.first || key.second) {
|
||||
auto userpic = std::shared_ptr<Data::CloudImageView>(); // #TODO optimize userpic
|
||||
if (peer->isSelf()) {
|
||||
const auto method = (_type == Type::Rounded)
|
||||
? Ui::EmptyUserpic::GenerateSavedMessagesRounded
|
||||
: Ui::EmptyUserpic::GenerateSavedMessages;
|
||||
method(st::notifyMacPhotoSize).save(v.path, "PNG");
|
||||
} else if (_type == Type::Rounded) {
|
||||
peer->saveUserpicRounded(userpic, v.path, st::notifyMacPhotoSize);
|
||||
peer->saveUserpicRounded(view, v.path, st::notifyMacPhotoSize);
|
||||
} else {
|
||||
peer->saveUserpic(userpic, v.path, st::notifyMacPhotoSize);
|
||||
peer->saveUserpic(view, v.path, st::notifyMacPhotoSize);
|
||||
}
|
||||
} else {
|
||||
Core::App().logoNoMargin().save(v.path, "PNG");
|
||||
@@ -98,7 +112,7 @@ void CachedUserpics::clearInMs(int ms) {
|
||||
_clearTimer.callOnce(ms);
|
||||
}
|
||||
|
||||
void CachedUserpics::onClear() {
|
||||
void CachedUserpics::clear() {
|
||||
auto ms = crl::now();
|
||||
auto minuntil = clear(ms);
|
||||
if (minuntil) {
|
||||
@@ -106,17 +120,5 @@ void CachedUserpics::onClear() {
|
||||
}
|
||||
}
|
||||
|
||||
CachedUserpics::~CachedUserpics() {
|
||||
if (_someSavedFlag) {
|
||||
crl::time result = 0;
|
||||
for (const auto &item : std::as_const(_images)) {
|
||||
QFile(item.path).remove();
|
||||
}
|
||||
|
||||
// This works about 1200ms on Windows for a folder with one image O_o
|
||||
// psDeleteDir(cWorkingDir() + qsl("tdata/temp"));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Notifications
|
||||
} // namespace Window
|
||||
|
@@ -10,27 +10,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "window/notifications_manager.h"
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Data {
|
||||
class CloudImageView;
|
||||
} // namespace Data
|
||||
|
||||
namespace Window {
|
||||
namespace Notifications {
|
||||
|
||||
class CachedUserpics : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class Type {
|
||||
Rounded,
|
||||
Circled,
|
||||
};
|
||||
|
||||
CachedUserpics(Type type);
|
||||
|
||||
QString get(const InMemoryKey &key, PeerData *peer);
|
||||
|
||||
~CachedUserpics();
|
||||
|
||||
private slots:
|
||||
void onClear();
|
||||
[[nodiscard]] QString get(
|
||||
const InMemoryKey &key,
|
||||
not_null<PeerData*> peer,
|
||||
std::shared_ptr<Data::CloudImageView> &view);
|
||||
|
||||
private:
|
||||
void clear();
|
||||
void clearInMs(int ms);
|
||||
crl::time clear(crl::time ms);
|
||||
|
||||
|
@@ -265,13 +265,13 @@ QPixmap MediaPreviewWidget::currentImage() const {
|
||||
return QPixmap();
|
||||
} else if (const auto image = _documentMedia->getStickerLarge()) {
|
||||
QSize s = currentDimensions();
|
||||
_cache = image->pix(_origin, s.width(), s.height());
|
||||
_cache = image->pix(s.width(), s.height());
|
||||
_cacheStatus = CacheLoaded;
|
||||
} else if (_cacheStatus != CacheThumbLoaded
|
||||
&& _document->hasThumbnail()
|
||||
&& _documentMedia->thumbnail()) {
|
||||
QSize s = currentDimensions();
|
||||
_cache = _documentMedia->thumbnail()->pixBlurred(_origin, s.width(), s.height());
|
||||
_cache = _documentMedia->thumbnail()->pixBlurred(s.width(), s.height());
|
||||
_cacheStatus = CacheThumbLoaded;
|
||||
}
|
||||
}
|
||||
@@ -290,10 +290,10 @@ QPixmap MediaPreviewWidget::currentImage() const {
|
||||
QSize s = currentDimensions();
|
||||
const auto thumbnail = _documentMedia->thumbnail();
|
||||
if (thumbnail) {
|
||||
_cache = thumbnail->pixBlurred(_origin, s.width(), s.height());
|
||||
_cache = thumbnail->pixBlurred(s.width(), s.height());
|
||||
_cacheStatus = CacheThumbLoaded;
|
||||
} else if (const auto blurred = _documentMedia->thumbnailInline()) {
|
||||
_cache = blurred->pixBlurred(_origin, s.width(), s.height());
|
||||
_cache = blurred->pixBlurred(s.width(), s.height());
|
||||
_cacheStatus = CacheThumbLoaded;
|
||||
}
|
||||
}
|
||||
@@ -302,7 +302,7 @@ QPixmap MediaPreviewWidget::currentImage() const {
|
||||
if (_cacheStatus != CacheLoaded) {
|
||||
if (_photoMedia->loaded()) {
|
||||
QSize s = currentDimensions();
|
||||
_cache = _photoMedia->image(Data::PhotoSize::Large)->pix(_origin, s.width(), s.height());
|
||||
_cache = _photoMedia->image(Data::PhotoSize::Large)->pix(s.width(), s.height());
|
||||
_cacheStatus = CacheLoaded;
|
||||
} else {
|
||||
_photo->load(_origin);
|
||||
@@ -310,14 +310,14 @@ QPixmap MediaPreviewWidget::currentImage() const {
|
||||
QSize s = currentDimensions();
|
||||
if (const auto thumbnail = _photoMedia->image(
|
||||
Data::PhotoSize::Thumbnail)) {
|
||||
_cache = thumbnail->pixBlurred(_origin, s.width(), s.height());
|
||||
_cache = thumbnail->pixBlurred(s.width(), s.height());
|
||||
_cacheStatus = CacheThumbLoaded;
|
||||
} else if (const auto small = _photoMedia->image(
|
||||
Data::PhotoSize::Small)) {
|
||||
_cache = small->pixBlurred(_origin, s.width(), s.height());
|
||||
_cache = small->pixBlurred(s.width(), s.height());
|
||||
_cacheStatus = CacheThumbLoaded;
|
||||
} else if (const auto blurred = _photoMedia->thumbnailInline()) {
|
||||
_cache = blurred->pixBlurred(_origin, s.width(), s.height());
|
||||
_cache = blurred->pixBlurred(s.width(), s.height());
|
||||
_cacheStatus = CacheThumbLoaded;
|
||||
} else {
|
||||
_photoMedia->wanted(Data::PhotoSize::Small, _origin);
|
||||
|
Reference in New Issue
Block a user