mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-20 23:27:23 +00:00
Added confirming only images and videos when edit album item.
- Added hiding of checkbox when edit album item.
This commit is contained in:
parent
25e3674819
commit
89e1291d86
@ -46,6 +46,7 @@ EditCaptionBox::EditCaptionBox(
|
||||
Expects(item->media() != nullptr);
|
||||
Expects(item->media()->allowsEditCaption());
|
||||
_isAllowedEditMedia = item->media()->allowsEditMedia();
|
||||
_isNotAlbum = !item->groupId();
|
||||
|
||||
QSize dimensions;
|
||||
auto image = (Image*)nullptr;
|
||||
@ -350,6 +351,15 @@ void EditCaptionBox::createEditMediaButton() {
|
||||
|
||||
const auto fileinfo = QFileInfo(_newMediaPath);
|
||||
const auto filename = fileinfo.fileName();
|
||||
|
||||
if (!_isNotAlbum) {
|
||||
// This check only for users, who chose not valid file with absolute path.
|
||||
if (!fileIsValidForAlbum(filename, Core::MimeTypeForFile(fileinfo).name())) {
|
||||
_newMediaPath = QString();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_isImage = fileIsImage(filename, Core::MimeTypeForFile(fileinfo).name());
|
||||
_isAudio = false;
|
||||
_animated = false;
|
||||
@ -360,7 +370,7 @@ void EditCaptionBox::createEditMediaButton() {
|
||||
_gifw = _gifh = _gifx = 0;
|
||||
|
||||
auto isGif = false;
|
||||
_wayWrap->toggle(_isImage, anim::type::instant);
|
||||
_wayWrap->toggle(_isImage && _isNotAlbum, anim::type::instant);
|
||||
|
||||
using Info = FileMediaInformation;
|
||||
if (const auto image = base::get_if<Info::Image>(fileMedia)
|
||||
@ -404,7 +414,9 @@ void EditCaptionBox::createEditMediaButton() {
|
||||
};
|
||||
|
||||
addButton(langFactory(lng_edit_media), [=] {
|
||||
const auto filters = QStringList(FileDialog::AllFilesFilter());
|
||||
const auto filters = _isNotAlbum
|
||||
? QStringList(FileDialog::AllFilesFilter())
|
||||
: QStringList(qsl("Image and Video Files (*.png *.jpg *.mp4)"));
|
||||
FileDialog::GetOpenPath(
|
||||
this,
|
||||
lang(lng_choose_file),
|
||||
|
@ -107,6 +107,7 @@ private:
|
||||
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
||||
QString _newMediaPath;
|
||||
bool _isAllowedEditMedia = false;
|
||||
bool _isNotAlbum;
|
||||
|
||||
QString _error;
|
||||
|
||||
|
@ -122,6 +122,22 @@ bool fileIsImage(const QString &name, const QString &mime) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool fileIsValidForAlbum(const QString &name, const QString &mime) {
|
||||
QString lowermime = mime.toLower(), namelower = name.toLower();
|
||||
if (lowermime.startsWith(qstr("video/mp4"))
|
||||
|| lowermime.startsWith(qstr("image/jpeg"))
|
||||
|| lowermime.startsWith(qstr("image/jpg"))
|
||||
|| lowermime.startsWith(qstr("image/png"))) {
|
||||
return true;
|
||||
} else if (namelower.endsWith(qstr(".mp4"))
|
||||
|| namelower.endsWith(qstr(".jpg"))
|
||||
|| namelower.endsWith(qstr(".jpeg"))
|
||||
|| namelower.endsWith(qstr(".png"))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString FileNameUnsafe(
|
||||
const QString &title,
|
||||
const QString &filter,
|
||||
|
@ -72,6 +72,7 @@ struct VoiceData : public DocumentAdditionalData {
|
||||
};
|
||||
|
||||
bool fileIsImage(const QString &name, const QString &mime);
|
||||
bool fileIsValidForAlbum(const QString &name, const QString &mime);
|
||||
|
||||
namespace Serialize {
|
||||
class Document;
|
||||
|
Loading…
Reference in New Issue
Block a user