From a8ac18e4fdbc99623112080ed9a5626b65c3bd58 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 25 Dec 2017 14:13:27 +0300 Subject: [PATCH] Save send way (album, photos, files) to settings. --- Telegram/SourceFiles/auth_session.cpp | 12 ++- Telegram/SourceFiles/auth_session.h | 12 ++- Telegram/SourceFiles/boxes/send_files_box.cpp | 98 ++++++++++++------- Telegram/SourceFiles/boxes/send_files_box.h | 24 ++--- .../SourceFiles/history/history_widget.cpp | 9 +- Telegram/SourceFiles/settings.cpp | 1 - Telegram/SourceFiles/settings.h | 1 - .../SourceFiles/storage/localimageloader.cpp | 2 +- Telegram/SourceFiles/storage/localstorage.cpp | 6 +- 9 files changed, 104 insertions(+), 61 deletions(-) diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index ecb9c41567..bc5db1b4d3 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "calls/calls_instance.h" #include "window/section_widget.h" #include "chat_helpers/tabbed_selector.h" +#include "boxes/send_files_box.h" namespace { @@ -41,7 +42,8 @@ constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000); } // namespace AuthSessionData::Variables::Variables() -: selectorTab(ChatHelpers::SelectorTab::Emoji) +: sendFilesWay(SendFilesWay::Album) +, selectorTab(ChatHelpers::SelectorTab::Emoji) , floatPlayerColumn(Window::Column::Second) , floatPlayerCorner(RectPart::TopRight) { } @@ -80,6 +82,7 @@ QByteArray AuthSessionData::serialize() const { 1000000)); stream << qint32(_variables.thirdColumnWidth.current()); stream << qint32(_variables.thirdSectionExtendedBy); + stream << qint32(_variables.sendFilesWay); } return result; } @@ -104,6 +107,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { float64 dialogsWidthRatio = _variables.dialogsWidthRatio.current(); int thirdColumnWidth = _variables.thirdColumnWidth.current(); int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy; + qint32 sendFilesWay = static_cast(_variables.sendFilesWay); stream >> selectorTab; stream >> lastSeenWarningSeen; if (!stream.atEnd()) { @@ -189,6 +193,12 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { if (_variables.thirdSectionInfoEnabled) { _variables.tabbedSelectorSectionEnabled = false; } + auto uncheckedSendFilesWay = static_cast(sendFilesWay); + switch (uncheckedSendFilesWay) { + case SendFilesWay::Album: + case SendFilesWay::Photos: + case SendFilesWay::Files: _variables.sendFilesWay = uncheckedSendFilesWay; + } } void AuthSessionData::markItemLayoutChanged(not_null item) { diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index b7a8669251..1bf2ec502e 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -26,6 +26,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "base/timer.h" #include "chat_helpers/stickers.h" +class ApiWrap; +enum class SendFilesWay; + namespace Storage { class Downloader; class Uploader; @@ -47,8 +50,6 @@ namespace ChatHelpers { enum class SelectorTab; } // namespace ChatHelpers -class ApiWrap; - class AuthSessionData final { public: base::Variable &contactsLoaded() { @@ -108,6 +109,12 @@ public: void setLastSeenWarningSeen(bool lastSeenWarningSeen) { _variables.lastSeenWarningSeen = lastSeenWarningSeen; } + void setSendFilesWay(SendFilesWay way) { + _variables.sendFilesWay = way; + } + SendFilesWay sendFilesWay() const { + return _variables.sendFilesWay; + } ChatHelpers::SelectorTab selectorTab() const { return _variables.selectorTab; } @@ -273,6 +280,7 @@ private: static constexpr auto kDefaultThirdColumnWidth = 0; bool lastSeenWarningSeen = false; + SendFilesWay sendFilesWay; ChatHelpers::SelectorTab selectorTab; // per-window bool tabbedSelectorSectionEnabled = false; // per-window int tabbedSelectorSectionTooltipShown = 0; diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 21da31c667..2fa19880ef 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -455,9 +455,9 @@ public: AlbumPreview( QWidget *parent, const Storage::PreparedList &list, - SendWay way); + SendFilesWay way); - void setSendWay(SendWay way); + void setSendWay(SendFilesWay way); protected: void paintEvent(QPaintEvent *e) override; @@ -474,7 +474,7 @@ private: void paintFiles(Painter &p, QRect clip) const; const Storage::PreparedList &_list; - SendWay _sendWay = SendWay::Files; + SendFilesWay _sendWay = SendFilesWay::Files; std::vector _thumbs; int _thumbsHeight = 0; int _photosHeight = 0; @@ -485,7 +485,7 @@ private: SendFilesBox::AlbumPreview::AlbumPreview( QWidget *parent, const Storage::PreparedList &list, - SendWay way) + SendFilesWay way) : RpWidget(parent) , _list(list) , _sendWay(way) { @@ -493,7 +493,7 @@ SendFilesBox::AlbumPreview::AlbumPreview( updateSize(); } -void SendFilesBox::AlbumPreview::setSendWay(SendWay way) { +void SendFilesBox::AlbumPreview::setSendWay(SendFilesWay way) { _sendWay = way; updateSize(); update(); @@ -615,9 +615,9 @@ SendFilesBox::AlbumThumb SendFilesBox::AlbumPreview::prepareThumb( void SendFilesBox::AlbumPreview::updateSize() { const auto height = [&] { switch (_sendWay) { - case SendWay::Album: return _thumbsHeight; - case SendWay::Photos: return _photosHeight; - case SendWay::Files: return _filesHeight; + case SendFilesWay::Album: return _thumbsHeight; + case SendFilesWay::Photos: return _photosHeight; + case SendFilesWay::Files: return _filesHeight; } Unexpected("Send way in SendFilesBox::AlbumPreview::updateSize"); }(); @@ -628,9 +628,9 @@ void SendFilesBox::AlbumPreview::paintEvent(QPaintEvent *e) { Painter p(this); switch (_sendWay) { - case SendWay::Album: paintAlbum(p); break; - case SendWay::Photos: paintPhotos(p, e->rect()); break; - case SendWay::Files: paintFiles(p, e->rect()); break; + case SendFilesWay::Album: paintAlbum(p); break; + case SendFilesWay::Photos: paintPhotos(p, e->rect()); break; + case SendFilesWay::Files: paintFiles(p, e->rect()); break; } } @@ -832,26 +832,39 @@ void SendFilesBox::prepare() { } void SendFilesBox::initSendWay() { - const auto value = (_compressConfirm == CompressConfirm::None) - ? SendWay::Files - : (_compressConfirm == CompressConfirm::Auto) - ? (cCompressPastedImage() - ? (_list.albumIsPossible ? SendWay::Album : SendWay::Photos) - : SendWay::Files) - : (_compressConfirm == CompressConfirm::Yes - ? (_list.albumIsPossible ? SendWay::Album : SendWay::Photos) - : SendWay::Files); - _sendWay = std::make_shared>(value); -} - -void SendFilesBox::setupControls() { - _albumVideosCount = ranges::v3::count( + _albumVideosCount = ranges::count( _list.files, Storage::PreparedFile::AlbumType::Video, [](const Storage::PreparedFile &file) { return file.type; }); _albumPhotosCount = _list.albumIsPossible ? (_list.files.size() - _albumVideosCount) : 0; + const auto value = [&] { + if (_compressConfirm == CompressConfirm::None) { + return SendFilesWay::Files; + } else if (_compressConfirm == CompressConfirm::No) { + return SendFilesWay::Files; + } else if (_compressConfirm == CompressConfirm::Yes) { + return _list.albumIsPossible + ? SendFilesWay::Album + : SendFilesWay::Photos; + } + const auto currentWay = Auth().data().sendFilesWay(); + if (currentWay == SendFilesWay::Files) { + return currentWay; + } else if (currentWay == SendFilesWay::Album) { + return _list.albumIsPossible + ? SendFilesWay::Album + : SendFilesWay::Photos; + } + return (_list.albumIsPossible && !_albumPhotosCount) + ? SendFilesWay::Album + : SendFilesWay::Photos; + }(); + _sendWay = std::make_shared>(value); +} + +void SendFilesBox::setupControls() { setupTitleText(); setupSendWayControls(); setupCaption(); @@ -862,17 +875,17 @@ void SendFilesBox::setupSendWayControls() { return; } const auto addRadio = [&]( - object_ptr> &button, - SendWay value, + object_ptr> &button, + SendFilesWay value, const QString &text) { const auto &style = st::defaultBoxCheckbox; button.create(this, _sendWay, value, text, style); }; if (_list.albumIsPossible) { - addRadio(_sendAlbum, SendWay::Album, lang(lng_send_album)); + addRadio(_sendAlbum, SendFilesWay::Album, lang(lng_send_album)); } if (!_list.albumIsPossible || _albumPhotosCount > 0) { - addRadio(_sendPhotos, SendWay::Photos, (_list.files.size() == 1) + addRadio(_sendPhotos, SendFilesWay::Photos, (_list.files.size() == 1) ? lang(lng_send_photo) : (_albumVideosCount > 0) ? (_list.albumIsPossible @@ -882,10 +895,10 @@ void SendFilesBox::setupSendWayControls() { ? lang(lng_send_separate_photos) : lng_send_photos(lt_count, _list.files.size()))); } - addRadio(_sendFiles, SendWay::Files, (_list.files.size() == 1) + addRadio(_sendFiles, SendFilesWay::Files, (_list.files.size() == 1) ? lang(lng_send_file) : lng_send_files(lt_count, _list.files.size())); - _sendWay->setChangedCallback([this](SendWay value) { + _sendWay->setChangedCallback([this](SendFilesWay value) { if (_albumPreview) { _albumPreview->setSendWay(value); } @@ -1021,14 +1034,25 @@ void SendFilesBox::setInnerFocus() { } void SendFilesBox::send(bool ctrlShiftEnter) { - // TODO settings - //if (_compressed && _compressConfirm == CompressConfirm::Auto && _compressed->checked() != cCompressPastedImage()) { - // cSetCompressPastedImage(_compressed->checked()); - // Local::writeUserSettings(); - //} + using Way = SendFilesWay; + const auto way = _sendWay ? _sendWay->value() : Way::Files; + + if (_compressConfirm == CompressConfirm::Auto) { + const auto oldWay = Auth().data().sendFilesWay(); + if (way != oldWay) { + // Check if the user _could_ use the old value, but didn't. + if ((oldWay == Way::Album && _sendAlbum) + || (oldWay == Way::Photos && _sendPhotos) + || (oldWay == Way::Files && _sendFiles) + || (way == Way::Files && (_sendAlbum || _sendPhotos))) { + // And in that case save it to settings. + Auth().data().setSendFilesWay(way); + Auth().saveDataDelayed(); + } + } + } _confirmed = true; if (_confirmedCallback) { - const auto way = _sendWay ? _sendWay->value() : SendWay::Files; auto caption = _caption ? TextUtilities::PrepareForSending( _caption->getLastText(), diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index edca3b1905..f16fbb99af 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -35,14 +35,14 @@ class InputArea; struct GroupMediaLayout; } // namespace Ui +enum class SendFilesWay { + Album, + Photos, + Files, +}; + class SendFilesBox : public BoxContent { public: - enum class SendWay { - Album, - Photos, - Files, - }; - SendFilesBox( QWidget*, Storage::PreparedList &&list, @@ -51,7 +51,7 @@ public: void setConfirmedCallback( base::lambda callback) { _confirmedCallback = std::move(callback); @@ -103,17 +103,17 @@ private: base::lambda _confirmedCallback; base::lambda _cancelledCallback; bool _confirmed = false; object_ptr _caption = { nullptr }; - object_ptr> _sendAlbum = { nullptr }; - object_ptr> _sendPhotos = { nullptr }; - object_ptr> _sendFiles = { nullptr }; - std::shared_ptr> _sendWay; + object_ptr> _sendAlbum = { nullptr }; + object_ptr> _sendPhotos = { nullptr }; + object_ptr> _sendFiles = { nullptr }; + std::shared_ptr> _sendWay; rpl::variable _footerHeight = 0; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 05665f3f99..29b9f1e23f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3133,7 +3133,7 @@ void HistoryWidget::chooseAttach() { auto list = Storage::PrepareMediaList( result.paths, st::sendMediaPreviewSize); - if (list.allFilesForCompress) { + if (list.allFilesForCompress || list.albumIsPossible) { confirmSendingFiles(std::move(list), CompressConfirm::Auto); } else if (!showSendingFilesError(list)) { uploadFiles(std::move(list), SendMediaType::File); @@ -3979,6 +3979,7 @@ bool HistoryWidget::showSendingFilesError( if (text.isEmpty()) { return false; } + Ui::show(Box(text)); return true; } @@ -4029,16 +4030,16 @@ bool HistoryWidget::confirmSendingFiles( auto box = Box(std::move(list), boxCompressConfirm); box->setConfirmedCallback(base::lambda_guarded(this, [=]( Storage::PreparedList &&list, - SendFilesBox::SendWay way, + SendFilesWay way, const QString &caption, bool ctrlShiftEnter) { if (showSendingFilesError(list)) { return; } - const auto type = (way == SendFilesBox::SendWay::Files) + const auto type = (way == SendFilesWay::Files) ? SendMediaType::File : SendMediaType::Photo; - const auto album = (way == SendFilesBox::SendWay::Album) + const auto album = (way == SendFilesWay::Album) ? std::make_shared() : nullptr; uploadFilesAfterConfirmation( diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index c4a271aa16..a2e358461a 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -64,7 +64,6 @@ QByteArray gLocalSalt; DBIScale gRealScale = dbisAuto; DBIScale gScreenScale = dbisOne; DBIScale gConfigScale = dbisAuto; -bool gCompressPastedImage = true; QString gTimeFormat = qsl("hh:mm"); diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 924cab8293..fb23e84045 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -120,7 +120,6 @@ DeclareSetting(QByteArray, LocalSalt); DeclareSetting(DBIScale, RealScale); DeclareSetting(DBIScale, ScreenScale); DeclareSetting(DBIScale, ConfigScale); -DeclareSetting(bool, CompressPastedImage); DeclareSetting(QString, TimeFormat); inline void cChangeTimeFormat(const QString &newFormat) { diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 79327aad46..5e3df513b9 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -523,7 +523,7 @@ void FileLoadTask::process() { isVideo = true; auto coverWidth = video->thumbnail.width(); auto coverHeight = video->thumbnail.height(); - if (video->isGifv) { + if (video->isGifv && !_album) { attributes.push_back(MTP_documentAttributeAnimated()); } auto flags = MTPDdocumentAttributeVideo::Flags(0); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 68240fcb38..22413af918 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "storage/serialize_common.h" #include "chat_helpers/stickers.h" #include "data/data_drafts.h" +#include "boxes/send_files_box.h" #include "window/themes/window_theme.h" #include "observer_peer.h" #include "mainwidget.h" @@ -1422,7 +1423,9 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting stream >> v; if (!_checkStreamStatus(stream)) return false; - cSetCompressPastedImage(v == 1); + GetStoredAuthSessionCache().setSendFilesWay((v == 1) + ? SendFilesWay::Album + : SendFilesWay::Files); } break; case dbiEmojiTabOld: { @@ -1804,7 +1807,6 @@ void _writeUserSettings() { data.stream << quint32(dbiNotificationsCorner) << qint32(Global::NotificationsCorner()); data.stream << quint32(dbiAskDownloadPath) << qint32(Global::AskDownloadPath()); data.stream << quint32(dbiDownloadPath) << (Global::AskDownloadPath() ? QString() : Global::DownloadPath()) << (Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark()); - data.stream << quint32(dbiCompressPastedImage) << qint32(cCompressPastedImage()); data.stream << quint32(dbiDialogLastPath) << cDialogLastPath(); data.stream << quint32(dbiSongVolume) << qint32(qRound(Global::SongVolume() * 1e6)); data.stream << quint32(dbiVideoVolume) << qint32(qRound(Global::VideoVolume() * 1e6));