fixed opening of uncompressed image sent from clipboard, intro refactoring finished

This commit is contained in:
John Preston 2016-03-16 14:54:37 +03:00
parent d58e63c82f
commit c2f1e95f3f
13 changed files with 115 additions and 112 deletions

View File

@ -224,12 +224,8 @@ void StickerSetInner::paintEvent(QPaintEvent *e) {
if (doc->status == FileReady) { if (doc->status == FileReady) {
doc->automaticLoad(0); doc->automaticLoad(0);
} }
if (doc->sticker()->img->isNull() && doc->loaded() && doc->loaded(true)) { if (doc->sticker()->img->isNull() && doc->loaded(DocumentData::FilePathResolveChecked)) {
if (doc->data().isEmpty()) { doc->sticker()->img = doc->data().isEmpty() ? ImagePtr(doc->filepath()) : ImagePtr(doc->data());
doc->sticker()->img = ImagePtr(doc->already());
} else {
doc->sticker()->img = ImagePtr(doc->data());
}
} }
} }

View File

@ -3859,7 +3859,7 @@ void HistoryVideo::updateStatusText(const HistoryItem *parent) const {
statusSize = _data->uploadOffset; statusSize = _data->uploadOffset;
} else if (_data->loading()) { } else if (_data->loading()) {
statusSize = _data->loadOffset(); statusSize = _data->loadOffset();
} else if (!_data->already().isEmpty()) { } else if (_data->loaded()) {
statusSize = FileStatusSizeLoaded; statusSize = FileStatusSizeLoaded;
} else { } else {
statusSize = FileStatusSizeReady; statusSize = FileStatusSizeReady;

View File

@ -657,10 +657,10 @@ void HistoryInner::onDragExec() {
mimeData->setData(qsl("application/x-td-forward-pressed"), "1"); mimeData->setData(qsl("application/x-td-forward-pressed"), "1");
} }
if (lnkDocument) { if (lnkDocument) {
QString already = static_cast<DocumentOpenLink*>(textlnkDown().data())->document()->already(true); QString filepath = static_cast<DocumentOpenLink*>(textlnkDown().data())->document()->filepath(DocumentData::FilePathResolveChecked);
if (!already.isEmpty()) { if (!filepath.isEmpty()) {
QList<QUrl> urls; QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(already)); urls.push_back(QUrl::fromLocalFile(filepath));
mimeData->setUrls(urls); mimeData->setUrls(urls);
} }
} }
@ -892,7 +892,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
if (lnkDocument && lnkDocument->document()->loaded() && lnkDocument->document()->isGifv()) { if (lnkDocument && lnkDocument->document()->loaded() && lnkDocument->document()->isGifv()) {
_menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true); _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((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); _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()) { if (doc->isGifv()) {
_menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true); _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((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); _menu->addAction(lang(lng_context_save_file), this, SLOT(saveContextFile()))->setEnabled(true);
@ -1101,17 +1101,19 @@ void HistoryInner::cancelContextDownload() {
} }
void HistoryInner::showContextInFolder() { void HistoryInner::showContextInFolder() {
QString already; QString filepath;
if (DocumentLink *lnkDocument = dynamic_cast<DocumentLink*>(_contextMenuLnk.data())) { if (DocumentLink *lnkDocument = dynamic_cast<DocumentLink*>(_contextMenuLnk.data())) {
already = lnkDocument->document()->already(true); filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked);
} else if (HistoryItem *item = App::contextItem()) { } else if (HistoryItem *item = App::contextItem()) {
if (HistoryMedia *media = item->getMedia()) { if (HistoryMedia *media = item->getMedia()) {
if (DocumentData *doc = media->getDocument()) { 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() { void HistoryInner::saveContextFile() {

View File

@ -276,7 +276,7 @@ bool IntroCode::codeSubmitFail(const RPCError &error) {
return true; return true;
} else if (err == "PHONE_NUMBER_UNOCCUPIED") { // success, need to signUp } else if (err == "PHONE_NUMBER_UNOCCUPIED") { // success, need to signUp
intro()->setCode(sentCode); intro()->setCode(sentCode);
intro()->nextStep(new IntroSignup(intro())); intro()->replaceStep(new IntroSignup(intro()));
return true; return true;
} else if (err == "SESSION_PASSWORD_NEEDED") { } else if (err == "SESSION_PASSWORD_NEEDED") {
intro()->setCode(sentCode); intro()->setCode(sentCode);
@ -338,7 +338,7 @@ void IntroCode::gotPassword(const MTPaccount_Password &result) {
intro()->setPwdSalt(qba(d.vcurrent_salt)); intro()->setPwdSalt(qba(d.vcurrent_salt));
intro()->setHasRecovery(mtpIsTrue(d.vhas_recovery)); intro()->setHasRecovery(mtpIsTrue(d.vhas_recovery));
intro()->setPwdHint(qs(d.vhint)); intro()->setPwdHint(qs(d.vhint));
intro()->nextStep(new IntroPwdCheck(intro())); intro()->replaceStep(new IntroPwdCheck(intro()));
} break; } break;
} }
} }

View File

@ -19,6 +19,8 @@ Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "intro/intropwdcheck.h"
#include "lang.h" #include "lang.h"
#include "style.h" #include "style.h"
@ -27,7 +29,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "application.h" #include "application.h"
#include "intro/intropwdcheck.h" #include "intro/introsignup.h"
IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent) IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent)
, a_errorAlpha(0) , a_errorAlpha(0)
@ -337,7 +339,7 @@ bool IntroPwdCheck::deleteFail(const RPCError &error) {
void IntroPwdCheck::deleteDone(const MTPBool &v) { void IntroPwdCheck::deleteDone(const MTPBool &v) {
Ui::hideLayer(); Ui::hideLayer();
intro()->onBack(); intro()->replaceStep(new IntroSignup(intro()));
} }
void IntroPwdCheck::onInputChange() { void IntroPwdCheck::onInputChange() {

View File

@ -164,7 +164,9 @@ public:
protected: protected:
IntroWidget *intro() { IntroWidget *intro() {
return qobject_cast<IntroWidget*>(parent()); IntroWidget *result = qobject_cast<IntroWidget*>(parentWidget());
t_assert(result != nullptr);
return result;
} }
}; };

View File

@ -533,7 +533,7 @@ void LayoutOverviewVideo::updateStatusText() const {
statusSize = _data->uploadOffset; statusSize = _data->uploadOffset;
} else if (_data->loading()) { } else if (_data->loading()) {
statusSize = _data->loadOffset(); statusSize = _data->loadOffset();
} else if (!_data->already().isEmpty()) { } else if (_data->loaded()) {
statusSize = FileStatusSizeLoaded; statusSize = FileStatusSizeLoaded;
} else { } else {
statusSize = FileStatusSizeReady; statusSize = FileStatusSizeReady;

View File

@ -1753,24 +1753,9 @@ void MainWidget::audioPlayProgress(const AudioMsgId &audioId) {
audioPlayer()->clearStoppedAtStart(audioId); audioPlayer()->clearStoppedAtStart(audioId);
DocumentData *audio = audioId.audio; DocumentData *audio = audioId.audio;
QString already = audio->already(true); QString filepath = audio->filepath(DocumentData::FilePathResolveSaveFromData);
if (already.isEmpty() && !audio->data().isEmpty()) { if (!filepath.isEmpty()) {
bool mp3 = (audio->mime == qstr("audio/mp3")); psOpenFile(filepath);
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);
} }
} }
@ -1790,35 +1775,9 @@ void MainWidget::documentPlayProgress(const SongMsgId &songId) {
audioPlayer()->clearStoppedAtStart(songId); audioPlayer()->clearStoppedAtStart(songId);
DocumentData *document = songId.song; DocumentData *document = songId.song;
QString already = document->already(true); QString filepath = document->filepath(DocumentData::FilePathResolveSaveFromData);
if (already.isEmpty() && !document->data().isEmpty()) { if (!filepath.isEmpty()) {
QString name = document->name, filter; psOpenFile(filepath);
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);
} }
} }

View File

@ -313,7 +313,7 @@ void MediaView::updateControls() {
_docRadial.start(_doc->progress()); _docRadial.start(_doc->progress());
} }
} else { } else {
if (_doc->loaded(true)) { if (_doc->loaded(DocumentData::FilePathResolveChecked)) {
_docDownload.hide(); _docDownload.hide();
_docSaveAs.moveToLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocIconSize, _docRect.y() + st::mvDocPadding + st::mvDocLinksTop); _docSaveAs.moveToLeft(_docRect.x() + 2 * st::mvDocPadding + st::mvDocIconSize, _docRect.y() + st::mvDocPadding + st::mvDocLinksTop);
_docSaveAs.show(); _docSaveAs.show();
@ -333,7 +333,7 @@ void MediaView::updateControls() {
_docCancel.hide(); _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()); _saveNav = myrtlrect(width() - st::mvIconSize.width() * 2, height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height());
_saveNavIcon = centersprite(_saveNav, st::mvSave); _saveNavIcon = centersprite(_saveNav, st::mvSave);
_moreNav = myrtlrect(width() - st::mvIconSize.width(), height() - st::mvIconSize.height(), st::mvIconSize.width(), st::mvIconSize.height()); _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() { void MediaView::updateDropdown() {
_btnSaveCancel->setVisible(_doc && _doc->loading()); _btnSaveCancel->setVisible(_doc && _doc->loading());
_btnToMessage->setVisible(_msgid > 0); _btnToMessage->setVisible(_msgid > 0);
_btnShowInFolder->setVisible(_doc && !_doc->already(true).isEmpty()); _btnShowInFolder->setVisible(_doc && !_doc->filepath(DocumentData::FilePathResolveChecked).isEmpty());
_btnSaveAs->setVisible(true); _btnSaveAs->setVisible(true);
_btnCopy->setVisible((_doc && fileShown()) || (_photo && _photo->loaded())); _btnCopy->setVisible((_doc && fileShown()) || (_photo && _photo->loaded()));
_btnForward->setVisible(_canForward); _btnForward->setVisible(_canForward);
@ -685,8 +685,11 @@ void MediaView::onSaveCancel() {
void MediaView::onShowInFolder() { void MediaView::onShowInFolder() {
if (!_doc) return; 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() { void MediaView::onForward() {

View File

@ -661,10 +661,10 @@ void OverviewInner::onDragExec() {
mimeData->setData(qsl("application/x-td-forward-pressed-link"), "1"); mimeData->setData(qsl("application/x-td-forward-pressed-link"), "1");
if (lnkDocument) { if (lnkDocument) {
QString already = static_cast<DocumentOpenLink*>(textlnkDown().data())->document()->already(true); QString filepath = static_cast<DocumentOpenLink*>(textlnkDown().data())->document()->filepath(DocumentData::FilePathResolveChecked);
if (!already.isEmpty()) { if (!filepath.isEmpty()) {
QList<QUrl> urls; QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(already)); urls.push_back(QUrl::fromLocalFile(filepath));
mimeData->setUrls(urls); mimeData->setUrls(urls);
} }
} }
@ -1275,7 +1275,7 @@ void OverviewInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
if (lnkDocument && lnkDocument->document()->loading()) { if (lnkDocument && lnkDocument->document()->loading()) {
_menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true); _menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true);
} else { } 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((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); _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() { void OverviewInner::showContextInFolder() {
DocumentLink *lnkDocument = dynamic_cast<DocumentLink*>(_contextMenuLnk.data()); if (DocumentLink *lnkDocument = dynamic_cast<DocumentLink*>(_contextMenuLnk.data())) {
QString already = lnkDocument ? lnkDocument->document()->already(true) : QString(); QString filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked);
if (!already.isEmpty()) psShowInFolder(already); if (!filepath.isEmpty()) {
psShowInFolder(filepath);
}
}
} }
void OverviewInner::saveContextFile() { void OverviewInner::saveContextFile() {

View File

@ -324,7 +324,7 @@ void PlayerWidget::preloadNext() {
if (next) { if (next) {
if (HistoryDocument *document = static_cast<HistoryDocument*>(next->getMedia())) { if (HistoryDocument *document = static_cast<HistoryDocument*>(next->getMedia())) {
DocumentData *d = document->getDocument(); DocumentData *d = document->getDocument();
if (!d->loaded(true)) { if (!d->loaded(DocumentData::FilePathResolveSaveFromDataSilent)) {
DocumentOpenLink::doOpen(d, ActionOnLoadNone); DocumentOpenLink::doOpen(d, ActionOnLoadNone);
} }
} }

View File

@ -787,7 +787,7 @@ bool StickerData::setInstalled() const {
return false; 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; QString name, filter, caption, prefix;
MimeType mimeType = mimeTypeForName(data->mime); MimeType mimeType = mimeTypeForName(data->mime);
QStringList p = mimeType.globPatterns(); QStringList p = mimeType.globPatterns();
@ -914,22 +914,21 @@ void GifOpenLink::onClick(Qt::MouseButton button) const {
void DocumentSaveLink::doSave(DocumentData *data, bool forceSavingAs) { void DocumentSaveLink::doSave(DocumentData *data, bool forceSavingAs) {
if (!data->date) return; if (!data->date) return;
QString already = data->already(true); QString filepath = data->filepath(DocumentData::FilePathResolveSaveFromData, forceSavingAs);
bool openWith = !already.isEmpty(); if (!filepath.isEmpty() && !forceSavingAs) {
if (openWith && !forceSavingAs) {
QPoint pos(QCursor::pos()); QPoint pos(QCursor::pos());
if (!psShowOpenWithMenu(pos.x(), pos.y(), already)) { if (!psShowOpenWithMenu(pos.x(), pos.y(), filepath)) {
psOpenFile(already, true); psOpenFile(filepath, true);
} }
} else { } else {
QFileInfo alreadyInfo(already); QFileInfo fileinfo(filepath);
QDir alreadyDir(already.isEmpty() ? QDir() : alreadyInfo.dir()); QDir filedir(filepath.isEmpty() ? QDir() : fileinfo.dir());
QString alreadyName(already.isEmpty() ? QString() : alreadyInfo.fileName()); QString filename(filepath.isEmpty() ? QString() : fileinfo.fileName());
QString filename = documentSaveFilename(data, forceSavingAs, alreadyName, alreadyDir); QString newfname = documentSaveFilename(data, forceSavingAs, filename, filedir);
if (!filename.isEmpty()) { if (!newfname.isEmpty()) {
ActionOnLoad action = already.isEmpty() ? ActionOnLoadNone : ActionOnLoadOpenWith; ActionOnLoad action = filename.isEmpty() ? ActionOnLoadNone : ActionOnLoadOpenWith;
FullMsgId actionMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId()); 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; _actionOnLoad = ActionOnLoadNone;
} }
bool DocumentData::loaded(bool check) const { bool DocumentData::loaded(FilePathResolveType type) const {
if (loading() && _loader->done()) { if (loading() && _loader->done()) {
if (_loader->fileType() == mtpc_storage_fileUnknown) { if (_loader->fileType() == mtpc_storage_fileUnknown) {
_loader->deleteLater(); _loader->deleteLater();
@ -1200,7 +1199,7 @@ bool DocumentData::loaded(bool check) const {
} }
notifyLayoutChanged(); notifyLayoutChanged();
} }
return !_data.isEmpty() || !already(check).isEmpty(); return !data().isEmpty() || !filepath(type).isEmpty();
} }
bool DocumentData::loading() const { 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) { 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)); const FileLocation &l(location(true));
if (!toFile.isEmpty()) { if (!toFile.isEmpty()) {
if (!_data.isEmpty()) { if (!_data.isEmpty()) {
QFile f(toFile); QFile f(toFile);
f.open(QIODevice::WriteOnly); f.open(QIODevice::WriteOnly);
f.write(_data); f.write(_data);
f.close();
setLocation(FileLocation(StorageFilePartial, toFile));
Local::writeFileLocation(mediaKey(), FileLocation(mtpToStorageType(mtpc_storage_filePartial), toFile));
} else if (l.accessEnable()) { } else if (l.accessEnable()) {
QFile(l.name()).copy(toFile); QFile(l.name()).copy(toFile);
l.accessDisable(); l.accessDisable();
} }
} }
performActionOnLoad();
return; return;
} }
@ -1253,15 +1260,11 @@ void DocumentData::save(const QString &toFile, ActionOnLoad action, const FullMs
} }
} }
_actionOnLoad = action;
_actionOnLoadMsgId = actionMsgId;
if (_loader) { if (_loader) {
if (fromCloud == LoadFromCloudOrLocal) _loader->permitLoadFromCloud(); if (fromCloud == LoadFromCloudOrLocal) _loader->permitLoadFromCloud();
} else { } else {
status = FileReady; status = FileReady;
LocationType type = voice() ? AudioFileLocation : (isVideo() ? VideoFileLocation : DocumentFileLocation); _loader = new mtpFileLoader(dc, id, access, locationType(), toFile, size, (saveToCache() ? LoadToCacheAsWell : LoadToFileOnly), fromCloud, autoLoading);
_loader = new mtpFileLoader(dc, id, access, type, toFile, size, (saveToCache() ? LoadToCacheAsWell : LoadToFileOnly), fromCloud, autoLoading);
_loader->connect(_loader, SIGNAL(progress(FileLoader*)), App::main(), SLOT(documentLoadProgress(FileLoader*))); _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->connect(_loader, SIGNAL(failed(FileLoader*,bool)), App::main(), SLOT(documentLoadFailed(FileLoader*,bool)));
_loader->start(); _loader->start();
@ -1312,11 +1315,6 @@ QByteArray documentWaveformEncode5bit(const VoiceWaveform &waveform) {
return result; return result;
} }
QString DocumentData::already(bool check) const {
if (check && _location.name().isEmpty()) return QString();
return location(check).name();
}
QByteArray DocumentData::data() const { QByteArray DocumentData::data() const {
return _data; 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<DocumentData*>(this)->_location = FileLocation(StorageFilePartial, filename);
Local::writeFileLocation(mediaKey(), _location);
result = filename;
}
}
}
}
return result;
}
ImagePtr DocumentData::makeReplyPreview() { ImagePtr DocumentData::makeReplyPreview() {
if (replyPreview->isNull() && !thumb->isNull()) { if (replyPreview->isNull() && !thumb->isNull()) {
if (thumb->loaded()) { if (thumb->loaded()) {

View File

@ -916,7 +916,13 @@ public:
void automaticLoad(const HistoryItem *item); // auto load sticker or video void automaticLoad(const HistoryItem *item); // auto load sticker or video
void automaticLoadSettingsChanged(); void automaticLoadSettingsChanged();
bool loaded(bool check = false) const; enum FilePathResolveType {
FilePathResolveCached,
FilePathResolveChecked,
FilePathResolveSaveFromData,
FilePathResolveSaveFromDataSilent,
};
bool loaded(FilePathResolveType type = FilePathResolveCached) const;
bool loading() const; bool loading() const;
bool displayLoading() const; bool displayLoading() const;
void save(const QString &toFile, ActionOnLoad action = ActionOnLoadNone, const FullMsgId &actionMsgId = FullMsgId(), LoadFromCloudSetting fromCloud = LoadFromCloudOrLocal, bool autoLoading = false); 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; int32 loadOffset() const;
bool uploading() const; bool uploading() const;
QString already(bool check = false) const;
QByteArray data() const; QByteArray data() const;
const FileLocation &location(bool check = false) const; const FileLocation &location(bool check = false) const;
void setLocation(const FileLocation &loc); void setLocation(const FileLocation &loc);
QString filepath(FilePathResolveType type = FilePathResolveCached, bool forceSavingAs = false) const;
bool saveToCache() const; bool saveToCache() const;
void performActionOnLoad(); void performActionOnLoad();
@ -1007,8 +1014,7 @@ public:
int32 md5[8]; int32 md5[8];
MediaKey mediaKey() const { MediaKey mediaKey() const {
LocationType t = isVideo() ? VideoFileLocation : (voice() ? AudioFileLocation : DocumentFileLocation); return ::mediaKey(locationType(), dc, id);
return ::mediaKey(t, dc, id);
} }
private: private:
@ -1018,6 +1024,10 @@ private:
DocumentAdditionalData *_additional; DocumentAdditionalData *_additional;
int32 _duration; int32 _duration;
LocationType locationType() const {
return voice() ? AudioFileLocation : (isVideo() ? VideoFileLocation : DocumentFileLocation);
}
ActionOnLoad _actionOnLoad; ActionOnLoad _actionOnLoad;
FullMsgId _actionOnLoadMsgId; FullMsgId _actionOnLoadMsgId;
mutable mtpFileLoader *_loader; mutable mtpFileLoader *_loader;