mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
fast dialogs, emoji pan etc done
This commit is contained in:
@@ -2279,11 +2279,11 @@ namespace Local {
|
||||
}
|
||||
}
|
||||
|
||||
class ImageLoadTask : public Task {
|
||||
class AbstractCachedLoadTask : public Task {
|
||||
public:
|
||||
|
||||
ImageLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) :
|
||||
_key(key), _location(location), _loader(loader), _result(0) {
|
||||
AbstractCachedLoadTask(const FileKey &key, const StorageKey &location, bool readImageFlag, mtpFileLoader *loader) :
|
||||
_key(key), _location(location), _readImageFlag(readImageFlag), _loader(loader), _result(0) {
|
||||
}
|
||||
void process() {
|
||||
FileReadDescriptor image;
|
||||
@@ -2294,43 +2294,44 @@ namespace Local {
|
||||
QByteArray imageData;
|
||||
quint64 locFirst, locSecond;
|
||||
quint32 imageType;
|
||||
image.stream >> locFirst >> locSecond >> imageType >> imageData;
|
||||
readFromStream(image.stream, locFirst, locSecond, imageType, imageData);
|
||||
|
||||
if (locFirst != _location.first || locSecond != _location.second) {
|
||||
return;
|
||||
}
|
||||
|
||||
_result = new Result(StorageFileType(imageType), imageData);
|
||||
_result = new Result(StorageFileType(imageType), imageData, _readImageFlag);
|
||||
}
|
||||
void finish() {
|
||||
if (_result) {
|
||||
_loader->localLoaded(_result->image, _result->format, _result->pixmap);
|
||||
} else {
|
||||
StorageMap::iterator j = _imagesMap.find(_location);
|
||||
if (j != _imagesMap.cend() && j->first == _key) {
|
||||
clearKey(_key, UserPath);
|
||||
_storageImagesSize -= j->second;
|
||||
_imagesMap.erase(j);
|
||||
}
|
||||
clearInMap();
|
||||
_loader->localLoaded(StorageImageSaved());
|
||||
}
|
||||
}
|
||||
virtual void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) = 0;
|
||||
virtual void clearInMap() = 0;
|
||||
|
||||
private:
|
||||
protected:
|
||||
FileKey _key;
|
||||
StorageKey _location;
|
||||
bool _readImageFlag;
|
||||
struct Result {
|
||||
Result(StorageFileType type, const QByteArray &data) : image(type, data) {
|
||||
QByteArray guessFormat;
|
||||
switch (type) {
|
||||
case mtpc_storage_fileGif: guessFormat = "GIF"; break;
|
||||
case mtpc_storage_fileJpeg: guessFormat = "JPG"; break;
|
||||
case mtpc_storage_filePng: guessFormat = "PNG"; break;
|
||||
default: guessFormat = QByteArray(); break;
|
||||
}
|
||||
pixmap = QPixmap::fromImage(App::readImage(data, &guessFormat, false), Qt::ColorOnly);
|
||||
if (!pixmap.isNull()) {
|
||||
format = guessFormat;
|
||||
Result(StorageFileType type, const QByteArray &data, bool readImageFlag) : image(type, data) {
|
||||
if (readImageFlag) {
|
||||
QByteArray guessFormat;
|
||||
switch (type) {
|
||||
case StorageFileGif: guessFormat = "GIF"; break;
|
||||
case StorageFileJpeg: guessFormat = "JPG"; break;
|
||||
case StorageFilePng: guessFormat = "PNG"; break;
|
||||
case StorageFileWebp: guessFormat = "WEBP"; break;
|
||||
default: guessFormat = QByteArray(); break;
|
||||
}
|
||||
pixmap = QPixmap::fromImage(App::readImage(data, &guessFormat, false), Qt::ColorOnly);
|
||||
if (!pixmap.isNull()) {
|
||||
format = guessFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
StorageImageSaved image;
|
||||
@@ -2342,6 +2343,24 @@ namespace Local {
|
||||
|
||||
};
|
||||
|
||||
class ImageLoadTask : public AbstractCachedLoadTask {
|
||||
public:
|
||||
ImageLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) :
|
||||
AbstractCachedLoadTask(key, location, true, loader) {
|
||||
}
|
||||
void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) {
|
||||
stream >> first >> second >> type >> data;
|
||||
}
|
||||
void clearInMap() {
|
||||
StorageMap::iterator j = _imagesMap.find(_location);
|
||||
if (j != _imagesMap.cend() && j->first == _key) {
|
||||
clearKey(_key, UserPath);
|
||||
_storageImagesSize -= j->second;
|
||||
_imagesMap.erase(j);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader) {
|
||||
StorageMap::iterator j = _imagesMap.find(location);
|
||||
if (j == _imagesMap.cend() || !_localLoader) {
|
||||
@@ -2350,27 +2369,6 @@ namespace Local {
|
||||
return _localLoader->addTask(new ImageLoadTask(j->first, location, loader));
|
||||
}
|
||||
|
||||
StorageImageSaved readImage(const StorageKey &location) {
|
||||
StorageMap::iterator j = _imagesMap.find(location);
|
||||
if (j == _imagesMap.cend()) {
|
||||
return StorageImageSaved();
|
||||
}
|
||||
FileReadDescriptor image;
|
||||
if (!readEncryptedFile(image, j.value().first, UserPath)) {
|
||||
clearKey(j.value().first, UserPath);
|
||||
_storageImagesSize -= j.value().second;
|
||||
_imagesMap.erase(j);
|
||||
return StorageImageSaved();
|
||||
}
|
||||
|
||||
QByteArray imageData;
|
||||
quint64 locFirst, locSecond;
|
||||
quint32 imageType;
|
||||
image.stream >> locFirst >> locSecond >> imageType >> imageData;
|
||||
|
||||
return (locFirst == location.first && locSecond == location.second) ? StorageImageSaved(StorageFileType(imageType), imageData) : StorageImageSaved();
|
||||
}
|
||||
|
||||
int32 hasImages() {
|
||||
return _imagesMap.size();
|
||||
}
|
||||
@@ -2403,32 +2401,31 @@ namespace Local {
|
||||
}
|
||||
}
|
||||
|
||||
class StickerImageLoadTask : public AbstractCachedLoadTask {
|
||||
public:
|
||||
StickerImageLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) :
|
||||
AbstractCachedLoadTask(key, location, true, loader) {
|
||||
}
|
||||
void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) {
|
||||
stream >> first >> second >> data;
|
||||
type = StorageFilePartial;
|
||||
}
|
||||
void clearInMap() {
|
||||
StorageMap::iterator j = _stickerImagesMap.find(_location);
|
||||
if (j != _stickerImagesMap.cend() && j->first == _key) {
|
||||
clearKey(j.value().first, UserPath);
|
||||
_storageStickersSize -= j.value().second;
|
||||
_stickerImagesMap.erase(j);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TaskId startStickerImageLoad(const StorageKey &location, mtpFileLoader *loader) {
|
||||
StorageMap::iterator j = _stickerImagesMap.find(location);
|
||||
if (j == _stickerImagesMap.cend()) {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QByteArray readStickerImage(const StorageKey &location) {
|
||||
StorageMap::iterator j = _stickerImagesMap.find(location);
|
||||
if (j == _stickerImagesMap.cend()) {
|
||||
return QByteArray();
|
||||
}
|
||||
FileReadDescriptor draft;
|
||||
if (!readEncryptedFile(draft, j.value().first, UserPath)) {
|
||||
clearKey(j.value().first, UserPath);
|
||||
_storageStickersSize -= j.value().second;
|
||||
_stickerImagesMap.erase(j);
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray stickerData;
|
||||
quint64 locFirst, locSecond;
|
||||
draft.stream >> locFirst >> locSecond >> stickerData;
|
||||
|
||||
return (locFirst == location.first && locSecond == location.second) ? stickerData : QByteArray();
|
||||
return _localLoader->addTask(new StickerImageLoadTask(j->first, location, loader));
|
||||
}
|
||||
|
||||
int32 hasStickers() {
|
||||
@@ -2463,32 +2460,31 @@ namespace Local {
|
||||
}
|
||||
}
|
||||
|
||||
class AudioLoadTask : public AbstractCachedLoadTask {
|
||||
public:
|
||||
AudioLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) :
|
||||
AbstractCachedLoadTask(key, location, false, loader) {
|
||||
}
|
||||
void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) {
|
||||
stream >> first >> second >> data;
|
||||
type = StorageFilePartial;
|
||||
}
|
||||
void clearInMap() {
|
||||
StorageMap::iterator j = _audiosMap.find(_location);
|
||||
if (j != _audiosMap.cend() && j->first == _key) {
|
||||
clearKey(j.value().first, UserPath);
|
||||
_storageAudiosSize -= j.value().second;
|
||||
_audiosMap.erase(j);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TaskId startAudioLoad(const StorageKey &location, mtpFileLoader *loader) {
|
||||
StorageMap::iterator j = _audiosMap.find(location);
|
||||
if (j == _audiosMap.cend()) {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QByteArray readAudio(const StorageKey &location) {
|
||||
StorageMap::iterator j = _audiosMap.find(location);
|
||||
if (j == _audiosMap.cend()) {
|
||||
return QByteArray();
|
||||
}
|
||||
FileReadDescriptor draft;
|
||||
if (!readEncryptedFile(draft, j.value().first, UserPath)) {
|
||||
clearKey(j.value().first, UserPath);
|
||||
_storageAudiosSize -= j.value().second;
|
||||
_audiosMap.erase(j);
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray audioData;
|
||||
quint64 locFirst, locSecond;
|
||||
draft.stream >> locFirst >> locSecond >> audioData;
|
||||
|
||||
return (locFirst == location.first && locSecond == location.second) ? audioData : QByteArray();
|
||||
return _localLoader->addTask(new AudioLoadTask(j->first, location, loader));
|
||||
}
|
||||
|
||||
int32 hasAudios() {
|
||||
|
Reference in New Issue
Block a user