Filter RTL in displayed file names(#156)

Adopted from upstream commit aec496d520 to avoid the phishing filenames.

Closes #103.
This commit is contained in:
Evgeniy Zheltonozhskiy 2018-06-20 22:20:39 +03:00 committed by Alex
parent 0d013603bd
commit 9f1896c680
14 changed files with 87 additions and 63 deletions

View File

@ -1709,7 +1709,7 @@ DocumentData *documentSet(const DocumentId &document, DocumentData *convert, con
versionChanged = convert->setRemoteVersion(version); versionChanged = convert->setRemoteVersion(version);
convert->setRemoteLocation(dc, access); convert->setRemoteLocation(dc, access);
convert->date = date; convert->date = date;
convert->mime = mime; convert->setMimeString(mime);
if (!thumb->isNull() && (convert->thumb->isNull() || convert->thumb->width() < thumb->width() || if (!thumb->isNull() && (convert->thumb->isNull() || convert->thumb->width() < thumb->width() ||
convert->thumb->height() < thumb->height() || versionChanged)) { convert->thumb->height() < thumb->height() || versionChanged)) {
updateImage(convert->thumb, thumb); updateImage(convert->thumb, thumb);
@ -1742,7 +1742,7 @@ DocumentData *documentSet(const DocumentId &document, DocumentData *convert, con
} else { } else {
result = DocumentData::create(document, dc, access, version, attributes); result = DocumentData::create(document, dc, access, version, attributes);
result->date = date; result->date = date;
result->mime = mime; result->setMimeString(mime);
result->thumb = thumb; result->thumb = thumb;
result->size = size; result->size = size;
result->recountIsImage(); result->recountIsImage();
@ -1760,7 +1760,7 @@ DocumentData *documentSet(const DocumentId &document, DocumentData *convert, con
result->setRemoteLocation(dc, access); result->setRemoteLocation(dc, access);
} }
result->date = date; result->date = date;
result->mime = mime; result->setMimeString(mime);
if (!thumb->isNull() && (result->thumb->isNull() || result->thumb->width() < thumb->width() || if (!thumb->isNull() && (result->thumb->isNull() || result->thumb->width() < thumb->width() ||
result->thumb->height() < thumb->height() || versionChanged)) { result->thumb->height() < thumb->height() || versionChanged)) {
result->thumb = thumb; result->thumb = thumb;

View File

@ -204,7 +204,7 @@ void SendFilesBox::prepareDocumentLayout() {
} }
} }
auto nameString = DocumentData::composeNameString(filename, songTitle, songPerformer); auto nameString = DocumentData::ComposeNameString(filename, songTitle, songPerformer);
_nameText.setText(st::semiboldTextStyle, nameString, _textNameOptions); _nameText.setText(st::semiboldTextStyle, nameString, _textNameOptions);
_statusText = formatSizeText(fileinfo.size()); _statusText = formatSizeText(fileinfo.size());
_statusWidth = std::max(_nameText.maxWidth(), st::normalFont->width(_statusText)); _statusWidth = std::max(_nameText.maxWidth(), st::normalFont->width(_statusText));
@ -535,11 +535,8 @@ EditCaptionBox::EditCaptionBox(QWidget *, HistoryMedia *media, FullMsgId msgId)
} }
if (doc) { if (doc) {
if (doc->voice()) { auto nameString = doc->voice() ? lang(lng_media_audio) : doc->composeNameString();
_name.setText(st::semiboldTextStyle, lang(lng_media_audio), _textNameOptions); _name.setText(st::semiboldTextStyle, nameString, _textNameOptions);
} else {
_name.setText(st::semiboldTextStyle, doc->composeNameString(), _textNameOptions);
}
_status = formatSizeText(doc->size); _status = formatSizeText(doc->size);
_statusw = std::max(_name.maxWidth(), st::normalFont->width(_status)); _statusw = std::max(_name.maxWidth(), st::normalFont->width(_status));
_isImage = doc->isImage(); _isImage = doc->isImage();

View File

@ -318,9 +318,9 @@ void finish() {
// FIPS_mode_set(0); // FIPS_mode_set(0);
ENGINE_cleanup(); ENGINE_cleanup();
CONF_modules_unload(1); CONF_modules_unload(1);
ERR_remove_state(0); ERR_remove_state(0); // TODO(Randl): deprecated in 1.0.0
ERR_free_strings(); ERR_free_strings();
ERR_remove_thread_state(nullptr); ERR_remove_thread_state(nullptr); // TODO(Randl): deprecated in 1.1.0
EVP_cleanup(); EVP_cleanup();
delete[] base::take(_sslLocks); delete[] base::take(_sslLocks);

View File

@ -1152,7 +1152,7 @@ void HistoryDocument::createComponents(bool caption) {
mask |= HistoryDocumentVoice::Bit(); mask |= HistoryDocumentVoice::Bit();
} else { } else {
mask |= HistoryDocumentNamed::Bit(); mask |= HistoryDocumentNamed::Bit();
if (!_data->song() && !documentIsExecutableName(_data->name) && !_data->thumb->isNull() && if (!_data->song() && !documentIsExecutableName(_data->filename()) && !_data->thumb->isNull() &&
_data->thumb->width() && _data->thumb->height()) { _data->thumb->width() && _data->thumb->height()) {
mask |= HistoryDocumentThumbed::Bit(); mask |= HistoryDocumentThumbed::Bit();
} }
@ -1171,8 +1171,8 @@ void HistoryDocument::createComponents(bool caption) {
} }
void HistoryDocument::fillNamedFromData(HistoryDocumentNamed *named) { void HistoryDocument::fillNamedFromData(HistoryDocumentNamed *named) {
auto name = named->_name = _data->composeNameString(); auto nameString = named->_name = _data->composeNameString();
named->_namew = st::semiboldFont->width(name); named->_namew = st::semiboldFont->width(nameString);
} }
void HistoryDocument::initDimensions() { void HistoryDocument::initDimensions() {

View File

@ -187,7 +187,8 @@ ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() {
} }
MTPVector<MTPDocumentAttribute> composeDocumentAttributes(DocumentData *document) { MTPVector<MTPDocumentAttribute> composeDocumentAttributes(DocumentData *document) {
QVector<MTPDocumentAttribute> attributes(1, MTP_documentAttributeFilename(MTP_string(document->name))); auto filenameAttribute = MTP_documentAttributeFilename(MTP_string(document->filename()));
auto attributes = QVector<MTPDocumentAttribute>(1, filenameAttribute);
if (document->dimensions.width() > 0 && document->dimensions.height() > 0) { if (document->dimensions.width() > 0 && document->dimensions.height() > 0) {
qint32 duration = document->duration(); qint32 duration = document->duration();
if (duration >= 0) { if (duration >= 0) {
@ -4736,9 +4737,10 @@ void HistoryWidget::onDocumentUploaded(const FullMsgId &newId, bool silent, cons
sendFlags |= MTPmessages_SendMedia::Flag::f_silent; sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
} }
auto caption = item->getMedia() ? item->getMedia()->getCaption() : TextWithEntities(); auto caption = item->getMedia() ? item->getMedia()->getCaption() : TextWithEntities();
auto media = MTP_inputMediaUploadedDocument(MTP_flags(0), file, MTPInputFile(), MTP_string(document->mime), auto media =
composeDocumentAttributes(document), MTP_string(caption.text), MTP_inputMediaUploadedDocument(MTP_flags(0), file, MTPInputFile(), MTP_string(document->mimeString()),
MTPVector<MTPInputDocument>(), MTP_int(0)); composeDocumentAttributes(document), MTP_string(caption.text),
MTPVector<MTPInputDocument>(), MTP_int(0));
hist->sendRequestId = hist->sendRequestId =
MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo), MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo),
media, MTP_long(randomId), MTPnullMarkup), media, MTP_long(randomId), MTPnullMarkup),
@ -4770,7 +4772,7 @@ void HistoryWidget::onThumbDocumentUploaded(const FullMsgId &newId, bool silent,
auto caption = media ? media->getCaption() : TextWithEntities(); auto caption = media ? media->getCaption() : TextWithEntities();
auto media = auto media =
MTP_inputMediaUploadedDocument(MTP_flags(MTPDinputMediaUploadedDocument::Flag::f_thumb), file, thumb, MTP_inputMediaUploadedDocument(MTP_flags(MTPDinputMediaUploadedDocument::Flag::f_thumb), file, thumb,
MTP_string(document->mime), composeDocumentAttributes(document), MTP_string(document->mimeString()), composeDocumentAttributes(document),
MTP_string(caption.text), MTPVector<MTPInputDocument>(), MTP_int(0)); MTP_string(caption.text), MTPVector<MTPInputDocument>(), MTP_int(0));
hist->sendRequestId = hist->sendRequestId =
MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo), MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo),
@ -6272,14 +6274,14 @@ void HistoryWidget::updatePreview() {
if (_previewData->title.isEmpty()) { if (_previewData->title.isEmpty()) {
if (_previewData->description.text.isEmpty()) { if (_previewData->description.text.isEmpty()) {
title = _previewData->author; title = _previewData->author;
desc = ((_previewData->document && !_previewData->document->name.isEmpty()) ? desc = ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
_previewData->document->name : _previewData->document->filename() :
_previewData->url); _previewData->url);
} else { } else {
title = _previewData->description.text; title = _previewData->description.text;
desc = _previewData->author.isEmpty() ? desc = _previewData->author.isEmpty() ?
((_previewData->document && !_previewData->document->name.isEmpty()) ? ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
_previewData->document->name : _previewData->document->filename() :
_previewData->url) : _previewData->url) :
_previewData->author; _previewData->author;
} }
@ -6287,8 +6289,8 @@ void HistoryWidget::updatePreview() {
title = _previewData->title; title = _previewData->title;
desc = _previewData->description.text.isEmpty() ? desc = _previewData->description.text.isEmpty() ?
(_previewData->author.isEmpty() ? (_previewData->author.isEmpty() ?
((_previewData->document && !_previewData->document->name.isEmpty()) ? ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
_previewData->document->name : _previewData->document->filename() :
_previewData->url) : _previewData->url) :
_previewData->author) : _previewData->author) :
_previewData->description.text; _previewData->description.text;
@ -6298,8 +6300,8 @@ void HistoryWidget::updatePreview() {
desc = _previewData->title.isEmpty() ? desc = _previewData->title.isEmpty() ?
(_previewData->description.text.isEmpty() ? (_previewData->description.text.isEmpty() ?
(_previewData->author.isEmpty() ? (_previewData->author.isEmpty() ?
((_previewData->document && !_previewData->document->name.isEmpty()) ? ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
_previewData->document->name : _previewData->document->filename() :
_previewData->url) : _previewData->url) :
_previewData->author) : _previewData->author) :
_previewData->description.text) : _previewData->description.text) :

View File

@ -161,13 +161,13 @@ QString formatPlayedText(qint64 played, qint64 duration) {
qint32 documentColorIndex(DocumentData *document, QString &ext) { qint32 documentColorIndex(DocumentData *document, QString &ext) {
qint32 colorIndex = 0; qint32 colorIndex = 0;
QString name = QString name = document ? (document->filename().isEmpty() ?
document ? (document->name.isEmpty() ? (document->sticker() ? lang(lng_in_dlg_sticker) : qsl("Unknown File")) : (document->sticker() ? lang(lng_in_dlg_sticker) : qsl("Unknown File")) :
document->name) : document->filename()) :
lang(lng_message_empty); lang(lng_message_empty);
name = name.toLower(); name = name.toLower();
qint32 lastDot = name.lastIndexOf('.'); qint32 lastDot = name.lastIndexOf('.');
QString mime = document ? document->mime.toLower() : QString(); QString mime = document ? document->mimeString().toLower() : QString();
if (name.endsWith(qstr(".doc")) || name.endsWith(qstr(".txt")) || name.endsWith(qstr(".psd")) || if (name.endsWith(qstr(".doc")) || name.endsWith(qstr(".txt")) || name.endsWith(qstr(".psd")) ||
mime.startsWith(qstr("text/"))) { mime.startsWith(qstr("text/"))) {
colorIndex = 0; colorIndex = 0;

View File

@ -324,9 +324,10 @@ void CoverWidget::handleSongChange() {
TextWithEntities textWithEntities; TextWithEntities textWithEntities;
if (song->performer.isEmpty()) { if (song->performer.isEmpty()) {
textWithEntities.text = song->title.isEmpty() ? textWithEntities.text =
(current.audio()->name.isEmpty() ? qsl("Unknown Track") : current.audio()->name) : song->title.isEmpty() ?
song->title; (current.audio()->filename().isEmpty() ? qsl("Unknown Track") : current.audio()->filename()) :
song->title;
} else { } else {
auto title = song->title.isEmpty() ? qsl("Unknown Track") : TextUtilities::Clean(song->title); auto title = song->title.isEmpty() ? qsl("Unknown Track") : TextUtilities::Clean(song->title);
textWithEntities.text = song->performer + QString::fromUtf8(" \xe2\x80\x93 ") + title; textWithEntities.text = song->performer + QString::fromUtf8(" \xe2\x80\x93 ") + title;

View File

@ -501,11 +501,12 @@ void Widget::handleSongChange() {
if (!song || song->performer.isEmpty()) { if (!song || song->performer.isEmpty()) {
textWithEntities.text = textWithEntities.text =
(!song || song->title.isEmpty()) ? (!song || song->title.isEmpty()) ?
(current.audio()->name.isEmpty() ? qsl("Unknown Track") : current.audio()->name) : (current.audio()->filename().isEmpty() ? qsl("Unknown Track") : current.audio()->filename()) :
song->title; song->title;
} else { } else {
auto title = song->title.isEmpty() ? qsl("Unknown Track") : TextUtilities::Clean(song->title); auto title = song->title.isEmpty() ? qsl("Unknown Track") : TextUtilities::Clean(song->title);
textWithEntities.text = song->performer + QString::fromUtf8(" \xe2\x80\x93 ") + title; auto dash = QString::fromUtf8(" \xe2\x80\x93 ");
textWithEntities.text = song->performer + dash + title;
textWithEntities.entities.append({EntityInTextBold, 0, song->performer.size(), QString()}); textWithEntities.entities.append({EntityInTextBold, 0, song->performer.size(), QString()});
} }
} }

View File

@ -838,7 +838,7 @@ void MediaView::onSaveAs() {
QFileInfo alreadyInfo(location.name()); QFileInfo alreadyInfo(location.name());
QDir alreadyDir(alreadyInfo.dir()); QDir alreadyDir(alreadyInfo.dir());
QString name = alreadyInfo.fileName(), filter; QString name = alreadyInfo.fileName(), filter;
MimeType mimeType = mimeTypeForName(_doc->mime); MimeType mimeType = mimeTypeForName(_doc->mimeString());
QStringList p = mimeType.globPatterns(); QStringList p = mimeType.globPatterns();
QString pattern = p.isEmpty() ? QString() : p.front(); QString pattern = p.isEmpty() ? QString() : p.front();
if (name.isEmpty()) { if (name.isEmpty()) {
@ -975,7 +975,7 @@ void MediaView::onDownload() {
const FileLocation &location(_doc->location(true)); const FileLocation &location(_doc->location(true));
if (location.accessEnable()) { if (location.accessEnable()) {
if (!QDir().exists(path)) QDir().mkpath(path); if (!QDir().exists(path)) QDir().mkpath(path);
toName = filedialogNextFilename(_doc->name, location.name(), path); toName = filedialogNextFilename(_doc->filename(), location.name(), path);
if (!toName.isEmpty() && toName != location.name()) { if (!toName.isEmpty() && toName != location.name()) {
QFile(toName).remove(); QFile(toName).remove();
if (!QFile(location.name()).copy(toName)) { if (!QFile(location.name()).copy(toName)) {
@ -1405,7 +1405,7 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty
lang(lng_in_dlg_sticker) : lang(lng_in_dlg_sticker) :
(_doc->type == AnimatedDocument ? (_doc->type == AnimatedDocument ?
qsl("GIF") : qsl("GIF") :
(_doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name)); (_doc->filename().isEmpty() ? lang(lng_mediaview_doc_image) : _doc->filename()));
} else { } else {
_docName = lang(lng_message_empty); _docName = lang(lng_message_empty);
} }
@ -3087,14 +3087,14 @@ void MediaView::updateHeader() {
if (index >= 0 && index < count && count > 1) { if (index >= 0 && index < count && count > 1) {
if (_doc) { if (_doc) {
_headerText = lng_mediaview_file_n_of_count( _headerText = lng_mediaview_file_n_of_count(
lt_file, _doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name, lt_n, lt_file, _doc->filename().isEmpty() ? lang(lng_mediaview_doc_image) : _doc->filename(), lt_n,
QString::number(index + 1), lt_count, QString::number(count)); QString::number(index + 1), lt_count, QString::number(count));
} else { } else {
_headerText = lng_mediaview_n_of_count(lt_n, QString::number(index + 1), lt_count, QString::number(count)); _headerText = lng_mediaview_n_of_count(lt_n, QString::number(index + 1), lt_count, QString::number(count));
} }
} else { } else {
if (_doc) { if (_doc) {
_headerText = _doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name; _headerText = _doc->filename().isEmpty() ? lang(lng_mediaview_doc_image) : _doc->filename();
} else if (_user) { } else if (_user) {
_headerText = lang(lng_mediaview_profile_photo); _headerText = lang(lng_mediaview_profile_photo);
} else if ((_channel && !_history->isMegagroup()) || (_peer && _peer->isChannel() && !_peer->isMegagroup())) { } else if ((_channel && !_history->isMegagroup()) || (_peer && _peer->isChannel() && !_peer->isMegagroup())) {

View File

@ -51,7 +51,7 @@ TextWithEntities ComposeNameWithEntities(DocumentData *document) {
TextWithEntities result; TextWithEntities result;
auto song = document->song(); auto song = document->song();
if (!song || (song->title.isEmpty() && song->performer.isEmpty())) { if (!song || (song->title.isEmpty() && song->performer.isEmpty())) {
result.text = document->name.isEmpty() ? qsl("Unknown File") : document->name; result.text = document->filename().isEmpty() ? qsl("Unknown File") : document->filename();
result.entities.push_back({EntityInTextBold, 0, result.text.size()}); result.entities.push_back({EntityInTextBold, 0, result.text.size()});
} else if (song->performer.isEmpty()) { } else if (song->performer.isEmpty()) {
result.text = song->title; result.text = song->title;

View File

@ -320,7 +320,7 @@ private:
bool withThumb() const { bool withThumb() const {
return !_data->song() && !_data->thumb->isNull() && _data->thumb->width() && _data->thumb->height() && return !_data->song() && !_data->thumb->isNull() && _data->thumb->width() && _data->thumb->height() &&
!documentIsExecutableName(_data->name); !documentIsExecutableName(_data->filename());
} }
bool updateStatusText(); bool updateStatusText();
}; };

View File

@ -39,7 +39,7 @@ namespace Serialize {
void Document::writeToStream(QDataStream &stream, DocumentData *document) { void Document::writeToStream(QDataStream &stream, DocumentData *document) {
stream << quint64(document->id) << quint64(document->_access) << qint32(document->date); stream << quint64(document->id) << quint64(document->_access) << qint32(document->date);
stream << qint32(document->_version); stream << qint32(document->_version);
stream << document->name << document->mime << qint32(document->_dc) << qint32(document->size); stream << document->filename() << document->mimeString() << qint32(document->_dc) << qint32(document->size);
stream << qint32(document->dimensions.width()) << qint32(document->dimensions.height()); stream << qint32(document->dimensions.width()) << qint32(document->dimensions.height());
stream << qint32(document->type); stream << qint32(document->type);
if (auto sticker = document->sticker()) { if (auto sticker = document->sticker()) {
@ -157,7 +157,7 @@ int Document::sizeInStream(DocumentData *document) {
// id + access + date + version // id + access + date + version
result += sizeof(quint64) + sizeof(quint64) + sizeof(qint32) + sizeof(qint32); result += sizeof(quint64) + sizeof(quint64) + sizeof(qint32) + sizeof(qint32);
// + namelen + name + mimelen + mime + dc + size // + namelen + name + mimelen + mime + dc + size
result += stringSize(document->name) + stringSize(document->mime) + sizeof(qint32) + sizeof(qint32); result += stringSize(document->filename()) + stringSize(document->mimeString()) + sizeof(qint32) + sizeof(qint32);
// + width + height // + width + height
result += sizeof(qint32) + sizeof(qint32); result += sizeof(qint32) + sizeof(qint32);
// + type // + type

View File

@ -1404,18 +1404,18 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
} }
QString name, filter, caption, prefix; QString name, filter, caption, prefix;
MimeType mimeType = mimeTypeForName(data->mime); MimeType mimeType = mimeTypeForName(data->mimeString());
QStringList p = mimeType.globPatterns(); QStringList p = mimeType.globPatterns();
QString pattern = p.isEmpty() ? QString() : p.front(); QString pattern = p.isEmpty() ? QString() : p.front();
if (data->voice()) { if (data->voice()) {
bool mp3 = (data->mime == qstr("audio/mp3")); bool mp3 = data->hasMimeType(qstr("audio/mp3"));
name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : already; name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : already;
filter = mp3 ? qsl("MP3 Audio (*.mp3);;") : qsl("OGG Opus Audio (*.ogg);;"); filter = mp3 ? qsl("MP3 Audio (*.mp3);;") : qsl("OGG Opus Audio (*.ogg);;");
filter += FileDialog::AllFilesFilter(); filter += FileDialog::AllFilesFilter();
caption = lang(lng_save_audio); caption = lang(lng_save_audio);
prefix = qsl("audio"); prefix = qsl("audio");
} else if (data->isVideo()) { } else if (data->isVideo()) {
name = already.isEmpty() ? data->name : already; name = already.isEmpty() ? data->filename() : already;
if (name.isEmpty()) { if (name.isEmpty()) {
name = pattern.isEmpty() ? qsl(".mov") : pattern.replace('*', QString()); name = pattern.isEmpty() ? qsl(".mov") : pattern.replace('*', QString());
} }
@ -1427,7 +1427,7 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
caption = lang(lng_save_video); caption = lang(lng_save_video);
prefix = qsl("video"); prefix = qsl("video");
} else { } else {
name = already.isEmpty() ? data->name : already; name = already.isEmpty() ? data->filename() : already;
if (name.isEmpty()) { if (name.isEmpty()) {
name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString()); name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString());
} }
@ -1696,7 +1696,15 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
song()->performer = qs(d.vperformer); song()->performer = qs(d.vperformer);
} }
} break; } break;
case mtpc_documentAttributeFilename: name = qs(attributes[i].c_documentAttributeFilename().vfile_name); break; case mtpc_documentAttributeFilename: {
auto &attribute = attributes[i];
auto remoteFileName = qs(attribute.c_documentAttributeFilename().vfile_name);
// We don't want RTL Override characters in filenames, because they introduce a security issue, when a
// filename "Fil[RTLO]gepj.exe" looks like "Filexe.jpeg" being ".exe"
auto rtlOverride = QChar(0x202E);
_filename = std::move(remoteFileName).replace(rtlOverride, "");
} break;
} }
} }
if (type == StickerDocument) { if (type == StickerDocument) {
@ -2122,7 +2130,7 @@ void DocumentData::recountIsImage() {
if (isAnimation() || isVideo()) { if (isAnimation() || isVideo()) {
return; return;
} }
_duration = fileIsImage(name, mime) ? 1 : -1; // hack _duration = fileIsImage(filename(), mimeString()) ? 1 : -1; // hack
} }
bool DocumentData::setRemoteVersion(qint32 version) { bool DocumentData::setRemoteVersion(qint32 version) {
@ -2182,7 +2190,7 @@ DocumentData::~DocumentData() {
} }
} }
QString DocumentData::composeNameString(const QString &filename, const QString &songTitle, QString DocumentData::ComposeNameString(const QString &filename, const QString &songTitle,
const QString &songPerformer) { const QString &songPerformer) {
if (songTitle.isEmpty() && songPerformer.isEmpty()) { if (songTitle.isEmpty() && songPerformer.isEmpty()) {
return filename.isEmpty() ? qsl("Unknown File") : filename; return filename.isEmpty() ? qsl("Unknown File") : filename;

View File

@ -1320,17 +1320,17 @@ public:
return (type == RoundVideoDocument); return (type == RoundVideoDocument);
} }
bool isAnimation() const { bool isAnimation() const {
return (type == AnimatedDocument) || isRoundVideo() || !mime.compare(qstr("image/gif"), Qt::CaseInsensitive); return (type == AnimatedDocument) || isRoundVideo() || hasMimeType(qstr("image/gif"));
} }
bool isGifv() const { bool isGifv() const {
return (type == AnimatedDocument) && !mime.compare(qstr("video/mp4"), Qt::CaseInsensitive); return (type == AnimatedDocument) && hasMimeType(qstr("video/mp4"));
} }
bool isTheme() const { bool isTheme() const {
return name.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive) || return _filename.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive) ||
name.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive); _filename.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive);
} }
bool tryPlaySong() const { bool tryPlaySong() const {
return (song() != nullptr) || mime.startsWith(qstr("audio/"), Qt::CaseInsensitive); return (song() != nullptr) || _mimeString.startsWith(qstr("audio/"), Qt::CaseInsensitive);
} }
bool isMusic() const { bool isMusic() const {
if (auto s = song()) { if (auto s = song()) {
@ -1374,14 +1374,26 @@ public:
// to (this) received from the server "same" document. // to (this) received from the server "same" document.
void collectLocalData(DocumentData *local); void collectLocalData(DocumentData *local);
QString filename() const {
return _filename;
}
QString mimeString() const {
return _mimeString;
}
bool hasMimeType(QLatin1String mime) const {
return !_mimeString.compare(mime, Qt::CaseInsensitive);
}
void setMimeString(const QString &mime) {
_mimeString = mime;
}
~DocumentData(); ~DocumentData();
DocumentId id = 0; DocumentId id = 0;
DocumentType type = FileDocument; DocumentType type = FileDocument;
QSize dimensions; QSize dimensions;
qint32 date = 0; qint32 date = 0;
QString name;
QString mime;
ImagePtr thumb, replyPreview; ImagePtr thumb, replyPreview;
qint32 size = 0; qint32 size = 0;
@ -1394,12 +1406,12 @@ public:
return ::mediaKey(locationType(), _dc, id, _version); return ::mediaKey(locationType(), _dc, id, _version);
} }
static QString composeNameString(const QString &filename, const QString &songTitle, const QString &songPerformer); static QString ComposeNameString(const QString &filename, const QString &songTitle, const QString &songPerformer);
QString composeNameString() const { QString composeNameString() const {
if (auto songData = song()) { if (auto songData = song()) {
return composeNameString(name, songData->title, songData->performer); return ComposeNameString(_filename, songData->title, songData->performer);
} }
return composeNameString(name, QString(), QString()); return ComposeNameString(_filename, QString(), QString());
} }
private: private:
@ -1417,6 +1429,9 @@ private:
quint64 _access = 0; quint64 _access = 0;
qint32 _version = 0; qint32 _version = 0;
QString _url; QString _url;
QString _filename;
QString _mimeString;
FileLocation _location; FileLocation _location;
QByteArray _data; QByteArray _data;