From bff8313a37bb17607bac05647c398d0f1886e007 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 27 Feb 2022 17:34:22 +0300 Subject: [PATCH] Use nice media names in Downloads. --- Telegram/SourceFiles/boxes/boxes.style | 2 +- .../data/data_download_manager.cpp | 6 ++++-- .../downloads/info_downloads_provider.cpp | 4 ++-- Telegram/SourceFiles/info/info.style | 2 +- .../info/media/info_media_list_widget.cpp | 8 +++++--- .../SourceFiles/overview/overview_layout.cpp | 6 +++--- .../SourceFiles/ui/controls/download_bar.cpp | 5 +++-- .../SourceFiles/ui/controls/download_bar.h | 2 +- .../ui/text/format_song_document_name.cpp | 19 +++++++++++++++++++ .../ui/text/format_song_document_name.h | 3 +++ 10 files changed, 42 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 3a7234f170..90344288b1 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -467,7 +467,7 @@ calendarPrevious: IconButton { icon: icon {{ "calendar_down-flip_vertical", boxTitleFg }}; iconPosition: point(-1px, -1px); - rippleAreaPosition: point(6px, 6px); + rippleAreaPosition: point(2px, 2px); rippleAreaSize: 44px; ripple: RippleAnimation(defaultRippleAnimation) { color: windowBgOver; diff --git a/Telegram/SourceFiles/data/data_download_manager.cpp b/Telegram/SourceFiles/data/data_download_manager.cpp index 8dc5262cd1..4386e4df20 100644 --- a/Telegram/SourceFiles/data/data_download_manager.cpp +++ b/Telegram/SourceFiles/data/data_download_manager.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/mime_type.h" #include "ui/controls/download_bar.h" +#include "ui/text/format_song_document_name.h" #include "storage/serialize_common.h" #include "apiwrap.h" @@ -822,8 +823,9 @@ rpl::producer MakeDownloadBarContent() { ) | rpl::map([=, &manager] { auto result = Ui::DownloadBarContent(); for (const auto id : manager.loadingList()) { - if (result.singleName.isEmpty()) { - result.singleName = id->object.document->filename(); + if (result.singleName.text.isEmpty()) { + const auto document = id->object.document; + result.singleName = Ui::Text::FormatDownloadsName(document); result.singleThumbnail = QImage(); } ++result.count; diff --git a/Telegram/SourceFiles/info/downloads/info_downloads_provider.cpp b/Telegram/SourceFiles/info/downloads/info_downloads_provider.cpp index 78b81c00fe..0177d83ff7 100644 --- a/Telegram/SourceFiles/info/downloads/info_downloads_provider.cpp +++ b/Telegram/SourceFiles/info/downloads/info_downloads_provider.cpp @@ -215,7 +215,7 @@ void Provider::performRefresh() { _postponedRefresh = false; _fullCount = _elements.size(); if (base::take(_postponedRefreshSort)) { - ranges::sort(_elements, ranges::greater(), &Element::started); + ranges::sort(_elements, ranges::less(), &Element::started); } _refreshed.fire({}); } @@ -255,7 +255,7 @@ std::vector Provider::fillSections( 1, ListSection(Type::File, sectionDelegate())); auto §ion = result.back(); - for (const auto &element : _elements) { + for (const auto &element : ranges::views::reverse(_elements)) { if (auto layout = getLayout(element, delegate)) { section.addItem(layout); } diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 23a3472a45..da66567bb3 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -212,7 +212,7 @@ infoLayerTopBarForward: IconButton(infoLayerTopBarBack) { icon: icon {{ "info/info_media_forward", boxTitleCloseFg }}; iconOver: icon {{ "info/info_media_forward", boxTitleCloseFgOver }}; iconPosition: point(11px, -1px); - rippleAreaPosition: point(3px, 4px); + rippleAreaPosition: point(3px, 8px); } infoLayerTopBarDelete: IconButton(infoLayerTopBarForward) { icon: icon {{ "info/info_media_delete", boxTitleCloseFg }}; diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index b304373ab7..8cf168f296 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1069,6 +1069,11 @@ void ListWidget::deleteItems(SelectedItems &&items, Fn confirmed) { ? tr::lng_downloads_delete_sure_one(tr::now) : tr::lng_downloads_delete_sure(tr::now, lt_count, count); const auto deleteSure = [=] { + Ui::PostponeCall(this, [=] { + if (const auto box = _actionBoxWeak.data()) { + box->closeBox(); + } + }); const auto ids = ranges::views::all( items.list ) | ranges::views::transform([](const SelectedItem &item) { @@ -1076,9 +1081,6 @@ void ListWidget::deleteItems(SelectedItems &&items, Fn confirmed) { }) | ranges::to_vector; Core::App().downloadManager().deleteFiles(ids); confirmed(); - if (const auto box = _actionBoxWeak.data()) { - box->closeBox(); - } }; setActionBoxWeak(window->show(Box( phrase, diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 37bb1dd98a..49a7c31cd1 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -941,9 +941,9 @@ Document::Document( , _datew(st::normalFont->width(_date)) { _name.setMarkedText( st::defaultTextStyle, - (_forceFileLayout - ? Ui::Text::Bold(_data->filename()) - : Ui::Text::FormatSongNameFor(_data).textWithEntities()), + (!_forceFileLayout + ? Ui::Text::FormatSongNameFor(_data).textWithEntities() + : Ui::Text::FormatDownloadsName(_data)), _documentNameOptions); AddComponents(Info::Bit()); diff --git a/Telegram/SourceFiles/ui/controls/download_bar.cpp b/Telegram/SourceFiles/ui/controls/download_bar.cpp index 489e647972..05a9361044 100644 --- a/Telegram/SourceFiles/ui/controls/download_bar.cpp +++ b/Telegram/SourceFiles/ui/controls/download_bar.cpp @@ -56,9 +56,10 @@ void DownloadBar::show(DownloadBarContent &&content) { _radial.start(computeProgress()); } _content = content; - _title.setText(st::semiboldTextStyle, + _title.setMarkedText(st::defaultTextStyle, (content.count > 1 - ? tr::lng_profile_files(tr::now, lt_count, content.count) + ? Ui::Text::Bold( + tr::lng_profile_files(tr::now, lt_count, content.count)) : content.singleName)); refreshInfo(_progress.current()); } diff --git a/Telegram/SourceFiles/ui/controls/download_bar.h b/Telegram/SourceFiles/ui/controls/download_bar.h index d44a96548b..fe69138884 100644 --- a/Telegram/SourceFiles/ui/controls/download_bar.h +++ b/Telegram/SourceFiles/ui/controls/download_bar.h @@ -22,7 +22,7 @@ struct DownloadBarProgress { }; struct DownloadBarContent { - QString singleName; + TextWithEntities singleName; QImage singleThumbnail; int count = 0; int done = 0; diff --git a/Telegram/SourceFiles/ui/text/format_song_document_name.cpp b/Telegram/SourceFiles/ui/text/format_song_document_name.cpp index 8324585da1..82d2a99fef 100644 --- a/Telegram/SourceFiles/ui/text/format_song_document_name.cpp +++ b/Telegram/SourceFiles/ui/text/format_song_document_name.cpp @@ -7,7 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/text/format_song_document_name.h" +#include "ui/text/text_utilities.h" #include "data/data_document.h" +#include "lang/lang_keys.h" namespace Ui::Text { @@ -20,4 +22,21 @@ FormatSongName FormatSongNameFor(not_null document) { song ? song->performer : QString()); } +TextWithEntities FormatDownloadsName(not_null document) { + return document->isVideoFile() + ? Bold(tr::lng_in_dlg_video(tr::now)) + : document->isVoiceMessage() + ? Bold(tr::lng_in_dlg_audio(tr::now)) + : document->isVideoMessage() + ? Bold(tr::lng_in_dlg_video_message(tr::now)) + : document->sticker() + ? Bold(document->sticker()->alt.isEmpty() + ? tr::lng_in_dlg_sticker(tr::now) + : tr::lng_in_dlg_sticker_emoji( + tr::now, + lt_emoji, + document->sticker()->alt)) + : FormatSongNameFor(document).textWithEntities(); +} + } // namespace Ui::Text diff --git a/Telegram/SourceFiles/ui/text/format_song_document_name.h b/Telegram/SourceFiles/ui/text/format_song_document_name.h index 3318ed95de..a1be4b699d 100644 --- a/Telegram/SourceFiles/ui/text/format_song_document_name.h +++ b/Telegram/SourceFiles/ui/text/format_song_document_name.h @@ -16,4 +16,7 @@ namespace Ui::Text { [[nodiscard]] FormatSongName FormatSongNameFor( not_null document); +[[nodiscard]] TextWithEntities FormatDownloadsName( + not_null document); + } // namespace Ui::Text