mirror of https://github.com/procxx/kepka.git
				
				
				
			Filter RTL in displayed file names(#156)
Adopted from upstream commit aec496d520 to avoid the phishing filenames.
Closes #103.
			
			
This commit is contained in:
		
							parent
							
								
									0d013603bd
								
							
						
					
					
						commit
						9f1896c680
					
				| 
						 | 
				
			
			@ -1709,7 +1709,7 @@ DocumentData *documentSet(const DocumentId &document, DocumentData *convert, con
 | 
			
		|||
			versionChanged = convert->setRemoteVersion(version);
 | 
			
		||||
			convert->setRemoteLocation(dc, access);
 | 
			
		||||
			convert->date = date;
 | 
			
		||||
			convert->mime = mime;
 | 
			
		||||
			convert->setMimeString(mime);
 | 
			
		||||
			if (!thumb->isNull() && (convert->thumb->isNull() || convert->thumb->width() < thumb->width() ||
 | 
			
		||||
			                         convert->thumb->height() < thumb->height() || versionChanged)) {
 | 
			
		||||
				updateImage(convert->thumb, thumb);
 | 
			
		||||
| 
						 | 
				
			
			@ -1742,7 +1742,7 @@ DocumentData *documentSet(const DocumentId &document, DocumentData *convert, con
 | 
			
		|||
		} else {
 | 
			
		||||
			result = DocumentData::create(document, dc, access, version, attributes);
 | 
			
		||||
			result->date = date;
 | 
			
		||||
			result->mime = mime;
 | 
			
		||||
			result->setMimeString(mime);
 | 
			
		||||
			result->thumb = thumb;
 | 
			
		||||
			result->size = size;
 | 
			
		||||
			result->recountIsImage();
 | 
			
		||||
| 
						 | 
				
			
			@ -1760,7 +1760,7 @@ DocumentData *documentSet(const DocumentId &document, DocumentData *convert, con
 | 
			
		|||
				result->setRemoteLocation(dc, access);
 | 
			
		||||
			}
 | 
			
		||||
			result->date = date;
 | 
			
		||||
			result->mime = mime;
 | 
			
		||||
			result->setMimeString(mime);
 | 
			
		||||
			if (!thumb->isNull() && (result->thumb->isNull() || result->thumb->width() < thumb->width() ||
 | 
			
		||||
			                         result->thumb->height() < thumb->height() || versionChanged)) {
 | 
			
		||||
				result->thumb = thumb;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
		_statusText = formatSizeText(fileinfo.size());
 | 
			
		||||
		_statusWidth = std::max(_nameText.maxWidth(), st::normalFont->width(_statusText));
 | 
			
		||||
| 
						 | 
				
			
			@ -535,11 +535,8 @@ EditCaptionBox::EditCaptionBox(QWidget *, HistoryMedia *media, FullMsgId msgId)
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		if (doc) {
 | 
			
		||||
			if (doc->voice()) {
 | 
			
		||||
				_name.setText(st::semiboldTextStyle, lang(lng_media_audio), _textNameOptions);
 | 
			
		||||
			} else {
 | 
			
		||||
				_name.setText(st::semiboldTextStyle, doc->composeNameString(), _textNameOptions);
 | 
			
		||||
			}
 | 
			
		||||
			auto nameString = doc->voice() ? lang(lng_media_audio) : doc->composeNameString();
 | 
			
		||||
			_name.setText(st::semiboldTextStyle, nameString, _textNameOptions);
 | 
			
		||||
			_status = formatSizeText(doc->size);
 | 
			
		||||
			_statusw = std::max(_name.maxWidth(), st::normalFont->width(_status));
 | 
			
		||||
			_isImage = doc->isImage();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -318,9 +318,9 @@ void finish() {
 | 
			
		|||
	// FIPS_mode_set(0);
 | 
			
		||||
	ENGINE_cleanup();
 | 
			
		||||
	CONF_modules_unload(1);
 | 
			
		||||
	ERR_remove_state(0);
 | 
			
		||||
	ERR_remove_state(0); // TODO(Randl): deprecated in 1.0.0
 | 
			
		||||
	ERR_free_strings();
 | 
			
		||||
	ERR_remove_thread_state(nullptr);
 | 
			
		||||
	ERR_remove_thread_state(nullptr); // TODO(Randl): deprecated in 1.1.0
 | 
			
		||||
	EVP_cleanup();
 | 
			
		||||
 | 
			
		||||
	delete[] base::take(_sslLocks);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1152,7 +1152,7 @@ void HistoryDocument::createComponents(bool caption) {
 | 
			
		|||
		mask |= HistoryDocumentVoice::Bit();
 | 
			
		||||
	} else {
 | 
			
		||||
		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()) {
 | 
			
		||||
			mask |= HistoryDocumentThumbed::Bit();
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -1171,8 +1171,8 @@ void HistoryDocument::createComponents(bool caption) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void HistoryDocument::fillNamedFromData(HistoryDocumentNamed *named) {
 | 
			
		||||
	auto name = named->_name = _data->composeNameString();
 | 
			
		||||
	named->_namew = st::semiboldFont->width(name);
 | 
			
		||||
	auto nameString = named->_name = _data->composeNameString();
 | 
			
		||||
	named->_namew = st::semiboldFont->width(nameString);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HistoryDocument::initDimensions() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -187,7 +187,8 @@ ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
		qint32 duration = document->duration();
 | 
			
		||||
		if (duration >= 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -4736,9 +4737,10 @@ void HistoryWidget::onDocumentUploaded(const FullMsgId &newId, bool silent, cons
 | 
			
		|||
				sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
 | 
			
		||||
			}
 | 
			
		||||
			auto caption = item->getMedia() ? item->getMedia()->getCaption() : TextWithEntities();
 | 
			
		||||
			auto media = MTP_inputMediaUploadedDocument(MTP_flags(0), file, MTPInputFile(), MTP_string(document->mime),
 | 
			
		||||
			                                            composeDocumentAttributes(document), MTP_string(caption.text),
 | 
			
		||||
			                                            MTPVector<MTPInputDocument>(), MTP_int(0));
 | 
			
		||||
			auto media =
 | 
			
		||||
			    MTP_inputMediaUploadedDocument(MTP_flags(0), file, MTPInputFile(), MTP_string(document->mimeString()),
 | 
			
		||||
			                                   composeDocumentAttributes(document), MTP_string(caption.text),
 | 
			
		||||
			                                   MTPVector<MTPInputDocument>(), MTP_int(0));
 | 
			
		||||
			hist->sendRequestId =
 | 
			
		||||
			    MTP::send(MTPmessages_SendMedia(MTP_flags(sendFlags), item->history()->peer->input, MTP_int(replyTo),
 | 
			
		||||
			                                    media, MTP_long(randomId), MTPnullMarkup),
 | 
			
		||||
| 
						 | 
				
			
			@ -4770,7 +4772,7 @@ void HistoryWidget::onThumbDocumentUploaded(const FullMsgId &newId, bool silent,
 | 
			
		|||
			auto caption = media ? media->getCaption() : TextWithEntities();
 | 
			
		||||
			auto media =
 | 
			
		||||
			    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));
 | 
			
		||||
			hist->sendRequestId =
 | 
			
		||||
			    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->description.text.isEmpty()) {
 | 
			
		||||
						title = _previewData->author;
 | 
			
		||||
						desc = ((_previewData->document && !_previewData->document->name.isEmpty()) ?
 | 
			
		||||
						            _previewData->document->name :
 | 
			
		||||
						desc = ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
 | 
			
		||||
						            _previewData->document->filename() :
 | 
			
		||||
						            _previewData->url);
 | 
			
		||||
					} else {
 | 
			
		||||
						title = _previewData->description.text;
 | 
			
		||||
						desc = _previewData->author.isEmpty() ?
 | 
			
		||||
						           ((_previewData->document && !_previewData->document->name.isEmpty()) ?
 | 
			
		||||
						                _previewData->document->name :
 | 
			
		||||
						           ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
 | 
			
		||||
						                _previewData->document->filename() :
 | 
			
		||||
						                _previewData->url) :
 | 
			
		||||
						           _previewData->author;
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			@ -6287,8 +6289,8 @@ void HistoryWidget::updatePreview() {
 | 
			
		|||
					title = _previewData->title;
 | 
			
		||||
					desc = _previewData->description.text.isEmpty() ?
 | 
			
		||||
					           (_previewData->author.isEmpty() ?
 | 
			
		||||
					                ((_previewData->document && !_previewData->document->name.isEmpty()) ?
 | 
			
		||||
					                     _previewData->document->name :
 | 
			
		||||
					                ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
 | 
			
		||||
					                     _previewData->document->filename() :
 | 
			
		||||
					                     _previewData->url) :
 | 
			
		||||
					                _previewData->author) :
 | 
			
		||||
					           _previewData->description.text;
 | 
			
		||||
| 
						 | 
				
			
			@ -6298,8 +6300,8 @@ void HistoryWidget::updatePreview() {
 | 
			
		|||
				desc = _previewData->title.isEmpty() ?
 | 
			
		||||
				           (_previewData->description.text.isEmpty() ?
 | 
			
		||||
				                (_previewData->author.isEmpty() ?
 | 
			
		||||
				                     ((_previewData->document && !_previewData->document->name.isEmpty()) ?
 | 
			
		||||
				                          _previewData->document->name :
 | 
			
		||||
				                     ((_previewData->document && !_previewData->document->filename().isEmpty()) ?
 | 
			
		||||
				                          _previewData->document->filename() :
 | 
			
		||||
				                          _previewData->url) :
 | 
			
		||||
				                     _previewData->author) :
 | 
			
		||||
				                _previewData->description.text) :
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -161,13 +161,13 @@ QString formatPlayedText(qint64 played, qint64 duration) {
 | 
			
		|||
qint32 documentColorIndex(DocumentData *document, QString &ext) {
 | 
			
		||||
	qint32 colorIndex = 0;
 | 
			
		||||
 | 
			
		||||
	QString name =
 | 
			
		||||
	    document ? (document->name.isEmpty() ? (document->sticker() ? lang(lng_in_dlg_sticker) : qsl("Unknown File")) :
 | 
			
		||||
	                                           document->name) :
 | 
			
		||||
	               lang(lng_message_empty);
 | 
			
		||||
	QString name = document ? (document->filename().isEmpty() ?
 | 
			
		||||
	                               (document->sticker() ? lang(lng_in_dlg_sticker) : qsl("Unknown File")) :
 | 
			
		||||
	                               document->filename()) :
 | 
			
		||||
	                          lang(lng_message_empty);
 | 
			
		||||
	name = name.toLower();
 | 
			
		||||
	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")) ||
 | 
			
		||||
	    mime.startsWith(qstr("text/"))) {
 | 
			
		||||
		colorIndex = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -324,9 +324,10 @@ void CoverWidget::handleSongChange() {
 | 
			
		|||
 | 
			
		||||
	TextWithEntities textWithEntities;
 | 
			
		||||
	if (song->performer.isEmpty()) {
 | 
			
		||||
		textWithEntities.text = song->title.isEmpty() ?
 | 
			
		||||
		                            (current.audio()->name.isEmpty() ? qsl("Unknown Track") : current.audio()->name) :
 | 
			
		||||
		                            song->title;
 | 
			
		||||
		textWithEntities.text =
 | 
			
		||||
		    song->title.isEmpty() ?
 | 
			
		||||
		        (current.audio()->filename().isEmpty() ? qsl("Unknown Track") : current.audio()->filename()) :
 | 
			
		||||
		        song->title;
 | 
			
		||||
	} else {
 | 
			
		||||
		auto title = song->title.isEmpty() ? qsl("Unknown Track") : TextUtilities::Clean(song->title);
 | 
			
		||||
		textWithEntities.text = song->performer + QString::fromUtf8(" \xe2\x80\x93 ") + title;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -501,11 +501,12 @@ void Widget::handleSongChange() {
 | 
			
		|||
		if (!song || song->performer.isEmpty()) {
 | 
			
		||||
			textWithEntities.text =
 | 
			
		||||
			    (!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;
 | 
			
		||||
		} else {
 | 
			
		||||
			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()});
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -838,7 +838,7 @@ void MediaView::onSaveAs() {
 | 
			
		|||
			QFileInfo alreadyInfo(location.name());
 | 
			
		||||
			QDir alreadyDir(alreadyInfo.dir());
 | 
			
		||||
			QString name = alreadyInfo.fileName(), filter;
 | 
			
		||||
			MimeType mimeType = mimeTypeForName(_doc->mime);
 | 
			
		||||
			MimeType mimeType = mimeTypeForName(_doc->mimeString());
 | 
			
		||||
			QStringList p = mimeType.globPatterns();
 | 
			
		||||
			QString pattern = p.isEmpty() ? QString() : p.front();
 | 
			
		||||
			if (name.isEmpty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -975,7 +975,7 @@ void MediaView::onDownload() {
 | 
			
		|||
		const FileLocation &location(_doc->location(true));
 | 
			
		||||
		if (location.accessEnable()) {
 | 
			
		||||
			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()) {
 | 
			
		||||
				QFile(toName).remove();
 | 
			
		||||
				if (!QFile(location.name()).copy(toName)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1405,7 +1405,7 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty
 | 
			
		|||
			               lang(lng_in_dlg_sticker) :
 | 
			
		||||
			               (_doc->type == AnimatedDocument ?
 | 
			
		||||
			                    qsl("GIF") :
 | 
			
		||||
			                    (_doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name));
 | 
			
		||||
			                    (_doc->filename().isEmpty() ? lang(lng_mediaview_doc_image) : _doc->filename()));
 | 
			
		||||
		} else {
 | 
			
		||||
			_docName = lang(lng_message_empty);
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -3087,14 +3087,14 @@ void MediaView::updateHeader() {
 | 
			
		|||
	if (index >= 0 && index < count && count > 1) {
 | 
			
		||||
		if (_doc) {
 | 
			
		||||
			_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));
 | 
			
		||||
		} else {
 | 
			
		||||
			_headerText = lng_mediaview_n_of_count(lt_n, QString::number(index + 1), lt_count, QString::number(count));
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		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) {
 | 
			
		||||
			_headerText = lang(lng_mediaview_profile_photo);
 | 
			
		||||
		} else if ((_channel && !_history->isMegagroup()) || (_peer && _peer->isChannel() && !_peer->isMegagroup())) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,7 +51,7 @@ TextWithEntities ComposeNameWithEntities(DocumentData *document) {
 | 
			
		|||
	TextWithEntities result;
 | 
			
		||||
	auto song = document->song();
 | 
			
		||||
	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()});
 | 
			
		||||
	} else if (song->performer.isEmpty()) {
 | 
			
		||||
		result.text = song->title;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -320,7 +320,7 @@ private:
 | 
			
		|||
 | 
			
		||||
	bool withThumb() const {
 | 
			
		||||
		return !_data->song() && !_data->thumb->isNull() && _data->thumb->width() && _data->thumb->height() &&
 | 
			
		||||
		       !documentIsExecutableName(_data->name);
 | 
			
		||||
		       !documentIsExecutableName(_data->filename());
 | 
			
		||||
	}
 | 
			
		||||
	bool updateStatusText();
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,7 +39,7 @@ namespace Serialize {
 | 
			
		|||
void Document::writeToStream(QDataStream &stream, DocumentData *document) {
 | 
			
		||||
	stream << quint64(document->id) << quint64(document->_access) << qint32(document->date);
 | 
			
		||||
	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->type);
 | 
			
		||||
	if (auto sticker = document->sticker()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -157,7 +157,7 @@ int Document::sizeInStream(DocumentData *document) {
 | 
			
		|||
	// id + access + date + version
 | 
			
		||||
	result += sizeof(quint64) + sizeof(quint64) + sizeof(qint32) + sizeof(qint32);
 | 
			
		||||
	// + 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
 | 
			
		||||
	result += sizeof(qint32) + sizeof(qint32);
 | 
			
		||||
	// + type
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1404,18 +1404,18 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	QString name, filter, caption, prefix;
 | 
			
		||||
	MimeType mimeType = mimeTypeForName(data->mime);
 | 
			
		||||
	MimeType mimeType = mimeTypeForName(data->mimeString());
 | 
			
		||||
	QStringList p = mimeType.globPatterns();
 | 
			
		||||
	QString pattern = p.isEmpty() ? QString() : p.front();
 | 
			
		||||
	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;
 | 
			
		||||
		filter = mp3 ? qsl("MP3 Audio (*.mp3);;") : qsl("OGG Opus Audio (*.ogg);;");
 | 
			
		||||
		filter += FileDialog::AllFilesFilter();
 | 
			
		||||
		caption = lang(lng_save_audio);
 | 
			
		||||
		prefix = qsl("audio");
 | 
			
		||||
	} else if (data->isVideo()) {
 | 
			
		||||
		name = already.isEmpty() ? data->name : already;
 | 
			
		||||
		name = already.isEmpty() ? data->filename() : already;
 | 
			
		||||
		if (name.isEmpty()) {
 | 
			
		||||
			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);
 | 
			
		||||
		prefix = qsl("video");
 | 
			
		||||
	} else {
 | 
			
		||||
		name = already.isEmpty() ? data->name : already;
 | 
			
		||||
		name = already.isEmpty() ? data->filename() : already;
 | 
			
		||||
		if (name.isEmpty()) {
 | 
			
		||||
			name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString());
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -1696,7 +1696,15 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
 | 
			
		|||
				song()->performer = qs(d.vperformer);
 | 
			
		||||
			}
 | 
			
		||||
		} 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) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2122,7 +2130,7 @@ void DocumentData::recountIsImage() {
 | 
			
		|||
	if (isAnimation() || isVideo()) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	_duration = fileIsImage(name, mime) ? 1 : -1; // hack
 | 
			
		||||
	_duration = fileIsImage(filename(), mimeString()) ? 1 : -1; // hack
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
	if (songTitle.isEmpty() && songPerformer.isEmpty()) {
 | 
			
		||||
		return filename.isEmpty() ? qsl("Unknown File") : filename;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1320,17 +1320,17 @@ public:
 | 
			
		|||
		return (type == RoundVideoDocument);
 | 
			
		||||
	}
 | 
			
		||||
	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 {
 | 
			
		||||
		return (type == AnimatedDocument) && !mime.compare(qstr("video/mp4"), Qt::CaseInsensitive);
 | 
			
		||||
		return (type == AnimatedDocument) && hasMimeType(qstr("video/mp4"));
 | 
			
		||||
	}
 | 
			
		||||
	bool isTheme() const {
 | 
			
		||||
		return name.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive) ||
 | 
			
		||||
		       name.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive);
 | 
			
		||||
		return _filename.endsWith(qstr(".tdesktop-theme"), Qt::CaseInsensitive) ||
 | 
			
		||||
		       _filename.endsWith(qstr(".tdesktop-palette"), Qt::CaseInsensitive);
 | 
			
		||||
	}
 | 
			
		||||
	bool tryPlaySong() const {
 | 
			
		||||
		return (song() != nullptr) || mime.startsWith(qstr("audio/"), Qt::CaseInsensitive);
 | 
			
		||||
		return (song() != nullptr) || _mimeString.startsWith(qstr("audio/"), Qt::CaseInsensitive);
 | 
			
		||||
	}
 | 
			
		||||
	bool isMusic() const {
 | 
			
		||||
		if (auto s = song()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1374,14 +1374,26 @@ public:
 | 
			
		|||
	// to (this) received from the server "same" document.
 | 
			
		||||
	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();
 | 
			
		||||
 | 
			
		||||
	DocumentId id = 0;
 | 
			
		||||
	DocumentType type = FileDocument;
 | 
			
		||||
	QSize dimensions;
 | 
			
		||||
	qint32 date = 0;
 | 
			
		||||
	QString name;
 | 
			
		||||
	QString mime;
 | 
			
		||||
	ImagePtr thumb, replyPreview;
 | 
			
		||||
	qint32 size = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1394,12 +1406,12 @@ public:
 | 
			
		|||
		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 {
 | 
			
		||||
		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:
 | 
			
		||||
| 
						 | 
				
			
			@ -1417,6 +1429,9 @@ private:
 | 
			
		|||
	quint64 _access = 0;
 | 
			
		||||
	qint32 _version = 0;
 | 
			
		||||
	QString _url;
 | 
			
		||||
	QString _filename;
 | 
			
		||||
	QString _mimeString;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	FileLocation _location;
 | 
			
		||||
	QByteArray _data;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue