mirror of https://github.com/procxx/kepka.git
Move automaticLoad() to DocumentMedia.
This commit is contained in:
parent
40f12a2584
commit
1e9c79ca85
|
@ -1235,7 +1235,7 @@ bool HasLottieThumbnail(
|
|||
if (!info->animated) {
|
||||
return false;
|
||||
}
|
||||
document->automaticLoad(document->stickerSetOrigin(), nullptr);
|
||||
media->automaticLoad(document->stickerSetOrigin(), nullptr);
|
||||
if (!media->loaded()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -233,7 +233,11 @@ QString FileNameForSave(
|
|||
return result;
|
||||
}
|
||||
|
||||
QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = false, const QString already = QString(), const QDir &dir = QDir()) {
|
||||
QString DocumentFileNameForSave(
|
||||
not_null<const DocumentData*> data,
|
||||
bool forceSavingAs,
|
||||
const QString &already,
|
||||
const QDir &dir) {
|
||||
auto alreadySavingFilename = data->loadingFilePath();
|
||||
if (!alreadySavingFilename.isEmpty()) {
|
||||
return alreadySavingFilename;
|
||||
|
@ -363,7 +367,7 @@ void DocumentSaveClickHandler::Save(
|
|||
const auto filename = filepath.isEmpty()
|
||||
? QString()
|
||||
: fileinfo.fileName();
|
||||
savename = documentSaveFilename(
|
||||
savename = DocumentFileNameForSave(
|
||||
data,
|
||||
(mode == Mode::ToNewFile),
|
||||
filename,
|
||||
|
@ -736,43 +740,6 @@ void DocumentData::unload() {
|
|||
_replyPreview = nullptr;
|
||||
}
|
||||
|
||||
void DocumentData::automaticLoad(
|
||||
Data::FileOrigin origin,
|
||||
const HistoryItem *item) {
|
||||
const auto media = activeMediaView();
|
||||
if (status != FileReady || !media || media->loaded() || cancelled()) {
|
||||
return;
|
||||
} else if (!item && type != StickerDocument && !isAnimation()) {
|
||||
return;
|
||||
}
|
||||
const auto toCache = saveToCache();
|
||||
if (!toCache && Global::AskDownloadPath()) {
|
||||
// We need a filename, but we're supposed to ask user for it.
|
||||
// No automatic download in this case.
|
||||
return;
|
||||
}
|
||||
const auto filename = toCache
|
||||
? QString()
|
||||
: documentSaveFilename(this);
|
||||
const auto shouldLoadFromCloud = !Data::IsExecutableName(filename)
|
||||
&& (item
|
||||
? Data::AutoDownload::Should(
|
||||
session().settings().autoDownload(),
|
||||
item->history()->peer,
|
||||
this)
|
||||
: Data::AutoDownload::Should(
|
||||
session().settings().autoDownload(),
|
||||
this));
|
||||
const auto loadFromCloud = shouldLoadFromCloud
|
||||
? LoadFromCloudOrLocal
|
||||
: LoadFromLocalOnly;
|
||||
save(
|
||||
origin,
|
||||
filename,
|
||||
loadFromCloud,
|
||||
true);
|
||||
}
|
||||
|
||||
void DocumentData::automaticLoadSettingsChanged() {
|
||||
if (!cancelled() || status != FileReady) {
|
||||
return;
|
||||
|
@ -1129,7 +1096,7 @@ bool DocumentData::saveFromDataChecked() {
|
|||
if (bytes.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
const auto path = documentSaveFilename(this);
|
||||
const auto path = DocumentFileNameForSave(this);
|
||||
if (path.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -95,9 +95,6 @@ public:
|
|||
void setattributes(
|
||||
const QVector<MTPDocumentAttribute> &attributes);
|
||||
|
||||
void automaticLoad(
|
||||
Data::FileOrigin origin,
|
||||
const HistoryItem *item);
|
||||
void automaticLoadSettingsChanged();
|
||||
|
||||
[[nodiscard]] bool loading() const;
|
||||
|
@ -430,6 +427,12 @@ QString FileNameForSave(
|
|||
bool savingAs,
|
||||
const QDir &dir = QDir());
|
||||
|
||||
QString DocumentFileNameForSave(
|
||||
not_null<const DocumentData*> data,
|
||||
bool forceSavingAs = false,
|
||||
const QString &already = QString(),
|
||||
const QDir &dir = QDir());
|
||||
|
||||
namespace Data {
|
||||
|
||||
QString FileExtension(const QString &filepath);
|
||||
|
|
|
@ -11,12 +11,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_session.h"
|
||||
#include "data/data_cloud_themes.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_auto_download.h"
|
||||
#include "media/clip/media_clip_reader.h"
|
||||
#include "main/main_session.h"
|
||||
#include "lottie/lottie_animation.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history.h"
|
||||
#include "window/themes/window_theme_preview.h"
|
||||
#include "storage/file_download.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "facades.h"
|
||||
#include "app.h"
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
|
@ -135,7 +139,7 @@ void DocumentMedia::checkStickerLarge() {
|
|||
return;
|
||||
}
|
||||
|
||||
_owner->automaticLoad(_owner->stickerSetOrigin(), nullptr);
|
||||
automaticLoad(_owner->stickerSetOrigin(), nullptr);
|
||||
if (data->animated || !loaded()) {
|
||||
return;
|
||||
}
|
||||
|
@ -158,6 +162,42 @@ void DocumentMedia::checkStickerLarge() {
|
|||
}
|
||||
}
|
||||
|
||||
void DocumentMedia::automaticLoad(
|
||||
Data::FileOrigin origin,
|
||||
const HistoryItem *item) {
|
||||
if (_owner->status != FileReady || loaded() || _owner->cancelled()) {
|
||||
return;
|
||||
} else if (!item && !_owner->sticker() && !_owner->isAnimation()) {
|
||||
return;
|
||||
}
|
||||
const auto toCache = _owner->saveToCache();
|
||||
if (!toCache && Global::AskDownloadPath()) {
|
||||
// We need a filename, but we're supposed to ask user for it.
|
||||
// No automatic download in this case.
|
||||
return;
|
||||
}
|
||||
const auto filename = toCache
|
||||
? QString()
|
||||
: DocumentFileNameForSave(_owner);
|
||||
const auto shouldLoadFromCloud = !Data::IsExecutableName(filename)
|
||||
&& (item
|
||||
? Data::AutoDownload::Should(
|
||||
_owner->session().settings().autoDownload(),
|
||||
item->history()->peer,
|
||||
_owner)
|
||||
: Data::AutoDownload::Should(
|
||||
_owner->session().settings().autoDownload(),
|
||||
_owner));
|
||||
const auto loadFromCloud = shouldLoadFromCloud
|
||||
? LoadFromCloudOrLocal
|
||||
: LoadFromLocalOnly;
|
||||
_owner->save(
|
||||
origin,
|
||||
filename,
|
||||
loadFromCloud,
|
||||
true);
|
||||
}
|
||||
|
||||
void DocumentMedia::setBytes(const QByteArray &bytes) {
|
||||
if (!bytes.isEmpty()) {
|
||||
_bytes = bytes;
|
||||
|
@ -173,15 +213,15 @@ bool DocumentMedia::loaded(bool check) const {
|
|||
}
|
||||
|
||||
float64 DocumentMedia::progress() const {
|
||||
return (owner()->uploading() || owner()->loading())
|
||||
? owner()->progress()
|
||||
return (_owner->uploading() || _owner->loading())
|
||||
? _owner->progress()
|
||||
: (loaded() ? 1. : 0.);
|
||||
}
|
||||
|
||||
bool DocumentMedia::canBePlayed() const {
|
||||
return !owner()->inappPlaybackFailed()
|
||||
&& owner()->useStreamingLoader()
|
||||
&& (loaded() || owner()->canBeStreamed());
|
||||
return !_owner->inappPlaybackFailed()
|
||||
&& _owner->useStreamingLoader()
|
||||
&& (loaded() || _owner->canBeStreamed());
|
||||
}
|
||||
|
||||
void DocumentMedia::checkStickerSmall() {
|
||||
|
@ -189,7 +229,7 @@ void DocumentMedia::checkStickerSmall() {
|
|||
if ((data && data->animated) || _owner->thumbnailEnoughForSticker()) {
|
||||
_owner->loadThumbnail(_owner->stickerSetOrigin());
|
||||
if (data && data->animated) {
|
||||
_owner->automaticLoad(_owner->stickerSetOrigin(), nullptr);
|
||||
automaticLoad(_owner->stickerSetOrigin(), nullptr);
|
||||
}
|
||||
} else {
|
||||
checkStickerLarge();
|
||||
|
|
|
@ -38,6 +38,8 @@ public:
|
|||
[[nodiscard]] float64 progress() const;
|
||||
[[nodiscard]] bool canBePlayed() const;
|
||||
|
||||
void automaticLoad(Data::FileOrigin origin, const HistoryItem *item);
|
||||
|
||||
// For DocumentData.
|
||||
static void CheckGoodThumbnail(not_null<DocumentData*> document);
|
||||
|
||||
|
|
|
@ -247,7 +247,7 @@ void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti
|
|||
const auto cornerDownload = downloadInCorner();
|
||||
|
||||
if (!_dataMedia->canBePlayed()) {
|
||||
_data->automaticLoad(_realParent->fullId(), _parent->data());
|
||||
_dataMedia->automaticLoad(_realParent->fullId(), _parent->data());
|
||||
}
|
||||
bool loaded = dataLoaded(), displayLoading = _data->displayLoading();
|
||||
bool selected = (selection == FullSelection);
|
||||
|
|
|
@ -110,7 +110,7 @@ void ThemeDocument::draw(Painter &p, const QRect &r, TextSelection selection, cr
|
|||
|
||||
ensureDataMediaCreated();
|
||||
|
||||
_data->automaticLoad(_realParent->fullId(), _parent->data());
|
||||
_dataMedia->automaticLoad(_realParent->fullId(), _parent->data());
|
||||
auto selected = (selection == FullSelection);
|
||||
auto loaded = dataLoaded();
|
||||
auto displayLoading = _data->displayLoading();
|
||||
|
|
|
@ -147,7 +147,7 @@ int Gif::resizeGetHeight(int width) {
|
|||
void Gif::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
||||
const auto document = getShownDocument();
|
||||
ensureDataMediaCreated(document);
|
||||
document->automaticLoad(fileOrigin(), nullptr);
|
||||
_dataMedia->automaticLoad(fileOrigin(), nullptr);
|
||||
|
||||
bool loaded = _dataMedia->loaded(), loading = document->loading(), displayLoading = document->displayLoading();
|
||||
if (loaded
|
||||
|
@ -1341,7 +1341,7 @@ void Game::paint(Painter &p, const QRect &clip, const PaintContext *context) con
|
|||
}
|
||||
auto animatedThumb = document && document->isAnimation();
|
||||
if (animatedThumb) {
|
||||
document->automaticLoad(fileOrigin(), nullptr);
|
||||
_dataMedia->automaticLoad(fileOrigin(), nullptr);
|
||||
|
||||
bool loaded = _dataMedia->loaded(), loading = document->loading(), displayLoading = document->displayLoading();
|
||||
if (loaded && !_gif && !_gif.isBad()) {
|
||||
|
|
|
@ -2000,13 +2000,13 @@ void OverlayWidget::displayDocument(
|
|||
if (_docMedia->canBePlayed()
|
||||
&& initStreaming(continueStreaming)) {
|
||||
} else if (_doc->isVideoFile()) {
|
||||
_doc->automaticLoad(fileOrigin(), item);
|
||||
_docMedia->automaticLoad(fileOrigin(), item);
|
||||
initStreamingThumbnail();
|
||||
} else if (_doc->isTheme()) {
|
||||
_doc->automaticLoad(fileOrigin(), item);
|
||||
_docMedia->automaticLoad(fileOrigin(), item);
|
||||
initThemePreview();
|
||||
} else {
|
||||
_doc->automaticLoad(fileOrigin(), item);
|
||||
_docMedia->automaticLoad(fileOrigin(), item);
|
||||
auto &location = _doc->location(true);
|
||||
if (location.accessEnable()) {
|
||||
const auto &path = location.name();
|
||||
|
|
|
@ -972,7 +972,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
|
|||
|
||||
const auto cornerDownload = downloadInCorner();
|
||||
|
||||
_data->automaticLoad(parent()->fullId(), parent());
|
||||
_dataMedia->automaticLoad(parent()->fullId(), parent());
|
||||
const auto loaded = dataLoaded();
|
||||
const auto displayLoading = _data->displayLoading();
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ QPixmap MediaPreviewWidget::currentImage() const {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
_document->automaticLoad(_origin, nullptr);
|
||||
_documentMedia->automaticLoad(_origin, nullptr);
|
||||
if (_documentMedia->loaded()) {
|
||||
if (!_gif && !_gif.isBad()) {
|
||||
auto that = const_cast<MediaPreviewWidget*>(this);
|
||||
|
|
Loading…
Reference in New Issue