mirror of
https://github.com/vale981/tdesktop
synced 2025-03-08 11:11:39 -05: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
4 changed files with 32 additions and 2 deletions
|
@ -46,6 +46,7 @@ EditCaptionBox::EditCaptionBox(
|
||||||
Expects(item->media() != nullptr);
|
Expects(item->media() != nullptr);
|
||||||
Expects(item->media()->allowsEditCaption());
|
Expects(item->media()->allowsEditCaption());
|
||||||
_isAllowedEditMedia = item->media()->allowsEditMedia();
|
_isAllowedEditMedia = item->media()->allowsEditMedia();
|
||||||
|
_isNotAlbum = !item->groupId();
|
||||||
|
|
||||||
QSize dimensions;
|
QSize dimensions;
|
||||||
auto image = (Image*)nullptr;
|
auto image = (Image*)nullptr;
|
||||||
|
@ -350,6 +351,15 @@ void EditCaptionBox::createEditMediaButton() {
|
||||||
|
|
||||||
const auto fileinfo = QFileInfo(_newMediaPath);
|
const auto fileinfo = QFileInfo(_newMediaPath);
|
||||||
const auto filename = fileinfo.fileName();
|
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());
|
_isImage = fileIsImage(filename, Core::MimeTypeForFile(fileinfo).name());
|
||||||
_isAudio = false;
|
_isAudio = false;
|
||||||
_animated = false;
|
_animated = false;
|
||||||
|
@ -360,7 +370,7 @@ void EditCaptionBox::createEditMediaButton() {
|
||||||
_gifw = _gifh = _gifx = 0;
|
_gifw = _gifh = _gifx = 0;
|
||||||
|
|
||||||
auto isGif = false;
|
auto isGif = false;
|
||||||
_wayWrap->toggle(_isImage, anim::type::instant);
|
_wayWrap->toggle(_isImage && _isNotAlbum, anim::type::instant);
|
||||||
|
|
||||||
using Info = FileMediaInformation;
|
using Info = FileMediaInformation;
|
||||||
if (const auto image = base::get_if<Info::Image>(fileMedia)
|
if (const auto image = base::get_if<Info::Image>(fileMedia)
|
||||||
|
@ -404,7 +414,9 @@ void EditCaptionBox::createEditMediaButton() {
|
||||||
};
|
};
|
||||||
|
|
||||||
addButton(langFactory(lng_edit_media), [=] {
|
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(
|
FileDialog::GetOpenPath(
|
||||||
this,
|
this,
|
||||||
lang(lng_choose_file),
|
lang(lng_choose_file),
|
||||||
|
|
|
@ -107,6 +107,7 @@ private:
|
||||||
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
||||||
QString _newMediaPath;
|
QString _newMediaPath;
|
||||||
bool _isAllowedEditMedia = false;
|
bool _isAllowedEditMedia = false;
|
||||||
|
bool _isNotAlbum;
|
||||||
|
|
||||||
QString _error;
|
QString _error;
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,22 @@ bool fileIsImage(const QString &name, const QString &mime) {
|
||||||
return false;
|
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(
|
QString FileNameUnsafe(
|
||||||
const QString &title,
|
const QString &title,
|
||||||
const QString &filter,
|
const QString &filter,
|
||||||
|
|
|
@ -72,6 +72,7 @@ struct VoiceData : public DocumentAdditionalData {
|
||||||
};
|
};
|
||||||
|
|
||||||
bool fileIsImage(const QString &name, const QString &mime);
|
bool fileIsImage(const QString &name, const QString &mime);
|
||||||
|
bool fileIsValidForAlbum(const QString &name, const QString &mime);
|
||||||
|
|
||||||
namespace Serialize {
|
namespace Serialize {
|
||||||
class Document;
|
class Document;
|
||||||
|
|
Loading…
Add table
Reference in a new issue