mirror of https://github.com/procxx/kepka.git
Added allowsEditMedia() to Media. Slightly refactored.
This commit is contained in:
parent
c84f99cf3a
commit
25e3674819
|
@ -45,6 +45,7 @@ EditCaptionBox::EditCaptionBox(
|
||||||
, _msgId(item->fullId()) {
|
, _msgId(item->fullId()) {
|
||||||
Expects(item->media() != nullptr);
|
Expects(item->media() != nullptr);
|
||||||
Expects(item->media()->allowsEditCaption());
|
Expects(item->media()->allowsEditCaption());
|
||||||
|
_isAllowedEditMedia = item->media()->allowsEditMedia();
|
||||||
|
|
||||||
QSize dimensions;
|
QSize dimensions;
|
||||||
auto image = (Image*)nullptr;
|
auto image = (Image*)nullptr;
|
||||||
|
@ -331,80 +332,78 @@ void EditCaptionBox::clipCallback(Media::Clip::Notification notification) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditCaptionBox::prepare() {
|
void EditCaptionBox::createEditMediaButton() {
|
||||||
addButton(langFactory(lng_settings_save), [this] { save(); });
|
const auto callback = [=](const FileDialog::OpenResult &result) {
|
||||||
addButton(langFactory(lng_edit_media), [this] {
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
const auto callback = [=](const FileDialog::OpenResult &result) {
|
return;
|
||||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
}
|
||||||
return;
|
|
||||||
|
if (!result.paths.isEmpty()) {
|
||||||
|
const auto filePath = result.paths.front();
|
||||||
|
_newMediaPath = filePath;
|
||||||
|
_preparedList = Storage::PrepareMediaList(
|
||||||
|
QStringList(_newMediaPath),
|
||||||
|
st::sendMediaPreviewSize);
|
||||||
|
|
||||||
|
const auto file = &_preparedList.files.front();
|
||||||
|
const auto fileMedia = &file->information->media;
|
||||||
|
|
||||||
|
const auto fileinfo = QFileInfo(_newMediaPath);
|
||||||
|
const auto filename = fileinfo.fileName();
|
||||||
|
_isImage = fileIsImage(filename, Core::MimeTypeForFile(fileinfo).name());
|
||||||
|
_isAudio = false;
|
||||||
|
_animated = false;
|
||||||
|
_photo = false;
|
||||||
|
_doc = false;
|
||||||
|
_gifPreview = nullptr;
|
||||||
|
_thumbw = _thumbh = _thumbx = 0;
|
||||||
|
_gifw = _gifh = _gifx = 0;
|
||||||
|
|
||||||
|
auto isGif = false;
|
||||||
|
_wayWrap->toggle(_isImage, anim::type::instant);
|
||||||
|
|
||||||
|
using Info = FileMediaInformation;
|
||||||
|
if (const auto image = base::get_if<Info::Image>(fileMedia)
|
||||||
|
&& _isImage) {
|
||||||
|
_photo = true;
|
||||||
|
} else if (const auto video =
|
||||||
|
base::get_if<Info::Video>(fileMedia)) {
|
||||||
|
_animated = true;
|
||||||
|
isGif = video->isGifv;
|
||||||
|
} else {
|
||||||
|
auto nameString = filename;
|
||||||
|
if (const auto song =
|
||||||
|
base::get_if<Info::Song>(fileMedia)) {
|
||||||
|
nameString = DocumentData::ComposeNameString(
|
||||||
|
filename,
|
||||||
|
song->title,
|
||||||
|
song->performer);
|
||||||
|
_isAudio = true;
|
||||||
|
}
|
||||||
|
setName(nameString, fileinfo.size());
|
||||||
|
_doc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.paths.isEmpty()) {
|
if (!_doc) {
|
||||||
const auto filePath = result.paths.front();
|
_thumb = App::pixmapFromImageInPlace(
|
||||||
LOG(("FILE PATH: %1").arg(filePath));
|
file->preview.scaled(st::sendMediaPreviewSize,
|
||||||
_newMediaPath = filePath;
|
st::confirmMaxHeight,
|
||||||
_preparedList = Storage::PrepareMediaList(
|
Qt::KeepAspectRatio));
|
||||||
QStringList(_newMediaPath),
|
_thumbw = _thumb.width();
|
||||||
st::sendMediaPreviewSize);
|
_thumbh = _thumb.height();
|
||||||
|
_thumbx = (st::boxWideWidth - _thumbw) / 2;
|
||||||
const auto file = &_preparedList.files.front();
|
if (isGif) {
|
||||||
const auto fileMedia = &file->information->media;
|
_gifw = _thumbw;
|
||||||
|
_gifh = _thumbh;
|
||||||
const auto fileinfo = QFileInfo(_newMediaPath);
|
_gifx = _thumbx;
|
||||||
const auto filename = fileinfo.fileName();
|
prepareGifPreview();
|
||||||
_isImage = fileIsImage(filename, Core::MimeTypeForFile(fileinfo).name());
|
|
||||||
_isAudio = false;
|
|
||||||
_animated = false;
|
|
||||||
_photo = false;
|
|
||||||
_doc = false;
|
|
||||||
_gifPreview = nullptr;
|
|
||||||
_thumbw = _thumbh = _thumbx = 0;
|
|
||||||
_gifw = _gifh = _gifx = 0;
|
|
||||||
|
|
||||||
auto isGif = false;
|
|
||||||
_wayWrap->toggle(_isImage, anim::type::instant);
|
|
||||||
|
|
||||||
using Info = FileMediaInformation;
|
|
||||||
if (const auto image = base::get_if<Info::Image>(fileMedia)
|
|
||||||
&& _isImage) {
|
|
||||||
_photo = true;
|
|
||||||
} else if (const auto video =
|
|
||||||
base::get_if<Info::Video>(fileMedia)) {
|
|
||||||
_animated = true;
|
|
||||||
isGif = video->isGifv;
|
|
||||||
} else {
|
|
||||||
auto nameString = filename;
|
|
||||||
if (const auto song =
|
|
||||||
base::get_if<Info::Song>(fileMedia)) {
|
|
||||||
nameString = DocumentData::ComposeNameString(
|
|
||||||
filename,
|
|
||||||
song->title,
|
|
||||||
song->performer);
|
|
||||||
_isAudio = true;
|
|
||||||
}
|
|
||||||
setName(nameString, fileinfo.size());
|
|
||||||
_doc = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_doc) {
|
|
||||||
_thumb = App::pixmapFromImageInPlace(
|
|
||||||
file->preview.scaled(st::sendMediaPreviewSize,
|
|
||||||
st::confirmMaxHeight,
|
|
||||||
Qt::KeepAspectRatio));
|
|
||||||
_thumbw = _thumb.width();
|
|
||||||
_thumbh = _thumb.height();
|
|
||||||
_thumbx = (st::boxWideWidth - _thumbw) / 2;
|
|
||||||
if (isGif) {
|
|
||||||
_gifw = _thumbw;
|
|
||||||
_gifh = _thumbh;
|
|
||||||
_gifx = _thumbx;
|
|
||||||
prepareGifPreview();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
captionResized();
|
|
||||||
}
|
}
|
||||||
};
|
captionResized();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
addButton(langFactory(lng_edit_media), [=] {
|
||||||
const auto filters = QStringList(FileDialog::AllFilesFilter());
|
const auto filters = QStringList(FileDialog::AllFilesFilter());
|
||||||
FileDialog::GetOpenPath(
|
FileDialog::GetOpenPath(
|
||||||
this,
|
this,
|
||||||
|
@ -412,6 +411,15 @@ void EditCaptionBox::prepare() {
|
||||||
filters.join(qsl(";;")),
|
filters.join(qsl(";;")),
|
||||||
crl::guard(this, callback));
|
crl::guard(this, callback));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditCaptionBox::prepare() {
|
||||||
|
addButton(langFactory(lng_settings_save), [this] { save(); });
|
||||||
|
if (_isAllowedEditMedia) {
|
||||||
|
createEditMediaButton();
|
||||||
|
} else {
|
||||||
|
_newMediaPath = QString();
|
||||||
|
}
|
||||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||||
|
|
||||||
updateBoxSize();
|
updateBoxSize();
|
||||||
|
|
|
@ -66,6 +66,8 @@ private:
|
||||||
|
|
||||||
int errorTopSkip() const;
|
int errorTopSkip() const;
|
||||||
|
|
||||||
|
void createEditMediaButton();
|
||||||
|
|
||||||
not_null<Window::Controller*> _controller;
|
not_null<Window::Controller*> _controller;
|
||||||
FullMsgId _msgId;
|
FullMsgId _msgId;
|
||||||
Image *_thumbnailImage = nullptr;
|
Image *_thumbnailImage = nullptr;
|
||||||
|
@ -104,6 +106,7 @@ private:
|
||||||
bool _asFile = false;
|
bool _asFile = false;
|
||||||
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
Ui::SlideWrap<Ui::RpWidget> *_wayWrap = nullptr;
|
||||||
QString _newMediaPath;
|
QString _newMediaPath;
|
||||||
|
bool _isAllowedEditMedia = false;
|
||||||
|
|
||||||
QString _error;
|
QString _error;
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,10 @@ bool Media::allowsEditCaption() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Media::allowsEditMedia() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool Media::allowsRevoke() const {
|
bool Media::allowsRevoke() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -323,6 +327,10 @@ bool MediaPhoto::allowsEditCaption() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MediaPhoto::allowsEditMedia() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString MediaPhoto::errorTextForForward(not_null<PeerData*> peer) const {
|
QString MediaPhoto::errorTextForForward(not_null<PeerData*> peer) const {
|
||||||
const auto errorKey = Data::RestrictionErrorKey(
|
const auto errorKey = Data::RestrictionErrorKey(
|
||||||
peer,
|
peer,
|
||||||
|
@ -648,6 +656,13 @@ bool MediaFile::allowsEditCaption() const {
|
||||||
return !_document->isVideoMessage() && !_document->sticker();
|
return !_document->isVideoMessage() && !_document->sticker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MediaFile::allowsEditMedia() const {
|
||||||
|
return !_document->isVideoMessage()
|
||||||
|
&& !_document->sticker()
|
||||||
|
&& !_document->isGifv()
|
||||||
|
&& !_document->isVoiceMessage();
|
||||||
|
}
|
||||||
|
|
||||||
bool MediaFile::forwardedBecomesUnread() const {
|
bool MediaFile::forwardedBecomesUnread() const {
|
||||||
return _document->isVoiceMessage()
|
return _document->isVoiceMessage()
|
||||||
//|| _document->isVideoFile()
|
//|| _document->isVideoFile()
|
||||||
|
|
|
@ -93,6 +93,7 @@ public:
|
||||||
virtual bool allowsForward() const;
|
virtual bool allowsForward() const;
|
||||||
virtual bool allowsEdit() const;
|
virtual bool allowsEdit() const;
|
||||||
virtual bool allowsEditCaption() const;
|
virtual bool allowsEditCaption() const;
|
||||||
|
virtual bool allowsEditMedia() const;
|
||||||
virtual bool allowsRevoke() const;
|
virtual bool allowsRevoke() const;
|
||||||
virtual bool forwardedBecomesUnread() const;
|
virtual bool forwardedBecomesUnread() const;
|
||||||
virtual QString errorTextForForward(not_null<PeerData*> peer) const;
|
virtual QString errorTextForForward(not_null<PeerData*> peer) const;
|
||||||
|
@ -141,6 +142,7 @@ public:
|
||||||
QString pinnedTextSubstring() const override;
|
QString pinnedTextSubstring() const override;
|
||||||
TextWithEntities clipboardText() const override;
|
TextWithEntities clipboardText() const override;
|
||||||
bool allowsEditCaption() const override;
|
bool allowsEditCaption() const override;
|
||||||
|
bool allowsEditMedia() const override;
|
||||||
QString errorTextForForward(not_null<PeerData*> peer) const override;
|
QString errorTextForForward(not_null<PeerData*> peer) const override;
|
||||||
|
|
||||||
bool updateInlineResultMedia(const MTPMessageMedia &media) override;
|
bool updateInlineResultMedia(const MTPMessageMedia &media) override;
|
||||||
|
@ -176,6 +178,7 @@ public:
|
||||||
QString pinnedTextSubstring() const override;
|
QString pinnedTextSubstring() const override;
|
||||||
TextWithEntities clipboardText() const override;
|
TextWithEntities clipboardText() const override;
|
||||||
bool allowsEditCaption() const override;
|
bool allowsEditCaption() const override;
|
||||||
|
bool allowsEditMedia() const override;
|
||||||
bool forwardedBecomesUnread() const override;
|
bool forwardedBecomesUnread() const override;
|
||||||
QString errorTextForForward(not_null<PeerData*> peer) const override;
|
QString errorTextForForward(not_null<PeerData*> peer) const override;
|
||||||
|
|
||||||
|
|
|
@ -313,6 +313,8 @@ void Uploader::sendNext() {
|
||||||
if (requestsSent.empty() && docRequestsSent.empty()) {
|
if (requestsSent.empty() && docRequestsSent.empty()) {
|
||||||
const auto silent = uploadingData.file
|
const auto silent = uploadingData.file
|
||||||
&& uploadingData.file->to.silent;
|
&& uploadingData.file->to.silent;
|
||||||
|
const auto edit = uploadingData.file &&
|
||||||
|
uploadingData.file->edit;
|
||||||
if (uploadingData.type() == SendMediaType::Photo) {
|
if (uploadingData.type() == SendMediaType::Photo) {
|
||||||
auto photoFilename = uploadingData.filename();
|
auto photoFilename = uploadingData.filename();
|
||||||
if (!photoFilename.endsWith(qstr(".jpg"), Qt::CaseInsensitive)) {
|
if (!photoFilename.endsWith(qstr(".jpg"), Qt::CaseInsensitive)) {
|
||||||
|
@ -329,7 +331,7 @@ void Uploader::sendNext() {
|
||||||
MTP_int(uploadingData.partsCount),
|
MTP_int(uploadingData.partsCount),
|
||||||
MTP_string(photoFilename),
|
MTP_string(photoFilename),
|
||||||
MTP_bytes(md5));
|
MTP_bytes(md5));
|
||||||
_photoReady.fire({ uploadingId, silent, file, uploadingData.file->edit });
|
_photoReady.fire({ uploadingId, silent, file, edit });
|
||||||
} else if (uploadingData.type() == SendMediaType::File
|
} else if (uploadingData.type() == SendMediaType::File
|
||||||
|| uploadingData.type() == SendMediaType::WallPaper
|
|| uploadingData.type() == SendMediaType::WallPaper
|
||||||
|| uploadingData.type() == SendMediaType::Audio) {
|
|| uploadingData.type() == SendMediaType::Audio) {
|
||||||
|
@ -363,9 +365,13 @@ void Uploader::sendNext() {
|
||||||
silent,
|
silent,
|
||||||
file,
|
file,
|
||||||
thumb,
|
thumb,
|
||||||
uploadingData.file->edit });
|
edit });
|
||||||
} else {
|
} else {
|
||||||
_documentReady.fire({ uploadingId, silent, file, uploadingData.file->edit });
|
_documentReady.fire({
|
||||||
|
uploadingId,
|
||||||
|
silent,
|
||||||
|
file,
|
||||||
|
edit });
|
||||||
}
|
}
|
||||||
} else if (uploadingData.type() == SendMediaType::Secure) {
|
} else if (uploadingData.type() == SendMediaType::Secure) {
|
||||||
_secureReady.fire({
|
_secureReady.fire({
|
||||||
|
|
Loading…
Reference in New Issue