mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Add automatic loading of videos/files.
This commit is contained in:
@@ -632,38 +632,42 @@ void DocumentData::unload() {
|
||||
void DocumentData::automaticLoad(
|
||||
Data::FileOrigin origin,
|
||||
const HistoryItem *item) {
|
||||
if (loaded() || status != FileReady) return;
|
||||
|
||||
if (saveToCache() && _loader != CancelledMtpFileLoader) {
|
||||
if (type == StickerDocument
|
||||
|| isAnimation()
|
||||
|| (isVoiceMessage() && item)) {
|
||||
const auto shouldLoadFromCloud = item
|
||||
? Data::AutoDownload::Should(
|
||||
Auth().settings().autoDownload(),
|
||||
item->history()->peer,
|
||||
this)
|
||||
: Data::AutoDownload::Should(
|
||||
Auth().settings().autoDownload(),
|
||||
this);
|
||||
const auto loadFromCloud = shouldLoadFromCloud
|
||||
? LoadFromCloudOrLocal
|
||||
: LoadFromLocalOnly;
|
||||
save(
|
||||
origin,
|
||||
QString(),
|
||||
_actionOnLoad,
|
||||
_actionOnLoadMsgId,
|
||||
loadFromCloud,
|
||||
true);
|
||||
}
|
||||
if (status != FileReady || 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 = item
|
||||
? Data::AutoDownload::Should(
|
||||
Auth().settings().autoDownload(),
|
||||
item->history()->peer,
|
||||
this)
|
||||
: Data::AutoDownload::Should(
|
||||
Auth().settings().autoDownload(),
|
||||
this);
|
||||
const auto loadFromCloud = shouldLoadFromCloud
|
||||
? LoadFromCloudOrLocal
|
||||
: LoadFromLocalOnly;
|
||||
save(
|
||||
origin,
|
||||
filename,
|
||||
_actionOnLoad,
|
||||
_actionOnLoadMsgId,
|
||||
loadFromCloud,
|
||||
true);
|
||||
}
|
||||
|
||||
void DocumentData::automaticLoadSettingsChanged() {
|
||||
if (_loader != CancelledMtpFileLoader
|
||||
|| status != FileReady
|
||||
|| loaded()) {
|
||||
if (!cancelled() || status != FileReady || loaded()) {
|
||||
return;
|
||||
}
|
||||
_loader = nullptr;
|
||||
@@ -790,7 +794,7 @@ bool DocumentData::loaded(FilePathResolveType type) const {
|
||||
|
||||
void DocumentData::destroyLoader(mtpFileLoader *newValue) const {
|
||||
const auto loader = std::exchange(_loader, newValue);
|
||||
if (_loader == CancelledMtpFileLoader) {
|
||||
if (cancelled()) {
|
||||
loader->cancel();
|
||||
}
|
||||
loader->stop();
|
||||
@@ -798,7 +802,7 @@ void DocumentData::destroyLoader(mtpFileLoader *newValue) const {
|
||||
}
|
||||
|
||||
bool DocumentData::loading() const {
|
||||
return _loader && _loader != CancelledMtpFileLoader;
|
||||
return _loader && !cancelled();
|
||||
}
|
||||
|
||||
QString DocumentData::loadingFilePath() const {
|
||||
@@ -874,7 +878,7 @@ void DocumentData::save(
|
||||
return;
|
||||
}
|
||||
|
||||
if (_loader == CancelledMtpFileLoader) {
|
||||
if (cancelled()) {
|
||||
_loader = nullptr;
|
||||
}
|
||||
if (_loader) {
|
||||
@@ -887,7 +891,9 @@ void DocumentData::save(
|
||||
_actionOnLoad = action;
|
||||
_actionOnLoadMsgId = actionMsgId;
|
||||
if (_loader) {
|
||||
if (fromCloud == LoadFromCloudOrLocal) _loader->permitLoadFromCloud();
|
||||
if (fromCloud == LoadFromCloudOrLocal) {
|
||||
_loader->permitLoadFromCloud();
|
||||
}
|
||||
} else {
|
||||
status = FileReady;
|
||||
if (hasWebLocation()) {
|
||||
@@ -922,6 +928,8 @@ void DocumentData::save(
|
||||
|
||||
_loader->connect(_loader, SIGNAL(progress(FileLoader*)), App::main(), SLOT(documentLoadProgress(FileLoader*)));
|
||||
_loader->connect(_loader, SIGNAL(failed(FileLoader*,bool)), App::main(), SLOT(documentLoadFailed(FileLoader*,bool)));
|
||||
}
|
||||
if (loading()) {
|
||||
_loader->start();
|
||||
}
|
||||
_session->data().notifyDocumentLayoutChanged(this);
|
||||
@@ -934,13 +942,15 @@ void DocumentData::cancel() {
|
||||
|
||||
destroyLoader(CancelledMtpFileLoader);
|
||||
_session->data().notifyDocumentLayoutChanged(this);
|
||||
if (auto main = App::main()) {
|
||||
main->documentLoadProgress(this);
|
||||
}
|
||||
App::main()->documentLoadProgress(this);
|
||||
|
||||
_actionOnLoad = ActionOnLoadNone;
|
||||
}
|
||||
|
||||
bool DocumentData::cancelled() const {
|
||||
return (_loader == CancelledMtpFileLoader);
|
||||
}
|
||||
|
||||
VoiceWaveform documentWaveformDecode(const QByteArray &encoded5bit) {
|
||||
auto bitsCount = static_cast<int>(encoded5bit.size() * 8);
|
||||
auto valuesCount = bitsCount / 5;
|
||||
|
Reference in New Issue
Block a user