diff --git a/Telegram/SourceFiles/boxes/stickersetbox.cpp b/Telegram/SourceFiles/boxes/stickersetbox.cpp index 65fdd9b32..b9632b4f8 100644 --- a/Telegram/SourceFiles/boxes/stickersetbox.cpp +++ b/Telegram/SourceFiles/boxes/stickersetbox.cpp @@ -224,12 +224,8 @@ void StickerSetInner::paintEvent(QPaintEvent *e) { if (doc->status == FileReady) { doc->automaticLoad(0); } - if (doc->sticker()->img->isNull() && doc->loaded() && doc->loaded(true)) { - if (doc->data().isEmpty()) { - doc->sticker()->img = ImagePtr(doc->already()); - } else { - doc->sticker()->img = ImagePtr(doc->data()); - } + if (doc->sticker()->img->isNull() && doc->loaded(DocumentData::FilePathResolveChecked)) { + doc->sticker()->img = doc->data().isEmpty() ? ImagePtr(doc->filepath()) : ImagePtr(doc->data()); } } diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index fcf242e6c..067d97cdb 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -3859,7 +3859,7 @@ void HistoryVideo::updateStatusText(const HistoryItem *parent) const { statusSize = _data->uploadOffset; } else if (_data->loading()) { statusSize = _data->loadOffset(); - } else if (!_data->already().isEmpty()) { + } else if (_data->loaded()) { statusSize = FileStatusSizeLoaded; } else { statusSize = FileStatusSizeReady; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 0ba8554d6..0b8b34fb8 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -657,10 +657,10 @@ void HistoryInner::onDragExec() { mimeData->setData(qsl("application/x-td-forward-pressed"), "1"); } if (lnkDocument) { - QString already = static_cast(textlnkDown().data())->document()->already(true); - if (!already.isEmpty()) { + QString filepath = static_cast(textlnkDown().data())->document()->filepath(DocumentData::FilePathResolveChecked); + if (!filepath.isEmpty()) { QList urls; - urls.push_back(QUrl::fromLocalFile(already)); + urls.push_back(QUrl::fromLocalFile(filepath)); mimeData->setUrls(urls); } } @@ -892,7 +892,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (lnkDocument && lnkDocument->document()->loaded() && lnkDocument->document()->isGifv()) { _menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true); } - if (lnkDocument && !lnkDocument->document()->already(true).isEmpty()) { + if (lnkDocument && !lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked).isEmpty()) { _menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true); } _menu->addAction(lang(lnkIsVideo ? lng_context_save_video : (lnkIsAudio ? lng_context_save_audio : lng_context_save_file)), this, SLOT(saveContextFile()))->setEnabled(true); @@ -976,7 +976,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (doc->isGifv()) { _menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true); } - if (!doc->already(true).isEmpty()) { + if (!doc->filepath(DocumentData::FilePathResolveChecked).isEmpty()) { _menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true); } _menu->addAction(lang(lng_context_save_file), this, SLOT(saveContextFile()))->setEnabled(true); @@ -1101,17 +1101,19 @@ void HistoryInner::cancelContextDownload() { } void HistoryInner::showContextInFolder() { - QString already; + QString filepath; if (DocumentLink *lnkDocument = dynamic_cast(_contextMenuLnk.data())) { - already = lnkDocument->document()->already(true); + filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked); } else if (HistoryItem *item = App::contextItem()) { if (HistoryMedia *media = item->getMedia()) { if (DocumentData *doc = media->getDocument()) { - already = doc->already(true); + filepath = doc->filepath(DocumentData::FilePathResolveChecked); } } } - if (!already.isEmpty()) psShowInFolder(already); + if (!filepath.isEmpty()) { + psShowInFolder(filepath); + } } void HistoryInner::saveContextFile() { diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index 71ed0bdf2..225161d2f 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -276,7 +276,7 @@ bool IntroCode::codeSubmitFail(const RPCError &error) { return true; } else if (err == "PHONE_NUMBER_UNOCCUPIED") { // success, need to signUp intro()->setCode(sentCode); - intro()->nextStep(new IntroSignup(intro())); + intro()->replaceStep(new IntroSignup(intro())); return true; } else if (err == "SESSION_PASSWORD_NEEDED") { intro()->setCode(sentCode); @@ -338,7 +338,7 @@ void IntroCode::gotPassword(const MTPaccount_Password &result) { intro()->setPwdSalt(qba(d.vcurrent_salt)); intro()->setHasRecovery(mtpIsTrue(d.vhas_recovery)); intro()->setPwdHint(qs(d.vhint)); - intro()->nextStep(new IntroPwdCheck(intro())); + intro()->replaceStep(new IntroPwdCheck(intro())); } break; } } diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index 3f2a0d5bd..da5927ec8 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -19,6 +19,8 @@ Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #include "stdafx.h" +#include "intro/intropwdcheck.h" + #include "lang.h" #include "style.h" @@ -27,7 +29,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" -#include "intro/intropwdcheck.h" +#include "intro/introsignup.h" IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent) , a_errorAlpha(0) @@ -337,7 +339,7 @@ bool IntroPwdCheck::deleteFail(const RPCError &error) { void IntroPwdCheck::deleteDone(const MTPBool &v) { Ui::hideLayer(); - intro()->onBack(); + intro()->replaceStep(new IntroSignup(intro())); } void IntroPwdCheck::onInputChange() { diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index 66ac6f02c..7aafd5593 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -164,7 +164,9 @@ public: protected: IntroWidget *intro() { - return qobject_cast(parent()); + IntroWidget *result = qobject_cast(parentWidget()); + t_assert(result != nullptr); + return result; } }; diff --git a/Telegram/SourceFiles/layout.cpp b/Telegram/SourceFiles/layout.cpp index 31605b763..b7bfc4ab0 100644 --- a/Telegram/SourceFiles/layout.cpp +++ b/Telegram/SourceFiles/layout.cpp @@ -533,7 +533,7 @@ void LayoutOverviewVideo::updateStatusText() const { statusSize = _data->uploadOffset; } else if (_data->loading()) { statusSize = _data->loadOffset(); - } else if (!_data->already().isEmpty()) { + } else if (_data->loaded()) { statusSize = FileStatusSizeLoaded; } else { statusSize = FileStatusSizeReady; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index f8c8d7b74..99d8b1da6 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1753,24 +1753,9 @@ void MainWidget::audioPlayProgress(const AudioMsgId &audioId) { audioPlayer()->clearStoppedAtStart(audioId); DocumentData *audio = audioId.audio; - QString already = audio->already(true); - if (already.isEmpty() && !audio->data().isEmpty()) { - bool mp3 = (audio->mime == qstr("audio/mp3")); - QString filename = saveFileName(lang(lng_save_audio), mp3 ? qsl("MP3 Audio (*.mp3);;All files (*.*)") : qsl("OGG Opus Audio (*.ogg);;All files (*.*)"), qsl("audio"), mp3 ? qsl(".mp3") : qsl(".ogg"), false); - if (!filename.isEmpty()) { - QFile f(filename); - if (f.open(QIODevice::WriteOnly)) { - if (f.write(audio->data()) == audio->data().size()) { - f.close(); - already = filename; - audio->setLocation(FileLocation(StorageFilePartial, filename)); - Local::writeFileLocation(mediaKey(AudioFileLocation, audio->dc, audio->id), FileLocation(mtpToStorageType(mtpc_storage_filePartial), filename)); - } - } - } - } - if (!already.isEmpty()) { - psOpenFile(already); + QString filepath = audio->filepath(DocumentData::FilePathResolveSaveFromData); + if (!filepath.isEmpty()) { + psOpenFile(filepath); } } @@ -1790,35 +1775,9 @@ void MainWidget::documentPlayProgress(const SongMsgId &songId) { audioPlayer()->clearStoppedAtStart(songId); DocumentData *document = songId.song; - QString already = document->already(true); - if (already.isEmpty() && !document->data().isEmpty()) { - QString name = document->name, filter; - MimeType mimeType = mimeTypeForName(document->mime); - QStringList p = mimeType.globPatterns(); - QString pattern = p.isEmpty() ? QString() : p.front(); - if (name.isEmpty()) { - name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString()); - } - if (pattern.isEmpty()) { - filter = QString(); - } else { - filter = mimeType.filterString() + qsl(";;All files (*.*)"); - } - QString filename = saveFileName(lang(lng_save_file), filter, qsl("doc"), name, false); - if (!filename.isEmpty()) { - QFile f(filename); - if (f.open(QIODevice::WriteOnly)) { - if (f.write(document->data()) == document->data().size()) { - f.close(); - already = filename; - document->setLocation(FileLocation(StorageFilePartial, filename)); - Local::writeFileLocation(mediaKey(DocumentFileLocation, document->dc, document->id), FileLocation(mtpToStorageType(mtpc_storage_filePartial), filename)); - } - } - } - } - if (!already.isEmpty()) { - psOpenFile(already); + QString filepath = document->filepath(DocumentData::FilePathResolveSaveFromData); + if (!filepath.isEmpty()) { + psOpenFile(filepath); } } diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 492189aa4..fc1734194 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -313,7 +313,7 @@ void MediaView::updateControls() { _docRadial.start(_doc->progress()); } } else { - if (_doc->loaded(true)) { + if (_doc->loaded(DocumentData::FilePathResolveChecked)) { _docDownload.hide(); _docSaveAs.moveToLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocIconSize, _docRect.y() + st::mvDocPadding + st::mvDocLinksTop); _docSaveAs.show(); @@ -333,7 +333,7 @@ void MediaView::updateControls() { _docCancel.hide(); } - _saveVisible = ((_photo && _photo->loaded()) || (_doc && (_doc->loaded(true) || (!fileShown() && (_photo || _doc))))); + _saveVisible = ((_photo && _photo->loaded()) || (_doc && (_doc->loaded(DocumentData::FilePathResolveChecked) || (!fileShown() && (_photo || _doc))))); _saveNav = myrtlrect(width() - st::mvIconSize.width() * 2, height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height()); _saveNavIcon = centersprite(_saveNav, st::mvSave); _moreNav = myrtlrect(width() - st::mvIconSize.width(), height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height()); @@ -394,7 +394,7 @@ void MediaView::updateControls() { void MediaView::updateDropdown() { _btnSaveCancel->setVisible(_doc && _doc->loading()); _btnToMessage->setVisible(_msgid > 0); - _btnShowInFolder->setVisible(_doc && !_doc->already(true).isEmpty()); + _btnShowInFolder->setVisible(_doc && !_doc->filepath(DocumentData::FilePathResolveChecked).isEmpty()); _btnSaveAs->setVisible(true); _btnCopy->setVisible((_doc && fileShown()) || (_photo && _photo->loaded())); _btnForward->setVisible(_canForward); @@ -685,8 +685,11 @@ void MediaView::onSaveCancel() { void MediaView::onShowInFolder() { if (!_doc) return; - QString already(_doc->already(true)); - if (!already.isEmpty()) psShowInFolder(already); + + QString filepath = _doc->filepath(DocumentData::FilePathResolveChecked); + if (!filepath.isEmpty()) { + psShowInFolder(filepath); + } } void MediaView::onForward() { diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index 2430d02d5..67013cf18 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -661,10 +661,10 @@ void OverviewInner::onDragExec() { mimeData->setData(qsl("application/x-td-forward-pressed-link"), "1"); if (lnkDocument) { - QString already = static_cast(textlnkDown().data())->document()->already(true); - if (!already.isEmpty()) { + QString filepath = static_cast(textlnkDown().data())->document()->filepath(DocumentData::FilePathResolveChecked); + if (!filepath.isEmpty()) { QList urls; - urls.push_back(QUrl::fromLocalFile(already)); + urls.push_back(QUrl::fromLocalFile(filepath)); mimeData->setUrls(urls); } } @@ -1275,7 +1275,7 @@ void OverviewInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (lnkDocument && lnkDocument->document()->loading()) { _menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true); } else { - if (lnkDocument && !lnkDocument->document()->already(true).isEmpty()) { + if (lnkDocument && !lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked).isEmpty()) { _menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true); } _menu->addAction(lang(lnkIsVideo ? lng_context_save_video : (lnkIsAudio ? lng_context_save_audio : lng_context_save_file)), this, SLOT(saveContextFile()))->setEnabled(true); @@ -1496,9 +1496,12 @@ void OverviewInner::cancelContextDownload() { } void OverviewInner::showContextInFolder() { - DocumentLink *lnkDocument = dynamic_cast(_contextMenuLnk.data()); - QString already = lnkDocument ? lnkDocument->document()->already(true) : QString(); - if (!already.isEmpty()) psShowInFolder(already); + if (DocumentLink *lnkDocument = dynamic_cast(_contextMenuLnk.data())) { + QString filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked); + if (!filepath.isEmpty()) { + psShowInFolder(filepath); + } + } } void OverviewInner::saveContextFile() { diff --git a/Telegram/SourceFiles/playerwidget.cpp b/Telegram/SourceFiles/playerwidget.cpp index 1ab72f6c5..eefeb4da0 100644 --- a/Telegram/SourceFiles/playerwidget.cpp +++ b/Telegram/SourceFiles/playerwidget.cpp @@ -324,7 +324,7 @@ void PlayerWidget::preloadNext() { if (next) { if (HistoryDocument *document = static_cast(next->getMedia())) { DocumentData *d = document->getDocument(); - if (!d->loaded(true)) { + if (!d->loaded(DocumentData::FilePathResolveSaveFromDataSilent)) { DocumentOpenLink::doOpen(d, ActionOnLoadNone); } } diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index b1122e559..ce45404dd 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -787,7 +787,7 @@ bool StickerData::setInstalled() const { return false; } -QString documentSaveFilename(DocumentData *data, bool forceSavingAs = false, const QString already = QString(), const QDir &dir = QDir()) { +QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = false, const QString already = QString(), const QDir &dir = QDir()) { QString name, filter, caption, prefix; MimeType mimeType = mimeTypeForName(data->mime); QStringList p = mimeType.globPatterns(); @@ -914,22 +914,21 @@ void GifOpenLink::onClick(Qt::MouseButton button) const { void DocumentSaveLink::doSave(DocumentData *data, bool forceSavingAs) { if (!data->date) return; - QString already = data->already(true); - bool openWith = !already.isEmpty(); - if (openWith && !forceSavingAs) { + QString filepath = data->filepath(DocumentData::FilePathResolveSaveFromData, forceSavingAs); + if (!filepath.isEmpty() && !forceSavingAs) { QPoint pos(QCursor::pos()); - if (!psShowOpenWithMenu(pos.x(), pos.y(), already)) { - psOpenFile(already, true); + if (!psShowOpenWithMenu(pos.x(), pos.y(), filepath)) { + psOpenFile(filepath, true); } } else { - QFileInfo alreadyInfo(already); - QDir alreadyDir(already.isEmpty() ? QDir() : alreadyInfo.dir()); - QString alreadyName(already.isEmpty() ? QString() : alreadyInfo.fileName()); - QString filename = documentSaveFilename(data, forceSavingAs, alreadyName, alreadyDir); - if (!filename.isEmpty()) { - ActionOnLoad action = already.isEmpty() ? ActionOnLoadNone : ActionOnLoadOpenWith; + QFileInfo fileinfo(filepath); + QDir filedir(filepath.isEmpty() ? QDir() : fileinfo.dir()); + QString filename(filepath.isEmpty() ? QString() : fileinfo.fileName()); + QString newfname = documentSaveFilename(data, forceSavingAs, filename, filedir); + if (!newfname.isEmpty()) { + ActionOnLoad action = filename.isEmpty() ? ActionOnLoadNone : ActionOnLoadOpenWith; FullMsgId actionMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId()); - data->save(filename, action, actionMsgId); + data->save(newfname, action, actionMsgId); } } } @@ -1180,7 +1179,7 @@ void DocumentData::performActionOnLoad() { _actionOnLoad = ActionOnLoadNone; } -bool DocumentData::loaded(bool check) const { +bool DocumentData::loaded(FilePathResolveType type) const { if (loading() && _loader->done()) { if (_loader->fileType() == mtpc_storage_fileUnknown) { _loader->deleteLater(); @@ -1200,7 +1199,7 @@ bool DocumentData::loaded(bool check) const { } notifyLayoutChanged(); } - return !_data.isEmpty() || !already(check).isEmpty(); + return !data().isEmpty() || !filepath(type).isEmpty(); } bool DocumentData::loading() const { @@ -1230,18 +1229,26 @@ bool DocumentData::uploading() const { } void DocumentData::save(const QString &toFile, ActionOnLoad action, const FullMsgId &actionMsgId, LoadFromCloudSetting fromCloud, bool autoLoading) { - if (loaded(true)) { + _actionOnLoad = action; + _actionOnLoadMsgId = actionMsgId; + + if (loaded(FilePathResolveChecked)) { const FileLocation &l(location(true)); if (!toFile.isEmpty()) { if (!_data.isEmpty()) { QFile f(toFile); f.open(QIODevice::WriteOnly); f.write(_data); + f.close(); + + setLocation(FileLocation(StorageFilePartial, toFile)); + Local::writeFileLocation(mediaKey(), FileLocation(mtpToStorageType(mtpc_storage_filePartial), toFile)); } else if (l.accessEnable()) { QFile(l.name()).copy(toFile); l.accessDisable(); } } + performActionOnLoad(); return; } @@ -1253,15 +1260,11 @@ void DocumentData::save(const QString &toFile, ActionOnLoad action, const FullMs } } - _actionOnLoad = action; - _actionOnLoadMsgId = actionMsgId; - if (_loader) { if (fromCloud == LoadFromCloudOrLocal) _loader->permitLoadFromCloud(); } else { status = FileReady; - LocationType type = voice() ? AudioFileLocation : (isVideo() ? VideoFileLocation : DocumentFileLocation); - _loader = new mtpFileLoader(dc, id, access, type, toFile, size, (saveToCache() ? LoadToCacheAsWell : LoadToFileOnly), fromCloud, autoLoading); + _loader = new mtpFileLoader(dc, id, access, locationType(), toFile, size, (saveToCache() ? LoadToCacheAsWell : LoadToFileOnly), fromCloud, autoLoading); _loader->connect(_loader, SIGNAL(progress(FileLoader*)), App::main(), SLOT(documentLoadProgress(FileLoader*))); _loader->connect(_loader, SIGNAL(failed(FileLoader*,bool)), App::main(), SLOT(documentLoadFailed(FileLoader*,bool))); _loader->start(); @@ -1312,11 +1315,6 @@ QByteArray documentWaveformEncode5bit(const VoiceWaveform &waveform) { return result; } -QString DocumentData::already(bool check) const { - if (check && _location.name().isEmpty()) return QString(); - return location(check).name(); -} - QByteArray DocumentData::data() const { return _data; } @@ -1334,6 +1332,34 @@ void DocumentData::setLocation(const FileLocation &loc) { } } +QString DocumentData::filepath(FilePathResolveType type, bool forceSavingAs) const { + bool check = (type != FilePathResolveCached); + QString result = (check && _location.name().isEmpty()) ? QString() : location(check).name(); + bool saveFromData = result.isEmpty() && !data().isEmpty(); + if (saveFromData) { + if (type != FilePathResolveSaveFromData && type != FilePathResolveSaveFromDataSilent) { + saveFromData = false; + } else if (type == FilePathResolveSaveFromDataSilent && cAskDownloadPath()) { + saveFromData = false; + } + } + if (saveFromData) { + QString filename = documentSaveFilename(this, forceSavingAs); + if (!filename.isEmpty()) { + QFile f(filename); + if (f.open(QIODevice::WriteOnly)) { + if (f.write(data()) == data().size()) { + f.close(); + const_cast(this)->_location = FileLocation(StorageFilePartial, filename); + Local::writeFileLocation(mediaKey(), _location); + result = filename; + } + } + } + } + return result; +} + ImagePtr DocumentData::makeReplyPreview() { if (replyPreview->isNull() && !thumb->isNull()) { if (thumb->loaded()) { diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index a5c5c8a0b..23616afcd 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -916,7 +916,13 @@ public: void automaticLoad(const HistoryItem *item); // auto load sticker or video void automaticLoadSettingsChanged(); - bool loaded(bool check = false) const; + enum FilePathResolveType { + FilePathResolveCached, + FilePathResolveChecked, + FilePathResolveSaveFromData, + FilePathResolveSaveFromDataSilent, + }; + bool loaded(FilePathResolveType type = FilePathResolveCached) const; bool loading() const; bool displayLoading() const; void save(const QString &toFile, ActionOnLoad action = ActionOnLoadNone, const FullMsgId &actionMsgId = FullMsgId(), LoadFromCloudSetting fromCloud = LoadFromCloudOrLocal, bool autoLoading = false); @@ -925,11 +931,12 @@ public: int32 loadOffset() const; bool uploading() const; - QString already(bool check = false) const; QByteArray data() const; const FileLocation &location(bool check = false) const; void setLocation(const FileLocation &loc); + QString filepath(FilePathResolveType type = FilePathResolveCached, bool forceSavingAs = false) const; + bool saveToCache() const; void performActionOnLoad(); @@ -1007,8 +1014,7 @@ public: int32 md5[8]; MediaKey mediaKey() const { - LocationType t = isVideo() ? VideoFileLocation : (voice() ? AudioFileLocation : DocumentFileLocation); - return ::mediaKey(t, dc, id); + return ::mediaKey(locationType(), dc, id); } private: @@ -1018,6 +1024,10 @@ private: DocumentAdditionalData *_additional; int32 _duration; + LocationType locationType() const { + return voice() ? AudioFileLocation : (isVideo() ? VideoFileLocation : DocumentFileLocation); + } + ActionOnLoad _actionOnLoad; FullMsgId _actionOnLoadMsgId; mutable mtpFileLoader *_loader;